public function actionSearch()
{
// note: intentionally not post-only
if (!XenForo_Visitor::getInstance()->canSearch())
{
throw $this->getNoPermissionResponseException();
}
$input = $this->_input->filter(array(
'keywords' => XenForo_Input::STRING,
'title_only' => XenForo_Input::UINT,
'date' => XenForo_Input::DATE_TIME,
'users' => XenForo_Input::STRING,
'nodes' => array(XenForo_Input::UINT, 'array' => true),
'child_nodes' => XenForo_Input::UINT,
'user_content' => XenForo_Input::STRING,
'order' => XenForo_Input::STRING,
'group_discussion' => XenForo_Input::UINT
));
$input['type'] = $this->_handleInputType($input);
if (!$input['order'])
{
$input['order'] = 'date';
}
$origKeywords = $input['keywords'];
$input['keywords'] = XenForo_Helper_String::censorString($input['keywords'], null, ''); // don't allow searching of censored stuff
$visitorUserId = XenForo_Visitor::getUserId();
$searchModel = $this->_getSearchModel();
$constraints = $searchModel->getGeneralConstraintsFromInput($input, $errors);
if ($errors)
{
return $this->responseError($errors);
}
if (!$input['type'] && $input['keywords'] === ''
&& count($constraints) == 1
&& !empty($constraints['user']) && count($constraints['user']) == 1
)
{
// we're searching for messages by a single user
$this->_request->setParam('user_id', reset($constraints['user']));
return $this->responseReroute(__CLASS__, 'member');
}
/*
if ($input['keywords'] === '' && empty($constraints['user']))
{
// must have keyword or user constraint
return $this->responseError(new XenForo_Phrase('please_specify_search_query_or_name_of_member'));
}
*/
$typeHandler = null;
if ($input['type'])
{
if (is_array($input['type']))
{
$typeInfo = $input['type'];
list($input['type'], $contentInfo) = each($input['type']);
list($contentType, $contentId) = each($contentInfo);
}
$typeHandler = $searchModel->getSearchDataHandler($input['type']);
if ($typeHandler)
{
$constraints = array_merge($constraints,
$typeHandler->getTypeConstraintsFromInput($this->_input)
);
}
}
$search = $searchModel->getExistingSearch(
$input['type'], $input['keywords'], $constraints, $input['order'], $input['group_discussion'], $visitorUserId
);
if (!$search)
{
$searcher = new XenForo_Search_Searcher($searchModel);
if ($typeHandler)
{
$results = $searcher->searchType(
$typeHandler, $input['keywords'], $constraints, $input['order'], $input['group_discussion']
);
$userResults = array();
}
else
{
$results = $searcher->searchGeneral($input['keywords'], $constraints, $input['order']);
$userResults = $this->_getUserSearch($input['keywords']);
}
if (!$results && !$userResults)
{
return $this->getNoSearchResultsResponse($searcher);
}
$warnings = $searcher->getErrors() + $searcher->getWarnings();
$search = $searchModel->insertSearch(
$results, $input['type'], $origKeywords, $constraints, $input['order'], $input['group_discussion'], $userResults,
$warnings, $visitorUserId
);
}
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
XenForo_Link::buildPublicLink('search', $search),
''
);
}