PageRenderTime 22ms CodeModel.GetById 19ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_finder/router.php

https://bitbucket.org/eternaware/joomus
PHP | 110 lines | 47 code | 14 blank | 49 comment | 14 complexity | 3d1ad7ac8bd500488a724af9ad5e77e0 MD5 | raw file
Possible License(s): LGPL-2.1
  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
 10defined('_JEXEC') or die;
 11
 12/**
 13 * Method to build a SEF route.
 14 *
 15 * @param   array  &$query  An array of route variables.
 16 *
 17 * @return  array  An array of route segments.
 18 *
 19 * @since   2.5
 20 */
 21function FinderBuildRoute(&$query)
 22{
 23	static $menu;
 24	$segments = array();
 25
 26	// Load the menu if necessary.
 27	if (!$menu)
 28	{
 29		$menu = JFactory::getApplication('site')->getMenu();
 30	}
 31
 32	/*
 33	 * First, handle menu item routes first. When the menu system builds a
 34	 * route, it only provides the option and the menu item id. We don't have
 35	 * to do anything to these routes.
 36	 */
 37	if (count($query) === 2 && isset($query['Itemid']) && isset($query['option']))
 38	{
 39		return $segments;
 40	}
 41
 42	/*
 43	 * Next, handle a route with a supplied menu item id. All system generated
 44	 * routes should fall into this group. We can assume that the menu item id
 45	 * is the best possible match for the query but we need to go through and
 46	 * see which variables we can eliminate from the route query string because
 47	 * they are present in the menu item route already.
 48	 */
 49	if (!empty($query['Itemid']))
 50	{
 51		// Get the menu item.
 52		$item = $menu->getItem($query['Itemid']);
 53
 54		// Check if the view matches.
 55		if ($item && @$item->query['view'] === @$query['view'])
 56		{
 57			unset($query['view']);
 58		}
 59
 60		// Check if the search query filter matches.
 61		if ($item && @$item->query['f'] === @$query['f'])
 62		{
 63			unset($query['f']);
 64		}
 65
 66		// Check if the search query string matches.
 67		if ($item && @$item->query['q'] === @$query['q'])
 68		{
 69			unset($query['q']);
 70		}
 71
 72		return $segments;
 73	}
 74
 75	/*
 76	 * Lastly, handle a route with no menu item id. Fortunately, we only need
 77	 * to deal with the view as the other route variables are supposed to stay
 78	 * in the query string.
 79	 */
 80	if (isset($query['view']))
 81	{
 82		// Add the view to the segments.
 83		$segments[] = $query['view'];
 84		unset($query['view']);
 85	}
 86
 87	return $segments;
 88}
 89
 90/**
 91 * Method to parse a SEF route.
 92 *
 93 * @param   array  $segments  An array of route segments.
 94 *
 95 * @return  array  An array of route variables.
 96 *
 97 * @since   2.5
 98 */
 99function FinderParseRoute($segments)
100{
101	$vars = array();
102
103	// Check if the view segment is set and it equals search or advanced.
104	if (@$segments[0] === 'search' || @$segments[0] === 'advanced')
105	{
106		$vars['view'] = $segments[0];
107	}
108
109	return $vars;
110}