5 use wcf\data\search\ISearchResultObject
;
6 use wcf\data\search\Search
;
7 use wcf\system\event\EventHandler
;
8 use wcf\system\exception\IllegalLinkException
;
9 use wcf\system\exception\ImplementationException
;
10 use wcf\system\page\PageLocationManager
;
11 use wcf\system\request\LinkHandler
;
12 use wcf\system\search\SearchEngine
;
14 use wcf\util\HeaderUtil
;
17 * Shows the result of a search request.
20 * @copyright 2001-2019 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
24 class SearchResultPage
extends MultipleLinkPage
29 public $itemsPerPage = SEARCH_RESULTS_PER_PAGE
;
35 public $highlight = '';
53 public $messages = [];
62 * result list template
65 public $resultListTemplateName = 'searchResultList';
68 * result list template's application
71 public $resultListApplication = 'wcf';
76 public function readParameters()
78 parent
::readParameters();
80 if (isset($_REQUEST['highlight'])) {
81 $this->highlight
= $_REQUEST['highlight'];
83 if (isset($_REQUEST['id'])) {
84 $this->searchID
= \
intval($_REQUEST['id']);
86 $this->search
= new Search($this->searchID
);
87 if (!$this->search
->searchID ||
$this->search
->searchType
!= 'messages') {
88 $this->redirectOrReject();
90 if ($this->search
->userID
&& $this->search
->userID
!= WCF
::getUser()->userID
) {
91 $this->redirectOrReject();
95 $this->searchData
= \
unserialize($this->search
->searchData
);
99 * Attempts to start a new search if the search id is invalid or unavailable, and the
100 * highlight parameter is available.
102 protected function redirectOrReject()
104 if (!empty($this->highlight
)) {
105 HeaderUtil
::redirect(
106 LinkHandler
::getInstance()->getLink('Search', ['q' => $this->highlight
])
111 throw new IllegalLinkException();
118 public function readData()
122 // cache message data
123 $this->cacheMessageData();
126 $this->readMessages();
128 // set active menu item
129 if (isset($this->searchData
['selectedObjectTypes']) && \
count($this->searchData
['selectedObjectTypes']) == 1) {
130 $objectType = SearchEngine
::getInstance()->getObjectType(\reset
($this->searchData
['selectedObjectTypes']));
131 $objectType->setLocation();
135 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.Search');
139 * Caches the message data.
141 protected function cacheMessageData()
145 // group object id by object type
146 for ($i = $this->startIndex
- 1; $i < $this->endIndex
; $i++
) {
147 $type = $this->searchData
['results'][$i]['objectType'];
148 $objectID = $this->searchData
['results'][$i]['objectID'];
150 if (!isset($types[$type])) {
153 $types[$type][] = $objectID;
156 foreach ($types as $type => $objectIDs) {
157 $objectType = SearchEngine
::getInstance()->getObjectType($type);
158 $objectType->cacheObjects($objectIDs, ($this->searchData
['additionalData'][$type] ??
null));
163 * Reads the data of the search result messages.
165 protected function readMessages()
167 for ($i = $this->startIndex
- 1; $i < $this->endIndex
; $i++
) {
168 $type = $this->searchData
['results'][$i]['objectType'];
169 $objectID = $this->searchData
['results'][$i]['objectID'];
171 $objectType = SearchEngine
::getInstance()->getObjectType($type);
172 if (($message = $objectType->getObject($objectID)) !== null) {
173 if (!($message instanceof ISearchResultObject
)) {
174 throw new ImplementationException(\
get_class($message), ISearchResultObject
::class);
177 $this->messages
[] = $message;
185 public function countItems()
187 // call countItems event
188 EventHandler
::getInstance()->fireAction($this, 'countItems');
190 return \
count($this->searchData
['results']);
196 protected function initObjectList()
203 protected function readObjects()
210 public function __run()
212 throw new IllegalLinkException();