elkarte /
Elkarte
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Handle all searching from here. |
||
| 5 | * |
||
| 6 | * @package ElkArte Forum |
||
| 7 | * @copyright ElkArte Forum contributors |
||
| 8 | * @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
||
| 9 | * |
||
| 10 | * This file contains code covered by: |
||
| 11 | * copyright: 2011 Simple Machines (http://www.simplemachines.org) |
||
| 12 | * |
||
| 13 | * @version 2.0 dev |
||
| 14 | * |
||
| 15 | */ |
||
| 16 | |||
| 17 | namespace ElkArte\Controller; |
||
| 18 | |||
| 19 | use ElkArte\AbstractController; |
||
| 20 | use ElkArte\Cache\Cache; |
||
| 21 | use ElkArte\Exceptions\Exception; |
||
| 22 | use ElkArte\Helper\Util; |
||
| 23 | use ElkArte\Helper\ValuesContainer; |
||
| 24 | use ElkArte\Languages\Txt; |
||
| 25 | use ElkArte\MembersList; |
||
| 26 | use ElkArte\MessagesCallback\BodyParser\Compact; |
||
| 27 | use ElkArte\MessagesCallback\BodyParser\Normal; |
||
| 28 | use ElkArte\MessagesCallback\SearchRenderer; |
||
| 29 | use ElkArte\MessageTopicIcons; |
||
| 30 | use ElkArte\Search\SearchApiWrapper; |
||
| 31 | use ElkArte\Search\SearchParams; |
||
| 32 | use ElkArte\Search\WeightFactors; |
||
| 33 | use ElkArte\VerificationControls\VerificationControlsIntegrate; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Handle the searching for the site |
||
| 37 | * |
||
| 38 | * @package Search |
||
| 39 | */ |
||
| 40 | class Search extends AbstractController |
||
| 41 | { |
||
| 42 | /** @var \ElkArte\Search\Search Holds the search object */ |
||
| 43 | protected $_search; |
||
| 44 | |||
| 45 | /** @var null|MessageTopicIcons The class that takes care of rendering the message icons */ |
||
| 46 | protected $_icon_sources; |
||
| 47 | |||
| 48 | /** @var array */ |
||
| 49 | protected $_participants = []; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Called before any other action method in this class. |
||
| 53 | * |
||
| 54 | * - If coming from the quick reply allows to route to the proper action |
||
| 55 | * - if needed (for example external search engine or members search |
||
| 56 | */ |
||
| 57 | public function pre_dispatch() |
||
| 58 | { |
||
| 59 | global $modSettings; |
||
| 60 | |||
| 61 | // Coming from quick search box and going to some custom place? |
||
| 62 | $search_selection = $this->_req->getRequest('search_selection', 'trim'); |
||
| 63 | $search = $this->_req->getRequest('search', 'trim'); |
||
| 64 | if (isset($search_selection) && !empty($modSettings['additional_search_engines'])) |
||
| 65 | { |
||
| 66 | $engines = prepareSearchEngines(); |
||
| 67 | if (isset($engines[$search_selection])) |
||
| 68 | { |
||
| 69 | $engine = $engines[$search_selection]; |
||
| 70 | redirectexit($engine['url'] . urlencode(implode($engine['separator'], explode(' ', $search)))); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | // If coming from the quick search box, and we want to search on members, well we need to do that ;) |
||
| 75 | if (isset($search_selection) && $search_selection === 'members') |
||
| 76 | { |
||
| 77 | redirectexit('action=memberlist;sa=search;fields=name,email;search=' . urlencode($search)); |
||
| 78 | } |
||
| 79 | // If load management is on and the load is high, no need to even show the form. |
||
| 80 | if (!empty($modSettings['loadavg_search']) && $modSettings['current_load'] >= $modSettings['loadavg_search']) |
||
| 81 | { |
||
| 82 | throw new Exception('loadavg_search_disabled', false); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Intended entry point for this class. |
||
| 88 | * |
||
| 89 | * - The default action for no sub-action is... present the search screen |
||
| 90 | * |
||
| 91 | * @see AbstractController::action_index |
||
| 92 | */ |
||
| 93 | public function action_index() |
||
| 94 | { |
||
| 95 | // Call the right method. |
||
| 96 | $this->action_search(); |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Ask the user what they want to search for. |
||
| 101 | * |
||
| 102 | * What it does: |
||
| 103 | * |
||
| 104 | * - Shows the screen to search forum posts (action=search), |
||
| 105 | * - Uses the main sub template of the Search template. |
||
| 106 | * - Uses the Search language file. |
||
| 107 | * - Requires the search_posts permission. |
||
| 108 | * - Decodes and loads search parameters given in the URL (if any). |
||
| 109 | * - The form redirects to index.php?action=search;sa=results. |
||
| 110 | * |
||
| 111 | * @throws Exception loadavg_search_disabled |
||
| 112 | * @uses Search template, searchform sub template |
||
| 113 | * |
||
| 114 | * @uses Search language file and Errors language when needed |
||
| 115 | */ |
||
| 116 | public function action_search(): void |
||
| 117 | { |
||
| 118 | global $txt, $modSettings, $context; |
||
| 119 | |||
| 120 | // Is the load average too high to allow searching just now? |
||
| 121 | if (!empty($modSettings['loadavg_search']) && $modSettings['current_load'] >= $modSettings['loadavg_search']) |
||
| 122 | { |
||
| 123 | throw new Exception('loadavg_search_disabled', false); |
||
| 124 | } |
||
| 125 | |||
| 126 | Txt::load('Search'); |
||
| 127 | |||
| 128 | // Don't load this in XML mode. |
||
| 129 | if ($this->getApi() === false) |
||
| 130 | { |
||
| 131 | theme()->getTemplates()->load('Search'); |
||
| 132 | $context['sub_template'] = 'searchform'; |
||
| 133 | loadJavascriptFile('suggest.js', ['defer' => false]); |
||
| 134 | } |
||
| 135 | |||
| 136 | // Check the user's permissions. |
||
| 137 | isAllowedTo('search_posts'); |
||
| 138 | |||
| 139 | // Link tree.... |
||
| 140 | $context['breadcrumbs'][] = [ |
||
| 141 | 'url' => getUrl('action', ['action' => 'search']), |
||
| 142 | 'name' => $txt['search'] |
||
| 143 | ]; |
||
| 144 | |||
| 145 | // This is hard coded maximum string length. |
||
| 146 | $context['search_string_limit'] = 100; |
||
| 147 | |||
| 148 | $context['require_verification'] = $this->user->is_guest && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 149 | if ($context['require_verification']) |
||
| 150 | { |
||
| 151 | // Build a verification control for the form |
||
| 152 | $verificationOptions = [ |
||
| 153 | 'id' => 'search', |
||
| 154 | ]; |
||
| 155 | |||
| 156 | $context['require_verification'] = VerificationControlsIntegrate::create($verificationOptions); |
||
| 157 | $context['visual_verification_id'] = $verificationOptions['id']; |
||
| 158 | } |
||
| 159 | |||
| 160 | // If you got back from search;sa=results by using the breadcrumbs, you get your original search parameters back. |
||
| 161 | $params = $this->_req->getQuery('params'); |
||
| 162 | if ($this->_search === null && isset($params)) |
||
| 163 | { |
||
| 164 | $search_params = new SearchParams($params); |
||
| 165 | |||
| 166 | $context['search_params'] = $search_params->get(); |
||
| 167 | } |
||
| 168 | |||
| 169 | $search = $this->_req->getRequest('search', 'un_htmlspecialchars|trim'); |
||
| 170 | if (isset($search)) |
||
| 171 | { |
||
| 172 | $context['search_params']['search'] = $search; |
||
| 173 | } |
||
| 174 | |||
| 175 | if (isset($context['search_params']['search'])) |
||
| 176 | { |
||
| 177 | $context['search_params']['search'] = Util::htmlspecialchars($context['search_params']['search']); |
||
| 178 | } |
||
| 179 | |||
| 180 | if (isset($context['search_params']['userspec'])) |
||
| 181 | { |
||
| 182 | $context['search_params']['userspec'] = htmlspecialchars($context['search_params']['userspec'], ENT_COMPAT, 'UTF-8'); |
||
| 183 | } |
||
| 184 | |||
| 185 | if (!empty($context['search_params']['searchtype'])) |
||
| 186 | { |
||
| 187 | $context['search_params']['searchtype'] = 2; |
||
| 188 | } |
||
| 189 | |||
| 190 | if (!empty($context['search_params']['minage'])) |
||
| 191 | { |
||
| 192 | $context['search_params']['minage'] = date("Y-m-d", strtotime('-' . $context['search_params']['minage'] . ' days')); |
||
| 193 | } |
||
| 194 | |||
| 195 | if (!empty($context['search_params']['maxage'])) |
||
| 196 | { |
||
| 197 | if ($context['search_params']['maxage'] === 9999) |
||
| 198 | { |
||
| 199 | $context['search_params']['maxage'] = 0; |
||
| 200 | } |
||
| 201 | else |
||
| 202 | { |
||
| 203 | $context['search_params']['maxage'] = date("Y-m-d", strtotime('-' . $context['search_params']['maxage'] . ' days')); |
||
| 204 | } |
||
| 205 | } |
||
| 206 | |||
| 207 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']); |
||
| 208 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']); |
||
| 209 | |||
| 210 | // Load the error text strings if there were errors in the search. |
||
| 211 | if (!empty($context['search_errors'])) |
||
| 212 | { |
||
| 213 | Txt::load('Errors'); |
||
| 214 | $context['search_errors']['messages'] = []; |
||
| 215 | foreach ($context['search_errors'] as $search_error => $dummy) |
||
| 216 | { |
||
| 217 | if ($search_error === 'messages') |
||
| 218 | { |
||
| 219 | continue; |
||
| 220 | } |
||
| 221 | |||
| 222 | if ($search_error === 'string_too_long') |
||
| 223 | { |
||
| 224 | $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
||
| 225 | } |
||
| 226 | |||
| 227 | $context['search_errors']['messages'][] = $txt['error_' . $search_error]; |
||
| 228 | } |
||
| 229 | } |
||
| 230 | |||
| 231 | require_once(SUBSDIR . '/Boards.subs.php'); |
||
| 232 | $context += getBoardList(['not_redirection' => true]); |
||
| 233 | |||
| 234 | $context['boards_in_category'] = []; |
||
| 235 | foreach ($context['categories'] as $cat => &$category) |
||
| 236 | { |
||
| 237 | $context['boards_in_category'][$cat] = count($category['boards']); |
||
| 238 | $category['child_ids'] = array_keys($category['boards']); |
||
| 239 | foreach ($category['boards'] as &$board) |
||
| 240 | { |
||
| 241 | $board['selected'] = (empty($context['search_params']['brd']) && (empty($modSettings['recycle_enable']) || $board['id'] != $modSettings['recycle_board']) && !in_array($board['id'], (array) $this->user->ignoreboards)) || (!empty($context['search_params']['brd']) && in_array($board['id'], $context['search_params']['brd'])); |
||
|
0 ignored issues
–
show
The property
ignoreboards does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||
| 242 | } |
||
| 243 | } |
||
| 244 | |||
| 245 | $topic = $this->_req->getRequest('topic', 'intval', 0); |
||
| 246 | if (!empty($topic)) |
||
| 247 | { |
||
| 248 | $context['search_params']['topic'] = $topic; |
||
| 249 | $context['search_params']['show_complete'] = true; |
||
| 250 | } |
||
| 251 | |||
| 252 | if (!empty($context['search_params']['topic'])) |
||
| 253 | { |
||
| 254 | $context['search_params']['topic'] = (int) $context['search_params']['topic']; |
||
| 255 | |||
| 256 | $context['search_topic'] = [ |
||
| 257 | 'id' => $context['search_params']['topic'], |
||
| 258 | 'href' => getUrl('action', ['topic' => $context['search_params']['topic'] . '.0']), |
||
| 259 | ]; |
||
| 260 | |||
| 261 | require_once(SUBSDIR . '/Topic.subs.php'); |
||
| 262 | $context['search_topic']['subject'] = getSubject($context['search_params']['topic']); |
||
| 263 | $context['search_topic']['link'] = '<a href="' . $context['search_topic']['href'] . '">' . $context['search_topic']['subject'] . '</a>'; |
||
| 264 | } |
||
| 265 | |||
| 266 | $context['page_title'] = $txt['set_parameters']; |
||
| 267 | $context['search_params'] = $this->_fill_default_search_params($context['search_params']); |
||
| 268 | |||
| 269 | // Start guest off collapsed |
||
| 270 | if ($context['user']['is_guest'] && !isset($context['minmax_preferences']['asearch'])) |
||
| 271 | { |
||
| 272 | $context['minmax_preferences']['asearch'] = 1; |
||
| 273 | } |
||
| 274 | |||
| 275 | call_integration_hook('integrate_search'); |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Fills the empty spaces in an array with the default values for search params |
||
| 280 | * |
||
| 281 | * @param array $array |
||
| 282 | * |
||
| 283 | * @return array |
||
| 284 | */ |
||
| 285 | private function _fill_default_search_params($array): array |
||
| 286 | { |
||
| 287 | $default = [ |
||
| 288 | 'search' => '', |
||
| 289 | 'userspec' => '*', |
||
| 290 | 'searchtype' => 0, |
||
| 291 | 'show_complete' => 0, |
||
| 292 | 'subject_only' => 0, |
||
| 293 | 'minage' => 0, |
||
| 294 | 'maxage' => 9999, |
||
| 295 | 'sort' => 'relevance', |
||
| 296 | ]; |
||
| 297 | |||
| 298 | $array = array_merge($default, $array); |
||
| 299 | if (empty($array['userspec'])) |
||
| 300 | { |
||
| 301 | $array['userspec'] = '*'; |
||
| 302 | } |
||
| 303 | |||
| 304 | $array['show_complete'] = (int) $array['show_complete']; |
||
| 305 | $array['subject_only'] = (int) $array['subject_only']; |
||
| 306 | |||
| 307 | return $array; |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Gather the results and show them. |
||
| 312 | * |
||
| 313 | * What it does: |
||
| 314 | * |
||
| 315 | * - Checks user input and searches the messages table for messages matching the query. |
||
| 316 | * - Requires the search_posts permission. |
||
| 317 | * - Uses the results sub template of the Search template. |
||
| 318 | * - Uses the Search language file. |
||
| 319 | * - Stores the results into the search cache. |
||
| 320 | * - Show the results of the search query. |
||
| 321 | */ |
||
| 322 | public function action_results() |
||
| 323 | { |
||
| 324 | global $modSettings, $txt, $settings, $context, $options, $messages_request; |
||
| 325 | |||
| 326 | // No, no, no... this is a bit hard on the server, so don't you go prefetching it! |
||
| 327 | stop_prefetching(); |
||
| 328 | |||
| 329 | // These vars don't require an interface, they're just here for tweaking. |
||
| 330 | $recentPercentage = 0.30; |
||
| 331 | |||
| 332 | // Message length used to tweak messages relevance of the results |
||
| 333 | $humungousTopicPosts = 200; |
||
| 334 | $shortTopicPosts = 5; |
||
| 335 | $maxMembersToSearch = 500; |
||
| 336 | |||
| 337 | // Maximum number of results |
||
| 338 | $maxMessageResults = empty($modSettings['search_max_results']) ? 0 : $modSettings['search_max_results'] * 5; |
||
| 339 | |||
| 340 | // Start with no errors. |
||
| 341 | $context['search_errors'] = []; |
||
| 342 | |||
| 343 | // Number of pages hard maximum - normally not set at all. |
||
| 344 | $modSettings['search_max_results'] = empty($modSettings['search_max_results']) ? 200 * $modSettings['search_results_per_page'] : (int) $modSettings['search_max_results']; |
||
| 345 | |||
| 346 | // Maximum length of the string. |
||
| 347 | $context['search_string_limit'] = 100; |
||
| 348 | |||
| 349 | Txt::load('Search'); |
||
| 350 | if ($this->getApi() === false) |
||
| 351 | { |
||
| 352 | theme()->getTemplates()->load('Search'); |
||
| 353 | } |
||
| 354 | // If we're doing XML we need to use the results template regardless really. |
||
| 355 | else |
||
| 356 | { |
||
| 357 | $context['sub_template'] = 'results'; |
||
| 358 | } |
||
| 359 | |||
| 360 | // Are you allowed? |
||
| 361 | isAllowedTo('search_posts'); |
||
| 362 | |||
| 363 | $this->_search = new \ElkArte\Search\Search(); |
||
| 364 | $this->_search->setWeights(new WeightFactors($modSettings, $this->user->is_admin)); |
||
| 365 | |||
| 366 | $params = $this->_req->getRequest('params', '', ''); |
||
| 367 | $search_params = new SearchParams($params); |
||
| 368 | $search_params->merge((array) $this->_req->post, $recentPercentage, $maxMembersToSearch); |
||
| 369 | |||
| 370 | $this->_search->setParams($search_params, !empty($modSettings['search_simple_fulltext'])); |
||
| 371 | |||
| 372 | $context['compact'] = $this->_search->isCompact(); |
||
| 373 | |||
| 374 | // Nothing?? |
||
| 375 | if ($this->_search->param('search') === false || $this->_search->param('search') === '') |
||
| 376 | { |
||
| 377 | $context['search_errors']['invalid_search_string'] = true; |
||
| 378 | } |
||
| 379 | // Too long? |
||
| 380 | elseif (Util::strlen($this->_search->param('search')) > $context['search_string_limit']) |
||
| 381 | { |
||
| 382 | $context['search_errors']['string_too_long'] = true; |
||
| 383 | } |
||
| 384 | |||
| 385 | // Build the search array |
||
| 386 | // $modSettings ['search_simple_fulltext'] is an hidden setting that will |
||
| 387 | // do fulltext searching in the most basic way. |
||
| 388 | $searchArray = $this->_search->getSearchArray(); |
||
| 389 | |||
| 390 | // This is used to remember words that will be ignored (because too short usually) |
||
| 391 | $context['search_ignored'] = $this->_search->getIgnored(); |
||
| 392 | |||
| 393 | // Make sure at least one word is being searched for. |
||
| 394 | if (empty($searchArray)) |
||
| 395 | { |
||
| 396 | if (!empty($context['search_ignored'])) |
||
| 397 | { |
||
| 398 | $context['search_errors']['search_string_small_words'] = true; |
||
| 399 | } |
||
| 400 | else |
||
| 401 | { |
||
| 402 | $context['search_errors']['invalid_search_string' . ($this->_search->foundBlockListedWords() ? '_blocklist' : '')] = true; |
||
| 403 | } |
||
| 404 | |||
| 405 | // Don't allow duplicate error messages if one string is too short. |
||
| 406 | if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) |
||
| 407 | { |
||
| 408 | unset($context['search_errors']['invalid_search_string']); |
||
| 409 | } |
||
| 410 | } |
||
| 411 | |||
| 412 | // Let the user adjust the search query, should they wish? |
||
| 413 | $context['search_params'] = (array) $this->_search->getSearchParams(true); |
||
| 414 | if (isset($context['search_params']['search'])) |
||
| 415 | { |
||
| 416 | $context['search_params']['search'] = Util::htmlspecialchars($context['search_params']['search']); |
||
| 417 | } |
||
| 418 | |||
| 419 | if (isset($context['search_params']['userspec'])) |
||
| 420 | { |
||
| 421 | $context['search_params']['userspec'] = Util::htmlspecialchars($context['search_params']['userspec']); |
||
| 422 | } |
||
| 423 | |||
| 424 | if (empty($context['search_params']['minage'])) |
||
| 425 | { |
||
| 426 | $context['search_params']['minage'] = 0; |
||
| 427 | } |
||
| 428 | |||
| 429 | if (empty($context['search_params']['maxage'])) |
||
| 430 | { |
||
| 431 | $context['search_params']['maxage'] = 9999; |
||
| 432 | } |
||
| 433 | |||
| 434 | $context['search_params'] = $this->_fill_default_search_params($context['search_params']); |
||
| 435 | |||
| 436 | $this->_controlVerifications(); |
||
| 437 | |||
| 438 | $context['params'] = $this->_search->compileURLparams(); |
||
| 439 | |||
| 440 | // ... and add the links to the link tree. |
||
| 441 | $context['breadcrumbs'][] = [ |
||
| 442 | 'url' => getUrl('action', ['action' => 'search', 'params' => $context['params']]), |
||
| 443 | 'name' => $txt['search'] |
||
| 444 | ]; |
||
| 445 | |||
| 446 | $context['breadcrumbs'][] = [ |
||
| 447 | 'url' => getUrl('action', ['action' => 'search', 'sa' => 'results', 'params' => $context['params']]), |
||
| 448 | 'name' => $txt['search_results'] |
||
| 449 | ]; |
||
| 450 | |||
| 451 | // Start guest off collapsed |
||
| 452 | if ($context['user']['is_guest'] && !isset($context['minmax_preferences']['asearch'])) |
||
| 453 | { |
||
| 454 | $context['minmax_preferences']['asearch'] = 1; |
||
| 455 | } |
||
| 456 | |||
| 457 | // *** A last error check |
||
| 458 | call_integration_hook('integrate_search_errors'); |
||
| 459 | |||
| 460 | // One or more search errors? Go back to the first search screen. |
||
| 461 | if (!empty($context['search_errors'])) |
||
| 462 | { |
||
| 463 | $this->action_search(); |
||
| 464 | return null; |
||
| 465 | } |
||
| 466 | |||
| 467 | // Spam me not, Spam-a-lot? |
||
| 468 | if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] !== $this->_search->param('search')) |
||
| 469 | { |
||
| 470 | spamProtection('search'); |
||
| 471 | } |
||
| 472 | |||
| 473 | // Store the last search string to allow pages of results to be browsed. |
||
| 474 | $_SESSION['last_ss'] = $this->_search->param('search'); |
||
| 475 | |||
| 476 | try |
||
| 477 | { |
||
| 478 | $search_config = new ValuesContainer([ |
||
| 479 | 'humungousTopicPosts' => $humungousTopicPosts, |
||
| 480 | 'shortTopicPosts' => $shortTopicPosts, |
||
| 481 | 'maxMessageResults' => $maxMessageResults, |
||
| 482 | 'search_index' => empty($modSettings['search_index']) ? '' : $modSettings['search_index'], |
||
| 483 | 'banned_words' => empty($modSettings['search_banned_words']) ? [] : explode(',', $modSettings['search_banned_words']), |
||
| 484 | ]); |
||
| 485 | $context['topics'] = $this->_search->searchQuery( |
||
| 486 | new SearchApiWrapper($search_config, $this->_search->getSearchParams()) |
||
| 487 | ); |
||
| 488 | } |
||
| 489 | catch (\Exception $exception) |
||
| 490 | { |
||
| 491 | $context['search_errors'][$exception->getMessage()] = true; |
||
| 492 | |||
| 493 | $this->action_search(); |
||
| 494 | return null; |
||
| 495 | } |
||
| 496 | |||
| 497 | // Did we find anything? |
||
| 498 | if (!empty($context['topics'])) |
||
| 499 | { |
||
| 500 | // Create an array for the permissions. |
||
| 501 | $boards_can = boardsAllowedTo(['post_reply_own', 'post_reply_any', 'mark_any_notify'], true, false); |
||
| 502 | |||
| 503 | // How's about some quick moderation? |
||
| 504 | if (!empty($options['display_quick_mod'])) |
||
| 505 | { |
||
| 506 | $boards_can = array_merge($boards_can, boardsAllowedTo(['lock_any', 'lock_own', 'make_sticky', 'move_any', 'move_own', 'remove_any', 'remove_own', 'merge_any'], true, false)); |
||
| 507 | |||
| 508 | $context['can_lock'] = in_array(0, $boards_can['lock_any']); |
||
| 509 | $context['can_sticky'] = in_array(0, $boards_can['make_sticky']); |
||
| 510 | $context['can_move'] = in_array(0, $boards_can['move_any']); |
||
| 511 | $context['can_remove'] = in_array(0, $boards_can['remove_any']); |
||
| 512 | $context['can_merge'] = in_array(0, $boards_can['merge_any']); |
||
| 513 | } |
||
| 514 | |||
| 515 | // What messages are we using? |
||
| 516 | $msg_list = array_keys($context['topics']); |
||
| 517 | $posters = $this->_search->loadPosters($msg_list, count($context['topics'])); |
||
| 518 | |||
| 519 | call_integration_hook('integrate_search_message_list', [&$msg_list, &$posters]); |
||
| 520 | |||
| 521 | if (!empty($posters)) |
||
| 522 | { |
||
| 523 | MembersList::load(array_unique($posters)); |
||
| 524 | } |
||
| 525 | |||
| 526 | // Get the messages out for the callback - select enough that it can be made to look just like Display. |
||
| 527 | $messages_request = $this->_search->loadMessagesRequest($msg_list, count($context['topics'])); |
||
| 528 | |||
| 529 | // If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore. |
||
| 530 | if ($this->_search->noMessages($messages_request)) |
||
| 531 | { |
||
| 532 | $context['topics'] = []; |
||
| 533 | } |
||
| 534 | |||
| 535 | $this->_prepareParticipants(!empty($modSettings['enableParticipation']), (int) $this->user->id); |
||
| 536 | } |
||
| 537 | |||
| 538 | // Now that we know how many results to expect we can start calculating the page numbers. |
||
| 539 | $start = $this->_req->getRequest('start', 'intval', 0); |
||
| 540 | $context['page_index'] = constructPageIndex('{scripturl}?action=search;sa=results;params=' . $context['params'], $start, $this->_search->getNumResults(), $modSettings['search_results_per_page'], false); |
||
| 541 | |||
| 542 | // Consider the search complete! |
||
| 543 | Cache::instance()->remove('search_start:' . ($this->user->is_guest ? $this->user->ip : $this->user->id)); |
||
| 544 | |||
| 545 | $context['sub_template'] = 'results'; |
||
| 546 | $context['page_title'] = $txt['search_results']; |
||
| 547 | |||
| 548 | $this->_icon_sources = new MessageTopicIcons(!empty($modSettings['messageIconChecks_enable']), $settings['theme_dir']); |
||
| 549 | |||
| 550 | // Set the callback. (do you REALIZE how much memory all the messages would take?!?) |
||
| 551 | // This will be called from the template. |
||
| 552 | if ($this->_search->isCompact()) |
||
| 553 | { |
||
| 554 | $bodyParser = new Compact($this->_search->getSearchArray(), empty($modSettings['search_method'])); |
||
| 555 | } |
||
| 556 | else |
||
| 557 | { |
||
| 558 | $bodyParser = new Normal($this->_search->getSearchArray(), empty($modSettings['search_method'])); |
||
| 559 | } |
||
| 560 | |||
| 561 | $opt = new ValuesContainer([ |
||
| 562 | 'icon_sources' => $this->_icon_sources, |
||
| 563 | 'show_signatures' => false, |
||
| 564 | 'boards_can' => $boards_can ?? [], |
||
| 565 | ]); |
||
| 566 | $renderer = new SearchRenderer($messages_request, $this->user, $bodyParser, $opt); |
||
| 567 | $renderer->setParticipants($this->_participants); |
||
| 568 | |||
| 569 | $context['topic_starter_id'] = 0; |
||
| 570 | $context['get_topics'] = [$renderer, 'getContext']; |
||
| 571 | |||
| 572 | $context['jump_to'] = [ |
||
| 573 | 'label' => addslashes(un_htmlspecialchars($txt['jump_to'])), |
||
| 574 | 'board_name' => addslashes(un_htmlspecialchars($txt['select_destination'])), |
||
| 575 | ]; |
||
| 576 | |||
| 577 | loadJavascriptFile('topic.js'); |
||
| 578 | $this->buildQuickModerationButtons(); |
||
| 579 | } |
||
| 580 | |||
| 581 | /** |
||
| 582 | * Show an anti-spam verification control |
||
| 583 | */ |
||
| 584 | protected function _controlVerifications(): void |
||
| 585 | { |
||
| 586 | global $modSettings, $context; |
||
| 587 | |||
| 588 | // Do we have captcha enabled? |
||
| 589 | if ($this->user->is_guest && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] !== $this->_search->param('search'))) |
||
|
0 ignored issues
–
show
The property
is_guest does not exist on ElkArte\Helper\ValuesContainer. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||
| 590 | { |
||
| 591 | $verificationOptions = [ |
||
| 592 | 'id' => 'search', |
||
| 593 | ]; |
||
| 594 | $context['require_verification'] = VerificationControlsIntegrate::create($verificationOptions, true); |
||
| 595 | |||
| 596 | if (is_array($context['require_verification'])) |
||
| 597 | { |
||
| 598 | foreach ($context['require_verification'] as $error) |
||
| 599 | { |
||
| 600 | $context['search_errors'][$error] = true; |
||
| 601 | } |
||
| 602 | } |
||
| 603 | // Don't keep asking for it - they've proven themselves worthy. |
||
| 604 | else |
||
| 605 | { |
||
| 606 | $_SESSION['ss_vv_passed'] = true; |
||
| 607 | } |
||
| 608 | } |
||
| 609 | } |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Prepares the participants data |
||
| 613 | * |
||
| 614 | * @param bool $participationEnabled Indicates if participation is enabled |
||
| 615 | * @param int $user_id The ID of the user |
||
| 616 | * |
||
| 617 | * @return void |
||
| 618 | */ |
||
| 619 | protected function _prepareParticipants($participationEnabled, $user_id): void |
||
| 620 | { |
||
| 621 | // If we want to know who participated in what then load this now. |
||
| 622 | if ($participationEnabled === true && $user_id !== 0) |
||
| 623 | { |
||
| 624 | $this->_participants = $this->_search->getParticipants(); |
||
| 625 | |||
| 626 | require_once(SUBSDIR . '/MessageIndex.subs.php'); |
||
| 627 | $topics_participated_in = topicsParticipation($user_id, array_keys($this->_participants)); |
||
| 628 | |||
| 629 | foreach ($topics_participated_in as $topic) |
||
| 630 | { |
||
| 631 | $this->_participants[$topic['id_topic']] = true; |
||
| 632 | } |
||
| 633 | } |
||
| 634 | } |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Loads into $context the moderation button array for template use. |
||
| 638 | * Call integrate_message_index_mod_buttons hook |
||
| 639 | */ |
||
| 640 | protected function buildQuickModerationButtons(): void |
||
| 641 | { |
||
| 642 | global $context; |
||
| 643 | |||
| 644 | // Build the mod button array with buttons that are valid for, at least some, of the messages |
||
| 645 | $context['mod_buttons'] = [ |
||
| 646 | 'move' => [ |
||
| 647 | 'test' => 'can_move', |
||
| 648 | 'text' => 'move_topic', |
||
| 649 | 'id' => 'move', |
||
| 650 | 'lang' => true, |
||
| 651 | 'url' => 'javascript:void(0);', |
||
| 652 | ], |
||
| 653 | 'remove' => [ |
||
| 654 | 'test' => 'can_remove', |
||
| 655 | 'text' => 'remove_topic', |
||
| 656 | 'id' => 'remove', |
||
| 657 | 'lang' => true, |
||
| 658 | 'url' => 'javascript:void(0);', |
||
| 659 | ], |
||
| 660 | 'lock' => [ |
||
| 661 | 'test' => 'can_lock', |
||
| 662 | 'text' => 'set_lock', |
||
| 663 | 'id' => 'lock', |
||
| 664 | 'lang' => true, |
||
| 665 | 'url' => 'javascript:void(0);', |
||
| 666 | ], |
||
| 667 | 'sticky' => [ |
||
| 668 | 'test' => 'can_sticky', |
||
| 669 | 'text' => 'set_sticky', |
||
| 670 | 'id' => 'sticky', |
||
| 671 | 'lang' => true, |
||
| 672 | 'url' => 'javascript:void(0);', |
||
| 673 | ], |
||
| 674 | 'markread' => [ |
||
| 675 | 'test' => 'can_markread', |
||
| 676 | 'text' => 'mark_read_short', |
||
| 677 | 'id' => 'markread', |
||
| 678 | 'lang' => true, |
||
| 679 | 'url' => 'javascript:void(0);', |
||
| 680 | ], |
||
| 681 | ]; |
||
| 682 | |||
| 683 | // Allow adding new buttons easily. |
||
| 684 | call_integration_hook('integrate_search_quickmod_buttons'); |
||
| 685 | |||
| 686 | $context['mod_buttons'] = array_reverse($context['mod_buttons']); |
||
| 687 | } |
||
| 688 | } |
||
| 689 |