Source for file manager.php

Documentation is available at manager.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. /**
  13.  * Media Component Manager Model
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_media
  17.  * @since       1.5
  18.  */
  19. {
  20.     public function getState($property = null, $default = null)
  21.     {
  22.         static $set;
  23.  
  24.         if (!$set)
  25.         {
  26.             $input = JFactory::getApplication()->input;
  27.  
  28.             $folder = $input->get('folder', '', 'path');
  29.             $this->setState('folder', $folder);
  30.  
  31.             $fieldid = $input->get('fieldid', '');
  32.             $this->setState('field.id', $fieldid);
  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.     /**
  44.      * Image Manager Popup
  45.      *
  46.      * @param string $listFolder The image directory to display
  47.      * @since 1.5
  48.      */
  49.     function getFolderList($base = null)
  50.     {
  51.         // Get some paths from the request
  52.         if (empty($base))
  53.         {
  54.             $base = COM_MEDIA_BASE;
  55.         }
  56.         //corrections for windows paths
  57.         $base = str_replace(DIRECTORY_SEPARATOR, '/', $base);
  58.         $com_media_base_uni = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE);
  59.  
  60.         // Get the list of folders
  61.         jimport('joomla.filesystem.folder');
  62.         $folders = JFolder::folders($base, '.', true, true);
  63.  
  64.         $document = JFactory::getDocument();
  65.         $document->setTitle(JText::_('COM_MEDIA_INSERT_IMAGE'));
  66.  
  67.         // Build the array of select options for the folder list
  68.         $options[] = JHtml::_('select.option', "", "/");
  69.  
  70.         foreach ($folders as $folder)
  71.         {
  72.             $folder        = str_replace($com_media_base_uni, "", str_replace(DIRECTORY_SEPARATOR, '/', $folder));
  73.             $value        = substr($folder, 1);
  74.             $text        = str_replace(DIRECTORY_SEPARATOR, "/", $folder);
  75.             $options[]    = JHtml::_('select.option', $value, $text);
  76.         }
  77.  
  78.         // Sort the folder list array
  79.         if (is_array($options))
  80.         {
  81.             sort($options);
  82.         }
  83.  
  84.         // Get asset and author id (use integer filter)
  85.         $input = JFactory::getApplication()->input;
  86.         $asset = $input->get('asset', 0, 'integer');
  87.  
  88.         // For new items the asset is a string. JAccess always checks type first
  89.         // so both string and integer are supported.
  90.         if ($asset == 0)
  91.         {
  92.             $asset = $input->get('asset', 0, 'string');
  93.         }
  94.  
  95.         $author = $input->get('author', 0, 'integer');
  96.  
  97.         // Create the drop-down folder select list
  98.         $list = JHtml::_('select.genericlist', $options, 'folderlist', 'class="inputbox" size="1" onchange="ImageManager.setFolder(this.options[this.selectedIndex].value, '.$asset.', '.$author.')" ', 'value', 'text', $base);
  99.  
  100.         return $list;
  101.     }
  102.  
  103.     function getFolderTree($base = null)
  104.     {
  105.         // Get some paths from the request
  106.         if (empty($base))
  107.         {
  108.             $base = COM_MEDIA_BASE;
  109.         }
  110.  
  111.         $mediaBase = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE.'/');
  112.  
  113.         // Get the list of folders
  114.         jimport('joomla.filesystem.folder');
  115.         $folders = JFolder::folders($base, '.', true, true);
  116.  
  117.         $tree = array();
  118.  
  119.         foreach ($folders as $folder)
  120.         {
  121.             $folder        = str_replace(DIRECTORY_SEPARATOR, '/', $folder);
  122.             $name        = substr($folder, strrpos($folder, '/') + 1);
  123.             $relative    = str_replace($mediaBase, '', $folder);
  124.             $absolute    = $folder;
  125.             $path        = explode('/', $relative);
  126.             $node        = (object) array('name' => $name, 'relative' => $relative, 'absolute' => $absolute);
  127.  
  128.             $tmp = &$tree;
  129.             for ($i = 0, $n = count($path); $i < $n; $i++)
  130.             {
  131.                 if (!isset($tmp['children']))
  132.                 {
  133.                     $tmp['children'] = array();
  134.                 }
  135.  
  136.                 if ($i == $n - 1)
  137.                 {
  138.                     // We need to place the node
  139.                     $tmp['children'][$relative] = array('data' => $node, 'children' => array());
  140.                     break;
  141.                 }
  142.  
  143.                 if (array_key_exists($key = implode('/', array_slice($path, 0, $i + 1)), $tmp['children']))
  144.                 {
  145.                     $tmp = &$tmp['children'][$key];
  146.                 }
  147.             }
  148.         }
  149.         $tree['data'] = (object) array('name' => JText::_('COM_MEDIA_MEDIA'), 'relative' => '', 'absolute' => $base);
  150.  
  151.         return $tree;
  152.     }
  153. }

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