[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage com_finder 6 * 7 * @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Finder\Site\Helper; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Uri\Uri; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('_JEXEC') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Finder route helper class. 23 * 24 * @since 2.5 25 */ 26 class RouteHelper 27 { 28 /** 29 * Method to get the route for a search page. 30 * 31 * @param integer $f The search filter id. [optional] 32 * @param string $q The search query string. [optional] 33 * 34 * @return string The search route. 35 * 36 * @since 2.5 37 */ 38 public static function getSearchRoute($f = null, $q = null) 39 { 40 // Get the menu item id. 41 $query = array('view' => 'search', 'q' => $q, 'f' => $f); 42 $item = self::getItemid($query); 43 44 // Get the base route. 45 $uri = clone Uri::getInstance('index.php?option=com_finder&view=search'); 46 47 // Add the pre-defined search filter if present. 48 if ($f !== null) { 49 $uri->setVar('f', $f); 50 } 51 52 // Add the search query string if present. 53 if ($q !== null) { 54 $uri->setVar('q', $q); 55 } 56 57 // Add the menu item id if present. 58 if ($item !== null) { 59 $uri->setVar('Itemid', $item); 60 } 61 62 return $uri->toString(array('path', 'query')); 63 } 64 65 /** 66 * Method to get the route for an advanced search page. 67 * 68 * @param integer $f The search filter id. [optional] 69 * @param string $q The search query string. [optional] 70 * 71 * @return string The advanced search route. 72 * 73 * @since 2.5 74 */ 75 public static function getAdvancedRoute($f = null, $q = null) 76 { 77 // Get the menu item id. 78 $query = array('view' => 'advanced', 'q' => $q, 'f' => $f); 79 $item = self::getItemid($query); 80 81 // Get the base route. 82 $uri = clone Uri::getInstance('index.php?option=com_finder&view=advanced'); 83 84 // Add the pre-defined search filter if present. 85 if ($q !== null) { 86 $uri->setVar('f', $f); 87 } 88 89 // Add the search query string if present. 90 if ($q !== null) { 91 $uri->setVar('q', $q); 92 } 93 94 // Add the menu item id if present. 95 if ($item !== null) { 96 $uri->setVar('Itemid', $item); 97 } 98 99 return $uri->toString(array('path', 'query')); 100 } 101 102 /** 103 * Method to get the most appropriate menu item for the route based on the 104 * supplied query needles. 105 * 106 * @param array $query An array of URL parameters. 107 * 108 * @return mixed An integer on success, null otherwise. 109 * 110 * @since 2.5 111 */ 112 public static function getItemid($query) 113 { 114 static $items, $active; 115 116 // Get the menu items for com_finder. 117 if (!$items || !$active) { 118 $app = Factory::getApplication(); 119 $com = ComponentHelper::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 return $active->id; 129 } 130 131 // Try to match the view, query, and filter. 132 foreach ($items as $item) { 133 if (@$item->query['view'] == @$query['view'] && @$item->query['q'] == @$query['q'] && @$item->query['f'] == @$query['f']) { 134 return $item->id; 135 } 136 } 137 138 // Try to match the view and filter. 139 foreach ($items as $item) { 140 if (@$item->query['view'] == @$query['view'] && @$item->query['f'] == @$query['f']) { 141 return $item->id; 142 } 143 } 144 145 // Try to match the view. 146 foreach ($items as $item) { 147 if (@$item->query['view'] == @$query['view']) { 148 return $item->id; 149 } 150 } 151 152 return null; 153 } 154 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |