Exemple #1
0
 public function actionIndex()
 {
     $tagUrl = $this->_input->filterSingle('tag_url', XenForo_Input::STRING);
     if ($tagUrl) {
         return $this->responseReroute(__CLASS__, 'tag');
     }
     $tagModel = $this->_getTagModel();
     $tags = $this->_input->filterSingle('tags', XenForo_Input::STRING);
     if ($this->_request->isPost()) {
         $tagList = $tagModel->splitTags($tags);
         if (!$tagList) {
             return $this->responseError(new XenForo_Phrase('please_enter_single_tag'));
         }
         if (count($tagList) == 1) {
             $tag = reset($tagList);
             $tagDetails = $tagModel->getTag($tag);
             if ($tagDetails) {
                 return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('tags', $tagDetails), '');
             } else {
                 return $this->responseError(new XenForo_Phrase('following_tags_not_found_x', array('tags' => $tag)));
             }
         }
         if (!XenForo_Visitor::getInstance()->canSearch()) {
             return $this->responseError(new XenForo_Phrase('please_enter_single_tag'));
         }
         $validTags = $tagModel->getTags($tagList, $notFound);
         if ($notFound) {
             return $this->responseError(new XenForo_Phrase('following_tags_not_found_x', array('tags' => implode(', ', $notFound))));
         } else {
             $tagConstraint = implode(' ', array_keys($validTags));
             $constraints = array('tag' => $tagConstraint);
             /** @var XenForo_Model_Search $searchModel */
             $searchModel = $this->getModelFromCache('XenForo_Model_Search');
             $searcher = new XenForo_Search_Searcher($searchModel);
             $results = $searcher->searchGeneral('', $constraints, 'date');
             if (!$results) {
                 return $this->responseMessage(new XenForo_Phrase('no_results_found'));
             }
             $search = $searchModel->insertSearch($results, 'tag', '', array('tag' => $tagConstraint), 'date', false);
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('search', $search), '');
         }
     }
     if (XenForo_Application::getOptions()->tagCloud['enabled']) {
         $tagCloud = $tagModel->getTagsForCloud(XenForo_Application::getOptions()->tagCloud['count'], XenForo_Application::getOptions()->tagCloudMinUses);
         $tagCloudLevels = $tagModel->getTagCloudLevels($tagCloud);
     } else {
         $tagCloud = array();
         $tagCloudLevels = array();
     }
     $viewParams = array('tags' => $tags, 'tagCloud' => $tagCloud, 'tagCloudLevels' => $tagCloudLevels, 'canSearch' => XenForo_Visitor::getInstance()->canSearch());
     return $this->responseView('XenForo_ViewPublic_Tag_Search', 'tag_search', $viewParams);
 }
 public function getThreadsByUser($userId)
 {
     $searchModel = $this->getModelFromCache('XenForo_Model_Search');
     $constraints = array('user' => array($userId), 'content' => 'post', 'node' => implode(',', XenForo_Application::get('options')->nfxtFeedbackForums));
     $searcher = new XenForo_Search_Searcher($searchModel);
     $threads = $searchModel->getSearchResultsForDisplay($searchModel->getViewableSearchResults($searcher->searchGeneral('', $constraints, 'date')));
     if ($threads) {
         $ret = array();
         foreach ($threads['results'] as $k => $thread) {
             $ret[$thread['content']['thread_id']] = $thread;
         }
         return $ret;
     }
     return array();
 }
 public function prioritizeResults(array &$results, XenForo_Search_Searcher $searcher, $searchQuery, array $constraints = array(), $order = 'date')
 {
     // prioritize contents by doing a second search for prioritized contents
     // this may cause performance issue but shouldn't make a big impact
     // admin can easily disable the feature in AdminCP
     // it's required to do another search because the original search has its own
     // max results and may not include all prioritized results
     $prioritizedContents = $this->getPrioritizedContents();
     if (empty($prioritizedContents)) {
         // nothing to do
         return;
     }
     $constraints['content'] = array_keys($prioritizedContents);
     $prioritizedResults = $searcher->searchGeneral($searchQuery, $constraints, $order);
     if (empty($prioritizedResults)) {
         // no prioritized results could be found, do nothing
         return;
     }
     $this->sortResults($prioritizedContents, $results, $prioritizedResults);
 }
