[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_config/controllers/ -> application.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Administrator
   4   * @subpackage    com_config
   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  defined('_JEXEC') or die;
  10  
  11  /**
  12   * @package        Joomla.Administrator
  13   * @subpackage    com_config
  14   */
  15  class ConfigControllerApplication extends JController
  16  {
  17      /**
  18       * Class Constructor
  19       *
  20       * @param    array    $config        An optional associative array of configuration settings.
  21       * @return    void
  22       * @since    1.5
  23       */
  24  	function __construct($config = array())
  25      {
  26          parent::__construct($config);
  27  
  28          // Map the apply task to the save method.
  29          $this->registerTask('apply', 'save');
  30      }
  31  
  32      /**
  33       * Method to save the configuration.
  34       *
  35       * @return    bool    True on success, false on failure.
  36       * @since    1.5
  37       */
  38  	public function save()
  39      {
  40          // Check for request forgeries.
  41          JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  42  
  43          // Check if the user is authorized to do this.
  44          if (!JFactory::getUser()->authorise('core.admin'))
  45          {
  46              JFactory::getApplication()->redirect('index.php', JText::_('JERROR_ALERTNOAUTHOR'));
  47              return;
  48          }
  49  
  50          // Set FTP credentials, if given.
  51          JClientHelper::setCredentialsFromRequest('ftp');
  52  
  53          // Initialise variables.
  54          $app    = JFactory::getApplication();
  55          $model    = $this->getModel('Application');
  56          $form    = $model->getForm();
  57          $data    = JRequest::getVar('jform', array(), 'post', 'array');
  58  
  59          // Validate the posted data.
  60          $return = $model->validate($form, $data);
  61  
  62          // Check for validation errors.
  63          if ($return === false)
  64          {
  65              // Get the validation messages.
  66              $errors    = $model->getErrors();
  67  
  68              // Push up to three validation messages out to the user.
  69              for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
  70                  if ($errors[$i] instanceof Exception) {
  71                      $app->enqueueMessage($errors[$i]->getMessage(), 'warning');
  72                  } else {
  73                      $app->enqueueMessage($errors[$i], 'warning');
  74                  }
  75              }
  76  
  77              // Save the data in the session.
  78              $app->setUserState('com_config.config.global.data', $data);
  79  
  80              // Redirect back to the edit screen.
  81              $this->setRedirect(JRoute::_('index.php?option=com_config&view=application', false));
  82              return false;
  83          }
  84  
  85          // Attempt to save the configuration.
  86          $data    = $return;
  87          $return = $model->save($data);
  88  
  89          // Check the return value.
  90          if ($return === false)
  91          {
  92              // Save the data in the session.
  93              $app->setUserState('com_config.config.global.data', $data);
  94  
  95              // Save failed, go back to the screen and display a notice.
  96              $message = JText::sprintf('JERROR_SAVE_FAILED', $model->getError());
  97              $this->setRedirect('index.php?option=com_config&view=application', $message, 'error');
  98              return false;
  99          }
 100  
 101          // Set the success message.
 102          $message = JText::_('COM_CONFIG_SAVE_SUCCESS');
 103  
 104          // Set the redirect based on the task.
 105          switch ($this->getTask())
 106          {
 107              case 'apply':
 108                  $this->setRedirect('index.php?option=com_config', $message);
 109                  break;
 110  
 111              case 'save':
 112              default:
 113                  $this->setRedirect('index.php', $message);
 114                  break;
 115          }
 116  
 117          return true;
 118      }
 119  
 120      /**
 121       * Cancel operation
 122       */
 123  	function cancel()
 124      {
 125          // Check if the user is authorized to do this.
 126          if (!JFactory::getUser()->authorise('core.admin', 'com_config'))
 127          {
 128              JFactory::getApplication()->redirect('index.php', JText::_('JERROR_ALERTNOAUTHOR'));
 129              return;
 130          }
 131  
 132          // Set FTP credentials, if given
 133          JClientHelper::setCredentialsFromRequest('ftp');
 134  
 135          // Clean the session data.
 136          $app = JFactory::getApplication();
 137          $app->setUserState('com_config.config.global.data',    null);
 138  
 139          $this->setRedirect('index.php');
 140      }
 141  
 142  	function refreshHelp()
 143      {
 144          jimport('joomla.filesystem.file');
 145  
 146          // Set FTP credentials, if given
 147          JClientHelper::setCredentialsFromRequest('ftp');
 148  
 149          if (($data = file_get_contents('http://help.joomla.org/helpsites.xml')) === false) {
 150              $this->setRedirect('index.php?option=com_config', JText::_('COM_CONFIG_ERROR_HELPREFRESH_FETCH'), 'error');
 151          } elseif (!JFile::write(JPATH_BASE . '/help/helpsites.xml', $data)) {
 152              $this->setRedirect('index.php?option=com_config', JText::_('COM_CONFIG_ERROR_HELPREFRESH_ERROR_STORE'), 'error');
 153          } else {
 154              $this->setRedirect('index.php?option=com_config', JText::_('COM_CONFIG_HELPREFRESH_SUCCESS'));
 155          }
 156      }
 157  
 158      /**
 159       * Method to remove the root property from the configuration.
 160       *
 161       * @return    bool    True on success, false on failure.
 162       * @since    1.5
 163       */
 164  	public function removeroot()
 165      {
 166          // Check for request forgeries.
 167          JSession::checkToken('get') or die('Invalid Token');
 168  
 169          // Check if the user is authorized to do this.
 170          if (!JFactory::getUser()->authorise('core.admin')) {
 171              JFactory::getApplication()->redirect('index.php', JText::_('JERROR_ALERTNOAUTHOR'));
 172              return;
 173          }
 174  
 175          // Initialise model.
 176          $model    = $this->getModel('Application');
 177  
 178          // Attempt to save the configuration and remove root.
 179          $return = $model->removeroot();
 180  
 181          // Check the return value.
 182          if ($return === false) {
 183              // Save failed, go back to the screen and display a notice.
 184              $this->setMessage(JText::sprintf('JERROR_SAVE_FAILED', $model->getError()), 'error');
 185              $this->setRedirect('index.php');
 186              return false;
 187          }
 188  
 189          // Set the success message.
 190          $message = JText::_('COM_CONFIG_SAVE_SUCCESS');
 191  
 192          // Set the redirect based on the task.
 193          $this->setRedirect('index.php', $message);
 194  
 195          return true;
 196      }
 197  }


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