diff --git a/administrator/components/com_categories/helpers/association.php b/administrator/components/com_categories/helpers/association.php index 67196ee95aa25..66ac7413e7eff 100644 --- a/administrator/components/com_categories/helpers/association.php +++ b/administrator/components/com_categories/helpers/association.php @@ -25,12 +25,13 @@ abstract class CategoryHelperAssociation * * @param integer $id Id of the item * @param string $extension Name of the component + * @param string $layout Category layout * * @return array Array of associations for the component categories * * @since 3.0 */ - public static function getCategoryAssociations($id = 0, $extension = 'com_content') + public static function getCategoryAssociations($id = 0, $extension = 'com_content', $layout = null) { $return = array(); @@ -46,11 +47,13 @@ public static function getCategoryAssociations($id = 0, $extension = 'com_conten { if (class_exists($helperClassname) && is_callable(array($helperClassname, 'getCategoryRoute'))) { - $return[$tag] = $helperClassname::getCategoryRoute($item, $tag); + $return[$tag] = $helperClassname::getCategoryRoute($item, $tag, $layout); } else { - $return[$tag] = 'index.php?option=' . $extension . '&view=category&id=' . $item; + $viewLayout = $layout ? '&layout=' . $layout : ''; + + $return[$tag] = 'index.php?option=' . $extension . '&view=category&id=' . $item . $viewLayout; } } } diff --git a/components/com_content/helpers/association.php b/components/com_content/helpers/association.php index f823bacea2f1c..e6df33f272b7c 100644 --- a/components/com_content/helpers/association.php +++ b/components/com_content/helpers/association.php @@ -20,81 +20,75 @@ */ abstract class ContentHelperAssociation extends CategoryHelperAssociation { - /** - * Cached array of the content item id. - * - * @var array - * @since __DEPLOY_VERSION__ - */ - protected static $filters = array(); - /** * Method to get the associations for a given item * - * @param integer $id Id of the item - * @param string $view Name of the view + * @param integer $id Id of the item + * @param string $view Name of the view + * @param string $layout View layout * * @return array Array of associations for the item * * @since 3.0 */ - public static function getAssociations($id = 0, $view = null) + public static function getAssociations($id = 0, $view = null, $layout = null) { - $jinput = JFactory::getApplication()->input; - $view = $view === null ? $jinput->get('view') : $view; - $id = empty($id) ? $jinput->getInt('id') : $id; - $user = JFactory::getUser(); - $groups = implode(',', $user->getAuthorisedViewLevels()); + $jinput = JFactory::getApplication()->input; + $view = $view === null ? $jinput->get('view') : $view; + $component = $jinput->getCmd('option'); + $id = empty($id) ? $jinput->getInt('id') : $id; + + if ($layout === null && $jinput->get('view') == $view && $component == 'com_content') + { + $layout = $jinput->get('layout', '', 'string'); + } if ($view === 'article') { if ($id) { - if (!isset(static::$filters[$id])) + $user = JFactory::getUser(); + $groups = implode(',', $user->getAuthorisedViewLevels()); + $db = JFactory::getDbo(); + $advClause = array(); + + // Filter by user groups + $advClause[] = 'c2.access IN (' . $groups . ')'; + + // Filter by current language + $advClause[] = 'c2.language != ' . $db->quote(JFactory::getLanguage()->getTag()); + + if (!$user->authorise('core.edit.state', 'com_content') && !$user->authorise('core.edit', 'com_content')) + { + // Filter by start and end dates. + $nullDate = $db->quote($db->getNullDate()); + $date = JFactory::getDate(); + + $nowDate = $db->quote($date->toSql()); + + $advClause[] = '(c2.publish_up = ' . $nullDate . ' OR c2.publish_up <= ' . $nowDate . ')'; + $advClause[] = '(c2.publish_down = ' . $nullDate . ' OR c2.publish_down >= ' . $nowDate . ')'; + + // Filter by published + $advClause[] = 'c2.state = 1'; + } + + $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id, 'id', 'alias', 'catid', $advClause); + + $return = array(); + + foreach ($associations as $tag => $item) { - $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id); - - $return = array(); - - foreach ($associations as $tag => $item) - { - if ($item->language != JFactory::getLanguage()->getTag()) - { - $arrId = explode(':', $item->id); - $assocId = $arrId[0]; - - $db = JFactory::getDbo(); - $query = $db->getQuery(true) - ->select($db->qn('state')) - ->from($db->qn('#__content')) - ->where($db->qn('id') . ' = ' . (int) $assocId) - ->where($db->qn('access') . ' IN (' . $groups . ')'); - $db->setQuery($query); - - $result = (int) $db->loadResult(); - - if ($result > 0) - { - $return[$tag] = ContentHelperRoute::getArticleRoute($item->id, (int) $item->catid, $item->language); - } - } - - static::$filters[$id] = $return; - } - - if (count($associations) === 0) - { - static::$filters[$id] = array(); - } + $return[$tag] = ContentHelperRoute::getArticleRoute($item->id, (int) $item->catid, $item->language, $layout); } - return static::$filters[$id]; + return $return; } } if ($view === 'category' || $view === 'categories') { - return self::getCategoryAssociations($id, 'com_content'); + return self::getCategoryAssociations($id, 'com_content', $layout); } return array(); @@ -105,7 +99,7 @@ public static function getAssociations($id = 0, $view = null) * * @param integer $id Id of the article * - * @return array An array containing the association URL and the related language object + * @return array An array containing the association URL and the related language object * * @since 3.7.0 */ diff --git a/components/com_content/helpers/route.php b/components/com_content/helpers/route.php index 822d59dc54634..2a12b2c0fdc43 100644 --- a/components/com_content/helpers/route.php +++ b/components/com_content/helpers/route.php @@ -22,12 +22,13 @@ abstract class ContentHelperRoute * @param integer $id The route of the content item. * @param integer $catid The category ID. * @param integer $language The language code. + * @param string $layout The layout value. * * @return string The article route. * * @since 1.5 */ - public static function getArticleRoute($id, $catid = 0, $language = 0) + public static function getArticleRoute($id, $catid = 0, $language = 0, $layout = null) { // Create the link $link = 'index.php?option=com_content&view=article&id=' . $id; @@ -42,6 +43,11 @@ public static function getArticleRoute($id, $catid = 0, $language = 0) $link .= '&lang=' . $language; } + if ($layout) + { + $link .= '&layout=' . $layout; + } + return $link; } @@ -50,12 +56,13 @@ public static function getArticleRoute($id, $catid = 0, $language = 0) * * @param integer $catid The category ID. * @param integer $language The language code. + * @param string $layout The layout value. * * @return string The article route. * * @since 1.5 */ - public static function getCategoryRoute($catid, $language = 0) + public static function getCategoryRoute($catid, $language = 0, $layout = null) { if ($catid instanceof JCategoryNode) { @@ -68,24 +75,19 @@ public static function getCategoryRoute($catid, $language = 0) if ($id < 1) { - $link = ''; + return ''; } - else - { - $link = 'index.php?option=com_content&view=category&id=' . $id; - if ($language && $language !== '*' && JLanguageMultilang::isEnabled()) - { - $link .= '&lang=' . $language; - } + $link = 'index.php?option=com_content&view=category&id=' . $id; - $jinput = JFactory::getApplication()->input; - $layout = $jinput->get('layout'); + if ($language && $language !== '*' && JLanguageMultilang::isEnabled()) + { + $link .= '&lang=' . $language; + } - if ($layout !== '') - { - $link .= '&layout=' . $layout; - } + if ($layout) + { + $link .= '&layout=' . $layout; } return $link; diff --git a/libraries/src/Language/Associations.php b/libraries/src/Language/Associations.php index 1aacc695dfb78..50e06657873df 100644 --- a/libraries/src/Language/Associations.php +++ b/libraries/src/Language/Associations.php @@ -29,20 +29,22 @@ class Associations * @param string $pk The name of the primary key in the given $table. * @param string $aliasField If the table has an alias field set it here. Null to not use it * @param string $catField If the table has a catid field set it here. Null to not use it + * @param array $advClause Additional advanced 'where' clause; use c as parent column key, c2 as associations column key * - * @return array The associated items + * @return array The associated items * * @since 3.1 * * @throws \Exception */ - public static function getAssociations($extension, $tablename, $context, $id, $pk = 'id', $aliasField = 'alias', $catField = 'catid') + public static function getAssociations($extension, $tablename, $context, $id, $pk = 'id', $aliasField = 'alias', $catField = 'catid', + $advClause = array()) { // To avoid doing duplicate database queries. static $multilanguageAssociations = array(); // Multilanguage association array key. If the key is already in the array we don't need to run the query again, just return it. - $queryKey = implode('|', func_get_args()); + $queryKey = md5(serialize(array_merge(array($extension, $tablename, $context, $id), $advClause))); if (!isset($multilanguageAssociations[$queryKey])) { @@ -97,6 +99,15 @@ public static function getAssociations($extension, $tablename, $context, $id, $p $query->where('c.extension = ' . $db->quote($extension)); } + // Advanced where clause + if (!empty($advClause)) + { + foreach ($advClause as $clause) + { + $query->where($clause); + } + } + $db->setQuery($query); try