Source for file style.php

Documentation is available at style.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_templates
  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.  * Template style controller class.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_templates
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * @var        string    The prefix to use with controller messages.
  22.      * @since   1.6
  23.      */
  24.     protected $text_prefix = 'COM_TEMPLATES_STYLE';
  25.  
  26.     public function save($key null$urlVar null)
  27.     {
  28.         if (!JSession::checkToken())
  29.         {
  30.             JFactory::getApplication()->redirect('index.php'JText::_('JINVALID_TOKEN'));
  31.         }
  32.  
  33.         $document JFactory::getDocument();
  34.  
  35.         if ($document->getType(== 'json')
  36.         {
  37.  
  38.             $app   JFactory::getApplication();
  39.             $lang  JFactory::getLanguage();
  40.             $model $this->getModel();
  41.             $table $model->getTable();
  42.             $data  $this->input->post->get('params'array()'array');
  43.             $checkin property_exists($table'checked_out');
  44.             $context "$this->option.edit.$this->context";
  45.             $task $this->getTask();
  46.  
  47.             $item $model->getItem($app->getTemplate('template')->id);
  48.  
  49.             // Setting received params
  50.             $item->set('params'$data);
  51.  
  52.             $data $item->getProperties();
  53.             unset($data['xml']);
  54.  
  55.             $key $table->getKeyName();
  56.             $urlVar $key;
  57.  
  58.             $recordId $this->input->getInt($urlVar);
  59.  
  60.             // Access check.
  61.             if (!$this->allowSave($data$key))
  62.             {
  63.  
  64.                 $app->enqueueMessage(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED')'error');
  65.  
  66.                 return false;
  67.             }
  68.  
  69.             JForm::addFormPath(JPATH_ADMINISTRATOR '/components/com_templates/models/forms');
  70.  
  71.             // Validate the posted data.
  72.             // Sometimes the form needs some posted data, such as for plugins and modules.
  73.             $form $model->getForm($datafalse);
  74.  
  75.             if (!$form)
  76.             {
  77.                 $app->enqueueMessage($model->getError()'error');
  78.  
  79.                 return false;
  80.             }
  81.  
  82.             // Test whether the data is valid.
  83.             $validData $model->validate($form$data);
  84.  
  85.             if ($validData === false)
  86.             {
  87.                 // Get the validation messages.
  88.                 $errors $model->getErrors();
  89.  
  90.                 // Push up to three validation messages out to the user.
  91.                 for ($i 0$n count($errors)$i $n && $i 3$i++)
  92.                 {
  93.                     if ($errors[$iinstanceof Exception)
  94.                     {
  95.                         $app->enqueueMessage($errors[$i]->getMessage()'warning');
  96.                     }
  97.                     else
  98.                     {
  99.                         $app->enqueueMessage($errors[$i]'warning');
  100.                     }
  101.                 }
  102.  
  103.                 // Save the data in the session.
  104.                 $app->setUserState($context '.data'$data);
  105.  
  106.                 return false;
  107.             }
  108.  
  109.             if (!isset($validData['tags']))
  110.             {
  111.                 $validData['tags'null;
  112.             }
  113.  
  114.             // Attempt to save the data.
  115.             if (!$model->save($validData))
  116.             {
  117.                 // Save the data in the session.
  118.                 $app->setUserState($context '.data'$validData);
  119.  
  120.                 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED'$model->getError())'error');
  121.  
  122.                 return false;
  123.             }
  124.  
  125.             // Save succeeded, so check-in the record.
  126.             if ($checkin && $model->checkin($validData[$key]=== false)
  127.             {
  128.                 // Save the data in the session.
  129.                 $app->setUserState($context '.data'$validData);
  130.  
  131.                 // Check-in failed, so go back to the record and display a notice.
  132.                 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED'$model->getError())'error');
  133.  
  134.                 return false;
  135.             }
  136.  
  137.             // Redirect the user and adjust session state
  138.             // Set the record data in the session.
  139.             $recordId $model->getState($this->context . '.id');
  140.             $this->holdEditId($context$recordId);
  141.             $app->setUserState($context '.data'null);
  142.             $model->checkout($recordId);
  143.  
  144.             // Invoke the postSave method to allow for the child class to access the model.
  145.             $this->postSaveHook($model$validData);
  146.  
  147.             return true;
  148.  
  149.         }
  150.         else
  151.         {
  152.             parent::save($key$urlVar);
  153.         }
  154.     }
  155. }

Documentation generated on Tue, 19 Nov 2013 15:14:38 +0100 by phpDocumentor 1.4.3