Source for file manage.php

Documentation is available at manage.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. require_once __DIR__ . '/extension.php';
  13.  
  14. /**
  15.  * Installer Manage Model
  16.  *
  17.  * @package     Joomla.Administrator
  18.  * @subpackage  com_installer
  19.  * @since       1.5
  20.  */
  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('name''client_id''status''type''folder''extension_id',);
  35.         }
  36.  
  37.         parent::__construct($config);
  38.     }
  39.  
  40.     /**
  41.      * Method to auto-populate the model state.
  42.      *
  43.      * Note. Calling getState in this method will result in recursion.
  44.      *
  45.      * @param   string  $ordering   An optional ordering field.
  46.      * @param   string  $direction  An optional direction (asc|desc).
  47.      *
  48.      * @return  void 
  49.      *
  50.      * @since   1.6
  51.      */
  52.     protected function populateState($ordering null$direction null)
  53.     {
  54.         $app JFactory::getApplication();
  55.  
  56.         // Load the filter state.
  57.         $search $this->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  58.         $this->setState('filter.search'$search);
  59.  
  60.         $clientId $this->getUserStateFromRequest($this->context . '.filter.client_id''filter_client_id''');
  61.         $this->setState('filter.client_id'$clientId);
  62.  
  63.         $status $this->getUserStateFromRequest($this->context . '.filter.status''filter_status''');
  64.         $this->setState('filter.status'$status);
  65.  
  66.         $categoryId $this->getUserStateFromRequest($this->context . '.filter.type''filter_type''');
  67.         $this->setState('filter.type'$categoryId);
  68.  
  69.         $group $this->getUserStateFromRequest($this->context . '.filter.group''filter_group''');
  70.         $this->setState('filter.group'$group);
  71.  
  72.         $this->setState('message'$app->getUserState('com_installer.message'));
  73.         $this->setState('extension_message'$app->getUserState('com_installer.extension_message'));
  74.         $app->setUserState('com_installer.message''');
  75.         $app->setUserState('com_installer.extension_message''');
  76.  
  77.         parent::populateState('name''asc');
  78.     }
  79.  
  80.     /**
  81.      * Enable/Disable an extension.
  82.      *
  83.      * @param   array  &$eid   Extension ids to un/publish
  84.      * @param   int    $value  Publish value
  85.      *
  86.      * @return  boolean  True on success
  87.      *
  88.      * @since   1.5
  89.      */
  90.     public function publish(&$eid array()$value 1)
  91.     {
  92.         $user JFactory::getUser();
  93.         if ($user->authorise('core.edit.state''com_installer'))
  94.         {
  95.             $result true;
  96.  
  97.             /*
  98.              * Ensure eid is an array of extension ids
  99.              * TODO: If it isn't an array do we want to set an error and fail?
  100.              */
  101.             if (!is_array($eid))
  102.             {
  103.                 $eid array($eid);
  104.             }
  105.  
  106.             // Get a table object for the extension type
  107.             $table JTable::getInstance('Extension');
  108.             JTable::addIncludePath(JPATH_ADMINISTRATOR '/components/com_templates/tables');
  109.  
  110.             // Enable the extension in the table and store it in the database
  111.             foreach ($eid as $i => $id)
  112.             {
  113.                 $table->load($id);
  114.                 if ($table->type == 'template')
  115.                 {
  116.                     $style JTable::getInstance('Style''TemplatesTable');
  117.                     if ($style->load(array('template' => $table->element'client_id' => $table->client_id'home' => 1)))
  118.                     {
  119.                         JError::raiseNotice(403JText::_('COM_INSTALLER_ERROR_DISABLE_DEFAULT_TEMPLATE_NOT_PERMITTED'));
  120.                         unset($eid[$i]);
  121.                         continue;
  122.                     }
  123.                 }
  124.                 if ($table->protected == 1)
  125.                 {
  126.                     $result false;
  127.                     JError::raiseWarning(403JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
  128.                 }
  129.                 else
  130.                 {
  131.                     $table->enabled $value;
  132.                 }
  133.                 if (!$table->store())
  134.                 {
  135.                     $this->setError($table->getError());
  136.                     $result false;
  137.                 }
  138.             }
  139.         }
  140.         else
  141.         {
  142.             $result false;
  143.             JError::raiseWarning(403JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
  144.         }
  145.         return $result;
  146.     }
  147.  
  148.     /**
  149.      * Refreshes the cached manifest information for an extension.
  150.      *
  151.      * @param   int  $eid  extension identifier (key in #__extensions)
  152.      *
  153.      * @return  boolean  result of refresh
  154.      *
  155.      * @since   1.6
  156.      */
  157.     public function refresh($eid)
  158.     {
  159.         if (!is_array($eid))
  160.         {
  161.             $eid array($eid => 0);
  162.         }
  163.  
  164.         // Get an installer object for the extension type
  165.         $installer JInstaller::getInstance();
  166.         $result 0;
  167.  
  168.         // Uninstall the chosen extensions
  169.         foreach ($eid as $id)
  170.         {
  171.             $result |= $installer->refreshManifestCache($id);
  172.         }
  173.         return $result;
  174.     }
  175.  
  176.     /**
  177.      * Remove (uninstall) an extension
  178.      *
  179.      * @param   array  $eid  An array of identifiers
  180.      *
  181.      * @return  boolean  True on success
  182.      *
  183.      * @since   1.5
  184.      */
  185.     public function remove($eid array())
  186.     {
  187.         $user JFactory::getUser();
  188.  
  189.         if ($user->authorise('core.delete''com_installer'))
  190.         {
  191.             $failed array();
  192.  
  193.             /*
  194.              * Ensure eid is an array of extension ids in the form id => client_id
  195.              * TODO: If it isn't an array do we want to set an error and fail?
  196.              */
  197.             if (!is_array($eid))
  198.             {
  199.                 $eid array($eid => 0);
  200.             }
  201.  
  202.             // Get an installer object for the extension type
  203.             $installer JInstaller::getInstance();
  204.             $row JTable::getInstance('extension');
  205.  
  206.             // Uninstall the chosen extensions
  207.             $msgs array();
  208.             $result false;
  209.             foreach ($eid as $id)
  210.             {
  211.                 $id trim($id);
  212.                 $row->load($id);
  213.  
  214.                 $langstring 'COM_INSTALLER_TYPE_TYPE_' strtoupper($row->type);
  215.                 $rowtype JText::_($langstring);
  216.                 if (strpos($rowtype$langstring!== false)
  217.                 {
  218.                     $rowtype $row->type;
  219.                 }
  220.  
  221.                 if ($row->type && $row->type != 'language')
  222.                 {
  223.                     $result $installer->uninstall($row->type$id);
  224.  
  225.                     // Build an array of extensions that failed to uninstall
  226.                     if ($result === false)
  227.                     {
  228.                         // There was an error in uninstalling the package
  229.                         $msgs[JText::sprintf('COM_INSTALLER_UNINSTALL_ERROR'$rowtype);
  230.                         $result false;
  231.                     }
  232.                     else
  233.                     {
  234.                         // Package uninstalled sucessfully
  235.                         $msgs[JText::sprintf('COM_INSTALLER_UNINSTALL_SUCCESS'$rowtype);
  236.                         $result true;
  237.                     }
  238.                 }
  239.                 else
  240.                 {
  241.                     if ($row->type == 'language')
  242.                     {
  243.  
  244.                         // One should always uninstall a language package, not a single language
  245.                         $msgs[JText::_('COM_INSTALLER_UNINSTALL_LANGUAGE');
  246.                         $result false;
  247.                     }
  248.                     else
  249.                     {
  250.  
  251.                         // There was an error in uninstalling the package
  252.                         $msgs[JText::sprintf('COM_INSTALLER_UNINSTALL_ERROR'$rowtype);
  253.                         $result false;
  254.                     }
  255.                 }
  256.             }
  257.             $msg implode("<br />"$msgs);
  258.             $app JFactory::getApplication();
  259.             $app->enqueueMessage($msg);
  260.             $this->setState('action''remove');
  261.             $this->setState('name'$installer->get('name'));
  262.             $app->setUserState('com_installer.message'$installer->message);
  263.             $app->setUserState('com_installer.extension_message'$installer->get('extension_message'));
  264.             return $result;
  265.         }
  266.         else
  267.         {
  268.             JError::raiseWarning(403JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
  269.         }
  270.     }
  271.  
  272.     /**
  273.      * Method to get the database query
  274.      *
  275.      * @return  JDatabaseQuery  The database query
  276.      *
  277.      * @since   1.6
  278.      */
  279.     protected function getListQuery()
  280.     {
  281.         $status $this->getState('filter.status');
  282.         $type $this->getState('filter.type');
  283.         $client $this->getState('filter.client_id');
  284.         $group $this->getState('filter.group');
  285.         $query JFactory::getDbo()->getQuery(true)
  286.             ->select('*')
  287.             ->select('2*protected+(1-protected)*enabled as status')
  288.             ->from('#__extensions')
  289.             ->where('state=0');
  290.         if ($status != '')
  291.         {
  292.             if ($status == '2')
  293.             {
  294.                 $query->where('protected = 1');
  295.             }
  296.             elseif ($status == '3')
  297.             {
  298.                 $query->where('protected = 0');
  299.             }
  300.             else
  301.             {
  302.                 $query->where('protected = 0')
  303.                     ->where('enabled=' . (int) $status);
  304.             }
  305.         }
  306.         if ($type)
  307.         {
  308.             $query->where('type=' $this->_db->quote($type));
  309.         }
  310.         if ($client != '')
  311.         {
  312.             $query->where('client_id=' . (int) $client);
  313.         }
  314.         if ($group != '' && in_array($typearray('plugin''library''')))
  315.         {
  316.             $query->where('folder=' $this->_db->quote($group == '*' '' $group));
  317.         }
  318.  
  319.         // Filter by search in id
  320.         $search $this->getState('filter.search');
  321.         if (!empty($search&& stripos($search'id:'=== 0)
  322.         {
  323.             $query->where('extension_id = ' . (int) substr($search3));
  324.         }
  325.  
  326.         return $query;
  327.     }
  328. }

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