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,67 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @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\Plugins\Administrator\Controller;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Router\Route;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Plugins display controller.
*
* @since 1.5
*/
class DisplayController extends BaseController
{
/**
* The default view.
*
* @var string
* @since 1.6
*/
protected $default_view = 'plugins';
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $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 = [])
{
$view = $this->input->get('view', 'plugins');
$layout = $this->input->get('layout', 'default');
$id = $this->input->getInt('extension_id');
// Check for edit form.
if ($view == 'plugin' && $layout == 'edit' && !$this->checkEditId('com_plugins.edit.plugin', $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_plugins&view=plugins', false));
return false;
}
return parent::display($cachable, $urlparams);
}
}

View File

@ -0,0 +1,77 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @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\Plugins\Administrator\Controller;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Router\Route;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Plugin controller class.
*
* @since 1.6
*/
class PluginController extends FormController
{
/**
* Method to cancel an edit.
*
* @param string $key The name of the primary key of the URL variable.
*
* @return boolean True if access level checks pass, false otherwise.
*
* @since 5.1.0
*/
public function cancel($key = null)
{
$result = parent::cancel($key);
// When editing in modal then redirect to modalreturn layout
if ($result && $this->input->get('layout') === 'modal') {
$id = $this->input->get('extension_id');
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id, 'extension_id')
. '&layout=modalreturn&from-task=cancel';
$this->setRedirect(Route::_($return, false));
}
return $result;
}
/**
* 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 5.1.0
*/
protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
{
parent::postSaveHook($model, $validData);
// When editing in modal then redirect to modalreturn layout
if ($this->input->get('layout') === 'modal' && $this->task === 'save') {
$id = $model->getState('plugin.id', '');
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id, 'extension_id')
. '&layout=modalreturn&from-task=save';
$this->setRedirect(Route::_($return, false));
}
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @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\Plugins\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
/**
* Plugins list controller class.
*
* @since 1.6
*/
class PluginsController extends AdminController
{
/**
* 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 = 'Plugin', $prefix = 'Administrator', $config = ['ignore_request' => true])
{
return parent::getModel($name, $prefix, $config);
}
/**
* Method to get the number of activated plugins
*
* @return void
*
* @since 4.0.0
*/
public function getQuickiconContent()
{
$model = $this->getModel('Plugins');
$model->setState('filter.enabled', 1);
$amount = (int) $model->getTotal();
$result = [];
$result['amount'] = $amount;
$result['sronly'] = Text::plural('COM_PLUGINS_N_QUICKICON_SRONLY', $amount);
$result['name'] = Text::plural('COM_PLUGINS_N_QUICKICON', $amount);
echo new JsonResponse($result);
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Plugins\Administrator\Field;
use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Plugins\Administrator\Helper\PluginsHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Plugin Element field.
*
* @since 3.9.0
*/
class PluginElementField extends ListField
{
/**
* The form field type.
*
* @var string
* @since 3.9.0
*/
protected $type = 'PluginElement';
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 3.9.0
*/
public function getOptions()
{
$options = PluginsHelper::elementOptions();
return array_merge(parent::getOptions(), $options);
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @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\Plugins\Administrator\Field;
use Joomla\CMS\Form\Field\ListField;
use Joomla\Component\Plugins\Administrator\Helper\PluginsHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Plugin Type field.
*
* @since 3.5
*/
class PluginTypeField extends ListField
{
/**
* The form field type.
*
* @var string
* @since 3.5
*/
protected $type = 'PluginType';
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 3.5
*/
public function getOptions()
{
$options = PluginsHelper::folderOptions();
return array_merge(parent::getOptions(), $options);
}
}

View File

@ -0,0 +1,73 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @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\Plugins\Administrator\Field;
use Joomla\CMS\Form\Field\OrderingField;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Supports an HTML select list of plugins.
*
* @since 1.6
*/
class PluginorderingField extends OrderingField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'Pluginordering';
/**
* Builds the query for the ordering list.
*
* @return \Joomla\Database\DatabaseQuery The query for the ordering form field.
*/
protected function getQuery()
{
$db = $this->getDatabase();
$folder = $this->form->getValue('folder');
// Build the query for the ordering list.
$query = $db->getQuery(true)
->select(
[
$db->quoteName('ordering', 'value'),
$db->quoteName('name', 'text'),
$db->quoteName('type'),
$db->quote('folder'),
$db->quote('extension_id'),
]
)
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = :folder')
->order($db->quoteName('ordering'))
->bind(':folder', $folder);
return $query;
}
/**
* Retrieves the current Item's Id.
*
* @return integer The current item ID.
*/
protected function getItemId()
{
return (int) $this->form->getValue('extension_id');
}
}

View File

@ -0,0 +1,125 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @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\Plugins\Administrator\Helper;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Object\CMSObject;
use Joomla\Filesystem\Path;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Plugins component helper.
*
* @since 1.6
*/
class PluginsHelper
{
public static $extension = 'com_plugins';
/**
* Returns an array of standard published state filter options.
*
* @return array The HTML code for the select tag
*/
public static function publishedOptions()
{
// Build the active state filter options.
$options = [];
$options[] = HTMLHelper::_('select.option', '1', 'JENABLED');
$options[] = HTMLHelper::_('select.option', '0', 'JDISABLED');
return $options;
}
/**
* Returns a list of folders filter options.
*
* @return object[] The HTML code for the select tag
*/
public static function folderOptions()
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('DISTINCT(folder) AS value, folder AS text')
->from('#__extensions')
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->order('folder');
$db->setQuery($query);
try {
$options = $db->loadObjectList();
} catch (\RuntimeException $e) {
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
return $options;
}
/**
* Returns a list of elements filter options.
*
* @return object[] The HTML code for the select tag
*/
public static function elementOptions()
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('DISTINCT(element) AS value, element AS text')
->from('#__extensions')
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->order('element');
$db->setQuery($query);
try {
$options = $db->loadObjectList();
} catch (\RuntimeException $e) {
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
return $options;
}
/**
* Parse the template file.
*
* @param string $templateBaseDir Base path to the template directory.
* @param string $templateDir Template directory.
*
* @return CMSObject|bool
*/
public function parseXMLTemplateFile($templateBaseDir, $templateDir)
{
$data = new CMSObject();
// Check of the xml file exists.
$filePath = Path::clean($templateBaseDir . '/templates/' . $templateDir . '/templateDetails.xml');
if (is_file($filePath)) {
$xml = Installer::parseXMLInstallFile($filePath);
if ($xml['type'] != 'template') {
return false;
}
foreach ($xml as $key => $value) {
$data->set($key, $value);
}
}
return $data;
}
}

View File

@ -0,0 +1,376 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @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\Plugins\Administrator\Model;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Table\Table;
use Joomla\Filesystem\Path;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Plugin model.
*
* @since 1.6
*/
class PluginModel extends AdminModel
{
/**
* @var string The help screen key for the module.
* @since 1.6
*/
protected $helpKey = 'Plugins:_Name_of_Plugin';
/**
* @var string The help screen base URL for the module.
* @since 1.6
*/
protected $helpURL;
/**
* @var array An array of cached plugin items.
* @since 1.6
*/
protected $_cache;
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param ?MVCFactoryInterface $factory The factory.
*
* @see \Joomla\CMS\MVC\Model\BaseDatabaseModel
* @since 3.2
*/
public function __construct($config = [], ?MVCFactoryInterface $factory = null)
{
$config = array_merge(
[
'event_after_save' => 'onExtensionAfterSave',
'event_before_save' => 'onExtensionBeforeSave',
'events_map' => [
'save' => 'extension',
],
],
$config
);
parent::__construct($config, $factory);
}
/**
* 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|bool A Form object on success, false on failure.
*
* @since 1.6
*/
public function getForm($data = [], $loadData = true)
{
// The folder and element vars are passed when saving the form.
if (empty($data)) {
$item = $this->getItem();
$folder = $item->folder;
$element = $item->element;
} else {
$folder = ArrayHelper::getValue($data, 'folder', '', 'cmd');
$element = ArrayHelper::getValue($data, 'element', '', 'cmd');
}
// Add the default fields directory
Form::addFieldPath(JPATH_PLUGINS . '/' . $folder . '/' . $element . '/field');
// These variables are used to add data from the plugin XML files.
$this->setState('item.folder', $folder);
$this->setState('item.element', $element);
// Get the form.
$form = $this->loadForm('com_plugins.plugin', 'plugin', ['control' => 'jform', 'load_data' => $loadData]);
if (empty($form)) {
return false;
}
// Modify the form based on access controls.
if (!$this->canEditState((object) $data)) {
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('enabled', 'disabled', 'true');
// Disable fields while saving.
// The controller has already verified this is a record you can edit.
$form->setFieldAttribute('ordering', 'filter', 'unset');
$form->setFieldAttribute('enabled', 'filter', 'unset');
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
*
* @since 1.6
*/
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = Factory::getApplication()->getUserState('com_plugins.edit.plugin.data', []);
if (empty($data)) {
$data = $this->getItem();
}
$this->preprocessData('com_plugins.plugin', $data);
return $data;
}
/**
* Method to get a single record.
*
* @param integer $pk The id of the primary key.
*
* @return mixed Object on success, false on failure.
*/
public function getItem($pk = null)
{
$pk = (!empty($pk)) ? $pk : (int) $this->getState('plugin.id');
$cacheId = $pk;
if (\is_array($cacheId)) {
$cacheId = serialize($cacheId);
}
if (!isset($this->_cache[$cacheId])) {
// Get a row instance.
$table = $this->getTable();
// Attempt to load the row.
$return = $table->load(\is_array($pk) ? $pk : ['extension_id' => $pk, 'type' => 'plugin']);
// Check for a table object error.
if ($return === false) {
return false;
}
// Convert to the \Joomla\CMS\Object\CMSObject before adding other data.
$properties = $table->getProperties(1);
$this->_cache[$cacheId] = ArrayHelper::toObject($properties, CMSObject::class);
// Convert the params field to an array.
$registry = new Registry($table->params);
$this->_cache[$cacheId]->params = $registry->toArray();
// Get the plugin XML.
$path = Path::clean(JPATH_PLUGINS . '/' . $table->folder . '/' . $table->element . '/' . $table->element . '.xml');
if (file_exists($path)) {
$this->_cache[$cacheId]->xml = simplexml_load_file($path);
} else {
$this->_cache[$cacheId]->xml = null;
}
}
return $this->_cache[$cacheId];
}
/**
* Returns a reference to the Table object, always creating it.
*
* @param string $type The table type to instantiate.
* @param string $prefix A prefix for the table class name. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return Table A database object
*/
public function getTable($type = 'Extension', $prefix = '\\Joomla\\CMS\\Table\\', $config = [])
{
return Table::getInstance($type, $prefix, $config);
}
/**
* Auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*
* @since 1.6
*/
protected function populateState()
{
// Execute the parent method.
parent::populateState();
$app = Factory::getApplication();
// Load the User state.
$pk = $app->getInput()->getInt('extension_id');
$this->setState('plugin.id', $pk);
}
/**
* Preprocess the form.
*
* @param Form $form A form object.
* @param mixed $data The data expected for the form.
* @param string $group Cache group name.
*
* @return void
*
* @since 1.6
*
* @throws \Exception if there is an error in the form event.
*/
protected function preprocessForm(Form $form, $data, $group = 'content')
{
$folder = $this->getState('item.folder');
$element = $this->getState('item.element');
$lang = Factory::getLanguage();
// Load the core and/or local language sys file(s) for the ordering field.
$db = $this->getDatabase();
$query = $db->getQuery(true)
->select($db->quoteName('element'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = :folder')
->bind(':folder', $folder);
$db->setQuery($query);
$elements = $db->loadColumn();
foreach ($elements as $elementa) {
$lang->load('plg_' . $folder . '_' . $elementa . '.sys', JPATH_ADMINISTRATOR)
|| $lang->load('plg_' . $folder . '_' . $elementa . '.sys', JPATH_PLUGINS . '/' . $folder . '/' . $elementa);
}
if (empty($folder) || empty($element)) {
$app = Factory::getApplication();
$app->redirect(Route::_('index.php?option=com_plugins&view=plugins', false));
}
$formFile = Path::clean(JPATH_PLUGINS . '/' . $folder . '/' . $element . '/' . $element . '.xml');
if (!file_exists($formFile)) {
throw new \Exception(Text::sprintf('COM_PLUGINS_ERROR_FILE_NOT_FOUND', $element . '.xml'));
}
// Load the core and/or local language file(s).
$lang->load('plg_' . $folder . '_' . $element, JPATH_ADMINISTRATOR)
|| $lang->load('plg_' . $folder . '_' . $element, JPATH_PLUGINS . '/' . $folder . '/' . $element);
if (file_exists($formFile)) {
// Get the plugin 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'));
}
// Get the help data from the XML file if present.
$help = $xml->xpath('/extension/help');
if (!empty($help)) {
$helpKey = trim((string) $help[0]['key']);
$helpURL = trim((string) $help[0]['url']);
$this->helpKey = $helpKey ?: $this->helpKey;
$this->helpURL = $helpURL ?: $this->helpURL;
}
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
/**
* A protected method to get a set of ordering conditions.
*
* @param object $table A record object.
*
* @return array An array of conditions to add to ordering queries.
*
* @since 1.6
*/
protected function getReorderConditions($table)
{
$db = $this->getDatabase();
return [
$db->quoteName('type') . ' = ' . $db->quote($table->type),
$db->quoteName('folder') . ' = ' . $db->quote($table->folder),
];
}
/**
* Override method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function save($data)
{
// Setup type.
$data['type'] = 'plugin';
return parent::save($data);
}
/**
* Get the necessary data to load an item help screen.
*
* @return object An object with key, url, and local properties for loading the item help screen.
*
* @since 1.6
*/
public function getHelp()
{
return (object) ['key' => $this->helpKey, 'url' => $this->helpURL];
}
/**
* Custom clean cache method, plugins are cached in 2 places for different clients.
*
* @param string $group Cache group name.
* @param integer $clientId No longer used, will be removed without replacement
* @deprecated 4.3 will be removed in 6.0
*
* @return void
*
* @since 1.6
*/
protected function cleanCache($group = null, $clientId = 0)
{
parent::cleanCache('com_plugins');
}
}

View File

@ -0,0 +1,291 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @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\Plugins\Administrator\Model;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Methods supporting a list of plugin records.
*
* @since 1.6
*/
class PluginsModel extends ListModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param ?MVCFactoryInterface $factory The factory.
*
* @see \Joomla\CMS\MVC\Model\BaseDatabaseModel
* @since 3.2
*/
public function __construct($config = [], ?MVCFactoryInterface $factory = null)
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'extension_id', 'a.extension_id',
'name', 'a.name',
'folder', 'a.folder',
'element', 'a.element',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'state', 'a.state',
'enabled', 'a.enabled',
'access', 'a.access', 'access_level',
'ordering', 'a.ordering',
'client_id', 'a.client_id',
];
}
parent::__construct($config, $factory);
}
/**
* 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 = 'folder', $direction = 'asc')
{
// Load the parameters.
$params = ComponentHelper::getParams('com_plugins');
$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('filter.search');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.enabled');
$id .= ':' . $this->getState('filter.folder');
$id .= ':' . $this->getState('filter.element');
return parent::getStoreId($id);
}
/**
* Returns an object list.
*
* @param QueryInterface|string $query A database query object.
* @param integer $limitstart Offset.
* @param integer $limit The number of records.
*
* @return object[]
*/
protected function _getList($query, $limitstart = 0, $limit = 0)
{
$search = $this->getState('filter.search');
$ordering = $this->getState('list.ordering', 'ordering');
// If "Sort Table By:" is not set, set ordering to name
if ($ordering == '') {
$ordering = 'name';
}
$db = $this->getDatabase();
if ($ordering == 'name' || (!empty($search) && stripos($search, 'id:') !== 0)) {
$db->setQuery($query);
$result = $db->loadObjectList();
$this->translate($result);
if (!empty($search)) {
$escapedSearchString = $this->refineSearchStringToRegex($search, '/');
foreach ($result as $i => $item) {
if (!preg_match("/$escapedSearchString/i", $item->name)) {
unset($result[$i]);
}
}
}
$orderingDirection = strtolower($this->getState('list.direction'));
$direction = ($orderingDirection == 'desc') ? -1 : 1;
$result = ArrayHelper::sortObjects($result, $ordering, $direction, true, true);
$total = \count($result);
$this->cache[$this->getStoreId('getTotal')] = $total;
if ($total < $limitstart) {
$limitstart = 0;
}
$this->cache[$this->getStoreId('getStart')] = $limitstart;
return \array_slice($result, $limitstart, $limit ?: null);
}
if ($ordering === 'ordering') {
$query->order('a.folder ASC');
$ordering = 'a.ordering';
}
$query->order($db->quoteName($ordering) . ' ' . $this->getState('list.direction'));
if ($ordering === 'folder') {
$query->order('a.ordering ASC');
}
$result = parent::_getList($query, $limitstart, $limit);
$this->translate($result);
return $result;
}
/**
* Translate a list of objects.
*
* @param object[] &$items The array of objects.
*
* @return void
*/
protected function translate(&$items)
{
$lang = Factory::getLanguage();
foreach ($items as &$item) {
$source = JPATH_PLUGINS . '/' . $item->folder . '/' . $item->element;
$extension = 'plg_' . $item->folder . '_' . $item->element;
$lang->load($extension . '.sys', JPATH_ADMINISTRATOR)
|| $lang->load($extension . '.sys', $source);
$item->name = Text::_($item->name);
}
}
/**
* 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, a.folder, a.checked_out, a.checked_out_time,' .
' a.enabled, a.access, a.ordering, a.note'
)
)
->from($db->quoteName('#__extensions') . ' AS a')
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));
// Join over the users for the checked out user.
$query->select('uc.name AS editor')
->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
// Join over the asset groups.
$query->select('ag.title AS access_level')
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
// 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.
$published = (string) $this->getState('filter.enabled');
if (is_numeric($published)) {
$published = (int) $published;
$query->where($db->quoteName('a.enabled') . ' = :published')
->bind(':published', $published, ParameterType::INTEGER);
} elseif ($published === '') {
$query->whereIn($db->quoteName('a.enabled'), [0, 1]);
}
// Filter by state.
$query->where('a.state >= 0');
// Filter by folder.
if ($folder = $this->getState('filter.folder')) {
$query->where($db->quoteName('a.folder') . ' = :folder')
->bind(':folder', $folder);
}
// Filter by element.
if ($element = $this->getState('filter.element')) {
$query->where($db->quoteName('a.element') . ' = :element')
->bind(':element', $element);
}
// Filter by search in name 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.extension_id') . ' = :id');
$query->bind(':id', $ids, ParameterType::INTEGER);
}
}
return $query;
}
/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
*
* @since 3.5
*/
protected function loadFormData()
{
$data = parent::loadFormData();
// Set the selected filter values for pages that use the Layouts for filtering
$data->list['sortTable'] = $this->state->get('list.ordering');
$data->list['directionTable'] = $this->state->get('list.direction');
return $data;
}
}

View File

@ -0,0 +1,164 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @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\Plugins\Administrator\View\Plugin;
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\ToolbarHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View to edit a plugin.
*
* @since 1.5
*/
class HtmlView extends BaseHtmlView
{
/**
* The item object for the newsfeed
*
* @var \stdClass
*/
protected $item;
/**
* The form object for the newsfeed
*
* @var \Joomla\CMS\Form\Form
*/
protected $form;
/**
* The model state of the newsfeed
*
* @var \Joomla\Registry\Registry
*/
protected $state;
/**
* 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');
$this->item = $this->get('Item');
$this->form = $this->get('Form');
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);
$canDo = ContentHelper::getActions('com_plugins');
$toolbar = $this->getDocument()->getToolbar();
ToolbarHelper::title(Text::sprintf('COM_PLUGINS_MANAGER_PLUGIN', Text::_($this->item->name)), 'plug plugin');
// If not checked out, can save the item.
if ($canDo->get('core.edit')) {
$toolbar->apply('plugin.apply');
$toolbar->save('plugin.save');
}
$toolbar->cancel('plugin.cancel');
$toolbar->divider();
// Get the help information for the plugin item.
$lang = $this->getLanguage();
$help = $this->get('Help');
if ($help->url && $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()
{
$canDo = ContentHelper::getActions('com_plugins');
$toolbar = $this->getDocument()->getToolbar();
ToolbarHelper::title(Text::sprintf('COM_PLUGINS_MANAGER_PLUGIN', Text::_($this->item->name)), 'plug plugin');
// If not checked out, can save the item.
if ($canDo->get('core.edit')) {
$toolbar->apply('plugin.apply');
$toolbar->save('plugin.save');
}
$toolbar->cancel('plugin.cancel');
$toolbar->inlinehelp();
}
}

View File

@ -0,0 +1,118 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_plugins
*
* @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\Plugins\Administrator\View\Plugins;
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\ToolbarHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View class for a list of plugins.
*
* @since 1.5
*/
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;
/**
* 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->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// 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()
{
$canDo = ContentHelper::getActions('com_plugins');
$toolbar = $this->getDocument()->getToolbar();
ToolbarHelper::title(Text::_('COM_PLUGINS_MANAGER_PLUGINS'), 'plug plugin');
if ($canDo->get('core.edit.state')) {
$toolbar->publish('plugins.publish', 'JTOOLBAR_ENABLE')->listCheck(true);
$toolbar->unpublish('plugins.unpublish', 'JTOOLBAR_DISABLE')->listCheck(true);
$toolbar->checkin('plugins.checkin');
}
if ($canDo->get('core.admin')) {
$toolbar->preferences('com_plugins');
}
$toolbar->help('Plugins');
}
}