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,87 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\Controller;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Modules manager display controller.
*
* @since 1.6
*/
class DisplayController extends BaseController
{
/**
* The default view.
*
* @var string
* @since 1.6
*/
protected $default_view = 'modules';
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array|boolean $urlparams An array of safe URL parameters and their variable types.
* @see \Joomla\CMS\Filter\InputFilter::clean() for valid values.
*
* @return static|boolean This object to support chaining or false on failure.
*
* @since 1.5
*/
public function display($cachable = false, $urlparams = false)
{
$layout = $this->input->get('layout', 'edit');
$id = $this->input->getInt('id');
// Verify client
$clientId = $this->input->post->getInt('client_id');
if (!\is_null($clientId)) {
$uri = Uri::getInstance();
if ((int) $uri->getVar('client_id') !== (int) $clientId) {
$this->setRedirect(Route::_('index.php?option=com_modules&view=modules&client_id=' . $clientId, false));
return false;
}
}
// Check for edit form.
if ($layout == 'edit' && !$this->checkEditId('com_modules.edit.module', $id)) {
// Somehow the person just went to the form - we don't allow that.
if (!\count($this->app->getMessageQueue())) {
$this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
}
$this->setRedirect(Route::_('index.php?option=com_modules&view=modules&client_id=' . $this->input->getInt('client_id'), false));
return false;
}
// Check if we have a mod_menu module set to All languages or a mod_menu module for each admin language.
$factory = $this->app->bootComponent('menus')->getMVCFactory();
if ($langMissing = $factory->createModel('Menus', 'Administrator')->getMissingModuleLanguages()) {
$this->app->enqueueMessage(Text::sprintf('JMENU_MULTILANG_WARNING_MISSING_MODULES', implode(', ', $langMissing)), 'warning');
}
return parent::display();
}
}

View File

@ -0,0 +1,363 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @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\Modules\Administrator\Controller;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Uri\Uri;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Module controller class.
*
* @since 1.6
*/
class ModuleController extends FormController
{
/**
* Override parent add method.
*
* @return \Exception|void True if the record can be added, a \Exception object if not.
*
* @since 1.6
*/
public function add()
{
$app = $this->app;
// Get the result of the parent method. If an error, just return it.
$result = parent::add();
if ($result instanceof \Exception) {
return $result;
}
// Look for the Extension ID.
$extensionId = $this->input->get('eid', 0, 'int');
if (empty($extensionId)) {
$redirectUrl = 'index.php?option=' . $this->option . '&view=' . $this->view_item . '&layout=edit';
$this->setRedirect(Route::_($redirectUrl, false));
$app->enqueueMessage(Text::_('COM_MODULES_ERROR_INVALID_EXTENSION'), 'warning');
}
$app->setUserState('com_modules.add.module.extension_id', $extensionId);
$app->setUserState('com_modules.add.module.params', null);
// Parameters could be coming in for a new item, so let's set them.
$params = $this->input->get('params', [], 'array');
$app->setUserState('com_modules.add.module.params', $params);
}
/**
* Override parent cancel method to reset the add module state.
*
* @param string $key The name of the primary key of the URL variable.
*
* @return boolean True if access level checks pass, false otherwise.
*
* @since 1.6
*/
public function cancel($key = null)
{
$result = parent::cancel();
$this->app->setUserState('com_modules.add.module.extension_id', null);
$this->app->setUserState('com_modules.add.module.params', null);
if ($return = $this->input->get('return', '', 'BASE64')) {
$return = base64_decode($return);
// Don't redirect to an external URL.
if (!Uri::isInternal($return)) {
$return = Uri::base();
}
$this->app->redirect($return);
} elseif ($result && $this->input->get('layout') === 'modal') {
// When editing in modal then redirect to modalreturn layout
$id = $this->input->get('id');
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id)
. '&layout=modalreturn&from-task=cancel';
$this->setRedirect(Route::_($return, false));
}
return $result;
}
/**
* Override parent allowSave method.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*
* @since 1.6
*/
protected function allowSave($data, $key = 'id')
{
// Use custom position if selected
if (isset($data['custom_position'])) {
if (empty($data['position'])) {
$data['position'] = $data['custom_position'];
}
unset($data['custom_position']);
}
return parent::allowSave($data, $key);
}
/**
* Method override to check if you can edit an existing record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*
* @since 3.2
*/
protected function allowEdit($data = [], $key = 'id')
{
// Initialise variables.
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
// Zero record (id:0), return component edit permission by calling parent controller method
if (!$recordId) {
return parent::allowEdit($data, $key);
}
// Check edit on the record asset (explicit or inherited)
if ($this->app->getIdentity()->authorise('core.edit', 'com_modules.module.' . $recordId)) {
return true;
}
return false;
}
/**
* Method to run batch operations.
*
* @param string $model The model
*
* @return boolean True on success.
*
* @since 1.7
*/
public function batch($model = null)
{
$this->checkToken();
// Set the model
$model = $this->getModel('Module', 'Administrator', []);
// Preset the redirect
$redirectUrl = 'index.php?option=com_modules&view=modules' . $this->getRedirectToListAppend();
$this->setRedirect(Route::_($redirectUrl, false));
return parent::batch($model);
}
/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param BaseDatabaseModel $model The data model object.
* @param array $validData The validated data.
*
* @return void
*
* @since 1.6
*/
protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
{
$task = $this->getTask();
switch ($task) {
case 'save2new':
$this->app->setUserState('com_modules.add.module.extension_id', $model->getState('module.extension_id'));
break;
default:
if ($this->input->get('layout') === 'modal' && $this->task === 'save') {
// When editing in modal then redirect to modalreturn layout
$id = $model->getState('module.id', '');
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id)
. '&layout=modalreturn&from-task=save';
$this->setRedirect(Route::_($return, false));
}
$this->app->setUserState('com_modules.add.module.extension_id', null);
break;
}
$this->app->setUserState('com_modules.add.module.params', null);
}
/**
* Method to save a record.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key
*
* @return boolean True if successful, false otherwise.
*/
public function save($key = null, $urlVar = null)
{
$this->checkToken();
if ($this->app->getDocument()->getType() == 'json') {
$model = $this->getModel();
$data = $this->input->post->get('jform', [], 'array');
$item = $model->getItem($this->input->get('id'));
$properties = $item->getProperties();
if (isset($data['params'])) {
unset($properties['params']);
}
// Replace changed properties
$data = array_replace_recursive($properties, $data);
if (!empty($data['assigned'])) {
$data['assigned'] = array_map('abs', $data['assigned']);
}
// Add new data to input before process by parent save()
$this->input->post->set('jform', $data);
// Add path of forms directory
Form::addFormPath(JPATH_ADMINISTRATOR . '/components/com_modules/models/forms');
}
return parent::save($key, $urlVar);
}
/**
* Method to get the other modules in the same position
*
* @return void
*
* @since 3.6.3
*/
public function orderPosition()
{
$app = $this->app;
// Send json mime type.
$app->mimeType = 'application/json';
$app->setHeader('Content-Type', $app->mimeType . '; charset=' . $app->charSet);
$app->sendHeaders();
// Check if user token is valid.
if (!Session::checkToken('get')) {
$app->enqueueMessage(Text::_('JINVALID_TOKEN_NOTICE'), 'error');
echo new JsonResponse();
$app->close();
}
$clientId = $this->input->getValue('client_id');
$position = $this->input->getValue('position');
$moduleId = $this->input->getValue('module_id');
// Access check.
if (
!$this->app->getIdentity()->authorise('core.create', 'com_modules')
&& !$this->app->getIdentity()->authorise('core.edit.state', 'com_modules')
&& ($moduleId && !$this->app->getIdentity()->authorise('core.edit.state', 'com_modules.module.' . $moduleId))
) {
$app->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 'error');
echo new JsonResponse();
$app->close();
}
$model = $this->getModel('Modules', 'Administrator', ['ignore_request' => true]);
$model->setState('client_id', $clientId);
$model->setState('filter.position', $position);
$model->setState('list.ordering', 'a.ordering');
try {
$orders = $model->getItems();
} catch (\RuntimeException $e) {
$app->enqueueMessage($e->getMessage(), 'error');
return;
}
$orders2 = [];
if (\count($orders)) {
foreach ($orders as $order) {
if (!isset($orders2[$order->position])) {
$orders2[$order->position] = 0;
}
$orders2[$order->position]++;
$ord = $orders2[$order->position];
$title = Text::sprintf('COM_MODULES_OPTION_ORDER_POSITION', $ord, htmlspecialchars($order->title, ENT_QUOTES, 'UTF-8'));
$html[] = $order->position . ',' . $ord . ',' . $title;
}
} else {
$html[] = $position . ',' . 1 . ',' . Text::_('JNONE');
}
echo new JsonResponse($html);
$app->close();
}
/**
* Gets the URL arguments to append to an item redirect.
*
* @param integer $recordId The primary key id for the item.
* @param string $urlVar The name of the URL variable for the id.
*
* @return string The arguments to append to the redirect URL.
*
* @since 4.0.0
*/
protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
{
$append = parent::getRedirectToItemAppend($recordId);
$append .= '&client_id=' . $this->input->getInt('client_id');
return $append;
}
/**
* Gets the URL arguments to append to a list redirect.
*
* @return string The arguments to append to the redirect URL.
*
* @since 4.0.0
*/
protected function getRedirectToListAppend()
{
$append = parent::getRedirectToListAppend();
$append .= '&client_id=' . $this->input->getInt('client_id');
return $append;
}
}

