Ejemplo n.º 1
0
 function listFiles($path, $regex = '.')
 {
     $files = array();
     // Make sure path is valid
     $path = JPath::clean($path);
     if (empty($path) || JString::strpos($path, JPATH_ROOT) === false) {
         return $files;
     }
     $list = JFolder::files($path, $regex, false, true);
     if (empty($list)) {
         return $files;
     }
     foreach ($list as $filename) {
         $f = new JObject();
         $f->name = JFile::getName($filename);
         $f->path = $filename;
         $f->src = JString::str_ireplace(JPATH_ROOT . DS, JURI::root(), $f->path);
         $f->src = str_replace(DS, '/', $f->src);
         $f->size = LinkrHelper::parseSize($f->path);
         $f->ext = strtolower(JFile::getExt($f->name));
         switch ($f->ext) {
             // Image
             case 'bmp':
             case 'gif':
             case 'jpg':
             case 'jpeg':
             case 'odg':
             case 'png':
             case 'xcf':
                 list($w, $h) = @getimagesize($f->path);
                 $size = LinkrHelper::imageResize($w, $h, 32);
                 $f->width = $size['width'];
                 $f->height = $size['height'];
                 $f->icon = JString::str_ireplace(JPATH_ROOT . DS, JURI::root(), $f->path);
                 $f->icon = str_replace(DS, '/', $f->icon);
                 $f->type = JText::_('Image');
                 break;
                 // Other files
             // Other files
             default:
                 $f->type = strtoupper($f->ext);
                 $f->width = 32;
                 $f->height = 32;
                 $icon = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_media' . DS . 'images' . DS . 'mime-icon-32' . DS . $f->ext . '.png';
                 if (file_exists($icon)) {
                     $f->icon = JURI::root() . 'administrator/components/com_media/images/mime-icon-32/' . $f->ext . '.png';
                 } else {
                     $f->icon = JURI::root() . 'administrator/components/com_media/images/con_info.png';
                 }
                 break;
         }
         $files[] = $f;
     }
     return $files;
 }
Ejemplo n.º 2
0
 function listFiles($path, $regex = '.', $simple = false)
 {
     $files = array();
     // Make sure path is valid
     jimport('joomla.filesystem.path');
     $path = JPath::clean($path);
     $root = strlen(JPATH_ROOT) ? JPATH_ROOT : DS;
     if (empty($path) || JString::strpos($path, $root) === false) {
         return $files;
     }
     // Get files
     jimport('joomla.filesystem.folder');
     $list = JFolder::files($path, $regex, false, true);
     if (empty($list)) {
         return $files;
     }
     // List files
     jimport('joomla.filesystem.file');
     // Simple list
     if ($simple) {
         foreach ($list as $f) {
             // Get source
             $s = strlen(JPATH_ROOT) ? JString::str_ireplace(JPATH_ROOT . DS, JURI::root(), $f) : JURI::root() . $f;
             $files[] = array('src' => str_replace(DS, '/', $s), 'name' => JFile::getName($f));
         }
     } else {
         foreach ($list as $filename) {
             $f = new JObject();
             $f->name = JFile::getName($filename);
             $f->path = $filename;
             if (strlen(JPATH_ROOT)) {
                 $f->src = JString::str_ireplace(JPATH_ROOT . DS, JURI::root(), $f->path);
             } else {
                 $f->src = JURI::root() . $f->path;
             }
             $f->src = str_replace(DS, '/', $f->src);
             $f->size = LinkrHelper::parseSize($f->path);
             $f->ext = strtolower(JFile::getExt($f->name));
             switch ($f->ext) {
                 // Image
                 case 'bmp':
                 case 'gif':
                 case 'jpg':
                 case 'jpeg':
                 case 'odg':
                 case 'png':
                 case 'xcf':
                     list($w, $h) = @getimagesize($f->path);
                     $size = LinkrHelper::imageResize($w, $h, 32);
                     $f->width = $size['width'];
                     $f->height = $size['height'];
                     if (strlen(JPATH_ROOT)) {
                         $f->icon = JString::str_ireplace(JPATH_ROOT . DS, JURI::root(), $f->path);
                     } else {
                         $f->icon = JURI::root() . $f->path;
                     }
                     $f->icon = str_replace(DS, '/', $f->icon);
                     //$f->type	= JText::_( 'Image' );
                     $f->type = 'Image';
                     break;
                     // Other files
                 // Other files
                 default:
                     $f->type = strtoupper($f->ext);
                     $f->width = 24;
                     $f->height = 24;
                     $icon = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_media' . DS . 'images' . DS . 'mime-icon-32' . DS . $f->ext . '.png';
                     if (file_exists($icon)) {
                         $f->icon = JURI::root() . 'administrator/components/com_media/images/mime-icon-32/' . $f->ext . '.png';
                     } else {
                         $f->icon = LINKR_ASSETS . 'img/files.unkown-type.png';
                     }
                     break;
             }
             $files[] = $f;
         }
     }
     return $files;
 }