From 299689ab5683f4ca7e3e2303b86c026be9c54b22 Mon Sep 17 00:00:00 2001 From: Jean-Marie Simonet Date: Thu, 30 Aug 2018 11:14:34 +0200 Subject: [PATCH 1/8] [4.0] Correcting info-block category and parent category urls --- components/com_content/Model/ArticleModel.php | 6 ++++-- .../com_content/Model/ArticlesModel.php | 6 ++++-- .../com_content/View/Archive/HtmlView.php | 9 +++++--- .../com_content/View/Article/HtmlView.php | 10 +++++---- .../com_content/View/Category/HtmlView.php | 9 ++++---- .../com_content/View/Featured/HtmlView.php | 8 ++++--- components/com_content/helpers/route.php | 21 ++++++++++--------- .../tmpl/archive/default_items.php | 13 +++++++----- .../tmpl/category/blog_children.php | 4 ++-- .../tmpl/category/default_children.php | 4 ++-- .../joomla/content/info_block/category.php | 5 +++-- .../content/info_block/parent_category.php | 3 ++- 12 files changed, 58 insertions(+), 40 deletions(-) diff --git a/components/com_content/Model/ArticleModel.php b/components/com_content/Model/ArticleModel.php index dafa7d6d01cf6..5d80777972ba9 100644 --- a/components/com_content/Model/ArticleModel.php +++ b/components/com_content/Model/ArticleModel.php @@ -115,7 +115,8 @@ public function getItem($pk = null) ->where($db->quoteName('wa.stage_id') . ' = ' . $db->quoteName('ws.id')); // Join on category table. - $query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access') + $query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access,' . + 'c.language AS category_language') ->innerJoin('#__categories AS c on c.id = a.catid') ->where('c.published > 0'); @@ -130,7 +131,8 @@ public function getItem($pk = null) } // Join over the categories to get parent category titles - $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias') + $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route,' . + 'parent.alias as parent_alias, parent.language as parent_language') ->join('LEFT', '#__categories as parent ON parent.id = c.parent_id'); // Join on voting table diff --git a/components/com_content/Model/ArticlesModel.php b/components/com_content/Model/ArticlesModel.php index c8d4fc0d3899f..b5791b7bba5cd 100644 --- a/components/com_content/Model/ArticlesModel.php +++ b/components/com_content/Model/ArticlesModel.php @@ -251,7 +251,8 @@ protected function getListQuery() ->join('LEFT', '#__workflow_stages AS ws ON ws.id = wa.stage_id'); // Join over the categories. - $query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias') + $query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias,' . + 'c.language AS category_language') ->select('c.published, c.published AS parents_published, c.lft') ->join('LEFT', '#__categories AS c ON c.id = a.catid'); @@ -262,7 +263,8 @@ protected function getListQuery() ->join('LEFT', '#__users AS uam ON uam.id = a.modified_by'); // Join over the categories to get parent category titles - $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias') + $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias,' . + 'parent.language as parent_language') ->join('LEFT', '#__categories as parent ON parent.id = c.parent_id'); if (PluginHelper::isEnabled('content', 'vote')) diff --git a/components/com_content/View/Archive/HtmlView.php b/components/com_content/View/Archive/HtmlView.php index cceb8a2e931f3..68a7e3f4f8d1d 100644 --- a/components/com_content/View/Archive/HtmlView.php +++ b/components/com_content/View/Archive/HtmlView.php @@ -115,13 +115,16 @@ public function display($tpl = null) foreach ($items as $item) { - $item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; - $item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; + $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; + $item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; + $item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; + $item->catlanguage = $item->category_language; + $item->parentlanguage = $item->parent_language; // No link for ROOT category if ($item->parent_alias === 'root') { - $item->parent_slug = null; + $item->parent_slug = null; } $item->event = new \stdClass; diff --git a/components/com_content/View/Article/HtmlView.php b/components/com_content/View/Article/HtmlView.php index 8154b7200d664..0931ab93f832f 100644 --- a/components/com_content/View/Article/HtmlView.php +++ b/components/com_content/View/Article/HtmlView.php @@ -107,9 +107,11 @@ public function display($tpl = null) $item->tagLayout = new FileLayout('joomla.content.tags'); // Add router helpers. - $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; - $item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; - $item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; + $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; + $item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; + $item->catlanguage = $item->category_language; + $item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; + $item->parentlanguage = $item->parent_language; // No link for ROOT category if ($item->parent_alias === 'root') @@ -302,7 +304,7 @@ protected function _prepareDocument() while ($category && ($menu->query['option'] !== 'com_content' || $menu->query['view'] === 'article' || $id != $category->id) && $category->id > 1) { - $path[] = array('title' => $category->title, 'link' => \ContentHelperRoute::getCategoryRoute($category->id)); + $path[] = array('title' => $category->title, 'link' => \ContentHelperRoute::getCategoryRoute($category->id, $category->language)); $category = $category->getParent(); } diff --git a/components/com_content/View/Category/HtmlView.php b/components/com_content/View/Category/HtmlView.php index 940d41eda9f5e..20f46ca4e7880 100644 --- a/components/com_content/View/Category/HtmlView.php +++ b/components/com_content/View/Category/HtmlView.php @@ -93,9 +93,11 @@ public function display($tpl = null) // Compute the article slugs and prepare introtext (runs content plugins). foreach ($this->items as $item) { - $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; - - $item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; + $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; + $item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; + $item->catlanguage = $item->category_language; + $item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; + $item->parentlanguage = $item->parent_language; // No link for ROOT category if ($item->parent_alias === 'root') @@ -103,7 +105,6 @@ public function display($tpl = null) $item->parent_slug = null; } - $item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; $item->event = new \stdClass; // Old plugins: Ensure that text property is available diff --git a/components/com_content/View/Featured/HtmlView.php b/components/com_content/View/Featured/HtmlView.php index dde1f0768b040..6a5d68056d4b4 100644 --- a/components/com_content/View/Featured/HtmlView.php +++ b/components/com_content/View/Featured/HtmlView.php @@ -140,9 +140,11 @@ public function display($tpl = null) // Compute the article slugs and prepare introtext (runs content plugins). foreach ($items as &$item) { - $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; - $item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; - $item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; + $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; + $item->catslug = $item->category_alias ? ($item->catid . ':' . $item->category_alias) : $item->catid; + $item->parent_slug = $item->parent_alias ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id; + $item->catlanguage = $item->category_language; + $item->parentlanguage = $item->parent_language; // No link for ROOT category if ($item->parent_alias === 'root') diff --git a/components/com_content/helpers/route.php b/components/com_content/helpers/route.php index 6878b9def2bcf..c72a00cc7a3e5 100644 --- a/components/com_content/helpers/route.php +++ b/components/com_content/helpers/route.php @@ -10,6 +10,7 @@ defined('_JEXEC') or die; use Joomla\CMS\Categories\CategoryNode; +use Joomla\CMS\Factory; use Joomla\CMS\Language\Multilanguage; /** @@ -77,17 +78,17 @@ public static function getCategoryRoute($catid, $language = 0) { $link = 'index.php?option=com_content&view=category&id=' . $id; - if ($language && $language !== '*' && Multilanguage::isEnabled()) + if ($language && Multilanguage::isEnabled()) { - $link .= '&lang=' . $language; - } - - $jinput = JFactory::getApplication()->input; - $layout = $jinput->get('layout'); - - if ($layout !== '') - { - $link .= '&layout=' . $layout; + if ($language !== '*') + { + $link .= '&lang=' . $language; + } + else + { + $lang = Factory::getLanguage()->getTag(); + $link .= '&lang=' . $lang; + } } } diff --git a/components/com_content/tmpl/archive/default_items.php b/components/com_content/tmpl/archive/default_items.php index 7a02d9e6e022e..ad00bed20eb9d 100644 --- a/components/com_content/tmpl/archive/default_items.php +++ b/components/com_content/tmpl/archive/default_items.php @@ -60,7 +60,8 @@
escape($item->parent_title); ?> get('link_parent_category') && !empty($item->parent_slug)) : ?> - parent_slug)) . '" itemprop="genre">' . $title . ''; ?> + parent_slug), + $item->parentlanguage ) . '" itemprop="genre">' . $title . ''; ?> ' . $title . ''); ?> @@ -73,7 +74,8 @@
escape($item->category_title); ?> get('link_category') && $item->catslug) : ?> - catslug)) . '" itemprop="genre">' . $title . ''; ?> + catslug, + $item->catlanguage)) . '" itemprop="genre">' . $title . ''; ?> ' . $title . ''); ?> @@ -146,7 +148,8 @@
escape($item->parent_title); ?> get('link_parent_category') && $item->parent_slug) : ?> - parent_slug)) . '" itemprop="genre">' . $title . ''; ?> + parent_slug, + $item->parentlanguage)) . '" itemprop="genre">' . $title . ''; ?> ' . $title . ''); ?> @@ -159,7 +162,7 @@
escape($item->category_title); ?> get('link_category') && $item->catslug) : ?> - catslug)) . '" itemprop="genre">' . $title . ''; ?> + catslug, $item->catlanguage)) . '" itemprop="genre">' . $title . ''; ?> ' . $title . ''); ?> @@ -223,6 +226,6 @@

- pagination->getPagesLinks(); ?> + pagination->getPagesLinks(); ?>
diff --git a/components/com_content/tmpl/category/blog_children.php b/components/com_content/tmpl/category/blog_children.php index f379f045bb570..9505441dedc51 100644 --- a/components/com_content/tmpl/category/blog_children.php +++ b/components/com_content/tmpl/category/blog_children.php @@ -32,7 +32,7 @@ getNumItems(true); ?> - + escape($child->title); ?> maxLevel > 1 && count($child->getChildren()) > 0) : ?> @@ -40,7 +40,7 @@ -