/**
  * Default search functionality.
  *
  * @since 2.0.0
  * @access public
  * @param int $Page Page number.
  */
 public function index($Page = '')
 {
     $this->addJsFile('search.js');
     $this->title(t('Search'));
     saveToConfig('Garden.Format.EmbedSize', '160x90', false);
     Gdn_Theme::section('SearchResults');
     list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20));
     $this->setData('_Limit', $Limit);
     $Search = $this->Form->getFormValue('Search');
     $Mode = $this->Form->getFormValue('Mode');
     if ($Mode) {
         $this->SearchModel->ForceSearchMode = $Mode;
     }
     try {
         $ResultSet = $this->SearchModel->search($Search, $Offset, $Limit);
     } catch (Gdn_UserException $Ex) {
         $this->Form->addError($Ex);
         $ResultSet = array();
     } catch (Exception $Ex) {
         LogException($Ex);
         $this->Form->addError($Ex);
         $ResultSet = array();
     }
     Gdn::userModel()->joinUsers($ResultSet, array('UserID'));
     // Fix up the summaries.
     $SearchTerms = explode(' ', Gdn_Format::text($Search));
     foreach ($ResultSet as &$Row) {
         $Row['Summary'] = searchExcerpt(htmlspecialchars(Gdn_Format::plainText($Row['Summary'], $Row['Format'])), $SearchTerms);
         $Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']);
         $Row['Format'] = 'Html';
     }
     $this->setData('SearchResults', $ResultSet, true);
     $this->setData('SearchTerm', Gdn_Format::text($Search), true);
     if ($ResultSet) {
         $NumResults = count($ResultSet);
     } else {
         $NumResults = 0;
     }
     if ($NumResults == $Offset + $Limit) {
         $NumResults++;
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->getPager('MorePager', $this);
     $this->Pager->MoreCode = 'More Results';
     $this->Pager->LessCode = 'Previous Results';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->configure($Offset, $Limit, $NumResults, 'dashboard/search/%1$s/%2$s/?Search=' . Gdn_Format::url($Search));
     //		if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
     //         $this->setJson('LessRow', $this->Pager->toString('less'));
     //         $this->setJson('MoreRow', $this->Pager->toString('more'));
     //         $this->View = 'results';
     //      }
     $this->canonicalUrl(url('search', true));
     $this->render();
 }
 /**
  * Default search functionality.
  *
  * @since 2.0.0
  * @access public
  * @param int $Page Page number.
  */
 public function index($Page = '')
 {
     $this->addJsFile('search.js');
     $this->title(t('Search'));
     saveToConfig('Garden.Format.EmbedSize', '160x90', false);
     Gdn_Theme::section('SearchResults');
     list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20));
     $this->setData('_Limit', $Limit);
     $Search = $this->Form->getFormValue('Search');
     $Mode = $this->Form->getFormValue('Mode');
     if ($Mode) {
         $this->SearchModel->ForceSearchMode = $Mode;
     }
     try {
         $ResultSet = $this->SearchModel->search($Search, $Offset, $Limit);
     } catch (Gdn_UserException $Ex) {
         $this->Form->addError($Ex);
         $ResultSet = array();
     } catch (Exception $Ex) {
         LogException($Ex);
         $this->Form->addError($Ex);
         $ResultSet = array();
     }
     Gdn::userModel()->joinUsers($ResultSet, array('UserID'));
     // Fix up the summaries.
     $SearchTerms = explode(' ', Gdn_Format::text($Search));
     foreach ($ResultSet as &$Row) {
         $Row['Summary'] = searchExcerpt(htmlspecialchars(Gdn_Format::plainText($Row['Summary'], $Row['Format'])), $SearchTerms);
         $Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']);
         $Row['Format'] = 'Html';
     }
     $this->setData('SearchResults', $ResultSet, true);
     $this->setData('SearchTerm', Gdn_Format::text($Search), true);
     $this->setData('_CurrentRecords', count($ResultSet));
     $this->canonicalUrl(url('search', true));
     $this->render();
 }
 public function searchAction()
 {
     $page_data = $this->index('basic_page');
     $request = new Request();
     if ($request->isPost()) {
         $search = new SearchModel($request);
         if (!$search->isSmall()) {
             if (!$search->isLarge()) {
                 $search_data = $search->search();
             } else {
                 Session::setFlash(__t('long_inquiry'));
             }
         } else {
             Session::setFlash(__t('short_inquiry'));
         }
     }
     $search_array = array();
     if (isset($search_data)) {
         foreach ($search_data as $material_type) {
             foreach ($material_type as $val) {
                 $search_array[] = $val;
             }
         }
     }
     $items_count = count($search_array);
     $items_per_page = Config::get('search_per_page');
     $request = new Request();
     $currentPage = $request->get('page') ? (int) $request->get('page') : 1;
     $data_pagination = self::getPagination($items_count, $items_per_page, $currentPage);
     if ($items_count) {
         $data_search_page = array_chunk($search_array, $items_per_page, true);
         if (isset($data_search_page[$currentPage - 1])) {
             $data_search_page = $data_search_page[$currentPage - 1];
         } else {
             throw new Exception('Page (' . Router::getUri() . ') not found', 404);
         }
     } else {
         $data_search_page = null;
     }
     $data_url = explode('?', Router::getUri());
     $lang = Router::getLanguage() == Config::get('default_language') ? '' : Router::getLanguage() . '/';
     //    $search_request = $search->getSearchRequest();
     $args = array('page_data' => $page_data, 'data_search' => $data_search_page, 'data_pagination' => $data_pagination, 'data_url' => $data_url[0], 'lang' => $lang, 'items_count' => $items_count, 'img' => $page_data['img']);
     return $this->render($args);
 }
