Source for file route.php

Documentation is available at route.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_finder
  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
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Finder route helper class.
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_finder
  17.  * @since       2.5
  18.  */
  19. {
  20.     /**
  21.      * Method to get the route for a search page.
  22.      *
  23.      * @param   integer  $f  The search filter id. [optional]
  24.      * @param   string   $q  The search query string. [optional]
  25.      *
  26.      * @return  string  The search route.
  27.      *
  28.      * @since   2.5
  29.      */
  30.     public static function getSearchRoute($f null$q null)
  31.     {
  32.         // Get the menu item id.
  33.         $query array('view' => 'search''q' => $q'f' => $f);
  34.         $item self::getItemid($query);
  35.  
  36.         // Get the base route.
  37.         $uri clone(JUri::getInstance('index.php?option=com_finder&view=search'));
  38.  
  39.         // Add the pre-defined search filter if present.
  40.         if ($f !== null)
  41.         {
  42.             $uri->setVar('f'$f);
  43.         }
  44.  
  45.         // Add the search query string if present.
  46.         if ($q !== null)
  47.         {
  48.             $uri->setVar('q'$q);
  49.         }
  50.  
  51.         // Add the menu item id if present.
  52.         if ($item !== null)
  53.         {
  54.             $uri->setVar('Itemid'$item);
  55.         }
  56.  
  57.         return $uri->toString(array('path''query'));
  58.     }
  59.  
  60.     /**
  61.      * Method to get the route for an advanced search page.
  62.      *
  63.      * @param   integer  $f  The search filter id. [optional]
  64.      * @param   string   $q  The search query string. [optional]
  65.      *
  66.      * @return  string  The advanced search route.
  67.      *
  68.      * @since   2.5
  69.      */
  70.     public static function getAdvancedRoute($f null$q null)
  71.     {
  72.         // Get the menu item id.
  73.         $query array('view' => 'advanced''q' => $q'f' => $f);
  74.         $item self::getItemid($query);
  75.  
  76.         // Get the base route.
  77.         $uri clone(JUri::getInstance('index.php?option=com_finder&view=advanced'));
  78.  
  79.         // Add the pre-defined search filter if present.
  80.         if ($q !== null)
  81.         {
  82.             $uri->setVar('f'$f);
  83.         }
  84.  
  85.         // Add the search query string if present.
  86.         if ($q !== null)
  87.         {
  88.             $uri->setVar('q'$q);
  89.         }
  90.  
  91.         // Add the menu item id if present.
  92.         if ($item !== null)
  93.         {
  94.             $uri->setVar('Itemid'$item);
  95.         }
  96.  
  97.         return $uri->toString(array('path''query'));
  98.     }
  99.  
  100.     /**
  101.      * Method to get the most appropriate menu item for the route based on the
  102.      * supplied query needles.
  103.      *
  104.      * @param   array  $query  An array of URL parameters.
  105.      *
  106.      * @return  mixed  An integer on success, null otherwise.
  107.      *
  108.      * @since   2.5
  109.      */
  110.     public static function getItemid($query)
  111.     {
  112.         static $items$active;
  113.  
  114.         // Get the menu items for com_finder.
  115.         if (!$items || !$active)
  116.         {
  117.             $app JFactory::getApplication('site');
  118.             $com JComponentHelper::getComponent('com_finder');
  119.             $menu $app->getMenu();
  120.             $active $menu->getActive();
  121.             $items $menu->getItems('component_id'$com->id);
  122.             $items is_array($items$items array();
  123.         }
  124.  
  125.         // Try to match the active view and filter.
  126.         if ($active && @$active->query['view'== @$query['view'&& @$active->query['f'== @$query['f'])
  127.         {
  128.             return $active->id;
  129.         }
  130.  
  131.         // Try to match the view, query, and filter.
  132.         foreach ($items as $item)
  133.         {
  134.             if (@$item->query['view'== @$query['view'&& @$item->query['q'== @$query['q'&& @$item->query['f'== @$query['f'])
  135.             {
  136.                 return $item->id;
  137.             }
  138.         }
  139.  
  140.         // Try to match the view and filter.
  141.         foreach ($items as $item)
  142.         {
  143.             if (@$item->query['view'== @$query['view'&& @$item->query['f'== @$query['f'])
  144.             {
  145.                 return $item->id;
  146.             }
  147.         }
  148.  
  149.         // Try to match the view.
  150.         foreach ($items as $item)
  151.         {
  152.             if (@$item->query['view'== @$query['view'])
  153.             {
  154.                 return $item->id;
  155.             }
  156.         }
  157.  
  158.         return null;
  159.     }
  160. }

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