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.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Save Controller for global configuration
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_config
  17.  * @since       3.2
  18. */
  19. {
  20.     /**
  21.      * Application object - Redeclared for proper typehinting
  22.      *
  23.      * @var    JApplicationCms 
  24.      * @since  3.2
  25.      */
  26.     protected $app;
  27.  
  28.     /**
  29.      * Method to save global configuration.
  30.      *
  31.      * @return  mixed  Calls $app->redirect()
  32.      *
  33.      * @since   3.2
  34.      */
  35.     public function execute()
  36.     {
  37.         // Check for request forgeries.
  38.         if (!JSession::checkToken())
  39.         {
  40.             $this->app->enqueueMessage(JText::_('JINVALID_TOKEN'));
  41.             $this->app->redirect('index.php');
  42.         }
  43.  
  44.         // Set FTP credentials, if given.
  45.         JClientHelper::setCredentialsFromRequest('ftp');
  46.  
  47.         $model  new ConfigModelComponent;
  48.         $form   $model->getForm();
  49.         $data   $this->input->get('jform'array()'array');
  50.         $id     $this->input->getInt('id');
  51.         $option $this->input->get('component');
  52.  
  53.         // Check if the user is authorized to do this.
  54.         if (!JFactory::getUser()->authorise('core.admin'$option))
  55.         {
  56.             $this->app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'));
  57.             $this->app->redirect('index.php');
  58.         }
  59.  
  60.         $returnUri $this->input->post->get('return'null'base64');
  61.  
  62.         if (!empty($returnUri))
  63.         {
  64.             $redirect '&return=' urlencode($returnUri);
  65.         }
  66.  
  67.         // Validate the posted data.
  68.         $return $model->validate($form$data);
  69.  
  70.         // Check for validation errors.
  71.         if ($return === false)
  72.         {
  73.             /*
  74.              * The validate method enqueued all messages for us, so we just need to redirect back.
  75.              */
  76.  
  77.             // Save the data in the session.
  78.             $this->app->setUserState('com_config.config.global.data'$data);
  79.  
  80.             // Redirect back to the edit screen.
  81.             $this->app->redirect(JRoute::_('index.php?option=com_config&view=component&component=' $option $redirectfalse));
  82.         }
  83.  
  84.         // Attempt to save the configuration.
  85.         $data array(
  86.             'params' => $return,
  87.             'id'     => $id,
  88.             'option' => $option
  89.         );
  90.  
  91.         try
  92.         {
  93.             $model->save($data);
  94.         }
  95.         catch (RuntimeException $e)
  96.         {
  97.             // Save the data in the session.
  98.             $this->app->setUserState('com_config.config.global.data'$data);
  99.  
  100.             // Save failed, go back to the screen and display a notice.
  101.             $this->app->enqueueMessage(JText::sprintf('JERROR_SAVE_FAILED'$e->getMessage())'error');
  102.             $this->app->redirect(JRoute::_('index.php?option=com_config&view=component&component=' $option $redirectfalse));
  103.         }
  104.  
  105.         // Set the redirect based on the task.
  106.         switch ($this->options[3])
  107.         {
  108.             case 'apply':
  109.                 $this->app->enqueueMessage(JText::_('COM_CONFIG_SAVE_SUCCESS'));
  110.                 $this->app->redirect(JRoute::_('index.php?option=com_config&view=component&component=' $option $redirectfalse));
  111.  
  112.                 break;
  113.  
  114.             case 'save':
  115.             default:
  116.                 $redirect 'index.php?option=' $option;
  117.  
  118.                 if (!empty($returnUri))
  119.                 {
  120.                     $redirect base64_decode($returnUri);
  121.                 }
  122.  
  123.                 $this->app->redirect(JRoute::_($redirectfalse));
  124.  
  125.                 break;
  126.         }
  127.  
  128.         return true;
  129.     }
  130. }

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