[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/components/com_media/models/ -> manager.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: manager.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @subpackage    Content
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant to the
   9   * GNU General Public License, and as distributed it includes or is derivative
  10   * of works licensed under the GNU General Public License or other free or open
  11   * source software licenses. See COPYRIGHT.php for copyright notices and
  12   * details.
  13   */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport('joomla.application.component.model');
  19  
  20  /**
  21   * Weblinks Component Weblink Model
  22   *
  23   * @package        Joomla
  24   * @subpackage    Content
  25   * @since 1.5
  26   */
  27  class MediaModelManager extends JModel
  28  {
  29  
  30  	function getState($property = null)
  31      {
  32          static $set;
  33  
  34          if (!$set) {
  35              $folder = JRequest::getVar( 'folder', '', '', 'path' );
  36              $this->setState('folder', $folder);
  37  
  38              $parent = str_replace("\\", "/", dirname($folder));
  39              $parent = ($parent == '.') ? null : $parent;
  40              $this->setState('parent', $parent);
  41              $set = true;
  42          }
  43          return parent::getState($property);
  44      }
  45  
  46      /**
  47       * Image Manager Popup
  48       *
  49       * @param string $listFolder The image directory to display
  50       * @since 1.5
  51       */
  52  	function getFolderList($base = null)
  53      {
  54          global $mainframe;
  55  
  56          // Get some paths from the request
  57          if (empty($base)) {
  58              $base = COM_MEDIA_BASE;
  59          }
  60  
  61          // Get the list of folders
  62          jimport('joomla.filesystem.folder');
  63          $folders = JFolder::folders($base, '.', true, true);
  64  
  65          // Load appropriate language files
  66          $lang = & JFactory::getLanguage();
  67          $lang->load(JRequest::getCmd( 'option' ), JPATH_ADMINISTRATOR);
  68  
  69          $document =& JFactory::getDocument();
  70          $document->setTitle(JText::_('Insert Image'));
  71  
  72          // Build the array of select options for the folder list
  73          $options[] = JHTML::_('select.option', "","/");
  74          foreach ($folders as $folder) {
  75              $folder     = str_replace(COM_MEDIA_BASE, "", $folder);
  76              $value        = substr($folder, 1);
  77              $text         = str_replace(DS, "/", $folder);
  78              $options[]     = JHTML::_('select.option', $value, $text);
  79          }
  80  
  81          // Sort the folder list array
  82          if (is_array($options)) {
  83              sort($options);
  84          }
  85  
  86          // Create the drop-down folder select list
  87          $list = JHTML::_('select.genericlist',  $options, 'folderlist', "class=\"inputbox\" size=\"1\" onchange=\"ImageManager.setFolder(this.options[this.selectedIndex].value)\" ", 'value', 'text', $base);
  88          return $list;
  89      }
  90  
  91  	function getFolderTree($base = null)
  92      {
  93          // Get some paths from the request
  94          if (empty($base)) {
  95              $base = COM_MEDIA_BASE;
  96          }
  97          $mediaBase = str_replace(DS, '/', COM_MEDIA_BASE.'/');
  98  
  99          // Get the list of folders
 100          jimport('joomla.filesystem.folder');
 101          $folders = JFolder::folders($base, '.', true, true);
 102  
 103          $tree = array();
 104          foreach ($folders as $folder)
 105          {
 106              $folder        = str_replace(DS, '/', $folder);
 107              $name        = substr($folder, strrpos($folder, '/') + 1);
 108              $relative    = str_replace($mediaBase, '', $folder);
 109              $absolute    = $folder;
 110              $path        = explode('/', $relative);
 111              $node        = (object) array('name' => $name, 'relative' => $relative, 'absolute' => $absolute);
 112  
 113              $tmp = &$tree;
 114              for ($i=0,$n=count($path); $i<$n; $i++)
 115              {
 116                  if (!isset($tmp['children'])) {
 117                      $tmp['children'] = array();
 118                  }
 119                  if ($i == $n-1) {
 120                      // We need to place the node
 121                      $tmp['children'][$relative] = array('data' =>$node, 'children' => array());
 122                      break;
 123                  }
 124                  if (array_key_exists($key = implode('/', array_slice($path, 0, $i+1)), $tmp['children'])) {
 125                      $tmp = &$tmp['children'][$key];
 126                  }
 127              }
 128          }
 129          $tree['data'] = (object) array('name' => JText::_('Media'), 'relative' => '', 'absolute' => $base);
 130          return $tree;
 131      }
 132  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1