/** * Generate the markup to display the item associations * * @param int $itemid The menu item id * * @return string * * @since 3.0 * * @throws Exception If there is an error on the query */ public static function association($itemid) { // Defaults $html = ''; // Get the associations if ($associations = MenusHelper::getAssociations($itemid)) { // Get the associated menu items $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('m.id, m.title')->select('l.sef as lang_sef')->select('mt.title as menu_title')->from('#__menu as m')->join('LEFT', '#__menu_types as mt ON mt.menutype=m.menutype')->where('m.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON m.language=l.lang_code')->select('l.image')->select('l.title as language_title'); $db->setQuery($query); try { $items = $db->loadObjectList('id'); } catch (runtimeException $e) { throw new Exception($e->getMessage(), 500); } // Construct html if ($items) { foreach ($items as &$item) { $text = strtoupper($item->lang_sef); $url = JRoute::_('index.php?option=com_menus&task=item.edit&id=' . (int) $item->id); $tooltipParts = array(JHtml::_('image', 'mod_languages/' . $item->image . '.gif', $item->language_title, array('title' => $item->language_title), true), $item->title, '(' . $item->menu_title . ')'); $class = 'hasTooltip label label-association label-' . $item->lang_sef; $item->link = JHtml::_('tooltip', implode(' ', $tooltipParts), null, null, $text, $url, null, $class); } } $html = JLayoutHelper::render('joomla.content.associations', $items); } return $html; }
/** * @param int $itemid The menu item id */ static function association($itemid) { // Get the associations $associations = MenusHelper::getAssociations($itemid); // Get the associated menu items $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('m.*'); $query->select('mt.title as menu_title'); $query->from('#__menu as m'); $query->leftJoin('#__menu_types as mt ON mt.menutype=m.menutype'); $query->where('m.id IN (' . implode(',', array_values($associations)) . ')'); $query->leftJoin('#__languages as l ON m.language=l.lang_code'); $query->select('l.image'); $query->select('l.title as language_title'); $db->setQuery($query); $items = $db->loadObjectList('id'); // Check for a database error. if ($error = $db->getErrorMsg()) { JError::raiseWarning(500, $error); return false; } // Construct html $text = array(); foreach ($associations as $tag => $associated) { if ($associated != $itemid) { $text[] = JText::sprintf('COM_MENUS_TIP_ASSOCIATED_LANGUAGE', JHtml::_('image', 'mod_languages/' . $items[$associated]->image . '.gif', $items[$associated]->language_title, array('title' => $items[$associated]->language_title), true), $items[$associated]->title, $items[$associated]->menu_title); } } return JHtml::_('tooltip', implode('<br />', $text), JText::_('COM_MENUS_TIP_ASSOCIATION'), 'menu/icon-16-links.png'); }
/** * Generate the markup to display the item associations * * @param int $itemid The menu item id * * @return string * * @since 3.0 * * @throws Exception If there is an error on the query */ public static function association($itemid) { // Defaults $html = ''; // Get the associations if ($associations = MenusHelper::getAssociations($itemid)) { // Get the associated menu items $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('m.id, m.title')->select('l.sef as lang_sef, l.lang_code')->select('mt.title as menu_title')->from('#__menu as m')->join('LEFT', '#__menu_types as mt ON mt.menutype=m.menutype')->where('m.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON m.language=l.lang_code')->select('l.image')->select('l.title as language_title'); $db->setQuery($query); try { $items = $db->loadObjectList('id'); } catch (runtimeException $e) { throw new Exception($e->getMessage(), 500); } // Construct html if ($items) { foreach ($items as &$item) { $text = strtoupper($item->lang_sef); $url = JRoute::_('index.php?option=com_menus&task=item.edit&id=' . (int) $item->id); $tooltip = $item->title . '<br />' . JText::sprintf('COM_MENUS_MENU_SPRINTF', $item->menu_title); $classes = 'hasPopover label label-association label-' . $item->lang_sef; $item->link = '<a href="' . $url . '" title="' . $item->language_title . '" class="' . $classes . '" data-content="' . $tooltip . '" data-placement="top">' . $text . '</a>'; } } JHtml::_('bootstrap.popover'); $html = JLayoutHelper::render('joomla.content.associations', $items); } return $html; }
public static function getList(&$params) { $user = JFactory::getUser(); $lang = JFactory::getLanguage(); $app = JFactory::getApplication(); $menu = $app->getMenu(); // Get menu home items $homes = array(); foreach ($menu->getMenu() as $item) { if ($item->home) { $homes[$item->language] = $item; } } // Load associations $assoc = isset($app->menu_associations) ? $app->menu_associations : 0; if ($assoc) { $active = $menu->getActive(); if ($active) { $associations = MenusHelper::getAssociations($active->id); } } $levels = $user->getAuthorisedViewLevels(); $languages = JLanguageHelper::getLanguages(); // Filter allowed languages foreach ($languages as $i => &$language) { // Do not display language without frontend UI if (!JLanguage::exists($language->lang_code)) { unset($languages[$i]); } elseif (!isset($homes[$language->lang_code])) { unset($languages[$i]); } elseif (isset($language->access) && $language->access && !in_array($language->access, $levels)) { unset($languages[$i]); } else { $language->active = $language->lang_code == $lang->getTag(); if ($app->getLanguageFilter()) { if (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) { $itemid = $associations[$language->lang_code]; if ($app->getCfg('sef') == '1') { $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid); } else { $language->link = 'index.php?lang=' . $language->sef . '&Itemid=' . $itemid; } } else { if ($app->getCfg('sef') == '1') { $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id; $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid); } else { $language->link = 'index.php?lang=' . $language->sef; } } } else { $language->link = JRoute::_('&Itemid=' . $homes['*']->id); } } } return $languages; }
public static function getList(&$params) { $lang = JFactory::getLanguage(); $languages = JLanguageHelper::getLanguages(); $db = JFactory::getDBO(); $app = JFactory::getApplication(); $query = $db->getQuery(true); $query->select('id'); $query->select('language'); $query->from($db->nameQuote('#__menu')); $query->where('home=1'); $db->setQuery($query); $homes = $db->loadObjectList('language'); if ($app->get('menu_associations', 0)) { $menu = $app->getMenu(); $active = $menu->getActive(); if ($active) { $associations = MenusHelper::getAssociations($active->id); } } foreach ($languages as $i => &$language) { // Do not display language without frontend UI if (!JLanguage::exists($language->lang_code)) { unset($languages[$i]); } elseif (!isset($homes[$language->lang_code])) { unset($languages[$i]); } else { $language->active = $language->lang_code == $lang->getTag(); if ($app->getLanguageFilter()) { if (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) { $itemid = $associations[$language->lang_code]; if ($app->getCfg('sef') == '1') { $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid); } else { $language->link = 'index.php?lang=' . $language->sef . '&Itemid=' . $itemid; } } else { if ($app->getCfg('sef') == '1') { $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id; $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid); } else { $language->link = 'index.php?lang=' . $language->sef; } } } else { $language->link = JRoute::_('&Itemid=' . $homes['*']->id); } } } return $languages; }
/** * This method adds alternate meta tags for associated menu items * * @return nothing * @since 1.7 */ public function onAfterDispatch() { if (App::isSite() && $this->params->get('alternate_meta') && Document::getType() == 'html') { // Get active menu item $active = App::get('menu')->getActive(); if (!$active) { return; } // Get menu item link if (Config::get('sef')) { $active_link = Route::url('index.php?Itemid=' . $active->id, false); } else { $active_link = Route::url($active->link . '&Itemid=' . $active->id, false); } if ($active_link == JUri::base(true) . '/') { $active_link .= 'index.php'; } // Get current link $current_link = Request::getUri(); if ($current_link == Request::base(true) . '/') { $current_link .= 'index.php'; } // Check the exact menu item's URL if ($active_link == $current_link) { // Get menu item associations JLoader::register('MenusHelper', PATH_CORE . '/components/com_menus/admin/helpers/menus.php'); $associations = MenusHelper::getAssociations($active->id); // Remove current menu item unset($associations[$active->language]); // Associated menu items in other languages if ($associations && $this->params->get('menu_associations')) { $menu = App::get('menu'); $server = JURI::getInstance()->toString(array('scheme', 'host', 'port')); foreach (JLanguageHelper::getLanguages() as $language) { if (isset($associations[$language->lang_code])) { $item = $menu->getItem($associations[$language->lang_code]); if ($item && Lang::exists($language->lang_code)) { if (Config::get('sef')) { $link = Route::url('index.php?Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef); } else { $link = Route::url($item->link . '&Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef); } // Check if language is the default site language and remove url language code is on if ($language->sef == self::$default_sef && $this->params->get('remove_default_prefix') == '1') { $relLink = preg_replace('|/' . $language->sef . '/|', '/', $link, 1); Document::addHeadLink($server . $relLink, 'alternate', 'rel', array('hreflang' => $language->lang_code)); } else { Document::addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code)); } } } } } elseif ($active->home) { $menu = App::get('menu'); $server = JURI::getInstance()->toString(array('scheme', 'host', 'port')); foreach (JLanguageHelper::getLanguages() as $language) { $item = $menu->getDefault($language->lang_code); if ($item && $item->language != $active->language && $item->language != '*' && JLanguage::exists($language->lang_code)) { if (Config::get('sef')) { $link = Route::url('index.php?Itemid=' . $item->id . '&lang=' . $language->sef); } else { $link = Route::url($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef); } // Check if language is the default site language and remove url language code is on if ($language->sef == self::$default_sef && $this->params->get('remove_default_prefix') == '1') { $relLink = preg_replace('|/' . $language->sef . '/|', '/', $link, 1); Document::addHeadLink($server . $relLink, 'alternate', 'rel', array('hreflang' => $language->lang_code)); } else { Document::addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code)); } } } } } } }
/** * Method to add alternative meta tags for associated menu items. * * @return void * * @since 1.7 */ public function onAfterDispatch() { $doc = JFactory::getDocument(); $menu = $this->app->getMenu(); $server = JUri::getInstance()->toString(array('scheme', 'host', 'port')); $option = $this->app->input->get('option'); $eName = JString::ucfirst(JString::str_ireplace('com_', '', $option)); if ($this->app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') { // Get active menu item. $active = $menu->getActive(); $assocs = array(); $home = false; // Load menu associations. if ($active) { $active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false); // Get current link. $current_link = JUri::getInstance()->toString(array('path', 'query')); // Check the exact menu item's URL. if ($active_link == $current_link) { $associations = MenusHelper::getAssociations($active->id); unset($associations[$active->language]); $assocs = array_keys($associations); // If the menu item is a home menu item and the URLs are identical, we are on the homepage $home = true; } } // Load component associations. $cName = JString::ucfirst($eName . 'HelperAssociation'); JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php')); if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) { $cassociations = call_user_func(array($cName, 'getAssociations')); $lang_code = $this->app->input->cookie->getString(JApplicationHelper::getHash('language')); // No cookie - let's try to detect browser language or use site default. if (!$lang_code) { if ($this->params->get('detect_browser', 1)) { $lang_code = JLanguageHelper::detectLanguage(); } else { $lang_code = $this->default_lang; } } unset($cassociations[$lang_code]); $assocs = array_merge(array_keys($cassociations), $assocs); } // Handle the default associations. if ($this->params->get('item_associations') || $active && $active->home && $home) { $languages = JLanguageHelper::getLanguages('lang_code'); foreach ($assocs as $language) { if (!JLanguage::exists($language)) { continue; } $lang = $languages[$language]; if (isset($cassociations[$language])) { $link = JRoute::_($cassociations[$language] . '&lang=' . $lang->sef); // Check if language is the default site language and remove url language code is on if ($lang->sef == $this->lang_codes[$this->default_lang]->sef && $this->params->get('remove_default_prefix') == '1') { $link = preg_replace('|/' . $lang->sef . '/|', '/', $link, 1); } $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language)); } elseif (isset($associations[$language])) { $item = $menu->getItem($associations[$language]); if ($item) { $link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $lang->sef); $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language)); } } } } } }
function switchLangAssocItem( $args=null ) { $flexiparams = JComponentHelper::getParams('com_flexicontent'); $app = JFactory::getApplication(); $session = JFactory::getSession(); // Execute only in frontend if( $app->isAdmin() ) return; // Execute only if groups enabled and if plugin parameter for switching is enabled if ( !$flexiparams->get('enable_translation_groups') || !$this->params->get('switch_langassociated_items', 1) ) return; // Execute only if some languange switcher is available if ( !FLEXI_J16GE && !FLEXI_FISH ) return; // Execute only if not previewing if (JRequest::getVar('preview') || ( JRequest::getVar('fcu') && JRequest::getVar('fcp') ) ) return; if ( JRequest::getVar('format', 'html') != 'html' ) return; // Get current user language $cntLang = substr(JFactory::getLanguage()->getTag(), 0,2); // Current Content language (Can be natively switched in J2.5) $urlLang = JRequest::getWord('lang', '' ); // Language from URL (Can be switched via Joomfish in J1.5) $curr_lang = (FLEXI_J16GE || empty($urlLang)) ? $cntLang : $urlLang; // Get variables if (FLEXI_FISH) { $view = JRequest::getVar('view'); $option = JRequest::getVar('option'); $task = JRequest::getVar('task'); $item_slug = JRequest::getVar('id'); $item_id = (int) $item_slug; // Execute only if current page is a FLEXIcontent items view (viewing an individual item) if ( $view != FLEXI_ITEMVIEW || $option!='com_flexicontent' ) return; } else if (FLEXI_J16GE) { $menus = $app->getMenu('site', array()); $curr_menu = $menus->getActive(); $curr_menu_isitem = @$menu->query['option']=='com_flexicontent' && @$menu->query['view']==FLEXI_ITEMVIEW && @$menu->query['id']==(int)JRequest::getVar('id'); $curr_menu_iscat = @$menu->query['option']=='com_flexicontent' && @$menu->query['view']=='category' && @$menu->query['cid']==(int)JRequest::getVar('cid'); $flexi_advroute_url = $session->get('flexi_advroute_url'); $view = @$flexi_advroute_url['view']; $option = @$flexi_advroute_url['option']; $task = @$flexi_advroute_url['task']; $cat_slug = @$flexi_advroute_url['cid']; $item_slug = @$flexi_advroute_url['id']; $prev_lang_tag = @$flexi_advroute_url['lang_tag']; $prev_page_ishome = @$flexi_advroute_url['ishome']; $prev_menu_id = @$flexi_advroute_url['menu_id']; $prev_menu_isitem = @$flexi_advroute_url['menu_isitem']; $prev_menu_iscat = @$flexi_advroute_url['menu_iscat']; //print_r($flexi_advroute_url); echo "<br/>"; $curr_lang_tag = JFactory::getLanguage()->getTag(); $curr_page_ishome = $this->detectHomepage(); $curr_menu_id = @$curr_menu->id; if ($this->params->get('debug_lang_switch', 0)) { //$app->enqueueMessage( "Previous Page is HOME: $prev_page_ishome, "."Previous menu item ID: $prev_menu_id<br>", 'message'); //$app->enqueueMessage( "Current Page is HOME: $curr_page_ishome, "."Current menu item ID: $curr_menu_id<br>", 'message'); //$app->enqueueMessage( "Previous language $prev_lang_tag && Current language: $curr_lang_tag<br><br>", 'message'); } // Set variables for next function call (next page load) unset($flexi_advroute_url); $flexi_advroute_url['view'] = JRequest::getVar('view'); $flexi_advroute_url['option'] = JRequest::getVar('option'); $flexi_advroute_url['task'] = JRequest::getVar('task'); $flexi_advroute_url['id'] = JRequest::getVar('id'); $flexi_advroute_url['cid'] = JRequest::getVar('cid'); $flexi_advroute_url['lang_tag']= $curr_lang_tag; $flexi_advroute_url['ishome'] = $curr_page_ishome; $flexi_advroute_url['menu_id'] = $curr_menu_id; $flexi_advroute_url['menu_isitem']= $curr_menu_isitem; $flexi_advroute_url['menu_iscat'] = $curr_menu_iscat; // Set only if current page is a FLEXIcontent item or category view if ( $flexi_advroute_url['view']==FLEXI_ITEMVIEW || $flexi_advroute_url['view']=='category' ) { $session->set('flexi_advroute_url', $flexi_advroute_url); //print_r($flexi_advroute_url); echo "<br/>"; } else if ($prev_lang_tag!=$curr_lang_tag) { // language changed we should clear last flexi url $session->set('flexi_advroute_url', array()); } // Detect if already redirected once, this code must be after the code setting the 'flexi_advroute_url' session variable if ( $session->get('flexi_lang_switched') ) { $session->set('flexi_lang_switched', 0); return; } // Indentify previous and current flexicontent view $prev_page_isitemview = $view==FLEXI_ITEMVIEW && $option=='com_flexicontent'; $prev_page_iscatview = $view=='category' && $option=='com_flexicontent'; $curr_page_isitemview = JRequest::getVar('view')==FLEXI_ITEMVIEW && JRequest::getVar('option')=='com_flexicontent'; $curr_page_iscatview = JRequest::getVar('view')=='category' && JRequest::getVar('option')=='com_flexicontent'; // Execute only if previous page was a FLEXIcontent item or category view if ( !$prev_page_isitemview && !$prev_page_iscatview ) return; // Calculate flags needed to decide action to take $language_changed = $prev_lang_tag!=$curr_lang_tag; $prev_page_isflexi = $prev_page_isitemview || $prev_page_iscatview; $switching_language = $prev_page_isflexi && $curr_page_ishome && $language_changed; // Check Joomla switching language for (a) Home Page menu items OR (b) other language associated menu items if ( $curr_menu && $curr_menu->language!='*' && $curr_menu->language!=$prev_lang_tag ) { // (a) Home Page menu items if ($prev_page_ishome && $curr_page_ishome) { if ($this->params->get('debug_lang_switch', 0)) $app->enqueueMessage( "Joomla language switched Home Page menu items<br><br>", 'message'); $switching_language = false; } // (b) Other language associated menu items else { // Get menu item associations for previously activated menu item require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_menus'.DS.'helpers'.DS.'menus.php'); $helper = new MenusHelper(); $associated = $helper->getAssociations($prev_menu_id); if ( isset($associated[$curr_lang_tag]) && $associated[$curr_lang_tag] == $curr_menu_id ) { if ($this->params->get('debug_lang_switch', 0)) $app->enqueueMessage( "Associated menu for $prev_menu_id: ".print_r($associated, true)."<br>" , 'message'); if ( ($prev_page_isitemview && !$prev_menu_isitem) || ($prev_page_iscatview && !$prev_menu_iscat) ){ if ($this->params->get('debug_lang_switch', 0)) $app->enqueueMessage( "Joomla language switched associated menu items that did not point to current content: Doing FLEXI switch<br>", 'message'); $switching_language = true; } else { if ($this->params->get('debug_lang_switch', 0)) $app->enqueueMessage( "Joomla language switched associated menu items: that do point to current content: Aborting FLEXI switch<br><br>", 'message'); $switching_language = false; } } } } /*echo "<br>prev_page_isflexi: $prev_page_isflexi, curr_page_ishome: $curr_page_ishome," ."<br>language_changed: $language_changed," ."<br>prev_page_isitemview: $prev_page_isitemview, prev_page_iscatview: $prev_page_iscatview" ."<br>curr_page_isitemview: $curr_page_isitemview, curr_page_iscatview: $curr_page_iscatview";*/ // Decide to execute switching: if ( !$switching_language && // (a) if previous page was a FLEXIcontent view (item or category view) and we switched language !$curr_page_isitemview // (b) if current page is FLEXIcontent item in order to check if language specified is not that of item's language ) return; $cat_id = (int) (($switching_language && $this->params->get('lang_switch_cats', 1)) ? $cat_slug : JRequest::getVar('cid')); $item_id = (int) ($switching_language ? $item_slug : JRequest::getVar('id')); $view = $switching_language ? $view : JRequest::getVar('view'); $option = $switching_language ? $option : JRequest::getVar('option'); $task = $switching_language ? $task : JRequest::getVar('task'); } if ( FLEXI_J16GE && $view=='category' ) { // Execute only if category id is set, and switching for categories is enabled if (!$cat_id) return; if (!$this->params->get('lang_switch_cats', 1)) return; if ($this->params->get('debug_lang_switch', 0)) $app->enqueueMessage( "*** Language switching category no: $cat_id<br><br>", 'message'); $session->set('flexi_lang_switched', 1); $cat_url = JRoute::_( FlexicontentHelperRoute::getCategoryRoute($cat_slug).'&lang='.$curr_lang, false ); $app->redirect( $cat_url ); } if (!$item_id) return; // Execute only if item id is set if ($task=="edit") return; // Execute only if not in item edit form if (!$this->params->get('lang_switch_items', 1)) return; // Execute only if switching for items is enabled // Execute only when not doing a task (e.g. edit) BROKEN !!! DISABLED //if ( !empty(JRequest::getVar('task')) ) return; // Get associated translating item for current language $lta = FLEXI_J16GE || $use_tmp ? 'i': 'ie'; $db = JFactory::getDBO(); $query = "SELECT i.id, CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(':', i.id, i.alias) ELSE i.id END as slug, ".$lta.".language, ie.type_id" . " FROM #__content AS i " . " LEFT JOIN #__flexicontent_items_ext AS ie ON ie.item_id = i.id " . " WHERE " . " ie.language LIKE ".$db->Quote( $curr_lang .'%' )." AND " . " ie.lang_parent_id = (SELECT lang_parent_id FROM #__flexicontent_items_ext WHERE item_id=".(int) $item_id.")"; ; $db->setQuery($query); $translation = $db->loadObject(); if( $db->getErrorNum() ) { $app->enqueueMessage( $db->getErrorMsg(), 'warning'); } if ( !$translation || $item_id==$translation->id ) return; // No associated item translation found if ($this->params->get('debug_lang_switch', 0)) $app->enqueueMessage( "*** Found translation of item {$item_id} for language $curr_lang. <br>Translating item is {$translation->id}<br><br>", 'message'); if (FLEXI_J16GE) { $item_url = JRoute::_( FlexicontentHelperRoute::getItemRoute($translation->slug, $cat_id, 0, $translation), false ); $session->set('flexi_lang_switched', 1); $app->redirect( $item_url ); } else { JRequest::setVar('id', $translation->id); } }
/** * Method to add alternative meta tags for associated menu items. * * @return void * * @since 1.7 */ public function onAfterDispatch() { $app = JFactory::getApplication(); $doc = JFactory::getDocument(); $menu = $app->getMenu(); $server = JUri::getInstance()->toString(array('scheme', 'host', 'port')); $option = $app->input->get('option'); $eName = JString::ucfirst(JString::str_ireplace('com_', '', $option)); if ($app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') { // Get active menu item. $active = $menu->getActive(); // Load menu associations. if ($active) { // Get menu item link. if ($app->get('sef')) { $active_link = JRoute::_('index.php?Itemid=' . $active->id, false); } else { $active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false); } if ($active_link == JUri::base(true) . '/') { $active_link .= 'index.php'; } // Get current link. $current_link = JUri::getInstance()->toString(array('path', 'query')); if ($current_link == JUri::base(true) . '/') { $current_link .= 'index.php'; } // Check the exact menu item's URL. if ($active_link == $current_link) { $associations = MenusHelper::getAssociations($active->id); unset($associations[$active->language]); } } // Load component associations. $cName = JString::ucfirst($eName . 'HelperAssociation'); JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php')); if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) { $cassociations = call_user_func(array($cName, 'getAssociations')); $lang_code = $app->input->cookie->getString(JApplication::getHash('language')); // No cookie - let's try to detect browser language or use site default. if (!$lang_code) { if ($this->params->get('detect_browser', 1)) { $lang_code = JLanguageHelper::detectLanguage(); } else { $lang_code = self::$default_lang; } } unset($cassociations[$lang_code]); } // Handle the default associations. if ((!empty($associations) || !empty($cassociations)) && $this->params->get('item_associations')) { foreach (JLanguageHelper::getLanguages() as $language) { if (!JLanguage::exists($language->lang_code)) { continue; } if (isset($cassociations[$language->lang_code])) { $link = JRoute::_($cassociations[$language->lang_code] . '&lang=' . $language->sef); $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code)); } elseif (isset($associations[$language->lang_code])) { $item = $menu->getItem($associations[$language->lang_code]); if ($item) { if ($app->get('sef')) { $link = JRoute::_('index.php?Itemid=' . $item->id . '&lang=' . $language->sef); } else { $link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef); } $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code)); } } } } elseif ($active && $active->home) { foreach (JLanguageHelper::getLanguages() as $language) { if (!JLanguage::exists($language->lang_code)) { continue; } $item = $menu->getDefault($language->lang_code); if ($item && $item->language != $active->language && $item->language != '*') { if ($app->get('sef')) { $link = JRoute::_('index.php?Itemid=' . $item->id . '&lang=' . $language->sef); } else { $link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef); } $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code)); } } } } }
/** * Gets a list of available languages * * @param JRegistry &$params module params * * @return array */ public static function getList(&$params) { $user = JFactory::getUser(); $lang = JFactory::getLanguage(); $app = JFactory::getApplication(); $menu = $app->getMenu(); // Get menu home items $homes = array(); foreach ($menu->getMenu() as $item) { if ($item->home) { $homes[$item->language] = $item; } } // Load associations $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $active = $menu->getActive(); if ($active) { $associations = MenusHelper::getAssociations($active->id); } // Load component associations $option = $app->input->get('option'); $eName = JString::ucfirst(JString::str_ireplace('com_', '', $option)); $cName = JString::ucfirst($eName . 'HelperAssociation'); JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php')); if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) { $cassociations = call_user_func(array($cName, 'getAssociations')); } } $levels = $user->getAuthorisedViewLevels(); $languages = JLanguageHelper::getLanguages(); // Filter allowed languages foreach ($languages as $i => &$language) { // Do not display language without frontend UI if (!JLanguage::exists($language->lang_code)) { unset($languages[$i]); } elseif (!isset($homes[$language->lang_code])) { unset($languages[$i]); } elseif (isset($language->access) && $language->access && !in_array($language->access, $levels)) { unset($languages[$i]); } else { $language->active = $language->lang_code == $lang->getTag(); if (JLanguageMultilang::isEnabled()) { if (isset($cassociations[$language->lang_code])) { $language->link = JRoute::_($cassociations[$language->lang_code] . '&lang=' . $language->sef); } elseif (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) { $itemid = $associations[$language->lang_code]; if ($app->get('sef') == '1') { $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid); } else { $language->link = 'index.php?lang=' . $language->sef . '&Itemid=' . $itemid; } } else { if ($app->get('sef') == '1') { $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id; $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid); } else { $language->link = 'index.php?lang=' . $language->sef; } } } else { $language->link = JRoute::_('&Itemid=' . $homes['*']->id); } } } return $languages; }
function getContinueShoppingUrl() { $params = J2Store::config(); $type = $params->get('config_continue_shopping_page', 'previous'); $item = new JObject(); $item->type = $type; switch ($type) { case 'previous': default: $item->url = ''; break; case 'menu': $url = ''; //get the menu item id $menu_itemid = $params->get('continue_shopping_page_menu', ''); if (empty($menu_itemid)) { $item->url = ''; $item->type = 'previous'; } else { $application = JFactory::getApplication(); $menu = $application->getMenu('site'); $menu_item = $menu->getItem($menu_itemid); if (is_object($menu_item)) { // we have the menu item. See if language associations are there JLoader::register('MenusHelper', JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php'); try { $associations = MenusHelper::getAssociations($menu_item->id); } catch (Exception $e) { $associations = array(); } //get the current language code $tag = JFactory::getLanguage()->getTag(); if (isset($associations[$tag])) { $cmenu = $menu->getItem($associations[$tag]); } else { $cmenu = $menu_item; } $link = JRoute::_($cmenu->link . '&Itemid=' . $cmenu->id, false); if (JURI::isInternal($link)) { $url = $link; } } if (empty($url)) { $item->url = ''; $item->type = 'previous'; } else { $item->url = $url; } } break; case 'url': $custom_url = $params->get('config_continue_shopping_page_url', ''); if (empty($custom_url)) { $item->url = ''; $item->type = 'previous'; } else { $item->url = $custom_url; } break; } //allow plugins to alter the checkout link. //This allows 3rd-party developers to create different checkout steps for j2store //Example. The plugin can return a completely different link J2Store::plugin()->event('GetContinueShoppingUrl', array(&$item)); return $item; }
/** * Return a list of Root Menu Items associated with the current Root Menu Item * * @access public * * @param null * * @return array */ public static function getRootItemAssociations() { $assoc = JLanguageAssociations::isEnabled(); if ($assoc == false) { return false; } $root_item = MageBridgeUrlHelper::getRootItem(); if ($root_item == false) { return false; } $associations = MenusHelper::getAssociations($root_item->id); return $associations; }
/** * function to discover a default item id only once */ static function _setDefaultMenuitemId() { // Cache the result on multiple calls static $_component_default_menuitem_id = null; if ( $_component_default_menuitem_id!==null ) return $_component_default_menuitem_id; // Default item not found (yet) ... set it to false to indicate that we tried $_component_default_menuitem_id = false; $curr_langtag = JFactory::getLanguage()->getTag(); // Current language tag for J2.5+ but not for J1.5 //$public_acclevel = !FLEXI_J16GE ? 0 : 1; $user = JFactory::getUser(); if (FLEXI_J16GE) $aid_arr = JAccess::getAuthorisedViewLevels($user->id); else $aid = (int) $user->get('aid'); // NOTE: In J1.5 the static method JSite::getMenu() will give an error, while JFactory::getApplication('site')->getMenu() will not return the frontend menus $menus = JFactory::getApplication()->getMenu('site', array()); // this will work in J1.5 backend too !!! // Get preference for default menu item $params = JComponentHelper::getParams('com_flexicontent'); $default_menuitem_preference = $params->get('default_menuitem_preference', 0); switch ($default_menuitem_preference) { case 1: // Try to use ACTIVE (current) menu item if pointing to Flexicontent, (if so configure in global options) $menu = $menus->getActive(); // Check that (a) it exists and is active (b) points to com_flexicontent if ($menu && @ $menu->query['option']=='com_flexicontent' ) { // For J1.5 access level is already OK (since active), for J2.5+ check language $item_matches = !FLEXI_J16GE ? true : ($curr_langtag == '*' || in_array($menu->language, array('*', $curr_langtag)) || !JLanguageMultilang::isEnabled()); // If matched set default and return it if ($item_matches) return $_component_default_menuitem_id = $menu->id; } // DO NOT BREAK HERE !! FALLBACK to 2 case 2: // Try to use (user defined) component's default menu item, (if so configure in global options) $_component_default_menuitem_id = $params->get('default_menu_itemid', false); $menu = $menus->getItem($_component_default_menuitem_id); // Check that (a) it exists and is active (b) points to com_flexicontent if ($menu && @ $menu->query['option']=='com_flexicontent' ) { // For J1.5 check access and for J2.5+ check language $item_matches = !FLEXI_J16GE ? ($menu->access <= $aid) : ($curr_langtag == '*' || in_array($menu->language, array('*', $curr_langtag)) || !JLanguageMultilang::isEnabled()); // If matched set default and return it if ($item_matches) return $_component_default_menuitem_id = $menu->id; // For J2.5+ we also need to try menu item associations and select the current language item if ( FLEXI_J16GE && $menu->language!='*' && $menu->language!='' && $menu->language!=$curr_langtag ) { require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_menus'.DS.'helpers'.DS.'menus.php'); $helper = new MenusHelper(); $associated = $helper->getAssociations($_component_default_menuitem_id); // Return associated menu item for current language if ( isset($associated[$curr_langtag]) ) $_component_default_menuitem_id = $associated[$curr_langtag]; } } return $_component_default_menuitem_id; } }
/** * function to discover a default item id only once */ static function _setLayoutDefaultMenuitemIds() { // Cache the result on multiple calls static $_layouts_default_menuitem_id = null; if ($_layouts_default_menuitem_id !== null) { return $_layouts_default_menuitem_id[$layout]; } // Default item not found (yet) ... set it to empty array to indicate that we tried $_layouts_default_menuitem_id = array(); $curr_langtag = JFactory::getLanguage()->getTag(); // Current language tag for J2.5+ but not for J1.5 // NOTE: In J1.5 the static method JSite::getMenu() will give an error, while JFactory::getApplication('site')->getMenu() will not return the frontend menus $menus = JFactory::getApplication()->getMenu('site', array()); // this will work in J1.5 backend too !!! // Get preference for default menu item $params = JComponentHelper::getParams('com_flexicontent'); $_layouts_default_menuitem_id = array(); $_layouts_default_menuitem_id['tags'] = $params->get('cat_tags_default_menu_itemid', 0); $_layouts_default_menuitem_id['favs'] = $params->get('cat_favs_default_menu_itemid', 0); $_layouts_default_menuitem_id['author'] = $params->get('cat_author_default_menu_itemid', 0); $_layouts_default_menuitem_id['myitems'] = $params->get('cat_myitems_default_menu_itemid', 0); $_layouts_default_menuitem_id['mcats'] = $params->get('cat_mcats_default_menu_itemid', 0); foreach ($_layouts_default_menuitem_id as $layout => $menuitem_id) { $menu = $menus->getItem($menuitem_id); // Check that (a) it exists and is active (b) points to com_flexicontent (c) is category view and of correct layout if ($menu && @$menu->query['option'] == 'com_flexicontent' && @$menu->query['view'] == 'category' && @$menu->query['layout'] == $layout) { // For J2.5+ check language, for J2.5+ checking access is not needed as it was done already above, by the JMenu::getItem() $item_matches = $curr_langtag == '*' || in_array($menu->language, array('*', $curr_langtag)) || !JLanguageMultilang::isEnabled(); // If item matched then selected menu item is good, continue with next layout type if ($item_matches) { continue; } // For J2.5+ we also need to try menu item associations and select the current language item if ($menu->language != '*' && $menu->language != '' && $menu->language != $curr_langtag) { require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_menus' . DS . 'helpers' . DS . 'menus.php'; $helper = new MenusHelper(); $associated = $helper->getAssociations($menuitem_id); // Assign the associated menu item as default, continue with next layout type if (isset($associated[$curr_langtag])) { // Check the associated menu item too $menu = $menus->getItem($associated[$curr_langtag]); if ($menu && @$menu->query['option'] == 'com_flexicontent' && @$menu->query['view'] == 'category' && @$menu->query['layout'] == $layout) { $_layouts_default_menuitem_id[$layout] = $associated[$curr_langtag]; continue; } } } } // Default menu item for the layout, did not match, clear it $_layouts_default_menuitem_id[$layout] = 0; } return $_layouts_default_menuitem_id; }
$active = $menu->getDefault(); } if ($tplparams->get('tpl_userpage_mid') == $active->id) { // Load associations $assoc = isset($app->item_associations) ? $app->item_associations : 0; if ($assoc) { // load component associations $option = $app->input->get('option'); $eName = JString::ucfirst(JString::str_ireplace('com_', '', $option)); $cName = JString::ucfirst($eName . 'HelperAssociation'); JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php')); if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) { $cassociations = call_user_func(array($cName, 'getAssociations')); } if (!empty($cassociations)) { $associations = MenusHelper::getAssociations($active->id); foreach ($list as $language) { if (!$language->active && $cassociations[$language->lang_code] && $associations[$language->lang_code]) { $language->link = JRoute::_(preg_replace('@Itemid=(\\d+)@', 'Itemid=' . $associations[$language->lang_code], $cassociations[$language->lang_code] . '&lang=' . $language->sef)); } } } } } ?> <div class="dropdown mod-languages"> <?php if ($headerText) { ?> <div class="pretext"><p><?php
/** * Method to get a menu item. * * @param integer $pk An optional id of the object to get, otherwise the id from the model state is used. * * @return mixed Menu item data object on success, false on failure. * @since 1.6 */ public function getItem($pk = null) { // Initialise variables. $pk = !empty($pk) ? $pk : (int) $this->getState('item.id'); // Get a level row instance. $table = $this->getTable(); // Attempt to load the row. $table->load($pk); // Check for a table object error. if ($error = $table->getError()) { $this->setError($error); $false = false; return $false; } // Prime required properties. if ($type = $this->getState('item.type')) { $table->type = $type; } if (empty($table->id)) { $table->parent_id = $this->getState('item.parent_id'); $table->menutype = $this->getState('item.menutype'); $table->params = '{}'; } // If the link has been set in the state, possibly changing link type. if ($link = $this->getState('item.link')) { // Check if we are changing away from the actual link type. if (MenusHelper::getLinkKey($table->link) != MenusHelper::getLinkKey($link)) { $table->link = $link; } } switch ($table->type) { case 'alias': $table->component_id = 0; $args = array(); parse_str(parse_url($table->link, PHP_URL_QUERY), $args); break; case 'separator': $table->link = ''; $table->component_id = 0; break; case 'url': $table->component_id = 0; parse_str(parse_url($table->link, PHP_URL_QUERY)); break; case 'component': default: // Enforce a valid type. $table->type = 'component'; // Ensure the integrity of the component_id field is maintained, particularly when changing the menu item type. $args = array(); parse_str(parse_url($table->link, PHP_URL_QUERY), $args); if (isset($args['option'])) { // Load the language file for the component. $lang = JFactory::getLanguage(); $lang->load($args['option'], JPATH_ADMINISTRATOR, null, false, false) || $lang->load($args['option'], JPATH_ADMINISTRATOR . '/components/' . $args['option'], null, false, false) || $lang->load($args['option'], JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($args['option'], JPATH_ADMINISTRATOR . '/components/' . $args['option'], $lang->getDefault(), false, false); // Determine the component id. $component = JComponentHelper::getComponent($args['option']); if (isset($component->id)) { $table->component_id = $component->id; } } break; } // We have a valid type, inject it into the state for forms to use. $this->setState('item.type', $table->type); // Convert to the JObject before adding the params. $properties = $table->getProperties(1); $result = JArrayHelper::toObject($properties, 'JObject'); // Convert the params field to an array. $registry = new JRegistry(); $registry->loadString($table->params); $result->params = $registry->toArray(); // Merge the request arguments in to the params for a component. if ($table->type == 'component') { // Note that all request arguments become reserved parameter names. $result->request = $args; $result->params = array_merge($result->params, $args); } if ($table->type == 'alias') { // Note that all request arguments become reserved parameter names. $args = array(); parse_str(parse_url($table->link, PHP_URL_QUERY), $args); $result->params = array_merge($result->params, $args); } if ($table->type == 'url') { // Note that all request arguments become reserved parameter names. $args = array(); parse_str(parse_url($table->link, PHP_URL_QUERY), $args); $result->params = array_merge($result->params, $args); } // Load associated menu items if (JFactory::getApplication()->get('menu_associations', 0)) { if ($pk != null) { $result->associations = MenusHelper::getAssociations($pk); } else { $result->associations = array(); } } $result->menuordering = $pk; return $result; }
public static function getList(&$params) { $lang = JFactory::getLanguage(); $languages = JLanguageHelper::getLanguages(); $app = JFactory::getApplication(); //use to remove default language code in url $lang_codes = JLanguageHelper::getLanguages('lang_code'); $default_lang = JComponentHelper::getParams('com_languages')->get('site', 'en-GB'); $default_sef = $lang_codes[$default_lang]->sef; $sefToolsEnabled = modFaLangHelper::sefToolEnabled(); $menu = $app->getMenu(); $active = $menu->getActive(); $uri = JURI::getInstance(); // Get menu home items $homes = array(); foreach ($menu->getMenu() as $item) { if ($item->home) { $homes[$item->language] = $item; } } if (FALANG_J30) { //since 3.2 if (version_compare(JVERSION, '3.2', 'ge')) { $assoc = JLanguageAssociations::isEnabled(); } else { $assoc = isset($app->item_associations) ? (boolean) $app->item_associations : false; } } else { $assoc = (boolean) $app->get('menu_associations', true); } if ($assoc) { if ($active) { $associations = MenusHelper::getAssociations($active->id); } } foreach($languages as $i => &$language) { // Do not display language without frontend UI if (!JLanguage::exists($language->lang_code)) { unset($languages[$i]); } if (FALANG_J30) { $language_filter = JLanguageMultilang::isEnabled(); } else { $language_filter = $app->getLanguageFilter(); } //set language active before language filter use for sh404 notice $language->active = $language->lang_code == $lang->getTag(); //since v1.4 change in 1.5 , ex rsform preview don't have active if (isset($active)){ $language->display = ($active->language == '*' || $language->active)?true:false; } else { $language->display = true; } if ($language_filter) { if (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) { $language->display = true; $itemid = $associations[$language->lang_code]; if ($app->getCfg('sef')=='1') { $language->link = JRoute::_('index.php?lang='.$language->sef.'&Itemid='.$itemid); } else { $language->link = 'index.php?lang='.$language->sef.'&Itemid='.$itemid; } } else { //sef case if ($app->getCfg('sef')=='1') { //sefToolsEnabled if ($sefToolsEnabled) { $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id; $language->link = JRoute::_('index.php?lang='.$language->sef.'&Itemid='.$itemid); continue; } //$uri->setVar('lang',$language->sef); $router = JApplication::getRouter(); $tmpuri = clone($uri); $router->parse($tmpuri); $vars = $router->getVars(); //workaround to fix index language $vars['lang'] = $language->sef; //case of category article if (!empty($vars['view']) && $vars['view'] == 'article' && !empty($vars['option']) && $vars['option'] == 'com_content') { if (FALANG_J30){ JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel'); $model = JModelLegacy::getInstance('Article', 'ContentModel', array('ignore_request'=>true)); $appParams = JFactory::getApplication()->getParams(); } else { JModel::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel'); $model =& JModel::getInstance('Article', 'ContentModel', array('ignore_request'=>true)); $appParams = JFactory::getApplication()->getParams(); } $model->setState('params', $appParams); //in sef some link have this url //index.php/component/content/article?id=39 //id is not in vars but in $tmpuri if (empty($vars['id'])) { $tmpid = $tmpuri->getVar('id'); if (!empty($tmpid)) { $vars['id'] = $tmpuri->getVar('id'); } else { continue; } } $item = $model->getItem($vars['id']); //get alias of content item without the id , so i don't have the translation $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('alias')->from('#__content')->where('id = ' . (int) $item->id); $db->setQuery($query); $alias = $db->loadResult(); $vars['id'] = $item->id.':'.$alias; $vars['catid'] =$item->catid.':'.$item->category_alias; } //new version 1.5 //case for k2 item alias write twice if (isset($vars['option']) && $vars['option'] == 'com_k2'){ if ($vars['task'] == $vars['id']){ unset($vars['id']); } } $url = 'index.php?'.JURI::buildQuery($vars); $language->link = JRoute::_($url); //TODO check performance 3 queries by languages -1 /** * Replace the slug from the language switch with correctly translated slug. * $language->lang_code language de la boucle (icone lien) * $lang->getTag() => language en cours sur le site * $default_lang langue par default du site */ if($lang->getTag() != $language->lang_code && !empty($vars['Itemid'])) { $fManager = FalangManager::getInstance(); $id_lang = $fManager->getLanguageID($language->lang_code); $db = JFactory::getDbo(); // get translated path if exist $query = $db->getQuery(true); $query->select('fc.value') ->from('#__falang_content fc') ->where('fc.reference_id = '.(int)$vars['Itemid']) ->where('fc.language_id = '.(int) $id_lang ) ->where('fc.reference_field = \'path\'') ->where('fc.reference_table = \'menu\''); $db->setQuery($query); $translatedPath = $db->loadResult(); // $translatedPath not exist if not translated or site default language // don't pass id to the query , so no translation given by falang $query = $db->getQuery(true); $query->select('m.path') ->from('#__menu m') ->where('m.id = '.(int)$vars['Itemid']); $db->setQuery($query); $originalPath = $db->loadResult(); $pathInUse = null; //si on est sur une page traduite on doit récupérer la traduction du path en cours if ($default_lang != $lang->getTag() ) { $id_lang = $fManager->getLanguageID($lang->getTag()); // get translated path if exist $query = $db->getQuery(true); $query->select('fc.value') ->from('#__falang_content fc') ->where('fc.reference_id = '.(int)$vars['Itemid']) ->where('fc.language_id = '.(int) $id_lang ) ->where('fc.reference_field = \'path\'') ->where('fc.reference_table = \'menu\''); $db->setQuery($query); $pathInUse = $db->loadResult(); } if (!isset($translatedPath)) { $translatedPath = $originalPath; } // not exist if not translated or site default language if (!isset($pathInUse)) { $pathInUse = $originalPath ; } //make replacement in the url //si language de boucle et language site if($language->lang_code == $default_lang) { if (isset($pathInUse) && isset($originalPath)){ $language->link = str_replace($pathInUse, $originalPath, $language->link); } } else { if (isset($pathInUse) && isset($translatedPath)){ $language->link = str_replace($pathInUse, $translatedPath, $language->link); } } } } //default case else { //we can't remove default language in the link $uri->setVar('lang',$language->sef); $language->link = 'index.php?'.$uri->getQuery(); } } } else { $language->link = 'index.php'; } } return $languages; }
/** * Method to add alternative meta tags for associated menu items. * * @return void * * @since 1.7 */ public function onAfterDispatch() { $doc = JFactory::getDocument(); if ($this->app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') { $languages = $this->lang_codes; $homes = JLanguageMultilang::getSiteHomePages(); $menu = $this->app->getMenu(); $active = $menu->getActive(); $levels = JFactory::getUser()->getAuthorisedViewLevels(); $remove_default_prefix = $this->params->get('remove_default_prefix', 0); $server = JUri::getInstance()->toString(array('scheme', 'host', 'port')); $is_home = false; if ($active) { $active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false); $current_link = JUri::getInstance()->toString(array('path', 'query')); // Load menu associations if ($active_link == $current_link) { $associations = MenusHelper::getAssociations($active->id); } // Check if we are on the homepage $is_home = $active->home && ($active_link == $current_link || $active_link == $current_link . 'index.php' || $active_link . '/' == $current_link); } // Load component associations. $option = $this->app->input->get('option'); $cName = JString::ucfirst(JString::str_ireplace('com_', '', $option)) . 'HelperAssociation'; JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php')); if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) { $cassociations = call_user_func(array($cName, 'getAssociations')); } // For each language... foreach ($languages as $i => &$language) { switch (true) { // Language without frontend UI || Language without specific home menu || Language without authorized access level case !array_key_exists($i, JLanguageMultilang::getSiteLangs()): case !isset($homes[$i]): case isset($language->access) && $language->access && !in_array($language->access, $levels): unset($languages[$i]); break; // Home page // Home page case $is_home: $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $homes[$i]->id); break; // Current language link // Current language link case $i == $this->current_lang: $language->link = JUri::getInstance()->toString(array('path', 'query')); break; // Component association // Component association case isset($cassociations[$i]): $language->link = JRoute::_($cassociations[$i] . '&lang=' . $language->sef); break; // Menu items association // Heads up! "$item = $menu" here below is an assignment, *NOT* comparison // Menu items association // Heads up! "$item = $menu" here below is an assignment, *NOT* comparison case isset($associations[$i]) && ($item = $menu->getItem($associations[$i])): $language->link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef); break; // Too bad... // Too bad... default: unset($languages[$i]); } } // If there are at least 2 of them, add the rel="alternate" links to the <head> if (count($languages) > 1) { // Remove the sef from the default language if "Remove URL Language Code" is on if (isset($languages[$this->default_lang]) && $remove_default_prefix) { $languages[$this->default_lang]->link = preg_replace('|/' . $languages[$this->default_lang]->sef . '/|', '/', $languages[$this->default_lang]->link, 1); } foreach ($languages as $i => &$language) { $doc->addHeadLink($server . $language->link, 'alternate', 'rel', array('hreflang' => $i)); } // Add x-default language tag if ($this->params->get('xdefault', 1)) { $xdefault_language = $this->params->get('xdefault_language', $this->default_lang); $xdefault_language = $xdefault_language == 'default' ? $this->default_lang : $xdefault_language; if (isset($languages[$xdefault_language])) { // Use a custom tag because addHeadLink is limited to one URI per tag $doc->addCustomTag('<link href="' . $server . $languages[$xdefault_language]->link . '" rel="alternate" hreflang="x-default" />'); } } } } }
/** * Gets a list of available languages * * @param \Joomla\Registry\Registry &$params module params * * @return array */ public static function getList(&$params) { $user = JFactory::getUser(); $lang = JFactory::getLanguage(); $languages = JLanguageHelper::getLanguages(); $app = JFactory::getApplication(); $menu = $app->getMenu(); // Get menu home items $homes = array(); $homes['*'] = $menu->getDefault('*'); foreach ($languages as $item) { $default = $menu->getDefault($item->lang_code); if ($default && $default->language == $item->lang_code) { $homes[$item->lang_code] = $default; } } // Load associations $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $active = $menu->getActive(); if ($active) { $associations = MenusHelper::getAssociations($active->id); } // Load component associations $class = str_replace('com_', '', $app->input->get('option')) . 'HelperAssociation'; JLoader::register($class, JPATH_COMPONENT_SITE . '/helpers/association.php'); if (class_exists($class) && is_callable(array($class, 'getAssociations'))) { $cassociations = call_user_func(array($class, 'getAssociations')); } } $levels = $user->getAuthorisedViewLevels(); // Filter allowed languages foreach ($languages as $i => &$language) { // Do not display language without frontend UI if (!array_key_exists($language->lang_code, MultilangstatusHelper::getSitelangs())) { unset($languages[$i]); } elseif (!isset($homes[$language->lang_code])) { unset($languages[$i]); } elseif (isset($language->access) && $language->access && !in_array($language->access, $levels)) { unset($languages[$i]); } else { $language->active = $language->lang_code == $lang->getTag(); if (JLanguageMultilang::isEnabled()) { if (isset($cassociations[$language->lang_code])) { $language->link = JRoute::_($cassociations[$language->lang_code] . '&lang=' . $language->sef); } 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); } else { if ($language->active) { $language->link = JUri::getInstance()->toString(array('scheme', 'host', 'port', 'path', 'query')); } else { $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id; $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid); } } } else { $language->link = JRoute::_('&Itemid=' . $homes['*']->id); } } } return $languages; }
/** * This method adds alternate meta tags for associated menu items * * @return nothing * @since 1.7 */ public function onAfterDispatch() { $app = JFactory::getApplication(); $doc = JFactory::getDocument(); if ($app->isSite() && $this->params->get('alternate_meta') && $doc->getType() == 'html') { // Get active menu item $active = $app->getMenu()->getActive(); if (!$active) { return; } // Get menu item link if ($app->getCfg('sef')) { $active_link = JRoute::_('index.php?Itemid=' . $active->id, false); } else { $active_link = JRoute::_($active->link . '&Itemid=' . $active->id, false); } if ($active_link == JUri::base(true) . '/') { $active_link .= 'index.php'; } // Get current link $current_link = JRequest::getUri(); if ($current_link == JUri::base(true) . '/') { $current_link .= 'index.php'; } // Check the exact menu item's URL if ($active_link == $current_link) { // Get menu item associations JLoader::register('MenusHelper', JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php'); $associations = MenusHelper::getAssociations($active->id); // Remove current menu item unset($associations[$active->language]); // Associated menu items in other languages if ($associations && $this->params->get('menu_associations')) { $menu = $app->getMenu(); $server = JURI::getInstance()->toString(array('scheme', 'host', 'port')); foreach (JLanguageHelper::getLanguages() as $language) { if (isset($associations[$language->lang_code])) { $item = $menu->getItem($associations[$language->lang_code]); if ($item && JLanguage::exists($language->lang_code)) { if ($app->getCfg('sef')) { $link = JRoute::_('index.php?Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef, false); } else { $link = JRoute::_($item->link . '&Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef, false); } $doc->addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code)); } } } } elseif ($active->home) { $menu = $app->getMenu(); $server = JURI::getInstance()->toString(array('scheme', 'host', 'port')); foreach (JLanguageHelper::getLanguages() as $language) { $item = $menu->getDefault($language->lang_code); if ($item && $item->language != $active->language && $item->language != '*' && JLanguage::exists($language->lang_code)) { if ($app->getCfg('sef')) { $link = JRoute::_('index.php?Itemid=' . $item->id . '&lang=' . $language->sef, false); } else { $link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef, false); } $doc->addHeadLink($server . JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef), 'alternate', 'rel', array('hreflang' => $language->lang_code)); } } } } } }
public static function getRouteByStorage(&$storage, $sef, $itemId, $config = array(), $lang_tag = '') { if (isset($storage[self::$table]->_route) && !$lang_tag) { return JRoute::_($storage[self::$table]->_route); } if ($sef) { if ($sef == '0' || $sef == '1') { $path = '&catid=' . $storage[self::$table]->catid; } elseif ($sef[0] == '4') { $path = '&catid=' . (isset($storage[self::$table]->category_alias) ? $storage[self::$table]->category_alias : $storage[self::$table]->catid); } elseif ($sef[0] == '3') { $path = '&typeid=' . $config['type']; } else { $path = ''; } if (is_object($storage[self::$table])) { $storage[self::$table]->_route = self::_getRoute($sef, $itemId, $storage[self::$table]->slug, $path); } // Multilanguage Associations if (JCckDevHelper::hasLanguageAssociations()) { $app = JFactory::getApplication(); $pk = $storage[self::$table]->id; if ($app->input->get('view') == 'article' && $app->input->get('id') == $storage[self::$table]->id && !count(self::$routes)) { JLoader::register('MenusHelper', JPATH_ADMINISTRATOR . '/components/com_menus/helpers/menus.php'); $assoc_c = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $pk); $assoc_m = MenusHelper::getAssociations($itemId); $languages = JLanguageHelper::getLanguages(); $lang_code = JFactory::getLanguage()->getTag(); foreach ($languages as $l) { if ($lang_code == $l->lang_code) { self::$routes[$l->lang_code] = $storage[self::$table]->_route; } else { $itemId2 = isset($assoc_m[$l->lang_code]) ? $assoc_m[$l->lang_code] : 0; $pk2 = isset($assoc_c[$l->lang_code]) ? (int) $assoc_c[$l->lang_code]->id : 0; self::$routes[$l->lang_code] = ''; if ($pk2 && $itemId2) { self::$routes[$l->lang_code] = self::getRoute($pk2, $sef, $itemId2, $config, $l->sef); } } } } } } else { require_once JPATH_SITE . '/components/com_content/helpers/route.php'; $storage[self::$table]->_route = ContentHelperRoute::getArticleRoute($storage[self::$table]->slug, $storage[self::$table]->catid, $storage[self::$table]->language); } return JRoute::_($storage[self::$table]->_route); }