View File

@ -0,0 +1,115 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @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\Modules\Administrator\Controller;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\AdminController;
use Joomla\CMS\Response\JsonResponse;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Modules list controller class.
*
* @since 1.6
*/
class ModulesController extends AdminController
{
/**
* Method to clone an existing module.
*
* @return void
*
* @since 1.6
*/
public function duplicate()
{
// Check for request forgeries
$this->checkToken();
$pks = (array) $this->input->post->get('cid', [], 'int');
// Remove zero values resulting from input filter
$pks = array_filter($pks);
try {
if (empty($pks)) {
throw new \Exception(Text::_('COM_MODULES_ERROR_NO_MODULES_SELECTED'));
}
$model = $this->getModel();
$model->duplicate($pks);
$this->setMessage(Text::plural('COM_MODULES_N_MODULES_DUPLICATED', \count($pks)));
} catch (\Exception $e) {
$this->app->enqueueMessage($e->getMessage(), 'warning');
}
$this->setRedirect('index.php?option=com_modules&view=modules' . $this->getRedirectToListAppend());
}
/**
* Method to get a model object, loading it if required.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return object The model.
*
* @since 1.6
*/
public function getModel($name = 'Module', $prefix = 'Administrator', $config = ['ignore_request' => true])
{
return parent::getModel($name, $prefix, $config);
}
/**
* Method to get the number of frontend modules
*
* @return void
*
* @since 4.0.0
*/
public function getQuickiconContent()
{
$model = $this->getModel('Modules');
$model->setState('filter.state', 1);
$model->setState('filter.client_id', 0);
$amount = (int) $model->getTotal();
$result = [];
$result['amount'] = $amount;
$result['sronly'] = Text::plural('COM_MODULES_N_QUICKICON_SRONLY', $amount);
$result['name'] = Text::plural('COM_MODULES_N_QUICKICON', $amount);
echo new JsonResponse($result);
}
/**
* Gets the URL arguments to append to a list redirect.
*
* @return string The arguments to append to the redirect URL.
*
* @since 4.0.0
*/
protected function getRedirectToListAppend()
{
$append = parent::getRedirectToListAppend();
$append .= '&client_id=' . $this->input->getInt('client_id');
return $append;
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\Extension;
use Joomla\CMS\Extension\BootableExtensionInterface;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
use Joomla\Component\Modules\Administrator\Service\HTML\Modules;
use Psr\Container\ContainerInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Component class for com_modules
*
* @since 4.0.0
*/
class ModulesComponent extends MVCComponent implements BootableExtensionInterface
{
use HTMLRegistryAwareTrait;
/**
* Booting the extension. This is the function to set up the environment of the extension like
* registering new class loaders, etc.
*
* If required, some initial set up can be done from services of the container, eg.
* registering HTML services.
*
* @param ContainerInterface $container The container
*
* @return void
*
* @since 4.0.0
*/
public function boot(ContainerInterface $container)
{
$this->getRegistry()->register('modules', new Modules());
}
}

View File

@ -0,0 +1,123 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\Field;
use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Modules\Administrator\Helper\ModulesHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Modules Module field.
*
* @since 3.4.2
*/
class ModulesModuleField extends ListField
{
/**
* The form field type.
*
* @var string
* @since 3.4.2
*/
protected $type = 'ModulesModule';
/**
* Client name.
*
* @var string
* @since 4.0.0
*/
protected $client;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 4.0.0
*/
public function __get($name)
{
switch ($name) {
case 'client':
return $this->$name;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 4.0.0
*/
public function __set($name, $value)
{
switch ($name) {
case 'client':
$this->$name = (string) $value;
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a Form object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 4.0.0
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true) {
$this->client = $this->element['client'] ? (string) $this->element['client'] : 'site';
}
return $result;
}
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 3.4.2
*/
public function getOptions()
{
$clientId = $this->client === 'administrator' ? 1 : 0;
$options = ModulesHelper::getModules($clientId);
return array_merge(parent::getOptions(), $options);
}
}

View File

@ -0,0 +1,123 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\Field;
use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Modules\Administrator\Helper\ModulesHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Modules Position field.
*
* @since 3.4.2
*/
class ModulesPositionField extends ListField
{
/**
* The form field type.
*
* @var string
* @since 3.4.2
*/
protected $type = 'ModulesPosition';
/**
* Client name.
*
* @var string
* @since 4.0.0
*/
protected $client;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 4.0.0
*/
public function __get($name)
{
switch ($name) {
case 'client':
return $this->$name;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 4.0.0
*/
public function __set($name, $value)
{
switch ($name) {
case 'client':
$this->$name = (string) $value;
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a Form object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 4.0.0
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true) {
$this->client = $this->element['client'] ? (string) $this->element['client'] : 'site';
}
return $result;
}
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 3.4.2
*/
public function getOptions()
{
$clientId = $this->client === 'administrator' ? 1 : 0;
$options = ModulesHelper::getPositions($clientId);
return array_merge(parent::getOptions(), $options);
}
}

View File

@ -0,0 +1,140 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\Field;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\HTML\HTMLHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Edit Modules Position field.
*
* @since 4.0.0
*/
class ModulesPositioneditField extends FormField
{
/**
* The form field type.
*
* @var string
* @since 4.0.0
*/
protected $type = 'ModulesPositionedit';
/**
* Name of the layout being used to render the field
*
* @var string
* @since 4.0.0
*/
protected $layout = 'joomla.form.field.modulespositionedit';
/**
* Client name.
*
* @var string
* @since 4.0.0
*/
protected $client;
/**
* Method to get certain otherwise inaccessible properties from the form field object.
*
* @param string $name The property name for which to get the value.
*
* @return mixed The property value or null.
*
* @since 4.0.0
*/
public function __get($name)
{
switch ($name) {
case 'client':
return $this->$name;
}
return parent::__get($name);
}
/**
* Method to set certain otherwise inaccessible properties of the form field object.
*
* @param string $name The property name for which to set the value.
* @param mixed $value The value of the property.
*
* @return void
*
* @since 4.0.0
*/
public function __set($name, $value)
{
switch ($name) {
case 'client':
$this->$name = (string) $value;
break;
default:
parent::__set($name, $value);
}
}
/**
* Method to attach a Form object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see FormField::setup()
* @since 4.0.0
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$result = parent::setup($element, $value, $group);
if ($result === true) {
$this->client = $this->element['client'] ? (string) $this->element['client'] : 'site';
}
return $result;
}
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 4.0.0
*/
protected function getInput()
{
$data = $this->getLayoutData();
$clientId = $this->client === 'administrator' ? 1 : 0;
$positions = HTMLHelper::_('modules.positions', $clientId, 1, $this->value);
$data['client'] = $clientId;
$data['positions'] = $positions;
$renderer = $this->getRenderer($this->layout);
$renderer->setComponent('com_modules');
$renderer->setClient(1);
return $renderer->render($data);
}
}

View File

@ -0,0 +1,312 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @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\Modules\Administrator\Helper;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\Database\ParameterType;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Modules component helper.
*
* @since 1.6
*/
abstract class ModulesHelper
{
/**
* Get a list of filter options for the state of a module.
*
* @return array An array of \JHtmlOption elements.
*/
public static function getStateOptions()
{
// Build the filter options.
$options = [];
$options[] = HTMLHelper::_('select.option', '1', Text::_('JPUBLISHED'));
$options[] = HTMLHelper::_('select.option', '0', Text::_('JUNPUBLISHED'));
$options[] = HTMLHelper::_('select.option', '-2', Text::_('JTRASHED'));
$options[] = HTMLHelper::_('select.option', '*', Text::_('JALL'));
return $options;
}
/**
* Get a list of filter options for the application clients.
*
* @return array An array of \JHtmlOption elements.
*/
public static function getClientOptions()
{
// Build the filter options.
$options = [];
$options[] = HTMLHelper::_('select.option', '0', Text::_('JSITE'));
$options[] = HTMLHelper::_('select.option', '1', Text::_('JADMINISTRATOR'));
return $options;
}
/**
* 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
*/
public static function getPositions($clientId, $editPositions = false)
{
$db = Factory::getDbo();
$clientId = (int) $clientId;
$query = $db->getQuery(true)
->select('DISTINCT ' . $db->quoteName('position'))
->from($db->quoteName('#__modules'))
->where($db->quoteName('client_id') . ' = :clientid')
->order($db->quoteName('position'))
->bind(':clientid', $clientId, ParameterType::INTEGER);
$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::_('COM_MODULES_NONE'));
} elseif (!$position) {
$options[] = HTMLHelper::_('select.option', '', Text::_('COM_MODULES_NONE'));
} else {
$options[] = HTMLHelper::_('select.option', $position, $position);
}
}
return $options;
}
/**
* Return a list of templates
*
* @param integer $clientId Client ID
* @param string $state State
* @param string $template Template name
*
* @return array List of templates
*/
public static function getTemplates($clientId = 0, $state = '', $template = '')
{
$db = Factory::getDbo();
$clientId = (int) $clientId;
// Get the database object and a new query object.
$query = $db->getQuery(true);
// Build the query.
$query->select($db->quoteName(['element', 'name', 'enabled']))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('client_id') . ' = :clientid')
->where($db->quoteName('type') . ' = ' . $db->quote('template'));
if ($state != '') {
$query->where($db->quoteName('enabled') . ' = :state')
->bind(':state', $state);
}
if ($template != '') {
$query->where($db->quoteName('element') . ' = :element')
->bind(':element', $template);
}
$query->bind(':clientid', $clientId, ParameterType::INTEGER);
// Set the query and load the templates.
$db->setQuery($query);
$templates = $db->loadObjectList('element');
return $templates;
}
/**
* Get a list of the unique modules installed in the client application.
*
* @param int $clientId The client id.
*
* @return array Array of unique modules
*/
public static function getModules($clientId)
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('element AS value, name AS text')
->from('#__extensions as e')
->where('e.client_id = ' . (int) $clientId)
->where('type = ' . $db->quote('module'))
->join('LEFT', '#__modules as m ON m.module=e.element AND m.client_id=e.client_id')
->where('m.module IS NOT NULL')
->group('element,name');
$db->setQuery($query);
$modules = $db->loadObjectList();
$lang = Factory::getLanguage();
foreach ($modules as $module) {
$extension = $module->value;
$path = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
$source = $path . "/modules/$extension";
$lang->load("$extension.sys", $path)
|| $lang->load("$extension.sys", $source);
$module->text = Text::_($module->text);
}
$modules = ArrayHelper::sortObjects($modules, 'text', 1, true, true);
return $modules;
}
/**
* Get a list of the assignment options for modules to menus.
*
* @param int $clientId The client id.
*
* @return array
*/
public static function getAssignmentOptions($clientId)
{
$options = [];
$options[] = HTMLHelper::_('select.option', '0', 'COM_MODULES_OPTION_MENU_ALL');
$options[] = HTMLHelper::_('select.option', '-', 'COM_MODULES_OPTION_MENU_NONE');
if ($clientId == 0) {
$options[] = HTMLHelper::_('select.option', '1', 'COM_MODULES_OPTION_MENU_INCLUDE');
$options[] = HTMLHelper::_('select.option', '-1', 'COM_MODULES_OPTION_MENU_EXCLUDE');
}
return $options;
}
/**
* Return a translated module position name
*
* @param integer $clientId Application client id 0: site | 1: admin
* @param string $template Template name
* @param string $position Position name
*
* @return string Return a translated position name
*
* @since 3.0
*/
public static function getTranslatedModulePosition($clientId, $template, $position)
{
// Template translation
$lang = Factory::getLanguage();
$path = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
$loaded = $lang->getPaths('tpl_' . $template . '.sys');
// Only load the template's language file if it hasn't been already
if (!$loaded) {
$lang->load('tpl_' . $template . '.sys', $path, null, false, false)
|| $lang->load('tpl_' . $template . '.sys', $path . '/templates/' . $template, null, false, false)
|| $lang->load('tpl_' . $template . '.sys', $path, $lang->getDefault(), false, false)
|| $lang->load('tpl_' . $template . '.sys', $path . '/templates/' . $template, $lang->getDefault(), false, false);
}
$langKey = strtoupper('TPL_' . $template . '_POSITION_' . $position);
$text = Text::_($langKey);
// Avoid untranslated strings
if (!self::isTranslatedText($langKey, $text)) {
// Modules component translation
$langKey = strtoupper('COM_MODULES_POSITION_' . $position);
$text = Text::_($langKey);
// Avoid untranslated strings
if (!self::isTranslatedText($langKey, $text)) {
// Try to humanize the position name
$text = ucfirst(preg_replace('/^' . $template . '\-/', '', $position));
$text = ucwords(str_replace(['-', '_'], ' ', $text));
}
}
return $text;
}
/**
* Check if the string was translated
*
* @param string $langKey Language file text key
* @param string $text The "translated" text to be checked
*
* @return boolean Return true for translated text
*
* @since 3.0
*/
public static function isTranslatedText($langKey, $text)
{
return $text !== $langKey;
}
/**
* 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.0
*/
public 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.0
*/
public static function createOptionGroup($label = '', $options = [])
{
$group = [];
$group['value'] = $label;
$group['text'] = $label;
$group['items'] = $options;
return $group;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,432 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\Model;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Modules Component Module Model
*
* @since 1.5
*/
class ModulesModel extends ListModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @see \JController
* @since 1.6
*/
public function __construct($config = [])
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'id', 'a.id',
'title', 'a.title',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'published', 'a.published', 'state',
'access', 'a.access',
'ag.title', 'access_level',
'ordering', 'a.ordering',
'module', 'a.module',
'language', 'a.language',
'l.title', 'language_title',
'publish_up', 'a.publish_up',
'publish_down', 'a.publish_down',
'client_id', 'a.client_id',
'position', 'a.position',
'pages',
'name', 'e.name',
'menuitem',
];
}
parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = 'a.position', $direction = 'asc')
{
$app = Factory::getApplication();
$layout = $app->getInput()->get('layout', '', 'cmd');
// Adjust the context to support modal layouts.
if ($layout) {
$this->context .= '.' . $layout;
}
// Make context client aware
$this->context .= '.' . $app->getInput()->get->getInt('client_id', 0);
// If in modal layout on the frontend, state and language are always forced.
if ($app->isClient('site') && $layout === 'modal') {
$this->setState('filter.language', 'current');
$this->setState('filter.state', 1);
}
// Special case for the client id.
if ($app->isClient('site') || $layout === 'modal') {
$this->setState('client_id', 0);
$clientId = 0;
} else {
$clientId = (int) $this->getUserStateFromRequest($this->context . '.client_id', 'client_id', 0, 'int');
$clientId = (!\in_array($clientId, [0, 1])) ? 0 : $clientId;
$this->setState('client_id', $clientId);
}
// Use a different filter file when client is administrator
if ($clientId == 1) {
$this->filterFormName = 'filter_modulesadmin';
}
// Load the parameters.
$params = ComponentHelper::getParams('com_modules');
$this->setState('params', $params);
// List state information.
parent::populateState($ordering, $direction);
}
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('client_id');
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.state');
$id .= ':' . $this->getState('filter.position');
$id .= ':' . $this->getState('filter.module');
$id .= ':' . $this->getState('filter.menuitem');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.language');
return parent::getStoreId($id);
}
/**
* Returns an object list
*
* @param QueryInterface $query The query
* @param int $limitstart Offset
* @param int $limit The number of records
*
* @return array
*/
protected function _getList($query, $limitstart = 0, $limit = 0)
{
$listOrder = $this->getState('list.ordering', 'a.position');
$listDirn = $this->getState('list.direction', 'asc');
$db = $this->getDatabase();
// If ordering by fields that need translate we need to sort the array of objects after translating them.
if (\in_array($listOrder, ['pages', 'name'])) {
// Fetch the results.
$db->setQuery($query);
$result = $db->loadObjectList();
// Translate the results.
$this->translate($result);
// Sort the array of translated objects.
$result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, true, true);
// Process pagination.
$total = \count($result);
$this->cache[$this->getStoreId('getTotal')] = $total;
if ($total < $limitstart) {
$limitstart = 0;
$this->setState('list.start', 0);
}
return \array_slice($result, $limitstart, $limit ?: null);
}
// If ordering by fields that doesn't need translate just order the query.
if ($listOrder === 'a.ordering') {
$query->order($db->quoteName('a.position') . ' ASC')
->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn));
} elseif ($listOrder === 'a.position') {
$query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn))
->order($db->quoteName('a.ordering') . ' ASC');
} else {
$query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn));
}
// Process pagination.
$result = parent::_getList($query, $limitstart, $limit);
// Translate the results.
$this->translate($result);
return $result;
}
/**
* Translate a list of objects
*
* @param array &$items The array of objects
*
* @return void
*/
protected function translate(&$items)
{
$lang = Factory::getLanguage();
$clientPath = $this->getState('client_id') ? JPATH_ADMINISTRATOR : JPATH_SITE;
foreach ($items as $item) {
$extension = $item->module;
$source = $clientPath . "/modules/$extension";
$lang->load("$extension.sys", $clientPath)
|| $lang->load("$extension.sys", $source);
$item->name = Text::_($item->name);
if (\is_null($item->pages)) {
$item->pages = Text::_('JNONE');
} elseif ($item->pages < 0) {
$item->pages = Text::_('COM_MODULES_ASSIGNED_VARIES_EXCEPT');
} elseif ($item->pages > 0) {
$item->pages = Text::_('COM_MODULES_ASSIGNED_VARIES_ONLY');
} else {
$item->pages = Text::_('JALL');
}
}
}
/**
* Build an SQL query to load the list data.
*
* @return QueryInterface
*/
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
// Select the required fields.
$query->select(
$this->getState(
'list.select',
'a.id, a.title, a.note, a.position, a.module, a.language,' .
'a.checked_out, a.checked_out_time, a.published AS published, e.enabled AS enabled, a.access, a.ordering, a.publish_up, a.publish_down'
)
);
// From modules table.
$query->from($db->quoteName('#__modules', 'a'));
// Join over the language
$query->select($db->quoteName('l.title', 'language_title'))
->select($db->quoteName('l.image', 'language_image'))
->join('LEFT', $db->quoteName('#__languages', 'l') . ' ON ' . $db->quoteName('l.lang_code') . ' = ' . $db->quoteName('a.language'));
// Join over the users for the checked out user.
$query->select($db->quoteName('uc.name', 'editor'))
->join('LEFT', $db->quoteName('#__users', 'uc') . ' ON ' . $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out'));
// Join over the asset groups.
$query->select($db->quoteName('ag.title', 'access_level'))
->join('LEFT', $db->quoteName('#__viewlevels', 'ag') . ' ON ' . $db->quoteName('ag.id') . ' = ' . $db->quoteName('a.access'));
// Join over the module menus
$query->select('MIN(mm.menuid) AS pages')
->join('LEFT', $db->quoteName('#__modules_menu', 'mm') . ' ON ' . $db->quoteName('mm.moduleid') . ' = ' . $db->quoteName('a.id'));
// Join over the extensions
$query->select($db->quoteName('e.name', 'name'))
->join('LEFT', $db->quoteName('#__extensions', 'e') . ' ON ' . $db->quoteName('e.element') . ' = ' . $db->quoteName('a.module'));
// Group (careful with PostgreSQL)
$query->group(
'a.id, a.title, a.note, a.position, a.module, a.language, a.checked_out, '
. 'a.checked_out_time, a.published, a.access, a.ordering, l.title, l.image, uc.name, ag.title, e.name, '
. 'l.lang_code, uc.id, ag.id, mm.moduleid, e.element, a.publish_up, a.publish_down, e.enabled'
);
// Filter by client.
$clientId = (int) $this->getState('client_id');
$query->where($db->quoteName('a.client_id') . ' = :aclientid')
->where($db->quoteName('e.client_id') . ' = :eclientid')
->bind(':aclientid', $clientId, ParameterType::INTEGER)
->bind(':eclientid', $clientId, ParameterType::INTEGER);
// Filter by current user access level.
$user = $this->getCurrentUser();
// Get the current user for authorisation checks
if ($user->authorise('core.admin') !== true) {
$groups = $user->getAuthorisedViewLevels();
$query->whereIn($db->quoteName('a.access'), $groups);
}
// Filter by access level.
if ($access = $this->getState('filter.access')) {
$access = (int) $access;
$query->where($db->quoteName('a.access') . ' = :access')
->bind(':access', $access, ParameterType::INTEGER);
}
// Filter by published state.
$state = $this->getState('filter.state', '');
if (is_numeric($state)) {
$state = (int) $state;
$query->where($db->quoteName('a.published') . ' = :state')
->bind(':state', $state, ParameterType::INTEGER);
} elseif ($state === '') {
$query->whereIn($db->quoteName('a.published'), [0, 1]);
}
// Filter by position.
if ($position = $this->getState('filter.position')) {
$position = ($position === 'none') ? '' : $position;
$query->where($db->quoteName('a.position') . ' = :position')
->bind(':position', $position);
}
// Filter by module.
if ($module = $this->getState('filter.module')) {
$query->where($db->quoteName('a.module') . ' = :module')
->bind(':module', $module);
}
// Filter by menuitem id (only for site client).
if ((int) $clientId === 0 && $menuItemId = $this->getState('filter.menuitem')) {
// If user selected the modules not assigned to any page (menu item).
if ((int) $menuItemId === -1) {
$query->having('MIN(' . $db->quoteName('mm.menuid') . ') IS NULL');
} else {
// If user selected the modules assigned to some particular page (menu item).
// Modules in "All" pages.
$subQuery1 = $db->getQuery(true);
$subQuery1->select('MIN(' . $db->quoteName('menuid') . ')')
->from($db->quoteName('#__modules_menu'))
->where($db->quoteName('moduleid') . ' = ' . $db->quoteName('a.id'));
// Modules in "Selected" pages that have the chosen menu item id.
$menuItemId = (int) $menuItemId;
$minusMenuItemId = $menuItemId * -1;
$subQuery2 = $db->getQuery(true);
$subQuery2->select($db->quoteName('moduleid'))
->from($db->quoteName('#__modules_menu'))
->where($db->quoteName('menuid') . ' = :menuitemid2');
// Modules in "All except selected" pages that doesn't have the chosen menu item id.
$subQuery3 = $db->getQuery(true);
$subQuery3->select($db->quoteName('moduleid'))
->from($db->quoteName('#__modules_menu'))
->where($db->quoteName('menuid') . ' = :menuitemid3');
// Filter by modules assigned to the selected menu item.
$query->where('(
(' . $subQuery1 . ') = 0
OR ((' . $subQuery1 . ') > 0 AND ' . $db->quoteName('a.id') . ' IN (' . $subQuery2 . '))
OR ((' . $subQuery1 . ') < 0 AND ' . $db->quoteName('a.id') . ' NOT IN (' . $subQuery3 . '))
)');
$query->bind(':menuitemid2', $menuItemId, ParameterType::INTEGER);
$query->bind(':menuitemid3', $minusMenuItemId, ParameterType::INTEGER);
}
}
// Filter by search in title or note or id:.
$search = $this->getState('filter.search');
if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$ids = (int) substr($search, 3);
$query->where($db->quoteName('a.id') . ' = :id')
->bind(':id', $ids, ParameterType::INTEGER);
} else {
$search = '%' . StringHelper::strtolower($search) . '%';
$query->extendWhere(
'AND',
[
'LOWER(' . $db->quoteName('a.title') . ') LIKE :title',
'LOWER(' . $db->quoteName('a.note') . ') LIKE :note',
],
'OR'
)
->bind(':title', $search)
->bind(':note', $search);
}
}
// Filter on the language.
if ($language = $this->getState('filter.language')) {
if ($language === 'current') {
$language = [Factory::getLanguage()->getTag(), '*'];
$query->whereIn($db->quoteName('a.language'), $language, ParameterType::STRING);
} else {
$query->where($db->quoteName('a.language') . ' = :language')
->bind(':language', $language);
}
}
return $query;
}
/**
* Manipulate the query to be used to evaluate if this is an Empty State to provide specific conditions for this extension.
*
* @return QueryInterface
*
* @since 4.0.0
*/
protected function getEmptyStateQuery()
{
$query = parent::getEmptyStateQuery();
$clientId = (int) $this->getState('client_id');
$query->where($this->getDatabase()->quoteName('a.client_id') . ' = :client_id')
->bind(':client_id', $clientId, ParameterType::INTEGER);
return $query;
}
}

View File

@ -0,0 +1,216 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\Model;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Component\Modules\Administrator\Helper\ModulesHelper;
use Joomla\Database\ParameterType;
use Joomla\Filesystem\Path;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Modules Component Positions Model
*
* @since 1.6
*/
class PositionsModel extends ListModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @see \JController
* @since 1.6
*/
public function __construct($config = [])
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'value',
'templates',
];
}
parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = 'ordering', $direction = 'asc')
{
// Special case for the client id.
$clientId = (int) $this->getUserStateFromRequest($this->context . '.client_id', 'client_id', 0, 'int');
$clientId = (!\in_array((int) $clientId, [0, 1])) ? 0 : (int) $clientId;
$this->setState('client_id', $clientId);
// Load the parameters.
$params = ComponentHelper::getParams('com_modules');
$this->setState('params', $params);
// List state information.
parent::populateState($ordering, $direction);
}
/**
* Method to get an array of data items.
*
* @return mixed An array of data items on success, false on failure.
*
* @since 1.6
*/
public function getItems()
{
if (!isset($this->items)) {
$lang = Factory::getLanguage();
$search = $this->getState('filter.search');
$state = $this->getState('filter.state');
$clientId = $this->getState('client_id');
$filter_template = $this->getState('filter.template');
$type = $this->getState('filter.type');
$ordering = $this->getState('list.ordering');
$direction = $this->getState('list.direction');
$limitstart = $this->getState('list.start');
$limit = $this->getState('list.limit');
$client = ApplicationHelper::getClientInfo($clientId);
if ($type != 'template') {
$clientId = (int) $clientId;
// Get the database object and a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select('DISTINCT ' . $db->quoteName('position', 'value'))
->from($db->quoteName('#__modules'))
->where($db->quoteName('client_id') . ' = :clientid')
->bind(':clientid', $clientId, ParameterType::INTEGER);
if ($search) {
$search = '%' . str_replace(' ', '%', trim($search)) . '%';
$query->where($db->quoteName('position') . ' LIKE :position')
->bind(':position', $search);
}
$db->setQuery($query);
try {
$positions = $db->loadObjectList('value');
} catch (\RuntimeException $e) {
$this->setError($e->getMessage());
return false;
}
foreach ($positions as $value => $position) {
$positions[$value] = [];
}
} else {
$positions = [];
}
// Load the positions from the installed templates.
foreach (ModulesHelper::getTemplates($clientId) as $template) {
$path = Path::clean($client->path . '/templates/' . $template->element . '/templateDetails.xml');
if (file_exists($path)) {
$xml = simplexml_load_file($path);
if (isset($xml->positions[0])) {
$lang->load('tpl_' . $template->element . '.sys', $client->path)
|| $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element);
foreach ($xml->positions[0] as $position) {
$value = (string) $position['value'];
$label = (string) $position;
if (!$value) {
$value = $label;
$label = preg_replace('/[^a-zA-Z0-9_\-]/', '_', 'TPL_' . $template->element . '_POSITION_' . $value);
$altlabel = preg_replace('/[^a-zA-Z0-9_\-]/', '_', 'COM_MODULES_POSITION_' . $value);
if (!$lang->hasKey($label) && $lang->hasKey($altlabel)) {
$label = $altlabel;
}
}
if ($type == 'user' || ($state != '' && $state != $template->enabled)) {
unset($positions[$value]);
} elseif (preg_match(\chr(1) . $search . \chr(1) . 'i', $value) && ($filter_template == '' || $filter_template == $template->element)) {
if (!isset($positions[$value])) {
$positions[$value] = [];
}
$positions[$value][$template->name] = $label;
}
}
}
}
}
$this->total = \count($positions);
if ($limitstart >= $this->total) {
$limitstart = $limitstart < $limit ? 0 : $limitstart - $limit;
$this->setState('list.start', $limitstart);
}
if ($ordering == 'value') {
if ($direction == 'asc') {
ksort($positions);
} else {
krsort($positions);
}
} else {
if ($direction == 'asc') {
asort($positions);
} else {
arsort($positions);
}
}
$this->items = \array_slice($positions, $limitstart, $limit ?: null);
}
return $this->items;
}
/**
* Method to get the total number of items.
*
* @return integer The total number of items.
*
* @since 1.6
*/
public function getTotal()
{
if (!isset($this->total)) {
$this->getItems();
}
return $this->total;
}
}

