[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_installer/models/ -> manage.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Administrator
   4   * @subpackage    com_installer
   5   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   6   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  // No direct access.
  10  defined('_JEXEC') or die;
  11  
  12  // Import library dependencies
  13  require_once dirname(__FILE__) . '/extension.php';
  14  
  15  /**
  16   * Installer Manage Model
  17   *
  18   * @package        Joomla.Administrator
  19   * @subpackage    com_installer
  20   * @since        1.5
  21   */
  22  class InstallerModelManage extends InstallerModel
  23  {
  24      /**
  25       * Constructor.
  26       *
  27       * @param    array    An optional associative array of configuration settings.
  28       * @see        JController
  29       * @since    1.6
  30       */
  31  	public function __construct($config = array())
  32      {
  33          if (empty($config['filter_fields'])) {
  34              $config['filter_fields'] = array(
  35                  'name',
  36                  'client_id',
  37                  'status',
  38                  'type',
  39                  'folder',
  40                  'extension_id',
  41              );
  42          }
  43  
  44          parent::__construct($config);
  45      }
  46  
  47      /**
  48       * Method to auto-populate the model state.
  49       *
  50       * Note. Calling getState in this method will result in recursion.
  51       *
  52       * @since    1.6
  53       */
  54  	protected function populateState($ordering = null, $direction = null)
  55      {
  56          // Initialise variables.
  57          $app = JFactory::getApplication();
  58          $filters = JRequest::getVar('filters');
  59          if (empty($filters)) {
  60              $data = $app->getUserState($this->context.'.data');
  61              $filters = $data['filters'];
  62          }
  63          else {
  64              $app->setUserState($this->context.'.data', array('filters'=>$filters));
  65          }
  66  
  67          $this->setState('message', $app->getUserState('com_installer.message'));
  68          $this->setState('extension_message', $app->getUserState('com_installer.extension_message'));
  69          $app->setUserState('com_installer.message', '');
  70          $app->setUserState('com_installer.extension_message', '');
  71  
  72          $this->setState('filter.search', isset($filters['search']) ? $filters['search'] : '');
  73          $this->setState('filter.status', isset($filters['status']) ? $filters['status'] : '');
  74          $this->setState('filter.type', isset($filters['type']) ? $filters['type'] : '');
  75          $this->setState('filter.group', isset($filters['group']) ? $filters['group'] : '');
  76          $this->setState('filter.client_id', isset($filters['client_id']) ? $filters['client_id'] : '');
  77          parent::populateState('name', 'asc');
  78      }
  79  
  80      /**
  81       * Enable/Disable an extension.
  82       *
  83       * @return    boolean True on success
  84       * @since    1.5
  85       */
  86  	function publish(&$eid = array(), $value = 1)
  87      {
  88          // Initialise variables.
  89          $user = JFactory::getUser();
  90          if ($user->authorise('core.edit.state', 'com_installer')) {
  91              $result = true;
  92  
  93              /*
  94              * Ensure eid is an array of extension ids
  95              * TODO: If it isn't an array do we want to set an error and fail?
  96              */
  97              if (!is_array($eid)) {
  98                  $eid = array($eid);
  99              }
 100  
 101              // Get a database connector
 102              $db = JFactory::getDBO();
 103  
 104              // Get a table object for the extension type
 105              $table = JTable::getInstance('Extension');
 106              JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_templates/tables');
 107              // Enable the extension in the table and store it in the database
 108              foreach($eid as $i=>$id) {
 109                  $table->load($id);
 110                  if ($table->type == 'template') {
 111                      $style = JTable::getInstance('Style', 'TemplatesTable');
 112                      if ($style->load(array('template' => $table->element, 'client_id' => $table->client_id, 'home'=>1))) {
 113                          JError::raiseNotice(403, JText::_('COM_INSTALLER_ERROR_DISABLE_DEFAULT_TEMPLATE_NOT_PERMITTED'));
 114                          unset($eid[$i]);
 115                          continue;
 116                      }
 117                  }
 118                  if ($table->protected == 1) {
 119                      $result = false;
 120                      JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
 121                  } else {
 122                      $table->enabled = $value;
 123                  }
 124                  if (!$table->store()) {
 125                      $this->setError($table->getError());
 126                      $result = false;
 127                  }
 128              }
 129          } else {
 130              $result = false;
 131              JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
 132          }
 133          return $result;
 134      }
 135  
 136      /**
 137       * Refreshes the cached manifest information for an extension.
 138       *
 139       * @param    int        extension identifier (key in #__extensions)
 140       * @return    boolean    result of refresh
 141       * @since    1.6
 142       */
 143  	function refresh($eid)
 144      {
 145          if (!is_array($eid)) {
 146              $eid = array($eid => 0);
 147          }
 148  
 149          // Get a database connector
 150          $db = JFactory::getDBO();
 151  
 152          // Get an installer object for the extension type
 153          $installer = JInstaller::getInstance();
 154          $row = JTable::getInstance('extension');
 155          $result = 0;
 156  
 157          // Uninstall the chosen extensions
 158          foreach($eid as $id) {
 159              $result|= $installer->refreshManifestCache($id);
 160          }
 161          return $result;
 162      }
 163  
 164      /**
 165       * Remove (uninstall) an extension
 166       *
 167       * @param    array    An array of identifiers
 168       * @return    boolean    True on success
 169       * @since    1.5
 170       */
 171  	function remove($eid = array())
 172      {
 173          // Initialise variables.
 174          $user = JFactory::getUser();
 175          if ($user->authorise('core.delete', 'com_installer')) {
 176  
 177              // Initialise variables.
 178              $failed = array();
 179  
 180              /*
 181              * Ensure eid is an array of extension ids in the form id => client_id
 182              * TODO: If it isn't an array do we want to set an error and fail?
 183              */
 184              if (!is_array($eid)) {
 185                  $eid = array($eid => 0);
 186              }
 187  
 188              // Get a database connector
 189              $db = JFactory::getDBO();
 190  
 191              // Get an installer object for the extension type
 192              $installer = JInstaller::getInstance();
 193              $row = JTable::getInstance('extension');
 194  
 195              // Uninstall the chosen extensions
 196              foreach($eid as $id) {
 197                  $id = trim($id);
 198                  $row->load($id);
 199                  if ($row->type) {
 200                      $result = $installer->uninstall($row->type, $id);
 201  
 202                      // Build an array of extensions that failed to uninstall
 203                      if ($result === false) {
 204                          $failed[] = $id;
 205                      }
 206                  }
 207                  else {
 208                      $failed[] = $id;
 209                  }
 210              }
 211  
 212              $langstring = 'COM_INSTALLER_TYPE_TYPE_'. strtoupper($row->type);
 213              $rowtype = JText::_($langstring);
 214              if(strpos($rowtype, $langstring) !== false) {
 215                  $rowtype = $row->type;
 216              }
 217  
 218              if (count($failed)) {
 219  
 220                  // There was an error in uninstalling the package
 221                  $msg = JText::sprintf('COM_INSTALLER_UNINSTALL_ERROR', $rowtype);
 222                  $result = false;
 223              } else {
 224  
 225                  // Package uninstalled sucessfully
 226                  $msg = JText::sprintf('COM_INSTALLER_UNINSTALL_SUCCESS', $rowtype);
 227                  $result = true;
 228              }
 229              $app = JFactory::getApplication();
 230              $app->enqueueMessage($msg);
 231              $this->setState('action', 'remove');
 232              $this->setState('name', $installer->get('name'));
 233              $app->setUserState('com_installer.message', $installer->message);
 234              $app->setUserState('com_installer.extension_message', $installer->get('extension_message'));
 235              return $result;
 236          } else {
 237              $result = false;
 238              JError::raiseWarning(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
 239          }
 240      }
 241  
 242      /**
 243       * Method to get the database query
 244       *
 245       * @return    JDatabaseQuery    The database query
 246       * @since    1.6
 247       */
 248  	protected function getListQuery()
 249      {
 250          $status = $this->getState('filter.status');
 251          $type = $this->getState('filter.type');
 252          $client = $this->getState('filter.client_id');
 253          $group = $this->getState('filter.group');
 254          $query = JFactory::getDBO()->getQuery(true);
 255          $query->select('*');
 256          $query->select('2*protected+(1-protected)*enabled as status');
 257          $query->from('#__extensions');
 258          $query->where('state=0');
 259          if ($status != '') {
 260              if ($status == '2')
 261              {
 262                  $query->where('protected = 1');
 263              }
 264              else
 265              {
 266                  $query->where('protected = 0');
 267                  $query->where('enabled=' . intval($status));
 268              }
 269          }
 270          if ($type) {
 271              $query->where('type=' . $this->_db->Quote($type));
 272          }
 273          if ($client != '') {
 274              $query->where('client_id=' . intval($client));
 275          }
 276          if ($group != '' && in_array($type, array('plugin', 'library', ''))) {
 277  
 278              $query->where('folder=' . $this->_db->Quote($group == '*' ? '' : $group));
 279          }
 280  
 281          // Filter by search in id
 282          $search = $this->getState('filter.search');
 283          if (!empty($search) && stripos($search, 'id:') === 0) {
 284              $query->where('extension_id = '.(int) substr($search, 3));
 285          }
 286  
 287          return $query;
 288      }
 289  
 290      /**
 291       * Method to get the row form.
 292       *
 293       * @param    array    $data        Data for the form.
 294       * @param    boolean    $loadData    True if the form is to load its own data (default case), false if not.
 295       * @return    mixed    A JForm object on success, false on failure
 296       * @since    1.6
 297       */
 298  	public function getForm($data = array(), $loadData = true)
 299      {
 300          // Get the form.
 301          $app = JFactory::getApplication();
 302          JForm::addFormPath(JPATH_COMPONENT . '/models/forms');
 303          JForm::addFieldPath(JPATH_COMPONENT . '/models/fields');
 304          $form = JForm::getInstance('com_installer.manage', 'manage', array('load_data' => $loadData));
 305  
 306          // Check for an error.
 307          if ($form == false) {
 308              $this->setError($form->getMessage());
 309              return false;
 310          }
 311          // Check the session for previously entered form data.
 312          $data = $this->loadFormData();
 313  
 314          // Bind the form data if present.
 315          if (!empty($data)) {
 316              $form->bind($data);
 317          }
 318  
 319          return $form;
 320      }
 321  
 322      /**
 323       * Method to get the data that should be injected in the form.
 324       *
 325       * @return    mixed    The data for the form.
 326       * @since    1.6
 327       */
 328  	protected function loadFormData()
 329      {
 330          // Check the session for previously entered form data.
 331          $data = JFactory::getApplication()->getUserState('com_installer.manage.data', array());
 332  
 333          return $data;
 334      }
 335  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1