Exemple #1
0
 public function actionSearch()
 {
     $visitor = XenForo_Visitor::getInstance()->toArray();
     $visitor_userid = XenForo_Visitor::getUserId();
     $search_model = $this->_getSearchModel();
     $node_model = $this->_getNodeModel();
     $user_model = $this->getModelFromCache('XenForo_Model_User');
     $vals = $this->_input->filter(array('userid' => XenForo_Input::UINT, 'showposts' => XenForo_Input::UINT, 'searchdate' => XenForo_Input::UINT, 'query' => XenForo_Input::STRING, 'searchuser' => XenForo_Input::STRING, 'sortby' => XenForo_Input::STRING, 'starteronly' => XenForo_Input::UINT, 'titleonly' => XenForo_Input::UINT));
     // Munge FR search constrants into XenForo search constraints
     $xf_input = array();
     if ($vals['sortby'] == 'replycount') {
         $xf_input['order'] = 'replies';
     } else {
         $xf_input['order'] = 'date';
     }
     if ($vals['showposts'] == 1) {
         $xf_input['group_discussion'] = 0;
     } else {
         $xf_input['group_discussion'] = 1;
     }
     if ($vals['starteronly']) {
         $xf_input['user_content'] = 'thread';
     }
     if ($vals['searchdate']) {
         $xf_input['date'] = date('Y-m-d', XenForo_Application::$time - $vals['searchdate'] * 86400);
     }
     $exclude = XenForo_Application::get('options')->forumrunnerExcludeForums;
     if (!$exclude) {
         $exclude = array();
     }
     $forums = $node_model->getViewableNodeList(null, true);
     foreach ($exclude as $remove) {
         fr_remove_node_and_children($forums, $remove);
     }
     $xf_input['nodes'] = array_keys($forums);
     $query = $vals['query'];
     $vals['query'] = XenForo_Helper_String::censorString($vals['query'], null, '');
     if ($vals['userid']) {
         // Look up Username
         $user = $user_model->getUserById($vals['userid']);
         if ($user) {
             $vals['searchuser'] = $user['username'];
         }
     }
     $xf_input += array('users' => $vals['searchuser'], 'keywords' => $vals['query'], 'title_only' => $vals['titleonly'] ? 1 : 0);
     $cons = $search_model->getGeneralConstraintsFromInput($xf_input, $errors);
     if ($errors) {
         return $this->sendError($errors[0]);
     }
     if ($xf_input['keywords'] == '' && empty($cons['user'])) {
         return $this->sendError(new XenForo_Phrase('please_specify_search_query_or_name_of_member'));
     }
     $post_handler = $search_model->getSearchDataHandler('post');
     $search = $search_model->getExistingSearch('post', $xf_input['keywords'], $cons, $xf_input['order'], $xf_input['group_discussion'], $visitor_userid);
     if (!$search) {
         $searcher = new XenForo_Search_Searcher($search_model);
         if ($post_handler) {
             $results = $searcher->searchType($post_handler, $xf_input['keywords'], $cons, $xf_input['order'], $xf_input['group_discussion']);
         } else {
             $results = $searcher->searchGeneral($xf_input['keywords'], $cons, $xf_input['order']);
         }
         if (!$results) {
             $errors = $searcher->getErrors();
             if ($errors) {
                 $errors = array_values($errors);
                 return $this->sendError($errors[0]);
             }
             return $this->sendError(new XenForo_Phrase('no_results_found'));
         }
         $search = $search_model->insertSearch($results, 'post', $query, $cons, $xf_input['order'], $xf_input['group_discussion'], $searcher->getWarnings(), $visitor_userid);
     }
     return $this->processSearch($search);
 }
Exemple #2
0
 /**
  * Handles the response behavior when there are no search results.
  *
  * @param XenForo_Search_Searcher|array $search
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function getNoSearchResultsResponse($search)
 {
     if ($search instanceof XenForo_Search_Searcher) {
         $errors = $search->getErrors();
         if ($errors) {
             return $this->responseError($errors);
         }
     } else {
         if (is_array($search) && !empty($search['user_results'])) {
             $viewParams = array('search' => $this->_getSearchModel()->prepareSearch($search));
             return $this->responseView('XenForo_ViewPublic_Search_UserResults', 'search_results_users_only', $viewParams);
         }
     }
     return $this->responseMessage(new XenForo_Phrase('no_results_found'));
 }
Exemple #3
0
 /**
  * Handles the response behavior when there are no search results.
  *
  * @param XenForo_Search_Searcher $searcher
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function getNoSearchResultsResponse(XenForo_Search_Searcher $searcher)
 {
     $errors = $searcher->getErrors();
     if ($errors) {
         return $this->responseError($errors);
     } else {
         return $this->responseMessage(new XenForo_Phrase('no_results_found'));
     }
 }