PageRenderTime 1116ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_search/controller.php

https://github.com/joebushi/joomla
PHP | 87 lines | 53 code | 11 blank | 23 comment | 3 complexity | 4da17d28fcc38be051333951c58f81b0 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Site
  5. * @subpackage Content
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. // No direct access
  10. defined('_JEXEC') or die;
  11. jimport('joomla.application.component.controller');
  12. /**
  13. * Search Component Controller
  14. *
  15. * @package Joomla.Site
  16. * @subpackage Search
  17. * @since 1.5
  18. */
  19. class SearchController extends JController
  20. {
  21. /**
  22. * Method to show the search view
  23. *
  24. * @access public
  25. * @since 1.5
  26. */
  27. function display()
  28. {
  29. JRequest::setVar('view','search'); // force it to be the polls view
  30. parent::display();
  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::getInt('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. // No need to guess Itemid if it's already present in the URL
  57. if (JRequest::getInt('Itemid') > 0) {
  58. $post['Itemid'] = JRequest::getInt('Itemid');
  59. } else {
  60. // set Itemid id for links
  61. $menu = &JSite::getMenu();
  62. $items = $menu->getItems('link', 'index.php?option=com_search&view=search');
  63. if (isset($items[0])) {
  64. $post['Itemid'] = $items[0]->id;
  65. }
  66. }
  67. unset($post['task']);
  68. unset($post['submit']);
  69. $uri = JURI::getInstance();
  70. $uri->setQuery($post);
  71. $uri->setVar('option', 'com_search');
  72. $this->setRedirect(JRoute::_('index.php'.$uri->toString(array('query', 'fragment')), false));
  73. }
  74. }