From b222a8dcdacb38efd16968137db49583b965f508 Mon Sep 17 00:00:00 2001 From: Thomas Hunziker Date: Sat, 21 Jan 2017 20:08:59 +0100 Subject: [PATCH 1/5] Properly merge tag params (#13643) * Properly merge tag params * Fixing a typo and yet another bug (wrong parameter read) --- components/com_tags/views/tag/view.html.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/components/com_tags/views/tag/view.html.php b/components/com_tags/views/tag/view.html.php index 573b5d1cba47c..9b4cb6168f8fa 100644 --- a/components/com_tags/views/tag/view.html.php +++ b/components/com_tags/views/tag/view.html.php @@ -132,6 +132,9 @@ public function display($tpl = null) $active = $app->getMenu()->getActive(); $temp = clone $this->params; + // Convert item params to a Registry object + $item[0]->params = new Registry($item[0]->params); + // Check to see which parameters should take priority if ($active) { @@ -140,9 +143,9 @@ public function display($tpl = null) // If the current view is the active item and an tag view for one tag, then the menu item params take priority if (strpos($currentLink, 'view=tag') && strpos($currentLink, '&id[0]=' . (string) $item[0]->id)) { - // $item->params are the article params, $temp are the menu item params + // $item[0]->params are the tag params, $temp are the menu item params // Merge so that the menu item params take priority - $this->params->merge($temp); + $item[0]->params->merge($temp); // Load layout from active query (in case it is an alternative menu item) if (isset($active->query['layout'])) @@ -152,14 +155,14 @@ public function display($tpl = null) } else { - // Current view is not tags, so the global params take priority since tags is not an item. - // Merge the menu item params with the global params so that the article params take priority - $temp->merge($this->state->params); - $this->params = $temp; + // Current menuitem is not a single tag view, so the tag params take priority. + // Merge the menu item params with the tag params so that the tag params take priority + $temp->merge($item[0]->params); + $item[0]->params = $temp; // Check for alternative layouts (since we are not in a single-article menu item) // Single-article menu item layout takes priority over alt layout for an article - if ($layout = $this->params->get('tags_layout')) + if ($layout = $item[0]->params->get('tag_layout')) { $this->setLayout($layout); } From f81a1ee697447953e1c25e25b7e9148f0ee30cbd Mon Sep 17 00:00:00 2001 From: Tuan Pham Ngoc Date: Sun, 22 Jan 2017 17:24:08 +0700 Subject: [PATCH 2/5] Clean up legacy controller + model classes (#13679) * Clean up JControllerForm * Clean up JModelAdmin * Clean up JModelList class --- libraries/legacy/controller/form.php | 5 ++--- libraries/legacy/model/admin.php | 13 ++++++++----- libraries/legacy/model/list.php | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libraries/legacy/controller/form.php b/libraries/legacy/controller/form.php index 009f192a36577..a93b5cfb18ff2 100644 --- a/libraries/legacy/controller/form.php +++ b/libraries/legacy/controller/form.php @@ -381,7 +381,7 @@ public function edit($key = null, $urlVar = null) // Get the previous record id (if any) and the current record id. $recordId = (int) (count($cid) ? $cid[0] : $this->input->getInt($urlVar)); - $checkin = property_exists($table, 'checked_out'); + $checkin = property_exists($table, $table->getColumnAlias('checked_out')); // Access check. if (!$this->allowEdit(array($key => $recordId), $key)) @@ -622,11 +622,10 @@ public function save($key = null, $urlVar = null) JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); - $lang = JFactory::getLanguage(); $model = $this->getModel(); $table = $model->getTable(); $data = $this->input->post->get('jform', array(), 'array'); - $checkin = property_exists($table, 'checked_out'); + $checkin = property_exists($table, $table->getColumnAlias('checked_out')); $context = "$this->option.edit.$this->context"; $task = $this->getTask(); diff --git a/libraries/legacy/model/admin.php b/libraries/legacy/model/admin.php index 73d229ac9552c..31aee469ada9e 100644 --- a/libraries/legacy/model/admin.php +++ b/libraries/legacy/model/admin.php @@ -11,6 +11,7 @@ use Joomla\Registry\Registry; use Joomla\String\StringHelper; +use Joomla\Utilities\ArrayHelper; /** * Prototype admin model. @@ -190,7 +191,7 @@ public function batch($commands, $pks, $contexts) { // Sanitize ids. $pks = array_unique($pks); - JArrayHelper::toInteger($pks); + $pks = ArrayHelper::toInteger($pks); // Remove any values of zero. if (array_search(0, $pks, true)) @@ -225,7 +226,7 @@ public function batch($commands, $pks, $contexts) if ($this->batch_copymove && !empty($commands[$this->batch_copymove])) { - $cmd = JArrayHelper::getValue($commands, 'move_copy', 'c'); + $cmd = ArrayHelper::getValue($commands, 'move_copy', 'c'); if ($cmd == 'c') { @@ -694,12 +695,14 @@ public function checkin($pks = array()) $pks = array((int) $this->getState($this->getName() . '.id')); } + $checkedOutField = $table->getColumnAlias('checked_out'); + // Check in all items. foreach ($pks as $pk) { if ($table->load($pk)) { - if ($table->checked_out > 0) + if ($table->{$checkedOutField} > 0) { if (!parent::checkin($pk)) { @@ -904,7 +907,7 @@ public function getItem($pk = null) // Convert to the JObject before adding other data. $properties = $table->getProperties(1); - $item = JArrayHelper::toObject($properties, 'JObject'); + $item = ArrayHelper::toObject($properties, 'JObject'); if (property_exists($item, 'params')) { @@ -1210,7 +1213,7 @@ public function save($data) $associations = $data['associations']; // Unset any invalid associations - $associations = Joomla\Utilities\ArrayHelper::toInteger($associations); + $associations = ArrayHelper::toInteger($associations); // Unset any invalid associations foreach ($associations as $tag => $id) diff --git a/libraries/legacy/model/list.php b/libraries/legacy/model/list.php index 3b67f7bce1019..fdc331b787a37 100644 --- a/libraries/legacy/model/list.php +++ b/libraries/legacy/model/list.php @@ -9,6 +9,8 @@ defined('JPATH_PLATFORM') or die; +use Joomla\Utilities\ArrayHelper; + /** * Model class for handling lists of items. * @@ -375,7 +377,7 @@ public function getFilterForm($data = array(), $loadData = true) protected function loadForm($name, $source = null, $options = array(), $clear = false, $xpath = false) { // Handle the optional arguments. - $options['control'] = JArrayHelper::getValue($options, 'control', false); + $options['control'] = ArrayHelper::getValue((array) $options, 'control', false); // Create a signature hash. $hash = md5($source . serialize($options)); @@ -640,7 +642,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') JPluginHelper::importPlugin($group); // Get the dispatcher. - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); // Trigger the form preparation event. $results = $dispatcher->trigger('onContentPrepareForm', array($form, $data)); From 6efb945b964850e8f15a6d10db86771bfc5d4b41 Mon Sep 17 00:00:00 2001 From: Martijn Maandag Date: Sun, 22 Jan 2017 11:43:51 +0100 Subject: [PATCH 3/5] Update en-GB.com_languages.sys.ini (#13681) --- administrator/language/en-GB/en-GB.com_languages.sys.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/language/en-GB/en-GB.com_languages.sys.ini b/administrator/language/en-GB/en-GB.com_languages.sys.ini index 5646707ee7a9a..0cd549931a4dc 100644 --- a/administrator/language/en-GB/en-GB.com_languages.sys.ini +++ b/administrator/language/en-GB/en-GB.com_languages.sys.ini @@ -10,5 +10,5 @@ COM_LANGUAGES_INSTALLED_VIEW_DEFAULT_DESC="Displays language packs installed int COM_LANGUAGES_INSTALLED_VIEW_DEFAULT_TITLE="Installed Languages" COM_LANGUAGES_LANGUAGES_VIEW_DEFAULT_DESC="Create or manage content languages for your Joomla! website." COM_LANGUAGES_LANGUAGES_VIEW_DEFAULT_TITLE="Content Languages" -COM_LANGUAGES_OVERRIDE_VIEW_DEFAULT_DESC="Here you assign custom text for a language key that you want to used instead of language pack default text." +COM_LANGUAGES_OVERRIDE_VIEW_DEFAULT_DESC="Here you assign custom text for a language key that you want to use instead of language pack default text." COM_LANGUAGES_OVERRIDE_VIEW_DEFAULT_TITLE="Language Overrides" From baef935fa1cf872091f7b708cf87682462749a79 Mon Sep 17 00:00:00 2001 From: Allon Moritz Date: Sun, 22 Jan 2017 12:33:45 +0100 Subject: [PATCH 4/5] Deprecate PSR-0 class loading (#13672) * Deprecate PSR-0 class loading * Fix typo * Add PSR4 support, not just the deprecated message * Fix deploy version * Throwing exceptions when invalid type is passed * Return type specific namespaces * Fix the test errors * Travis * Please travis be nice to me * Last try otherwise I go to the bar * Small tweaks * Update loader.php --- libraries/loader.php | 93 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 84 insertions(+), 9 deletions(-) diff --git a/libraries/loader.php b/libraries/loader.php index dd1c81435cd0b..b272c0e0b1c80 100644 --- a/libraries/loader.php +++ b/libraries/loader.php @@ -62,7 +62,7 @@ abstract class JLoader * @var array * @since 12.3 */ - protected static $namespaces = array(); + protected static $namespaces = array('psr0' => array(), 'psr4' => array()); /** * Holds a reference for all deprecated aliases (mainly for use by a logging platform). @@ -152,13 +152,19 @@ public static function getDeprecatedAliases() /** * Method to get the list of registered namespaces. * + * @param string $type Defines the type of namespace, can be prs0 or psr4. + * * @return array The array of namespace => path values for the autoloader. * * @since 12.3 */ - public static function getNamespaces() + public static function getNamespaces($type = 'psr0') { - return self::$namespaces; + if ($type !== 'psr0' && $type !== 'psr4') + { + throw new InvalidArgumentException('Type needs to be prs0 or psr4!'); + } + return self::$namespaces[$type]; } /** @@ -384,15 +390,22 @@ public static function registerAlias($alias, $original, $version = false) * @param string $path A case sensitive absolute file path to the library root where classes of the given namespace can be found. * @param boolean $reset True to reset the namespace with only the given lookup path. * @param boolean $prepend If true, push the path to the beginning of the namespace lookup paths array. + * @param string $type Defines the type of namespace, can be prs0 or psr4. * * @return void * * @throws RuntimeException * + * @note The default argument of $type will be changed in J4 to be 'psr4' * @since 12.3 */ - public static function registerNamespace($namespace, $path, $reset = false, $prepend = false) + public static function registerNamespace($namespace, $path, $reset = false, $prepend = false, $type = 'psr0') { + if ($type !== 'psr0' && $type !== 'psr4') + { + throw new InvalidArgumentException('Type needs to be prs0 or psr4!'); + } + // Verify the library path exists. if (!file_exists($path)) { @@ -402,9 +415,9 @@ public static function registerNamespace($namespace, $path, $reset = false, $pre } // If the namespace is not yet registered or we have an explicit reset flag then set the path. - if (!isset(self::$namespaces[$namespace]) || $reset) + if (!isset(self::$namespaces[$type][$namespace]) || $reset) { - self::$namespaces[$namespace] = array($path); + self::$namespaces[$type][$namespace] = array($path); } // Otherwise we want to simply add the path to the namespace. @@ -412,11 +425,11 @@ public static function registerNamespace($namespace, $path, $reset = false, $pre { if ($prepend) { - array_unshift(self::$namespaces[$namespace], $path); + array_unshift(self::$namespaces[$type][$namespace], $path); } else { - self::$namespaces[$namespace][] = $path; + self::$namespaces[$type][$namespace][] = $path; } } } @@ -457,10 +470,70 @@ public static function setup($enablePsr = true, $enablePrefixes = true, $enableC { // Register the PSR-0 based autoloader. spl_autoload_register(array('JLoader', 'loadByPsr0')); + spl_autoload_register(array('JLoader', 'loadByPsr4')); spl_autoload_register(array('JLoader', 'loadByAlias')); } } + /** + * Method to autoload classes that are namespaced to the PSR-4 standard. + * + * @param string $class The fully qualified class name to autoload. + * + * @return boolean True on success, false otherwise. + * + * @since __DEPLOY_VERSION__ + */ + public static function loadByPsr4($class) + { + // Remove the root backslash if present. + if ($class[0] == '\\') + { + $class = substr($class, 1); + } + + // Find the location of the last NS separator. + $pos = strrpos($class, '\\'); + + // If one is found, we're dealing with a NS'd class. + if ($pos !== false) + { + $classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR; + $className = substr($class, $pos + 1); + } + // If not, no need to parse path. + else + { + $classPath = null; + $className = $class; + } + + $classPath .= $className . '.php'; + + // Loop through registered namespaces until we find a match. + foreach (self::$namespaces['psr4'] as $ns => $paths) + { + $nsPath = trim(str_replace('\\', DIRECTORY_SEPARATOR, $ns), DIRECTORY_SEPARATOR); + + if (strpos($class, $ns) === 0) + { + // Loop through paths registered to this namespace until we find a match. + foreach ($paths as $path) + { + $classFilePath = $path . DIRECTORY_SEPARATOR . str_replace($nsPath, '', $classPath); + + // We check for class_exists to handle case-sensitive file systems + if (file_exists($classFilePath) && !class_exists($class, false)) + { + return (bool) include_once $classFilePath; + } + } + } + } + + return false; + } + /** * Method to autoload classes that are namespaced to the PSR-0 standard. * @@ -469,6 +542,8 @@ public static function setup($enablePsr = true, $enablePrefixes = true, $enableC * @return boolean True on success, false otherwise. * * @since 13.1 + * + * @deprecated 4.0 this method will be removed */ public static function loadByPsr0($class) { @@ -497,7 +572,7 @@ public static function loadByPsr0($class) $classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; // Loop through registered namespaces until we find a match. - foreach (self::$namespaces as $ns => $paths) + foreach (self::$namespaces['psr0'] as $ns => $paths) { if (strpos($class, $ns) === 0) { From f0d927051091a6725cc6bfe1e3b5ba13b81b8b4c Mon Sep 17 00:00:00 2001 From: zero-24 Date: Sun, 22 Jan 2017 12:41:06 +0100 Subject: [PATCH 5/5] Fix CS issues introduced with https://github.com/joomla/joomla-cms/pull/13672 --- libraries/loader.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/loader.php b/libraries/loader.php index b272c0e0b1c80..af3d01df45840 100644 --- a/libraries/loader.php +++ b/libraries/loader.php @@ -164,6 +164,7 @@ public static function getNamespaces($type = 'psr0') { throw new InvalidArgumentException('Type needs to be prs0 or psr4!'); } + return self::$namespaces[$type]; } @@ -184,10 +185,10 @@ public static function import($key, $base = null) { // Setup some variables. $success = false; - $parts = explode('.', $key); - $class = array_pop($parts); - $base = (!empty($base)) ? $base : __DIR__; - $path = str_replace('.', DIRECTORY_SEPARATOR, $key); + $parts = explode('.', $key); + $class = array_pop($parts); + $base = (!empty($base)) ? $base : __DIR__; + $path = str_replace('.', DIRECTORY_SEPARATOR, $key); // Handle special case for helper classes. if ($class == 'helper')