Source for file save.php

Documentation is available at save.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_config
  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. defined('_JEXEC'or die;
  10.  
  11. /**
  12.  * Save Controller for global configuration
  13.  *
  14.  * @package     Joomla.Site
  15.  * @subpackage  com_config
  16.  * @since       3.2
  17. */
  18. {
  19.     /**
  20.      * Application object - Redeclared for proper typehinting
  21.      *
  22.      * @var    JApplicationCms 
  23.      * @since  3.2
  24.      */
  25.     protected $app;
  26.  
  27.     /**
  28.      * Method to save global configuration.
  29.      *
  30.      * @return  boolean  True on success.
  31.      *
  32.      * @since   3.2
  33.      */
  34.     public function execute()
  35.     {
  36.         // Check for request forgeries.
  37.         if (!JSession::checkToken())
  38.         {
  39.             $this->app->enqueueMessage(JText::_('JINVALID_TOKEN'));
  40.             $this->app->redirect('index.php');
  41.         }
  42.  
  43.         // Check if the user is authorized to do this.
  44.         if (!JFactory::getUser()->authorise('core.admin'))
  45.         {
  46.             $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'));
  47.             $this->app->redirect('index.php');
  48.         }
  49.  
  50.         // Set FTP credentials, if given.
  51.         JClientHelper::setCredentialsFromRequest('ftp');
  52.  
  53.         $model new ConfigModelConfig;
  54.         $form  $model->getForm();
  55.         $data  $this->input->post->get('jform'array()'array');
  56.  
  57.         // Validate the posted data.
  58.         $return $model->validate($form$data);
  59.  
  60.         // Check for validation errors.
  61.         if ($return === false)
  62.         {
  63.             /*
  64.              * The validate method enqueued all messages for us, so we just need to redirect back.
  65.              */
  66.  
  67.             // Save the data in the session.
  68.             $this->app->setUserState('com_config.config.global.data'$data);
  69.  
  70.             // Redirect back to the edit screen.
  71.             $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.config'false));
  72.         }
  73.  
  74.         // Attempt to save the configuration.
  75.         $data $return;
  76.  
  77.         // Access back-end com_config
  78.         JLoader::registerPrefix('Config'JPATH_ADMINISTRATOR '/components/com_config');
  79.         $saveClass new ConfigControllerApplicationSave;
  80.  
  81.         // Get a document object
  82.         $document JFactory::getDocument();
  83.  
  84.         // Set back-end required params
  85.         $document->setType('json');
  86.  
  87.         // Execute back-end controller
  88.         $return $saveClass->execute();
  89.  
  90.         // Reset params back after requesting from service
  91.         $document->setType('html');
  92.  
  93.         // Check the return value.
  94.         if ($return === false)
  95.         {
  96.             /*
  97.              * The save method enqueued all messages for us, so we just need to redirect back.
  98.              */
  99.  
  100.             // Save the data in the session.
  101.             $this->app->setUserState('com_config.config.global.data'$data);
  102.  
  103.             // Save failed, go back to the screen and display a notice.
  104.             $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.config'false));
  105.         }
  106.  
  107.         // Redirect back to com_config display
  108.         $this->app->enqueueMessage(JText::_('COM_CONFIG_SAVE_SUCCESS'));
  109.         $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.config'false));
  110.  
  111.         return true;
  112.     }
  113. }

Documentation generated on Tue, 19 Nov 2013 15:12:36 +0100 by phpDocumentor 1.4.3