input; $view = is_null($view) ? $jinput->get('view', '', 'cmd') : $view; $id = empty($id) ? $jinput->get('id', 0, 'int') : $id; if ($view === 'item') { $associations = $id ? self::getItemAssociations($id) : array(); if (!$associations) { return self::_getMenuAssociations($view, $id); } foreach ($associations as $tag => $assoc) { $lang_code = substr($tag, 0, 2); $return[$tag] = FlexicontentHelperRoute::getItemRoute($assoc->title_slug, $assoc->cat_slug, 0, $assoc); //. '&lang=' . $lang_code; } return $return; } elseif ($view === 'category') { $cid = $jinput->getInt('cid'); $layout = $jinput->getCmd('layout'); if ($layout === 'tags') { $tagid = $jinput->getInt('tagid', 0); $associations = $tagid ? self::getTagAssociations($tagid) : array(); if ($associations) { $urlvars = flexicontent_html::getCatViewLayoutVars($catmodel = null, $use_slug = true); foreach ($associations as $tag => $assoc) { $lang_code = substr($tag, 0, 2); $return[$tag] = FlexicontentHelperRoute::getCategoryRoute($cid, 0, $urlvars, $assoc); //. '&lang=' . $lang_code; } return $return; } } $associations = $cid ? self::getCatAssociations($cid) : array(); if (!$associations) { return self::_getMenuAssociations($view, $cid); } $urlvars = flexicontent_html::getCatViewLayoutVars($catmodel = null, $use_slug = true); foreach ($associations as $tag => $assoc) { $lang_code = substr($tag, 0, 2); $return[$tag] = FlexicontentHelperRoute::getCategoryRoute($assoc->title_slug, 0, $urlvars, $assoc); //. '&lang=' . $lang_code; } return $return; } else { // We do not have do associations for legacy views, use current Joomla menu item associations return array(); } } public static function getItemAssociations($item_id) { if (!$item_id) { return array(); } $db = \Joomla\CMS\Factory::getDbo(); $query = 'SELECT i.language, ie.type_id, i.id, i.catid, ' . ' CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(":", i.id, i.alias) ELSE i.id END as title_slug, ' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as cat_slug ' . ' FROM #__associations AS a' . ' JOIN #__associations AS k ON a.`key`=k.`key`' . ' JOIN #__content AS i ON i.id = k.id' . ' JOIN #__flexicontent_items_ext AS ie ON ie.item_id = i.id ' . ' JOIN #__categories AS c ON c.id = i.catid ' . ' WHERE a.id = '. $item_id .' AND a.context = ' . $db->Quote('com_content.item'); $translations = $db->setQuery($query)->loadObjectList('language'); return $translations; } public static function getTagAssociations($tag_id) { if (!$tag_id) { return array(); } $db = \Joomla\CMS\Factory::getDbo(); if (!FLEXI_FALANG) return array(); $query = //'SELECT la.lang_code AS language, t.id AS id, ' 'SELECT la.lang_code AS language, t.id AS id, ' . ' CASE WHEN CHAR_LENGTH(fat.value) THEN fat.value ELSE t.name END as title, ' . ' CONCAT_WS(":", t.id, t.alias) AS title_slug ' //. ' CASE WHEN CHAR_LENGTH(faa.value) THEN CONCAT_WS(":", t.id, faa.value) ELSE CONCAT_WS(":", t.id, t.alias) END as title_slug ' .' FROM #__flexicontent_tags AS t' .' JOIN #__tags AS jt ON t.jtag_id = jt.id' . ' JOIN #__falang_content AS fat ON fat.reference_table = "tags" ' . ' AND fat.reference_field = "title" AND fat.reference_id = t.jtag_id' . ' LEFT JOIN #__falang_content AS faa ON faa.reference_table = "tags" ' . ' AND faa.reference_field = "alias" AND faa.reference_id = t.jtag_id' . ' JOIN #__languages AS la ON la.lang_id = fat.language_id ' . ' WHERE t.id = '. $tag_id; ; $translations = $db->setQuery($query)->loadObjectList('language'); $lang = flexicontent_html::getSiteDefaultLang(); if ($translations && !isset($translations[$lang])) { $tag = $db->setQuery('SELECT t.name AS title, CONCAT_WS(":", t.id, t.alias) AS title_slug ' . ' FROM #__flexicontent_tags AS t' . ' WHERE t.id = '. $tag_id )->loadObject(); $translations[$lang] = (object) array('language' => $lang, 'id' => ($tag_id), 'title' => $tag->title, 'title_slug' => $tag->title_slug); } //echo '
'; print_r($translations); echo '
'; exit; return $translations; } public static function getCatAssociations($cat_id) { if (!$cat_id) { return array(); } $db = \Joomla\CMS\Factory::getDbo(); $query = 'SELECT c.language, c.id, ' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as title_slug ' . ' FROM #__associations AS a' . ' JOIN #__associations AS k ON a.`key`=k.`key`' . ' JOIN #__categories AS c ON c.id = k.id ' . ' WHERE a.id = '. $cat_id .' AND a.context = ' . $db->Quote('com_categories.item'); $translations = $db->setQuery($query)->loadObjectList('language'); return $translations; } private static function _getMenuAssociations($view, $id) { if ($view == 'item') { $record = \Joomla\CMS\Table\Table::getInstance('flexicontent_items', ''); $record->load(array('id' => $id)); } elseif ($view == 'category') { $record = \Joomla\CMS\Table\Table::getInstance('flexicontent_categories', ''); $record->load(array('id' => $id)); } if (($view !== 'item' && $view !== 'category') || $record->language !== '*') { return array(); } $app = \Joomla\CMS\Factory::getApplication(); $jinput = $app->input; $menus = $app->getMenu(); $Itemid = $jinput->getInt('Itemid', 0); $langAssociations = \Joomla\CMS\Language\Associations::getAssociations('com_menus', '#__menu', 'com_menus.item', $Itemid, 'id', '', ''); $associations = array(); foreach ($langAssociations as $tag => $menu_item) { $menu = $menus->getItem($menu_item->id); $moption = isset($menu->query['option']) ? $menu->query['option'] : ''; $matched = false; if (0 && $moption !== 'com_flexicontent') { // Active menu is a Non-flexicontent menu item, e.g. a Joomla category or Joomla article menu item // just switch to associated menu item without also pointing to the record $associations[$tag] = 'index.php?Itemid=' . $menu_item->id; } elseif ($view === 'item') { $title_slug = $record->id . ':' . $record->alias; $cat_slug = self::_getItemCatSlug($record, $menu); $lang_code = substr($tag, 0, 2); $associations[$tag] = FlexicontentHelperRoute::getItemRoute($title_slug, $cat_slug, $menu_item->id, $record); //. '&lang=' . $lang_code; } elseif ($view === 'category') { $title_slug = $record->id . ':' . $record->alias; $urlvars = flexicontent_html::getCatViewLayoutVars($catmodel = null, $use_slug = true); $lang_code = substr($tag, 0, 2); $associations[$tag] = FlexicontentHelperRoute::getCategoryRoute($title_slug, $menu_item->id, $urlvars, $record); //. '&lang=' . $lang_code; } else { // UNHANDLED view case, switch to associated menu item without also pointing to the record $associations[$tag] = 'index.php?Itemid=' . $menu_item->id; } } return $associations; } /** * Get category slug for a content item, considering if the given menu item points to a category belonging to the item */ private static function _getItemCatSlug($record, $menu) { $db = \Joomla\CMS\Factory::getDbo(); $moption = isset($menu->query['option']) ? $menu->query['option'] : ''; $mview = isset($menu->query['view']) ? $menu->query['view'] : ''; $mcid = isset($menu->query['cid']) ? $menu->query['cid'] : ''; /** * Get the categories assigned to the item */ $catids = array(); if ($moption === 'com_flexicontent' && $mview === 'category' && $mcid) { $query = $db->getQuery(true)->select('catid') ->from('#__flexicontent_cats_item_relations') ->where('itemid = ' . (int) $record->id); $catids = $db->setQuery($query)->loadColumn(); } // Use matching category from menu item, otherwise use main category of item $matched_cid = in_array($mcid, $catids) ? $mcid : $record->catid; $cat = \Joomla\CMS\Table\Table::getInstance('flexicontent_categories', ''); $cat->load(array('id' => $matched_cid)); return $matched_cid . ($cat ? ':' . $cat->alias : ''); } }