Source for file route.php

Documentation is available at route.php

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

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