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