[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage com_config 6 * 7 * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Config\Site\Controller; 12 13 use Joomla\CMS\Application\CMSApplication; 14 use Joomla\CMS\Client\ClientHelper; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\MVC\Controller\BaseController; 17 use Joomla\CMS\MVC\Factory\MVCFactoryInterface; 18 use Joomla\CMS\Router\Route; 19 use Joomla\CMS\Uri\Uri; 20 21 // phpcs:disable PSR1.Files.SideEffects 22 \defined('_JEXEC') or die; 23 // phpcs:enable PSR1.Files.SideEffects 24 25 /** 26 * Component Controller 27 * 28 * @since 1.5 29 */ 30 class TemplatesController extends BaseController 31 { 32 /** 33 * @param array $config An optional associative array of configuration settings. 34 * Recognized key values include 'name', 'default_task', 'model_path', and 35 * 'view_path' (this list is not meant to be comprehensive). 36 * @param MVCFactoryInterface|null $factory The factory. 37 * @param CMSApplication|null $app The Application for the dispatcher 38 * @param \Joomla\CMS\Input\Input|null $input The Input object for the request 39 * 40 * @since 1.6 41 */ 42 public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null) 43 { 44 parent::__construct($config, $factory, $app, $input); 45 46 // Apply, Save & New, and Save As copy should be standard on forms. 47 $this->registerTask('apply', 'save'); 48 } 49 50 /** 51 * Method to handle cancel 52 * 53 * @return boolean True on success. 54 * 55 * @since 3.2 56 */ 57 public function cancel() 58 { 59 // Redirect back to home(base) page 60 $this->setRedirect(Uri::base()); 61 } 62 63 /** 64 * Method to save global configuration. 65 * 66 * @return boolean True on success. 67 * 68 * @since 3.2 69 */ 70 public function save() 71 { 72 // Check for request forgeries. 73 $this->checkToken(); 74 75 // Check if the user is authorized to do this. 76 if (!$this->app->getIdentity()->authorise('core.admin')) { 77 $this->setRedirect('index.php', Text::_('JERROR_ALERTNOAUTHOR')); 78 79 return false; 80 } 81 82 // Set FTP credentials, if given. 83 ClientHelper::setCredentialsFromRequest('ftp'); 84 85 $app = $this->app; 86 87 // Access backend com_templates 88 $controllerClass = $app->bootComponent('com_templates') 89 ->getMVCFactory()->createController('Style', 'Administrator', [], $app, $app->input); 90 91 // Get a document object 92 $document = $app->getDocument(); 93 94 // Set backend required params 95 $document->setType('json'); 96 $this->input->set('id', $app->getTemplate(true)->id); 97 98 // Execute backend controller 99 $return = $controllerClass->save(); 100 101 // Reset params back after requesting from service 102 $document->setType('html'); 103 104 // Check the return value. 105 if ($return === false) { 106 // Save failed, go back to the screen and display a notice. 107 $this->setMessage(Text::sprintf('JERROR_SAVE_FAILED'), 'error'); 108 $this->setRedirect(Route::_('index.php?option=com_config&view=templates', false)); 109 110 return false; 111 } 112 113 // Set the success message. 114 $this->setMessage(Text::_('COM_CONFIG_SAVE_SUCCESS')); 115 116 // Redirect back to com_config display 117 $this->setRedirect(Route::_('index.php?option=com_config&view=templates', false)); 118 119 return true; 120 } 121 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |