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