View File

@ -0,0 +1,164 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @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\Modules\Administrator\Model;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\Filesystem\Path;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Module model.
*
* @since 1.6
*/
class SelectModel extends ListModel
{
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
$app = Factory::getApplication();
// Load the filter state.
$clientId = $app->getUserStateFromRequest('com_modules.modules.client_id', 'client_id', 0);
$this->setState('client_id', (int) $clientId);
// Load the parameters.
$params = ComponentHelper::getParams('com_modules');
$this->setState('params', $params);
// Manually set limits to get all modules.
$this->setState('list.limit', 0);
$this->setState('list.start', 0);
$this->setState('list.ordering', 'a.name');
$this->setState('list.direction', 'ASC');
}
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('client_id');
return parent::getStoreId($id);
}
/**
* Build an SQL query to load the list data.
*
* @return QueryInterface
*/
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDatabase();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'a.extension_id, a.name, a.element AS module'
)
);
$query->from($db->quoteName('#__extensions', 'a'));
// Filter by module
$query->where($db->quoteName('a.type') . ' = ' . $db->quote('module'));
// Filter by client.
$clientId = (int) $this->getState('client_id');
$query->where($db->quoteName('a.client_id') . ' = :clientid')
->bind(':clientid', $clientId, ParameterType::INTEGER);
// Filter by enabled
$query->where($db->quoteName('a.enabled') . ' = 1');
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'a.ordering')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
return $query;
}
/**
* Method to get a list of items.
*
* @return mixed An array of objects on success, false on failure.
*/
public function getItems()
{
// Get the list of items from the database.
$items = parent::getItems();
$client = ApplicationHelper::getClientInfo($this->getState('client_id', 0));
$lang = Factory::getLanguage();
// Loop through the results to add the XML metadata,
// and load language support.
foreach ($items as &$item) {
$path = Path::clean($client->path . '/modules/' . $item->module . '/' . $item->module . '.xml');
if (file_exists($path)) {
$item->xml = simplexml_load_file($path);
} else {
$item->xml = null;
}
// 1.5 Format; Core files or language packs then
// 1.6 3PD Extension Support
$lang->load($item->module . '.sys', $client->path)
|| $lang->load($item->module . '.sys', $client->path . '/modules/' . $item->module);
$item->name = Text::_($item->name);
if (isset($item->xml) && $text = trim($item->xml->description)) {
$item->desc = Text::_($text);
} else {
$item->desc = Text::_('COM_MODULES_NODESCRIPTION');
}
}
$items = ArrayHelper::sortObjects($items, 'name', 1, true, true);
// @todo: Use the cached XML from the extensions table?
return $items;
}
}

