primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,141 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Controller;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Client\ClientHelper;
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;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Component Controller
*
* @since 1.5
*/
class ConfigController extends BaseController
{
/**
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task', 'model_path', and
* 'view_path' (this list is not meant to be comprehensive).
* @param ?MVCFactoryInterface $factory The factory.
* @param ?CMSApplication $app The JApplication for the dispatcher
* @param ?\Joomla\CMS\Input\Input $input The Input object for the request
*
* @since 1.6
*/
public function __construct($config = [], ?MVCFactoryInterface $factory = null, $app = null, $input = null)
{
parent::__construct($config, $factory, $app, $input);
$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 global configuration.
*
* @return boolean True on success.
*
* @since 3.2
*/
public function save()
{
// Check for request forgeries.
$this->checkToken();
// Check if the user is authorized to do this.
if (!$this->app->getIdentity()->authorise('core.admin')) {
$this->app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'));
$this->app->redirect('index.php');
}
// Set FTP credentials, if given.
ClientHelper::setCredentialsFromRequest('ftp');
$model = $this->getModel();
$form = $model->getForm();
$data = $this->app->getInput()->post->get('jform', [], 'array');
// Validate the posted data.
$return = $model->validate($form, $data);
// Check for validation errors.
if ($return === false) {
/*
* The validate method enqueued all messages for us, so we just need to redirect back.
*/
// Save the data in the session.
$this->app->setUserState('com_config.config.global.data', $data);
// Redirect back to the edit screen.
$this->app->redirect(Route::_('index.php?option=com_config&view=config', false));
}
// Attempt to save the configuration.
$data = $return;
// Access backend com_config
$saveClass = $this->factory->createController('Application', 'Administrator', [], $this->app, $this->input);
// Get a document object
$document = $this->app->getDocument();
// Set backend required params
$document->setType('json');
// Execute backend controller
$return = $saveClass->save();
// Reset params back after requesting from service
$document->setType('html');
// Check the return value.
if ($return === false) {
/*
* The save method enqueued all messages for us, so we just need to redirect back.
*/
// Save the data in the session.
$this->app->setUserState('com_config.config.global.data', $data);
// Save failed, go back to the screen and display a notice.
$this->app->redirect(Route::_('index.php?option=com_config&view=config', false));
}
// Redirect back to com_config display
$this->app->enqueueMessage(Text::_('COM_CONFIG_SAVE_SUCCESS'));
$this->app->redirect(Route::_('index.php?option=com_config&view=config', false));
return true;
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Controller;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Uri\Uri;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Component Controller
*
* @since 1.5
*/
class DisplayController extends BaseController
{
/**
* Method to handle cancel
*
* @return void
*
* @since 3.2
*/
public function cancel()
{
// Redirect back to home(base) page
$this->setRedirect(Uri::base());
}
}

View File

@ -0,0 +1,178 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Controller;
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;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Component Controller
*
* @since 1.5
*/
class ModulesController extends BaseController
{
/**
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task', 'model_path', and
* 'view_path' (this list is not meant to be comprehensive).
* @param ?MVCFactoryInterface $factory The factory.
* @param ?CMSApplication $app The Application for the dispatcher
* @param ?\Joomla\CMS\Input\Input $input The Input object for the request
*
* @since 1.6
*/
public function __construct($config = [], ?MVCFactoryInterface $factory = null, $app = null, $input = null)
{
parent::__construct($config, $factory, $app, $input);
$this->registerTask('apply', 'save');
}
/**
* Method to handle cancel
*
* @return void
*
* @since 3.2
*/
public function cancel()
{
// Redirect back to previous page
$this->setRedirect($this->getReturnUrl());
}
/**
* 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'))) {
$this->app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
$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');
$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'), '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:
$this->setRedirect($this->getReturnUrl());
break;
}
}
/**
* Method to get redirect URL after saving or cancel editing a module from frontend
*
* @return string
*
* @since 5.1.0
*/
private function getReturnUrl(): string
{
if ($return = $this->input->post->get('return', '', 'BASE64')) {
$return = base64_decode(urldecode($return));
// Only redirect to if it is an internal URL
if (Uri::isInternal($return)) {
return $return;
}
}
return Uri::base();
}
}

View File

@ -0,0 +1,121 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Controller;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Client\ClientHelper;
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;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Component Controller
*
* @since 1.5
*/
class TemplatesController extends BaseController
{
/**
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task', 'model_path', and
* 'view_path' (this list is not meant to be comprehensive).
* @param ?MVCFactoryInterface $factory The factory.
* @param ?CMSApplication $app The Application for the dispatcher
* @param ?\Joomla\CMS\Input\Input $input The Input object for the request
*
* @since 1.6
*/
public function __construct($config = [], ?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 global configuration.
*
* @return boolean True on success.
*
* @since 3.2
*/
public function save()
{
// Check for request forgeries.
$this->checkToken();
// Check if the user is authorized to do this.
if (!$this->app->getIdentity()->authorise('core.admin')) {
$this->setRedirect('index.php', Text::_('JERROR_ALERTNOAUTHOR'));
return false;
}
// Set FTP credentials, if given.
ClientHelper::setCredentialsFromRequest('ftp');
$app = $this->app;
// Access backend com_templates
$controllerClass = $app->bootComponent('com_templates')
->getMVCFactory()->createController('Style', 'Administrator', [], $app, $app->getInput());
// Get a document object
$document = $app->getDocument();
// Set backend required params
$document->setType('json');
$this->input->set('id', $app->getTemplate(true)->id);
// Execute backend controller
$return = $controllerClass->save();
// Reset params back after requesting from service
$document->setType('html');
// Check the return value.
if ($return === false) {
// Save failed, go back to the screen and display a notice.
$this->setMessage(Text::sprintf('JERROR_SAVE_FAILED'), 'error');
$this->setRedirect(Route::_('index.php?option=com_config&view=templates', false));
return false;
}
// Set the success message.
$this->setMessage(Text::_('COM_CONFIG_SAVE_SUCCESS'));
// Redirect back to com_config display
$this->setRedirect(Route::_('index.php?option=com_config&view=templates', false));
return true;
}
}

View File

@ -0,0 +1,52 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Dispatcher;
use Joomla\CMS\Access\Exception\NotAllowed;
use Joomla\CMS\Dispatcher\ComponentDispatcher;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* ComponentDispatcher class for com_config
*
* @since 4.0.0
*/
class Dispatcher extends ComponentDispatcher
{
/**
* Method to check component access permission
*
* @since 4.0.0
*
* @return void
*
* @throws \Exception|NotAllowed
*/
protected function checkAccess()
{
parent::checkAccess();
$task = $this->input->getCmd('task', 'display');
$view = $this->input->get('view');
$user = $this->app->getIdentity();
if (substr($task, 0, 8) === 'modules.' || $view === 'modules') {
if (!$user->authorise('module.edit.frontend', 'com_modules.module.' . $this->input->get('id'))) {
throw new NotAllowed($this->app->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403);
}
} elseif (!$user->authorise('core.admin')) {
throw new NotAllowed($this->app->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403);
}
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Model;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Model for the global configuration
*
* @since 3.2
*/
class ConfigModel extends FormModel
{
/**
* Method to get a form object.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return mixed A Form object on success, false on failure
*
* @since 3.2
*/
public function getForm($data = [], $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_config.config', 'config', ['control' => 'jform', 'load_data' => $loadData]);
if (empty($form)) {
return false;
}
return $form;
}
}

View File

@ -0,0 +1,271 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Model;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\FormModel as BaseForm;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Prototype form model.
*
* @see JForm
* @see \Joomla\CMS\Form\FormField
* @see \Joomla\CMS\Form\FormRule
* @since 3.2
*/
abstract class FormModel extends BaseForm
{
/**
* Array of form objects.
*
* @var array
* @since 3.2
*/
protected $forms = [];
/**
* Method to checkin a row.
*
* @param integer $pk The numeric id of the primary key.
*
* @return boolean False on failure or error, true otherwise.
*
* @since 3.2
* @throws \RuntimeException
*/
public function checkin($pk = null)
{
// Only attempt to check the row in if it exists.
if ($pk) {
$user = $this->getCurrentUser();
// Get an instance of the row to checkin.
$table = $this->getTable();
if (!$table->load($pk)) {
throw new \RuntimeException($table->getError());
}
// Check if this is the user has previously checked out the row.
if (!\is_null($table->checked_out) && $table->checked_out != $user->id && !$user->authorise('core.admin', 'com_checkin')) {
throw new \RuntimeException($table->getError());
}
// Attempt to check the row in.
if (!$table->checkIn($pk)) {
throw new \RuntimeException($table->getError());
}
}
return true;
}
/**
* Method to check-out a row for editing.
*
* @param integer $pk The numeric id of the primary key.
*
* @return boolean False on failure or error, true otherwise.
*
* @since 3.2
*/
public function checkout($pk = null)
{
// Only attempt to check the row in if it exists.
if ($pk) {
$user = $this->getCurrentUser();
// Get an instance of the row to checkout.
$table = $this->getTable();
if (!$table->load($pk)) {
throw new \RuntimeException($table->getError());
}
// Check if this is the user having previously checked out the row.
if (!\is_null($table->checked_out) && $table->checked_out != $user->id) {
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_CHECKOUT_USER_MISMATCH'));
}
// Attempt to check the row out.
if (!$table->checkOut($user->id, $pk)) {
throw new \RuntimeException($table->getError());
}
}
return true;
}
/**
* Method to get a form object.
*
* @param string $name The name of the form.
* @param string $source The form source. Can be XML string if file flag is set to false.
* @param array $options Optional array of options for the form creation.
* @param boolean $clear Optional argument to force load a new form.
* @param string $xpath An optional xpath to search for the fields.
*
* @return mixed JForm object on success, False on error.
*
* @see JForm
* @since 3.2
*/
protected function loadForm($name, $source = null, $options = [], $clear = false, $xpath = false)
{
// Handle the optional arguments.
$options['control'] = ArrayHelper::getValue($options, 'control', false);
// Create a signature hash.
$hash = sha1($source . serialize($options));
// Check if we can use a previously loaded form.
if (isset($this->_forms[$hash]) && !$clear) {
return $this->_forms[$hash];
}
// Register the paths for the form.
Form::addFormPath(JPATH_SITE . '/components/com_config/forms');
Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_config/forms');
try {
// Get the form.
$form = Form::getInstance($name, $source, $options, false, $xpath);
if (isset($options['load_data']) && $options['load_data']) {
// Get the data for the form.
$data = $this->loadFormData();
} else {
$data = [];
}
// Allow for additional modification of the form, and events to be triggered.
// We pass the data because plugins may require it.
$this->preprocessForm($form, $data);
// Load the data into the form after the plugins have operated.
$form->bind($data);
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage($e->getMessage());
return false;
}
// Store the form for later.
$this->_forms[$hash] = $form;
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return array The default data is an empty array.
*
* @since 3.2
*/
protected function loadFormData()
{
return [];
}
/**
* Method to allow derived classes to preprocess the data.
*
* @param string $context The context identifier.
* @param mixed &$data The data to be processed. It gets altered directly.
* @param string $group The name of the plugin group to import (defaults to "content").
*
* @return void
*
* @since 3.2
*/
protected function preprocessData($context, &$data, $group = 'content')
{
// Get the dispatcher and load the users plugins.
PluginHelper::importPlugin('content');
// Trigger the data preparation event.
Factory::getApplication()->triggerEvent('onContentPrepareData', [$context, $data]);
}
/**
* Method to allow derived classes to preprocess the form.
*
* @param Form $form A Form object.
* @param mixed $data The data expected for the form.
* @param string $group The name of the plugin group to import (defaults to "content").
*
* @return void
*
* @see \Joomla\CMS\Form\FormField
* @since 3.2
* @throws \Exception if there is an error in the form event.
*/
protected function preprocessForm(Form $form, $data, $group = 'content')
{
// Import the appropriate plugin group.
PluginHelper::importPlugin($group);
// Trigger the form preparation event.
Factory::getApplication()->triggerEvent('onContentPrepareForm', [$form, $data]);
}
/**
* Method to validate the form data.
*
* @param Form $form The form to validate against.
* @param array $data The data to validate.
* @param string $group The name of the field group to validate.
*
* @return mixed Array of filtered data if valid, false otherwise.
*
* @see \Joomla\CMS\Form\FormRule
* @see \Joomla\CMS\Filter\InputFilter
* @since 3.2
*/
public function validate($form, $data, $group = null)
{
// Filter and validate the form data.
$data = $form->filter($data);
$return = $form->validate($data, $group);
// Check for an error.
if ($return instanceof \Exception) {
Factory::getApplication()->enqueueMessage($return->getMessage(), 'error');
return false;
}
// Check the validation results.
if ($return === false) {
// Get the validation messages from the form.
foreach ($form->getErrors() as $message) {
if ($message instanceof \Exception) {
$message = $message->getMessage();
}
Factory::getApplication()->enqueueMessage($message, 'error');
}
return false;
}
return $data;
}
}

View File

@ -0,0 +1,253 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2014 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Model;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\Filesystem\Path;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Config Module model.
*
* @since 3.2
*/
class ModulesModel extends FormModel
{
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 3.2
*/
protected function populateState()
{
$app = Factory::getApplication();
// Load the User state.
$pk = $app->getInput()->getInt('id');
$this->setState('module.id', $pk);
}
/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return Form A Form object on success, false on failure
*
* @since 3.2
*/
public function getForm($data = [], $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_config.modules', 'modules', ['control' => 'jform', 'load_data' => $loadData]);
if (empty($form)) {
return false;
}
return $form;
}
/**
* Method to preprocess the form
*
* @param Form $form A form object.
* @param mixed $data The data expected for the form.
* @param string $group The name of the plugin group to import (defaults to "content").
*
* @return void
*
* @since 3.2
* @throws \Exception if there is an error loading the form.
*/
protected function preprocessForm(Form $form, $data, $group = 'content')
{
$lang = Factory::getLanguage();
$module = $this->getState()->get('module.name');
$basePath = JPATH_BASE;
$formFile = Path::clean($basePath . '/modules/' . $module . '/' . $module . '.xml');
// Load the core and/or local language file(s).
$lang->load($module, $basePath)
|| $lang->load($module, $basePath . '/modules/' . $module);
if (file_exists($formFile)) {
// Get the module form.
if (!$form->loadFile($formFile, false, '//config')) {
throw new \Exception(Text::_('JERROR_LOADFILE_FAILED'));
}
// Attempt to load the xml file.
if (!$xml = simplexml_load_file($formFile)) {
throw new \Exception(Text::_('JERROR_LOADFILE_FAILED'));
}
}
// Load the default advanced params
Form::addFormPath(JPATH_BASE . '/components/com_config/model/form');
$form->loadFile('modules_advanced', false);
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
/**
* Method to get list of module positions in current template
*
* @return array
*
* @since 3.2
*/
public function getPositions()
{
$lang = Factory::getLanguage();
$templateName = Factory::getApplication()->getTemplate();
// Load templateDetails.xml file
$path = Path::clean(JPATH_BASE . '/templates/' . $templateName . '/templateDetails.xml');
$currentTemplatePositions = [];
if (file_exists($path)) {
$xml = simplexml_load_file($path);
if (isset($xml->positions[0])) {
// Load language files
$lang->load('tpl_' . $templateName . '.sys', JPATH_BASE)
|| $lang->load('tpl_' . $templateName . '.sys', JPATH_BASE . '/templates/' . $templateName);
foreach ($xml->positions[0] as $position) {
$value = (string) $position;
$text = preg_replace('/[^a-zA-Z0-9_\-]/', '_', 'TPL_' . strtoupper($templateName) . '_POSITION_' . strtoupper($value));
// Construct list of positions
$currentTemplatePositions[] = self::createOption($value, Text::_($text) . ' [' . $value . ']');
}
}
}
$templateGroups = [];
// Add an empty value to be able to deselect a module position
$option = self::createOption();
$templateGroups[''] = self::createOptionGroup('', [$option]);
$templateGroups[$templateName] = self::createOptionGroup($templateName, $currentTemplatePositions);
// Add custom position to options
$customGroupText = Text::_('COM_MODULES_CUSTOM_POSITION');
$editPositions = true;
$customPositions = self::getActivePositions(0, $editPositions);
$templateGroups[$customGroupText] = self::createOptionGroup($customGroupText, $customPositions);
return $templateGroups;
}
/**
* Get a list of modules positions
*
* @param integer $clientId Client ID
* @param boolean $editPositions Allow to edit the positions
*
* @return array A list of positions
*
* @since 3.6.3
*/
public static function getActivePositions($clientId, $editPositions = false)
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('DISTINCT position')
->from($db->quoteName('#__modules'))
->where($db->quoteName('client_id') . ' = ' . (int) $clientId)
->order($db->quoteName('position'));
$db->setQuery($query);
try {
$positions = $db->loadColumn();
$positions = \is_array($positions) ? $positions : [];
} catch (\RuntimeException $e) {
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
return;
}
// Build the list
$options = [];
foreach ($positions as $position) {
if (!$position && !$editPositions) {
$options[] = HTMLHelper::_('select.option', 'none', ':: ' . Text::_('JNONE') . ' ::');
} else {
$options[] = HTMLHelper::_('select.option', $position, $position);
}
}
return $options;
}
/**
* Create and return a new Option
*
* @param string $value The option value [optional]
* @param string $text The option text [optional]
*
* @return object The option as an object (stdClass instance)
*
* @since 3.6.3
*/
private static function createOption($value = '', $text = '')
{
if (empty($text)) {
$text = $value;
}
$option = new \stdClass();
$option->value = $value;
$option->text = $text;
return $option;
}
/**
* Create and return a new Option Group
*
* @param string $label Value and label for group [optional]
* @param array $options Array of options to insert into group [optional]
*
* @return array Return the new group as an array
*
* @since 3.6.3
*/
private static function createOptionGroup($label = '', $options = [])
{
$group = [];
$group['value'] = $label;
$group['text'] = $label;
$group['items'] = $options;
return $group;
}
}

View File

@ -0,0 +1,123 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Model;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\Filesystem\Path;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Template style model.
*
* @since 3.2
*/
class TemplatesModel extends FormModel
{
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return null
*
* @since 3.2
*/
protected function populateState()
{
parent::populateState();
$this->setState('params', ComponentHelper::getParams('com_templates'));
}
/**
* Method to get the record form.
*
* @param array $data An optional array of data for the form to interrogate.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return Form|bool A Form object on success, false on failure
*
* @since 3.2
*/
public function getForm($data = [], $loadData = true)
{
try {
// Get the form.
$form = $this->loadForm('com_config.templates', 'templates', ['load_data' => $loadData]);
$data = [];
$this->preprocessForm($form, $data);
// Load the data into the form
$form->bind($data);
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage($e->getMessage());
return false;
}
if (empty($form)) {
return false;
}
return $form;
}
/**
* Method to preprocess the form
*
* @param Form $form A form object.
* @param mixed $data The data expected for the form.
* @param string $group Plugin group to load
*
* @return void
*
* @since 3.2
* @throws \Exception if there is an error in the form event.
*/
protected function preprocessForm(Form $form, $data, $group = 'content')
{
$lang = Factory::getLanguage();
$template = Factory::getApplication()->getTemplate();
// Load the core and/or local language file(s).
$lang->load('tpl_' . $template, JPATH_BASE)
|| $lang->load('tpl_' . $template, JPATH_BASE . '/templates/' . $template);
// Look for com_config.xml, which contains fields to display
$formFile = Path::clean(JPATH_BASE . '/templates/' . $template . '/com_config.xml');
if (!file_exists($formFile)) {
// If com_config.xml not found, fall back to templateDetails.xml
$formFile = Path::clean(JPATH_BASE . '/templates/' . $template . '/templateDetails.xml');
}
// Get the template form.
if (file_exists($formFile) && !$form->loadFile($formFile, false, '//config')) {
throw new \Exception(Text::_('JERROR_LOADFILE_FAILED'));
}
// Attempt to load the xml file.
if (!$xml = simplexml_load_file($formFile)) {
throw new \Exception(Text::_('JERROR_LOADFILE_FAILED'));
}
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\Service;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Component\Router\RouterView;
use Joomla\CMS\Component\Router\RouterViewConfiguration;
use Joomla\CMS\Component\Router\Rules\MenuRules;
use Joomla\CMS\Component\Router\Rules\NomenuRules;
use Joomla\CMS\Component\Router\Rules\StandardRules;
use Joomla\CMS\Menu\AbstractMenu;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Routing class from com_config
*
* @since 4.0.0
*/
class Router extends RouterView
{
/**
* Config Component router constructor
*
* @param SiteApplication $app The application object
* @param AbstractMenu $menu The menu object to work with
*/
public function __construct(SiteApplication $app, AbstractMenu $menu)
{
$this->registerView(new RouterViewConfiguration('config'));
$this->registerView(new RouterViewConfiguration('templates'));
parent::__construct($app, $menu);
$this->attachRule(new MenuRules($this));
$this->attachRule(new StandardRules($this));
$this->attachRule(new NomenuRules($this));
}
}

View File

@ -0,0 +1,135 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\View\Config;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\Component\Config\Administrator\Controller\RequestController;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View for the global configuration
*
* @since 3.2
*/
class HtmlView extends BaseHtmlView
{
/**
* The form object
*
* @var \Joomla\CMS\Form\Form
*
* @since 3.2
*/
public $form;
/**
* The data to be displayed in the form
*
* @var array
*
* @since 3.2
*/
public $data;
/**
* Is the current user a super administrator?
*
* @var boolean
*
* @since 3.2
*/
protected $userIsSuperAdmin;
/**
* The page class suffix
*
* @var string
*
* @since 4.0.0
*/
protected $pageclass_sfx = '';
/**
* The page parameters
*
* @var \Joomla\Registry\Registry|null
*
* @since 4.0.0
*/
protected $params = null;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 3.2
*/
public function display($tpl = null)
{
$user = $this->getCurrentUser();
$this->userIsSuperAdmin = $user->authorise('core.admin');
// Access backend com_config
$requestController = new RequestController();
// Execute backend controller
$serviceData = json_decode($requestController->getJson(), true);
$form = $this->getForm();
if ($form) {
$form->bind($serviceData);
}
$this->form = $form;
$this->data = $serviceData;
$this->_prepareDocument();
parent::display($tpl);
}
/**
* Prepares the document.
*
* @return void
*
* @since 4.0.0
*/
protected function _prepareDocument()
{
$params = Factory::getApplication()->getParams();
// Because the application sets a default page title, we need to get it
// right from the menu item itself
$this->setDocumentTitle($params->get('page_title', ''));
if ($params->get('menu-meta_description')) {
$this->getDocument()->setDescription($params->get('menu-meta_description'));
}
if ($params->get('robots')) {
$this->getDocument()->setMetaData('robots', $params->get('robots'));
}
// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
$this->params = &$params;
}
}

View File

@ -0,0 +1,100 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\View\Modules;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View to edit a module.
*
* @since 3.2
*/
class HtmlView extends BaseHtmlView
{
/**
* The module to be rendered
*
* @var array
*
* @since 3.2
*/
public $item;
/**
* The form object
*
* @var Form
*
* @since 3.2
*/
public $form;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 3.2
*/
public function display($tpl = null)
{
$lang = Factory::getApplication()->getLanguage();
$lang->load('', JPATH_ADMINISTRATOR, $lang->getTag());
$lang->load('com_modules', JPATH_ADMINISTRATOR, $lang->getTag());
// @todo Move and clean up
$module = (new \Joomla\Component\Modules\Administrator\Model\ModuleModel())->getItem(Factory::getApplication()->getInput()->getInt('id'));
$moduleData = $module->getProperties();
unset($moduleData['xml']);
/** @var \Joomla\Component\Config\Site\Model\ModulesModel $model */
$model = $this->getModel();
// Need to add module name to the state of model
$model->getState()->set('module.name', $moduleData['module']);
/** @var Form form */
$this->form = $this->get('form');
$this->positions = $this->get('positions');
$this->item = $moduleData;
if ($this->form) {
$this->form->bind($moduleData);
}
$this->_prepareDocument();
parent::display($tpl);
}
/**
* Prepares the document.
*
* @return void
*
* @since 4.0.0
*/
protected function _prepareDocument()
{
// There is no menu item for this so we have to use the title from the component
$this->setDocumentTitle(Text::_('COM_CONFIG_MODULES_SETTINGS_TITLE'));
}
}

View File

@ -0,0 +1,158 @@
<?php
/**
* @package Joomla.Site
* @subpackage com_config
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Config\Site\View\Templates;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\MVC\Factory\MVCFactory;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\Component\Config\Administrator\Controller\RequestController;
use Joomla\Component\Templates\Administrator\View\Style\JsonView;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View to edit a template style.
*
* @since 3.2
*/
class HtmlView extends BaseHtmlView
{
/**
* The data to be displayed in the form
*
* @var array
*
* @since 3.2
*/
public $item;
/**
* The form object
*
* @var Form
*
* @since 3.2
*/
public $form;
/**
* Is the current user a super administrator?
*
* @var boolean
*
* @since 3.2
*/
protected $userIsSuperAdmin;
/**
* The page class suffix
*
* @var string
*
* @since 4.0.0
*/
protected $pageclass_sfx = '';
/**
* The page parameters
*
* @var \Joomla\Registry\Registry|null
*
* @since 4.0.0
*/
protected $params = null;
/**
* Method to render the view.
*
* @return void
*
* @since 3.2
*/
public function display($tpl = null)
{
$user = $this->getCurrentUser();
$this->userIsSuperAdmin = $user->authorise('core.admin');
$app = Factory::getApplication();
$app->getInput()->set('id', $app->getTemplate(true)->id);
/** @var MVCFactory $factory */
$factory = $app->bootComponent('com_templates')->getMVCFactory();
/** @var JsonView $view */
$view = $factory->createView('Style', 'Administrator', 'Json');
$view->setModel($factory->createModel('Style', 'Administrator'), true);
$view->setLanguage($app->getLanguage());
$view->document = $this->getDocument();
$json = $view->display();
// Execute backend controller
$serviceData = json_decode($json, true);
// Access backend com_config
$requestController = new RequestController();
// Execute backend controller
$configData = json_decode($requestController->getJson(), true);
$data = array_merge($configData, $serviceData);
/** @var Form $form */
$form = $this->getForm();
if ($form) {
$form->bind($data);
}
$this->form = $form;
$this->data = $serviceData;
$this->_prepareDocument();
parent::display($tpl);
}
/**
* Prepares the document.
*
* @return void
*
* @since 4.0.0
*/
protected function _prepareDocument()
{
$params = Factory::getApplication()->getParams();
// Because the application sets a default page title, we need to get it
// right from the menu item itself
$this->setDocumentTitle($params->get('page_title', ''));
if ($params->get('menu-meta_description')) {
$this->getDocument()->setDescription($params->get('menu-meta_description'));
}
if ($params->get('robots')) {
$this->getDocument()->setMetaData('robots', $params->get('robots'));
}
// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
$this->params = &$params;
}
}