diff --git a/modules/mod_languages/helper.php b/modules/mod_languages/helper.php index 3b344960d5290..44351f42ccf4b 100644 --- a/modules/mod_languages/helper.php +++ b/modules/mod_languages/helper.php @@ -33,7 +33,8 @@ public static function getList(&$params) $app = JFactory::getApplication(); $menu = $app->getMenu(); $active = $menu->getActive(); - + $input = $app->input; + // Get menu home items $homes = array(); $homes['*'] = $menu->getDefault('*'); @@ -117,7 +118,54 @@ public static function getList(&$params) elseif (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) { $itemid = $associations[$language->lang_code]; - $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid); + + // Now dealing with an article view where article lang is * and menu item has associations + // => with a "simulated" association: article view in other languages actually does exist + $simulatedAssoc = false; + if ($input->get('view') == "article") + { + if (!isset($art_lang)) + { + // Retrieve current article's id/alias/lang + $ids = explode(':', $input->getString('id')); + $art_id = $ids[0]; + $article = JTable::getInstance("content"); + $article->load($art_id); + $art_alias = $article->get("alias"); + $art_lang = $article->get("language"); + } + if ($art_lang == '*') + { + if (!isset($menuUrl)) + { + // Store current menu component into $menuComp[1] (can be different than current URL component) + $menuUrl = $menu->getItem($input->get('Itemid'))->link; + preg_match("/option=com_(\w*)/", $menuUrl, $menuComp); + + // Retrieves current query in raw URL for replacement of its vars + $uriInst = clone JUri::getInstance(); + $query = JSite::getRouter()->parse($uriInst); + $rawQuery = $uriInst->buildQuery($query); + } + // Replace current URL component with active menu's one for compatibility with overriding component + $newUrl = preg_replace("/option=com_(\w*)/", "option=com_" . $menuComp[1], $rawQuery); + + // Replace also menu item and language, then complete art_id with art slug + $newUrl = preg_replace("/Itemid=(\d*)/", "Itemid=" . $itemid, $newUrl); + $newUrl = preg_replace("/lang=((?>\w|-)*)/", "lang=" . $language->lang_code, $newUrl); + if (strpos($newUrl, ":" . $art_alias) === false) + { + $newUrl = preg_replace("/&id=(\d*)/", "&id=" . $art_id . ":" . $art_alias, $newUrl); + } + + $simulatedAssoc = true; + $language->link = JRoute::_("index.php?" . $newUrl); + } + } + if (!$simulatedAssoc) + { + $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid); + } } elseif ($active && $active->language == '*') {