Source for file route.php

Documentation is available at route.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_contact
  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.  * Contact Component Route Helper
  14.  *
  15.  * @static
  16.  * @package     Joomla.Site
  17.  * @subpackage  com_contact
  18.  * @since       1.5
  19.  */
  20. abstract class ContactHelperRoute
  21. {
  22.     protected static $lookup;
  23.  
  24.     protected static $lang_lookup array();
  25.  
  26.     /**
  27.      * @param   integer  The route of the contact
  28.      */
  29.     public static function getContactRoute($id$catid$language 0)
  30.     {
  31.         $needles array(
  32.             'contact'  => array((int) $id)
  33.         );
  34.         //Create the link
  35.         $link 'index.php?option=com_contact&view=contact&id='$id;
  36.         if ($catid 1)
  37.         {
  38.             $categories JCategories::getInstance('Contact');
  39.             $category $categories->get($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('Contact')->get($id);
  77.         }
  78.  
  79.         if ($id || !($category instanceof JCategoryNode))
  80.         {
  81.             $link '';
  82.         }
  83.         else
  84.         {
  85.             $needles array();
  86.  
  87.             // Create the link
  88.             $link 'index.php?option=com_contact&view=category&id=' $id;
  89.  
  90.             $catids array_reverse($category->getPath());
  91.             $needles['category'$catids;
  92.             $needles['categories'$catids;
  93.  
  94.             if ($language && $language != "*" && JLanguageMultilang::isEnabled())
  95.             {
  96.                 self::buildLanguageLookup();
  97.  
  98.                 if (isset(self::$lang_lookup[$language]))
  99.                 {
  100.                     $link .= '&lang=' self::$lang_lookup[$language];
  101.                     $needles['language'$language;
  102.                 }
  103.             }
  104.  
  105.             if ($item self::_findItem($needles))
  106.             {
  107.                 $link .= '&Itemid='.$item;
  108.             }
  109.         }
  110.  
  111.         return $link;
  112.     }
  113.  
  114.     protected static function buildLanguageLookup()
  115.     {
  116.         if (count(self::$lang_lookup== 0)
  117.         {
  118.             $db    JFactory::getDbo();
  119.             $query $db->getQuery(true)
  120.                 ->select('a.sef AS sef')
  121.                 ->select('a.lang_code AS lang_code')
  122.                 ->from('#__languages AS a');
  123.  
  124.             $db->setQuery($query);
  125.             $langs $db->loadObjectList();
  126.  
  127.             foreach ($langs as $lang)
  128.             {
  129.                 self::$lang_lookup[$lang->lang_code$lang->sef;
  130.             }
  131.         }
  132.     }
  133.  
  134.     protected static function _findItem($needles null)
  135.     {
  136.         $app        JFactory::getApplication();
  137.         $menus        $app->getMenu('site');
  138.         $language    = isset($needles['language']$needles['language''*';
  139.  
  140.         // Prepare the reverse lookup array.
  141.         if (!isset(self::$lookup[$language]))
  142.         {
  143.             self::$lookup[$languagearray();
  144.  
  145.             $component    JComponentHelper::getComponent('com_contact');
  146.  
  147.             $attributes array('component_id');
  148.             $values array($component->id);
  149.  
  150.             if ($language != '*')
  151.             {
  152.                 $attributes['language';
  153.                 $values[array($needles['language']'*');
  154.             }
  155.  
  156.             $items $menus->getItems($attributes$values);
  157.  
  158.             foreach ($items as $item)
  159.             {
  160.                 if (isset($item->query&& isset($item->query['view']))
  161.                 {
  162.                     $view $item->query['view'];
  163.                     if (!isset(self::$lookup[$language][$view]))
  164.                     {
  165.                         self::$lookup[$language][$viewarray();
  166.                     }
  167.                     if (isset($item->query['id']))
  168.                     {
  169.  
  170.                         // here it will become a bit tricky
  171.                         // language != * can override existing entries
  172.                         // language == * cannot override existing entries
  173.                         if (!isset(self::$lookup[$language][$view][$item->query['id']]|| $item->language != '*')
  174.                         {
  175.                             self::$lookup[$language][$view][$item->query['id']] $item->id;
  176.                         }
  177.                     }
  178.                 }
  179.             }
  180.         }
  181.  
  182.         if ($needles)
  183.         {
  184.             foreach ($needles as $view => $ids)
  185.             {
  186.                 if (isset(self::$lookup[$language][$view]))
  187.                 {
  188.                     foreach ($ids as $id)
  189.                     {
  190.                         if (isset(self::$lookup[$language][$view][(int) $id]))
  191.                         {
  192.                             return self::$lookup[$language][$view][(int) $id];
  193.                         }
  194.                     }
  195.                 }
  196.             }
  197.         }
  198.  
  199.         $active $menus->getActive();
  200.         if ($active && ($active->language == '*' || !JLanguageMultilang::isEnabled()))
  201.         {
  202.             return $active->id;
  203.         }
  204.  
  205.         // if not found, return language specific home link
  206.         $default $menus->getDefault($language);
  207.         return !empty($default->id$default->id null;
  208.     }
  209. }

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