Source for file save.php

Documentation is available at save.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  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.Administrator
  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  mixed  Calls $app->redirect() for all cases except JSON
  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 ConfigModelApplication;
  54.         $data  $this->input->post->get('jform'array()'array');
  55.  
  56.         // Complete data array if needed
  57.         $oldData $model->getData();
  58.         $data array_replace($oldData$data);
  59.  
  60.         // Get request type
  61.         $saveFormat JFactory::getDocument()->getType();
  62.  
  63.         // Handle service requests
  64.         if ($saveFormat == 'json')
  65.         {
  66.             return $model->save($data);
  67.         }
  68.  
  69.         // Must load after serving service-requests
  70.         $form $model->getForm();
  71.  
  72.         // Validate the posted data.
  73.         $return $model->validate($form$data);
  74.  
  75.         // Check for validation errors.
  76.         if ($return === false)
  77.         {
  78.             /*
  79.              * The validate method enqueued all messages for us, so we just need to redirect back.
  80.              */
  81.  
  82.             // Save the data in the session.
  83.             $this->app->setUserState('com_config.config.global.data'$data);
  84.  
  85.             // Redirect back to the edit screen.
  86.             $this->app->redirect(JRoute::_('index.php?option=com_config&controller=config.display.application'false));
  87.         }
  88.  
  89.         // Attempt to save the configuration.
  90.         $data    $return;
  91.         $return $model->save($data);
  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.application'false));
  105.         }
  106.  
  107.         // Set the success message.
  108.         $this->app->enqueueMessage(JText::_('COM_CONFIG_SAVE_SUCCESS'));
  109.  
  110.         // Set the redirect based on the task.
  111.         switch ($this->options[3])
  112.         {
  113.             case 'apply':
  114.                 $this->app->redirect(JRoute::_('index.php?option=com_config'false));
  115.                 break;
  116.  
  117.             case 'save':
  118.             default:
  119.                 $this->app->redirect(JRoute::_('index.php'false));
  120.                 break;
  121.         }
  122.     }
  123. }

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