Exemple #4
0
 public function search($keywords, $order = 'asc', $type = NULL)
 {
     $keywords = strtolower(XenForo_Helper_String::censorString($keywords, null, ''));
     $this->getModels()->checkModel('search', XenForo_Model::create('XenForo_Model_Search'));
     $searcher = new XenForo_Search_Searcher($this->getModels()->getModel('search'));
     $xenforo_results = $searcher->searchGeneral($keywords, array(), $order);
     $results = array();
     foreach ($xenforo_results as &$result) {
         if ($type !== NULL) {
             if (strtolower($result[0]) != strtolower($type) && !(strtolower($result[0]) == 'thread' && strtolower($type) == 'thread_title')) {
                 continue;
             }
         }
         $result = array('type' => $result[0], 'data' => $result[1]);
         switch ($result['type']) {
             case 'post':
                 $result['data'] = $this->getPost($result['data']);
                 break;
             case 'thread':
                 $result['data'] = $this->getThread($result['data']);
                 if ($type !== NULL && strtolower($type) == 'thread_title' && ($titleFound = $result['data']['title'] != $keywords)) {
                     continue 2;
                 }
                 break;
             case 'resource_update':
                 // TODO
                 $result['data'] = array('resource_update_id' => $result['data']);
                 break;
         }
         $results[] = $result;
     }
     return $results;
 }
 /**
  * Reruns the given search with higher maximum.
  * If errors occur, a response exception will be thrown.
  *
  * @param array $search Search info (does not need search_id, constraints,
  * results, or warnings)
  * @param array $constraints Array of search constraints
  *
  * @return array New search
  */
 public function runExtendedSearch(array $search, array $constraints)
 {
     if (!XenForo_Visitor::getInstance()->canSearch()) {
         throw $this->getNoPermissionResponseException();
     }
     $visitorUserId = XenForo_Visitor::getUserId();
     $searchModel = $this->_getSearchModel();
     $typeHandler = null;
     if ($search['search_type']) {
         $typeHandler = $searchModel->getSearchDataHandler($search['search_type']);
     }
     $searcher = new XenForo_Search_Searcher($searchModel);
     $maxResults = XenForo_Application::get('options')->th_searchAndExport_maximumSearchResults;
     if ($typeHandler) {
         $results = $searcher->searchType($typeHandler, $search['search_query'], $constraints, $search['search_order'], $search['search_grouping'], $maxResults);
     } else {
         $search['search_type'] = '';
         $results = $searcher->searchGeneral($search['search_query'], $constraints, $search['search_order'], $maxResults);
     }
     if (!$results) {
         throw $this->responseException($this->getNoSearchResultsResponse($searcher));
     }
     $constraints['extended'] = true;
     return $searchModel->insertSearch($results, $search['search_type'], $search['search_query'], $constraints, $search['search_order'], $search['search_grouping'], array(), $searcher->getWarnings(), $visitorUserId);
 }