View File

@ -0,0 +1,259 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\Service\HTML;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\Component\Modules\Administrator\Helper\ModulesHelper;
use Joomla\Component\Templates\Administrator\Helper\TemplatesHelper;
use Joomla\Database\ParameterType;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* HTMLHelper module helper class.
*
* @since 1.6
*/
class Modules
{
/**
* Builds an array of template options
*
* @param integer $clientId The client id.
* @param string $state The state of the template.
*
* @return array
*/
public function templates($clientId = 0, $state = '')
{
$options = [];
$templates = ModulesHelper::getTemplates($clientId, $state);
foreach ($templates as $template) {
$options[] = HTMLHelper::_('select.option', $template->element, $template->name);
}
return $options;
}
/**
* Builds an array of template type options
*
* @return array
*/
public function types()
{
$options = [];
$options[] = HTMLHelper::_('select.option', 'user', 'COM_MODULES_OPTION_POSITION_USER_DEFINED');
$options[] = HTMLHelper::_('select.option', 'template', 'COM_MODULES_OPTION_POSITION_TEMPLATE_DEFINED');
return $options;
}
/**
* Builds an array of template state options
*
* @return array
*/
public function templateStates()
{
$options = [];
$options[] = HTMLHelper::_('select.option', '1', 'JENABLED');
$options[] = HTMLHelper::_('select.option', '0', 'JDISABLED');
return $options;
}
/**
* Returns a published state on a grid
*
* @param integer $value The state value.
* @param integer $i The row index
* @param boolean $enabled An optional setting for access control on the action.
* @param string $checkbox An optional prefix for checkboxes.
*
* @return string The Html code
*
* @see HTMLHelperJGrid::state
* @since 1.7.1
*/
public function state($value, $i, $enabled = true, $checkbox = 'cb')
{
$states = [
1 => [
'unpublish',
'COM_MODULES_EXTENSION_PUBLISHED_ENABLED',
'COM_MODULES_HTML_UNPUBLISH_ENABLED',
'COM_MODULES_EXTENSION_PUBLISHED_ENABLED',
true,
'publish',
'publish',
],
0 => [
'publish',
'COM_MODULES_EXTENSION_UNPUBLISHED_ENABLED',
'COM_MODULES_HTML_PUBLISH_ENABLED',
'COM_MODULES_EXTENSION_UNPUBLISHED_ENABLED',
true,
'unpublish',
'unpublish',
],
-1 => [
'unpublish',
'COM_MODULES_EXTENSION_PUBLISHED_DISABLED',
'COM_MODULES_HTML_UNPUBLISH_DISABLED',
'COM_MODULES_EXTENSION_PUBLISHED_DISABLED',
true,
'warning',
'warning',
],
-2 => [
'publish',
'COM_MODULES_EXTENSION_UNPUBLISHED_DISABLED',
'COM_MODULES_HTML_PUBLISH_DISABLED',
'COM_MODULES_EXTENSION_UNPUBLISHED_DISABLED',
true,
'unpublish',
'unpublish',
],
];
return HTMLHelper::_('jgrid.state', $states, $value, $i, 'modules.', $enabled, true, $checkbox);
}
/**
* Display a batch widget for the module position selector.
*
* @param integer $clientId The client ID.
* @param integer $state The state of the module (enabled, unenabled, trashed).
* @param string $selectedPosition The currently selected position for the module.
*
* @return string The necessary positions for the widget.
*
* @since 2.5
*/
public function positions($clientId, $state = 1, $selectedPosition = '')
{
$templates = array_keys(ModulesHelper::getTemplates($clientId, $state));
$templateGroups = [];
// Add an empty value to be able to deselect a module position
$option = ModulesHelper::createOption('', Text::_('COM_MODULES_NONE'));
$templateGroups[''] = ModulesHelper::createOptionGroup('', [$option]);
// Add positions from templates
$isTemplatePosition = false;
foreach ($templates as $template) {
$options = [];
$positions = TemplatesHelper::getPositions($clientId, $template);
if (\is_array($positions)) {
foreach ($positions as $position) {
$text = ModulesHelper::getTranslatedModulePosition($clientId, $template, $position) . ' [' . $position . ']';
$options[] = ModulesHelper::createOption($position, $text);
if (!$isTemplatePosition && $selectedPosition === $position) {
$isTemplatePosition = true;
}
}
$options = ArrayHelper::sortObjects($options, 'text');
}
$templateGroups[$template] = ModulesHelper::createOptionGroup(ucfirst($template), $options);
}
// Add custom position to options
$customGroupText = Text::_('COM_MODULES_CUSTOM_POSITION');
$editPositions = true;
$customPositions = ModulesHelper::getPositions($clientId, $editPositions);
$app = Factory::getApplication();
$position = $app->getUserState('com_modules.modules.' . $clientId . '.filter.position');
if ($position) {
$customPositions[] = HTMLHelper::_('select.option', $position);
$customPositions = array_unique($customPositions, SORT_REGULAR);
}
$templateGroups[$customGroupText] = ModulesHelper::createOptionGroup($customGroupText, $customPositions);
return $templateGroups;
}
/**
* Get a select with the batch action options
*
* @return void
*/
public function batchOptions()
{
// Create the copy/move options.
$options = [
HTMLHelper::_('select.option', 'c', Text::_('JLIB_HTML_BATCH_COPY')),
HTMLHelper::_('select.option', 'm', Text::_('JLIB_HTML_BATCH_MOVE')),
];
echo HTMLHelper::_('select.radiolist', $options, 'batch[move_copy]', '', 'value', 'text', 'm');
}
/**
* Method to get the field options.
*
* @param integer $clientId The client ID
*
* @return array The field option objects.
*
* @since 2.5
*
* @deprecated 4.3 will be removed in 6.0
* Will be removed with no replacement
*/
public function positionList($clientId = 0)
{
$clientId = (int) $clientId;
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('DISTINCT ' . $db->quoteName('position', 'value'))
->select($db->quoteName('position', 'text'))
->from($db->quoteName('#__modules'))
->where($db->quoteName('client_id') . ' = :clientid')
->order($db->quoteName('position'))
->bind(':clientid', $clientId, ParameterType::INTEGER);
// Get the options.
$db->setQuery($query);
try {
$options = $db->loadObjectList();
} catch (\RuntimeException $e) {
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
// Pop the first item off the array if it's blank
if (\count($options)) {
if (\strlen($options[0]->text) < 1) {
array_shift($options);
}
}
return $options;
}
}

View File

@ -0,0 +1,223 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\View\Module;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View to edit a module.
*
* @since 1.6
*/
class HtmlView extends BaseHtmlView
{
/**
* The Form object
*
* @var \Joomla\CMS\Form\Form
*/
protected $form;
/**
* The active item
*
* @var object
*/
protected $item;
/**
* The model state
*
* @var \Joomla\Registry\Registry
*/
protected $state;
/**
* The actions the user is authorised to perform
*
* @var \Joomla\Registry\Registry
*
* @since 4.0.0
*/
protected $canDo;
/**
* Array of fieldsets not to display
*
* @var string[]
*
* @since 5.2.0
*/
public $ignore_fieldsets = [];
/**
* Display the view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
// Have to stop it earlier, because on cancel task for a new module we do not have an ID, and Model doing redirect on getItem()
if ($this->getLayout() === 'modalreturn' && !$this->state->get('module.id')) {
parent::display($tpl);
return;
}
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->canDo = ContentHelper::getActions('com_modules', 'module', $this->item->id);
if ($this->getLayout() === 'modalreturn') {
parent::display($tpl);
return;
}
// Check for errors.
if (\count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n", $errors), 500);
}
if ($this->getLayout() !== 'modal') {
$this->addToolbar();
} else {
$this->addModalToolbar();
}
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
Factory::getApplication()->getInput()->set('hidemainmenu', true);
$user = $this->getCurrentUser();
$isNew = ($this->item->id == 0);
$checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $user->id);
$canDo = $this->canDo;
$toolbar = $this->getDocument()->getToolbar();
ToolbarHelper::title(Text::sprintf('COM_MODULES_MANAGER_MODULE', Text::_($this->item->module)), 'cube module');
// For new records, check the create permission.
if ($isNew && $canDo->get('core.create')) {
$toolbar->apply('module.apply');
$saveGroup = $toolbar->dropdownButton('save-group');
$saveGroup->configure(
function (Toolbar $childBar) {
$childBar->save('module.save');
$childBar->save2new('module.save2new');
}
);
$toolbar->cancel('module.cancel', 'JTOOLBAR_CANCEL');
} else {
// Can't save the record if it's checked out.
if (!$checkedOut && $canDo->get('core.edit')) {
$toolbar->apply('module.apply');
}
$saveGroup = $toolbar->dropdownButton('save-group');
$saveGroup->configure(
function (Toolbar $childBar) use ($checkedOut, $canDo) {
// Can't save the record if it's checked out. Since it's an existing record, check the edit permission.
if (!$checkedOut && $canDo->get('core.edit')) {
$childBar->save('module.save');
// We can save this record, but check the create permission to see if we can return to make a new one.
if ($canDo->get('core.create')) {
$childBar->save2new('module.save2new');
}
}
// If checked out, we can still save
if ($canDo->get('core.create')) {
$childBar->save2copy('module.save2copy');
}
}
);
$toolbar->cancel('module.cancel');
}
// Get the help information for the menu item.
$lang = $this->getLanguage();
$help = $this->get('Help');
if ($lang->hasKey($help->url)) {
$debug = $lang->setDebug(false);
$url = Text::_($help->url);
$lang->setDebug($debug);
} else {
$url = null;
}
$toolbar->inlinehelp();
$toolbar->help($help->key, false, $url);
}
/**
* Add the modal toolbar.
*
* @return void
*
* @since 5.1.0
*
* @throws \Exception
*/
protected function addModalToolbar()
{
$isNew = ($this->item->id == 0);
$toolbar = $this->getDocument()->getToolbar();
$canDo = $this->canDo;
ToolbarHelper::title(Text::sprintf('COM_MODULES_MANAGER_MODULE', Text::_($this->item->module)), 'cube module');
$canCreate = $isNew && $canDo->get('core.create');
$canEdit = $canDo->get('core.edit');
// For new records, check the create permission.
if ($canCreate || $canEdit) {
$toolbar->apply('module.apply');
$toolbar->save('module.save');
}
$toolbar->cancel('module.cancel');
$toolbar->inlinehelp();
}
}

View File

@ -0,0 +1,246 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\View\Modules;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\Button\DropdownButton;
use Joomla\CMS\Toolbar\ToolbarHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View class for a list of modules.
*
* @since 1.6
*/
class HtmlView extends BaseHtmlView
{
/**
* An array of items
*
* @var array
*/
protected $items;
/**
* The pagination object
*
* @var \Joomla\CMS\Pagination\Pagination
*/
protected $pagination;
/**
* The model state
*
* @var \Joomla\Registry\Registry
*/
protected $state;
/**
* Form object for search filters
*
* @var \Joomla\CMS\Form\Form
*
* @since 4.0.0
*/
public $filterForm;
/**
* The active search filters
*
* @var array
* @since 4.0.0
*/
public $activeFilters;
/**
* Is this view an Empty State
*
* @var boolean
* @since 4.0.0
*/
private $isEmptyState = false;
/**
* Display the view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*
* @since 1.6
*/
public function display($tpl = null)
{
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->total = $this->get('Total');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
$this->clientId = $this->state->get('client_id');
if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
$this->setLayout('emptystate');
}
/**
* The code below make sure the remembered position will be available from filter dropdown even if there are no
* modules available for this position. This will make the UI less confusing for users in case there is only one
* module in the selected position and user:
* 1. Edit the module, change it to new position, save it and come back to Modules Management Screen
* 2. Or move that module to new position using Batch action
*/
if (\count($this->items) === 0 && $this->state->get('filter.position')) {
$selectedPosition = $this->state->get('filter.position');
$positionField = $this->filterForm->getField('position', 'filter');
$positionExists = false;
foreach ($positionField->getOptions() as $option) {
if ($option->value === $selectedPosition) {
$positionExists = true;
break;
}
}
if ($positionExists === false) {
$positionField->addOption($selectedPosition, ['value' => $selectedPosition]);
}
}
// Check for errors.
if (\count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n", $errors), 500);
}
// We do not need the Language filter when modules are not filtered
if ($this->clientId == 1 && !ModuleHelper::isAdminMultilang()) {
unset($this->activeFilters['language']);
$this->filterForm->removeField('language', 'filter');
}
// We don't need the toolbar in the modal window.
if ($this->getLayout() !== 'modal') {
$this->addToolbar();
// We do not need to filter by language when multilingual is disabled
if (!Multilanguage::isEnabled()) {
unset($this->activeFilters['language']);
$this->filterForm->removeField('language', 'filter');
}
} else {
// If in modal layout.
// Client id selector should not exist.
$this->filterForm->removeField('client_id', '');
// If in the frontend state and language should not activate the search tools.
if (Factory::getApplication()->isClient('site')) {
unset($this->activeFilters['state']);
unset($this->activeFilters['language']);
}
}
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
$state = $this->get('State');
$canDo = ContentHelper::getActions('com_modules');
$user = $this->getCurrentUser();
// Get the toolbar object instance
$toolbar = $this->getDocument()->getToolbar();
if ($state->get('client_id') == 1) {
ToolbarHelper::title(Text::_('COM_MODULES_MANAGER_MODULES_ADMIN'), 'cube module');
} else {
ToolbarHelper::title(Text::_('COM_MODULES_MANAGER_MODULES_SITE'), 'cube module');
}
if ($canDo->get('core.create')) {
$toolbar->standardButton('new', 'JTOOLBAR_NEW')
->onclick("location.href='index.php?option=com_modules&amp;view=select&amp;client_id=" . $this->state->get('client_id', 0) . "'");
}
if (!$this->isEmptyState && ($canDo->get('core.edit.state') || $this->getCurrentUser()->authorise('core.admin'))) {
/** @var DropdownButton $dropdown */
$dropdown = $toolbar->dropdownButton('status-group', 'JTOOLBAR_CHANGE_STATUS')
->toggleSplit(false)
->icon('icon-ellipsis-h')
->buttonClass('btn btn-action')
->listCheck(true);
$childBar = $dropdown->getChildToolbar();
if ($canDo->get('core.edit.state')) {
$childBar->publish('modules.publish')->listCheck(true);
$childBar->unpublish('modules.unpublish')->listCheck(true);
}
if ($this->getCurrentUser()->authorise('core.admin')) {
$childBar->checkin('modules.checkin')->listCheck(true);
}
if ($canDo->get('core.edit.state') && $this->state->get('filter.published') != -2) {
$childBar->trash('modules.trash')->listCheck(true);
}
// Add a batch button
if (
$user->authorise('core.create', 'com_modules') && $user->authorise('core.edit', 'com_modules')
&& $user->authorise('core.edit.state', 'com_modules')
) {
$childBar->popupButton('batch', 'JTOOLBAR_BATCH')
->popupType('inline')
->textHeader(Text::_('COM_MODULES_BATCH_OPTIONS'))
->url('#joomla-dialog-batch')
->modalWidth('800px')
->modalHeight('fit-content')
->listCheck(true);
}
if ($canDo->get('core.create')) {
$childBar->standardButton('copy', 'JTOOLBAR_DUPLICATE', 'modules.duplicate')
->listCheck(true);
}
}
if (!$this->isEmptyState && ($state->get('filter.state') == -2 && $canDo->get('core.delete'))) {
$toolbar->delete('modules.delete', 'JTOOLBAR_DELETE_FROM_TRASH')
->message('JGLOBAL_CONFIRM_DELETE')
->listCheck(true);
}
if ($canDo->get('core.admin')) {
$toolbar->preferences('com_modules');
}
$toolbar->help('Modules');
}
}

View File

@ -0,0 +1,99 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @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\Modules\Administrator\View\Select;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* HTML View class for the Modules component
*
* @since 1.6
*/
class HtmlView extends BaseHtmlView
{
/**
* The model state
*
* @var \Joomla\Registry\Registry
*/
protected $state;
/**
* An array of items
*
* @var array
*/
protected $items;
/**
* A suffix for links for modal use
*
* @var string
*/
protected $modalLink;
/**
* Display the view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->modalLink = '';
// Check for errors.
if (\count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n", $errors), 500);
}
$this->addToolbar();
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
$state = $this->get('State');
$clientId = (int) $state->get('client_id', 0);
$toolbar = $this->getDocument()->getToolbar();
// Add page title
ToolbarHelper::title(Text::_('COM_MODULES_MANAGER_MODULES_SITE'), 'cube module');
if ($clientId === 1) {
ToolbarHelper::title(Text::_('COM_MODULES_MANAGER_MODULES_ADMIN'), 'cube module');
}
// Instantiate a new FileLayout instance and render the layout
$layout = new FileLayout('toolbar.cancelselect');
$toolbar->customButton('new')
->html($layout->render(['client_id' => $clientId]));
}
}