Файловый менеджер - Редактировать - /home/wuectly/www/03cbe/com_modules.tar
Назад
controller.php 0000604 00000002175 15245530523 0007445 0 ustar 00 <?php /** * @package Joomla.Site * @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 */ defined('_JEXEC') or die; /** * Modules manager master display controller. * * @since 3.5 */ class ModulesController extends JControllerLegacy { /** * Constructor. * * @param array $config An optional associative array of configuration settings. * Recognized key values include 'name', 'default_task', 'model_path', and * 'view_path' (this list is not meant to be comprehensive). * * @since 3.5 */ public function __construct($config = array()) { $this->input = JFactory::getApplication()->input; // Modules frontpage Editor Module proxying: if ($this->input->get('view') === 'modules' && $this->input->get('layout') === 'modal') { JHtml::_('stylesheet', 'system/adminlist.css', array('version' => 'auto', 'relative' => true)); $config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR; } parent::__construct($config); } } modules.php 0000604 00000001707 15245530523 0006732 0 ustar 00 <?php /** * @package Joomla.Site * @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 */ defined('_JEXEC') or die; // Load the required admin language files $lang = JFactory::getLanguage(); $app = JFactory::getApplication(); $config = array(); $lang->load('com_modules', JPATH_ADMINISTRATOR); if ($app->input->get('view') === 'modules' && $app->input->get('layout') === 'modal') { if (!JFactory::getUser()->authorise('core.create', 'com_modules')) { $app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'warning'); return; } } if ($app->input->get('task') === 'module.orderPosition') { $config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR; } // Trigger the controller $controller = JControllerLegacy::getInstance('Modules', $config); $controller->execute($app->input->get('task')); $controller->redirect(); models/forms/filter_modules.xml 0000604 00000005323 15245530523 0012717 0 ustar 00 <?xml version="1.0" encoding="utf-8"?> <form> <fieldset addfieldpath="/administrator/components/com_modules/models/fields" /> <fields name="filter"> <field name="search" type="text" inputmode="search" label="COM_MODULES_MODULES_FILTER_SEARCH_LABEL" description="COM_MODULES_MODULES_FILTER_SEARCH_DESC" hint="JSEARCH_FILTER" noresults="COM_MODULES_MSG_MANAGE_NO_MODULES" /> <field name="position" type="modulesposition" label="COM_MODULES_FIELD_POSITION_LABEL" onchange="this.form.submit();" > <option value="">COM_MODULES_OPTION_SELECT_POSITION</option> </field> <field name="module" type="ModulesModule" label="COM_MODULES_OPTION_SELECT_MODULE" onchange="this.form.submit();" > <option value="">COM_MODULES_OPTION_SELECT_MODULE</option> </field> <field name="access" type="accesslevel" label="JOPTION_FILTER_ACCESS" description="JOPTION_FILTER_ACCESS_DESC" onchange="this.form.submit();" > <option value="">JOPTION_SELECT_ACCESS</option> </field> </fields> <fields name="list"> <field name="fullordering" type="list" label="JGLOBAL_SORT_BY" description="JGLOBAL_SORT_BY" statuses="*,0,1,-2" onchange="this.form.submit();" default="a.position ASC" validate="options" > <option value="">JGLOBAL_SORT_BY</option> <option value="a.ordering ASC">JGRID_HEADING_ORDERING_ASC</option> <option value="a.ordering DESC">JGRID_HEADING_ORDERING_DESC</option> <option value="a.published ASC">JSTATUS_ASC</option> <option value="a.published DESC">JSTATUS_DESC</option> <option value="a.title ASC">JGLOBAL_TITLE_ASC</option> <option value="a.title DESC">JGLOBAL_TITLE_DESC</option> <option value="a.position ASC">COM_MODULES_HEADING_POSITION_ASC</option> <option value="a.position DESC">COM_MODULES_HEADING_POSITION_DESC</option> <option value="name ASC">COM_MODULES_HEADING_MODULE_ASC</option> <option value="name DESC">COM_MODULES_HEADING_MODULE_DESC</option> <option value="pages ASC">COM_MODULES_HEADING_PAGES_ASC</option> <option value="pages DESC">COM_MODULES_HEADING_PAGES_DESC</option> <option value="ag.title ASC">JGRID_HEADING_ACCESS_ASC</option> <option value="ag.title DESC">JGRID_HEADING_ACCESS_DESC</option> <option value="l.title ASC">JGRID_HEADING_LANGUAGE_ASC</option> <option value="l.title DESC">JGRID_HEADING_LANGUAGE_DESC</option> <option value="a.id ASC">JGRID_HEADING_ID_ASC</option> <option value="a.id DESC">JGRID_HEADING_ID_DESC</option> </field> <field name="limit" type="limitbox" label="COM_MODULES_LIST_LIMIT" description="JFIELD_PLG_SEARCH_SEARCHLIMIT_DESC" class="input-mini" default="25" onchange="this.form.submit();" /> </fields> </form> js/admin-modules-modal.min.js 0000604 00000002110 15245540357 0012130 0 ustar 00 document.addEventListener('DOMContentLoaded',function(){'use strict';var b,a=document.querySelectorAll('.js-module-insert'),c=document.querySelectorAll('.js-position-insert');for(b=0;a.length>b;b++)a[b].addEventListener('click',function(d){d.preventDefault();var e=d.target.getAttribute('data-module'),f=d.target.getAttribute('data-editor');window.parent.Joomla&&window.parent.Joomla.editors&&window.parent.Joomla.editors.instances&&window.parent.Joomla.editors.instances.hasOwnProperty(f)?window.parent.Joomla.editors.instances[f].replaceSelection('{loadmoduleid '+e+'}'):window.parent.jInsertEditorText('{loadmoduleid '+e+'}',f),window.parent.jModalClose()});for(b=0;c.length>b;b++)c[b].addEventListener('click',function(d){d.preventDefault();var e=d.target.getAttribute('data-position'),f=d.target.getAttribute('data-editor');window.Joomla&&window.Joomla.editors&&Joomla.editors.instances&&Joomla.editors.instances.hasOwnProperty(f)?Joomla.editors.instances[f].replaceSelection('{loadposition '+e+'}'):window.parent.jInsertEditorText('{loadposition '+e+'}',f),window.parent.jModalClose()})}); js/admin-modules-modal.js 0000604 00000003561 15245540357 0011361 0 ustar 00 /** * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ document.addEventListener('DOMContentLoaded', function() { "use strict"; /** Get the elements **/ var modulesLinks = document.querySelectorAll('.js-module-insert'), i, positionsLinks = document.querySelectorAll('.js-position-insert'); /** Assign listener for click event (for single module id insertion) **/ for (i= 0; modulesLinks.length > i; i++) { modulesLinks[i].addEventListener('click', function(event) { event.preventDefault(); var modid = event.target.getAttribute('data-module'), editor = event.target.getAttribute('data-editor'); /** Use the API, if editor supports it **/ if (window.parent.Joomla && window.parent.Joomla.editors && window.parent.Joomla.editors.instances && window.parent.Joomla.editors.instances.hasOwnProperty(editor)) { window.parent.Joomla.editors.instances[editor].replaceSelection("{loadmoduleid " + modid + "}") } else { window.parent.jInsertEditorText("{loadmoduleid " + modid + "}", editor); } window.parent.jModalClose(); }); } /** Assign listener for click event (for position insertion) **/ for (i= 0; positionsLinks.length > i; i++) { positionsLinks[i].addEventListener('click', function(event) { event.preventDefault(); var position = event.target.getAttribute('data-position'), editor = event.target.getAttribute('data-editor'); /** Use the API, if editor supports it **/ if (window.Joomla && window.Joomla.editors && Joomla.editors.instances && Joomla.editors.instances.hasOwnProperty(editor)) { Joomla.editors.instances[editor].replaceSelection("{loadposition " + position + "}") } else { window.parent.jInsertEditorText("{loadposition " + position + "}", editor); } window.parent.jModalClose(); }); } }); layouts/toolbar/newmodule.php 0000604 00000001034 15245570476 0012427 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_modules * * @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; $text = JText::_('JTOOLBAR_NEW'); ?> <button onclick="location.href='index.php?option=com_modules&view=select'" class="btn btn-small btn-success" title="<?php echo $text; ?>"> <span class="icon-plus icon-white" aria-hidden="true"></span> <?php echo $text; ?> </button> layouts/toolbar/cancelselect.php 0000604 00000000757 15245570476 0013070 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_modules * * @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; $text = JText::_('JTOOLBAR_CANCEL'); ?> <button onclick="location.href='index.php?option=com_modules'" class="btn" title="<?php echo $text; ?>"> <span class="icon-remove" aria-hidden="true"></span> <?php echo $text; ?> </button> modules.xml 0000604 00000001747 15245570476 0006762 0 ustar 00 <?xml version="1.0" encoding="utf-8"?> <extension type="component" version="3.1" method="upgrade"> <name>com_modules</name> <author>Joomla! Project</author> <creationDate>April 2006</creationDate> <copyright>(C) 2006 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.0.0</version> <description>COM_MODULES_XML_DESCRIPTION</description> <administration> <files folder="admin"> <filename>config.xml</filename> <filename>controller.php</filename> <filename>modules.php</filename> <folder>controllers</folder> <folder>helpers</folder> <folder>models</folder> <folder>views</folder> </files> <languages folder="admin"> <language tag="en-GB">language/en-GB.com_modules.ini</language> <language tag="en-GB">language/en-GB.com_modules.sys.ini</language> </languages> </administration> </extension> models/forms/advanced.xml 0000604 00000002050 15245570476 0011454 0 ustar 00 <?xml version="1.0" encoding="utf-8"?> <form> <fields name="params"> <fieldset name="advanced"> <field name="module_tag" type="moduletag" label="COM_MODULES_FIELD_MODULE_TAG_LABEL" description="COM_MODULES_FIELD_MODULE_TAG_DESC" default="div" validate="options" /> <field name="bootstrap_size" type="integer" label="COM_MODULES_FIELD_BOOTSTRAP_SIZE_LABEL" description="COM_MODULES_FIELD_BOOTSTRAP_SIZE_DESC" first="0" last="12" step="1" /> <field name="header_tag" type="headertag" label="COM_MODULES_FIELD_HEADER_TAG_LABEL" description="COM_MODULES_FIELD_HEADER_TAG_DESC" default="h3" validate="options" /> <field name="header_class" type="text" label="COM_MODULES_FIELD_HEADER_CLASS_LABEL" description="COM_MODULES_FIELD_HEADER_CLASS_DESC" /> <field name="style" type="chromestyle" label="COM_MODULES_FIELD_MODULE_STYLE_LABEL" description="COM_MODULES_FIELD_MODULE_STYLE_DESC" /> </fieldset> </fields> </form> models/forms/module.xml 0000604 00000006371 15245570476 0011206 0 ustar 00 <?xml version="1.0" encoding="utf-8"?> <form> <fieldset> <field name="id" type="number" label="JGLOBAL_FIELD_ID_LABEL" description="JGLOBAL_FIELD_ID_DESC" default="0" readonly="true" /> <field name="title" type="text" label="JGLOBAL_TITLE" description="COM_MODULES_FIELD_TITLE_DESC" class="input-xxlarge input-large-text" size="40" maxlength="100" required="true" /> <field name="note" type="text" label="COM_MODULES_FIELD_NOTE_LABEL" description="COM_MODULES_FIELD_NOTE_DESC" maxlength="255" size="40" class="span12" /> <field name="module" type="hidden" label="COM_MODULES_FIELD_MODULE_LABEL" description="COM_MODULES_FIELD_MODULE_DESC" readonly="readonly" size="20" /> <field name="showtitle" type="radio" label="COM_MODULES_FIELD_SHOWTITLE_LABEL" description="COM_MODULES_FIELD_SHOWTITLE_DESC" class="btn-group btn-group-yesno" default="1" size="1" > <option value="1">JSHOW</option> <option value="0">JHIDE</option> </field> <field name="published" type="list" label="JSTATUS" description="COM_MODULES_FIELD_PUBLISHED_DESC" class="chzn-color-state" default="1" size="1" > <option value="1">JPUBLISHED</option> <option value="0">JUNPUBLISHED</option> <option value="-2">JTRASHED</option> </field> <field name="publish_up" type="calendar" label="COM_MODULES_FIELD_PUBLISH_UP_LABEL" description="COM_MODULES_FIELD_PUBLISH_UP_DESC" filter="user_utc" translateformat="true" showtime="true" size="22" /> <field name="publish_down" type="calendar" label="COM_MODULES_FIELD_PUBLISH_DOWN_LABEL" description="COM_MODULES_FIELD_PUBLISH_DOWN_DESC" filter="user_utc" translateformat="true" showtime="true" size="22" /> <field name="client_id" type="hidden" label="COM_MODULES_FIELD_CLIENT_ID_LABEL" description="COM_MODULES_FIELD_CLIENT_ID_DESC" readonly="true" size="1" /> <field name="position" type="moduleposition" label="COM_MODULES_FIELD_POSITION_LABEL" description="COM_MODULES_FIELD_POSITION_DESC" default="" maxlength="50" /> <field name="access" type="accesslevel" label="JFIELD_ACCESS_LABEL" description="JFIELD_ACCESS_DESC" size="1" /> <field name="ordering" type="moduleorder" label="JFIELD_ORDERING_LABEL" description="JFIELD_ORDERING_DESC" linked="position" /> <field name="content" type="editor" label="COM_MODULES_FIELD_CONTENT_LABEL" description="COM_MODULES_FIELD_CONTENT_DESC" buttons="true" filter="JComponentHelper::filterText" hide="readmore,pagebreak,module" /> <field name="language" type="contentlanguage" label="JFIELD_LANGUAGE_LABEL" description="JFIELD_MODULE_LANGUAGE_DESC" > <option value="*">JALL</option> </field> <field name="assignment" type="hidden" /> <field name="assigned" type="hidden" /> <field name="asset_id" type="hidden" filter="unset" /> <field name="rules" type="rules" label="JFIELD_RULES_LABEL" translate_label="false" filter="rules" component="com_modules" section="module" validate="rules" /> </fieldset> </form> models/forms/moduleadmin.xml 0000604 00000006375 15245570476 0012223 0 ustar 00 <?xml version="1.0" encoding="utf-8"?> <form> <fieldset> <field name="id" type="number" label="JGLOBAL_FIELD_ID_LABEL" description="JGLOBAL_FIELD_ID_DESC" default="0" readonly="true" /> <field name="title" type="text" label="JGLOBAL_TITLE" description="COM_MODULES_FIELD_TITLE_DESC" class="input-xxlarge input-large-text" size="40" maxlength="100" required="true" /> <field name="note" type="text" label="COM_MODULES_FIELD_NOTE_LABEL" description="COM_MODULES_FIELD_NOTE_DESC" maxlength="255" size="40" class="span12" /> <field name="module" type="hidden" label="COM_MODULES_FIELD_MODULE_LABEL" description="COM_MODULES_FIELD_MODULE_DESC" readonly="readonly" size="20" /> <field name="showtitle" type="radio" label="COM_MODULES_FIELD_SHOWTITLE_LABEL" description="COM_MODULES_FIELD_SHOWTITLE_DESC" class="btn-group btn-group-yesno" default="1" size="1" > <option value="1">JSHOW</option> <option value="0">JHIDE</option> </field> <field name="published" type="list" label="JSTATUS" description="COM_MODULES_FIELD_PUBLISHED_DESC" class="chzn-color-state" default="1" size="1" > <option value="1">JPUBLISHED</option> <option value="0">JUNPUBLISHED</option> <option value="-2">JTRASHED</option> </field> <field name="publish_up" type="calendar" label="COM_MODULES_FIELD_PUBLISH_UP_LABEL" description="COM_MODULES_FIELD_PUBLISH_UP_DESC" filter="user_utc" translateformat="true" showtime="true" size="22" /> <field name="publish_down" type="calendar" label="COM_MODULES_FIELD_PUBLISH_DOWN_LABEL" description="COM_MODULES_FIELD_PUBLISH_DOWN_DESC" filter="user_utc" translateformat="true" showtime="true" size="22" /> <field name="client_id" type="hidden" label="COM_MODULES_FIELD_CLIENT_ID_LABEL" description="COM_MODULES_FIELD_CLIENT_ID_DESC" readonly="true" size="1" /> <field name="position" type="moduleposition" label="COM_MODULES_FIELD_POSITION_LABEL" description="COM_MODULES_FIELD_POSITION_DESC" default="" maxlength="50" /> <field name="access" type="accesslevel" label="JFIELD_ACCESS_LABEL" description="JFIELD_ACCESS_DESC" size="1" /> <field name="ordering" type="moduleorder" label="JFIELD_ORDERING_LABEL" description="JFIELD_ORDERING_DESC" linked="position" /> <field name="language" type="language" label="JFIELD_LANGUAGE_LABEL" description="JFIELD_MODULE_LANGUAGE_DESC" default="*" client="administrator" > <option value="*">JALL</option> </field> <field name="content" type="editor" label="COM_MODULES_FIELD_CONTENT_LABEL" description="COM_MODULES_FIELD_CONTENT_DESC" buttons="true" filter="JComponentHelper::filterText" hide="readmore,pagebreak,module" /> <field name="assignment" type="hidden" /> <field name="assigned" type="hidden" /> <field name="asset_id" type="hidden" filter="unset" /> <field name="rules" type="rules" label="JFIELD_RULES_LABEL" translate_label="false" filter="rules" component="com_modules" section="module" validate="rules" /> </fieldset> </form> models/forms/filter_modulesadmin.xml 0000604 00000006601 15245570476 0013743 0 ustar 00 <?xml version="1.0" encoding="utf-8"?> <form> <fieldset addfieldpath="/administrator/components/com_modules/models/fields" /> <field name="client_id" type="list" label="" filtermode="selector" layout="default" onchange="jQuery('#filter_position, #filter_module, #filter_language').val('');this.form.submit();" > <option value="0">JSITE</option> <option value="1">JADMINISTRATOR</option> </field> <fields name="filter"> <field name="search" type="text" inputmode="search" label="COM_MODULES_MODULES_FILTER_SEARCH_LABEL" description="COM_MODULES_MODULES_FILTER_SEARCH_DESC" hint="JSEARCH_FILTER" noresults="COM_MODULES_MSG_MANAGE_NO_MODULES" /> <field name="state" type="status" label="JSTATUS" filter="*,-2,0,1" onchange="this.form.submit();" > <option value="">JOPTION_SELECT_PUBLISHED</option> </field> <field name="position" type="modulesposition" label="COM_MODULES_FIELD_POSITION_LABEL" onchange="this.form.submit();" > <option value="">COM_MODULES_OPTION_SELECT_POSITION</option> </field> <field name="module" type="ModulesModule" label="COM_MODULES_OPTION_SELECT_MODULE" onchange="this.form.submit();" > <option value="">COM_MODULES_OPTION_SELECT_MODULE</option> </field> <field name="access" type="accesslevel" label="JOPTION_FILTER_ACCESS" description="JOPTION_FILTER_ACCESS_DESC" onchange="this.form.submit();" > <option value="">JOPTION_SELECT_ACCESS</option> </field> <field name="language" type="language" label="JOPTION_FILTER_LANGUAGE" description="JOPTION_FILTER_LANGUAGE_DESC" client="administrator" onchange="this.form.submit();" > <option value="">JOPTION_SELECT_LANGUAGE</option> <option value="*">JALL</option> </field> </fields> <fields name="list"> <field name="fullordering" type="list" label="JGLOBAL_SORT_BY" description="JGLOBAL_SORT_BY" statuses="*,0,1,-2" onchange="this.form.submit();" default="a.position ASC" validate="options" > <option value="">JGLOBAL_SORT_BY</option> <option value="a.ordering ASC">JGRID_HEADING_ORDERING_ASC</option> <option value="a.ordering DESC">JGRID_HEADING_ORDERING_DESC</option> <option value="a.published ASC">JSTATUS_ASC</option> <option value="a.published DESC">JSTATUS_DESC</option> <option value="a.title ASC">JGLOBAL_TITLE_ASC</option> <option value="a.title DESC">JGLOBAL_TITLE_DESC</option> <option value="a.position ASC">COM_MODULES_HEADING_POSITION_ASC</option> <option value="a.position DESC">COM_MODULES_HEADING_POSITION_DESC</option> <option value="name ASC">COM_MODULES_HEADING_MODULE_ASC</option> <option value="name DESC">COM_MODULES_HEADING_MODULE_DESC</option> <option value="ag.title ASC">JGRID_HEADING_ACCESS_ASC</option> <option value="ag.title DESC">JGRID_HEADING_ACCESS_DESC</option> <option value="a.language ASC" requires="adminlanguage">JGRID_HEADING_LANGUAGE_ASC</option> <option value="a.language DESC" requires="adminlanguage">JGRID_HEADING_LANGUAGE_DESC</option> <option value="a.id ASC">JGRID_HEADING_ID_ASC</option> <option value="a.id DESC">JGRID_HEADING_ID_DESC</option> </field> <field name="limit" type="limitbox" label="COM_MODULES_LIST_LIMIT" description="JFIELD_PLG_SEARCH_SEARCHLIMIT_DESC" class="input-mini" default="25" onchange="this.form.submit();" /> </fields> </form> models/module.php 0000604 00000066721 15245570476 0010054 0 ustar 00 <?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 */ defined('_JEXEC') or die; use Joomla\Registry\Registry; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; /** * Module model. * * @since 1.6 */ class ModulesModelModule extends JModelAdmin { /** * The type alias for this content type. * * @var string * @since 3.4 */ public $typeAlias = 'com_modules.module'; /** * @var string The prefix to use with controller messages. * @since 1.6 */ protected $text_prefix = 'COM_MODULES'; /** * @var string The help screen key for the module. * @since 1.6 */ protected $helpKey = 'JHELP_EXTENSIONS_MODULE_MANAGER_EDIT'; /** * @var string The help screen base URL for the module. * @since 1.6 */ protected $helpURL; /** * Batch copy/move command. If set to false, * the batch copy/move command is not supported * * @var string */ protected $batch_copymove = 'position_id'; /** * Allowed batch commands * * @var array */ protected $batch_commands = array( 'assetgroup_id' => 'batchAccess', 'language_id' => 'batchLanguage', ); /** * Constructor. * * @param array $config An optional associative array of configuration settings. */ public function __construct($config = array()) { $config = array_merge( array( 'event_after_delete' => 'onExtensionAfterDelete', 'event_after_save' => 'onExtensionAfterSave', 'event_before_delete' => 'onExtensionBeforeDelete', 'event_before_save' => 'onExtensionBeforeSave', 'events_map' => array( 'save' => 'extension', 'delete' => 'extension' ) ), $config ); parent::__construct($config); } /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication('administrator'); // Load the User state. $pk = $app->input->getInt('id'); if (!$pk) { if ($extensionId = (int) $app->getUserState('com_modules.add.module.extension_id')) { $this->setState('extension.id', $extensionId); } } $this->setState('module.id', $pk); // Load the parameters. $params = JComponentHelper::getParams('com_modules'); $this->setState('params', $params); } /** * Batch copy modules to a new position or current. * * @param integer $value The new value matching a module position. * @param array $pks An array of row IDs. * @param array $contexts An array of item contexts. * * @return boolean True if successful, false otherwise and internal error is set. * * @since 2.5 */ protected function batchCopy($value, $pks, $contexts) { // Set the variables $user = JFactory::getUser(); $table = $this->getTable(); $newIds = array(); foreach ($pks as $pk) { if ($user->authorise('core.create', 'com_modules')) { $table->reset(); $table->load($pk); // Set the new position if ($value == 'noposition') { $position = ''; } elseif ($value == 'nochange') { $position = $table->position; } else { $position = $value; } $table->position = $position; // Copy of the Asset ID $oldAssetId = $table->asset_id; // Alter the title if necessary $data = $this->generateNewTitle(0, $table->title, $table->position); $table->title = $data['0']; // Reset the ID because we are making a copy $table->id = 0; // Unpublish the new module $table->published = 0; if (!$table->store()) { $this->setError($table->getError()); return false; } // Get the new item ID $newId = $table->get('id'); // Add the new ID to the array $newIds[$pk] = $newId; // Now we need to handle the module assignments $db = $this->getDbo(); $query = $db->getQuery(true) ->select($db->quoteName('menuid')) ->from($db->quoteName('#__modules_menu')) ->where($db->quoteName('moduleid') . ' = ' . $pk); $db->setQuery($query); $menus = $db->loadColumn(); // Insert the new records into the table foreach ($menus as $menu) { $query->clear() ->insert($db->quoteName('#__modules_menu')) ->columns(array($db->quoteName('moduleid'), $db->quoteName('menuid'))) ->values($newId . ', ' . $menu); $db->setQuery($query); $db->execute(); } // Copy rules $query->clear() ->update($db->quoteName('#__assets', 't')) ->join('INNER', $db->quoteName('#__assets', 's') . ' ON ' . $db->quoteName('s.id') . ' = ' . $oldAssetId ) ->set($db->quoteName('t.rules') . ' = ' . $db->quoteName('s.rules')) ->where($db->quoteName('t.id') . ' = ' . $table->asset_id); $db->setQuery($query)->execute(); } else { $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE')); return false; } } // Clean the cache $this->cleanCache(); return $newIds; } /** * Batch move modules to a new position or current. * * @param integer $value The new value matching a module position. * @param array $pks An array of row IDs. * @param array $contexts An array of item contexts. * * @return boolean True if successful, false otherwise and internal error is set. * * @since 2.5 */ protected function batchMove($value, $pks, $contexts) { // Set the variables $user = JFactory::getUser(); $table = $this->getTable(); foreach ($pks as $pk) { if ($user->authorise('core.edit', 'com_modules')) { $table->reset(); $table->load($pk); // Set the new position if ($value == 'noposition') { $position = ''; } elseif ($value == 'nochange') { $position = $table->position; } else { $position = $value; } $table->position = $position; if (!$table->store()) { $this->setError($table->getError()); return false; } } else { $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); return false; } } // Clean the cache $this->cleanCache(); return true; } /** * Method to test whether a record can have its state edited. * * @param object $record A record object. * * @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component. * * @since 3.2 */ protected function canEditState($record) { // Check for existing module. if (!empty($record->id)) { return JFactory::getUser()->authorise('core.edit.state', 'com_modules.module.' . (int) $record->id); } // Default to component settings if module not known. return parent::canEditState($record); } /** * Method to delete rows. * * @param array &$pks An array of item ids. * * @return boolean Returns true on success, false on failure. * * @since 1.6 * @throws Exception */ public function delete(&$pks) { $dispatcher = JEventDispatcher::getInstance(); $pks = (array) $pks; $user = JFactory::getUser(); $table = $this->getTable(); $context = $this->option . '.' . $this->name; // Include the plugins for the on delete events. JPluginHelper::importPlugin($this->events_map['delete']); // Iterate the items to delete each one. foreach ($pks as $pk) { if ($table->load($pk)) { // Access checks. if (!$user->authorise('core.delete', 'com_modules.module.' . (int) $pk) || $table->published != -2) { JError::raiseWarning(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED')); return; } // Trigger the before delete event. $result = $dispatcher->trigger($this->event_before_delete, array($context, $table)); if (in_array(false, $result, true) || !$table->delete($pk)) { throw new Exception($table->getError()); } else { // Delete the menu assignments $db = $this->getDbo(); $query = $db->getQuery(true) ->delete('#__modules_menu') ->where('moduleid=' . (int) $pk); $db->setQuery($query); $db->execute(); // Trigger the after delete event. $dispatcher->trigger($this->event_after_delete, array($context, $table)); } // Clear module cache parent::cleanCache($table->module, $table->client_id); } else { throw new Exception($table->getError()); } } // Clear modules cache $this->cleanCache(); return true; } /** * Method to duplicate modules. * * @param array &$pks An array of primary key IDs. * * @return boolean|JException Boolean true on success, JException instance on error * * @since 1.6 * @throws Exception */ public function duplicate(&$pks) { $user = JFactory::getUser(); $db = $this->getDbo(); // Access checks. if (!$user->authorise('core.create', 'com_modules')) { throw new Exception(JText::_('JERROR_CORE_CREATE_NOT_PERMITTED')); } $table = $this->getTable(); foreach ($pks as $pk) { if ($table->load($pk, true)) { // Reset the id to create a new record. $table->id = 0; // Alter the title. $m = null; if (preg_match('#\((\d+)\)$#', $table->title, $m)) { $table->title = preg_replace('#\(\d+\)$#', '(' . ($m[1] + 1) . ')', $table->title); } $data = $this->generateNewTitle(0, $table->title, $table->position); $table->title = $data[0]; // Unpublish duplicate module $table->published = 0; if (!$table->check() || !$table->store()) { throw new Exception($table->getError()); } $query = $db->getQuery(true) ->select($db->quoteName('menuid')) ->from($db->quoteName('#__modules_menu')) ->where($db->quoteName('moduleid') . ' = ' . (int) $pk); $db->setQuery($query); $rows = $db->loadColumn(); foreach ($rows as $menuid) { $tuples[] = (int) $table->id . ',' . (int) $menuid; } } else { throw new Exception($table->getError()); } } if (!empty($tuples)) { // Module-Menu Mapping: Do it in one query $query = $db->getQuery(true) ->insert($db->quoteName('#__modules_menu')) ->columns($db->quoteName(array('moduleid', 'menuid'))) ->values($tuples); $db->setQuery($query); try { $db->execute(); } catch (RuntimeException $e) { return JError::raiseWarning(500, $e->getMessage()); } } // Clear modules cache $this->cleanCache(); return true; } /** * Method to change the title. * * @param integer $categoryId The id of the category. Not used here. * @param string $title The title. * @param string $position The position. * * @return array Contains the modified title. * * @since 2.5 */ protected function generateNewTitle($categoryId, $title, $position) { // Alter the title & alias $table = $this->getTable(); while ($table->load(array('position' => $position, 'title' => $title))) { $title = StringHelper::increment($title); } return array($title); } /** * Method to get the client object * * @return void * * @since 1.6 */ public function &getClient() { return $this->_client; } /** * 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 JForm A JForm object on success, false on failure * * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // The folder and element vars are passed when saving the form. if (empty($data)) { $item = $this->getItem(); $clientId = $item->client_id; $module = $item->module; $id = $item->id; } else { $clientId = ArrayHelper::getValue($data, 'client_id'); $module = ArrayHelper::getValue($data, 'module'); $id = ArrayHelper::getValue($data, 'id'); } // Add the default fields directory $baseFolder = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE; JForm::addFieldPath($baseFolder . '/modules' . '/' . $module . '/field'); // These variables are used to add data from the plugin XML files. $this->setState('item.client_id', $clientId); $this->setState('item.module', $module); // Get the form. if ($clientId == 1) { $form = $this->loadForm('com_modules.module.admin', 'moduleadmin', array('control' => 'jform', 'load_data' => $loadData), true); // Display language field to filter admin custom menus per language if (!JModuleHelper::isAdminMultilang()) { $form->setFieldAttribute('language', 'type', 'hidden'); } } else { $form = $this->loadForm('com_modules.module', 'module', array('control' => 'jform', 'load_data' => $loadData), true); } if (empty($form)) { return false; } $form->setFieldAttribute('position', 'client', $this->getState('item.client_id') == 0 ? 'site' : 'administrator'); $user = JFactory::getUser(); /** * Check for existing module * Modify the form based on Edit State access controls. */ if ($id != 0 && (!$user->authorise('core.edit.state', 'com_modules.module.' . (int) $id)) || ($id == 0 && !$user->authorise('core.edit.state', 'com_modules')) ) { // Disable fields for display. $form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('published', 'disabled', 'true'); $form->setFieldAttribute('publish_up', 'disabled', 'true'); $form->setFieldAttribute('publish_down', '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('published', 'filter', 'unset'); $form->setFieldAttribute('publish_up', 'filter', 'unset'); $form->setFieldAttribute('publish_down', '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() { $app = JFactory::getApplication(); // Check the session for previously entered form data. $data = $app->getUserState('com_modules.edit.module.data', array()); if (empty($data)) { $data = $this->getItem(); // Pre-select some filters (Status, Module Position, Language, Access Level) in edit form if those have been selected in Module Manager if (!$data->id) { $filters = (array) $app->getUserState('com_modules.modules.filter'); $data->set('published', $app->input->getInt('published', ((isset($filters['state']) && $filters['state'] !== '') ? $filters['state'] : null))); $data->set('position', $app->input->getInt('position', (!empty($filters['position']) ? $filters['position'] : null))); $data->set('language', $app->input->getString('language', (!empty($filters['language']) ? $filters['language'] : null))); $data->set('access', $app->input->getInt('access', (!empty($filters['access']) ? $filters['access'] : JFactory::getConfig()->get('access')))); } // Avoid to delete params of a second module opened in a new browser tab while new one is not saved yet. if (empty($data->params)) { // This allows us to inject parameter settings into a new module. $params = $app->getUserState('com_modules.add.module.params'); if (is_array($params)) { $data->set('params', $params); } } } $this->preprocessData('com_modules.module', $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. * * @since 1.6 */ public function getItem($pk = null) { $pk = (!empty($pk)) ? (int) $pk : (int) $this->getState('module.id'); $db = $this->getDbo(); if (!isset($this->_cache[$pk])) { // Get a row instance. $table = $this->getTable(); // Attempt to load the row. $return = $table->load($pk); // Check for a table object error. if ($return === false && $error = $table->getError()) { $this->setError($error); return false; } // Check if we are creating a new extension. if (empty($pk)) { if ($extensionId = (int) $this->getState('extension.id')) { $query = $db->getQuery(true) ->select('element, client_id') ->from('#__extensions') ->where('extension_id = ' . $extensionId) ->where('type = ' . $db->quote('module')); $db->setQuery($query); try { $extension = $db->loadObject(); } catch (RuntimeException $e) { $this->setError($e->getMessage()); return false; } if (empty($extension)) { $this->setError('COM_MODULES_ERROR_CANNOT_FIND_MODULE'); return false; } // Extension found, prime some module values. $table->module = $extension->element; $table->client_id = $extension->client_id; } else { JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_modules&view=modules', false)); return false; } } // Convert to the JObject before adding other data. $properties = $table->getProperties(1); $this->_cache[$pk] = ArrayHelper::toObject($properties, 'JObject'); // Convert the params field to an array. $registry = new Registry($table->params); $this->_cache[$pk]->params = $registry->toArray(); // Determine the page assignment mode. $query = $db->getQuery(true) ->select($db->quoteName('menuid')) ->from($db->quoteName('#__modules_menu')) ->where($db->quoteName('moduleid') . ' = ' . (int) $pk); $db->setQuery($query); $assigned = $db->loadColumn(); if (empty($pk)) { // If this is a new module, assign to all pages. $assignment = 0; } elseif (empty($assigned)) { // For an existing module it is assigned to none. $assignment = '-'; } else { if ($assigned[0] > 0) { $assignment = 1; } elseif ($assigned[0] < 0) { $assignment = -1; } else { $assignment = 0; } } $this->_cache[$pk]->assigned = $assigned; $this->_cache[$pk]->assignment = $assignment; // Get the module XML. $client = JApplicationHelper::getClientInfo($table->client_id); $path = JPath::clean($client->path . '/modules/' . $table->module . '/' . $table->module . '.xml'); if (file_exists($path)) { $this->_cache[$pk]->xml = simplexml_load_file($path); } else { $this->_cache[$pk]->xml = null; } } return $this->_cache[$pk]; } /** * 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) array('key' => $this->helpKey, 'url' => $this->helpURL); } /** * Returns a reference to the a 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 JTable A database object * * @since 1.6 */ public function getTable($type = 'Module', $prefix = 'JTable', $config = array()) { return JTable::getInstance($type, $prefix, $config); } /** * Prepare and sanitise the table prior to saving. * * @param JTable $table The database object * * @return void * * @since 1.6 */ protected function prepareTable($table) { $table->title = htmlspecialchars_decode($table->title, ENT_QUOTES); $table->position = trim($table->position); } /** * Method to preprocess the form * * @param JForm $form A form object. * @param mixed $data The data expected for the form. * @param string $group The name of the plugin group to import (defaults to "content"). * * @return void * * @since 1.6 * @throws Exception if there is an error loading the form. */ protected function preprocessForm(JForm $form, $data, $group = 'content') { jimport('joomla.filesystem.path'); $lang = JFactory::getLanguage(); $clientId = $this->getState('item.client_id'); $module = $this->getState('item.module'); $client = JApplicationHelper::getClientInfo($clientId); $formFile = JPath::clean($client->path . '/modules/' . $module . '/' . $module . '.xml'); // Load the core and/or local language file(s). $lang->load($module, $client->path, null, false, true) || $lang->load($module, $client->path . '/modules/' . $module, null, false, true); if (file_exists($formFile)) { // Get the module form. if (!$form->loadFile($formFile, false, '//config')) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } // Attempt to load the xml file. if (!$xml = simplexml_load_file($formFile)) { throw new Exception(JText::_('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; } } // Load the default advanced params JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/com_modules/models/forms'); $form->loadFile('advanced', false); // Trigger the default form events. parent::preprocessForm($form, $data, $group); } /** * Loads ContentHelper for filters before validating data. * * @param object $form The form to validate against. * @param array $data The data to validate. * @param string $group The name of the group(defaults to null). * * @return mixed Array of filtered data if valid, false otherwise. * * @since 1.1 */ public function validate($form, $data, $group = null) { JLoader::register('ContentHelper', JPATH_ADMINISTRATOR . '/components/com_content/helpers/content.php'); if (!JFactory::getUser()->authorise('core.admin', 'com_modules')) { if (isset($data['rules'])) { unset($data['rules']); } } return parent::validate($form, $data, $group); } /** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $dispatcher = JEventDispatcher::getInstance(); $input = JFactory::getApplication()->input; $table = $this->getTable(); $pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('module.id'); $isNew = true; $context = $this->option . '.' . $this->name; // Include the plugins for the save event. JPluginHelper::importPlugin($this->events_map['save']); // Load the row if saving an existing record. if ($pk > 0) { $table->load($pk); $isNew = false; } // Alter the title and published state for Save as Copy if ($input->get('task') == 'save2copy') { $orig_table = clone $this->getTable(); $orig_table->load((int) $input->getInt('id')); $data['published'] = 0; if ($data['title'] == $orig_table->title) { $data['title'] = StringHelper::increment($data['title']); } } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Prepare the row for saving $this->prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the before save event. $result = $dispatcher->trigger($this->event_before_save, array($context, &$table, $isNew)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } // Process the menu link mappings. $assignment = isset($data['assignment']) ? $data['assignment'] : 0; // Delete old module to menu item associations $db = $this->getDbo(); $query = $db->getQuery(true) ->delete('#__modules_menu') ->where('moduleid = ' . (int) $table->id); $db->setQuery($query); try { $db->execute(); } catch (RuntimeException $e) { $this->setError($e->getMessage()); return false; } // If the assignment is numeric, then something is selected (otherwise it's none). if (is_numeric($assignment)) { // Variable is numeric, but could be a string. $assignment = (int) $assignment; // Logic check: if no module excluded then convert to display on all. if ($assignment == -1 && empty($data['assigned'])) { $assignment = 0; } // Check needed to stop a module being assigned to `All` // and other menu items resulting in a module being displayed twice. if ($assignment === 0) { // Assign new module to `all` menu item associations. $query->clear() ->insert('#__modules_menu') ->columns(array($db->quoteName('moduleid'), $db->quoteName('menuid'))) ->values((int) $table->id . ', 0'); $db->setQuery($query); try { $db->execute(); } catch (RuntimeException $e) { $this->setError($e->getMessage()); return false; } } elseif (!empty($data['assigned'])) { // Get the sign of the number. $sign = $assignment < 0 ? -1 : 1; $query->clear() ->insert($db->quoteName('#__modules_menu')) ->columns($db->quoteName(array('moduleid', 'menuid'))); foreach ($data['assigned'] as &$pk) { $query->values((int) $table->id . ',' . (int) $pk * $sign); } $db->setQuery($query); try { $db->execute(); } catch (RuntimeException $e) { $this->setError($e->getMessage()); return false; } } } // Trigger the after save event. $dispatcher->trigger($this->event_after_save, array($context, &$table, $isNew)); // Compute the extension id of this module in case the controller wants it. $query->clear() ->select($db->quoteName('extension_id')) ->from($db->quoteName('#__extensions', 'e')) ->join( 'LEFT', $db->quoteName('#__modules', 'm') . ' ON ' . $db->quoteName('e.client_id') . ' = ' . (int) $table->client_id . ' AND ' . $db->quoteName('e.element') . ' = ' . $db->quoteName('m.module') ) ->where($db->quoteName('m.id') . ' = ' . (int) $table->id); $db->setQuery($query); try { $extensionId = $db->loadResult(); } catch (RuntimeException $e) { JError::raiseWarning(500, $e->getMessage()); return false; } $this->setState('module.extension_id', $extensionId); $this->setState('module.id', $table->id); // Clear modules cache $this->cleanCache(); // Clean module cache parent::cleanCache($table->module, $table->client_id); return true; } /** * 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 add to ordering queries. * * @since 1.6 */ protected function getReorderConditions($table) { $condition = array(); $condition[] = 'client_id = ' . (int) $table->client_id; $condition[] = 'position = ' . $this->_db->quote($table->position); return $condition; } /** * Custom clean cache method for different clients * * @param string $group The name of the plugin group to import (defaults to null). * @param integer $clientId The client ID. [optional] * * @return void * * @since 1.6 */ protected function cleanCache($group = null, $clientId = 0) { parent::cleanCache('com_modules', $this->getClient()); } } models/modules.php 0000604 00000032241 15245570476 0010225 0 ustar 00 <?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 */ defined('_JEXEC') or die; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; /** * Modules Component Module Model * * @since 1.5 */ class ModulesModelModules extends JModelList { /** * Constructor. * * @param array $config An optional associative array of configuration settings. * * @see JController * @since 1.6 */ public function __construct($config = array()) { if (empty($config['filter_fields'])) { $config['filter_fields'] = array( '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 = JFactory::getApplication(); $layout = $app->input->get('layout', '', 'cmd'); // Adjust the context to support modal layouts. if ($layout) { $this->context .= '.' . $layout; } // Load the filter state. $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string')); $this->setState('filter.position', $this->getUserStateFromRequest($this->context . '.filter.position', 'filter_position', '', 'string')); $this->setState('filter.module', $this->getUserStateFromRequest($this->context . '.filter.module', 'filter_module', '', 'string')); $this->setState('filter.menuitem', $this->getUserStateFromRequest($this->context . '.filter.menuitem', 'filter_menuitem', '', 'cmd')); $this->setState('filter.access', $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', '', 'cmd')); // 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); } // If in backend (modal or not) we get the same fields from the user request. else { $this->setState('filter.language', $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '', 'string')); $this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string')); } // 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, array (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 = JComponentHelper::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 string $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'); // If ordering by fields that need translate we need to sort the array of objects after translating them. if (in_array($listOrder, array('pages', 'name'))) { // Fetch the results. $this->_db->setQuery($query); $result = $this->_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($this->_db->quoteName('a.position') . ' ASC') ->order($this->_db->quoteName($listOrder) . ' ' . $this->_db->escape($listDirn)); } elseif ($listOrder === 'a.position') { $query->order($this->_db->quoteName($listOrder) . ' ' . $this->_db->escape($listDirn)) ->order($this->_db->quoteName('a.ordering') . ' ASC'); } else { $query->order($this->_db->quoteName($listOrder) . ' ' . $this->_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 array The array of translated objects */ protected function translate(&$items) { $lang = JFactory::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, null, false, true) || $lang->load("$extension.sys", $source, null, false, true); $item->name = JText::_($item->name); if (is_null($item->pages)) { $item->pages = JText::_('JNONE'); } elseif ($item->pages < 0) { $item->pages = JText::_('COM_MODULES_ASSIGNED_VARIES_EXCEPT'); } elseif ($item->pages > 0) { $item->pages = JText::_('COM_MODULES_ASSIGNED_VARIES_ONLY'); } else { $item->pages = JText::_('JALL'); } } } /** * Build an SQL query to load the list data. * * @return JDatabaseQuery */ protected function getListQuery() { $app = JFactory::getApplication(); // Create a new query object. $db = $this->getDbo(); $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 = $this->getState('client_id'); $query->where($db->quoteName('a.client_id') . ' = ' . (int) $clientId . ' AND ' . $db->quoteName('e.client_id') . ' = ' . (int) $clientId); // Filter by current user access level. $user = JFactory::getUser(); // Get the current user for authorisation checks if ($user->authorise('core.admin') !== true) { $groups = implode(',', $user->getAuthorisedViewLevels()); $query->where('a.access IN (' . $groups . ')'); } // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where($db->quoteName('a.access') . ' = ' . (int) $access); } // Filter by published state. $state = $this->getState('filter.state'); if (is_numeric($state)) { $query->where($db->quoteName('a.published') . ' = ' . (int) $state); } elseif ($state === '') { $query->where($db->quoteName('a.published') . ' IN (0, 1)'); } // Filter by position. if ($position = $this->getState('filter.position')) { $query->where($db->quoteName('a.position') . ' = ' . $db->quote(($position === 'none') ? '' : $position)); } // Filter by module. if ($module = $this->getState('filter.module')) { $query->where($db->quoteName('a.module') . ' = ' . $db->quote($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'); } // If user selected the modules assigned to some particular page (menu item). else { // 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. $subQuery2 = $db->getQuery(true); $subQuery2->select($db->quoteName('moduleid')) ->from($db->quoteName('#__modules_menu')) ->where($db->quoteName('menuid') . ' = ' . (int) $menuItemId); // 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') . ' = -' . (int) $menuItemId); // 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 . ')) )' ); } } // Filter by search in title or note or id:. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where($db->quoteName('a.id') . ' = ' . (int) substr($search, 3)); } else { $search = $db->quote('%' . StringHelper::strtolower($search) . '%'); $query->where('(LOWER(a.title) LIKE ' . $search . ' OR LOWER(a.note) LIKE ' . $search . ')'); } } // Filter on the language. if ($language = $this->getState('filter.language')) { if ($language === 'current') { $query->where($db->quoteName('a.language') . ' IN (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); } else { $query->where($db->quoteName('a.language') . ' = ' . $db->quote($language)); } } return $query; } } models/fields/modulesposition.php 0000604 00000001711 15245570476 0013256 0 ustar 00 <?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 */ defined('_JEXEC') or die; JLoader::register('ModulesHelper', JPATH_ADMINISTRATOR . '/components/com_modules/helpers/modules.php'); JFormHelper::loadFieldClass('list'); /** * Modules Position field. * * @since 3.4.2 */ class JFormFieldModulesPosition extends JFormFieldList { /** * The form field type. * * @var string * @since 3.4.2 */ protected $type = 'ModulesPosition'; /** * Method to get the field options. * * @return array The field option objects. * * @since 3.4.2 */ public function getOptions() { $options = ModulesHelper::getPositions(JFactory::getApplication()->getUserState('com_modules.modules.client_id', 0)); return array_merge(parent::getOptions(), $options); } } models/fields/modulesmodule.php 0000604 00000001701 15245570476 0012676 0 ustar 00 <?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 */ defined('_JEXEC') or die; JLoader::register('ModulesHelper', JPATH_ADMINISTRATOR . '/components/com_modules/helpers/modules.php'); JFormHelper::loadFieldClass('list'); /** * Modules Module field. * * @since 3.4.2 */ class JFormFieldModulesModule extends JFormFieldList { /** * The form field type. * * @var string * @since 3.4.2 */ protected $type = 'ModulesModule'; /** * Method to get the field options. * * @return array The field option objects. * * @since 3.4.2 */ public function getOptions() { $options = ModulesHelper::getModules(JFactory::getApplication()->getUserState('com_modules.modules.client_id', 0)); return array_merge(parent::getOptions(), $options); } } models/positions.php 0000604 00000014256 15245570476 0010612 0 ustar 00 <?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 */ defined('_JEXEC') or die; /** * Modules Component Positions Model * * @since 1.6 */ class ModulesModelPositions extends JModelList { /** * Constructor. * * @param array $config An optional associative array of configuration settings. * * @see JController * @since 1.6 */ public function __construct($config = array()) { if (empty($config['filter_fields'])) { $config['filter_fields'] = array( '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 = 'value', $direction = 'asc') { $app = JFactory::getApplication('administrator'); // Load the filter state. $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); $this->setState('filter.search', $search); $state = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string'); $this->setState('filter.state', $state); $template = $this->getUserStateFromRequest($this->context . '.filter.template', 'filter_template', '', 'string'); $this->setState('filter.template', $template); $type = $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type', '', 'string'); $this->setState('filter.type', $type); // Special case for the client id. $clientId = (int) $this->getUserStateFromRequest($this->context . '.client_id', 'client_id', 0, 'int'); $clientId = (!in_array((int) $clientId, array (0, 1))) ? 0 : (int) $clientId; $this->setState('client_id', $clientId); // Load the parameters. $params = JComponentHelper::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 = JFactory::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 = JApplicationHelper::getClientInfo($clientId); if ($type != 'template') { // Get the database object and a new query object. $query = $this->_db->getQuery(true) ->select('DISTINCT(position) as value') ->from('#__modules') ->where($this->_db->quoteName('client_id') . ' = ' . (int) $clientId); if ($search) { $search = $this->_db->quote('%' . str_replace(' ', '%', $this->_db->escape(trim($search), true) . '%')); $query->where('position LIKE ' . $search); } $this->_db->setQuery($query); try { $positions = $this->_db->loadObjectList('value'); } catch (RuntimeException $e) { $this->setError($e->getMessage()); return false; } foreach ($positions as $value => $position) { $positions[$value] = array(); } } else { $positions = array(); } // Load the positions from the installed templates. foreach (ModulesHelper::getTemplates($clientId) as $template) { $path = JPath::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, null, false, true) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, true); 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] = array(); } $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; } } models/select.php 0000604 00000007674 15245570476 0010050 0 ustar 00 <?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 */ defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; /** * Module model. * * @since 1.6 */ class ModulesModelSelect extends JModelList { /** * 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 = JFactory::getApplication('administrator'); // Load the filter state. $clientId = $app->getUserState('com_modules.modules.client_id', 0); $this->setState('client_id', (int) $clientId); // Load the parameters. $params = JComponentHelper::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 JDatabaseQuery */ protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $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') . ' AS a'); // Filter by module $query->where('a.type = ' . $db->quote('module')); // Filter by client. $clientId = $this->getState('client_id'); $query->where('a.client_id = ' . (int) $clientId); // Filter by enabled $query->where('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 = JApplicationHelper::getClientInfo($this->getState('client_id', 0)); $lang = JFactory::getLanguage(); // Loop through the results to add the XML metadata, // and load language support. foreach ($items as &$item) { $path = JPath::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, null, false, true) || $lang->load($item->module . '.sys', $client->path . '/modules/' . $item->module, null, false, true); $item->name = JText::_($item->name); if (isset($item->xml) && $text = trim($item->xml->description)) { $item->desc = JText::_($text); } else { $item->desc = JText::_('COM_MODULES_NODESCRIPTION'); } } $items = ArrayHelper::sortObjects($items, 'name', 1, true, true); // TODO: Use the cached XML from the extensions table? return $items; } } config.xml 0000604 00000002236 15245570476 0006551 0 ustar 00 <?xml version="1.0" encoding="utf-8"?> <config> <fieldset name="modules" label="COM_MODULES_GENERAL" description="COM_MODULES_GENERAL_FIELDSET_DESC" > <field name="redirect_edit" type="list" class="advancedSelect" default="site" label="COM_MODULES_REDIRECT_EDIT_LABEL" description="COM_MODULES_REDIRECT_EDIT_DESC" > <option value="admin">JADMINISTRATOR</option> <option value="site">JSITE</option> </field> </fieldset> <fieldset name="admin_modules" label="COM_MODULES_ADMIN_LANG_FILTER_FIELDSET_LABEL" > <field name="adminlangfilter" type="radio" label="COM_MODULES_ADMIN_LANG_FILTER_LABEL" description="COM_MODULES_ADMIN_LANG_FILTER_DESC" class="btn-group btn-group-yesno" default="0" filter="integer" > <option value="1">JYES</option> <option value="0">JNO</option> </field> </fieldset> <fieldset name="permissions" label="JCONFIG_PERMISSIONS_LABEL" description="JCONFIG_PERMISSIONS_DESC" > <field name="rules" type="rules" label="JCONFIG_PERMISSIONS_LABEL" filter="rules" validate="rules" component="com_modules" section="component" /> </fieldset> </config> access.xml 0000604 00000002473 15245570476 0006550 0 ustar 00 <?xml version="1.0" encoding="utf-8" ?> <access component="com_modules"> <section name="component"> <action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" /> <action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" /> <action name="core.create" title="JACTION_CREATE" description="JACTION_CREATE_COMPONENT_DESC" /> <action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" /> <action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" /> <action name="core.edit.state" title="JACTION_EDITSTATE" description="JACTION_EDITSTATE_COMPONENT_DESC" /> <action name="module.edit.frontend" title="COM_MODULES_ACTION_EDITFRONTEND" description="COM_MODULES_ACTION_EDITFRONTEND_COMPONENT_DESC" /> </section> <section name="module"> <action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" /> <action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" /> <action name="core.edit.state" title="JACTION_EDITSTATE" description="JACTION_EDITSTATE_COMPONENT_DESC" /> <action name="module.edit.frontend" title="COM_MODULES_ACTION_EDITFRONTEND" description="COM_MODULES_ACTION_EDITFRONTEND_COMPONENT_DESC" /> </section> </access>