Source for file route.php

Documentation is available at route.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_content
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Content Component Route Helper
  14.  *
  15.  * @static
  16.  * @package     Joomla.Site
  17.  * @subpackage  com_content
  18.  * @since       1.5
  19.  */
  20. abstract class ContentHelperRoute
  21. {
  22.     protected static $lookup array();
  23.  
  24.     protected static $lang_lookup array();
  25.  
  26.     /**
  27.      * @param   integer  The route of the content item
  28.      */
  29.     public static function getArticleRoute($id$catid 0$language 0)
  30.     {
  31.         $needles array(
  32.             'article'  => array((int) $id)
  33.         );
  34.         //Create the link
  35.         $link 'index.php?option=com_content&view=article&id='$id;
  36.         if ((int) $catid 1)
  37.         {
  38.             $categories JCategories::getInstance('Content');
  39.             $category $categories->get((int) $catid);
  40.             if ($category)
  41.             {
  42.                 $needles['category'array_reverse($category->getPath());
  43.                 $needles['categories'$needles['category'];
  44.                 $link .= '&catid='.$catid;
  45.             }
  46.         }
  47.         if ($language && $language != "*" && JLanguageMultilang::isEnabled())
  48.         {
  49.             self::buildLanguageLookup();
  50.  
  51.             if (isset(self::$lang_lookup[$language]))
  52.             {
  53.                 $link .= '&lang=' self::$lang_lookup[$language];
  54.                 $needles['language'$language;
  55.             }
  56.         }
  57.  
  58.         if ($item self::_findItem($needles))
  59.         {
  60.             $link .= '&Itemid='.$item;
  61.         }
  62.  
  63.         return $link;
  64.     }
  65.  
  66.     public static function getCategoryRoute($catid$language 0)
  67.     {
  68.         if ($catid instanceof JCategoryNode)
  69.         {
  70.             $id $catid->id;
  71.             $category $catid;
  72.         }
  73.         else
  74.         {
  75.             $id = (int) $catid;
  76.             $category JCategories::getInstance('Content')->get($id);
  77.         }
  78.  
  79.         if ($id || !($category instanceof JCategoryNode))
  80.         {
  81.             $link '';
  82.         }
  83.         else
  84.         {
  85.             $needles array();
  86.  
  87.             $link 'index.php?option=com_content&view=category&id='.$id;
  88.  
  89.             $catids array_reverse($category->getPath());
  90.             $needles['category'$catids;
  91.             $needles['categories'$catids;
  92.  
  93.             if ($language && $language != "*" && JLanguageMultilang::isEnabled())
  94.             {
  95.                 self::buildLanguageLookup();
  96.  
  97.                 if(isset(self::$lang_lookup[$language]))
  98.                 {
  99.                     $link .= '&lang=' self::$lang_lookup[$language];
  100.                     $needles['language'$language;
  101.                 }
  102.             }
  103.  
  104.             if ($item self::_findItem($needles))
  105.             {
  106.                 $link .= '&Itemid='.$item;
  107.             }
  108.         }
  109.  
  110.         return $link;
  111.     }
  112.  
  113.     public static function getFormRoute($id)
  114.     {
  115.         //Create the link
  116.         if ($id)
  117.         {
  118.             $link 'index.php?option=com_content&task=article.edit&a_id='$id;
  119.         }
  120.         else
  121.         {
  122.             $link 'index.php?option=com_content&task=article.edit&a_id=0';
  123.         }
  124.  
  125.         return $link;
  126.     }
  127.  
  128.     protected static function buildLanguageLookup()
  129.     {
  130.         if (count(self::$lang_lookup== 0)
  131.         {
  132.             $db    JFactory::getDbo();
  133.             $query $db->getQuery(true)
  134.                 ->select('a.sef AS sef')
  135.                 ->select('a.lang_code AS lang_code')
  136.                 ->from('#__languages AS a');
  137.  
  138.             $db->setQuery($query);
  139.             $langs $db->loadObjectList();
  140.  
  141.             foreach ($langs as $lang)
  142.             {
  143.                 self::$lang_lookup[$lang->lang_code$lang->sef;
  144.             }
  145.         }
  146.     }
  147.  
  148.     protected static function _findItem($needles null)
  149.     {
  150.         $app        JFactory::getApplication();
  151.         $menus        $app->getMenu('site');
  152.         $language    = isset($needles['language']$needles['language''*';
  153.  
  154.         // Prepare the reverse lookup array.
  155.         if (!isset(self::$lookup[$language]))
  156.         {
  157.             self::$lookup[$languagearray();
  158.  
  159.             $component    JComponentHelper::getComponent('com_content');
  160.  
  161.             $attributes array('component_id');
  162.             $values array($component->id);
  163.  
  164.             if ($language != '*')
  165.             {
  166.                 $attributes['language';
  167.                 $values[array($needles['language']'*');
  168.             }
  169.  
  170.             $items        $menus->getItems($attributes$values);
  171.  
  172.             foreach ($items as $item)
  173.             {
  174.                 if (isset($item->query&& isset($item->query['view']))
  175.                 {
  176.                     $view $item->query['view'];
  177.                     if (!isset(self::$lookup[$language][$view]))
  178.                     {
  179.                         self::$lookup[$language][$viewarray();
  180.                     }
  181.                     if (isset($item->query['id'])) {
  182.  
  183.                         // here it will become a bit tricky
  184.                         // language != * can override existing entries
  185.                         // language == * cannot override existing entries
  186.                         if (!isset(self::$lookup[$language][$view][$item->query['id']]|| $item->language != '*')
  187.                         {
  188.                             self::$lookup[$language][$view][$item->query['id']] $item->id;
  189.                         }
  190.                     }
  191.                 }
  192.             }
  193.         }
  194.  
  195.         if ($needles)
  196.         {
  197.             foreach ($needles as $view => $ids)
  198.             {
  199.                 if (isset(self::$lookup[$language][$view]))
  200.                 {
  201.                     foreach ($ids as $id)
  202.                     {
  203.                         if (isset(self::$lookup[$language][$view][(int) $id]))
  204.                         {
  205.                             return self::$lookup[$language][$view][(int) $id];
  206.                         }
  207.                     }
  208.                 }
  209.             }
  210.         }
  211.  
  212.         $active $menus->getActive();
  213.         if ($active && $active->component == 'com_content' && ($active->language == '*' || !JLanguageMultilang::isEnabled()))
  214.         {
  215.             return $active->id;
  216.         }
  217.  
  218.         // if not found, return language specific home link
  219.         $default $menus->getDefault($language);
  220.         return !empty($default->id$default->id null;
  221.     }
  222. }

Documentation generated on Tue, 19 Nov 2013 15:12:21 +0100 by phpDocumentor 1.4.3