29
0
mirror of https://github.com/joomla/joomla-cms.git synced 2024-05-28 16:01:28 +00:00
cms/components/com_config/src/Controller/ModulesController.php
George Wilson 032ea5d32d Joomla! 3.9.14
-----BEGIN PGP SIGNATURE-----
 
 iQHIBAABCgAyFiEEc8tLlhrb4aveTfJiRzuTXEnqGwgFAl34mZsUHGxlaXRobmVy
 QGl0cm9uaWMuYXQACgkQRzuTXEnqGwhOYAv+PgzapMJWw6Hic32RIfVrgQtbl4ac
 gybmYhBLFeSd4qrc1Ya8+Fsx79U1RR1elkrZGB1Rm5/vGvHqgFI9JzmpbK8wGTWF
 yU46g9rDM++2M08qQQxg8a2vx9VoN5yvccPi7oKEpU4gzRcEsPr9ih406dtPlSBZ
 w38jmD8J/DF0TcOuWS0dZjEF8NtbxGFGS6x9Wc4ZyYoPvfsqpjYXKnc70ExifSgc
 373B+vCkyhvHaW+aA4nZ50WuZHd3Rasf4VNB8JVz8hXMnnJf2zwthWaJtWiwjLeS
 u6x59xbsibQqZImlqdooSbIKROY3ZjVgNPCrYk4Iolm6MD8khIm4rvOmGP1Nrrr8
 fZrBuN42ynv5tLutuSwSJSPXvX+RGjgPSeLSGM8FXujtCoxNJrbP3qo7EdkIofAD
 BPwwRDUiorRFwT4JfMqyBHSrM4BUqOlFN+9wi7oVM/405LfmTx3K0zfh2YCPvRXt
 IybdpfYAld7RQb6KWONf42Q/+mEVE5/wJhRe
 =KyXf
 -----END PGP SIGNATURE-----

Merge tag '3.9.14' into 4.0-dev

Joomla! 3.9.14
2020-03-04 18:50:06 +00:00

178 lines
4.6 KiB
PHP

<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\Application\AdministratorApplication;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Client\ClientHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Modules\Administrator\Controller\ModuleController;
/**
* Component Controller
*
* @since 1.5
*/
class ModulesController extends BaseController
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param MVCFactoryInterface $factory The factory.
* @param CMSApplication $app The JApplication for the dispatcher
* @param \JInput $input Input
*
* @since 1.6
* @see \JControllerLegacy
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null)
{
parent::__construct($config, $factory, $app, $input);
// Apply, Save & New, and Save As copy should be standard on forms.
$this->registerTask('apply', 'save');
}
/**
* Method to handle cancel
*
* @return void
*
* @since 3.2
*/
public function cancel()
{
// Redirect back to home(base) page
$this->setRedirect(Uri::base());
}
/**
* Method to save module editing.
*
* @return void
*
* @since 3.2
*/
public function save()
{
// Check for request forgeries.
$this->checkToken();
// Check if the user is authorized to do this.
$user = $this->app->getIdentity();
if (!$user->authorise('module.edit.frontend', 'com_modules.module.' . $this->input->get('id'))
&& !$user->authorise('module.edit.frontend', 'com_modules'))
{
$this->app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'));
$this->app->redirect('index.php');
}
// Set FTP credentials, if given.
ClientHelper::setCredentialsFromRequest('ftp');
// Get submitted module id
$moduleId = '&id=' . $this->input->getInt('id');
// Get returnUri
$returnUri = $this->input->post->get('return', null, 'base64');
$redirect = '';
if (!empty($returnUri))
{
$redirect = '&return=' . $returnUri;
}
/** @var AdministratorApplication $app */
$app = Factory::getContainer()->get(AdministratorApplication::class);
// Reset Uri cache.
Uri::reset();
// Get a document object
$document = $this->app->getDocument();
// Load application dependencies.
$app->loadLanguage($this->app->getLanguage());
$app->loadDocument($document);
$app->loadIdentity($user);
/** @var \Joomla\CMS\Dispatcher\ComponentDispatcher $dispatcher */
$dispatcher = $app->bootComponent('com_modules')->getDispatcher($app);
/** @var ModuleController $controllerClass */
$controllerClass = $dispatcher->getController('Module');
// Set backend required params
$document->setType('json');
// Execute backend controller
Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_modules/forms');
$return = $controllerClass->save();
// Reset params back after requesting from service
$document->setType('html');
// Check the return value.
if ($return === false)
{
// Save the data in the session.
$data = $this->input->post->get('jform', array(), 'array');
$this->app->setUserState('com_config.modules.global.data', $data);
// Save failed, go back to the screen and display a notice.
$this->app->enqueueMessage(Text::_('JERROR_SAVE_FAILED'));
$this->app->redirect(Route::_('index.php?option=com_config&view=modules' . $moduleId . $redirect, false));
}
// Redirect back to com_config display
$this->app->enqueueMessage(Text::_('COM_CONFIG_MODULES_SAVE_SUCCESS'));
// Set the redirect based on the task.
switch ($this->input->getCmd('task'))
{
case 'apply':
$this->app->redirect(Route::_('index.php?option=com_config&view=modules' . $moduleId . $redirect, false));
break;
case 'save':
default:
if (!empty($returnUri))
{
$redirect = base64_decode(urldecode($returnUri));
// Don't redirect to an external URL.
if (!Uri::isInternal($redirect))
{
$redirect = Uri::base();
}
}
else
{
$redirect = Uri::base();
}
$this->setRedirect($redirect);
break;
}
}
}