@@ -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. |
@@ -1239,14 +1310,15 @@ discard block |
||
1239 | 1310 | ) !== false; |
1240 | 1311 | |
1241 | 1312 | // Clean up some previous cache. |
1242 | - if (!$createTemporary) |
|
1243 | - $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
1313 | + if (!$createTemporary) { |
|
1314 | + $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
1244 | 1315 | DELETE FROM {db_prefix}log_search_topics |
1245 | 1316 | WHERE id_search = {int:search_id}', |
1246 | 1317 | array( |
1247 | 1318 | 'search_id' => $_SESSION['search_cache']['id_search'], |
1248 | 1319 | ) |
1249 | 1320 | ); |
1321 | + } |
|
1250 | 1322 | |
1251 | 1323 | foreach ($searchWords as $orIndex => $words) |
1252 | 1324 | { |
@@ -1278,8 +1350,7 @@ discard block |
||
1278 | 1350 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
1279 | 1351 | $subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}'; |
1280 | 1352 | $subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]'; |
1281 | - } |
|
1282 | - else |
|
1353 | + } else |
|
1283 | 1354 | { |
1284 | 1355 | $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)'; |
1285 | 1356 | $subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}'; |
@@ -1334,8 +1405,9 @@ discard block |
||
1334 | 1405 | call_integration_hook('integrate_subject_search_query', array(&$subject_query)); |
1335 | 1406 | |
1336 | 1407 | // Nothing to search for? |
1337 | - if (empty($subject_query['where'])) |
|
1338 | - continue; |
|
1408 | + if (empty($subject_query['where'])) { |
|
1409 | + continue; |
|
1410 | + } |
|
1339 | 1411 | |
1340 | 1412 | $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( ' |
1341 | 1413 | INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics |
@@ -1358,19 +1430,21 @@ discard block |
||
1358 | 1430 | { |
1359 | 1431 | $ind = $createTemporary ? 0 : 1; |
1360 | 1432 | // No duplicates! |
1361 | - if (isset($inserts[$row[$ind]])) |
|
1362 | - continue; |
|
1433 | + if (isset($inserts[$row[$ind]])) { |
|
1434 | + continue; |
|
1435 | + } |
|
1363 | 1436 | |
1364 | 1437 | $inserts[$row[$ind]] = $row; |
1365 | 1438 | } |
1366 | 1439 | $smcFunc['db_free_result']($ignoreRequest); |
1367 | 1440 | $numSubjectResults = count($inserts); |
1441 | + } else { |
|
1442 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1368 | 1443 | } |
1369 | - else |
|
1370 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1371 | 1444 | |
1372 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
1373 | - break; |
|
1445 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
1446 | + break; |
|
1447 | + } |
|
1374 | 1448 | } |
1375 | 1449 | |
1376 | 1450 | // Got some non-MySQL data to plonk in? |
@@ -1388,8 +1462,9 @@ discard block |
||
1388 | 1462 | { |
1389 | 1463 | $main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END'; |
1390 | 1464 | $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)'; |
1391 | - if (!$createTemporary) |
|
1392 | - $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
1465 | + if (!$createTemporary) { |
|
1466 | + $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
1467 | + } |
|
1393 | 1468 | } |
1394 | 1469 | } |
1395 | 1470 | |
@@ -1417,14 +1492,15 @@ discard block |
||
1417 | 1492 | ) !== false; |
1418 | 1493 | |
1419 | 1494 | // Clear, all clear! |
1420 | - if (!$createTemporary) |
|
1421 | - $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
1495 | + if (!$createTemporary) { |
|
1496 | + $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
1422 | 1497 | DELETE FROM {db_prefix}log_search_messages |
1423 | 1498 | WHERE id_search = {int:id_search}', |
1424 | 1499 | array( |
1425 | 1500 | 'id_search' => $_SESSION['search_cache']['id_search'], |
1426 | 1501 | ) |
1427 | 1502 | ); |
1503 | + } |
|
1428 | 1504 | |
1429 | 1505 | foreach ($searchWords as $orIndex => $words) |
1430 | 1506 | { |
@@ -1458,19 +1534,21 @@ discard block |
||
1458 | 1534 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1459 | 1535 | { |
1460 | 1536 | // No duplicates! |
1461 | - if (isset($inserts[$row[0]])) |
|
1462 | - continue; |
|
1537 | + if (isset($inserts[$row[0]])) { |
|
1538 | + continue; |
|
1539 | + } |
|
1463 | 1540 | |
1464 | 1541 | $inserts[$row[0]] = $row; |
1465 | 1542 | } |
1466 | 1543 | $smcFunc['db_free_result']($ignoreRequest); |
1467 | 1544 | $indexedResults = count($inserts); |
1545 | + } else { |
|
1546 | + $indexedResults += $smcFunc['db_affected_rows'](); |
|
1468 | 1547 | } |
1469 | - else |
|
1470 | - $indexedResults += $smcFunc['db_affected_rows'](); |
|
1471 | 1548 | |
1472 | - if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) |
|
1473 | - break; |
|
1549 | + if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) { |
|
1550 | + break; |
|
1551 | + } |
|
1474 | 1552 | } |
1475 | 1553 | } |
1476 | 1554 | |
@@ -1490,8 +1568,7 @@ discard block |
||
1490 | 1568 | $context['search_errors']['query_not_specific_enough'] = true; |
1491 | 1569 | $_REQUEST['params'] = $context['params']; |
1492 | 1570 | return PlushSearch1(); |
1493 | - } |
|
1494 | - elseif (!empty($indexedResults)) |
|
1571 | + } elseif (!empty($indexedResults)) |
|
1495 | 1572 | { |
1496 | 1573 | $main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)'; |
1497 | 1574 | if (!$createTemporary) |
@@ -1513,15 +1590,18 @@ discard block |
||
1513 | 1590 | foreach ($words['all_words'] as $regularWord) |
1514 | 1591 | { |
1515 | 1592 | $where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
1516 | - if (in_array($regularWord, $excludedWords)) |
|
1517 | - $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
1593 | + if (in_array($regularWord, $excludedWords)) { |
|
1594 | + $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
1595 | + } |
|
1518 | 1596 | $main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
1519 | 1597 | } |
1520 | - if (!empty($where)) |
|
1521 | - $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
1598 | + if (!empty($where)) { |
|
1599 | + $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
1600 | + } |
|
1601 | + } |
|
1602 | + if (!empty($orWhere)) { |
|
1603 | + $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
1522 | 1604 | } |
1523 | - if (!empty($orWhere)) |
|
1524 | - $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
1525 | 1605 | |
1526 | 1606 | if (!empty($userQuery)) |
1527 | 1607 | { |
@@ -1559,8 +1639,9 @@ discard block |
||
1559 | 1639 | foreach ($main_query['weights'] as $type => $value) |
1560 | 1640 | { |
1561 | 1641 | $relevance .= $weight[$type]; |
1562 | - if (!empty($value['search'])) |
|
1563 | - $relevance .= ' * ' . $value['search']; |
|
1642 | + if (!empty($value['search'])) { |
|
1643 | + $relevance .= ' * ' . $value['search']; |
|
1644 | + } |
|
1564 | 1645 | $relevance .= ' + '; |
1565 | 1646 | $new_weight_total += $weight[$type]; |
1566 | 1647 | } |
@@ -1591,11 +1672,13 @@ discard block |
||
1591 | 1672 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1592 | 1673 | { |
1593 | 1674 | // No duplicates! |
1594 | - if (isset($inserts[$row[2]])) |
|
1595 | - continue; |
|
1675 | + if (isset($inserts[$row[2]])) { |
|
1676 | + continue; |
|
1677 | + } |
|
1596 | 1678 | |
1597 | - foreach ($row as $key => $value) |
|
1598 | - $inserts[$row[2]][] = (int) $row[$key]; |
|
1679 | + foreach ($row as $key => $value) { |
|
1680 | + $inserts[$row[2]][] = (int) $row[$key]; |
|
1681 | + } |
|
1599 | 1682 | } |
1600 | 1683 | $smcFunc['db_free_result']($ignoreRequest); |
1601 | 1684 | |
@@ -1603,8 +1686,9 @@ discard block |
||
1603 | 1686 | if (!empty($inserts)) |
1604 | 1687 | { |
1605 | 1688 | $query_columns = array(); |
1606 | - foreach ($main_query['select'] as $k => $v) |
|
1607 | - $query_columns[$k] = 'int'; |
|
1689 | + foreach ($main_query['select'] as $k => $v) { |
|
1690 | + $query_columns[$k] = 'int'; |
|
1691 | + } |
|
1608 | 1692 | |
1609 | 1693 | $smcFunc['db_insert']('', |
1610 | 1694 | '{db_prefix}log_search_results', |
@@ -1614,21 +1698,23 @@ discard block |
||
1614 | 1698 | ); |
1615 | 1699 | } |
1616 | 1700 | $_SESSION['search_cache']['num_results'] += count($inserts); |
1701 | + } else { |
|
1702 | + $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
1617 | 1703 | } |
1618 | - else |
|
1619 | - $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
1620 | 1704 | } |
1621 | 1705 | |
1622 | 1706 | // Insert subject-only matches. |
1623 | 1707 | if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0) |
1624 | 1708 | { |
1625 | 1709 | $relevance = '1000 * ('; |
1626 | - foreach ($weight_factors as $type => $value) |
|
1627 | - if (isset($value['results'])) |
|
1710 | + foreach ($weight_factors as $type => $value) { |
|
1711 | + if (isset($value['results'])) |
|
1628 | 1712 | { |
1629 | 1713 | $relevance .= $weight[$type]; |
1630 | - if (!empty($value['results'])) |
|
1631 | - $relevance .= ' * ' . $value['results']; |
|
1714 | + } |
|
1715 | + if (!empty($value['results'])) { |
|
1716 | + $relevance .= ' * ' . $value['results']; |
|
1717 | + } |
|
1632 | 1718 | $relevance .= ' + '; |
1633 | 1719 | } |
1634 | 1720 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1662,8 +1748,9 @@ discard block |
||
1662 | 1748 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1663 | 1749 | { |
1664 | 1750 | // No duplicates! |
1665 | - if (isset($usedIDs[$row[1]])) |
|
1666 | - continue; |
|
1751 | + if (isset($usedIDs[$row[1]])) { |
|
1752 | + continue; |
|
1753 | + } |
|
1667 | 1754 | |
1668 | 1755 | $usedIDs[$row[1]] = true; |
1669 | 1756 | $inserts[] = $row; |
@@ -1681,12 +1768,12 @@ discard block |
||
1681 | 1768 | ); |
1682 | 1769 | } |
1683 | 1770 | $_SESSION['search_cache']['num_results'] += count($inserts); |
1771 | + } else { |
|
1772 | + $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
1684 | 1773 | } |
1685 | - else |
|
1686 | - $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
1774 | + } elseif ($_SESSION['search_cache']['num_results'] == -1) { |
|
1775 | + $_SESSION['search_cache']['num_results'] = 0; |
|
1687 | 1776 | } |
1688 | - elseif ($_SESSION['search_cache']['num_results'] == -1) |
|
1689 | - $_SESSION['search_cache']['num_results'] = 0; |
|
1690 | 1777 | } |
1691 | 1778 | } |
1692 | 1779 | |
@@ -1756,14 +1843,16 @@ discard block |
||
1756 | 1843 | ) |
1757 | 1844 | ); |
1758 | 1845 | $posters = array(); |
1759 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1760 | - $posters[] = $row['id_member']; |
|
1846 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1847 | + $posters[] = $row['id_member']; |
|
1848 | + } |
|
1761 | 1849 | $smcFunc['db_free_result']($request); |
1762 | 1850 | |
1763 | 1851 | call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters)); |
1764 | 1852 | |
1765 | - if (!empty($posters)) |
|
1766 | - loadMemberData(array_unique($posters)); |
|
1853 | + if (!empty($posters)) { |
|
1854 | + loadMemberData(array_unique($posters)); |
|
1855 | + } |
|
1767 | 1856 | |
1768 | 1857 | // Get the messages out for the callback - select enough that it can be made to look just like Display. |
1769 | 1858 | $messages_request = $smcFunc['db_query']('', ' |
@@ -1797,8 +1886,9 @@ discard block |
||
1797 | 1886 | ); |
1798 | 1887 | |
1799 | 1888 | // If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore. |
1800 | - if ($smcFunc['db_num_rows']($messages_request) == 0) |
|
1801 | - $context['topics'] = array(); |
|
1889 | + if ($smcFunc['db_num_rows']($messages_request) == 0) { |
|
1890 | + $context['topics'] = array(); |
|
1891 | + } |
|
1802 | 1892 | |
1803 | 1893 | // If we want to know who participated in what then load this now. |
1804 | 1894 | if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) |
@@ -1816,8 +1906,9 @@ discard block |
||
1816 | 1906 | 'limit' => count($participants), |
1817 | 1907 | ) |
1818 | 1908 | ); |
1819 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1820 | - $participants[$row['id_topic']] = true; |
|
1909 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
1910 | + $participants[$row['id_topic']] = true; |
|
1911 | + } |
|
1821 | 1912 | $smcFunc['db_free_result']($result); |
1822 | 1913 | } |
1823 | 1914 | } |
@@ -1826,15 +1917,17 @@ discard block |
||
1826 | 1917 | $context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false); |
1827 | 1918 | |
1828 | 1919 | // Consider the search complete! |
1829 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1830 | - cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
1920 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1921 | + cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
1922 | + } |
|
1831 | 1923 | |
1832 | 1924 | $context['key_words'] = &$searchArray; |
1833 | 1925 | |
1834 | 1926 | // Setup the default topic icons... for checking they exist and the like! |
1835 | 1927 | $context['icon_sources'] = array(); |
1836 | - foreach ($context['stable_icons'] as $icon) |
|
1837 | - $context['icon_sources'][$icon] = 'images_url'; |
|
1928 | + foreach ($context['stable_icons'] as $icon) { |
|
1929 | + $context['icon_sources'][$icon] = 'images_url'; |
|
1930 | + } |
|
1838 | 1931 | |
1839 | 1932 | $context['sub_template'] = 'results'; |
1840 | 1933 | $context['page_title'] = $txt['search_results']; |
@@ -1865,26 +1958,31 @@ discard block |
||
1865 | 1958 | global $boards_can, $participants, $smcFunc; |
1866 | 1959 | static $recycle_board = null; |
1867 | 1960 | |
1868 | - if ($recycle_board === null) |
|
1869 | - $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
1961 | + if ($recycle_board === null) { |
|
1962 | + $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
1963 | + } |
|
1870 | 1964 | |
1871 | 1965 | // Remember which message this is. (ie. reply #83) |
1872 | 1966 | static $counter = null; |
1873 | - if ($counter == null || $reset) |
|
1874 | - $counter = $_REQUEST['start'] + 1; |
|
1967 | + if ($counter == null || $reset) { |
|
1968 | + $counter = $_REQUEST['start'] + 1; |
|
1969 | + } |
|
1875 | 1970 | |
1876 | 1971 | // If the query returned false, bail. |
1877 | - if ($messages_request == false) |
|
1878 | - return false; |
|
1972 | + if ($messages_request == false) { |
|
1973 | + return false; |
|
1974 | + } |
|
1879 | 1975 | |
1880 | 1976 | // Start from the beginning... |
1881 | - if ($reset) |
|
1882 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1977 | + if ($reset) { |
|
1978 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1979 | + } |
|
1883 | 1980 | |
1884 | 1981 | // Attempt to get the next message. |
1885 | 1982 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
1886 | - if (!$message) |
|
1887 | - return false; |
|
1983 | + if (!$message) { |
|
1984 | + return false; |
|
1985 | + } |
|
1888 | 1986 | |
1889 | 1987 | // Can't have an empty subject can we? |
1890 | 1988 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1923,9 +2021,9 @@ discard block |
||
1923 | 2021 | |
1924 | 2022 | if ($smcFunc['strlen']($message['body']) > $charLimit) |
1925 | 2023 | { |
1926 | - if (empty($context['key_words'])) |
|
1927 | - $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
1928 | - else |
|
2024 | + if (empty($context['key_words'])) { |
|
2025 | + $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
2026 | + } else |
|
1929 | 2027 | { |
1930 | 2028 | $matchString = ''; |
1931 | 2029 | $force_partial_word = false; |
@@ -1934,18 +2032,20 @@ discard block |
||
1934 | 2032 | $keyword = un_htmlspecialchars($keyword); |
1935 | 2033 | $keyword = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&'))); |
1936 | 2034 | |
1937 | - if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) |
|
1938 | - $force_partial_word = true; |
|
2035 | + if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) { |
|
2036 | + $force_partial_word = true; |
|
2037 | + } |
|
1939 | 2038 | $matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|'; |
1940 | 2039 | } |
1941 | 2040 | $matchString = un_htmlspecialchars(substr($matchString, 0, -1)); |
1942 | 2041 | |
1943 | 2042 | $message['body'] = un_htmlspecialchars(strtr($message['body'], array(' ' => ' ', '<br>' => "\n", '[' => '[', ']' => ']', ':' => ':', '@' => '@'))); |
1944 | 2043 | |
1945 | - if (empty($modSettings['search_method']) || $force_partial_word) |
|
1946 | - 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); |
|
1947 | - else |
|
1948 | - 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); |
|
2044 | + if (empty($modSettings['search_method']) || $force_partial_word) { |
|
2045 | + 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); |
|
2046 | + } else { |
|
2047 | + 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); |
|
2048 | + } |
|
1949 | 2049 | |
1950 | 2050 | $message['body'] = ''; |
1951 | 2051 | foreach ($matches[0] as $index => $match) |
@@ -1958,8 +2058,7 @@ discard block |
||
1958 | 2058 | // Re-fix the international characters. |
1959 | 2059 | $message['body'] = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']); |
1960 | 2060 | } |
1961 | - } |
|
1962 | - else |
|
2061 | + } else |
|
1963 | 2062 | { |
1964 | 2063 | // Run BBC interpreter on the message. |
1965 | 2064 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
@@ -1978,21 +2077,26 @@ discard block |
||
1978 | 2077 | // Sadly, we need to check the icon ain't broke. |
1979 | 2078 | if (!empty($modSettings['messageIconChecks_enable'])) |
1980 | 2079 | { |
1981 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
1982 | - $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1983 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
1984 | - $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1985 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1986 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1987 | - } |
|
1988 | - else |
|
2080 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
2081 | + $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2082 | + } |
|
2083 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
2084 | + $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2085 | + } |
|
2086 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
2087 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2088 | + } |
|
2089 | + } else |
|
1989 | 2090 | { |
1990 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
1991 | - $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
1992 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
1993 | - $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
1994 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1995 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
2091 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
2092 | + $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
2093 | + } |
|
2094 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
2095 | + $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
2096 | + } |
|
2097 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
2098 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
2099 | + } |
|
1996 | 2100 | } |
1997 | 2101 | |
1998 | 2102 | // Do we have quote tag enabled? |
@@ -2002,12 +2106,14 @@ discard block |
||
2002 | 2106 | $colorClass = 'windowbg'; |
2003 | 2107 | |
2004 | 2108 | // Sticky topics should get a different color, too. |
2005 | - if ($message['is_sticky']) |
|
2006 | - $colorClass .= ' sticky'; |
|
2109 | + if ($message['is_sticky']) { |
|
2110 | + $colorClass .= ' sticky'; |
|
2111 | + } |
|
2007 | 2112 | |
2008 | 2113 | // Locked topics get special treatment as well. |
2009 | - if ($message['locked']) |
|
2010 | - $colorClass .= ' locked'; |
|
2114 | + if ($message['locked']) { |
|
2115 | + $colorClass .= ' locked'; |
|
2116 | + } |
|
2011 | 2117 | |
2012 | 2118 | $output = array_merge($context['topics'][$message['id_msg']], array( |
2013 | 2119 | 'id' => $message['id_topic'], |
@@ -2151,8 +2257,9 @@ discard block |
||
2151 | 2257 | |
2152 | 2258 | // Load up the search API we are going to use. |
2153 | 2259 | $modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index']; |
2154 | - if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) |
|
2155 | - 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 | + } |
|
2156 | 2263 | require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'); |
2157 | 2264 | |
2158 | 2265 | // Create an instance of the search API and check it is valid for this version of SMF. |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | 'class' => 'centercol', |
394 | 394 | ), |
395 | 395 | 'data' => array( |
396 | - 'function' => function ($rowData) |
|
396 | + 'function' => function($rowData) |
|
397 | 397 | { |
398 | 398 | return $rowData['selected'] ? '<span class="generic_icons valid"></span>' : ''; |
399 | 399 | }, |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | 'class' => 'centercol', |
454 | 454 | ), |
455 | 455 | 'data' => array( |
456 | - 'function' => function ($rowData) |
|
456 | + 'function' => function($rowData) |
|
457 | 457 | { |
458 | 458 | return $rowData['selected'] ? '' : sprintf('<input type="checkbox" name="smiley_set[%1$d]">', $rowData['id']); |
459 | 459 | }, |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | 'value' => $txt['smileys_location'], |
998 | 998 | ), |
999 | 999 | 'data' => array( |
1000 | - 'function' => function ($rowData) use ($txt) |
|
1000 | + 'function' => function($rowData) use ($txt) |
|
1001 | 1001 | { |
1002 | 1002 | if (empty($rowData['hidden'])) |
1003 | 1003 | return $txt['smileys_location_form']; |
@@ -1008,7 +1008,7 @@ discard block |
||
1008 | 1008 | }, |
1009 | 1009 | ), |
1010 | 1010 | 'sort' => array( |
1011 | - 'default' => $smcFunc['db_custom_order']('hidden', array_keys($smiley_locations)) , |
|
1011 | + 'default' => $smcFunc['db_custom_order']('hidden', array_keys($smiley_locations)), |
|
1012 | 1012 | 'reverse' => $smcFunc['db_custom_order']('hidden', array_keys($smiley_locations), true), |
1013 | 1013 | ), |
1014 | 1014 | ), |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | 'value' => $txt['smileys_description'], |
1018 | 1018 | ), |
1019 | 1019 | 'data' => array( |
1020 | - 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
|
1020 | + 'function' => function($rowData) use ($context, $txt, $modSettings, $smcFunc) |
|
1021 | 1021 | { |
1022 | 1022 | if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
1023 | 1023 | return $smcFunc['htmlspecialchars']($rowData['description']); |
@@ -1554,7 +1554,7 @@ discard block |
||
1554 | 1554 | 'action' => $smcFunc['htmlspecialchars'](strtr($action['destination'], array($boarddir => '.'))) |
1555 | 1555 | ); |
1556 | 1556 | |
1557 | - $file = $packagesdir . '/temp/' . $base_path . $action['filename']; |
|
1557 | + $file = $packagesdir . '/temp/' . $base_path . $action['filename']; |
|
1558 | 1558 | if (isset($action['filename']) && (!file_exists($file) || !is_writable(dirname($action['destination'])))) |
1559 | 1559 | { |
1560 | 1560 | $context['has_failure'] = true; |
@@ -1599,7 +1599,7 @@ discard block |
||
1599 | 1599 | { |
1600 | 1600 | updateSettings(array( |
1601 | 1601 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . basename($action['action']), |
1602 | - 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count($context['actions']) > 1 ? ' ' . (!empty($action['description']) ? $smcFunc['htmlspecialchars']($action['description']) : basename($action['action'])) : ''), |
|
1602 | + 'smiley_sets_names' => $modSettings['smiley_sets_names'] . "\n" . $smileyInfo['name'] . (count($context['actions']) > 1 ? ' ' . (!empty($action['description']) ? $smcFunc['htmlspecialchars']($action['description']) : basename($action['action'])) : ''), |
|
1603 | 1603 | )); |
1604 | 1604 | } |
1605 | 1605 | |
@@ -1611,7 +1611,7 @@ discard block |
||
1611 | 1611 | '{db_prefix}log_packages', |
1612 | 1612 | array( |
1613 | 1613 | 'filename' => 'string', 'name' => 'string', 'package_id' => 'string', 'version' => 'string', |
1614 | - 'id_member_installed' => 'int', 'member_installed' => 'string','time_installed' => 'int', |
|
1614 | + 'id_member_installed' => 'int', 'member_installed' => 'string', 'time_installed' => 'int', |
|
1615 | 1615 | 'install_state' => 'int', 'failed_steps' => 'string', 'themes_installed' => 'string', |
1616 | 1616 | 'member_removed' => 'int', 'db_changes' => 'string', 'credits' => 'string', |
1617 | 1617 | ), |
@@ -1860,7 +1860,7 @@ discard block |
||
1860 | 1860 | 'columns' => array( |
1861 | 1861 | 'icon' => array( |
1862 | 1862 | 'data' => array( |
1863 | - 'function' => function ($rowData) use ($settings, $smcFunc) |
|
1863 | + 'function' => function($rowData) use ($settings, $smcFunc) |
|
1864 | 1864 | { |
1865 | 1865 | $images_url = $settings[file_exists(sprintf('%1$s/images/post/%2$s.png', $settings['theme_dir'], $rowData['filename'])) ? 'actual_images_url' : 'default_images_url']; |
1866 | 1866 | return sprintf('<img src="%1$s/post/%2$s.png" alt="%3$s">', $images_url, $rowData['filename'], $smcFunc['htmlspecialchars']($rowData['title'])); |
@@ -1894,7 +1894,7 @@ discard block |
||
1894 | 1894 | 'value' => $txt['icons_board'], |
1895 | 1895 | ), |
1896 | 1896 | 'data' => array( |
1897 | - 'function' => function ($rowData) use ($txt) |
|
1897 | + 'function' => function($rowData) use ($txt) |
|
1898 | 1898 | { |
1899 | 1899 | return empty($rowData['board_name']) ? $txt['icons_edit_icons_all_boards'] : $rowData['board_name']; |
1900 | 1900 | }, |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | |
256 | 256 | case 'datetime': |
257 | 257 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
258 | - return 'str_to_date('. |
|
259 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
258 | + return 'str_to_date(' . |
|
259 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
260 | 260 | ',\'%Y-%m-%d %h:%i:%s\')'; |
261 | 261 | else |
262 | 262 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | $old_pos = 0; |
461 | 461 | $pos = -1; |
462 | 462 | // Remove the string escape for better runtime |
463 | - $db_string_1 = str_replace('\\\'','',$db_string); |
|
463 | + $db_string_1 = str_replace('\\\'', '', $db_string); |
|
464 | 464 | while (true) |
465 | 465 | { |
466 | 466 | $pos = strpos($db_string_1, '\'', $pos + 1); |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | { |
843 | 843 | $count = count($insertRows); |
844 | 844 | $ai = 0; |
845 | - for($i = 0; $i < $count; $i++) |
|
845 | + for ($i = 0; $i < $count; $i++) |
|
846 | 846 | { |
847 | 847 | $old_id = $smcFunc['db_insert_id'](); |
848 | 848 | |
@@ -868,13 +868,13 @@ discard block |
||
868 | 868 | $count2 = count($indexed_columns); |
869 | 869 | for ($x = 0; $x < $count2; $x++) |
870 | 870 | { |
871 | - $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
|
871 | + $where_string += key($indexed_columns[$x]) . ' = ' . $insertRows[$i][$x]; |
|
872 | 872 | if (($x + 1) < $count2) |
873 | 873 | $where_string += ' AND '; |
874 | 874 | } |
875 | 875 | |
876 | - $request = $smcFunc['db_query']('',' |
|
877 | - SELECT `'. $keys[0] . '` FROM ' . $table .' |
|
876 | + $request = $smcFunc['db_query']('', ' |
|
877 | + SELECT `'. $keys[0] . '` FROM ' . $table . ' |
|
878 | 878 | WHERE ' . $where_string . ' LIMIT 1', |
879 | 879 | array() |
880 | 880 | ); |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | $return_var = array(); |
904 | 904 | $count = count($insertRows); |
905 | 905 | $start = smf_db_insert_id($table, $keys[0]); |
906 | - for ($i = 0; $i < $count; $i++ ) |
|
906 | + for ($i = 0; $i < $count; $i++) |
|
907 | 907 | $return_var[] = $start + $i; |
908 | 908 | } |
909 | 909 | return $return_var; |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', |
1037 | 1037 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
1038 | 1038 | $error_array[7], $error_array[8]); |
1039 | - mysqli_stmt_execute ($mysql_error_data_prep); |
|
1039 | + mysqli_stmt_execute($mysql_error_data_prep); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | /** |
@@ -1050,7 +1050,7 @@ discard block |
||
1050 | 1050 | */ |
1051 | 1051 | function smf_db_custom_order($field, $array_values, $desc = false) |
1052 | 1052 | { |
1053 | - $return = 'CASE '. $field . ' '; |
|
1053 | + $return = 'CASE ' . $field . ' '; |
|
1054 | 1054 | $count = count($array_values); |
1055 | 1055 | $then = ($desc ? ' THEN -' : ' THEN '); |
1056 | 1056 |
@@ -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 | /** |
20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -33,8 +34,8 @@ discard block |
||
33 | 34 | global $smcFunc; |
34 | 35 | |
35 | 36 | // Map some database specific functions, only do this once. |
36 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
37 | - $smcFunc += array( |
|
37 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
38 | + $smcFunc += array( |
|
38 | 39 | 'db_query' => 'smf_db_query', |
39 | 40 | 'db_quote' => 'smf_db_quote', |
40 | 41 | 'db_fetch_assoc' => 'mysqli_fetch_assoc', |
@@ -63,9 +64,11 @@ discard block |
||
63 | 64 | 'db_error_insert' => 'smf_db_error_insert', |
64 | 65 | 'db_custom_order' => 'smf_db_custom_order', |
65 | 66 | ); |
67 | + } |
|
66 | 68 | |
67 | - if (!empty($db_options['persist'])) |
|
68 | - $db_server = 'p:' . $db_server; |
|
69 | + if (!empty($db_options['persist'])) { |
|
70 | + $db_server = 'p:' . $db_server; |
|
71 | + } |
|
69 | 72 | |
70 | 73 | $connection = mysqli_init(); |
71 | 74 | |
@@ -74,24 +77,27 @@ discard block |
||
74 | 77 | $success = false; |
75 | 78 | |
76 | 79 | if ($connection) { |
77 | - if (!empty($db_options['port'])) |
|
78 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
79 | - else |
|
80 | - $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
80 | + if (!empty($db_options['port'])) { |
|
81 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', $db_options['port'], null, $flags); |
|
82 | + } else { |
|
83 | + $success = mysqli_real_connect($connection, $db_server, $db_user, $db_passwd, '', 0, null, $flags); |
|
84 | + } |
|
81 | 85 | } |
82 | 86 | |
83 | 87 | // Something's wrong, show an error if its fatal (which we assume it is) |
84 | 88 | if ($success === false) |
85 | 89 | { |
86 | - if (!empty($db_options['non_fatal'])) |
|
87 | - return null; |
|
88 | - else |
|
89 | - display_db_error(); |
|
90 | + if (!empty($db_options['non_fatal'])) { |
|
91 | + return null; |
|
92 | + } else { |
|
93 | + display_db_error(); |
|
94 | + } |
|
90 | 95 | } |
91 | 96 | |
92 | 97 | // Select the database, unless told not to |
93 | - if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) |
|
94 | - display_db_error(); |
|
98 | + if (empty($db_options['dont_select_db']) && !@mysqli_select_db($connection, $db_name) && empty($db_options['non_fatal'])) { |
|
99 | + display_db_error(); |
|
100 | + } |
|
95 | 101 | |
96 | 102 | $smcFunc['db_query']('', 'SET SESSION sql_mode = \'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'', |
97 | 103 | array(), |
@@ -167,34 +173,42 @@ discard block |
||
167 | 173 | global $db_callback, $user_info, $db_prefix, $smcFunc; |
168 | 174 | |
169 | 175 | list ($values, $connection) = $db_callback; |
170 | - if (!is_object($connection)) |
|
171 | - display_db_error(); |
|
176 | + if (!is_object($connection)) { |
|
177 | + display_db_error(); |
|
178 | + } |
|
172 | 179 | |
173 | - if ($matches[1] === 'db_prefix') |
|
174 | - return $db_prefix; |
|
180 | + if ($matches[1] === 'db_prefix') { |
|
181 | + return $db_prefix; |
|
182 | + } |
|
175 | 183 | |
176 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
177 | - return $user_info[$matches[1]]; |
|
184 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
185 | + return $user_info[$matches[1]]; |
|
186 | + } |
|
178 | 187 | |
179 | - if ($matches[1] === 'empty') |
|
180 | - return '\'\''; |
|
188 | + if ($matches[1] === 'empty') { |
|
189 | + return '\'\''; |
|
190 | + } |
|
181 | 191 | |
182 | - if (!isset($matches[2])) |
|
183 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
192 | + if (!isset($matches[2])) { |
|
193 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
194 | + } |
|
184 | 195 | |
185 | - if ($matches[1] === 'literal') |
|
186 | - return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
196 | + if ($matches[1] === 'literal') { |
|
197 | + return '\'' . mysqli_real_escape_string($connection, $matches[2]) . '\''; |
|
198 | + } |
|
187 | 199 | |
188 | - if (!isset($values[$matches[2]])) |
|
189 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
200 | + if (!isset($values[$matches[2]])) { |
|
201 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
202 | + } |
|
190 | 203 | |
191 | 204 | $replacement = $values[$matches[2]]; |
192 | 205 | |
193 | 206 | switch ($matches[1]) |
194 | 207 | { |
195 | 208 | case 'int': |
196 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
197 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
209 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
210 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
211 | + } |
|
198 | 212 | return (string) (int) $replacement; |
199 | 213 | break; |
200 | 214 | |
@@ -206,65 +220,73 @@ discard block |
||
206 | 220 | case 'array_int': |
207 | 221 | if (is_array($replacement)) |
208 | 222 | { |
209 | - if (empty($replacement)) |
|
210 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
223 | + if (empty($replacement)) { |
|
224 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
225 | + } |
|
211 | 226 | |
212 | 227 | foreach ($replacement as $key => $value) |
213 | 228 | { |
214 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
215 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
229 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
230 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
231 | + } |
|
216 | 232 | |
217 | 233 | $replacement[$key] = (string) (int) $value; |
218 | 234 | } |
219 | 235 | |
220 | 236 | return implode(', ', $replacement); |
237 | + } else { |
|
238 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
221 | 239 | } |
222 | - else |
|
223 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
224 | 240 | |
225 | 241 | break; |
226 | 242 | |
227 | 243 | case 'array_string': |
228 | 244 | if (is_array($replacement)) |
229 | 245 | { |
230 | - if (empty($replacement)) |
|
231 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
246 | + if (empty($replacement)) { |
|
247 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
248 | + } |
|
232 | 249 | |
233 | - foreach ($replacement as $key => $value) |
|
234 | - $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
250 | + foreach ($replacement as $key => $value) { |
|
251 | + $replacement[$key] = sprintf('\'%1$s\'', mysqli_real_escape_string($connection, $value)); |
|
252 | + } |
|
235 | 253 | |
236 | 254 | return implode(', ', $replacement); |
255 | + } else { |
|
256 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
237 | 257 | } |
238 | - else |
|
239 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
240 | 258 | break; |
241 | 259 | |
242 | 260 | case 'date': |
243 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
244 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
245 | - else |
|
246 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
261 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
262 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]); |
|
263 | + } else { |
|
264 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
265 | + } |
|
247 | 266 | break; |
248 | 267 | |
249 | 268 | case 'time': |
250 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
251 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
252 | - else |
|
253 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
269 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
270 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]); |
|
271 | + } else { |
|
272 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
273 | + } |
|
254 | 274 | break; |
255 | 275 | |
256 | 276 | case 'datetime': |
257 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
258 | - return 'str_to_date('. |
|
277 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
278 | + return 'str_to_date('. |
|
259 | 279 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
260 | 280 | ',\'%Y-%m-%d %h:%i:%s\')'; |
261 | - else |
|
262 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
281 | + } else { |
|
282 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
283 | + } |
|
263 | 284 | break; |
264 | 285 | |
265 | 286 | case 'float': |
266 | - if (!is_numeric($replacement)) |
|
267 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
287 | + if (!is_numeric($replacement)) { |
|
288 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
289 | + } |
|
268 | 290 | return (string) (float) $replacement; |
269 | 291 | break; |
270 | 292 | |
@@ -278,32 +300,37 @@ discard block |
||
278 | 300 | break; |
279 | 301 | |
280 | 302 | case 'inet': |
281 | - if ($replacement == 'null' || $replacement == '') |
|
282 | - return 'null'; |
|
283 | - if (!isValidIP($replacement)) |
|
284 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
303 | + if ($replacement == 'null' || $replacement == '') { |
|
304 | + return 'null'; |
|
305 | + } |
|
306 | + if (!isValidIP($replacement)) { |
|
307 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
308 | + } |
|
285 | 309 | //we don't use the native support of mysql > 5.6.2 |
286 | 310 | return sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($replacement))); |
287 | 311 | |
288 | 312 | case 'array_inet': |
289 | 313 | if (is_array($replacement)) |
290 | 314 | { |
291 | - if (empty($replacement)) |
|
292 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
315 | + if (empty($replacement)) { |
|
316 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
317 | + } |
|
293 | 318 | |
294 | 319 | foreach ($replacement as $key => $value) |
295 | 320 | { |
296 | - if ($replacement == 'null' || $replacement == '') |
|
297 | - $replacement[$key] = 'null'; |
|
298 | - if (!isValidIP($value)) |
|
299 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
321 | + if ($replacement == 'null' || $replacement == '') { |
|
322 | + $replacement[$key] = 'null'; |
|
323 | + } |
|
324 | + if (!isValidIP($value)) { |
|
325 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
326 | + } |
|
300 | 327 | $replacement[$key] = sprintf('unhex(\'%1$s\')', bin2hex(inet_pton($value))); |
301 | 328 | } |
302 | 329 | |
303 | 330 | return implode(', ', $replacement); |
331 | + } else { |
|
332 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
304 | 333 | } |
305 | - else |
|
306 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
307 | 334 | break; |
308 | 335 | |
309 | 336 | default: |
@@ -379,22 +406,25 @@ discard block |
||
379 | 406 | // Are we in SSI mode? If so try that username and password first |
380 | 407 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
381 | 408 | { |
382 | - if (empty($db_persist)) |
|
383 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
384 | - else |
|
385 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
409 | + if (empty($db_persist)) { |
|
410 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
411 | + } else { |
|
412 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
413 | + } |
|
386 | 414 | } |
387 | 415 | // Fall back to the regular username and password if need be |
388 | 416 | if (!$db_connection) |
389 | 417 | { |
390 | - if (empty($db_persist)) |
|
391 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
392 | - else |
|
393 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
418 | + if (empty($db_persist)) { |
|
419 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
420 | + } else { |
|
421 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
422 | + } |
|
394 | 423 | } |
395 | 424 | |
396 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
397 | - $db_connection = false; |
|
425 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
426 | + $db_connection = false; |
|
427 | + } |
|
398 | 428 | |
399 | 429 | $connection = $db_connection; |
400 | 430 | } |
@@ -402,18 +432,20 @@ discard block |
||
402 | 432 | // One more query.... |
403 | 433 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
404 | 434 | |
405 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
406 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
435 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
436 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
437 | + } |
|
407 | 438 | |
408 | 439 | // Use "ORDER BY null" to prevent Mysql doing filesorts for Group By clauses without an Order By |
409 | 440 | if (strpos($db_string, 'GROUP BY') !== false && strpos($db_string, 'ORDER BY') === false && preg_match('~^\s+SELECT~i', $db_string)) |
410 | 441 | { |
411 | 442 | // Add before LIMIT |
412 | - if ($pos = strpos($db_string, 'LIMIT ')) |
|
413 | - $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
414 | - else |
|
415 | - // Append it. |
|
443 | + if ($pos = strpos($db_string, 'LIMIT ')) { |
|
444 | + $db_string = substr($db_string, 0, $pos) . "\t\t\tORDER BY null\n" . substr($db_string, $pos, strlen($db_string)); |
|
445 | + } else { |
|
446 | + // Append it. |
|
416 | 447 | $db_string .= "\n\t\t\tORDER BY null"; |
448 | + } |
|
417 | 449 | } |
418 | 450 | |
419 | 451 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
@@ -435,8 +467,9 @@ discard block |
||
435 | 467 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
436 | 468 | |
437 | 469 | // Initialize $db_cache if not already initialized. |
438 | - if (!isset($db_cache)) |
|
439 | - $db_cache = array(); |
|
470 | + if (!isset($db_cache)) { |
|
471 | + $db_cache = array(); |
|
472 | + } |
|
440 | 473 | |
441 | 474 | if (!empty($_SESSION['debug_redirect'])) |
442 | 475 | { |
@@ -464,17 +497,18 @@ discard block |
||
464 | 497 | while (true) |
465 | 498 | { |
466 | 499 | $pos = strpos($db_string_1, '\'', $pos + 1); |
467 | - if ($pos === false) |
|
468 | - break; |
|
500 | + if ($pos === false) { |
|
501 | + break; |
|
502 | + } |
|
469 | 503 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
470 | 504 | |
471 | 505 | while (true) |
472 | 506 | { |
473 | 507 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
474 | 508 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
475 | - if ($pos1 === false) |
|
476 | - break; |
|
477 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
509 | + if ($pos1 === false) { |
|
510 | + break; |
|
511 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
478 | 512 | { |
479 | 513 | $pos = $pos1; |
480 | 514 | break; |
@@ -490,29 +524,35 @@ discard block |
||
490 | 524 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
491 | 525 | |
492 | 526 | // Comments? We don't use comments in our queries, we leave 'em outside! |
493 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
494 | - $fail = true; |
|
527 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
528 | + $fail = true; |
|
529 | + } |
|
495 | 530 | // Trying to change passwords, slow us down, or something? |
496 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
497 | - $fail = true; |
|
498 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
499 | - $fail = true; |
|
531 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
532 | + $fail = true; |
|
533 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
534 | + $fail = true; |
|
535 | + } |
|
500 | 536 | |
501 | - if (!empty($fail) && function_exists('log_error')) |
|
502 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
537 | + if (!empty($fail) && function_exists('log_error')) { |
|
538 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
539 | + } |
|
503 | 540 | } |
504 | 541 | |
505 | - if (empty($db_unbuffered)) |
|
506 | - $ret = @mysqli_query($connection, $db_string); |
|
507 | - else |
|
508 | - $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
542 | + if (empty($db_unbuffered)) { |
|
543 | + $ret = @mysqli_query($connection, $db_string); |
|
544 | + } else { |
|
545 | + $ret = @mysqli_query($connection, $db_string, MYSQLI_USE_RESULT); |
|
546 | + } |
|
509 | 547 | |
510 | - if ($ret === false && empty($db_values['db_error_skip'])) |
|
511 | - $ret = smf_db_error($db_string, $connection); |
|
548 | + if ($ret === false && empty($db_values['db_error_skip'])) { |
|
549 | + $ret = smf_db_error($db_string, $connection); |
|
550 | + } |
|
512 | 551 | |
513 | 552 | // Debugging. |
514 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
515 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
553 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
554 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
555 | + } |
|
516 | 556 | |
517 | 557 | return $ret; |
518 | 558 | } |
@@ -559,12 +599,13 @@ discard block |
||
559 | 599 | // Decide which connection to use |
560 | 600 | $connection = $connection === null ? $db_connection : $connection; |
561 | 601 | |
562 | - if ($type == 'begin') |
|
563 | - return @mysqli_query($connection, 'BEGIN'); |
|
564 | - elseif ($type == 'rollback') |
|
565 | - return @mysqli_query($connection, 'ROLLBACK'); |
|
566 | - elseif ($type == 'commit') |
|
567 | - return @mysqli_query($connection, 'COMMIT'); |
|
602 | + if ($type == 'begin') { |
|
603 | + return @mysqli_query($connection, 'BEGIN'); |
|
604 | + } elseif ($type == 'rollback') { |
|
605 | + return @mysqli_query($connection, 'ROLLBACK'); |
|
606 | + } elseif ($type == 'commit') { |
|
607 | + return @mysqli_query($connection, 'COMMIT'); |
|
608 | + } |
|
568 | 609 | |
569 | 610 | return false; |
570 | 611 | } |
@@ -604,8 +645,9 @@ discard block |
||
604 | 645 | // 2013: Lost connection to server during query. |
605 | 646 | |
606 | 647 | // Log the error. |
607 | - if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) |
|
608 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
648 | + if ($query_errno != 1213 && $query_errno != 1205 && function_exists('log_error')) { |
|
649 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n$db_string" : ''), 'database', $file, $line); |
|
650 | + } |
|
609 | 651 | |
610 | 652 | // Database error auto fixing ;). |
611 | 653 | if (function_exists('cache_get_data') && (!isset($modSettings['autoFixDatabase']) || $modSettings['autoFixDatabase'] == '1')) |
@@ -614,8 +656,9 @@ discard block |
||
614 | 656 | $old_cache = @$modSettings['cache_enable']; |
615 | 657 | $modSettings['cache_enable'] = '1'; |
616 | 658 | |
617 | - if (($temp = cache_get_data('db_last_error', 600)) !== null) |
|
618 | - $db_last_error = max(@$db_last_error, $temp); |
|
659 | + if (($temp = cache_get_data('db_last_error', 600)) !== null) { |
|
660 | + $db_last_error = max(@$db_last_error, $temp); |
|
661 | + } |
|
619 | 662 | |
620 | 663 | if (@$db_last_error < time() - 3600 * 24 * 3) |
621 | 664 | { |
@@ -631,8 +674,9 @@ discard block |
||
631 | 674 | foreach ($tables as $table) |
632 | 675 | { |
633 | 676 | // Now, it's still theoretically possible this could be an injection. So backtick it! |
634 | - if (trim($table) != '') |
|
635 | - $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
677 | + if (trim($table) != '') { |
|
678 | + $fix_tables[] = '`' . strtr(trim($table), array('`' => '')) . '`'; |
|
679 | + } |
|
636 | 680 | } |
637 | 681 | } |
638 | 682 | |
@@ -641,8 +685,9 @@ discard block |
||
641 | 685 | // Table crashed. Let's try to fix it. |
642 | 686 | elseif ($query_errno == 1016) |
643 | 687 | { |
644 | - if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) |
|
645 | - $fix_tables = array('`' . $match[1] . '`'); |
|
688 | + if (preg_match('~\'([^\.\']+)~', $query_error, $match) != 0) { |
|
689 | + $fix_tables = array('`' . $match[1] . '`'); |
|
690 | + } |
|
646 | 691 | } |
647 | 692 | // Indexes crashed. Should be easy to fix! |
648 | 693 | elseif ($query_errno == 1034 || $query_errno == 1035) |
@@ -661,13 +706,15 @@ discard block |
||
661 | 706 | |
662 | 707 | // Make a note of the REPAIR... |
663 | 708 | cache_put_data('db_last_error', time(), 600); |
664 | - if (($temp = cache_get_data('db_last_error', 600)) === null) |
|
665 | - updateSettingsFile(array('db_last_error' => time())); |
|
709 | + if (($temp = cache_get_data('db_last_error', 600)) === null) { |
|
710 | + updateSettingsFile(array('db_last_error' => time())); |
|
711 | + } |
|
666 | 712 | |
667 | 713 | // Attempt to find and repair the broken table. |
668 | - foreach ($fix_tables as $table) |
|
669 | - $smcFunc['db_query']('', " |
|
714 | + foreach ($fix_tables as $table) { |
|
715 | + $smcFunc['db_query']('', " |
|
670 | 716 | REPAIR TABLE $table", false, false); |
717 | + } |
|
671 | 718 | |
672 | 719 | // And send off an email! |
673 | 720 | sendmail($webmaster_email, $txt['database_error'], $txt['tried_to_repair'], null, 'dberror'); |
@@ -676,11 +723,12 @@ discard block |
||
676 | 723 | |
677 | 724 | // Try the query again...? |
678 | 725 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
679 | - if ($ret !== false) |
|
680 | - return $ret; |
|
726 | + if ($ret !== false) { |
|
727 | + return $ret; |
|
728 | + } |
|
729 | + } else { |
|
730 | + $modSettings['cache_enable'] = $old_cache; |
|
681 | 731 | } |
682 | - else |
|
683 | - $modSettings['cache_enable'] = $old_cache; |
|
684 | 732 | |
685 | 733 | // Check for the "lost connection" or "deadlock found" errors - and try it just one more time. |
686 | 734 | if (in_array($query_errno, array(1205, 1213, 2006, 2013))) |
@@ -690,22 +738,25 @@ discard block |
||
690 | 738 | // Are we in SSI mode? If so try that username and password first |
691 | 739 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
692 | 740 | { |
693 | - if (empty($db_persist)) |
|
694 | - $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
695 | - else |
|
696 | - $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
741 | + if (empty($db_persist)) { |
|
742 | + $db_connection = @mysqli_connect($db_server, $ssi_db_user, $ssi_db_passwd); |
|
743 | + } else { |
|
744 | + $db_connection = @mysqli_connect('p:' . $db_server, $ssi_db_user, $ssi_db_passwd); |
|
745 | + } |
|
697 | 746 | } |
698 | 747 | // Fall back to the regular username and password if need be |
699 | 748 | if (!$db_connection) |
700 | 749 | { |
701 | - if (empty($db_persist)) |
|
702 | - $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
703 | - else |
|
704 | - $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
750 | + if (empty($db_persist)) { |
|
751 | + $db_connection = @mysqli_connect($db_server, $db_user, $db_passwd); |
|
752 | + } else { |
|
753 | + $db_connection = @mysqli_connect('p:' . $db_server, $db_user, $db_passwd); |
|
754 | + } |
|
705 | 755 | } |
706 | 756 | |
707 | - if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) |
|
708 | - $db_connection = false; |
|
757 | + if (!$db_connection || !@mysqli_select_db($db_connection, $db_name)) { |
|
758 | + $db_connection = false; |
|
759 | + } |
|
709 | 760 | } |
710 | 761 | |
711 | 762 | if ($db_connection) |
@@ -716,24 +767,27 @@ discard block |
||
716 | 767 | $ret = $smcFunc['db_query']('', $db_string, false, false); |
717 | 768 | |
718 | 769 | $new_errno = mysqli_errno($db_connection); |
719 | - if ($ret !== false || in_array($new_errno, array(1205, 1213))) |
|
720 | - break; |
|
770 | + if ($ret !== false || in_array($new_errno, array(1205, 1213))) { |
|
771 | + break; |
|
772 | + } |
|
721 | 773 | } |
722 | 774 | |
723 | 775 | // If it failed again, shucks to be you... we're not trying it over and over. |
724 | - if ($ret !== false) |
|
725 | - return $ret; |
|
776 | + if ($ret !== false) { |
|
777 | + return $ret; |
|
778 | + } |
|
726 | 779 | } |
727 | 780 | } |
728 | 781 | // Are they out of space, perhaps? |
729 | 782 | elseif ($query_errno == 1030 && (strpos($query_error, ' -1 ') !== false || strpos($query_error, ' 28 ') !== false || strpos($query_error, ' 12 ') !== false)) |
730 | 783 | { |
731 | - if (!isset($txt)) |
|
732 | - $query_error .= ' - check database storage space.'; |
|
733 | - else |
|
784 | + if (!isset($txt)) { |
|
785 | + $query_error .= ' - check database storage space.'; |
|
786 | + } else |
|
734 | 787 | { |
735 | - if (!isset($txt['mysql_error_space'])) |
|
736 | - loadLanguage('Errors'); |
|
788 | + if (!isset($txt['mysql_error_space'])) { |
|
789 | + loadLanguage('Errors'); |
|
790 | + } |
|
737 | 791 | |
738 | 792 | $query_error .= !isset($txt['mysql_error_space']) ? ' - check database storage space.' : $txt['mysql_error_space']; |
739 | 793 | } |
@@ -741,15 +795,17 @@ discard block |
||
741 | 795 | } |
742 | 796 | |
743 | 797 | // Nothing's defined yet... just die with it. |
744 | - if (empty($context) || empty($txt)) |
|
745 | - die($query_error); |
|
798 | + if (empty($context) || empty($txt)) { |
|
799 | + die($query_error); |
|
800 | + } |
|
746 | 801 | |
747 | 802 | // Show an error message, if possible. |
748 | 803 | $context['error_title'] = $txt['database_error']; |
749 | - if (allowedTo('admin_forum')) |
|
750 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
751 | - else |
|
752 | - $context['error_message'] = $txt['try_again']; |
|
804 | + if (allowedTo('admin_forum')) { |
|
805 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
806 | + } else { |
|
807 | + $context['error_message'] = $txt['try_again']; |
|
808 | + } |
|
753 | 809 | |
754 | 810 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
755 | 811 | { |
@@ -781,8 +837,9 @@ discard block |
||
781 | 837 | $return_var = null; |
782 | 838 | |
783 | 839 | // With nothing to insert, simply return. |
784 | - if (empty($data)) |
|
785 | - return; |
|
840 | + if (empty($data)) { |
|
841 | + return; |
|
842 | + } |
|
786 | 843 | |
787 | 844 | // Replace the prefix holder with the actual prefix. |
788 | 845 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -792,23 +849,26 @@ discard block |
||
792 | 849 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
793 | 850 | { |
794 | 851 | $with_returning = true; |
795 | - if ($returnmode == 2) |
|
796 | - $return_var = array(); |
|
852 | + if ($returnmode == 2) { |
|
853 | + $return_var = array(); |
|
854 | + } |
|
797 | 855 | } |
798 | 856 | |
799 | 857 | // Inserting data as a single row can be done as a single array. |
800 | - if (!is_array($data[array_rand($data)])) |
|
801 | - $data = array($data); |
|
858 | + if (!is_array($data[array_rand($data)])) { |
|
859 | + $data = array($data); |
|
860 | + } |
|
802 | 861 | |
803 | 862 | // Create the mold for a single row insert. |
804 | 863 | $insertData = '('; |
805 | 864 | foreach ($columns as $columnName => $type) |
806 | 865 | { |
807 | 866 | // Are we restricting the length? |
808 | - if (strpos($type, 'string-') !== false) |
|
809 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
810 | - else |
|
811 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
867 | + if (strpos($type, 'string-') !== false) { |
|
868 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
869 | + } else { |
|
870 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
871 | + } |
|
812 | 872 | } |
813 | 873 | $insertData = substr($insertData, 0, -2) . ')'; |
814 | 874 | |
@@ -817,8 +877,9 @@ discard block |
||
817 | 877 | |
818 | 878 | // Here's where the variables are injected to the query. |
819 | 879 | $insertRows = array(); |
820 | - foreach ($data as $dataRow) |
|
821 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
880 | + foreach ($data as $dataRow) { |
|
881 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
882 | + } |
|
822 | 883 | |
823 | 884 | // Determine the method of insertion. |
824 | 885 | $queryTitle = $method == 'replace' ? 'REPLACE' : ($method == 'ignore' ? 'INSERT IGNORE' : 'INSERT'); |
@@ -837,8 +898,7 @@ discard block |
||
837 | 898 | ), |
838 | 899 | $connection |
839 | 900 | ); |
840 | - } |
|
841 | - else //special way for ignore method with returning |
|
901 | + } else //special way for ignore method with returning |
|
842 | 902 | { |
843 | 903 | $count = count($insertRows); |
844 | 904 | $ai = 0; |
@@ -858,19 +918,21 @@ discard block |
||
858 | 918 | ); |
859 | 919 | $new_id = $smcFunc['db_insert_id'](); |
860 | 920 | |
861 | - if ($last_id != $new_id) //the inserted value was new |
|
921 | + if ($last_id != $new_id) { |
|
922 | + //the inserted value was new |
|
862 | 923 | { |
863 | 924 | $ai = $new_id; |
864 | 925 | } |
865 | - else // the inserted value already exists we need to find the pk |
|
926 | + } else // the inserted value already exists we need to find the pk |
|
866 | 927 | { |
867 | 928 | $where_string = ''; |
868 | 929 | $count2 = count($indexed_columns); |
869 | 930 | for ($x = 0; $x < $count2; $x++) |
870 | 931 | { |
871 | 932 | $where_string += key($indexed_columns[$x]) . ' = '. $insertRows[$i][$x]; |
872 | - if (($x + 1) < $count2) |
|
873 | - $where_string += ' AND '; |
|
933 | + if (($x + 1) < $count2) { |
|
934 | + $where_string += ' AND '; |
|
935 | + } |
|
874 | 936 | } |
875 | 937 | |
876 | 938 | $request = $smcFunc['db_query']('',' |
@@ -886,25 +948,27 @@ discard block |
||
886 | 948 | } |
887 | 949 | } |
888 | 950 | |
889 | - if ($returnmode == 1) |
|
890 | - $return_var = $ai; |
|
891 | - else if ($returnmode == 2) |
|
892 | - $return_var[] = $ai; |
|
951 | + if ($returnmode == 1) { |
|
952 | + $return_var = $ai; |
|
953 | + } else if ($returnmode == 2) { |
|
954 | + $return_var[] = $ai; |
|
955 | + } |
|
893 | 956 | } |
894 | 957 | } |
895 | 958 | |
896 | 959 | |
897 | 960 | if ($with_returning) |
898 | 961 | { |
899 | - if ($returnmode == 1 && empty($return_var)) |
|
900 | - $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
901 | - else if ($returnmode == 2 && empty($return_var)) |
|
962 | + if ($returnmode == 1 && empty($return_var)) { |
|
963 | + $return_var = smf_db_insert_id($table, $keys[0]) + count($insertRows) - 1; |
|
964 | + } else if ($returnmode == 2 && empty($return_var)) |
|
902 | 965 | { |
903 | 966 | $return_var = array(); |
904 | 967 | $count = count($insertRows); |
905 | 968 | $start = smf_db_insert_id($table, $keys[0]); |
906 | - for ($i = 0; $i < $count; $i++ ) |
|
907 | - $return_var[] = $start + $i; |
|
969 | + for ($i = 0; $i < $count; $i++ ) { |
|
970 | + $return_var[] = $start + $i; |
|
971 | + } |
|
908 | 972 | } |
909 | 973 | return $return_var; |
910 | 974 | } |
@@ -922,8 +986,9 @@ discard block |
||
922 | 986 | */ |
923 | 987 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
924 | 988 | { |
925 | - if (empty($log_message)) |
|
926 | - $log_message = $error_message; |
|
989 | + if (empty($log_message)) { |
|
990 | + $log_message = $error_message; |
|
991 | + } |
|
927 | 992 | |
928 | 993 | foreach (debug_backtrace() as $step) |
929 | 994 | { |
@@ -942,12 +1007,14 @@ discard block |
||
942 | 1007 | } |
943 | 1008 | |
944 | 1009 | // A special case - we want the file and line numbers for debugging. |
945 | - if ($error_type == 'return') |
|
946 | - return array($file, $line); |
|
1010 | + if ($error_type == 'return') { |
|
1011 | + return array($file, $line); |
|
1012 | + } |
|
947 | 1013 | |
948 | 1014 | // Is always a critical error. |
949 | - if (function_exists('log_error')) |
|
950 | - log_error($log_message, 'critical', $file, $line); |
|
1015 | + if (function_exists('log_error')) { |
|
1016 | + log_error($log_message, 'critical', $file, $line); |
|
1017 | + } |
|
951 | 1018 | |
952 | 1019 | if (function_exists('fatal_error')) |
953 | 1020 | { |
@@ -955,12 +1022,12 @@ discard block |
||
955 | 1022 | |
956 | 1023 | // Cannot continue... |
957 | 1024 | exit; |
1025 | + } elseif ($error_type) { |
|
1026 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
1027 | + } else { |
|
1028 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
1029 | + } |
|
958 | 1030 | } |
959 | - elseif ($error_type) |
|
960 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
961 | - else |
|
962 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
963 | -} |
|
964 | 1031 | |
965 | 1032 | /** |
966 | 1033 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -977,10 +1044,11 @@ discard block |
||
977 | 1044 | '\\' => '\\\\', |
978 | 1045 | ); |
979 | 1046 | |
980 | - if ($translate_human_wildcards) |
|
981 | - $replacements += array( |
|
1047 | + if ($translate_human_wildcards) { |
|
1048 | + $replacements += array( |
|
982 | 1049 | '*' => '%', |
983 | 1050 | ); |
1051 | + } |
|
984 | 1052 | |
985 | 1053 | return strtr($string, $replacements); |
986 | 1054 | } |
@@ -994,8 +1062,9 @@ discard block |
||
994 | 1062 | */ |
995 | 1063 | function smf_is_resource($result) |
996 | 1064 | { |
997 | - if ($result instanceof mysqli_result) |
|
998 | - return true; |
|
1065 | + if ($result instanceof mysqli_result) { |
|
1066 | + return true; |
|
1067 | + } |
|
999 | 1068 | |
1000 | 1069 | return false; |
1001 | 1070 | } |
@@ -1023,16 +1092,18 @@ discard block |
||
1023 | 1092 | global $db_prefix, $db_connection; |
1024 | 1093 | static $mysql_error_data_prep; |
1025 | 1094 | |
1026 | - if (empty($mysql_error_data_prep)) |
|
1027 | - $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1095 | + if (empty($mysql_error_data_prep)) { |
|
1096 | + $mysql_error_data_prep = mysqli_prepare($db_connection, |
|
1028 | 1097 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
1029 | 1098 | VALUES( ?, ?, unhex(?), ?, ?, ?, ?, ?, ?)' |
1030 | 1099 | ); |
1100 | + } |
|
1031 | 1101 | |
1032 | - if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) |
|
1033 | - $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1034 | - else |
|
1035 | - $error_array[2] = null; |
|
1102 | + if (filter_var($error_array[2], FILTER_VALIDATE_IP) !== false) { |
|
1103 | + $error_array[2] = bin2hex(inet_pton($error_array[2])); |
|
1104 | + } else { |
|
1105 | + $error_array[2] = null; |
|
1106 | + } |
|
1036 | 1107 | mysqli_stmt_bind_param($mysql_error_data_prep, 'iissssssi', |
1037 | 1108 | $error_array[0], $error_array[1], $error_array[2], $error_array[3], $error_array[4], $error_array[5], $error_array[6], |
1038 | 1109 | $error_array[7], $error_array[8]); |
@@ -1054,8 +1125,9 @@ discard block |
||
1054 | 1125 | $count = count($array_values); |
1055 | 1126 | $then = ($desc ? ' THEN -' : ' THEN '); |
1056 | 1127 | |
1057 | - for ($i = 0; $i < $count; $i++) |
|
1058 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1128 | + for ($i = 0; $i < $count; $i++) { |
|
1129 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1130 | + } |
|
1059 | 1131 | |
1060 | 1132 | $return .= 'END'; |
1061 | 1133 | return $return; |
@@ -199,22 +199,22 @@ discard block |
||
199 | 199 | |
200 | 200 | case 'date': |
201 | 201 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
202 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
202 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]) . '::date'; |
|
203 | 203 | else |
204 | 204 | smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
205 | 205 | break; |
206 | 206 | |
207 | 207 | case 'time': |
208 | 208 | if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
209 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
209 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]) . '::time'; |
|
210 | 210 | else |
211 | 211 | smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
212 | 212 | break; |
213 | 213 | |
214 | 214 | case 'datetime': |
215 | 215 | if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
216 | - return 'to_timestamp('. |
|
217 | - sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
|
216 | + return 'to_timestamp(' . |
|
217 | + sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5], $datetime_matches[6]) . |
|
218 | 218 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
219 | 219 | else |
220 | 220 | smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | $old_pos = 0; |
425 | 425 | $pos = -1; |
426 | 426 | // Remove the string escape for better runtime |
427 | - $db_string_1 = str_replace('\'\'','',$db_string); |
|
427 | + $db_string_1 = str_replace('\'\'', '', $db_string); |
|
428 | 428 | while (true) |
429 | 429 | { |
430 | 430 | $pos = strpos($db_string_1, '\'', $pos + 1); |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | if (!empty($keys) && (count($keys) > 0) && $returnmode > 0) |
803 | 803 | { |
804 | 804 | // we only take the first key |
805 | - $returning = ' RETURNING '.$keys[0]; |
|
805 | + $returning = ' RETURNING ' . $keys[0]; |
|
806 | 806 | $with_returning = true; |
807 | 807 | } |
808 | 808 | |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | INSERT INTO ' . $table . '("' . implode('", "', $indexed_columns) . '") |
834 | 834 | VALUES |
835 | 835 | ' . implode(', |
836 | - ', $insertRows).$replace.$returning, |
|
836 | + ', $insertRows) . $replace . $returning, |
|
837 | 837 | array( |
838 | 838 | 'security_override' => true, |
839 | 839 | 'db_error_skip' => $method == 'ignore' || $table === $db_prefix . 'log_errors', |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | if ($returnmode === 2) |
847 | 847 | $return_var = array(); |
848 | 848 | |
849 | - while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
849 | + while (($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
|
850 | 850 | { |
851 | 851 | if (is_numeric($row[0])) // try to emulate mysql limitation |
852 | 852 | { |
@@ -1009,7 +1009,7 @@ discard block |
||
1009 | 1009 | */ |
1010 | 1010 | function smf_db_custom_order($field, $array_values, $desc = false) |
1011 | 1011 | { |
1012 | - $return = 'CASE '. $field . ' '; |
|
1012 | + $return = 'CASE ' . $field . ' '; |
|
1013 | 1013 | $count = count($array_values); |
1014 | 1014 | $then = ($desc ? ' THEN -' : ' THEN '); |
1015 | 1015 |
@@ -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 | /** |
20 | 21 | * Maps the implementations in this file (smf_db_function_name) |
@@ -34,8 +35,8 @@ discard block |
||
34 | 35 | global $smcFunc; |
35 | 36 | |
36 | 37 | // Map some database specific functions, only do this once. |
37 | - if (!isset($smcFunc['db_fetch_assoc'])) |
|
38 | - $smcFunc += array( |
|
38 | + if (!isset($smcFunc['db_fetch_assoc'])) { |
|
39 | + $smcFunc += array( |
|
39 | 40 | 'db_query' => 'smf_db_query', |
40 | 41 | 'db_quote' => 'smf_db_quote', |
41 | 42 | 'db_insert' => 'smf_db_insert', |
@@ -64,11 +65,13 @@ discard block |
||
64 | 65 | 'db_error_insert' => 'smf_db_error_insert', |
65 | 66 | 'db_custom_order' => 'smf_db_custom_order', |
66 | 67 | ); |
68 | + } |
|
67 | 69 | |
68 | - if (!empty($db_options['persist'])) |
|
69 | - $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
70 | - else |
|
71 | - $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
70 | + if (!empty($db_options['persist'])) { |
|
71 | + $connection = @pg_pconnect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
72 | + } else { |
|
73 | + $connection = @pg_connect('host=' . $db_server . ' dbname=' . $db_name . ' user=\'' . $db_user . '\' password=\'' . $db_passwd . '\'' . (empty($db_options['port']) ? '' : ' port=\'' . $db_options['port'] . '\'')); |
|
74 | + } |
|
72 | 75 | |
73 | 76 | // Something's wrong, show an error if its fatal (which we assume it is) |
74 | 77 | if (!$connection) |
@@ -76,8 +79,7 @@ discard block |
||
76 | 79 | if (!empty($db_options['non_fatal'])) |
77 | 80 | { |
78 | 81 | return null; |
79 | - } |
|
80 | - else |
|
82 | + } else |
|
81 | 83 | { |
82 | 84 | display_db_error(); |
83 | 85 | } |
@@ -128,31 +130,38 @@ discard block |
||
128 | 130 | |
129 | 131 | list ($values, $connection) = $db_callback; |
130 | 132 | |
131 | - if ($matches[1] === 'db_prefix') |
|
132 | - return $db_prefix; |
|
133 | + if ($matches[1] === 'db_prefix') { |
|
134 | + return $db_prefix; |
|
135 | + } |
|
133 | 136 | |
134 | - if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) |
|
135 | - return $user_info[$matches[1]]; |
|
137 | + if (isset($user_info[$matches[1]]) && strpos($matches[1], 'query_') !== false) { |
|
138 | + return $user_info[$matches[1]]; |
|
139 | + } |
|
136 | 140 | |
137 | - if ($matches[1] === 'empty') |
|
138 | - return '\'\''; |
|
141 | + if ($matches[1] === 'empty') { |
|
142 | + return '\'\''; |
|
143 | + } |
|
139 | 144 | |
140 | - if (!isset($matches[2])) |
|
141 | - smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
145 | + if (!isset($matches[2])) { |
|
146 | + smf_db_error_backtrace('Invalid value inserted or no type specified.', '', E_USER_ERROR, __FILE__, __LINE__); |
|
147 | + } |
|
142 | 148 | |
143 | - if ($matches[1] === 'literal') |
|
144 | - return '\'' . pg_escape_string($matches[2]) . '\''; |
|
149 | + if ($matches[1] === 'literal') { |
|
150 | + return '\'' . pg_escape_string($matches[2]) . '\''; |
|
151 | + } |
|
145 | 152 | |
146 | - if (!isset($values[$matches[2]])) |
|
147 | - smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
153 | + if (!isset($values[$matches[2]])) { |
|
154 | + smf_db_error_backtrace('The database value you\'re trying to insert does not exist: ' . (isset($smcFunc['htmlspecialchars']) ? $smcFunc['htmlspecialchars']($matches[2]) : htmlspecialchars($matches[2])), '', E_USER_ERROR, __FILE__, __LINE__); |
|
155 | + } |
|
148 | 156 | |
149 | 157 | $replacement = $values[$matches[2]]; |
150 | 158 | |
151 | 159 | switch ($matches[1]) |
152 | 160 | { |
153 | 161 | case 'int': |
154 | - if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) |
|
155 | - smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
162 | + if (!is_numeric($replacement) || (string) $replacement !== (string) (int) $replacement) { |
|
163 | + smf_db_error_backtrace('Wrong value type sent to the database. Integer expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
164 | + } |
|
156 | 165 | return (string) (int) $replacement; |
157 | 166 | break; |
158 | 167 | |
@@ -164,65 +173,73 @@ discard block |
||
164 | 173 | case 'array_int': |
165 | 174 | if (is_array($replacement)) |
166 | 175 | { |
167 | - if (empty($replacement)) |
|
168 | - smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
176 | + if (empty($replacement)) { |
|
177 | + smf_db_error_backtrace('Database error, given array of integer values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
178 | + } |
|
169 | 179 | |
170 | 180 | foreach ($replacement as $key => $value) |
171 | 181 | { |
172 | - if (!is_numeric($value) || (string) $value !== (string) (int) $value) |
|
173 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
182 | + if (!is_numeric($value) || (string) $value !== (string) (int) $value) { |
|
183 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
184 | + } |
|
174 | 185 | |
175 | 186 | $replacement[$key] = (string) (int) $value; |
176 | 187 | } |
177 | 188 | |
178 | 189 | return implode(', ', $replacement); |
190 | + } else { |
|
191 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
179 | 192 | } |
180 | - else |
|
181 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of integers expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
182 | 193 | |
183 | 194 | break; |
184 | 195 | |
185 | 196 | case 'array_string': |
186 | 197 | if (is_array($replacement)) |
187 | 198 | { |
188 | - if (empty($replacement)) |
|
189 | - smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
199 | + if (empty($replacement)) { |
|
200 | + smf_db_error_backtrace('Database error, given array of string values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
201 | + } |
|
190 | 202 | |
191 | - foreach ($replacement as $key => $value) |
|
192 | - $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
203 | + foreach ($replacement as $key => $value) { |
|
204 | + $replacement[$key] = sprintf('\'%1$s\'', pg_escape_string($value)); |
|
205 | + } |
|
193 | 206 | |
194 | 207 | return implode(', ', $replacement); |
208 | + } else { |
|
209 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
195 | 210 | } |
196 | - else |
|
197 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of strings expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
198 | 211 | break; |
199 | 212 | |
200 | 213 | case 'date': |
201 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) |
|
202 | - return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
203 | - else |
|
204 | - smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
214 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d)$~', $replacement, $date_matches) === 1) { |
|
215 | + return sprintf('\'%04d-%02d-%02d\'', $date_matches[1], $date_matches[2], $date_matches[3]).'::date'; |
|
216 | + } else { |
|
217 | + smf_db_error_backtrace('Wrong value type sent to the database. Date expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
218 | + } |
|
205 | 219 | break; |
206 | 220 | |
207 | 221 | case 'time': |
208 | - if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) |
|
209 | - return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
210 | - else |
|
211 | - smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
222 | + if (preg_match('~^([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $time_matches) === 1) { |
|
223 | + return sprintf('\'%02d:%02d:%02d\'', $time_matches[1], $time_matches[2], $time_matches[3]).'::time'; |
|
224 | + } else { |
|
225 | + smf_db_error_backtrace('Wrong value type sent to the database. Time expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
226 | + } |
|
212 | 227 | break; |
213 | 228 | |
214 | 229 | case 'datetime': |
215 | - if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) |
|
216 | - return 'to_timestamp('. |
|
230 | + if (preg_match('~^(\d{4})-([0-1]?\d)-([0-3]?\d) ([0-1]?\d|2[0-3]):([0-5]\d):([0-5]\d)$~', $replacement, $datetime_matches) === 1) { |
|
231 | + return 'to_timestamp('. |
|
217 | 232 | sprintf('\'%04d-%02d-%02d %02d:%02d:%02d\'', $datetime_matches[1], $datetime_matches[2], $datetime_matches[3], $datetime_matches[4], $datetime_matches[5] ,$datetime_matches[6]). |
218 | 233 | ',\'YYYY-MM-DD HH24:MI:SS\')'; |
219 | - else |
|
220 | - smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
234 | + } else { |
|
235 | + smf_db_error_backtrace('Wrong value type sent to the database. Datetime expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
236 | + } |
|
221 | 237 | break; |
222 | 238 | |
223 | 239 | case 'float': |
224 | - if (!is_numeric($replacement)) |
|
225 | - smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
240 | + if (!is_numeric($replacement)) { |
|
241 | + smf_db_error_backtrace('Wrong value type sent to the database. Floating point number expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
242 | + } |
|
226 | 243 | return (string) (float) $replacement; |
227 | 244 | break; |
228 | 245 | |
@@ -235,31 +252,36 @@ discard block |
||
235 | 252 | break; |
236 | 253 | |
237 | 254 | case 'inet': |
238 | - if ($replacement == 'null' || $replacement == '') |
|
239 | - return 'null'; |
|
240 | - if (inet_pton($replacement) === false) |
|
241 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
255 | + if ($replacement == 'null' || $replacement == '') { |
|
256 | + return 'null'; |
|
257 | + } |
|
258 | + if (inet_pton($replacement) === false) { |
|
259 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
260 | + } |
|
242 | 261 | return sprintf('\'%1$s\'::inet', pg_escape_string($replacement)); |
243 | 262 | |
244 | 263 | case 'array_inet': |
245 | 264 | if (is_array($replacement)) |
246 | 265 | { |
247 | - if (empty($replacement)) |
|
248 | - smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
266 | + if (empty($replacement)) { |
|
267 | + smf_db_error_backtrace('Database error, given array of IPv4 or IPv6 values is empty. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
268 | + } |
|
249 | 269 | |
250 | 270 | foreach ($replacement as $key => $value) |
251 | 271 | { |
252 | - if ($replacement == 'null' || $replacement == '') |
|
253 | - $replacement[$key] = 'null'; |
|
254 | - if (!isValidIP($value)) |
|
255 | - smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
272 | + if ($replacement == 'null' || $replacement == '') { |
|
273 | + $replacement[$key] = 'null'; |
|
274 | + } |
|
275 | + if (!isValidIP($value)) { |
|
276 | + smf_db_error_backtrace('Wrong value type sent to the database. IPv4 or IPv6 expected.(' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
277 | + } |
|
256 | 278 | $replacement[$key] = sprintf('\'%1$s\'::inet', pg_escape_string($value)); |
257 | 279 | } |
258 | 280 | |
259 | 281 | return implode(', ', $replacement); |
282 | + } else { |
|
283 | + smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
260 | 284 | } |
261 | - else |
|
262 | - smf_db_error_backtrace('Wrong value type sent to the database. Array of IPv4 or IPv6 expected. (' . $matches[2] . ')', '', E_USER_ERROR, __FILE__, __LINE__); |
|
263 | 285 | break; |
264 | 286 | |
265 | 287 | default: |
@@ -350,14 +372,16 @@ discard block |
||
350 | 372 | ), |
351 | 373 | ); |
352 | 374 | |
353 | - if (isset($replacements[$identifier])) |
|
354 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
375 | + if (isset($replacements[$identifier])) { |
|
376 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
377 | + } |
|
355 | 378 | |
356 | 379 | // Limits need to be a little different. |
357 | 380 | $db_string = preg_replace('~\sLIMIT\s(\d+|{int:.+}),\s*(\d+|{int:.+})\s*$~i', 'LIMIT $2 OFFSET $1', $db_string); |
358 | 381 | |
359 | - if (trim($db_string) == '') |
|
360 | - return false; |
|
382 | + if (trim($db_string) == '') { |
|
383 | + return false; |
|
384 | + } |
|
361 | 385 | |
362 | 386 | // Comments that are allowed in a query are preg_removed. |
363 | 387 | static $allowed_comments_from = array( |
@@ -377,8 +401,9 @@ discard block |
||
377 | 401 | $db_count = !isset($db_count) ? 1 : $db_count + 1; |
378 | 402 | $db_replace_result = 0; |
379 | 403 | |
380 | - if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) |
|
381 | - smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
404 | + if (empty($modSettings['disableQueryCheck']) && strpos($db_string, '\'') !== false && empty($db_values['security_override'])) { |
|
405 | + smf_db_error_backtrace('Hacking attempt...', 'Illegal character (\') used in query...', true, __FILE__, __LINE__); |
|
406 | + } |
|
382 | 407 | |
383 | 408 | if (empty($db_values['security_override']) && (!empty($db_values) || strpos($db_string, '{db_prefix}') !== false)) |
384 | 409 | { |
@@ -399,8 +424,9 @@ discard block |
||
399 | 424 | list ($file, $line) = smf_db_error_backtrace('', '', 'return', __FILE__, __LINE__); |
400 | 425 | |
401 | 426 | // Initialize $db_cache if not already initialized. |
402 | - if (!isset($db_cache)) |
|
403 | - $db_cache = array(); |
|
427 | + if (!isset($db_cache)) { |
|
428 | + $db_cache = array(); |
|
429 | + } |
|
404 | 430 | |
405 | 431 | if (!empty($_SESSION['debug_redirect'])) |
406 | 432 | { |
@@ -428,17 +454,18 @@ discard block |
||
428 | 454 | while (true) |
429 | 455 | { |
430 | 456 | $pos = strpos($db_string_1, '\'', $pos + 1); |
431 | - if ($pos === false) |
|
432 | - break; |
|
457 | + if ($pos === false) { |
|
458 | + break; |
|
459 | + } |
|
433 | 460 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
434 | 461 | |
435 | 462 | while (true) |
436 | 463 | { |
437 | 464 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
438 | 465 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
439 | - if ($pos1 === false) |
|
440 | - break; |
|
441 | - elseif ($pos2 === false || $pos2 > $pos1) |
|
466 | + if ($pos1 === false) { |
|
467 | + break; |
|
468 | + } elseif ($pos2 === false || $pos2 > $pos1) |
|
442 | 469 | { |
443 | 470 | $pos = $pos1; |
444 | 471 | break; |
@@ -454,16 +481,19 @@ discard block |
||
454 | 481 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
455 | 482 | |
456 | 483 | // Comments? We don't use comments in our queries, we leave 'em outside! |
457 | - if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
458 | - $fail = true; |
|
484 | + if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) { |
|
485 | + $fail = true; |
|
486 | + } |
|
459 | 487 | // Trying to change passwords, slow us down, or something? |
460 | - elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
461 | - $fail = true; |
|
462 | - elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
463 | - $fail = true; |
|
488 | + elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) { |
|
489 | + $fail = true; |
|
490 | + } elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) { |
|
491 | + $fail = true; |
|
492 | + } |
|
464 | 493 | |
465 | - if (!empty($fail) && function_exists('log_error')) |
|
466 | - smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
494 | + if (!empty($fail) && function_exists('log_error')) { |
|
495 | + smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
496 | + } |
|
467 | 497 | } |
468 | 498 | |
469 | 499 | // Set optimize stuff |
@@ -482,18 +512,21 @@ discard block |
||
482 | 512 | |
483 | 513 | $db_string = $query_hints_set . $db_string; |
484 | 514 | |
485 | - if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') |
|
486 | - $db_cache[$db_count]['q'] = "\t\t" . $db_string; |
|
515 | + if (isset($db_show_debug) && $db_show_debug === true && $db_cache[$db_count]['q'] != '...') { |
|
516 | + $db_cache[$db_count]['q'] = "\t\t" . $db_string; |
|
517 | + } |
|
487 | 518 | } |
488 | 519 | |
489 | 520 | $db_last_result = @pg_query($connection, $db_string); |
490 | 521 | |
491 | - if ($db_last_result === false && empty($db_values['db_error_skip'])) |
|
492 | - $db_last_result = smf_db_error($db_string, $connection); |
|
522 | + if ($db_last_result === false && empty($db_values['db_error_skip'])) { |
|
523 | + $db_last_result = smf_db_error($db_string, $connection); |
|
524 | + } |
|
493 | 525 | |
494 | 526 | // Debugging. |
495 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
496 | - $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
527 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
528 | + $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
529 | + } |
|
497 | 530 | |
498 | 531 | return $db_last_result; |
499 | 532 | } |
@@ -510,10 +543,11 @@ discard block |
||
510 | 543 | { |
511 | 544 | global $db_last_result, $db_replace_result; |
512 | 545 | |
513 | - if ($db_replace_result) |
|
514 | - return $db_replace_result; |
|
515 | - elseif ($result === null && !$db_last_result) |
|
516 | - return 0; |
|
546 | + if ($db_replace_result) { |
|
547 | + return $db_replace_result; |
|
548 | + } elseif ($result === null && !$db_last_result) { |
|
549 | + return 0; |
|
550 | + } |
|
517 | 551 | |
518 | 552 | return pg_affected_rows($result === null ? $db_last_result : $result); |
519 | 553 | } |
@@ -537,8 +571,9 @@ discard block |
||
537 | 571 | array( |
538 | 572 | ) |
539 | 573 | ); |
540 | - if (!$request) |
|
541 | - return false; |
|
574 | + if (!$request) { |
|
575 | + return false; |
|
576 | + } |
|
542 | 577 | list ($lastID) = $smcFunc['db_fetch_row']($request); |
543 | 578 | $smcFunc['db_free_result']($request); |
544 | 579 | |
@@ -559,12 +594,13 @@ discard block |
||
559 | 594 | // Decide which connection to use |
560 | 595 | $connection = $connection === null ? $db_connection : $connection; |
561 | 596 | |
562 | - if ($type == 'begin') |
|
563 | - return @pg_query($connection, 'BEGIN'); |
|
564 | - elseif ($type == 'rollback') |
|
565 | - return @pg_query($connection, 'ROLLBACK'); |
|
566 | - elseif ($type == 'commit') |
|
567 | - return @pg_query($connection, 'COMMIT'); |
|
597 | + if ($type == 'begin') { |
|
598 | + return @pg_query($connection, 'BEGIN'); |
|
599 | + } elseif ($type == 'rollback') { |
|
600 | + return @pg_query($connection, 'ROLLBACK'); |
|
601 | + } elseif ($type == 'commit') { |
|
602 | + return @pg_query($connection, 'COMMIT'); |
|
603 | + } |
|
568 | 604 | |
569 | 605 | return false; |
570 | 606 | } |
@@ -592,19 +628,22 @@ discard block |
||
592 | 628 | $query_error = @pg_last_error($connection); |
593 | 629 | |
594 | 630 | // Log the error. |
595 | - if (function_exists('log_error')) |
|
596 | - log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
631 | + if (function_exists('log_error')) { |
|
632 | + log_error($txt['database_error'] . ': ' . $query_error . (!empty($modSettings['enableErrorQueryLogging']) ? "\n\n" . $db_string : ''), 'database', $file, $line); |
|
633 | + } |
|
597 | 634 | |
598 | 635 | // Nothing's defined yet... just die with it. |
599 | - if (empty($context) || empty($txt)) |
|
600 | - die($query_error); |
|
636 | + if (empty($context) || empty($txt)) { |
|
637 | + die($query_error); |
|
638 | + } |
|
601 | 639 | |
602 | 640 | // Show an error message, if possible. |
603 | 641 | $context['error_title'] = $txt['database_error']; |
604 | - if (allowedTo('admin_forum')) |
|
605 | - $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
606 | - else |
|
607 | - $context['error_message'] = $txt['try_again']; |
|
642 | + if (allowedTo('admin_forum')) { |
|
643 | + $context['error_message'] = nl2br($query_error) . '<br>' . $txt['file'] . ': ' . $file . '<br>' . $txt['line'] . ': ' . $line; |
|
644 | + } else { |
|
645 | + $context['error_message'] = $txt['try_again']; |
|
646 | + } |
|
608 | 647 | |
609 | 648 | if (allowedTo('admin_forum') && isset($db_show_debug) && $db_show_debug === true) |
610 | 649 | { |
@@ -626,12 +665,14 @@ discard block |
||
626 | 665 | { |
627 | 666 | global $db_row_count; |
628 | 667 | |
629 | - if ($counter !== false) |
|
630 | - return pg_fetch_row($request, $counter); |
|
668 | + if ($counter !== false) { |
|
669 | + return pg_fetch_row($request, $counter); |
|
670 | + } |
|
631 | 671 | |
632 | 672 | // Reset the row counter... |
633 | - if (!isset($db_row_count[(int) $request])) |
|
634 | - $db_row_count[(int) $request] = 0; |
|
673 | + if (!isset($db_row_count[(int) $request])) { |
|
674 | + $db_row_count[(int) $request] = 0; |
|
675 | + } |
|
635 | 676 | |
636 | 677 | // Return the right row. |
637 | 678 | return @pg_fetch_row($request, $db_row_count[(int) $request]++); |
@@ -648,12 +689,14 @@ discard block |
||
648 | 689 | { |
649 | 690 | global $db_row_count; |
650 | 691 | |
651 | - if ($counter !== false) |
|
652 | - return pg_fetch_assoc($request, $counter); |
|
692 | + if ($counter !== false) { |
|
693 | + return pg_fetch_assoc($request, $counter); |
|
694 | + } |
|
653 | 695 | |
654 | 696 | // Reset the row counter... |
655 | - if (!isset($db_row_count[(int) $request])) |
|
656 | - $db_row_count[(int) $request] = 0; |
|
697 | + if (!isset($db_row_count[(int) $request])) { |
|
698 | + $db_row_count[(int) $request] = 0; |
|
699 | + } |
|
657 | 700 | |
658 | 701 | // Return the right row. |
659 | 702 | return @pg_fetch_assoc($request, $db_row_count[(int) $request]++); |
@@ -706,11 +749,13 @@ discard block |
||
706 | 749 | |
707 | 750 | $replace = ''; |
708 | 751 | |
709 | - if (empty($data)) |
|
710 | - return; |
|
752 | + if (empty($data)) { |
|
753 | + return; |
|
754 | + } |
|
711 | 755 | |
712 | - if (!is_array($data[array_rand($data)])) |
|
713 | - $data = array($data); |
|
756 | + if (!is_array($data[array_rand($data)])) { |
|
757 | + $data = array($data); |
|
758 | + } |
|
714 | 759 | |
715 | 760 | // Replace the prefix holder with the actual prefix. |
716 | 761 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
@@ -729,11 +774,13 @@ discard block |
||
729 | 774 | //pg 9.5 got replace support |
730 | 775 | $pg_version = $smcFunc['db_get_version'](); |
731 | 776 | // if we got a Beta Version |
732 | - if (stripos($pg_version, 'beta') !== false) |
|
733 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
777 | + if (stripos($pg_version, 'beta') !== false) { |
|
778 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'beta')) . '.0'; |
|
779 | + } |
|
734 | 780 | // or RC |
735 | - if (stripos($pg_version, 'rc') !== false) |
|
736 | - $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
781 | + if (stripos($pg_version, 'rc') !== false) { |
|
782 | + $pg_version = substr($pg_version, 0, stripos($pg_version, 'rc')) . '.0'; |
|
783 | + } |
|
737 | 784 | |
738 | 785 | $replace_support = (version_compare($pg_version, '9.5.0', '>=') ? true : false); |
739 | 786 | } |
@@ -752,32 +799,35 @@ discard block |
||
752 | 799 | $key_str .= ($count_pk > 0 ? ',' : ''); |
753 | 800 | $key_str .= $columnName; |
754 | 801 | $count_pk++; |
755 | - } |
|
756 | - else if ($method == 'replace') //normal field |
|
802 | + } else if ($method == 'replace') { |
|
803 | + //normal field |
|
757 | 804 | { |
758 | 805 | $col_str .= ($count > 0 ? ',' : ''); |
806 | + } |
|
759 | 807 | $col_str .= $columnName . ' = EXCLUDED.' . $columnName; |
760 | 808 | $count++; |
761 | 809 | } |
762 | 810 | } |
763 | - if ($method == 'replace') |
|
764 | - $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
765 | - else |
|
766 | - $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
767 | - } |
|
768 | - else if ($method == 'replace') |
|
811 | + if ($method == 'replace') { |
|
812 | + $replace = ' ON CONFLICT (' . $key_str . ') DO UPDATE SET ' . $col_str; |
|
813 | + } else { |
|
814 | + $replace = ' ON CONFLICT (' . $key_str . ') DO NOTHING'; |
|
815 | + } |
|
816 | + } else if ($method == 'replace') |
|
769 | 817 | { |
770 | 818 | foreach ($columns as $columnName => $type) |
771 | 819 | { |
772 | 820 | // Are we restricting the length? |
773 | - if (strpos($type, 'string-') !== false) |
|
774 | - $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
775 | - else |
|
776 | - $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
821 | + if (strpos($type, 'string-') !== false) { |
|
822 | + $actualType = sprintf($columnName . ' = SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $count); |
|
823 | + } else { |
|
824 | + $actualType = sprintf($columnName . ' = {%1$s:%2$s}, ', $type, $count); |
|
825 | + } |
|
777 | 826 | |
778 | 827 | // A key? That's what we were looking for. |
779 | - if (in_array($columnName, $keys)) |
|
780 | - $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
828 | + if (in_array($columnName, $keys)) { |
|
829 | + $where .= (empty($where) ? '' : ' AND ') . substr($actualType, 0, -2); |
|
830 | + } |
|
781 | 831 | $count++; |
782 | 832 | } |
783 | 833 | |
@@ -813,10 +863,11 @@ discard block |
||
813 | 863 | foreach ($columns as $columnName => $type) |
814 | 864 | { |
815 | 865 | // Are we restricting the length? |
816 | - if (strpos($type, 'string-') !== false) |
|
817 | - $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
818 | - else |
|
819 | - $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
866 | + if (strpos($type, 'string-') !== false) { |
|
867 | + $insertData .= sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . '), ', $columnName); |
|
868 | + } else { |
|
869 | + $insertData .= sprintf('{%1$s:%2$s}, ', $type, $columnName); |
|
870 | + } |
|
820 | 871 | } |
821 | 872 | $insertData = substr($insertData, 0, -2) . ')'; |
822 | 873 | |
@@ -825,8 +876,9 @@ discard block |
||
825 | 876 | |
826 | 877 | // Here's where the variables are injected to the query. |
827 | 878 | $insertRows = array(); |
828 | - foreach ($data as $dataRow) |
|
829 | - $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
879 | + foreach ($data as $dataRow) { |
|
880 | + $insertRows[] = smf_db_quote($insertData, array_combine($indexed_columns, $dataRow), $connection); |
|
881 | + } |
|
830 | 882 | |
831 | 883 | // Do the insert. |
832 | 884 | $request = $smcFunc['db_query']('', ' |
@@ -843,19 +895,21 @@ discard block |
||
843 | 895 | |
844 | 896 | if ($with_returning && $request !== false) |
845 | 897 | { |
846 | - if ($returnmode === 2) |
|
847 | - $return_var = array(); |
|
898 | + if ($returnmode === 2) { |
|
899 | + $return_var = array(); |
|
900 | + } |
|
848 | 901 | |
849 | 902 | while(($row = $smcFunc['db_fetch_row']($request)) && $with_returning) |
850 | 903 | { |
851 | - if (is_numeric($row[0])) // try to emulate mysql limitation |
|
904 | + if (is_numeric($row[0])) { |
|
905 | + // try to emulate mysql limitation |
|
852 | 906 | { |
853 | 907 | if ($returnmode === 1) |
854 | 908 | $return_var = $row[0]; |
855 | - elseif ($returnmode === 2) |
|
856 | - $return_var[] = $row[0]; |
|
857 | - } |
|
858 | - else |
|
909 | + } elseif ($returnmode === 2) { |
|
910 | + $return_var[] = $row[0]; |
|
911 | + } |
|
912 | + } else |
|
859 | 913 | { |
860 | 914 | $with_returning = false; |
861 | 915 | trigger_error('trying to returning ID Field which is not a Int field', E_USER_ERROR); |
@@ -864,9 +918,10 @@ discard block |
||
864 | 918 | } |
865 | 919 | } |
866 | 920 | |
867 | - if ($with_returning && !empty($return_var)) |
|
868 | - return $return_var; |
|
869 | -} |
|
921 | + if ($with_returning && !empty($return_var)) { |
|
922 | + return $return_var; |
|
923 | + } |
|
924 | + } |
|
870 | 925 | |
871 | 926 | /** |
872 | 927 | * Dummy function really. Doesn't do anything on PostgreSQL. |
@@ -903,8 +958,9 @@ discard block |
||
903 | 958 | */ |
904 | 959 | function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null) |
905 | 960 | { |
906 | - if (empty($log_message)) |
|
907 | - $log_message = $error_message; |
|
961 | + if (empty($log_message)) { |
|
962 | + $log_message = $error_message; |
|
963 | + } |
|
908 | 964 | |
909 | 965 | foreach (debug_backtrace() as $step) |
910 | 966 | { |
@@ -923,12 +979,14 @@ discard block |
||
923 | 979 | } |
924 | 980 | |
925 | 981 | // A special case - we want the file and line numbers for debugging. |
926 | - if ($error_type == 'return') |
|
927 | - return array($file, $line); |
|
982 | + if ($error_type == 'return') { |
|
983 | + return array($file, $line); |
|
984 | + } |
|
928 | 985 | |
929 | 986 | // Is always a critical error. |
930 | - if (function_exists('log_error')) |
|
931 | - log_error($log_message, 'critical', $file, $line); |
|
987 | + if (function_exists('log_error')) { |
|
988 | + log_error($log_message, 'critical', $file, $line); |
|
989 | + } |
|
932 | 990 | |
933 | 991 | if (function_exists('fatal_error')) |
934 | 992 | { |
@@ -936,12 +994,12 @@ discard block |
||
936 | 994 | |
937 | 995 | // Cannot continue... |
938 | 996 | exit; |
997 | + } elseif ($error_type) { |
|
998 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
999 | + } else { |
|
1000 | + trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
1001 | + } |
|
939 | 1002 | } |
940 | - elseif ($error_type) |
|
941 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type); |
|
942 | - else |
|
943 | - trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : '')); |
|
944 | -} |
|
945 | 1003 | |
946 | 1004 | /** |
947 | 1005 | * Escape the LIKE wildcards so that they match the character and not the wildcard. |
@@ -958,10 +1016,11 @@ discard block |
||
958 | 1016 | '\\' => '\\\\', |
959 | 1017 | ); |
960 | 1018 | |
961 | - if ($translate_human_wildcards) |
|
962 | - $replacements += array( |
|
1019 | + if ($translate_human_wildcards) { |
|
1020 | + $replacements += array( |
|
963 | 1021 | '*' => '%', |
964 | 1022 | ); |
1023 | + } |
|
965 | 1024 | |
966 | 1025 | return strtr($string, $replacements); |
967 | 1026 | } |
@@ -989,11 +1048,12 @@ discard block |
||
989 | 1048 | global $db_prefix, $db_connection; |
990 | 1049 | static $pg_error_data_prep; |
991 | 1050 | |
992 | - if (empty($pg_error_data_prep)) |
|
993 | - $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
1051 | + if (empty($pg_error_data_prep)) { |
|
1052 | + $pg_error_data_prep = pg_prepare($db_connection, 'smf_log_errors', |
|
994 | 1053 | 'INSERT INTO ' . $db_prefix . 'log_errors(id_member, log_time, ip, url, message, session, error_type, file, line) |
995 | 1054 | VALUES( $1, $2, $3, $4, $5, $6, $7, $8, $9)' |
996 | 1055 | ); |
1056 | + } |
|
997 | 1057 | |
998 | 1058 | pg_execute($db_connection, 'smf_log_errors', $error_array); |
999 | 1059 | } |
@@ -1013,8 +1073,9 @@ discard block |
||
1013 | 1073 | $count = count($array_values); |
1014 | 1074 | $then = ($desc ? ' THEN -' : ' THEN '); |
1015 | 1075 | |
1016 | - for ($i = 0; $i < $count; $i++) |
|
1017 | - $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1076 | + for ($i = 0; $i < $count; $i++) { |
|
1077 | + $return .= 'WHEN ' . (int) $array_values[$i] . $then . $i . ' '; |
|
1078 | + } |
|
1018 | 1079 | |
1019 | 1080 | $return .= 'END'; |
1020 | 1081 | return $return; |