Source for file extension.php

Documentation is available at extension.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_installer
  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.  * Extension Manager Abstract Extension Model
  14.  *
  15.  * @abstract
  16.  * @package     Joomla.Administrator
  17.  * @subpackage  com_installer
  18.  * @since       1.5
  19.  */
  20. class InstallerModel extends JModelList
  21. {
  22.     /**
  23.      * Constructor.
  24.      *
  25.      * @param   array  $config  An optional associative array of configuration settings.
  26.      *
  27.      * @see     JController
  28.      * @since   1.6
  29.      */
  30.     public function __construct($config = array())
  31.     {
  32.         if (empty($config['filter_fields']))
  33.         {
  34.             $config['filter_fields'] = array(
  35.                 'name',
  36.                 'client_id',
  37.                 'enabled',
  38.                 'type',
  39.                 'folder',
  40.                 'extension_id',
  41.             );
  42.         }
  43.  
  44.         parent::__construct($config);
  45.     }
  46.  
  47.     /**
  48.      * Returns an object list
  49.      *
  50.      * @param   string  $query       The query
  51.      * @param   int     $limitstart  Offset
  52.      * @param   int     $limit       The number of records
  53.      *
  54.      * @return  array 
  55.      */
  56.     protected function _getList($query, $limitstart = 0, $limit = 0)
  57.     {
  58.         $ordering    = $this->getState('list.ordering');
  59.         $search        = $this->getState('filter.search');
  60.  
  61.         // Replace slashes so preg_match will work
  62.         $search     = str_replace('/', ' ', $search);
  63.         $db            = $this->getDbo();
  64.  
  65.         if ($ordering == 'name' || (!empty($search) && stripos($search, 'id:') !== 0))
  66.         {
  67.             $db->setQuery($query);
  68.             $result = $db->loadObjectList();
  69.             $this->translate($result);
  70.             if (!empty($search))
  71.             {
  72.                 foreach ($result as $i => $item)
  73.                 {
  74.                     if (!preg_match("/$search/i", $item->name))
  75.                     {
  76.                         unset($result[$i]);
  77.                     }
  78.                 }
  79.             }
  80.             JArrayHelper::sortObjects($result, $this->getState('list.ordering'), $this->getState('list.direction') == 'desc' ? -1 : 1, true, true);
  81.             $total = count($result);
  82.             $this->cache[$this->getStoreId('getTotal')] = $total;
  83.             if ($total < $limitstart)
  84.             {
  85.                 $limitstart = 0;
  86.                 $this->setState('list.start', 0);
  87.             }
  88.             return array_slice($result, $limitstart, $limit ? $limit : null);
  89.         }
  90.         else
  91.         {
  92.             $query->order($db->quoteName($ordering) . ' ' . $this->getState('list.direction'));
  93.             $result = parent::_getList($query, $limitstart, $limit);
  94.             $this->translate($result);
  95.             return $result;
  96.         }
  97.     }
  98.  
  99.     /**
  100.      * Translate a list of objects
  101.      *
  102.      * @param   array  &$items  The array of objects
  103.      *
  104.      * @return  array The array of translated objects
  105.      */
  106.     private function translate(&$items)
  107.     {
  108.         $lang = JFactory::getLanguage();
  109.         foreach ($items as &$item)
  110.         {
  111.             if (strlen($item->manifest_cache))
  112.             {
  113.                 $data = json_decode($item->manifest_cache);
  114.                 if ($data)
  115.                 {
  116.                     foreach ($data as $key => $value)
  117.                     {
  118.                         if ($key == 'type')
  119.                         {
  120.                             // Ignore the type field
  121.                             continue;
  122.                         }
  123.                         $item->$key = $value;
  124.                     }
  125.                 }
  126.             }
  127.             $item->author_info = @$item->authorEmail . '<br />' . @$item->authorUrl;
  128.             $item->client = $item->client_id ? JText::_('JADMINISTRATOR') : JText::_('JSITE');
  129.             $path = $item->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE;
  130.             switch ($item->type)
  131.             {
  132.                 case 'component':
  133.                     $extension = $item->element;
  134.                     $source = JPATH_ADMINISTRATOR . '/components/' . $extension;
  135.                         $lang->load("$extension.sys", JPATH_ADMINISTRATOR, null, false, true)
  136.                     ||    $lang->load("$extension.sys", $source, null, false, true);
  137.                 break;
  138.                 case 'file':
  139.                     $extension = 'files_' . $item->element;
  140.                         $lang->load("$extension.sys", JPATH_SITE, null, false, true);
  141.                 break;
  142.                 case 'library':
  143.                     $extension = 'lib_' . $item->element;
  144.                         $lang->load("$extension.sys", JPATH_SITE, null, false, true);
  145.                 break;
  146.                 case 'module':
  147.                     $extension = $item->element;
  148.                     $source = $path . '/modules/' . $extension;
  149.                         $lang->load("$extension.sys", $path, null, false, true)
  150.                     ||    $lang->load("$extension.sys", $source, null, false, true);
  151.                 break;
  152.                 case 'package':
  153.                     $extension = $item->element;
  154.                         $lang->load("$extension.sys", JPATH_SITE, null, false, true);
  155.                 break;
  156.                 case 'plugin':
  157.                     $extension = 'plg_' . $item->folder . '_' . $item->element;
  158.                     $source = JPATH_PLUGINS . '/' . $item->folder . '/' . $item->element;
  159.                         $lang->load("$extension.sys", JPATH_ADMINISTRATOR, null, false, true)
  160.                     ||    $lang->load("$extension.sys", $source, null, false, true);
  161.                 break;
  162.                 case 'template':
  163.                     $extension = 'tpl_' . $item->element;
  164.                     $source = $path . '/templates/' . $item->element;
  165.                         $lang->load("$extension.sys", $path, null, false, true)
  166.                     ||    $lang->load("$extension.sys", $source, null, false, true);
  167.                 break;
  168.             }
  169.             if (!in_array($item->type, array('language', 'template', 'library')))
  170.             {
  171.                 $item->name = JText::_($item->name);
  172.             }
  173.             settype($item->description, 'string');
  174.             if (!in_array($item->type, array('language')))
  175.             {
  176.                 $item->description = JText::_($item->description);
  177.             }
  178.         }
  179.     }
  180. }

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