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