/components/com_search/controller.php

https://bitbucket.org/kraymitchell/fcd · PHP · 83 lines · 47 code · 11 blank · 25 comment · 8 complexity · 9dae7a50f165307df4428f07884e7e4b MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Site
  4. * @subpackage com_search
  5. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. defined('_JEXEC') or die;
  9. /**
  10. * Search Component Controller
  11. *
  12. * @package Joomla.Site
  13. * @subpackage com_search
  14. * @since 1.5
  15. */
  16. class SearchController extends JControllerLegacy
  17. {
  18. /**
  19. * Method to display a view.
  20. *
  21. * @param boolean If true, the view output will be cached
  22. * @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  23. *
  24. * @return JController This object to support chaining.
  25. * @since 1.5
  26. */
  27. public function display($cachable = false, $urlparams = false)
  28. {
  29. JRequest::setVar('view', 'search'); // force it to be the search view
  30. return parent::display($cachable, $urlparams);
  31. }
  32. function search()
  33. {
  34. // slashes cause errors, <> get stripped anyway later on. # causes problems.
  35. $badchars = array('#', '>', '<', '\\');
  36. $searchword = trim(str_replace($badchars, '', JRequest::getString('searchword', null, 'post')));
  37. // if searchword enclosed in double quotes, strip quotes and do exact match
  38. if (substr($searchword, 0, 1) == '"' && substr($searchword, -1) == '"') {
  39. $post['searchword'] = substr($searchword, 1, -1);
  40. JRequest::setVar('searchphrase', 'exact');
  41. }
  42. else {
  43. $post['searchword'] = $searchword;
  44. }
  45. $post['ordering'] = JRequest::getWord('ordering', null, 'post');
  46. $post['searchphrase'] = JRequest::getWord('searchphrase', 'all', 'post');
  47. $post['limit'] = JRequest::getUInt('limit', null, 'post');
  48. if ($post['limit'] === null) unset($post['limit']);
  49. $areas = JRequest::getVar('areas', null, 'post', 'array');
  50. if ($areas) {
  51. foreach($areas as $area)
  52. {
  53. $post['areas'][] = JFilterInput::getInstance()->clean($area, 'cmd');
  54. }
  55. }
  56. // set Itemid id for links from menu
  57. $app = JFactory::getApplication();
  58. $menu = $app->getMenu();
  59. $items = $menu->getItems('link', 'index.php?option=com_search&view=search');
  60. if(isset($items[0])) {
  61. $post['Itemid'] = $items[0]->id;
  62. } elseif (JRequest::getInt('Itemid') > 0) { //use Itemid from requesting page only if there is no existing menu
  63. $post['Itemid'] = JRequest::getInt('Itemid');
  64. }
  65. unset($post['task']);
  66. unset($post['submit']);
  67. $uri = JURI::getInstance();
  68. $uri->setQuery($post);
  69. $uri->setVar('option', 'com_search');
  70. $this->setRedirect(JRoute::_('index.php'.$uri->toString(array('query', 'fragment')), false));
  71. }
  72. }