Exemple #6
0
 public function _doSearch($contentType = '', array $constraints = array())
 {
     if (!XenForo_Visitor::getInstance()->canSearch()) {
         throw $this->getNoPermissionResponseException();
     }
     $input = array('order' => 'relevance', 'group_discussion' => false);
     $input['keywords'] = $this->_input->filterSingle('q', XenForo_Input::STRING);
     $input['keywords'] = XenForo_Helper_String::censorString($input['keywords'], null, '');
     // don't allow searching of censored stuff
     if (empty($input['keywords'])) {
         throw $this->responseException($this->responseError(new XenForo_Phrase('bdapi_slash_search_requires_q'), 400));
     }
     $maxResults = XenForo_Application::getOptions()->get('maximumSearchResults');
     switch ($contentType) {
         case 'thread':
         case 'post':
             // only these two legacy content types support `limit` param while searching
             // others use `limit` to control how many pieces of data are returned
             $limit = $this->_input->filterSingle('limit', XenForo_Input::UINT);
             if ($limit > 0) {
                 $maxResults = min($maxResults, $limit);
             }
     }
     $forumId = $this->_input->filterSingle('forum_id', XenForo_Input::UINT);
     if (!empty($forumId)) {
         $childNodeIds = array_keys($this->_getNodeModel()->getChildNodesForNodeIds(array($forumId)));
         $nodeIds = array_unique(array_merge(array($forumId), $childNodeIds));
         $constraints['node'] = implode(' ', $nodeIds);
         if (!$constraints['node']) {
             unset($constraints['node']);
         }
     }
     $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT);
     if (!empty($userId)) {
         $constraints['user'] = array($userId);
     }
     $searchModel = $this->_getSearchModel();
     $searcher = new XenForo_Search_Searcher($searchModel);
     if (!empty($contentType)) {
         // content type searching
         $typeHandler = $searchModel->getSearchDataHandler($contentType);
         if (empty($typeHandler)) {
             throw new XenForo_Exception(sprintf('No search data handler found for content type %s', $contentType));
         }
         $results = $searcher->searchType($typeHandler, $input['keywords'], $constraints, $input['order'], $input['group_discussion'], $maxResults);
     } else {
         // general searching
         $results = $searcher->searchGeneral($input['keywords'], $constraints, $input['order'], $maxResults);
     }
     $search = $searchModel->insertSearch($results, $contentType, $input['keywords'], $constraints, $input['order'], $input['group_discussion']);
     return $search;
 }
Exemple #7
0
 /**
  * Reruns the given search. If errors occur, a response exception will be thrown.
  *
  * @param array $search Search info (does not need search_id, constraints, results, or warnings)
  * @param array $constraints Array of search constraints
  *
  * @return array New search
  */
 public function rerunSearch(array $search, array $constraints)
 {
     if (!XenForo_Visitor::getInstance()->canSearch()) {
         throw $this->getNoPermissionResponseException();
     }
     $visitorUserId = XenForo_Visitor::getUserId();
     $searchModel = $this->_getSearchModel();
     $existingSearch = $searchModel->getExistingSearch($search['search_type'], $search['search_query'], $constraints, $search['search_order'], $search['search_grouping'], $visitorUserId);
     if ($existingSearch) {
         return $existingSearch;
     }
     $typeHandler = null;
     if ($search['search_type']) {
         $typeHandler = $searchModel->getSearchDataHandler($search['search_type']);
     }
     $searcher = new XenForo_Search_Searcher($searchModel);
     $userResults = array();
     if ($typeHandler) {
         $results = $searcher->searchType($typeHandler, $search['search_query'], $constraints, $search['search_order'], $search['search_grouping']);
         $userResults = array();
     } else {
         $search['search_type'] = '';
         $results = $searcher->searchGeneral($search['search_query'], $constraints, $search['search_order']);
         $userResults = $this->_getUserSearch($search['search_query']);
     }
     if (!$results && !$userResults) {
         throw $this->responseException($this->getNoSearchResultsResponse($searcher));
     }
     return $searchModel->insertSearch($results, $search['search_type'], $search['search_query'], $constraints, $search['search_order'], $search['search_grouping'], $userResults, $searcher->getWarnings(), $visitorUserId);
 }
 public function actionParentalControlDownloadLogFile()
 {
     $GLOBALS['XenForo_ControllerPublic_Account'] = $this;
     $visitor = XenForo_Visitor::getInstance();
     $results = array();
     $users = $this->_getUserModel()->getUsers(array('parent_email' => $visitor['parent_email']));
     $constraints = array('user' => array_keys($users), 'date' => strtotime("-1 month", XenForo_Application::$time));
     $searchModel = $this->getModelFromCache('XenForo_Model_Search');
     $searcher = new XenForo_Search_Searcher($searchModel);
     $results = $searcher->searchGeneral('', $constraints, 'date');
     $results = $this->getModelFromCache('XenForo_Model_Search')->getSearchResultsForDisplay($results);
     $viewParams = array('results' => $results);
     $containerParams = array('containerTemplate' => 'th_log_file_container_parentalcontrol');
     return $this->responseView('ThemeHouse_ParentalContro_ViewPublic_Account_ParentalControl_LogFile', 'th_log_file_parentalcontrol', $viewParams, $containerParams);
 }
Exemple #9
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);
 }