Exemple #4
0
 public function qAction()
 {
     $q = urldecode($this->strVal(3));
     $page = $this->intVal(4);
     if ($page == 0) {
         $page = 1;
     }
     $size = 10;
     $begin = ($page - 1) * $size;
     $searchModel = new SearchModel();
     $ret = $searchModel->search($q, $begin, $size);
     $retArray = json_decode($ret, true);
     $count = $retArray["hits"]["total"];
     $pageControl = ToolModel::pageControl($page, $count, $size, "<a href='/search/q/{$q}/#page#/'>");
     $this->_mainContent->assign("pageControl", $pageControl);
     $this->_mainContent->assign("results", $retArray);
     $this->_mainContent->assign("search", $retArray);
     $this->_view->assign("search_q", $q);
     $this->_mainContent->assign("search_q", $q);
     $this->display();
     //var_dump($retArray);
 }
Exemple #5
0
 public function search($args)
 {
     $cat = new RetrieveModel();
     $dat = new SearchModel();
     EStructure::view("search", $cat->getCategories(), $dat->search());
 }
Exemple #6
0
 public function showAction()
 {
     $id = $this->intVal(3);
     $threadModel = new ThreadModel();
     $userModel = new UserModel();
     $reputation = $userModel->reputation($this->userid);
     if ($_POST) {
         if (!$this->isEmailValidated) {
             header("location: /home/");
             die;
         }
         if ($reputation < 0) {
             header("location: /home/");
             die;
         }
         if ($this->userid > 0) {
             if (strlen($_POST["content"]) > 0) {
                 $data = array();
                 $time = time();
                 $data["threadid"] = $id;
                 $data["name"] = $this->username;
                 $data["userid"] = $this->userid;
                 $data["content"] = $_POST["content"];
                 $data["createdate"] = $time;
                 $data["updatedate"] = $time;
                 $replys = $threadModel->newReply($data);
                 if ($replys) {
                     $thread = array();
                     $thread["id"] = $id;
                     $thread["replys"] = $replys;
                     $thread["updatedate"] = $time;
                     $thread["lastreply"] = $data["name"];
                     $thread["lastreplyid"] = $data["userid"];
                     $threadModel->updateThread($thread);
                 }
                 header("location: /thread/show/{$id}/");
                 die;
             }
         }
     }
     header('Pragma: ');
     header("cache-control: s-maxage=600");
     $cacheModel = new FilecacheModel();
     $thread = $threadModel->threadById($id);
     if (!$thread || $thread["del"] == 1) {
         header("HTTP/1.1 301 Moved Permanently");
         header("location: /home/");
         die;
     }
     $replysCount = $threadModel->replysCountById($id);
     $replys = $threadModel->replysById($id);
     $voteInfo = $threadModel->voteInfo($id);
     $userVote = $threadModel->userVote($id, $this->userid);
     //limit10replys
     $isBot = ToolModel::isBot();
     if ($this->userid == 0 && !$isBot && $replysCount > 10) {
         $replys = array_slice($replys, 0, 10);
     }
     if (!$this->userid) {
         $this->_mainContent->assign("userid", 0);
     } else {
         $this->_mainContent->assign("userid", $this->userid);
     }
     if ($this->userid) {
         $userModel = new UserModel();
         $userInfo = $userModel->userInfo($this->userid);
         $reputation = $userInfo["reputation"];
     } else {
         $reputation = 0;
     }
     $this->_mainContent->assign("reputation", $reputation);
     $this->_mainContent->assign("thread", $thread);
     $this->_mainContent->assign("replysCount", $replysCount);
     $this->_mainContent->assign("replys", $replys);
     $this->_mainContent->assign("voteInfo", $voteInfo);
     $this->_mainContent->assign("userVote", $userVote);
     $searchModel = new SearchModel();
     $ret = $searchModel->search($thread["title"], 0, 11);
     $relativeThread = json_decode($ret, true);
     $this->_mainContent->assign("relativeThread", $relativeThread["hits"]["hits"]);
     $toplist = $cacheModel->getCache("toplist", "toplist");
     if (!$toplist) {
         $toplistModel = new ToplistModel();
         $toplist = $toplistModel->toplist();
         $cacheModel->createCache("toplist", "toplist", $toplist);
     }
     $this->_mainContent->assign("toplist", $toplist);
     if (isset($this->isEmailValidated)) {
         $this->_mainContent->assign("isEmailValidated", $this->isEmailValidated);
     }
     $this->_mainContent->assign("reputation", $reputation);
     $this->setTitle($thread["title"]);
     $this->display();
 }