コード例 #1
0
ファイル: Tag.php プロジェクト: VoDongMy/xenforo-laravel5.1
 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);
 }
コード例 #2
0
 protected function _render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $template)
 {
     $threads = array();
     if (isset($params['thread']) and !empty($params['thread']['thread_id'])) {
         // $thread is found in the template params, try to fetch the tags
         $tags = Tinhte_XenTag_Helper::unserialize($params['thread'][Tinhte_XenTag_Constants::FIELD_THREAD_TAGS]);
     }
     if (empty($tags) and isset($params['page']) and !empty($params['page']['node_id'])) {
         // fetch page's tags
         $tags = Tinhte_XenTag_Helper::unserialize($params['page'][Tinhte_XenTag_Constants::FIELD_PAGE_TAGS]);
     }
     if (empty($tags) and isset($params['forum']) and !empty($params['forum']['node_id'])) {
         // fetch forum's tags
         $tags = Tinhte_XenTag_Helper::unserialize($params['forum'][Tinhte_XenTag_Constants::FIELD_FORUM_TAGS]);
     }
     if (empty($tags) and isset($params['resource']) and !empty($params['resource']['resource_id'])) {
         // fetch resource's tags
         $tags = Tinhte_XenTag_Helper::unserialize($params['resource'][Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS]);
     }
     if (!empty($tags)) {
         $core = WidgetFramework_Core::getInstance();
         /* @var $searchModel XenForo_Model_Search */
         $searchModel = $core->getModelFromCache('XenForo_Model_Search');
         $tagConstraint = implode(' ', array_keys($tags));
         $constraints = array(Tinhte_XenTag_Constants::SEARCH_CONSTRAINT_TAGS => $tagConstraint);
         $searcher = new XenForo_Search_Searcher($searchModel);
         $searchQuery = '';
         $order = 'date';
         $typeHandler = $searchModel->getSearchDataHandler('thread');
         $results = $searcher->searchType($typeHandler, $searchQuery, $constraints, $order, false, $widget['options']['limit'] * 10);
         if (!empty($results)) {
             $threadIds = array();
             foreach ($results as $result) {
                 if ($result[0] === 'thread') {
                     $threadIds[] = $result[1];
                 }
             }
             $threadIds = array_unique($threadIds);
             $forumIds = $this->_helperGetForumIdsFromOption(array(), $params, empty($widget['options']['as_guest']) ? false : true);
             $conditions = array('node_id' => $forumIds, Tinhte_XenTag_XenForo_Model_Thread::CONDITIONS_THREAD_ID => $threadIds, 'deleted' => false, 'moderated' => false);
             $fetchOptions = array('limit' => $widget['options']['limit'], 'join' => XenForo_Model_Thread::FETCH_AVATAR, 'order' => 'post_date', 'orderDirection' => 'desc');
             /* @var $threadModel XenForo_Model_Thread */
             $threadModel = $core->getModelFromCache('XenForo_Model_Thread');
             $threads = $threadModel->getThreads($conditions, $fetchOptions);
         }
     }
     $template->setParam('threads', $threads);
     return $template->render();
 }
コード例 #3
0
ファイル: Trader.php プロジェクト: melvingb/XenForo-XenTrader
 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();
 }
コード例 #4
0
 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);
 }
コード例 #5
0
ファイル: Search.php プロジェクト: Sywooch/forums
 public function prioritizeResults(array &$results, XenForo_Search_Searcher $searcher, $searchQuery, array $constraints = array(), $order = 'relevance')
 {
     // 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;
     }
     $typeHandler = XenForo_Search_DataHandler_Abstract::create('Tinhte_XenTag_Search_DataHandler_General');
     $typeHandler->setSearchContentTypes(array_keys($prioritizedContents));
     $prioritizedResults = $searcher->searchType($typeHandler, $searchQuery, $constraints, $order);
     if (empty($prioritizedResults)) {
         // no prioritized results could be found, do nothing
         return;
     }
     // drop all prioritized results from general results
     foreach (array_keys($results) as $resultKey) {
         if (isset($prioritizedContents[$results[$resultKey][0]])) {
             unset($results[$resultKey]);
         }
     }
     // append priorizied results
     asort($prioritizedContents);
     $prioritizedResultsKeys = array_reverse(array_keys($prioritizedResults));
     foreach ($prioritizedContents as $contentType => $displayOrder) {
         foreach ($prioritizedResultsKeys as $prioritizedResultKey) {
             if ($prioritizedResults[$prioritizedResultKey][0] == $contentType) {
                 array_unshift($results, $prioritizedResults[$prioritizedResultKey]);
             }
         }
     }
     // normalized array indeces
     $results = array_values($results);
 }
