[ 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\AdministratorApplication; 14 use Joomla\CMS\Application\CMSApplication; 15 use Joomla\CMS\Client\ClientHelper; 16 use Joomla\CMS\Factory; 17 use Joomla\CMS\Form\Form; 18 use Joomla\CMS\Language\Text; 19 use Joomla\CMS\MVC\Controller\BaseController; 20 use Joomla\CMS\MVC\Factory\MVCFactoryInterface; 21 use Joomla\CMS\Router\Route; 22 use Joomla\CMS\Uri\Uri; 23 use Joomla\Component\Modules\Administrator\Controller\ModuleController; 24 25 // phpcs:disable PSR1.Files.SideEffects 26 \defined('_JEXEC') or die; 27 // phpcs:enable PSR1.Files.SideEffects 28 29 /** 30 * Component Controller 31 * 32 * @since 1.5 33 */ 34 class ModulesController extends BaseController 35 { 36 /** 37 * @param array $config An optional associative array of configuration settings. 38 * Recognized key values include 'name', 'default_task', 'model_path', and 39 * 'view_path' (this list is not meant to be comprehensive). 40 * @param MVCFactoryInterface|null $factory The factory. 41 * @param CMSApplication|null $app The Application for the dispatcher 42 * @param \Joomla\CMS\Input\Input|null $input The Input object for the request 43 * 44 * @since 1.6 45 */ 46 public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null) 47 { 48 parent::__construct($config, $factory, $app, $input); 49 50 $this->registerTask('apply', 'save'); 51 } 52 53 /** 54 * Method to handle cancel 55 * 56 * @return void 57 * 58 * @since 3.2 59 */ 60 public function cancel() 61 { 62 // Redirect back to home(base) page 63 $this->setRedirect(Uri::base()); 64 } 65 66 /** 67 * Method to save module editing. 68 * 69 * @return void 70 * 71 * @since 3.2 72 */ 73 public function save() 74 { 75 // Check for request forgeries. 76 $this->checkToken(); 77 78 // Check if the user is authorized to do this. 79 $user = $this->app->getIdentity(); 80 81 if (!$user->authorise('module.edit.frontend', 'com_modules.module.' . $this->input->get('id'))) { 82 $this->app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error'); 83 $this->app->redirect('index.php'); 84 } 85 86 // Set FTP credentials, if given. 87 ClientHelper::setCredentialsFromRequest('ftp'); 88 89 // Get submitted module id 90 $moduleId = '&id=' . $this->input->getInt('id'); 91 92 // Get returnUri 93 $returnUri = $this->input->post->get('return', null, 'base64'); 94 $redirect = ''; 95 96 if (!empty($returnUri)) { 97 $redirect = '&return=' . $returnUri; 98 } 99 100 /** @var AdministratorApplication $app */ 101 $app = Factory::getContainer()->get(AdministratorApplication::class); 102 103 // Reset Uri cache. 104 Uri::reset(); 105 106 // Get a document object 107 $document = $this->app->getDocument(); 108 109 // Load application dependencies. 110 $app->loadLanguage($this->app->getLanguage()); 111 $app->loadDocument($document); 112 $app->loadIdentity($user); 113 114 /** @var \Joomla\CMS\Dispatcher\ComponentDispatcher $dispatcher */ 115 $dispatcher = $app->bootComponent('com_modules')->getDispatcher($app); 116 117 /** @var ModuleController $controllerClass */ 118 $controllerClass = $dispatcher->getController('Module'); 119 120 // Set backend required params 121 $document->setType('json'); 122 123 // Execute backend controller 124 Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_modules/forms'); 125 $return = $controllerClass->save(); 126 127 // Reset params back after requesting from service 128 $document->setType('html'); 129 130 // Check the return value. 131 if ($return === false) { 132 // Save the data in the session. 133 $data = $this->input->post->get('jform', array(), 'array'); 134 135 $this->app->setUserState('com_config.modules.global.data', $data); 136 137 // Save failed, go back to the screen and display a notice. 138 $this->app->enqueueMessage(Text::_('JERROR_SAVE_FAILED')); 139 $this->app->redirect(Route::_('index.php?option=com_config&view=modules' . $moduleId . $redirect, false)); 140 } 141 142 // Redirect back to com_config display 143 $this->app->enqueueMessage(Text::_('COM_CONFIG_MODULES_SAVE_SUCCESS')); 144 145 // Set the redirect based on the task. 146 switch ($this->input->getCmd('task')) { 147 case 'apply': 148 $this->app->redirect(Route::_('index.php?option=com_config&view=modules' . $moduleId . $redirect, false)); 149 break; 150 151 case 'save': 152 default: 153 if (!empty($returnUri)) { 154 $redirect = base64_decode(urldecode($returnUri)); 155 156 // Don't redirect to an external URL. 157 if (!Uri::isInternal($redirect)) { 158 $redirect = Uri::base(); 159 } 160 } else { 161 $redirect = Uri::base(); 162 } 163 164 $this->setRedirect($redirect); 165 break; 166 } 167 } 168 }
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 |