Source for file route.php

Documentation is available at route.php

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

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