PageRenderTime 93ms CodeModel.GetById 41ms app.highlight 4ms RepoModel.GetById 26ms 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
 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
10// No direct access
11defined('_JEXEC') or die;
12
13jimport('joomla.application.component.controller');
14
15/**
16 * Search Component Controller
17 *
18 * @package		Joomla.Site
19 * @subpackage	Search
20 * @since 1.5
21 */
22class SearchController extends JController
23{
24	/**
25	 * Method to show the search view
26	 *
27	 * @access	public
28	 * @since	1.5
29	 */
30	function display()
31	{
32		JRequest::setVar('view','search'); // force it to be the polls view
33		parent::display();
34	}
35
36	function search()
37	{
38		// slashes cause errors, <> get stripped anyway later on. # causes problems.
39		$badchars = array('#','>','<','\\');
40		$searchword = trim(str_replace($badchars, '', JRequest::getString('searchword', null, 'post')));
41		// if searchword enclosed in double quotes, strip quotes and do exact match
42		if (substr($searchword,0,1) == '"' && substr($searchword, -1) == '"') {
43			$post['searchword'] = substr($searchword,1,-1);
44			JRequest::setVar('searchphrase', 'exact');
45		}
46		else {
47			$post['searchword'] = $searchword;
48		}
49		$post['ordering']	= JRequest::getWord('ordering', null, 'post');
50		$post['searchphrase']	= JRequest::getWord('searchphrase', 'all', 'post');
51		$post['limit']  = JRequest::getInt('limit', null, 'post');
52		if ($post['limit'] === null) unset($post['limit']);
53
54		$areas = JRequest::getVar('areas', null, 'post', 'array');
55		if ($areas) {
56			foreach($areas as $area)
57			{
58				$post['areas'][] = JFilterInput::getInstance()->clean($area, 'cmd');
59			}
60		}
61
62		// No need to guess Itemid if it's already present in the URL
63		if (JRequest::getInt('Itemid') > 0) {
64			$post['Itemid'] = JRequest::getInt('Itemid');
65		} else {
66
67			// set Itemid id for links
68			$menu = &JSite::getMenu();
69			$items	= $menu->getItems('link', 'index.php?option=com_search&view=search');
70
71			if (isset($items[0])) {
72				$post['Itemid'] = $items[0]->id;
73			}
74
75		}
76
77		unset($post['task']);
78		unset($post['submit']);
79
80		$uri = JURI::getInstance();
81		$uri->setQuery($post);
82		$uri->setVar('option', 'com_search');
83
84
85		$this->setRedirect(JRoute::_('index.php'.$uri->toString(array('query', 'fragment')), false));
86	}
87}