コード例 #6
0
ファイル: api.php プロジェクト: pritcham/XenAPI
 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;
 }
コード例 #7
0
ファイル: Abstract.php プロジェクト: Sywooch/forums
 /**
  * Triggers a warning with the searcher object. This will be shown to the user
  * on the search results page.
  *
  * @param XenForo_Phrase|string $message Warning message
  * @param string $field Field warning applies to
  */
 public function warning($message, $field)
 {
     if ($this->_searcher) {
         $this->_searcher->warning($message, $field);
     }
 }
コード例 #8
0
 /**
  * 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);
 }
コード例 #9
0
ファイル: Search.php プロジェクト: burtay/bdApi
 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;
 }
コード例 #10
0
ファイル: Search.php プロジェクト: Sywooch/forums
 /**
  * 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'));
 }
コード例 #11
0
 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);
 }
コード例 #12
0
ファイル: Search.php プロジェクト: Sywooch/forums
 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);
 }
コード例 #13
0
ファイル: Search.php プロジェクト: hahuunguyen/DTUI_201105
 /**
  * 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'));
     }
 }
コード例 #14
0
ファイル: Tag.php プロジェクト: Sywooch/forums
 protected function _doSearch($tagText)
 {
     $visitorUserId = XenForo_Visitor::getUserId();
     /* @var $searchModel XenForo_Model_Search */
     $searchModel = $this->getModelFromCache('XenForo_Model_Search');
     /* @var $tagSearchModel Tinhte_XenTag_Model_Search */
     $tagSearchModel = $this->getModelFromCache('Tinhte_XenTag_Model_Search');
     $input = array('type' => Tinhte_XenTag_Constants::SEARCH_TYPE_TAG, 'keywords' => '', Tinhte_XenTag_Constants::SEARCH_INPUT_TAGS => $tagText, 'order' => 'date', 'group_discussion' => 0);
     $constraints = $searchModel->getGeneralConstraintsFromInput($input, $errors);
     if ($errors) {
         return $this->responseError($errors);
     }
     $forceRefresh = $this->_input->filterSingle('force_refresh', XenForo_Input::UINT) > 0;
     if ($forceRefresh) {
         if (XenForo_Visitor::getInstance()->get('isTrusted')) {
             // good, this is a trusted user (admin or mod)
         } else {
             // do not accept force refresh request from not-trusted users
             $forceRefresh = false;
         }
     }
     if ($forceRefresh == false) {
         // force to use cache to have a nice and clean url
         $search = $searchModel->getExistingSearch($input['type'], $input['keywords'], $constraints, $input['order'], $input['group_discussion'], $visitorUserId, Tinhte_XenTag_Option::get('searchForceUseCache'));
     } else {
         // skip getting existing results, this will cause a real search to be made
         $search = false;
     }
     if (empty($search)) {
         $searcher = new XenForo_Search_Searcher($searchModel);
         $typeHandler = XenForo_Search_DataHandler_Abstract::create('Tinhte_XenTag_Search_DataHandler_General');
         $results = $searcher->searchType($typeHandler, $input['keywords'], $constraints, $input['order']);
         if (empty($results)) {
             return $this->_getNoResultsResponse($tagText);
         } else {
             $tagSearchModel->prioritizeResults($results, $searcher, $input['keywords'], $constraints, $input['order']);
         }
         $warnings = $searcher->getErrors() + $searcher->getWarnings();
         $search = $searchModel->insertSearch($results, $input['type'], $input['keywords'], $constraints, $input['order'], $input['group_discussion'], array(), $warnings, $visitorUserId);
     }
     return $search;
 }