diff --git a/administrator/components/com_plugins/controller.php b/administrator/components/com_plugins/controller.php index 3ac7acbcc94d1..4608bfbe7c165 100644 --- a/administrator/components/com_plugins/controller.php +++ b/administrator/components/com_plugins/controller.php @@ -21,15 +21,16 @@ class PluginsController extends JControllerLegacy /** * Method to display a view. * - * @param boolean If true, the view output will be cached - * @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. + * @param boolean $cachable If true, the view output will be cached + * @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. * * @return JController This object to support chaining. + * * @since 1.5 */ public function display($cachable = false, $urlparams = false) { - require_once JPATH_COMPONENT.'/helpers/plugins.php'; + require_once JPATH_COMPONENT . '/helpers/plugins.php'; // Load the submenu. PluginsHelper::addSubmenu($this->input->get('view', 'plugins')); diff --git a/administrator/components/com_plugins/controllers/plugins.php b/administrator/components/com_plugins/controllers/plugins.php index f5e148ed4d79c..8b6de0177ff4d 100644 --- a/administrator/components/com_plugins/controllers/plugins.php +++ b/administrator/components/com_plugins/controllers/plugins.php @@ -32,6 +32,7 @@ class PluginsControllerPlugins extends JControllerAdmin public function getModel($name = 'Plugin', $prefix = 'PluginsModel', $config = array('ignore_request' => true)) { $model = parent::getModel($name, $prefix, $config); + return $model; } } diff --git a/administrator/components/com_plugins/helpers/plugins.php b/administrator/components/com_plugins/helpers/plugins.php index 12b7532ab67a7..3a4c6149dae84 100644 --- a/administrator/components/com_plugins/helpers/plugins.php +++ b/administrator/components/com_plugins/helpers/plugins.php @@ -23,7 +23,9 @@ class PluginsHelper /** * Configure the Linkbar. * - * @param string The name of the active view. + * @param string $vName The name of the active view. + * + * @return void */ public static function addSubmenu($vName) { @@ -39,10 +41,10 @@ public static function addSubmenu($vName) */ public static function getActions() { - // Log usage of deprecated function + // Log usage of deprecated function. JLog::add(__METHOD__ . '() is deprecated, use JHelperContent::getActions() with new arguments order instead.', JLog::WARNING, 'deprecated'); - // Get list of actions + // Get list of actions. $result = JHelperContent::getActions('com_plugins'); return $result; @@ -91,12 +93,21 @@ public static function folderOptions() return $options; } + /** + * Parse the template file. + * + * @param string $templateBaseDir Base path to the template directory. + * @param string $templateDir Template directory. + * + * @return JObject + */ public function parseXMLTemplateFile($templateBaseDir, $templateDir) { $data = new JObject; - // Check of the xml file exists + // Check of the xml file exists. $filePath = JPath::clean($templateBaseDir . '/templates/' . $templateDir . '/templateDetails.xml'); + if (is_file($filePath)) { $xml = JInstaller::parseXMLInstallFile($filePath); diff --git a/administrator/components/com_plugins/models/fields/pluginordering.php b/administrator/components/com_plugins/models/fields/pluginordering.php index ab02d2572fca2..d707c2b612f47 100644 --- a/administrator/components/com_plugins/models/fields/pluginordering.php +++ b/administrator/components/com_plugins/models/fields/pluginordering.php @@ -12,7 +12,7 @@ JFormHelper::loadFieldClass('ordering'); /** - * Supports an HTML select list of plugins + * Supports an HTML select list of plugins. * * @package Joomla.Administrator * @subpackage com_plugins @@ -31,7 +31,7 @@ class JFormFieldPluginordering extends JFormFieldOrdering /** * Builds the query for the ordering list. * - * @return JDatabaseQuery The query for the ordering form field + * @return JDatabaseQuery The query for the ordering form field. */ protected function getQuery() { @@ -40,7 +40,15 @@ protected function getQuery() // Build the query for the ordering list. $query = $db->getQuery(true) - ->select(array($db->quoteName('ordering', 'value'), $db->quoteName('name', 'text'), $db->quoteName('type'), $db->quote('folder'), $db->quote('extension_id'))) + ->select( + array( + $db->quoteName('ordering', 'value'), + $db->quoteName('name', 'text'), + $db->quoteName('type'), + $db->quote('folder'), + $db->quote('extension_id') + ) + ) ->from($db->quoteName('#__extensions')) ->where('(type =' . $db->quote('plugin') . 'AND folder=' . $db->quote($folder) . ')') ->order('ordering'); @@ -51,7 +59,7 @@ protected function getQuery() /** * Retrieves the current Item's Id. * - * @return integer The current item ID + * @return integer The current item ID. */ protected function getItemId() { diff --git a/administrator/components/com_plugins/models/plugin.php b/administrator/components/com_plugins/models/plugin.php index 3a4f8513649c4..15b403e6a2940 100644 --- a/administrator/components/com_plugins/models/plugin.php +++ b/administrator/components/com_plugins/models/plugin.php @@ -53,8 +53,9 @@ class PluginsModelPlugin extends JModelAdmin * * @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 + * + * @return JForm A JForm object on success, false on failure. + * * @since 1.6 */ public function getForm($data = array(), $loadData = true) @@ -104,6 +105,7 @@ public function getForm($data = array(), $loadData = true) * 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() @@ -124,7 +126,7 @@ protected function loadFormData() /** * Method to get a single record. * - * @param integer The id of the primary key. + * @param integer $pk The id of the primary key. * * @return mixed Object on success, false on failure. */ @@ -146,6 +148,7 @@ public function getItem($pk = null) if ($return === false && $table->getError()) { $this->setError($table->getError()); + return $false; } @@ -175,13 +178,14 @@ public function getItem($pk = null) } /** - * Returns a reference to the a Table object, always creating it. + * 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. * - * @param type The table type to instantiate - * @param string A prefix for the table class name. Optional. - * @param array Configuration array for model. Optional. * @return JTable A database object - */ + */ public function getTable($type = 'Extension', $prefix = 'JTable', $config = array()) { return JTable::getInstance($type, $prefix, $config); @@ -193,6 +197,7 @@ public function getTable($type = 'Extension', $prefix = 'JTable', $config = arra * Note. Calling getState in this method will result in recursion. * * @return void + * * @since 1.6 */ protected function populateState() @@ -208,9 +213,14 @@ protected function populateState() } /** - * @param object A form object. - * @param mixed The data expected for the form. + * Preprocess the form. + * + * @param JForm $form A form object. + * @param mixed $data The data expected for the form. + * @param string $group Cache group name. + * * @return mixed True if successful. + * * @throws Exception if there is an error in the form event. * @since 1.6 */ @@ -245,6 +255,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') } $formFile = JPath::clean(JPATH_PLUGINS . '/' . $folder . '/' . $element . '/' . $element . '.xml'); + if (!file_exists($formFile)) { throw new Exception(JText::sprintf('COM_PLUGINS_ERROR_FILE_NOT_FOUND', $element . '.xml')); @@ -271,6 +282,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') // Get the help data from the XML file if present. $help = $xml->xpath('/extension/help'); + if (!empty($help)) { $helpKey = trim((string) $help[0]['key']); @@ -287,8 +299,10 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') /** * A protected method to get a set of ordering conditions. * - * @param object A record object. + * @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) @@ -296,14 +310,17 @@ protected function getReorderConditions($table) $condition = array(); $condition[] = 'type = ' . $this->_db->quote($table->type); $condition[] = 'folder = ' . $this->_db->quote($table->folder); + return $condition; } /** * Override method to save the form data. * - * @param array The form data. + * @param array $data The form data. + * * @return boolean True on success. + * * @since 1.6 */ public function save($data) @@ -311,7 +328,7 @@ public function save($data) // Load the extension plugin group. JPluginHelper::importPlugin('extension'); - // Setup type + // Setup type. $data['type'] = 'plugin'; return parent::save($data); @@ -321,6 +338,7 @@ public function 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() @@ -329,7 +347,12 @@ public function getHelp() } /** - * Custom clean cache method, plugins are cached in 2 places for different clients + * Custom clean cache method, plugins are cached in 2 places for different clients. + * + * @param string $group Cache group name. + * @param integer $client_id Application client id. + * + * @return void * * @since 1.6 */ diff --git a/administrator/components/com_plugins/models/plugins.php b/administrator/components/com_plugins/models/plugins.php index 98ddf9617d43d..04837b5c7d633 100644 --- a/administrator/components/com_plugins/models/plugins.php +++ b/administrator/components/com_plugins/models/plugins.php @@ -21,7 +21,8 @@ class PluginsModelPlugins extends JModelList /** * Constructor. * - * @param array An optional associative array of configuration settings. + * @param array $config An optional associative array of configuration settings. + * * @see JController * @since 1.6 */ @@ -92,7 +93,7 @@ protected function populateState($ordering = null, $direction = null) * different modules that might need different sets of data or different * ordering requirements. * - * @param string A prefix for the store id. + * @param string $id A prefix for the store id. * * @return string A store id. */ @@ -109,25 +110,29 @@ protected function getStoreId($id = '') } /** - * Returns an object list + * Returns an object list. + * + * @param JDatabaseQuery $query A database query object. + * @param integer $limitstart Offset. + * @param integer $limit The number of records. * - * @param string The query - * @param int Offset - * @param int The number of records * @return array */ protected function _getList($query, $limitstart = 0, $limit = 0) { $search = $this->getState('filter.search'); $ordering = $this->getState('list.ordering', 'ordering'); + if ($ordering == 'name' || (!empty($search) && stripos($search, 'id:') !== 0)) { $this->_db->setQuery($query); $result = $this->_db->loadObjectList(); $this->translate($result); + if (!empty($search)) { $search = str_replace(' ', '.*', preg_quote(trim($search), '/')); + foreach ($result as $i => $item) { if (!preg_match("/$search/i", $item->name)) @@ -142,11 +147,13 @@ protected function _getList($query, $limitstart = 0, $limit = 0) $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 ? $limit : null); } else @@ -156,23 +163,27 @@ protected function _getList($query, $limitstart = 0, $limit = 0) $query->order('a.folder ASC'); $ordering = 'a.ordering'; } + $query->order($this->_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 + * Translate a list of objects. * - * @param array The array of objects - * @return array The array of translated objects + * @param array &$items The array of objects. + * + * @return array The array of translated objects. */ protected function translate(&$items) { @@ -224,8 +235,9 @@ protected function getListQuery() $query->where('a.access = ' . (int) $access); } - // Filter by published state + // Filter by published state. $published = $this->getState('filter.enabled'); + if (is_numeric($published)) { $query->where('a.enabled = ' . (int) $published); @@ -235,7 +247,7 @@ protected function getListQuery() $query->where('(a.enabled IN (0, 1))'); } - // Filter by state + // Filter by state. $query->where('a.state >= 0'); // Filter by folder. @@ -244,8 +256,9 @@ protected function getListQuery() $query->where('a.folder = ' . $db->quote($folder)); } - // Filter by search in name or id + // Filter by search in name or id. $search = $this->getState('filter.search'); + if (!empty($search)) { if (stripos($search, 'id:') === 0) diff --git a/administrator/components/com_plugins/views/plugin/view.html.php b/administrator/components/com_plugins/views/plugin/view.html.php index f5aa4765d5da4..4f3707fa135fb 100644 --- a/administrator/components/com_plugins/views/plugin/view.html.php +++ b/administrator/components/com_plugins/views/plugin/view.html.php @@ -25,7 +25,11 @@ class PluginsViewPlugin extends JViewLegacy protected $state; /** - * Display the view + * Display the view. + * + * @param string $tpl The name of the template file to parse; automatically searches through the template paths. + * + * @return mixed A string if successful, otherwise a Error object. */ public function display($tpl = null) { @@ -37,6 +41,7 @@ public function display($tpl = null) if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); + return false; } @@ -47,6 +52,8 @@ public function display($tpl = null) /** * Add the page title and toolbar. * + * @return void + * * @since 1.6 */ protected function addToolbar() @@ -63,13 +70,15 @@ protected function addToolbar() JToolbarHelper::apply('plugin.apply'); JToolbarHelper::save('plugin.save'); } + JToolbarHelper::cancel('plugin.cancel', 'JTOOLBAR_CLOSE'); JToolbarHelper::divider(); - // Get the help information for the plugin item. + // Get the help information for the plugin item. $lang = JFactory::getLanguage(); $help = $this->get('Help'); + if ($lang->hasKey($help->url)) { $debug = $lang->setDebug(false); @@ -80,6 +89,7 @@ protected function addToolbar() { $url = null; } + JToolbarHelper::help($help->key, false, $url); } } diff --git a/administrator/components/com_plugins/views/plugins/view.html.php b/administrator/components/com_plugins/views/plugins/view.html.php index 6c3aedaefd6e8..3d2326ad145e1 100644 --- a/administrator/components/com_plugins/views/plugins/view.html.php +++ b/administrator/components/com_plugins/views/plugins/view.html.php @@ -25,7 +25,11 @@ class PluginsViewPlugins extends JViewLegacy protected $state; /** - * Display the view + * Display the view. + * + * @param string $tpl The name of the template file to parse; automatically searches through the template paths. + * + * @return mixed A string if successful, otherwise a Error object. */ public function display($tpl = null) { @@ -37,10 +41,11 @@ public function display($tpl = null) if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); + return false; } - // Check if there are no matching items + // Check if there are no matching items. if (!count($this->items)) { JFactory::getApplication()->enqueueMessage( @@ -56,6 +61,8 @@ public function display($tpl = null) /** * Add the page title and toolbar. * + * @return void + * * @since 1.6 */ protected function addToolbar() @@ -86,31 +93,30 @@ protected function addToolbar() JHtmlSidebar::setAction('index.php?option=com_plugins&view=plugins'); JHtmlSidebar::addFilter( - JText::_('JOPTION_SELECT_PUBLISHED'), - 'filter_enabled', - JHtml::_('select.options', PluginsHelper::publishedOptions(), 'value', 'text', $this->state->get('filter.enabled'), true) + JText::_('JOPTION_SELECT_PUBLISHED'), + 'filter_enabled', + JHtml::_('select.options', PluginsHelper::publishedOptions(), 'value', 'text', $this->state->get('filter.enabled'), true) ); JHtmlSidebar::addFilter( - JText::_('COM_PLUGINS_OPTION_FOLDER'), - 'filter_folder', - JHtml::_('select.options', PluginsHelper::folderOptions(), 'value', 'text', $this->state->get('filter.folder')) + JText::_('COM_PLUGINS_OPTION_FOLDER'), + 'filter_folder', + JHtml::_('select.options', PluginsHelper::folderOptions(), 'value', 'text', $this->state->get('filter.folder')) ); JHtmlSidebar::addFilter( - JText::_('JOPTION_SELECT_ACCESS'), - 'filter_access', - JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text', $this->state->get('filter.access')) + JText::_('JOPTION_SELECT_ACCESS'), + 'filter_access', + JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text', $this->state->get('filter.access')) ); $this->sidebar = JHtmlSidebar::render(); - } /** - * Returns an array of fields the table can be sorted by + * Returns an array of fields the table can be sorted by. * - * @return array Array containing the field name to sort by as the key and display text as value + * @return array Array containing the field name to sort by as the key and display text as value. * * @since 3.0 */