Source for file list.php

Documentation is available at list.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_media
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. jimport('joomla.filesystem.folder');
  13. jimport('joomla.filesystem.file');
  14.  
  15. /**
  16.  * Media Component List Model
  17.  *
  18.  * @package     Joomla.Administrator
  19.  * @subpackage  com_media
  20.  * @since       1.5
  21.  */
  22. class MediaModelList extends JModelLegacy
  23. {
  24.     public function getState($property null$default null)
  25.     {
  26.         static $set;
  27.  
  28.         if (!$set)
  29.         {
  30.             $input  JFactory::getApplication()->input;
  31.             $folder $input->get('folder''''path');
  32.             $this->setState('folder'$folder);
  33.  
  34.             $parent str_replace("\\""/"dirname($folder));
  35.             $parent ($parent == '.'null $parent;
  36.             $this->setState('parent'$parent);
  37.             $set true;
  38.         }
  39.  
  40.         return parent::getState($property$default);
  41.     }
  42.  
  43.     public function getImages()
  44.     {
  45.         $list $this->getList();
  46.  
  47.         return $list['images'];
  48.     }
  49.  
  50.     public function getFolders()
  51.     {
  52.         $list $this->getList();
  53.  
  54.         return $list['folders'];
  55.     }
  56.  
  57.     public function getDocuments()
  58.     {
  59.         $list $this->getList();
  60.  
  61.         return $list['docs'];
  62.     }
  63.  
  64.     /**
  65.      * Build imagelist
  66.      *
  67.      * @param string $listFolder The image directory to display
  68.      * @since 1.5
  69.      */
  70.     public function getList()
  71.     {
  72.         static $list;
  73.  
  74.         // Only process the list once per request
  75.         if (is_array($list))
  76.         {
  77.             return $list;
  78.         }
  79.  
  80.         // Get current path from request
  81.         $current $this->getState('folder');
  82.  
  83.         // If undefined, set to empty
  84.         if ($current == 'undefined')
  85.         {
  86.             $current '';
  87.         }
  88.  
  89.         if (strlen($current0)
  90.         {
  91.             $basePath COM_MEDIA_BASE.'/'.$current;
  92.         }
  93.         else
  94.         {
  95.             $basePath COM_MEDIA_BASE;
  96.         }
  97.  
  98.         $mediaBase str_replace(DIRECTORY_SEPARATOR'/'COM_MEDIA_BASE.'/');
  99.  
  100.         $images        array ();
  101.         $folders    array ();
  102.         $docs        array ();
  103.  
  104.         $fileList false;
  105.         $folderList false;
  106.         if (file_exists($basePath))
  107.         {
  108.             // Get the list of files and folders from the given folder
  109.             $fileList    JFolder::files($basePath);
  110.             $folderList JFolder::folders($basePath);
  111.         }
  112.  
  113.         // Iterate over the files if they exist
  114.         if ($fileList !== false)
  115.         {
  116.             foreach ($fileList as $file)
  117.             {
  118.                 if (is_file($basePath.'/'.$file&& substr($file01!= '.' && strtolower($file!== 'index.html')
  119.                 {
  120.                     $tmp new JObject;
  121.                     $tmp->name $file;
  122.                     $tmp->title $file;
  123.                     $tmp->path str_replace(DIRECTORY_SEPARATOR'/'JPath::clean($basePath '/' $file));
  124.                     $tmp->path_relative str_replace($mediaBase''$tmp->path);
  125.                     $tmp->size filesize($tmp->path);
  126.  
  127.                     $ext strtolower(JFile::getExt($file));
  128.                     switch ($ext)
  129.                     {
  130.                         // Image
  131.                         case 'jpg':
  132.                         case 'png':
  133.                         case 'gif':
  134.                         case 'xcf':
  135.                         case 'odg':
  136.                         case 'bmp':
  137.                         case 'jpeg':
  138.                         case 'ico':
  139.                             $info @getimagesize($tmp->path);
  140.                             $tmp->width        @$info[0];
  141.                             $tmp->height    @$info[1];
  142.                             $tmp->type        @$info[2];
  143.                             $tmp->mime        @$info['mime'];
  144.  
  145.                             if (($info[060|| ($info[160))
  146.                             {
  147.                                 $dimensions MediaHelper::imageResize($info[0]$info[1]60);
  148.                                 $tmp->width_60 $dimensions[0];
  149.                                 $tmp->height_60 $dimensions[1];
  150.                             }
  151.                             else {
  152.                                 $tmp->width_60 $tmp->width;
  153.                                 $tmp->height_60 $tmp->height;
  154.                             }
  155.  
  156.                             if (($info[016|| ($info[116))
  157.                             {
  158.                                 $dimensions MediaHelper::imageResize($info[0]$info[1]16);
  159.                                 $tmp->width_16 $dimensions[0];
  160.                                 $tmp->height_16 $dimensions[1];
  161.                             }
  162.                             else {
  163.                                 $tmp->width_16 $tmp->width;
  164.                                 $tmp->height_16 $tmp->height;
  165.                             }
  166.  
  167.                             $images[$tmp;
  168.                             break;
  169.  
  170.                         // Non-image document
  171.                         default:
  172.                             $tmp->icon_32 "media/mime-icon-32/".$ext.".png";
  173.                             $tmp->icon_16 "media/mime-icon-16/".$ext.".png";
  174.                             $docs[$tmp;
  175.                             break;
  176.                     }
  177.                 }
  178.             }
  179.         }
  180.  
  181.         // Iterate over the folders if they exist
  182.         if ($folderList !== false)
  183.         {
  184.             foreach ($folderList as $folder)
  185.             {
  186.                 $tmp new JObject;
  187.                 $tmp->name basename($folder);
  188.                 $tmp->path str_replace(DIRECTORY_SEPARATOR'/'JPath::clean($basePath '/' $folder));
  189.                 $tmp->path_relative str_replace($mediaBase''$tmp->path);
  190.                 $count MediaHelper::countFiles($tmp->path);
  191.                 $tmp->files $count[0];
  192.                 $tmp->folders $count[1];
  193.  
  194.                 $folders[$tmp;
  195.             }
  196.         }
  197.  
  198.         $list array('folders' => $folders'docs' => $docs'images' => $images);
  199.  
  200.         return $list;
  201.     }
  202. }

Documentation generated on Tue, 19 Nov 2013 15:07:15 +0100 by phpDocumentor 1.4.3