@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | |
660 | 660 | // Remove the phrase parts and extract the words. |
661 | 661 | $wordArray = preg_replace('~(?:^|\s)(?:[-]?)"(?:[^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), ' ', $search_params['search']); |
662 | - $wordArray = explode(' ', $smcFunc['htmlspecialchars'](un_htmlspecialchars($wordArray), ENT_QUOTES)); |
|
662 | + $wordArray = explode(' ', $smcFunc['htmlspecialchars'](un_htmlspecialchars($wordArray), ENT_QUOTES)); |
|
663 | 663 | |
664 | 664 | // A minus sign in front of a word excludes the word.... so... |
665 | 665 | $excludedWords = array(); |
@@ -1102,7 +1102,7 @@ discard block |
||
1102 | 1102 | SELECT |
1103 | 1103 | {int:id_search}, |
1104 | 1104 | t.id_topic, |
1105 | - ' . $relevance. ', |
|
1105 | + ' . $relevance . ', |
|
1106 | 1106 | ' . (empty($userQuery) ? 't.id_first_msg' : 'm.id_msg') . ', |
1107 | 1107 | 1 |
1108 | 1108 | FROM ' . $subject_query['from'] . (empty($subject_query['inner_join']) ? '' : ' |
@@ -1335,7 +1335,7 @@ discard block |
||
1335 | 1335 | if (empty($subject_query['where'])) |
1336 | 1336 | continue; |
1337 | 1337 | |
1338 | - $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( ' |
|
1338 | + $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? (' |
|
1339 | 1339 | INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics |
1340 | 1340 | (' . ($createTemporary ? '' : 'id_search, ') . 'id_topic)') : '') . ' |
1341 | 1341 | SELECT ' . ($createTemporary ? '' : $_SESSION['search_cache']['id_search'] . ', ') . 't.id_topic |
@@ -1562,7 +1562,7 @@ discard block |
||
1562 | 1562 | } |
1563 | 1563 | $main_query['select']['relevance'] = substr($relevance, 0, -3) . ') / ' . $new_weight_total . ' AS relevance'; |
1564 | 1564 | |
1565 | - $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_no_index', ($smcFunc['db_support_ignore'] ? ( ' |
|
1565 | + $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_no_index', ($smcFunc['db_support_ignore'] ? (' |
|
1566 | 1566 | INSERT IGNORE INTO ' . '{db_prefix}log_search_results |
1567 | 1567 | (' . implode(', ', array_keys($main_query['select'])) . ')') : '') . ' |
1568 | 1568 | SELECT |
@@ -1630,7 +1630,7 @@ discard block |
||
1630 | 1630 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
1631 | 1631 | |
1632 | 1632 | $usedIDs = array_flip(empty($inserts) ? array() : array_keys($inserts)); |
1633 | - $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_sub_only', ($smcFunc['db_support_ignore'] ? ( ' |
|
1633 | + $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_sub_only', ($smcFunc['db_support_ignore'] ? (' |
|
1634 | 1634 | INSERT IGNORE INTO {db_prefix}log_search_results |
1635 | 1635 | (id_search, id_topic, relevance, id_msg, num_matches)') : '') . ' |
1636 | 1636 | SELECT |
@@ -2099,7 +2099,7 @@ discard block |
||
2099 | 2099 | if (strlen($query) == 0) |
2100 | 2100 | continue; |
2101 | 2101 | |
2102 | - $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => ''')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function ($m) |
|
2102 | + $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => ''')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function($m) |
|
2103 | 2103 | { |
2104 | 2104 | return isset($m[2]) && "$m[2]" == "$m[1]" ? stripslashes("$m[1]") : "<strong class=\"highlight\">$m[1]</strong>"; |
2105 | 2105 | }, $body_highlighted); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | // This defines two version types for checking the API's are compatible with this version of SMF. |
20 | 21 | $GLOBALS['search_versions'] = array( |
@@ -39,8 +40,9 @@ discard block |
||
39 | 40 | global $txt, $scripturl, $modSettings, $user_info, $context, $smcFunc, $sourcedir; |
40 | 41 | |
41 | 42 | // Is the load average too high to allow searching just now? |
42 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
43 | - fatal_lang_error('loadavg_search_disabled', false); |
|
43 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
44 | + fatal_lang_error('loadavg_search_disabled', false); |
|
45 | + } |
|
44 | 46 | |
45 | 47 | loadLanguage('Search'); |
46 | 48 | // Don't load this in XML mode. |
@@ -88,23 +90,30 @@ discard block |
||
88 | 90 | @list ($k, $v) = explode('|\'|', $data); |
89 | 91 | $context['search_params'][$k] = $v; |
90 | 92 | } |
91 | - if (isset($context['search_params']['brd'])) |
|
92 | - $context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']); |
|
93 | + if (isset($context['search_params']['brd'])) { |
|
94 | + $context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']); |
|
95 | + } |
|
93 | 96 | } |
94 | 97 | |
95 | - if (isset($_REQUEST['search'])) |
|
96 | - $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
98 | + if (isset($_REQUEST['search'])) { |
|
99 | + $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
100 | + } |
|
97 | 101 | |
98 | - if (isset($context['search_params']['search'])) |
|
99 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
100 | - if (isset($context['search_params']['userspec'])) |
|
101 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
102 | - if (!empty($context['search_params']['searchtype'])) |
|
103 | - $context['search_params']['searchtype'] = 2; |
|
104 | - if (!empty($context['search_params']['minage'])) |
|
105 | - $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
106 | - if (!empty($context['search_params']['maxage'])) |
|
107 | - $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
102 | + if (isset($context['search_params']['search'])) { |
|
103 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
104 | + } |
|
105 | + if (isset($context['search_params']['userspec'])) { |
|
106 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
107 | + } |
|
108 | + if (!empty($context['search_params']['searchtype'])) { |
|
109 | + $context['search_params']['searchtype'] = 2; |
|
110 | + } |
|
111 | + if (!empty($context['search_params']['minage'])) { |
|
112 | + $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
113 | + } |
|
114 | + if (!empty($context['search_params']['maxage'])) { |
|
115 | + $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
116 | + } |
|
108 | 117 | |
109 | 118 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']); |
110 | 119 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']); |
@@ -116,11 +125,13 @@ discard block |
||
116 | 125 | $context['search_errors']['messages'] = array(); |
117 | 126 | foreach ($context['search_errors'] as $search_error => $dummy) |
118 | 127 | { |
119 | - if ($search_error === 'messages') |
|
120 | - continue; |
|
128 | + if ($search_error === 'messages') { |
|
129 | + continue; |
|
130 | + } |
|
121 | 131 | |
122 | - if ($search_error == 'string_too_long') |
|
123 | - $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
|
132 | + if ($search_error == 'string_too_long') { |
|
133 | + $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
|
134 | + } |
|
124 | 135 | |
125 | 136 | $context['search_errors']['messages'][] = $txt['error_' . $search_error]; |
126 | 137 | } |
@@ -143,12 +154,13 @@ discard block |
||
143 | 154 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
144 | 155 | { |
145 | 156 | // This category hasn't been set up yet.. |
146 | - if (!isset($context['categories'][$row['id_cat']])) |
|
147 | - $context['categories'][$row['id_cat']] = array( |
|
157 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
158 | + $context['categories'][$row['id_cat']] = array( |
|
148 | 159 | 'id' => $row['id_cat'], |
149 | 160 | 'name' => $row['cat_name'], |
150 | 161 | 'boards' => array() |
151 | 162 | ); |
163 | + } |
|
152 | 164 | |
153 | 165 | // Set this board up, and let the template know when it's a child. (indent them..) |
154 | 166 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -159,8 +171,9 @@ discard block |
||
159 | 171 | ); |
160 | 172 | |
161 | 173 | // If a board wasn't checked that probably should have been ensure the board selection is selected, yo! |
162 | - if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) |
|
163 | - $context['boards_check_all'] = false; |
|
174 | + if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) { |
|
175 | + $context['boards_check_all'] = false; |
|
176 | + } |
|
164 | 177 | } |
165 | 178 | $smcFunc['db_free_result']($request); |
166 | 179 | |
@@ -182,18 +195,20 @@ discard block |
||
182 | 195 | } |
183 | 196 | |
184 | 197 | $max_boards = ceil(count($temp_boards) / 2); |
185 | - if ($max_boards == 1) |
|
186 | - $max_boards = 2; |
|
198 | + if ($max_boards == 1) { |
|
199 | + $max_boards = 2; |
|
200 | + } |
|
187 | 201 | |
188 | 202 | // Now, alternate them so they can be shown left and right ;). |
189 | 203 | $context['board_columns'] = array(); |
190 | 204 | for ($i = 0; $i < $max_boards; $i++) |
191 | 205 | { |
192 | 206 | $context['board_columns'][] = $temp_boards[$i]; |
193 | - if (isset($temp_boards[$i + $max_boards])) |
|
194 | - $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
195 | - else |
|
196 | - $context['board_columns'][] = array(); |
|
207 | + if (isset($temp_boards[$i + $max_boards])) { |
|
208 | + $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
209 | + } else { |
|
210 | + $context['board_columns'][] = array(); |
|
211 | + } |
|
197 | 212 | } |
198 | 213 | |
199 | 214 | if (!empty($_REQUEST['topic'])) |
@@ -225,8 +240,9 @@ discard block |
||
225 | 240 | ) |
226 | 241 | ); |
227 | 242 | |
228 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
229 | - fatal_lang_error('topic_gone', false); |
|
243 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
244 | + fatal_lang_error('topic_gone', false); |
|
245 | + } |
|
230 | 246 | |
231 | 247 | list ($context['search_topic']['subject']) = $smcFunc['db_fetch_row']($request); |
232 | 248 | $smcFunc['db_free_result']($request); |
@@ -256,11 +272,13 @@ discard block |
||
256 | 272 | global $excludedWords, $participants, $smcFunc; |
257 | 273 | |
258 | 274 | // if comming from the quick search box, and we want to search on members, well we need to do that ;) |
259 | - if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') |
|
260 | - redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search'])); |
|
275 | + if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') { |
|
276 | + redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search'])); |
|
277 | + } |
|
261 | 278 | |
262 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
263 | - fatal_lang_error('loadavg_search_disabled', false); |
|
279 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
280 | + fatal_lang_error('loadavg_search_disabled', false); |
|
281 | + } |
|
264 | 282 | |
265 | 283 | // No, no, no... this is a bit hard on the server, so don't you go prefetching it! |
266 | 284 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -307,8 +325,9 @@ discard block |
||
307 | 325 | } |
308 | 326 | |
309 | 327 | // Zero weight. Weightless :P. |
310 | - if (empty($weight_total)) |
|
311 | - fatal_lang_error('search_invalid_weights'); |
|
328 | + if (empty($weight_total)) { |
|
329 | + fatal_lang_error('search_invalid_weights'); |
|
330 | + } |
|
312 | 331 | |
313 | 332 | // These vars don't require an interface, they're just here for tweaking. |
314 | 333 | $recentPercentage = 0.30; |
@@ -326,11 +345,13 @@ discard block |
||
326 | 345 | $context['search_string_limit'] = 100; |
327 | 346 | |
328 | 347 | loadLanguage('Search'); |
329 | - if (!isset($_REQUEST['xml'])) |
|
330 | - loadTemplate('Search'); |
|
348 | + if (!isset($_REQUEST['xml'])) { |
|
349 | + loadTemplate('Search'); |
|
350 | + } |
|
331 | 351 | //If we're doing XML we need to use the results template regardless really. |
332 | - else |
|
333 | - $context['sub_template'] = 'results'; |
|
352 | + else { |
|
353 | + $context['sub_template'] = 'results'; |
|
354 | + } |
|
334 | 355 | |
335 | 356 | // Are you allowed? |
336 | 357 | isAllowedTo('search_posts'); |
@@ -363,34 +384,39 @@ discard block |
||
363 | 384 | $search_params[$k] = $v; |
364 | 385 | } |
365 | 386 | |
366 | - if (isset($search_params['brd'])) |
|
367 | - $search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']); |
|
387 | + if (isset($search_params['brd'])) { |
|
388 | + $search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']); |
|
389 | + } |
|
368 | 390 | } |
369 | 391 | |
370 | 392 | // Store whether simple search was used (needed if the user wants to do another query). |
371 | - if (!isset($search_params['advanced'])) |
|
372 | - $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
393 | + if (!isset($search_params['advanced'])) { |
|
394 | + $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
395 | + } |
|
373 | 396 | |
374 | 397 | // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'. |
375 | - if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) |
|
376 | - $search_params['searchtype'] = 2; |
|
398 | + if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) { |
|
399 | + $search_params['searchtype'] = 2; |
|
400 | + } |
|
377 | 401 | |
378 | 402 | // Minimum age of messages. Default to zero (don't set param in that case). |
379 | - if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) |
|
380 | - $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
403 | + if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) { |
|
404 | + $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
405 | + } |
|
381 | 406 | |
382 | 407 | // Maximum age of messages. Default to infinite (9999 days: param not set). |
383 | - if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) |
|
384 | - $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
408 | + if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) { |
|
409 | + $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
410 | + } |
|
385 | 411 | |
386 | 412 | // Searching a specific topic? |
387 | 413 | if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic')) |
388 | 414 | { |
389 | 415 | $search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : ''); |
390 | 416 | $search_params['show_complete'] = true; |
417 | + } elseif (!empty($search_params['topic'])) { |
|
418 | + $search_params['topic'] = (int) $search_params['topic']; |
|
391 | 419 | } |
392 | - elseif (!empty($search_params['topic'])) |
|
393 | - $search_params['topic'] = (int) $search_params['topic']; |
|
394 | 420 | |
395 | 421 | if (!empty($search_params['minage']) || !empty($search_params['maxage'])) |
396 | 422 | { |
@@ -408,19 +434,21 @@ discard block |
||
408 | 434 | ) |
409 | 435 | ); |
410 | 436 | list ($minMsgID, $maxMsgID) = $smcFunc['db_fetch_row']($request); |
411 | - if ($minMsgID < 0 || $maxMsgID < 0) |
|
412 | - $context['search_errors']['no_messages_in_time_frame'] = true; |
|
437 | + if ($minMsgID < 0 || $maxMsgID < 0) { |
|
438 | + $context['search_errors']['no_messages_in_time_frame'] = true; |
|
439 | + } |
|
413 | 440 | $smcFunc['db_free_result']($request); |
414 | 441 | } |
415 | 442 | |
416 | 443 | // Default the user name to a wildcard matching every user (*). |
417 | - if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) |
|
418 | - $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
444 | + if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) { |
|
445 | + $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
446 | + } |
|
419 | 447 | |
420 | 448 | // If there's no specific user, then don't mention it in the main query. |
421 | - if (empty($search_params['userspec'])) |
|
422 | - $userQuery = ''; |
|
423 | - else |
|
449 | + if (empty($search_params['userspec'])) { |
|
450 | + $userQuery = ''; |
|
451 | + } else |
|
424 | 452 | { |
425 | 453 | $userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('"' => '"')); |
426 | 454 | $userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); |
@@ -432,19 +460,21 @@ discard block |
||
432 | 460 | { |
433 | 461 | $possible_users[$k] = trim($possible_users[$k]); |
434 | 462 | |
435 | - if (strlen($possible_users[$k]) == 0) |
|
436 | - unset($possible_users[$k]); |
|
463 | + if (strlen($possible_users[$k]) == 0) { |
|
464 | + unset($possible_users[$k]); |
|
465 | + } |
|
437 | 466 | } |
438 | 467 | |
439 | 468 | // Create a list of database-escaped search names. |
440 | 469 | $realNameMatches = array(); |
441 | - foreach ($possible_users as $possible_user) |
|
442 | - $realNameMatches[] = $smcFunc['db_quote']( |
|
470 | + foreach ($possible_users as $possible_user) { |
|
471 | + $realNameMatches[] = $smcFunc['db_quote']( |
|
443 | 472 | '{string:possible_user}', |
444 | 473 | array( |
445 | 474 | 'possible_user' => $possible_user |
446 | 475 | ) |
447 | 476 | ); |
477 | + } |
|
448 | 478 | |
449 | 479 | // Retrieve a list of possible members. |
450 | 480 | $request = $smcFunc['db_query']('', ' |
@@ -456,9 +486,9 @@ discard block |
||
456 | 486 | ) |
457 | 487 | ); |
458 | 488 | // Simply do nothing if there're too many members matching the criteria. |
459 | - if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) |
|
460 | - $userQuery = ''; |
|
461 | - elseif ($smcFunc['db_num_rows']($request) == 0) |
|
489 | + if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) { |
|
490 | + $userQuery = ''; |
|
491 | + } elseif ($smcFunc['db_num_rows']($request) == 0) |
|
462 | 492 | { |
463 | 493 | $userQuery = $smcFunc['db_quote']( |
464 | 494 | 'm.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})', |
@@ -467,12 +497,12 @@ discard block |
||
467 | 497 | 'match_possible_guest_names' => 'm.poster_name LIKE ' . implode(' OR m.poster_name LIKE ', $realNameMatches), |
468 | 498 | ) |
469 | 499 | ); |
470 | - } |
|
471 | - else |
|
500 | + } else |
|
472 | 501 | { |
473 | 502 | $memberlist = array(); |
474 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
475 | - $memberlist[] = $row['id_member']; |
|
503 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
504 | + $memberlist[] = $row['id_member']; |
|
505 | + } |
|
476 | 506 | $userQuery = $smcFunc['db_quote']( |
477 | 507 | '(m.id_member IN ({array_int:matched_members}) OR (m.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})))', |
478 | 508 | array( |
@@ -486,22 +516,25 @@ discard block |
||
486 | 516 | } |
487 | 517 | |
488 | 518 | // If the boards were passed by URL (params=), temporarily put them back in $_REQUEST. |
489 | - if (!empty($search_params['brd']) && is_array($search_params['brd'])) |
|
490 | - $_REQUEST['brd'] = $search_params['brd']; |
|
519 | + if (!empty($search_params['brd']) && is_array($search_params['brd'])) { |
|
520 | + $_REQUEST['brd'] = $search_params['brd']; |
|
521 | + } |
|
491 | 522 | |
492 | 523 | // Ensure that brd is an array. |
493 | 524 | if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board')) |
494 | 525 | { |
495 | - if (!empty($_REQUEST['brd'])) |
|
496 | - $_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']); |
|
497 | - else |
|
498 | - $_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array(); |
|
526 | + if (!empty($_REQUEST['brd'])) { |
|
527 | + $_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']); |
|
528 | + } else { |
|
529 | + $_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array(); |
|
530 | + } |
|
499 | 531 | } |
500 | 532 | |
501 | 533 | // Make sure all boards are integers. |
502 | - if (!empty($_REQUEST['brd'])) |
|
503 | - foreach ($_REQUEST['brd'] as $id => $brd) |
|
534 | + if (!empty($_REQUEST['brd'])) { |
|
535 | + foreach ($_REQUEST['brd'] as $id => $brd) |
|
504 | 536 | $_REQUEST['brd'][$id] = (int) $brd; |
537 | + } |
|
505 | 538 | |
506 | 539 | // Special case for boards: searching just one topic? |
507 | 540 | if (!empty($search_params['topic'])) |
@@ -520,17 +553,18 @@ discard block |
||
520 | 553 | ) |
521 | 554 | ); |
522 | 555 | |
523 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
524 | - fatal_lang_error('topic_gone', false); |
|
556 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
557 | + fatal_lang_error('topic_gone', false); |
|
558 | + } |
|
525 | 559 | |
526 | 560 | $search_params['brd'] = array(); |
527 | 561 | list ($search_params['brd'][0]) = $smcFunc['db_fetch_row']($request); |
528 | 562 | $smcFunc['db_free_result']($request); |
529 | 563 | } |
530 | 564 | // Select all boards you've selected AND are allowed to see. |
531 | - elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) |
|
532 | - $search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd']; |
|
533 | - else |
|
565 | + elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) { |
|
566 | + $search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd']; |
|
567 | + } else |
|
534 | 568 | { |
535 | 569 | $see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board'; |
536 | 570 | $request = $smcFunc['db_query']('', ' |
@@ -548,19 +582,22 @@ discard block |
||
548 | 582 | ) |
549 | 583 | ); |
550 | 584 | $search_params['brd'] = array(); |
551 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
552 | - $search_params['brd'][] = $row['id_board']; |
|
585 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
586 | + $search_params['brd'][] = $row['id_board']; |
|
587 | + } |
|
553 | 588 | $smcFunc['db_free_result']($request); |
554 | 589 | |
555 | 590 | // This error should pro'bly only happen for hackers. |
556 | - if (empty($search_params['brd'])) |
|
557 | - $context['search_errors']['no_boards_selected'] = true; |
|
591 | + if (empty($search_params['brd'])) { |
|
592 | + $context['search_errors']['no_boards_selected'] = true; |
|
593 | + } |
|
558 | 594 | } |
559 | 595 | |
560 | 596 | if (count($search_params['brd']) != 0) |
561 | 597 | { |
562 | - foreach ($search_params['brd'] as $k => $v) |
|
563 | - $search_params['brd'][$k] = (int) $v; |
|
598 | + foreach ($search_params['brd'] as $k => $v) { |
|
599 | + $search_params['brd'][$k] = (int) $v; |
|
600 | + } |
|
564 | 601 | |
565 | 602 | // If we've selected all boards, this parameter can be left empty. |
566 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -574,15 +611,16 @@ discard block |
||
574 | 611 | list ($num_boards) = $smcFunc['db_fetch_row']($request); |
575 | 612 | $smcFunc['db_free_result']($request); |
576 | 613 | |
577 | - if (count($search_params['brd']) == $num_boards) |
|
614 | + if (count($search_params['brd']) == $num_boards) { |
|
615 | + $boardQuery = ''; |
|
616 | + } elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) { |
|
617 | + $boardQuery = '!= ' . $modSettings['recycle_board']; |
|
618 | + } else { |
|
619 | + $boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')'; |
|
620 | + } |
|
621 | + } else { |
|
578 | 622 | $boardQuery = ''; |
579 | - elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) |
|
580 | - $boardQuery = '!= ' . $modSettings['recycle_board']; |
|
581 | - else |
|
582 | - $boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')'; |
|
583 | 623 | } |
584 | - else |
|
585 | - $boardQuery = ''; |
|
586 | 624 | |
587 | 625 | $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']); |
588 | 626 | $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']); |
@@ -596,11 +634,13 @@ discard block |
||
596 | 634 | 'id_msg', |
597 | 635 | ); |
598 | 636 | call_integration_hook('integrate_search_sort_columns', array(&$sort_columns)); |
599 | - if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) |
|
600 | - list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
637 | + if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) { |
|
638 | + list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
639 | + } |
|
601 | 640 | $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'relevance'; |
602 | - if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') |
|
603 | - $search_params['sort'] = 'id_msg'; |
|
641 | + if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') { |
|
642 | + $search_params['sort'] = 'id_msg'; |
|
643 | + } |
|
604 | 644 | |
605 | 645 | // Sorting direction: descending unless stated otherwise. |
606 | 646 | $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc'; |
@@ -624,17 +664,19 @@ discard block |
||
624 | 664 | // What are we searching for? |
625 | 665 | if (empty($search_params['search'])) |
626 | 666 | { |
627 | - if (isset($_GET['search'])) |
|
628 | - $search_params['search'] = un_htmlspecialchars($_GET['search']); |
|
629 | - elseif (isset($_POST['search'])) |
|
630 | - $search_params['search'] = $_POST['search']; |
|
631 | - else |
|
632 | - $search_params['search'] = ''; |
|
667 | + if (isset($_GET['search'])) { |
|
668 | + $search_params['search'] = un_htmlspecialchars($_GET['search']); |
|
669 | + } elseif (isset($_POST['search'])) { |
|
670 | + $search_params['search'] = $_POST['search']; |
|
671 | + } else { |
|
672 | + $search_params['search'] = ''; |
|
673 | + } |
|
633 | 674 | } |
634 | 675 | |
635 | 676 | // Nothing?? |
636 | - if (!isset($search_params['search']) || $search_params['search'] == '') |
|
637 | - $context['search_errors']['invalid_search_string'] = true; |
|
677 | + if (!isset($search_params['search']) || $search_params['search'] == '') { |
|
678 | + $context['search_errors']['invalid_search_string'] = true; |
|
679 | + } |
|
638 | 680 | // Too long? |
639 | 681 | elseif ($smcFunc['strlen']($search_params['search']) > $context['search_string_limit']) |
640 | 682 | { |
@@ -648,8 +690,9 @@ discard block |
||
648 | 690 | $stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query)); |
649 | 691 | |
650 | 692 | // This (hidden) setting will do fulltext searching in the most basic way. |
651 | - if (!empty($modSettings['search_simple_fulltext'])) |
|
652 | - $stripped_query = strtr($stripped_query, array('"' => '')); |
|
693 | + if (!empty($modSettings['search_simple_fulltext'])) { |
|
694 | + $stripped_query = strtr($stripped_query, array('"' => '')); |
|
695 | + } |
|
653 | 696 | |
654 | 697 | $no_regexp = preg_match('~&#(?:\d{1,7}|x[0-9a-fA-F]{1,6});~', $stripped_query) === 1; |
655 | 698 | |
@@ -672,8 +715,9 @@ discard block |
||
672 | 715 | { |
673 | 716 | if ($word === '-') |
674 | 717 | { |
675 | - if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) |
|
676 | - $excludedWords[] = $word; |
|
718 | + if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { |
|
719 | + $excludedWords[] = $word; |
|
720 | + } |
|
677 | 721 | unset($phraseArray[$index]); |
678 | 722 | } |
679 | 723 | } |
@@ -683,8 +727,9 @@ discard block |
||
683 | 727 | { |
684 | 728 | if (strpos(trim($word), '-') === 0) |
685 | 729 | { |
686 | - if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) |
|
687 | - $excludedWords[] = $word; |
|
730 | + if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { |
|
731 | + $excludedWords[] = $word; |
|
732 | + } |
|
688 | 733 | unset($wordArray[$index]); |
689 | 734 | } |
690 | 735 | } |
@@ -697,8 +742,9 @@ discard block |
||
697 | 742 | foreach ($searchArray as $index => $value) |
698 | 743 | { |
699 | 744 | // Skip anything practically empty. |
700 | - if (($searchArray[$index] = trim($value, '-_\' ')) === '') |
|
701 | - unset($searchArray[$index]); |
|
745 | + if (($searchArray[$index] = trim($value, '-_\' ')) === '') { |
|
746 | + unset($searchArray[$index]); |
|
747 | + } |
|
702 | 748 | // Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing. |
703 | 749 | elseif (in_array($searchArray[$index], $blacklisted_words)) |
704 | 750 | { |
@@ -716,31 +762,37 @@ discard block |
||
716 | 762 | |
717 | 763 | // Create an array of replacements for highlighting. |
718 | 764 | $context['mark'] = array(); |
719 | - foreach ($searchArray as $word) |
|
720 | - $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
765 | + foreach ($searchArray as $word) { |
|
766 | + $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
767 | + } |
|
721 | 768 | |
722 | 769 | // Initialize two arrays storing the words that have to be searched for. |
723 | 770 | $orParts = array(); |
724 | 771 | $searchWords = array(); |
725 | 772 | |
726 | 773 | // Make sure at least one word is being searched for. |
727 | - if (empty($searchArray)) |
|
728 | - $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true; |
|
774 | + if (empty($searchArray)) { |
|
775 | + $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true; |
|
776 | + } |
|
729 | 777 | // All words/sentences must match. |
730 | - elseif (empty($search_params['searchtype'])) |
|
731 | - $orParts[0] = $searchArray; |
|
778 | + elseif (empty($search_params['searchtype'])) { |
|
779 | + $orParts[0] = $searchArray; |
|
780 | + } |
|
732 | 781 | // Any word/sentence must match. |
733 | - else |
|
734 | - foreach ($searchArray as $index => $value) |
|
782 | + else { |
|
783 | + foreach ($searchArray as $index => $value) |
|
735 | 784 | $orParts[$index] = array($value); |
785 | + } |
|
736 | 786 | |
737 | 787 | // Don't allow duplicate error messages if one string is too short. |
738 | - if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) |
|
739 | - unset($context['search_errors']['invalid_search_string']); |
|
788 | + if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) { |
|
789 | + unset($context['search_errors']['invalid_search_string']); |
|
790 | + } |
|
740 | 791 | // Make sure the excluded words are in all or-branches. |
741 | - foreach ($orParts as $orIndex => $andParts) |
|
742 | - foreach ($excludedWords as $word) |
|
792 | + foreach ($orParts as $orIndex => $andParts) { |
|
793 | + foreach ($excludedWords as $word) |
|
743 | 794 | $orParts[$orIndex][] = $word; |
795 | + } |
|
744 | 796 | |
745 | 797 | // Determine the or-branches and the fulltext search words. |
746 | 798 | foreach ($orParts as $orIndex => $andParts) |
@@ -754,8 +806,9 @@ discard block |
||
754 | 806 | ); |
755 | 807 | |
756 | 808 | // Sort the indexed words (large words -> small words -> excluded words). |
757 | - if ($searchAPI->supportsMethod('searchSort')) |
|
758 | - usort($orParts[$orIndex], 'searchSort'); |
|
809 | + if ($searchAPI->supportsMethod('searchSort')) { |
|
810 | + usort($orParts[$orIndex], 'searchSort'); |
|
811 | + } |
|
759 | 812 | |
760 | 813 | foreach ($orParts[$orIndex] as $word) |
761 | 814 | { |
@@ -767,15 +820,17 @@ discard block |
||
767 | 820 | if (!$is_excluded || count($subjectWords) === 1) |
768 | 821 | { |
769 | 822 | $searchWords[$orIndex]['subject_words'] = array_merge($searchWords[$orIndex]['subject_words'], $subjectWords); |
770 | - if ($is_excluded) |
|
771 | - $excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords); |
|
823 | + if ($is_excluded) { |
|
824 | + $excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords); |
|
825 | + } |
|
826 | + } else { |
|
827 | + $excludedPhrases[] = $word; |
|
772 | 828 | } |
773 | - else |
|
774 | - $excludedPhrases[] = $word; |
|
775 | 829 | |
776 | 830 | // Have we got indexes to prepare? |
777 | - if ($searchAPI->supportsMethod('prepareIndexes')) |
|
778 | - $searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded); |
|
831 | + if ($searchAPI->supportsMethod('prepareIndexes')) { |
|
832 | + $searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded); |
|
833 | + } |
|
779 | 834 | } |
780 | 835 | |
781 | 836 | // Search_force_index requires all AND parts to have at least one fulltext word. |
@@ -783,8 +838,7 @@ discard block |
||
783 | 838 | { |
784 | 839 | $context['search_errors']['query_not_specific_enough'] = true; |
785 | 840 | break; |
786 | - } |
|
787 | - elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords)) |
|
841 | + } elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords)) |
|
788 | 842 | { |
789 | 843 | $context['search_errors']['query_not_specific_enough'] = true; |
790 | 844 | break; |
@@ -812,8 +866,9 @@ discard block |
||
812 | 866 | $found_misspelling = false; |
813 | 867 | foreach ($searchArray as $word) |
814 | 868 | { |
815 | - if (empty($link)) |
|
816 | - continue; |
|
869 | + if (empty($link)) { |
|
870 | + continue; |
|
871 | + } |
|
817 | 872 | |
818 | 873 | // Don't check phrases. |
819 | 874 | if (preg_match('~^\w+$~', $word) === 0) |
@@ -828,8 +883,7 @@ discard block |
||
828 | 883 | $did_you_mean['search'][] = $word; |
829 | 884 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
830 | 885 | continue; |
831 | - } |
|
832 | - elseif (spell_check($link, $word)) |
|
886 | + } elseif (spell_check($link, $word)) |
|
833 | 887 | { |
834 | 888 | $did_you_mean['search'][] = $word; |
835 | 889 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
@@ -840,11 +894,13 @@ discard block |
||
840 | 894 | foreach ($suggestions as $i => $s) |
841 | 895 | { |
842 | 896 | // Search is case insensitive. |
843 | - if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) |
|
844 | - unset($suggestions[$i]); |
|
897 | + if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) { |
|
898 | + unset($suggestions[$i]); |
|
899 | + } |
|
845 | 900 | // Plus, don't suggest something the user thinks is rude! |
846 | - elseif ($suggestions[$i] != censorText($s)) |
|
847 | - unset($suggestions[$i]); |
|
901 | + elseif ($suggestions[$i] != censorText($s)) { |
|
902 | + unset($suggestions[$i]); |
|
903 | + } |
|
848 | 904 | } |
849 | 905 | |
850 | 906 | // Anything found? If so, correct it! |
@@ -854,8 +910,7 @@ discard block |
||
854 | 910 | $did_you_mean['search'][] = $suggestions[0]; |
855 | 911 | $did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>'; |
856 | 912 | $found_misspelling = true; |
857 | - } |
|
858 | - else |
|
913 | + } else |
|
859 | 914 | { |
860 | 915 | $did_you_mean['search'][] = $word; |
861 | 916 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
@@ -872,8 +927,7 @@ discard block |
||
872 | 927 | { |
873 | 928 | $temp_excluded['search'][] = '-"' . $word . '"'; |
874 | 929 | $temp_excluded['display'][] = '-"' . $smcFunc['htmlspecialchars']($word) . '"'; |
875 | - } |
|
876 | - else |
|
930 | + } else |
|
877 | 931 | { |
878 | 932 | $temp_excluded['search'][] = '-' . $word; |
879 | 933 | $temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word); |
@@ -885,11 +939,13 @@ discard block |
||
885 | 939 | |
886 | 940 | $temp_params = $search_params; |
887 | 941 | $temp_params['search'] = implode(' ', $did_you_mean['search']); |
888 | - if (isset($temp_params['brd'])) |
|
889 | - $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
942 | + if (isset($temp_params['brd'])) { |
|
943 | + $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
944 | + } |
|
890 | 945 | $context['params'] = array(); |
891 | - foreach ($temp_params as $k => $v) |
|
892 | - $context['did_you_mean_params'][] = $k . '|\'|' . $v; |
|
946 | + foreach ($temp_params as $k => $v) { |
|
947 | + $context['did_you_mean_params'][] = $k . '|\'|' . $v; |
|
948 | + } |
|
893 | 949 | $context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params'])); |
894 | 950 | $context['did_you_mean'] = implode(' ', $did_you_mean['display']); |
895 | 951 | } |
@@ -897,18 +953,20 @@ discard block |
||
897 | 953 | |
898 | 954 | // Let the user adjust the search query, should they wish? |
899 | 955 | $context['search_params'] = $search_params; |
900 | - if (isset($context['search_params']['search'])) |
|
901 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
902 | - if (isset($context['search_params']['userspec'])) |
|
903 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
956 | + if (isset($context['search_params']['search'])) { |
|
957 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
958 | + } |
|
959 | + if (isset($context['search_params']['userspec'])) { |
|
960 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
961 | + } |
|
904 | 962 | |
905 | 963 | // Do we have captcha enabled? |
906 | 964 | if ($user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search'])) |
907 | 965 | { |
908 | 966 | // If we come from another search box tone down the error... |
909 | - if (!isset($_REQUEST['search_vv'])) |
|
910 | - $context['search_errors']['need_verification_code'] = true; |
|
911 | - else |
|
967 | + if (!isset($_REQUEST['search_vv'])) { |
|
968 | + $context['search_errors']['need_verification_code'] = true; |
|
969 | + } else |
|
912 | 970 | { |
913 | 971 | require_once($sourcedir . '/Subs-Editor.php'); |
914 | 972 | $verificationOptions = array( |
@@ -918,12 +976,14 @@ discard block |
||
918 | 976 | |
919 | 977 | if (is_array($context['require_verification'])) |
920 | 978 | { |
921 | - foreach ($context['require_verification'] as $error) |
|
922 | - $context['search_errors'][$error] = true; |
|
979 | + foreach ($context['require_verification'] as $error) { |
|
980 | + $context['search_errors'][$error] = true; |
|
981 | + } |
|
923 | 982 | } |
924 | 983 | // Don't keep asking for it - they've proven themselves worthy. |
925 | - else |
|
926 | - $_SESSION['ss_vv_passed'] = true; |
|
984 | + else { |
|
985 | + $_SESSION['ss_vv_passed'] = true; |
|
986 | + } |
|
927 | 987 | } |
928 | 988 | } |
929 | 989 | |
@@ -931,19 +991,22 @@ discard block |
||
931 | 991 | |
932 | 992 | // All search params have been checked, let's compile them to a single string... made less simple by PHP 4.3.9 and below. |
933 | 993 | $temp_params = $search_params; |
934 | - if (isset($temp_params['brd'])) |
|
935 | - $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
994 | + if (isset($temp_params['brd'])) { |
|
995 | + $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
996 | + } |
|
936 | 997 | $context['params'] = array(); |
937 | - foreach ($temp_params as $k => $v) |
|
938 | - $context['params'][] = $k . '|\'|' . $v; |
|
998 | + foreach ($temp_params as $k => $v) { |
|
999 | + $context['params'][] = $k . '|\'|' . $v; |
|
1000 | + } |
|
939 | 1001 | |
940 | 1002 | if (!empty($context['params'])) |
941 | 1003 | { |
942 | 1004 | // Due to old IE's 2083 character limit, we have to compress long search strings |
943 | 1005 | $params = @gzcompress(implode('|"|', $context['params'])); |
944 | 1006 | // Gzcompress failed, use try non-gz |
945 | - if (empty($params)) |
|
946 | - $params = implode('|"|', $context['params']); |
|
1007 | + if (empty($params)) { |
|
1008 | + $params = implode('|"|', $context['params']); |
|
1009 | + } |
|
947 | 1010 | // Base64 encode, then replace +/= with uri safe ones that can be reverted |
948 | 1011 | $context['params'] = str_replace(array('+', '/', '='), array('-', '_', '.'), base64_encode($params)); |
949 | 1012 | } |
@@ -969,8 +1032,9 @@ discard block |
||
969 | 1032 | } |
970 | 1033 | |
971 | 1034 | // Spam me not, Spam-a-lot? |
972 | - if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) |
|
973 | - spamProtection('search'); |
|
1035 | + if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) { |
|
1036 | + spamProtection('search'); |
|
1037 | + } |
|
974 | 1038 | // Store the last search string to allow pages of results to be browsed. |
975 | 1039 | $_SESSION['last_ss'] = $search_params['search']; |
976 | 1040 | |
@@ -1030,8 +1094,9 @@ discard block |
||
1030 | 1094 | 'where' => array(), |
1031 | 1095 | ); |
1032 | 1096 | |
1033 | - if ($modSettings['postmod_active']) |
|
1034 | - $subject_query['where'][] = 't.approved = {int:is_approved}'; |
|
1097 | + if ($modSettings['postmod_active']) { |
|
1098 | + $subject_query['where'][] = 't.approved = {int:is_approved}'; |
|
1099 | + } |
|
1035 | 1100 | |
1036 | 1101 | $numTables = 0; |
1037 | 1102 | $prev_join = 0; |
@@ -1043,8 +1108,7 @@ discard block |
||
1043 | 1108 | { |
1044 | 1109 | $subject_query['left_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}') . ' AND subj' . $numTables . '.id_topic = t.id_topic)'; |
1045 | 1110 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
1046 | - } |
|
1047 | - else |
|
1111 | + } else |
|
1048 | 1112 | { |
1049 | 1113 | $subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)'; |
1050 | 1114 | $subject_query['where'][] = 'subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}'); |
@@ -1062,14 +1126,18 @@ discard block |
||
1062 | 1126 | } |
1063 | 1127 | $subject_query['where'][] = $userQuery; |
1064 | 1128 | } |
1065 | - if (!empty($search_params['topic'])) |
|
1066 | - $subject_query['where'][] = 't.id_topic = ' . $search_params['topic']; |
|
1067 | - if (!empty($minMsgID)) |
|
1068 | - $subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID; |
|
1069 | - if (!empty($maxMsgID)) |
|
1070 | - $subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID; |
|
1071 | - if (!empty($boardQuery)) |
|
1072 | - $subject_query['where'][] = 't.id_board ' . $boardQuery; |
|
1129 | + if (!empty($search_params['topic'])) { |
|
1130 | + $subject_query['where'][] = 't.id_topic = ' . $search_params['topic']; |
|
1131 | + } |
|
1132 | + if (!empty($minMsgID)) { |
|
1133 | + $subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID; |
|
1134 | + } |
|
1135 | + if (!empty($maxMsgID)) { |
|
1136 | + $subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID; |
|
1137 | + } |
|
1138 | + if (!empty($boardQuery)) { |
|
1139 | + $subject_query['where'][] = 't.id_board ' . $boardQuery; |
|
1140 | + } |
|
1073 | 1141 | if (!empty($excludedPhrases)) |
1074 | 1142 | { |
1075 | 1143 | if ($subject_query['from'] != '{db_prefix}messages AS m') |
@@ -1089,8 +1157,9 @@ discard block |
||
1089 | 1157 | foreach ($weight_factors as $type => $value) |
1090 | 1158 | { |
1091 | 1159 | $relevance .= $weight[$type]; |
1092 | - if (!empty($value['results'])) |
|
1093 | - $relevance .= ' * ' . $value['results']; |
|
1160 | + if (!empty($value['results'])) { |
|
1161 | + $relevance .= ' * ' . $value['results']; |
|
1162 | + } |
|
1094 | 1163 | $relevance .= ' + '; |
1095 | 1164 | } |
1096 | 1165 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1128,20 +1197,23 @@ discard block |
||
1128 | 1197 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1129 | 1198 | { |
1130 | 1199 | // No duplicates! |
1131 | - if (isset($inserts[$row[1]])) |
|
1132 | - continue; |
|
1200 | + if (isset($inserts[$row[1]])) { |
|
1201 | + continue; |
|
1202 | + } |
|
1133 | 1203 | |
1134 | - foreach ($row as $key => $value) |
|
1135 | - $inserts[$row[1]][] = (int) $row[$key]; |
|
1204 | + foreach ($row as $key => $value) { |
|
1205 | + $inserts[$row[1]][] = (int) $row[$key]; |
|
1206 | + } |
|
1136 | 1207 | } |
1137 | 1208 | $smcFunc['db_free_result']($ignoreRequest); |
1138 | 1209 | $numSubjectResults = count($inserts); |
1210 | + } else { |
|
1211 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1139 | 1212 | } |
1140 | - else |
|
1141 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1142 | 1213 | |
1143 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
1144 | - break; |
|
1214 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
1215 | + break; |
|
1216 | + } |
|
1145 | 1217 | } |
1146 | 1218 | |
1147 | 1219 | // If there's data to be inserted for non-IGNORE databases do it here! |
@@ -1156,8 +1228,7 @@ discard block |
||
1156 | 1228 | } |
1157 | 1229 | |
1158 | 1230 | $_SESSION['search_cache']['num_results'] = $numSubjectResults; |
1159 | - } |
|
1160 | - else |
|
1231 | + } else |
|
1161 | 1232 | { |
1162 | 1233 | $main_query = array( |
1163 | 1234 | 'select' => array( |
@@ -1189,8 +1260,7 @@ discard block |
||
1189 | 1260 | $main_query['weights'] = $weight_factors; |
1190 | 1261 | |
1191 | 1262 | $main_query['group_by'][] = 't.id_topic'; |
1192 | - } |
|
1193 | - else |
|
1263 | + } else |
|
1194 | 1264 | { |
1195 | 1265 | // This is outrageous! |
1196 | 1266 | $main_query['select']['id_topic'] = 'm.id_msg AS id_topic'; |
@@ -1211,8 +1281,9 @@ discard block |
||
1211 | 1281 | $main_query['where'][] = 't.id_topic = {int:topic}'; |
1212 | 1282 | $main_query['parameters']['topic'] = $search_params['topic']; |
1213 | 1283 | } |
1214 | - if (!empty($search_params['show_complete'])) |
|
1215 | - $main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg'; |
|
1284 | + if (!empty($search_params['show_complete'])) { |
|
1285 | + $main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg'; |
|
1286 | + } |
|
1216 | 1287 | } |
1217 | 1288 | |
1218 | 1289 | // *** Get the subject results. |
@@ -1237,14 +1308,15 @@ discard block |
||
1237 | 1308 | ) !== false; |
1238 | 1309 | |
1239 | 1310 | // Clean up some previous cache. |
1240 | - if (!$createTemporary) |
|
1241 | - $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
1311 | + if (!$createTemporary) { |
|
1312 | + $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
1242 | 1313 | DELETE FROM {db_prefix}log_search_topics |
1243 | 1314 | WHERE id_search = {int:search_id}', |
1244 | 1315 | array( |
1245 | 1316 | 'search_id' => $_SESSION['search_cache']['id_search'], |
1246 | 1317 | ) |
1247 | 1318 | ); |
1319 | + } |
|
1248 | 1320 | |
1249 | 1321 | foreach ($searchWords as $orIndex => $words) |
1250 | 1322 | { |
@@ -1276,8 +1348,7 @@ discard block |
||
1276 | 1348 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
1277 | 1349 | $subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}'; |
1278 | 1350 | $subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]'; |
1279 | - } |
|
1280 | - else |
|
1351 | + } else |
|
1281 | 1352 | { |
1282 | 1353 | $subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)'; |
1283 | 1354 | $subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}'; |
@@ -1332,8 +1403,9 @@ discard block |
||
1332 | 1403 | call_integration_hook('integrate_subject_search_query', array(&$subject_query)); |
1333 | 1404 | |
1334 | 1405 | // Nothing to search for? |
1335 | - if (empty($subject_query['where'])) |
|
1336 | - continue; |
|
1406 | + if (empty($subject_query['where'])) { |
|
1407 | + continue; |
|
1408 | + } |
|
1337 | 1409 | |
1338 | 1410 | $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( ' |
1339 | 1411 | INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics |
@@ -1356,19 +1428,21 @@ discard block |
||
1356 | 1428 | { |
1357 | 1429 | $ind = $createTemporary ? 0 : 1; |
1358 | 1430 | // No duplicates! |
1359 | - if (isset($inserts[$row[$ind]])) |
|
1360 | - continue; |
|
1431 | + if (isset($inserts[$row[$ind]])) { |
|
1432 | + continue; |
|
1433 | + } |
|
1361 | 1434 | |
1362 | 1435 | $inserts[$row[$ind]] = $row; |
1363 | 1436 | } |
1364 | 1437 | $smcFunc['db_free_result']($ignoreRequest); |
1365 | 1438 | $numSubjectResults = count($inserts); |
1439 | + } else { |
|
1440 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1366 | 1441 | } |
1367 | - else |
|
1368 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1369 | 1442 | |
1370 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
1371 | - break; |
|
1443 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
1444 | + break; |
|
1445 | + } |
|
1372 | 1446 | } |
1373 | 1447 | |
1374 | 1448 | // Got some non-MySQL data to plonk in? |
@@ -1386,8 +1460,9 @@ discard block |
||
1386 | 1460 | { |
1387 | 1461 | $main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END'; |
1388 | 1462 | $main_query['left_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics AS lst ON (' . ($createTemporary ? '' : 'lst.id_search = {int:id_search} AND ') . 'lst.id_topic = t.id_topic)'; |
1389 | - if (!$createTemporary) |
|
1390 | - $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
1463 | + if (!$createTemporary) { |
|
1464 | + $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
1465 | + } |
|
1391 | 1466 | } |
1392 | 1467 | } |
1393 | 1468 | |
@@ -1413,14 +1488,15 @@ discard block |
||
1413 | 1488 | ) !== false; |
1414 | 1489 | |
1415 | 1490 | // Clear, all clear! |
1416 | - if (!$createTemporary) |
|
1417 | - $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
1491 | + if (!$createTemporary) { |
|
1492 | + $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
1418 | 1493 | DELETE FROM {db_prefix}log_search_messages |
1419 | 1494 | WHERE id_search = {int:id_search}', |
1420 | 1495 | array( |
1421 | 1496 | 'id_search' => $_SESSION['search_cache']['id_search'], |
1422 | 1497 | ) |
1423 | 1498 | ); |
1499 | + } |
|
1424 | 1500 | |
1425 | 1501 | foreach ($searchWords as $orIndex => $words) |
1426 | 1502 | { |
@@ -1454,19 +1530,21 @@ discard block |
||
1454 | 1530 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1455 | 1531 | { |
1456 | 1532 | // No duplicates! |
1457 | - if (isset($inserts[$row[0]])) |
|
1458 | - continue; |
|
1533 | + if (isset($inserts[$row[0]])) { |
|
1534 | + continue; |
|
1535 | + } |
|
1459 | 1536 | |
1460 | 1537 | $inserts[$row[0]] = $row; |
1461 | 1538 | } |
1462 | 1539 | $smcFunc['db_free_result']($ignoreRequest); |
1463 | 1540 | $indexedResults = count($inserts); |
1541 | + } else { |
|
1542 | + $indexedResults += $smcFunc['db_affected_rows'](); |
|
1464 | 1543 | } |
1465 | - else |
|
1466 | - $indexedResults += $smcFunc['db_affected_rows'](); |
|
1467 | 1544 | |
1468 | - if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) |
|
1469 | - break; |
|
1545 | + if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) { |
|
1546 | + break; |
|
1547 | + } |
|
1470 | 1548 | } |
1471 | 1549 | } |
1472 | 1550 | |
@@ -1486,8 +1564,7 @@ discard block |
||
1486 | 1564 | $context['search_errors']['query_not_specific_enough'] = true; |
1487 | 1565 | $_REQUEST['params'] = $context['params']; |
1488 | 1566 | return PlushSearch1(); |
1489 | - } |
|
1490 | - elseif (!empty($indexedResults)) |
|
1567 | + } elseif (!empty($indexedResults)) |
|
1491 | 1568 | { |
1492 | 1569 | $main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)'; |
1493 | 1570 | if (!$createTemporary) |
@@ -1509,15 +1586,18 @@ discard block |
||
1509 | 1586 | foreach ($words['all_words'] as $regularWord) |
1510 | 1587 | { |
1511 | 1588 | $where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
1512 | - if (in_array($regularWord, $excludedWords)) |
|
1513 | - $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
1589 | + if (in_array($regularWord, $excludedWords)) { |
|
1590 | + $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
1591 | + } |
|
1514 | 1592 | $main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
1515 | 1593 | } |
1516 | - if (!empty($where)) |
|
1517 | - $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
1594 | + if (!empty($where)) { |
|
1595 | + $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
1596 | + } |
|
1597 | + } |
|
1598 | + if (!empty($orWhere)) { |
|
1599 | + $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
1518 | 1600 | } |
1519 | - if (!empty($orWhere)) |
|
1520 | - $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
1521 | 1601 | |
1522 | 1602 | if (!empty($userQuery)) |
1523 | 1603 | { |
@@ -1555,8 +1635,9 @@ discard block |
||
1555 | 1635 | foreach ($main_query['weights'] as $type => $value) |
1556 | 1636 | { |
1557 | 1637 | $relevance .= $weight[$type]; |
1558 | - if (!empty($value['search'])) |
|
1559 | - $relevance .= ' * ' . $value['search']; |
|
1638 | + if (!empty($value['search'])) { |
|
1639 | + $relevance .= ' * ' . $value['search']; |
|
1640 | + } |
|
1560 | 1641 | $relevance .= ' + '; |
1561 | 1642 | $new_weight_total += $weight[$type]; |
1562 | 1643 | } |
@@ -1587,11 +1668,13 @@ discard block |
||
1587 | 1668 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1588 | 1669 | { |
1589 | 1670 | // No duplicates! |
1590 | - if (isset($inserts[$row[2]])) |
|
1591 | - continue; |
|
1671 | + if (isset($inserts[$row[2]])) { |
|
1672 | + continue; |
|
1673 | + } |
|
1592 | 1674 | |
1593 | - foreach ($row as $key => $value) |
|
1594 | - $inserts[$row[2]][] = (int) $row[$key]; |
|
1675 | + foreach ($row as $key => $value) { |
|
1676 | + $inserts[$row[2]][] = (int) $row[$key]; |
|
1677 | + } |
|
1595 | 1678 | } |
1596 | 1679 | $smcFunc['db_free_result']($ignoreRequest); |
1597 | 1680 | |
@@ -1599,8 +1682,9 @@ discard block |
||
1599 | 1682 | if (!empty($inserts)) |
1600 | 1683 | { |
1601 | 1684 | $query_columns = array(); |
1602 | - foreach ($main_query['select'] as $k => $v) |
|
1603 | - $query_columns[$k] = 'int'; |
|
1685 | + foreach ($main_query['select'] as $k => $v) { |
|
1686 | + $query_columns[$k] = 'int'; |
|
1687 | + } |
|
1604 | 1688 | |
1605 | 1689 | $smcFunc['db_insert']('', |
1606 | 1690 | '{db_prefix}log_search_results', |
@@ -1610,21 +1694,23 @@ discard block |
||
1610 | 1694 | ); |
1611 | 1695 | } |
1612 | 1696 | $_SESSION['search_cache']['num_results'] += count($inserts); |
1697 | + } else { |
|
1698 | + $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
1613 | 1699 | } |
1614 | - else |
|
1615 | - $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
1616 | 1700 | } |
1617 | 1701 | |
1618 | 1702 | // Insert subject-only matches. |
1619 | 1703 | if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0) |
1620 | 1704 | { |
1621 | 1705 | $relevance = '1000 * ('; |
1622 | - foreach ($weight_factors as $type => $value) |
|
1623 | - if (isset($value['results'])) |
|
1706 | + foreach ($weight_factors as $type => $value) { |
|
1707 | + if (isset($value['results'])) |
|
1624 | 1708 | { |
1625 | 1709 | $relevance .= $weight[$type]; |
1626 | - if (!empty($value['results'])) |
|
1627 | - $relevance .= ' * ' . $value['results']; |
|
1710 | + } |
|
1711 | + if (!empty($value['results'])) { |
|
1712 | + $relevance .= ' * ' . $value['results']; |
|
1713 | + } |
|
1628 | 1714 | $relevance .= ' + '; |
1629 | 1715 | } |
1630 | 1716 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1658,8 +1744,9 @@ discard block |
||
1658 | 1744 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1659 | 1745 | { |
1660 | 1746 | // No duplicates! |
1661 | - if (isset($usedIDs[$row[1]])) |
|
1662 | - continue; |
|
1747 | + if (isset($usedIDs[$row[1]])) { |
|
1748 | + continue; |
|
1749 | + } |
|
1663 | 1750 | |
1664 | 1751 | $usedIDs[$row[1]] = true; |
1665 | 1752 | $inserts[] = $row; |
@@ -1677,12 +1764,12 @@ discard block |
||
1677 | 1764 | ); |
1678 | 1765 | } |
1679 | 1766 | $_SESSION['search_cache']['num_results'] += count($inserts); |
1767 | + } else { |
|
1768 | + $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
1680 | 1769 | } |
1681 | - else |
|
1682 | - $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
1770 | + } elseif ($_SESSION['search_cache']['num_results'] == -1) { |
|
1771 | + $_SESSION['search_cache']['num_results'] = 0; |
|
1683 | 1772 | } |
1684 | - elseif ($_SESSION['search_cache']['num_results'] == -1) |
|
1685 | - $_SESSION['search_cache']['num_results'] = 0; |
|
1686 | 1773 | } |
1687 | 1774 | } |
1688 | 1775 | |
@@ -1752,14 +1839,16 @@ discard block |
||
1752 | 1839 | ) |
1753 | 1840 | ); |
1754 | 1841 | $posters = array(); |
1755 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1756 | - $posters[] = $row['id_member']; |
|
1842 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1843 | + $posters[] = $row['id_member']; |
|
1844 | + } |
|
1757 | 1845 | $smcFunc['db_free_result']($request); |
1758 | 1846 | |
1759 | 1847 | call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters)); |
1760 | 1848 | |
1761 | - if (!empty($posters)) |
|
1762 | - loadMemberData(array_unique($posters)); |
|
1849 | + if (!empty($posters)) { |
|
1850 | + loadMemberData(array_unique($posters)); |
|
1851 | + } |
|
1763 | 1852 | |
1764 | 1853 | // Get the messages out for the callback - select enough that it can be made to look just like Display. |
1765 | 1854 | $messages_request = $smcFunc['db_query']('', ' |
@@ -1792,8 +1881,9 @@ discard block |
||
1792 | 1881 | ); |
1793 | 1882 | |
1794 | 1883 | // If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore. |
1795 | - if ($smcFunc['db_num_rows']($messages_request) == 0) |
|
1796 | - $context['topics'] = array(); |
|
1884 | + if ($smcFunc['db_num_rows']($messages_request) == 0) { |
|
1885 | + $context['topics'] = array(); |
|
1886 | + } |
|
1797 | 1887 | |
1798 | 1888 | // If we want to know who participated in what then load this now. |
1799 | 1889 | if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) |
@@ -1811,8 +1901,9 @@ discard block |
||
1811 | 1901 | 'limit' => count($participants), |
1812 | 1902 | ) |
1813 | 1903 | ); |
1814 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1815 | - $participants[$row['id_topic']] = true; |
|
1904 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
1905 | + $participants[$row['id_topic']] = true; |
|
1906 | + } |
|
1816 | 1907 | $smcFunc['db_free_result']($result); |
1817 | 1908 | } |
1818 | 1909 | } |
@@ -1821,15 +1912,17 @@ discard block |
||
1821 | 1912 | $context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false); |
1822 | 1913 | |
1823 | 1914 | // Consider the search complete! |
1824 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1825 | - cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
1915 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1916 | + cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
1917 | + } |
|
1826 | 1918 | |
1827 | 1919 | $context['key_words'] = &$searchArray; |
1828 | 1920 | |
1829 | 1921 | // Setup the default topic icons... for checking they exist and the like! |
1830 | 1922 | $context['icon_sources'] = array(); |
1831 | - foreach ($context['stable_icons'] as $icon) |
|
1832 | - $context['icon_sources'][$icon] = 'images_url'; |
|
1923 | + foreach ($context['stable_icons'] as $icon) { |
|
1924 | + $context['icon_sources'][$icon] = 'images_url'; |
|
1925 | + } |
|
1833 | 1926 | |
1834 | 1927 | $context['sub_template'] = 'results'; |
1835 | 1928 | $context['page_title'] = $txt['search_results']; |
@@ -1860,26 +1953,31 @@ discard block |
||
1860 | 1953 | global $boards_can, $participants, $smcFunc; |
1861 | 1954 | static $recycle_board = null; |
1862 | 1955 | |
1863 | - if ($recycle_board === null) |
|
1864 | - $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
1956 | + if ($recycle_board === null) { |
|
1957 | + $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
1958 | + } |
|
1865 | 1959 | |
1866 | 1960 | // Remember which message this is. (ie. reply #83) |
1867 | 1961 | static $counter = null; |
1868 | - if ($counter == null || $reset) |
|
1869 | - $counter = $_REQUEST['start'] + 1; |
|
1962 | + if ($counter == null || $reset) { |
|
1963 | + $counter = $_REQUEST['start'] + 1; |
|
1964 | + } |
|
1870 | 1965 | |
1871 | 1966 | // If the query returned false, bail. |
1872 | - if ($messages_request == false) |
|
1873 | - return false; |
|
1967 | + if ($messages_request == false) { |
|
1968 | + return false; |
|
1969 | + } |
|
1874 | 1970 | |
1875 | 1971 | // Start from the beginning... |
1876 | - if ($reset) |
|
1877 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1972 | + if ($reset) { |
|
1973 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1974 | + } |
|
1878 | 1975 | |
1879 | 1976 | // Attempt to get the next message. |
1880 | 1977 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
1881 | - if (!$message) |
|
1882 | - return false; |
|
1978 | + if (!$message) { |
|
1979 | + return false; |
|
1980 | + } |
|
1883 | 1981 | |
1884 | 1982 | // Can't have an empty subject can we? |
1885 | 1983 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1918,9 +2016,9 @@ discard block |
||
1918 | 2016 | |
1919 | 2017 | if ($smcFunc['strlen']($message['body']) > $charLimit) |
1920 | 2018 | { |
1921 | - if (empty($context['key_words'])) |
|
1922 | - $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
1923 | - else |
|
2019 | + if (empty($context['key_words'])) { |
|
2020 | + $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
2021 | + } else |
|
1924 | 2022 | { |
1925 | 2023 | $matchString = ''; |
1926 | 2024 | $force_partial_word = false; |
@@ -1929,18 +2027,20 @@ discard block |
||
1929 | 2027 | $keyword = un_htmlspecialchars($keyword); |
1930 | 2028 | $keyword = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&'))); |
1931 | 2029 | |
1932 | - if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) |
|
1933 | - $force_partial_word = true; |
|
2030 | + if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) { |
|
2031 | + $force_partial_word = true; |
|
2032 | + } |
|
1934 | 2033 | $matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|'; |
1935 | 2034 | } |
1936 | 2035 | $matchString = un_htmlspecialchars(substr($matchString, 0, -1)); |
1937 | 2036 | |
1938 | 2037 | $message['body'] = un_htmlspecialchars(strtr($message['body'], array(' ' => ' ', '<br>' => "\n", '[' => '[', ']' => ']', ':' => ':', '@' => '@'))); |
1939 | 2038 | |
1940 | - if (empty($modSettings['search_method']) || $force_partial_word) |
|
1941 | - preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
1942 | - else |
|
1943 | - preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
2039 | + if (empty($modSettings['search_method']) || $force_partial_word) { |
|
2040 | + preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
2041 | + } else { |
|
2042 | + preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches); |
|
2043 | + } |
|
1944 | 2044 | |
1945 | 2045 | $message['body'] = ''; |
1946 | 2046 | foreach ($matches[0] as $index => $match) |
@@ -1953,8 +2053,7 @@ discard block |
||
1953 | 2053 | // Re-fix the international characters. |
1954 | 2054 | $message['body'] = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']); |
1955 | 2055 | } |
1956 | - } |
|
1957 | - else |
|
2056 | + } else |
|
1958 | 2057 | { |
1959 | 2058 | // Run BBC interpreter on the message. |
1960 | 2059 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
@@ -1973,21 +2072,26 @@ discard block |
||
1973 | 2072 | // Sadly, we need to check the icon ain't broke. |
1974 | 2073 | if (!empty($modSettings['messageIconChecks_enable'])) |
1975 | 2074 | { |
1976 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
1977 | - $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1978 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
1979 | - $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1980 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1981 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1982 | - } |
|
1983 | - else |
|
2075 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
2076 | + $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2077 | + } |
|
2078 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
2079 | + $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2080 | + } |
|
2081 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
2082 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2083 | + } |
|
2084 | + } else |
|
1984 | 2085 | { |
1985 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
1986 | - $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
1987 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
1988 | - $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
1989 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1990 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
2086 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
2087 | + $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
2088 | + } |
|
2089 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
2090 | + $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
2091 | + } |
|
2092 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
2093 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
2094 | + } |
|
1991 | 2095 | } |
1992 | 2096 | |
1993 | 2097 | // Do we have quote tag enabled? |
@@ -1997,12 +2101,14 @@ discard block |
||
1997 | 2101 | $colorClass = 'windowbg'; |
1998 | 2102 | |
1999 | 2103 | // Sticky topics should get a different color, too. |
2000 | - if ($message['is_sticky']) |
|
2001 | - $colorClass .= ' sticky'; |
|
2104 | + if ($message['is_sticky']) { |
|
2105 | + $colorClass .= ' sticky'; |
|
2106 | + } |
|
2002 | 2107 | |
2003 | 2108 | // Locked topics get special treatment as well. |
2004 | - if ($message['locked']) |
|
2005 | - $colorClass .= ' locked'; |
|
2109 | + if ($message['locked']) { |
|
2110 | + $colorClass .= ' locked'; |
|
2111 | + } |
|
2006 | 2112 | |
2007 | 2113 | $output = array_merge($context['topics'][$message['id_msg']], array( |
2008 | 2114 | 'id' => $message['id_topic'], |
@@ -2096,8 +2202,9 @@ discard block |
||
2096 | 2202 | $query = strtr($smcFunc['htmlspecialchars']($query), array('\\\'' => '\'')); |
2097 | 2203 | |
2098 | 2204 | // Highlighting empty strings would make a terrible mess... |
2099 | - if (strlen($query) == 0) |
|
2100 | - continue; |
|
2205 | + if (strlen($query) == 0) { |
|
2206 | + continue; |
|
2207 | + } |
|
2101 | 2208 | |
2102 | 2209 | $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => ''')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function ($m) |
2103 | 2210 | { |
@@ -2150,8 +2257,9 @@ discard block |
||
2150 | 2257 | |
2151 | 2258 | // Load up the search API we are going to use. |
2152 | 2259 | $modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index']; |
2153 | - if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) |
|
2154 | - fatal_lang_error('search_api_missing'); |
|
2260 | + if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) { |
|
2261 | + fatal_lang_error('search_api_missing'); |
|
2262 | + } |
|
2155 | 2263 | require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'); |
2156 | 2264 | |
2157 | 2265 | // Create an instance of the search API and check it is valid for this version of SMF. |