@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | |
660 | 660 | // Remove the phrase parts and extract the words. |
661 | 661 | $wordArray = preg_replace('~(?:^|\s)(?:[-]?)"(?:[^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), ' ', $search_params['search']); |
662 | - $wordArray = explode(' ', $smcFunc['htmlspecialchars'](un_htmlspecialchars($wordArray), ENT_QUOTES)); |
|
662 | + $wordArray = explode(' ', $smcFunc['htmlspecialchars'](un_htmlspecialchars($wordArray), ENT_QUOTES)); |
|
663 | 663 | |
664 | 664 | // A minus sign in front of a word excludes the word.... so... |
665 | 665 | $excludedWords = array(); |
@@ -1104,7 +1104,7 @@ discard block |
||
1104 | 1104 | SELECT |
1105 | 1105 | {int:id_search}, |
1106 | 1106 | t.id_topic, |
1107 | - ' . $relevance. ', |
|
1107 | + ' . $relevance . ', |
|
1108 | 1108 | ' . (empty($userQuery) ? 't.id_first_msg' : 'm.id_msg') . ', |
1109 | 1109 | 1 |
1110 | 1110 | FROM ' . $subject_query['from'] . (empty($subject_query['inner_join']) ? '' : ' |
@@ -1339,7 +1339,7 @@ discard block |
||
1339 | 1339 | if (empty($subject_query['where'])) |
1340 | 1340 | continue; |
1341 | 1341 | |
1342 | - $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( ' |
|
1342 | + $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? (' |
|
1343 | 1343 | INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics |
1344 | 1344 | (' . ($createTemporary ? '' : 'id_search, ') . 'id_topic)') : '') . ' |
1345 | 1345 | SELECT ' . ($createTemporary ? '' : $_SESSION['search_cache']['id_search'] . ', ') . 't.id_topic |
@@ -1568,7 +1568,7 @@ discard block |
||
1568 | 1568 | } |
1569 | 1569 | $main_query['select']['relevance'] = substr($relevance, 0, -3) . ') / ' . $new_weight_total . ' AS relevance'; |
1570 | 1570 | |
1571 | - $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_no_index', ($smcFunc['db_support_ignore'] ? ( ' |
|
1571 | + $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_no_index', ($smcFunc['db_support_ignore'] ? (' |
|
1572 | 1572 | INSERT IGNORE INTO ' . '{db_prefix}log_search_results |
1573 | 1573 | (' . implode(', ', array_keys($main_query['select'])) . ')') : '') . ' |
1574 | 1574 | SELECT |
@@ -1636,7 +1636,7 @@ discard block |
||
1636 | 1636 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
1637 | 1637 | |
1638 | 1638 | $usedIDs = array_flip(empty($inserts) ? array() : array_keys($inserts)); |
1639 | - $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_sub_only', ($smcFunc['db_support_ignore'] ? ( ' |
|
1639 | + $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_sub_only', ($smcFunc['db_support_ignore'] ? (' |
|
1640 | 1640 | INSERT IGNORE INTO {db_prefix}log_search_results |
1641 | 1641 | (id_search, id_topic, relevance, id_msg, num_matches)') : '') . ' |
1642 | 1642 | SELECT |
@@ -2102,7 +2102,7 @@ discard block |
||
2102 | 2102 | $query = trim($query, "\*+"); |
2103 | 2103 | $query = strtr($smcFunc['htmlspecialchars']($query), array('\\\'' => '\'')); |
2104 | 2104 | |
2105 | - $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => ''')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function ($m) |
|
2105 | + $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => ''')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function($m) |
|
2106 | 2106 | { |
2107 | 2107 | return isset($m[2]) && "$m[2]" == "$m[1]" ? stripslashes("$m[1]") : "<strong class=\"highlight\">$m[1]</strong>"; |
2108 | 2108 | }, $body_highlighted); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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. |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('No direct access...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Generates the query to determine the list of available boards for a user |
@@ -25,8 +26,9 @@ discard block |
||
25 | 26 | { |
26 | 27 | global $smcFunc, $sourcedir; |
27 | 28 | |
28 | - if (isset($boardListOptions['excluded_boards']) && isset($boardListOptions['included_boards'])) |
|
29 | - trigger_error('getBoardList(): Setting both excluded_boards and included_boards is not allowed.', E_USER_ERROR); |
|
29 | + if (isset($boardListOptions['excluded_boards']) && isset($boardListOptions['included_boards'])) { |
|
30 | + trigger_error('getBoardList(): Setting both excluded_boards and included_boards is not allowed.', E_USER_ERROR); |
|
31 | + } |
|
30 | 32 | |
31 | 33 | $where = array(); |
32 | 34 | $where_parameters = array(); |
@@ -42,11 +44,11 @@ discard block |
||
42 | 44 | $where_parameters['included_boards'] = $boardListOptions['included_boards']; |
43 | 45 | } |
44 | 46 | |
45 | - if (!empty($boardListOptions['ignore_boards'])) |
|
46 | - $where[] = '{query_wanna_see_board}'; |
|
47 | - |
|
48 | - elseif (!empty($boardListOptions['use_permissions'])) |
|
49 | - $where[] = '{query_see_board}'; |
|
47 | + if (!empty($boardListOptions['ignore_boards'])) { |
|
48 | + $where[] = '{query_wanna_see_board}'; |
|
49 | + } elseif (!empty($boardListOptions['use_permissions'])) { |
|
50 | + $where[] = '{query_see_board}'; |
|
51 | + } |
|
50 | 52 | |
51 | 53 | if (!empty($boardListOptions['not_redirection'])) |
52 | 54 | { |
@@ -68,12 +70,13 @@ discard block |
||
68 | 70 | { |
69 | 71 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
70 | 72 | { |
71 | - if (!isset($return_value[$row['id_cat']])) |
|
72 | - $return_value[$row['id_cat']] = array( |
|
73 | + if (!isset($return_value[$row['id_cat']])) { |
|
74 | + $return_value[$row['id_cat']] = array( |
|
73 | 75 | 'id' => $row['id_cat'], |
74 | 76 | 'name' => $row['cat_name'], |
75 | 77 | 'boards' => array(), |
76 | 78 | ); |
79 | + } |
|
77 | 80 | |
78 | 81 | $return_value[$row['id_cat']]['boards'][$row['id_board']] = array( |
79 | 82 | 'id' => $row['id_board'], |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Entry point for this section. |
@@ -38,8 +39,7 @@ discard block |
||
38 | 39 | 'stats' => 'SpiderStats', |
39 | 40 | ); |
40 | 41 | $default = 'stats'; |
41 | - } |
|
42 | - else |
|
42 | + } else |
|
43 | 43 | { |
44 | 44 | $subActions = array( |
45 | 45 | 'settings' => 'ManageSearchEngineSettings', |
@@ -90,11 +90,12 @@ discard block |
||
90 | 90 | { |
91 | 91 | disabledState = document.getElementById(\'spider_mode\').value == 0;'; |
92 | 92 | |
93 | - foreach ($config_vars as $variable) |
|
94 | - if ($variable[1] != 'spider_mode') |
|
93 | + foreach ($config_vars as $variable) { |
|
94 | + if ($variable[1] != 'spider_mode') |
|
95 | 95 | $javascript_function .= ' |
96 | 96 | if (document.getElementById(\'' . $variable[1] . '\')) |
97 | 97 | document.getElementById(\'' . $variable[1] . '\').disabled = disabledState;'; |
98 | + } |
|
98 | 99 | |
99 | 100 | $javascript_function .= ' |
100 | 101 | } |
@@ -102,8 +103,9 @@ discard block |
||
102 | 103 | |
103 | 104 | call_integration_hook('integrate_modify_search_engine_settings', array(&$config_vars)); |
104 | 105 | |
105 | - if ($return_config) |
|
106 | - return $config_vars; |
|
106 | + if ($return_config) { |
|
107 | + return $config_vars; |
|
108 | + } |
|
107 | 109 | |
108 | 110 | // We need to load the groups for the spider group thingy. |
109 | 111 | $request = $smcFunc['db_query']('', ' |
@@ -116,13 +118,15 @@ discard block |
||
116 | 118 | 'moderator_group' => 3, |
117 | 119 | ) |
118 | 120 | ); |
119 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
120 | - $config_vars['spider_group'][2][$row['id_group']] = $row['group_name']; |
|
121 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
122 | + $config_vars['spider_group'][2][$row['id_group']] = $row['group_name']; |
|
123 | + } |
|
121 | 124 | $smcFunc['db_free_result']($request); |
122 | 125 | |
123 | 126 | // Make sure it's valid - note that regular members are given id_group = 1 which is reversed in Load.php - no admins here! |
124 | - if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']])) |
|
125 | - $_POST['spider_group'] = 0; |
|
127 | + if (isset($_POST['spider_group']) && !isset($config_vars['spider_group'][2][$_POST['spider_group']])) { |
|
128 | + $_POST['spider_group'] = 0; |
|
129 | + } |
|
126 | 130 | |
127 | 131 | // We'll want this for our easy save. |
128 | 132 | require_once($sourcedir . '/ManageServer.php'); |
@@ -166,8 +170,9 @@ discard block |
||
166 | 170 | } |
167 | 171 | |
168 | 172 | // Are we adding a new one? |
169 | - if (!empty($_POST['addSpider'])) |
|
170 | - return EditSpider(); |
|
173 | + if (!empty($_POST['addSpider'])) { |
|
174 | + return EditSpider(); |
|
175 | + } |
|
171 | 176 | // User pressed the 'remove selection button'. |
172 | 177 | elseif (!empty($_POST['removeSpiders']) && !empty($_POST['remove']) && is_array($_POST['remove'])) |
173 | 178 | { |
@@ -175,8 +180,9 @@ discard block |
||
175 | 180 | validateToken('admin-ser'); |
176 | 181 | |
177 | 182 | // Make sure every entry is a proper integer. |
178 | - foreach ($_POST['remove'] as $index => $spider_id) |
|
179 | - $_POST['remove'][(int) $index] = (int) $spider_id; |
|
183 | + foreach ($_POST['remove'] as $index => $spider_id) { |
|
184 | + $_POST['remove'][(int) $index] = (int) $spider_id; |
|
185 | + } |
|
180 | 186 | |
181 | 187 | // Delete them all! |
182 | 188 | $smcFunc['db_query']('', ' |
@@ -215,8 +221,9 @@ discard block |
||
215 | 221 | ); |
216 | 222 | |
217 | 223 | $context['spider_last_seen'] = array(); |
218 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
219 | - $context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time']; |
|
224 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
225 | + $context['spider_last_seen'][$row['id_spider']] = $row['last_seen_time']; |
|
226 | + } |
|
220 | 227 | $smcFunc['db_free_result']($request); |
221 | 228 | |
222 | 229 | createToken('admin-ser'); |
@@ -346,8 +353,9 @@ discard block |
||
346 | 353 | ) |
347 | 354 | ); |
348 | 355 | $spiders = array(); |
349 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
350 | - $spiders[$row['id_spider']] = $row; |
|
356 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
357 | + $spiders[$row['id_spider']] = $row; |
|
358 | + } |
|
351 | 359 | $smcFunc['db_free_result']($request); |
352 | 360 | |
353 | 361 | return $spiders; |
@@ -397,14 +405,15 @@ discard block |
||
397 | 405 | foreach ($ip_sets as $set) |
398 | 406 | { |
399 | 407 | $test = ip2range(trim($set)); |
400 | - if (!empty($test)) |
|
401 | - $ips[] = $set; |
|
408 | + if (!empty($test)) { |
|
409 | + $ips[] = $set; |
|
410 | + } |
|
402 | 411 | } |
403 | 412 | $ips = implode(',', $ips); |
404 | 413 | |
405 | 414 | // Goes in as it is... |
406 | - if ($context['id_spider']) |
|
407 | - $smcFunc['db_query']('', ' |
|
415 | + if ($context['id_spider']) { |
|
416 | + $smcFunc['db_query']('', ' |
|
408 | 417 | UPDATE {db_prefix}spiders |
409 | 418 | SET spider_name = {string:spider_name}, user_agent = {string:spider_agent}, |
410 | 419 | ip_info = {string:ip_info} |
@@ -416,8 +425,8 @@ discard block |
||
416 | 425 | 'ip_info' => $ips, |
417 | 426 | ) |
418 | 427 | ); |
419 | - else |
|
420 | - $smcFunc['db_insert']('insert', |
|
428 | + } else { |
|
429 | + $smcFunc['db_insert']('insert', |
|
421 | 430 | '{db_prefix}spiders', |
422 | 431 | array( |
423 | 432 | 'spider_name' => 'string', 'user_agent' => 'string', 'ip_info' => 'string', |
@@ -427,6 +436,7 @@ discard block |
||
427 | 436 | ), |
428 | 437 | array('id_spider') |
429 | 438 | ); |
439 | + } |
|
430 | 440 | |
431 | 441 | |
432 | 442 | cache_put_data('spider_search', null); |
@@ -454,13 +464,14 @@ discard block |
||
454 | 464 | 'current_spider' => $context['id_spider'], |
455 | 465 | ) |
456 | 466 | ); |
457 | - if ($row = $smcFunc['db_fetch_assoc']($request)) |
|
458 | - $context['spider'] = array( |
|
467 | + if ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
468 | + $context['spider'] = array( |
|
459 | 469 | 'id' => $row['id_spider'], |
460 | 470 | 'name' => $row['spider_name'], |
461 | 471 | 'agent' => $row['user_agent'], |
462 | 472 | 'ip_info' => $row['ip_info'], |
463 | 473 | ); |
474 | + } |
|
464 | 475 | $smcFunc['db_free_result']($request); |
465 | 476 | } |
466 | 477 | |
@@ -477,8 +488,9 @@ discard block |
||
477 | 488 | { |
478 | 489 | global $modSettings, $smcFunc; |
479 | 490 | |
480 | - if (isset($_SESSION['id_robot'])) |
|
481 | - unset($_SESSION['id_robot']); |
|
491 | + if (isset($_SESSION['id_robot'])) { |
|
492 | + unset($_SESSION['id_robot']); |
|
493 | + } |
|
482 | 494 | $_SESSION['robot_check'] = time(); |
483 | 495 | |
484 | 496 | // We cache the spider data for ten minutes if we can. |
@@ -492,15 +504,17 @@ discard block |
||
492 | 504 | ) |
493 | 505 | ); |
494 | 506 | $spider_data = array(); |
495 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
496 | - $spider_data[] = $row; |
|
507 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
508 | + $spider_data[] = $row; |
|
509 | + } |
|
497 | 510 | $smcFunc['db_free_result']($request); |
498 | 511 | |
499 | 512 | cache_put_data('spider_search', $spider_data, 600); |
500 | 513 | } |
501 | 514 | |
502 | - if (empty($spider_data)) |
|
503 | - return false; |
|
515 | + if (empty($spider_data)) { |
|
516 | + return false; |
|
517 | + } |
|
504 | 518 | |
505 | 519 | // Only do these bits once. |
506 | 520 | $ci_user_agent = strtolower($_SERVER['HTTP_USER_AGENT']); |
@@ -508,33 +522,38 @@ discard block |
||
508 | 522 | foreach ($spider_data as $spider) |
509 | 523 | { |
510 | 524 | // User agent is easy. |
511 | - if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false) |
|
512 | - $_SESSION['id_robot'] = $spider['id_spider']; |
|
525 | + if (!empty($spider['user_agent']) && strpos($ci_user_agent, strtolower($spider['user_agent'])) !== false) { |
|
526 | + $_SESSION['id_robot'] = $spider['id_spider']; |
|
527 | + } |
|
513 | 528 | // IP stuff is harder. |
514 | 529 | elseif ($_SERVER['REMOTE_ADDR']) |
515 | 530 | { |
516 | 531 | $ips = explode(',', $spider['ip_info']); |
517 | 532 | foreach ($ips as $ip) |
518 | 533 | { |
519 | - if ($ip === '') |
|
520 | - continue; |
|
534 | + if ($ip === '') { |
|
535 | + continue; |
|
536 | + } |
|
521 | 537 | |
522 | 538 | $ip = ip2range($ip); |
523 | 539 | if (!empty($ip)) |
524 | 540 | { |
525 | - if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR'])) |
|
526 | - $_SESSION['id_robot'] = $spider['id_spider']; |
|
541 | + if (inet_ptod($ip['low']) <= inet_ptod($_SERVER['REMOTE_ADDR']) && inet_ptod($ip['high']) >= inet_ptod($_SERVER['REMOTE_ADDR'])) { |
|
542 | + $_SESSION['id_robot'] = $spider['id_spider']; |
|
543 | + } |
|
527 | 544 | } |
528 | 545 | } |
529 | 546 | } |
530 | 547 | |
531 | - if (isset($_SESSION['id_robot'])) |
|
532 | - break; |
|
548 | + if (isset($_SESSION['id_robot'])) { |
|
549 | + break; |
|
550 | + } |
|
533 | 551 | } |
534 | 552 | |
535 | 553 | // If this is low server tracking then log the spider here as opposed to the main logging function. |
536 | - if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot'])) |
|
537 | - logSpider(); |
|
554 | + if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] == 1 && !empty($_SESSION['id_robot'])) { |
|
555 | + logSpider(); |
|
556 | + } |
|
538 | 557 | |
539 | 558 | return !empty($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
540 | 559 | } |
@@ -548,8 +567,9 @@ discard block |
||
548 | 567 | { |
549 | 568 | global $smcFunc, $modSettings, $context; |
550 | 569 | |
551 | - if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot'])) |
|
552 | - return; |
|
570 | + if (empty($modSettings['spider_mode']) || empty($_SESSION['id_robot'])) { |
|
571 | + return; |
|
572 | + } |
|
553 | 573 | |
554 | 574 | // Attempt to update today's entry. |
555 | 575 | if ($modSettings['spider_mode'] == 1) |
@@ -590,9 +610,9 @@ discard block |
||
590 | 610 | $url = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']); |
591 | 611 | unset($url['sesc'], $url[$context['session_var']]); |
592 | 612 | $url = json_encode($url); |
613 | + } else { |
|
614 | + $url = ''; |
|
593 | 615 | } |
594 | - else |
|
595 | - $url = ''; |
|
596 | 616 | |
597 | 617 | $smcFunc['db_insert']('insert', |
598 | 618 | '{db_prefix}log_spider_hits', |
@@ -620,12 +640,14 @@ discard block |
||
620 | 640 | ) |
621 | 641 | ); |
622 | 642 | $spider_hits = array(); |
623 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
624 | - $spider_hits[] = $row; |
|
643 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
644 | + $spider_hits[] = $row; |
|
645 | + } |
|
625 | 646 | $smcFunc['db_free_result']($request); |
626 | 647 | |
627 | - if (empty($spider_hits)) |
|
628 | - return; |
|
648 | + if (empty($spider_hits)) { |
|
649 | + return; |
|
650 | + } |
|
629 | 651 | |
630 | 652 | // Attempt to update the master data. |
631 | 653 | $stat_inserts = array(); |
@@ -646,18 +668,20 @@ discard block |
||
646 | 668 | 'hits' => $stat['num_hits'], |
647 | 669 | ) |
648 | 670 | ); |
649 | - if ($smcFunc['db_affected_rows']() == 0) |
|
650 | - $stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']); |
|
671 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
672 | + $stat_inserts[] = array($date, $stat['id_spider'], $stat['num_hits'], $stat['last_seen']); |
|
673 | + } |
|
651 | 674 | } |
652 | 675 | |
653 | 676 | // New stats? |
654 | - if (!empty($stat_inserts)) |
|
655 | - $smcFunc['db_insert']('ignore', |
|
677 | + if (!empty($stat_inserts)) { |
|
678 | + $smcFunc['db_insert']('ignore', |
|
656 | 679 | '{db_prefix}log_spider_stats', |
657 | 680 | array('stat_date' => 'date', 'id_spider' => 'int', 'page_hits' => 'int', 'last_seen' => 'int'), |
658 | 681 | $stat_inserts, |
659 | 682 | array('stat_date', 'id_spider') |
660 | 683 | ); |
684 | + } |
|
661 | 685 | |
662 | 686 | // All processed. |
663 | 687 | $smcFunc['db_query']('', ' |
@@ -700,8 +724,7 @@ discard block |
||
700 | 724 | 'delete_period' => $deleteTime, |
701 | 725 | ) |
702 | 726 | ); |
703 | - } |
|
704 | - else |
|
727 | + } else |
|
705 | 728 | { |
706 | 729 | // Deleting all of them |
707 | 730 | $smcFunc['db_query']('', ' |
@@ -791,10 +814,11 @@ discard block |
||
791 | 814 | foreach ($context['spider_logs']['rows'] as $k => $row) |
792 | 815 | { |
793 | 816 | // Feature disabled? |
794 | - if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3) |
|
795 | - $context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>'; |
|
796 | - else |
|
797 | - $urls[$k] = array($row['data']['viewing']['value'], -1); |
|
817 | + if (empty($row['data']['viewing']['value']) && isset($modSettings['spider_mode']) && $modSettings['spider_mode'] < 3) { |
|
818 | + $context['spider_logs']['rows'][$k]['viewing']['value'] = '<em>' . $txt['spider_disabled'] . '</em>'; |
|
819 | + } else { |
|
820 | + $urls[$k] = array($row['data']['viewing']['value'], -1); |
|
821 | + } |
|
798 | 822 | } |
799 | 823 | |
800 | 824 | // Now stick in the new URLs. |
@@ -836,8 +860,9 @@ discard block |
||
836 | 860 | ) |
837 | 861 | ); |
838 | 862 | $spider_logs = array(); |
839 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
840 | - $spider_logs[] = $row; |
|
863 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
864 | + $spider_logs[] = $row; |
|
865 | + } |
|
841 | 866 | $smcFunc['db_free_result']($request); |
842 | 867 | |
843 | 868 | return $spider_logs; |
@@ -913,14 +938,18 @@ discard block |
||
913 | 938 | |
914 | 939 | // Prepare the dates for the drop down. |
915 | 940 | $date_choices = array(); |
916 | - for ($y = $min_year; $y <= $max_year; $y++) |
|
917 | - for ($m = 1; $m <= 12; $m++) |
|
941 | + for ($y = $min_year; $y <= $max_year; $y++) { |
|
942 | + for ($m = 1; |
|
943 | + } |
|
944 | + $m <= 12; $m++) |
|
918 | 945 | { |
919 | 946 | // This doesn't count? |
920 | - if ($y == $min_year && $m < $min_month) |
|
921 | - continue; |
|
922 | - if ($y == $max_year && $m > $max_month) |
|
923 | - break; |
|
947 | + if ($y == $min_year && $m < $min_month) { |
|
948 | + continue; |
|
949 | + } |
|
950 | + if ($y == $max_year && $m > $max_month) { |
|
951 | + break; |
|
952 | + } |
|
924 | 953 | |
925 | 954 | $date_choices[$y . $m] = $txt['months_short'][$m] . ' ' . $y; |
926 | 955 | } |
@@ -933,13 +962,14 @@ discard block |
||
933 | 962 | ' . $txt['spider_stats_select_month'] . ': |
934 | 963 | <select name="new_date" onchange="document.spider_stat_list.submit();">'; |
935 | 964 | |
936 | - if (empty($date_choices)) |
|
937 | - $date_select .= ' |
|
965 | + if (empty($date_choices)) { |
|
966 | + $date_select .= ' |
|
938 | 967 | <option></option>'; |
939 | - else |
|
940 | - foreach ($date_choices as $id => $text) |
|
968 | + } else { |
|
969 | + foreach ($date_choices as $id => $text) |
|
941 | 970 | $date_select .= ' |
942 | 971 | <option value="' . $id . '"' . ($current_date == $id ? ' selected' : '') . '>' . $text . '</option>'; |
972 | + } |
|
943 | 973 | |
944 | 974 | $date_select .= ' |
945 | 975 | </select> |
@@ -1063,8 +1093,9 @@ discard block |
||
1063 | 1093 | ) |
1064 | 1094 | ); |
1065 | 1095 | $spider_stats = array(); |
1066 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1067 | - $spider_stats[] = $row; |
|
1096 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1097 | + $spider_stats[] = $row; |
|
1098 | + } |
|
1068 | 1099 | $smcFunc['db_free_result']($request); |
1069 | 1100 | |
1070 | 1101 | return $spider_stats; |
@@ -1105,8 +1136,9 @@ discard block |
||
1105 | 1136 | array() |
1106 | 1137 | ); |
1107 | 1138 | $spiders = array(); |
1108 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1109 | - $spiders[$row['id_spider']] = $row['spider_name']; |
|
1139 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1140 | + $spiders[$row['id_spider']] = $row['spider_name']; |
|
1141 | + } |
|
1110 | 1142 | $smcFunc['db_free_result']($request); |
1111 | 1143 | |
1112 | 1144 | updateSettings(array('spider_name_cache' => json_encode($spiders))); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | $table = str_replace('{db_prefix}', $db_prefix, $table); |
93 | 93 | |
94 | - $pg_tables = array('pg_catalog','information_schema'); |
|
94 | + $pg_tables = array('pg_catalog', 'information_schema'); |
|
95 | 95 | |
96 | 96 | $request = $smcFunc['db_query']('', ' |
97 | 97 | SELECT pg_relation_size(C.oid) AS "size" |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | { |
290 | 290 | static $ver; |
291 | 291 | |
292 | - if(!empty($ver)) |
|
292 | + if (!empty($ver)) |
|
293 | 293 | return $ver; |
294 | 294 | |
295 | 295 | global $smcFunc; |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Add the functions implemented in this file to the $smcFunc array. |
@@ -23,8 +24,8 @@ discard block |
||
23 | 24 | { |
24 | 25 | global $smcFunc; |
25 | 26 | |
26 | - if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') |
|
27 | - $smcFunc += array( |
|
27 | + if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') { |
|
28 | + $smcFunc += array( |
|
28 | 29 | 'db_backup_table' => 'smf_db_backup_table', |
29 | 30 | 'db_optimize_table' => 'smf_db_optimize_table', |
30 | 31 | 'db_table_sql' => 'smf_db_table_sql', |
@@ -32,7 +33,8 @@ discard block |
||
32 | 33 | 'db_get_version' => 'smf_db_get_version', |
33 | 34 | 'db_get_engine' => 'smf_db_get_engine', |
34 | 35 | ); |
35 | -} |
|
36 | + } |
|
37 | + } |
|
36 | 38 | |
37 | 39 | /** |
38 | 40 | * Backup $table to $backup_table. |
@@ -48,13 +50,14 @@ discard block |
||
48 | 50 | |
49 | 51 | // Do we need to drop it first? |
50 | 52 | $tables = smf_db_list_tables(false, $backup_table); |
51 | - if (!empty($tables)) |
|
52 | - $smcFunc['db_query']('', ' |
|
53 | + if (!empty($tables)) { |
|
54 | + $smcFunc['db_query']('', ' |
|
53 | 55 | DROP TABLE {raw:backup_table}', |
54 | 56 | array( |
55 | 57 | 'backup_table' => $backup_table, |
56 | 58 | ) |
57 | 59 | ); |
60 | + } |
|
58 | 61 | |
59 | 62 | /** |
60 | 63 | * @todo Should we create backups of sequences as well? |
@@ -117,8 +120,9 @@ discard block |
||
117 | 120 | ) |
118 | 121 | ); |
119 | 122 | |
120 | - if (!$request) |
|
121 | - return -1; |
|
123 | + if (!$request) { |
|
124 | + return -1; |
|
125 | + } |
|
122 | 126 | |
123 | 127 | $request = $smcFunc['db_query']('', ' |
124 | 128 | SELECT pg_relation_size(C.oid) AS "size" |
@@ -136,11 +140,12 @@ discard block |
||
136 | 140 | $row = $smcFunc['db_fetch_assoc']($request); |
137 | 141 | $smcFunc['db_free_result']($request); |
138 | 142 | |
139 | - if (isset($row['size'])) |
|
140 | - return ($old_size - $row['size']) / 1024; |
|
141 | - else |
|
142 | - return 0; |
|
143 | -} |
|
143 | + if (isset($row['size'])) { |
|
144 | + return ($old_size - $row['size']) / 1024; |
|
145 | + } else { |
|
146 | + return 0; |
|
147 | + } |
|
148 | + } |
|
144 | 149 | |
145 | 150 | /** |
146 | 151 | * This function lists all tables in the database. |
@@ -167,8 +172,9 @@ discard block |
||
167 | 172 | ); |
168 | 173 | |
169 | 174 | $tables = array(); |
170 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
171 | - $tables[] = $row[0]; |
|
175 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
176 | + $tables[] = $row[0]; |
|
177 | + } |
|
172 | 178 | $smcFunc['db_free_result']($request); |
173 | 179 | |
174 | 180 | return $tables; |
@@ -209,12 +215,14 @@ discard block |
||
209 | 215 | ); |
210 | 216 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
211 | 217 | { |
212 | - if ($row['data_type'] == 'character varying') |
|
213 | - $row['data_type'] = 'varchar'; |
|
214 | - elseif ($row['data_type'] == 'character') |
|
215 | - $row['data_type'] = 'char'; |
|
216 | - if ($row['character_maximum_length']) |
|
217 | - $row['data_type'] .= '(' . $row['character_maximum_length'] . ')'; |
|
218 | + if ($row['data_type'] == 'character varying') { |
|
219 | + $row['data_type'] = 'varchar'; |
|
220 | + } elseif ($row['data_type'] == 'character') { |
|
221 | + $row['data_type'] = 'char'; |
|
222 | + } |
|
223 | + if ($row['character_maximum_length']) { |
|
224 | + $row['data_type'] .= '(' . $row['character_maximum_length'] . ')'; |
|
225 | + } |
|
218 | 226 | |
219 | 227 | // Make the CREATE for this column. |
220 | 228 | $schema_create .= ' "' . $row['column_name'] . '" ' . $row['data_type'] . ($row['is_nullable'] != 'YES' ? ' NOT NULL' : ''); |
@@ -265,13 +273,14 @@ discard block |
||
265 | 273 | { |
266 | 274 | if ($row['is_primary']) |
267 | 275 | { |
268 | - if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) |
|
269 | - continue; |
|
276 | + if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) { |
|
277 | + continue; |
|
278 | + } |
|
270 | 279 | |
271 | 280 | $index_create .= $crlf . 'ALTER TABLE ' . $tableName . ' ADD PRIMARY KEY ("' . $matches[1] . '");'; |
281 | + } else { |
|
282 | + $index_create .= $crlf . $row['inddef'] . ';'; |
|
272 | 283 | } |
273 | - else |
|
274 | - $index_create .= $crlf . $row['inddef'] . ';'; |
|
275 | 284 | } |
276 | 285 | $smcFunc['db_free_result']($result); |
277 | 286 | |
@@ -289,8 +298,9 @@ discard block |
||
289 | 298 | { |
290 | 299 | static $ver; |
291 | 300 | |
292 | - if(!empty($ver)) |
|
293 | - return $ver; |
|
301 | + if(!empty($ver)) { |
|
302 | + return $ver; |
|
303 | + } |
|
294 | 304 | |
295 | 305 | global $smcFunc; |
296 | 306 |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
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 | * Scheduled tasks management dispatcher. This function checks permissions and delegates |
@@ -40,10 +41,11 @@ discard block |
||
40 | 41 | ); |
41 | 42 | |
42 | 43 | // We need to find what's the action. |
43 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
44 | - $context['sub_action'] = $_REQUEST['sa']; |
|
45 | - else |
|
46 | - $context['sub_action'] = 'tasks'; |
|
44 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
45 | + $context['sub_action'] = $_REQUEST['sa']; |
|
46 | + } else { |
|
47 | + $context['sub_action'] = 'tasks'; |
|
48 | + } |
|
47 | 49 | |
48 | 50 | // Now for the lovely tabs. That we all love. |
49 | 51 | $context[$context['admin_menu_name']]['tab_data'] = array( |
@@ -90,9 +92,10 @@ discard block |
||
90 | 92 | |
91 | 93 | // Enable and disable as required. |
92 | 94 | $enablers = array(0); |
93 | - foreach ($_POST['enable_task'] as $id => $enabled) |
|
94 | - if ($enabled) |
|
95 | + foreach ($_POST['enable_task'] as $id => $enabled) { |
|
96 | + if ($enabled) |
|
95 | 97 | $enablers[] = (int) $id; |
98 | + } |
|
96 | 99 | |
97 | 100 | // Do the update! |
98 | 101 | $smcFunc['db_query']('', ' |
@@ -130,8 +133,9 @@ discard block |
||
130 | 133 | |
131 | 134 | // Lets figure out which ones they want to run. |
132 | 135 | $tasks = array(); |
133 | - foreach ($_POST['run_task'] as $task => $dummy) |
|
134 | - $tasks[] = (int) $task; |
|
136 | + foreach ($_POST['run_task'] as $task => $dummy) { |
|
137 | + $tasks[] = (int) $task; |
|
138 | + } |
|
135 | 139 | |
136 | 140 | // Load up the tasks. |
137 | 141 | $request = $smcFunc['db_query']('', ' |
@@ -151,36 +155,41 @@ discard block |
||
151 | 155 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
152 | 156 | { |
153 | 157 | // What kind of task are we handling? |
154 | - if (!empty($row['callable'])) |
|
155 | - $task_string = $row['callable']; |
|
158 | + if (!empty($row['callable'])) { |
|
159 | + $task_string = $row['callable']; |
|
160 | + } |
|
156 | 161 | |
157 | 162 | // Default SMF task or old mods? |
158 | - elseif (function_exists('scheduled_' . $row['task'])) |
|
159 | - $task_string = 'scheduled_' . $row['task']; |
|
163 | + elseif (function_exists('scheduled_' . $row['task'])) { |
|
164 | + $task_string = 'scheduled_' . $row['task']; |
|
165 | + } |
|
160 | 166 | |
161 | 167 | // One last resource, the task name. |
162 | - elseif (!empty($row['task'])) |
|
163 | - $task_string = $row['task']; |
|
168 | + elseif (!empty($row['task'])) { |
|
169 | + $task_string = $row['task']; |
|
170 | + } |
|
164 | 171 | |
165 | 172 | $start_time = microtime(); |
166 | 173 | // The functions got to exist for us to use it. |
167 | - if (empty($task_string)) |
|
168 | - continue; |
|
174 | + if (empty($task_string)) { |
|
175 | + continue; |
|
176 | + } |
|
169 | 177 | |
170 | 178 | // Try to stop a timeout, this would be bad... |
171 | 179 | @set_time_limit(300); |
172 | - if (function_exists('apache_reset_timeout')) |
|
173 | - @apache_reset_timeout(); |
|
180 | + if (function_exists('apache_reset_timeout')) { |
|
181 | + @apache_reset_timeout(); |
|
182 | + } |
|
174 | 183 | |
175 | 184 | // Get the callable. |
176 | 185 | $callable_task = call_helper($task_string, true); |
177 | 186 | |
178 | 187 | // Perform the task. |
179 | - if (!empty($callable_task)) |
|
180 | - $completed = call_user_func($callable_task); |
|
181 | - |
|
182 | - else |
|
183 | - $completed = false; |
|
188 | + if (!empty($callable_task)) { |
|
189 | + $completed = call_user_func($callable_task); |
|
190 | + } else { |
|
191 | + $completed = false; |
|
192 | + } |
|
184 | 193 | |
185 | 194 | // Log that we did it ;) |
186 | 195 | if ($completed) |
@@ -197,8 +206,9 @@ discard block |
||
197 | 206 | $smcFunc['db_free_result']($request); |
198 | 207 | |
199 | 208 | // If we had any errors, push them to session so we can pick them up next time to tell the user. |
200 | - if (!empty($context['scheduled_errors'])) |
|
201 | - $_SESSION['st_error'] = $context['scheduled_errors']; |
|
209 | + if (!empty($context['scheduled_errors'])) { |
|
210 | + $_SESSION['st_error'] = $context['scheduled_errors']; |
|
211 | + } |
|
202 | 212 | |
203 | 213 | redirectexit('action=admin;area=scheduledtasks;done'); |
204 | 214 | } |
@@ -370,8 +380,9 @@ discard block |
||
370 | 380 | $context['server_time'] = timeformat(time(), false, 'server'); |
371 | 381 | |
372 | 382 | // Cleaning... |
373 | - if (!isset($_GET['tid'])) |
|
374 | - fatal_lang_error('no_access', false); |
|
383 | + if (!isset($_GET['tid'])) { |
|
384 | + fatal_lang_error('no_access', false); |
|
385 | + } |
|
375 | 386 | $_GET['tid'] = (int) $_GET['tid']; |
376 | 387 | |
377 | 388 | // Saving? |
@@ -387,10 +398,12 @@ discard block |
||
387 | 398 | preg_match('~(\d{1,2}):(\d{1,2})~', $_POST['offset'], $matches); |
388 | 399 | |
389 | 400 | // If a half is empty then assume zero offset! |
390 | - if (!isset($matches[2]) || $matches[2] > 59) |
|
391 | - $matches[2] = 0; |
|
392 | - if (!isset($matches[1]) || $matches[1] > 23) |
|
393 | - $matches[1] = 0; |
|
401 | + if (!isset($matches[2]) || $matches[2] > 59) { |
|
402 | + $matches[2] = 0; |
|
403 | + } |
|
404 | + if (!isset($matches[1]) || $matches[1] > 23) { |
|
405 | + $matches[1] = 0; |
|
406 | + } |
|
394 | 407 | |
395 | 408 | // Now the offset is easy; easy peasy - except we need to offset by a few hours... |
396 | 409 | $offset = $matches[1] * 3600 + $matches[2] * 60 - date('Z'); |
@@ -400,8 +413,9 @@ discard block |
||
400 | 413 | $unit = in_array(substr($_POST['unit'], 0, 1), array('m', 'h', 'd', 'w')) ? substr($_POST['unit'], 0, 1) : 'd'; |
401 | 414 | |
402 | 415 | // Don't allow one minute intervals. |
403 | - if ($interval == 1 && $unit == 'm') |
|
404 | - $interval = 2; |
|
416 | + if ($interval == 1 && $unit == 'm') { |
|
417 | + $interval = 2; |
|
418 | + } |
|
405 | 419 | |
406 | 420 | // Is it disabled? |
407 | 421 | $disabled = !isset($_POST['enabled']) ? 1 : 0; |
@@ -439,8 +453,9 @@ discard block |
||
439 | 453 | ); |
440 | 454 | |
441 | 455 | // Should never, ever, happen! |
442 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
443 | - fatal_lang_error('no_access', false); |
|
456 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
457 | + fatal_lang_error('no_access', false); |
|
458 | + } |
|
444 | 459 | |
445 | 460 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
446 | 461 | { |
@@ -598,13 +613,14 @@ discard block |
||
598 | 613 | ) |
599 | 614 | ); |
600 | 615 | $log_entries = array(); |
601 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
602 | - $log_entries[] = array( |
|
616 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
617 | + $log_entries[] = array( |
|
603 | 618 | 'id' => $row['id_log'], |
604 | 619 | 'name' => isset($txt['scheduled_task_' . $row['task']]) ? $txt['scheduled_task_' . $row['task']] : $row['task'], |
605 | 620 | 'time_run' => $row['time_run'], |
606 | 621 | 'time_taken' => $row['time_taken'], |
607 | 622 | ); |
623 | + } |
|
608 | 624 | $smcFunc['db_free_result']($request); |
609 | 625 | |
610 | 626 | return $log_entries; |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | ) |
51 | 51 | ); |
52 | 52 | $members = array(); |
53 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
54 | - $members[$row['id_member']] = array( |
|
53 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
54 | + $members[$row['id_member']] = array( |
|
55 | 55 | 'id' => $row['id_member'], |
56 | 56 | 'real_name' => $row['real_name'], |
57 | 57 | 'email_address' => $row['email_address'], |
@@ -62,6 +62,7 @@ discard block |
||
62 | 62 | ), |
63 | 63 | 'lngfile' => $row['lngfile'], |
64 | 64 | ); |
65 | + } |
|
65 | 66 | $smcFunc['db_free_result']($request); |
66 | 67 | |
67 | 68 | return $members; |
@@ -83,13 +84,14 @@ discard block |
||
83 | 84 | |
84 | 85 | call_integration_hook('mention_insert_' . $content_type, array($content_id, &$members)); |
85 | 86 | |
86 | - foreach ($members as $member) |
|
87 | - $smcFunc['db_insert']('ignore', |
|
87 | + foreach ($members as $member) { |
|
88 | + $smcFunc['db_insert']('ignore', |
|
88 | 89 | '{db_prefix}mentions', |
89 | 90 | array('content_id' => 'int', 'content_type' => 'string', 'id_member' => 'int', 'id_mentioned' => 'int', 'time' => 'int'), |
90 | 91 | array((int) $content_id, $content_type, $id_member, $member['id'], time()), |
91 | 92 | array('content_id', 'content_type', 'id_mentioned') |
92 | 93 | ); |
94 | + } |
|
93 | 95 | } |
94 | 96 | |
95 | 97 | /** |
@@ -103,8 +105,9 @@ discard block |
||
103 | 105 | */ |
104 | 106 | public static function getBody($body, array $members) |
105 | 107 | { |
106 | - foreach ($members as $member) |
|
107 | - $body = str_ireplace(static::$char . $member['real_name'], '[member=' . $member['id'] . ']' . $member['real_name'] . '[/member]', $body); |
|
108 | + foreach ($members as $member) { |
|
109 | + $body = str_ireplace(static::$char . $member['real_name'], '[member=' . $member['id'] . ']' . $member['real_name'] . '[/member]', $body); |
|
110 | + } |
|
108 | 111 | |
109 | 112 | return $body; |
110 | 113 | } |
@@ -123,8 +126,9 @@ discard block |
||
123 | 126 | |
124 | 127 | $possible_names = self::getPossibleMentions($body); |
125 | 128 | |
126 | - if (empty($possible_names) || !allowedTo('mention')) |
|
127 | - return array(); |
|
129 | + if (empty($possible_names) || !allowedTo('mention')) { |
|
130 | + return array(); |
|
131 | + } |
|
128 | 132 | |
129 | 133 | $request = $smcFunc['db_query']('', ' |
130 | 134 | SELECT id_member, real_name |
@@ -140,8 +144,9 @@ discard block |
||
140 | 144 | $members = array(); |
141 | 145 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
142 | 146 | { |
143 | - if (stripos($body, static::$char . $row['real_name']) === false) |
|
144 | - continue; |
|
147 | + if (stripos($body, static::$char . $row['real_name']) === false) { |
|
148 | + continue; |
|
149 | + } |
|
145 | 150 | |
146 | 151 | $members[$row['id_member']] = array( |
147 | 152 | 'id' => $row['id_member'], |
@@ -185,8 +190,9 @@ discard block |
||
185 | 190 | $body = htmlspecialchars_decode(preg_replace('~<br\s*/?\>~', "\n", str_replace(' ', ' ', $body)), ENT_QUOTES); |
186 | 191 | |
187 | 192 | // Remove quotes, we don't want to get double mentions. |
188 | - while (preg_match('~\[quote[^\]]*\](.+?)\[\/quote\]~s', $body)) |
|
189 | - $body = preg_replace('~\[quote[^\]]*\](.+?)\[\/quote\]~s', '', $body); |
|
193 | + while (preg_match('~\[quote[^\]]*\](.+?)\[\/quote\]~s', $body)) { |
|
194 | + $body = preg_replace('~\[quote[^\]]*\](.+?)\[\/quote\]~s', '', $body); |
|
195 | + } |
|
190 | 196 | |
191 | 197 | $matches = array(); |
192 | 198 | $string = str_split($body); |
@@ -197,9 +203,9 @@ discard block |
||
197 | 203 | { |
198 | 204 | $depth++; |
199 | 205 | $matches[] = array(); |
206 | + } elseif ($char == "\n") { |
|
207 | + $depth = 0; |
|
200 | 208 | } |
201 | - elseif ($char == "\n") |
|
202 | - $depth = 0; |
|
203 | 209 | |
204 | 210 | for ($i = $depth; $i > 0; $i--) |
205 | 211 | { |
@@ -212,8 +218,9 @@ discard block |
||
212 | 218 | } |
213 | 219 | } |
214 | 220 | |
215 | - foreach ($matches as $k => $match) |
|
216 | - $matches[$k] = substr(implode('', $match), 1); |
|
221 | + foreach ($matches as $k => $match) { |
|
222 | + $matches[$k] = substr(implode('', $match), 1); |
|
223 | + } |
|
217 | 224 | |
218 | 225 | // Names can have spaces, other breaks, or they can't...we try to match every possible |
219 | 226 | // combination. |
@@ -223,8 +230,9 @@ discard block |
||
223 | 230 | $match = preg_split('/([^\w])/', $match, -1, PREG_SPLIT_DELIM_CAPTURE); |
224 | 231 | $count = count($match); |
225 | 232 | |
226 | - for ($i = 1; $i <= $count; $i++) |
|
227 | - $names[] = $smcFunc['htmlspecialchars']($smcFunc['htmltrim'](implode('', array_slice($match, 0, $i)))); |
|
233 | + for ($i = 1; $i <= $count; $i++) { |
|
234 | + $names[] = $smcFunc['htmlspecialchars']($smcFunc['htmltrim'](implode('', array_slice($match, 0, $i)))); |
|
235 | + } |
|
228 | 236 | } |
229 | 237 | |
230 | 238 | $names = array_unique($names); |
@@ -1326,7 +1326,7 @@ discard block |
||
1326 | 1326 | 'class' => 'centercol', |
1327 | 1327 | ), |
1328 | 1328 | 'data' => array( |
1329 | - 'function' => function ($rowData) |
|
1329 | + 'function' => function($rowData) |
|
1330 | 1330 | { |
1331 | 1331 | $isChecked = $rowData['disabled'] ? '' : ' checked'; |
1332 | 1332 | $onClickHandler = $rowData['can_show_register'] ? sprintf(' onclick="document.getElementById(\'reg_%1$s\').disabled = !this.checked;"', $rowData['id']) : ''; |
@@ -1342,7 +1342,7 @@ discard block |
||
1342 | 1342 | 'class' => 'centercol', |
1343 | 1343 | ), |
1344 | 1344 | 'data' => array( |
1345 | - 'function' => function ($rowData) |
|
1345 | + 'function' => function($rowData) |
|
1346 | 1346 | { |
1347 | 1347 | $isChecked = $rowData['on_register'] && !$rowData['disabled'] ? ' checked' : ''; |
1348 | 1348 | $isDisabled = $rowData['can_show_register'] ? '' : ' disabled'; |
@@ -1389,15 +1389,15 @@ discard block |
||
1389 | 1389 | 'value' => $txt['custom_profile_fieldorder'], |
1390 | 1390 | ), |
1391 | 1391 | 'data' => array( |
1392 | - 'function' => function ($rowData) use ($context, $txt, $scripturl) |
|
1392 | + 'function' => function($rowData) use ($context, $txt, $scripturl) |
|
1393 | 1393 | { |
1394 | - $return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br />'; |
|
1394 | + $return = '<p class="centertext bold_text">' . $rowData['field_order'] . '<br />'; |
|
1395 | 1395 | |
1396 | 1396 | if ($rowData['field_order'] > 1) |
1397 | - $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>'; |
|
1397 | + $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="' . $txt['custom_edit_order_move'] . ' ' . $txt['custom_edit_order_up'] . '"></span></a>'; |
|
1398 | 1398 | |
1399 | 1399 | if ($rowData['field_order'] < $context['custFieldsMaxOrder']) |
1400 | - $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>'; |
|
1400 | + $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="' . $txt['custom_edit_order_move'] . ' ' . $txt['custom_edit_order_down'] . '"></span></a>'; |
|
1401 | 1401 | |
1402 | 1402 | $return .= '</p>'; |
1403 | 1403 | |
@@ -1415,7 +1415,7 @@ discard block |
||
1415 | 1415 | 'value' => $txt['custom_profile_fieldname'], |
1416 | 1416 | ), |
1417 | 1417 | 'data' => array( |
1418 | - 'function' => function ($rowData) use ($scripturl) |
|
1418 | + 'function' => function($rowData) use ($scripturl) |
|
1419 | 1419 | { |
1420 | 1420 | return sprintf('<a href="%1$s?action=admin;area=featuresettings;sa=profileedit;fid=%2$d">%3$s</a><div class="smalltext">%4$s</div>', $scripturl, $rowData['id_field'], $rowData['field_name'], $rowData['field_desc']); |
1421 | 1421 | }, |
@@ -1431,7 +1431,7 @@ discard block |
||
1431 | 1431 | 'value' => $txt['custom_profile_fieldtype'], |
1432 | 1432 | ), |
1433 | 1433 | 'data' => array( |
1434 | - 'function' => function ($rowData) use ($txt) |
|
1434 | + 'function' => function($rowData) use ($txt) |
|
1435 | 1435 | { |
1436 | 1436 | $textKey = sprintf('custom_profile_type_%1$s', $rowData['field_type']); |
1437 | 1437 | return isset($txt[$textKey]) ? $txt[$textKey] : $textKey; |
@@ -1449,7 +1449,7 @@ discard block |
||
1449 | 1449 | 'value' => $txt['custom_profile_active'], |
1450 | 1450 | ), |
1451 | 1451 | 'data' => array( |
1452 | - 'function' => function ($rowData) use ($txt) |
|
1452 | + 'function' => function($rowData) use ($txt) |
|
1453 | 1453 | { |
1454 | 1454 | return $rowData['active'] ? $txt['yes'] : $txt['no']; |
1455 | 1455 | }, |
@@ -1466,7 +1466,7 @@ discard block |
||
1466 | 1466 | 'value' => $txt['custom_profile_placement'], |
1467 | 1467 | ), |
1468 | 1468 | 'data' => array( |
1469 | - 'function' => function ($rowData) |
|
1469 | + 'function' => function($rowData) |
|
1470 | 1470 | { |
1471 | 1471 | global $txt, $context; |
1472 | 1472 | |
@@ -1701,7 +1701,7 @@ discard block |
||
1701 | 1701 | redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler |
1702 | 1702 | |
1703 | 1703 | // All good, proceed. |
1704 | - $smcFunc['db_query']('',' |
|
1704 | + $smcFunc['db_query']('', ' |
|
1705 | 1705 | UPDATE {db_prefix}custom_fields |
1706 | 1706 | SET field_order = {int:old_order} |
1707 | 1707 | WHERE field_order = {int:new_order}', |
@@ -1710,7 +1710,7 @@ discard block |
||
1710 | 1710 | 'old_order' => $context['field']['order'], |
1711 | 1711 | ) |
1712 | 1712 | ); |
1713 | - $smcFunc['db_query']('',' |
|
1713 | + $smcFunc['db_query']('', ' |
|
1714 | 1714 | UPDATE {db_prefix}custom_fields |
1715 | 1715 | SET field_order = {int:new_order} |
1716 | 1716 | WHERE id_field = {int:id_field}', |
@@ -1812,7 +1812,7 @@ discard block |
||
1812 | 1812 | $smcFunc['db_free_result']($request); |
1813 | 1813 | |
1814 | 1814 | $unique = false; |
1815 | - for ($i = 0; !$unique && $i < 9; $i ++) |
|
1815 | + for ($i = 0; !$unique && $i < 9; $i++) |
|
1816 | 1816 | { |
1817 | 1817 | if (!in_array($col_name, $current_fields)) |
1818 | 1818 | $unique = true; |
@@ -1985,7 +1985,7 @@ discard block |
||
1985 | 1985 | ); |
1986 | 1986 | |
1987 | 1987 | // Re-arrange the order. |
1988 | - $smcFunc['db_query']('',' |
|
1988 | + $smcFunc['db_query']('', ' |
|
1989 | 1989 | UPDATE {db_prefix}custom_fields |
1990 | 1990 | SET field_order = field_order - 1 |
1991 | 1991 | WHERE field_order > {int:current_order}', |
@@ -2249,7 +2249,7 @@ discard block |
||
2249 | 2249 | $context['token_check'] = 'noti-admin'; |
2250 | 2250 | |
2251 | 2251 | // Specify our action since we'll want to post back here instead of the profile |
2252 | - $context['action'] = 'action=admin;area=featuresettings;sa=alerts;'. $context['session_var'] .'='. $context['session_id']; |
|
2252 | + $context['action'] = 'action=admin;area=featuresettings;sa=alerts;' . $context['session_var'] . '=' . $context['session_id']; |
|
2253 | 2253 | |
2254 | 2254 | loadTemplate('Profile'); |
2255 | 2255 | loadLanguage('Profile'); |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * This function makes sure the requested subaction does exists, if it doesn't, it sets a default action or. |
@@ -205,16 +206,18 @@ discard block |
||
205 | 206 | { |
206 | 207 | $all_zones = timezone_identifiers_list(); |
207 | 208 | // Make sure we set the value to the same as the printed value. |
208 | - foreach ($all_zones as $zone) |
|
209 | - $config_vars['default_timezone'][2][$zone] = $zone; |
|
209 | + foreach ($all_zones as $zone) { |
|
210 | + $config_vars['default_timezone'][2][$zone] = $zone; |
|
211 | + } |
|
212 | + } else { |
|
213 | + unset($config_vars['default_timezone']); |
|
210 | 214 | } |
211 | - else |
|
212 | - unset($config_vars['default_timezone']); |
|
213 | 215 | |
214 | 216 | call_integration_hook('integrate_modify_basic_settings', array(&$config_vars)); |
215 | 217 | |
216 | - if ($return_config) |
|
217 | - return $config_vars; |
|
218 | + if ($return_config) { |
|
219 | + return $config_vars; |
|
220 | + } |
|
218 | 221 | |
219 | 222 | // Saving? |
220 | 223 | if (isset($_GET['save'])) |
@@ -222,8 +225,9 @@ discard block |
||
222 | 225 | checkSession(); |
223 | 226 | |
224 | 227 | // Prevent absurd boundaries here - make it a day tops. |
225 | - if (isset($_POST['lastActive'])) |
|
226 | - $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440); |
|
228 | + if (isset($_POST['lastActive'])) { |
|
229 | + $_POST['lastActive'] = min((int) $_POST['lastActive'], 1440); |
|
230 | + } |
|
227 | 231 | |
228 | 232 | call_integration_hook('integrate_save_basic_settings'); |
229 | 233 | |
@@ -268,8 +272,9 @@ discard block |
||
268 | 272 | |
269 | 273 | call_integration_hook('integrate_modify_bbc_settings', array(&$config_vars)); |
270 | 274 | |
271 | - if ($return_config) |
|
272 | - return $config_vars; |
|
275 | + if ($return_config) { |
|
276 | + return $config_vars; |
|
277 | + } |
|
273 | 278 | |
274 | 279 | // Setup the template. |
275 | 280 | require_once($sourcedir . '/ManageServer.php'); |
@@ -286,13 +291,15 @@ discard block |
||
286 | 291 | |
287 | 292 | // Clean up the tags. |
288 | 293 | $bbcTags = array(); |
289 | - foreach (parse_bbc(false) as $tag) |
|
290 | - $bbcTags[] = $tag['tag']; |
|
294 | + foreach (parse_bbc(false) as $tag) { |
|
295 | + $bbcTags[] = $tag['tag']; |
|
296 | + } |
|
291 | 297 | |
292 | - if (!isset($_POST['disabledBBC_enabledTags'])) |
|
293 | - $_POST['disabledBBC_enabledTags'] = array(); |
|
294 | - elseif (!is_array($_POST['disabledBBC_enabledTags'])) |
|
295 | - $_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']); |
|
298 | + if (!isset($_POST['disabledBBC_enabledTags'])) { |
|
299 | + $_POST['disabledBBC_enabledTags'] = array(); |
|
300 | + } elseif (!is_array($_POST['disabledBBC_enabledTags'])) { |
|
301 | + $_POST['disabledBBC_enabledTags'] = array($_POST['disabledBBC_enabledTags']); |
|
302 | + } |
|
296 | 303 | // Work out what is actually disabled! |
297 | 304 | $_POST['disabledBBC'] = implode(',', array_diff($bbcTags, $_POST['disabledBBC_enabledTags'])); |
298 | 305 | |
@@ -336,8 +343,9 @@ discard block |
||
336 | 343 | |
337 | 344 | call_integration_hook('integrate_layout_settings', array(&$config_vars)); |
338 | 345 | |
339 | - if ($return_config) |
|
340 | - return $config_vars; |
|
346 | + if ($return_config) { |
|
347 | + return $config_vars; |
|
348 | + } |
|
341 | 349 | |
342 | 350 | // Saving? |
343 | 351 | if (isset($_GET['save'])) |
@@ -378,8 +386,9 @@ discard block |
||
378 | 386 | |
379 | 387 | call_integration_hook('integrate_likes_settings', array(&$config_vars)); |
380 | 388 | |
381 | - if ($return_config) |
|
382 | - return $config_vars; |
|
389 | + if ($return_config) { |
|
390 | + return $config_vars; |
|
391 | + } |
|
383 | 392 | |
384 | 393 | // Saving? |
385 | 394 | if (isset($_GET['save'])) |
@@ -417,8 +426,9 @@ discard block |
||
417 | 426 | |
418 | 427 | call_integration_hook('integrate_mentions_settings', array(&$config_vars)); |
419 | 428 | |
420 | - if ($return_config) |
|
421 | - return $config_vars; |
|
429 | + if ($return_config) { |
|
430 | + return $config_vars; |
|
431 | + } |
|
422 | 432 | |
423 | 433 | // Saving? |
424 | 434 | if (isset($_GET['save'])) |
@@ -462,8 +472,8 @@ discard block |
||
462 | 472 | 'enable' => array('check', 'warning_enable'), |
463 | 473 | ); |
464 | 474 | |
465 | - if (!empty($modSettings['warning_settings']) && $currently_enabled) |
|
466 | - $config_vars += array( |
|
475 | + if (!empty($modSettings['warning_settings']) && $currently_enabled) { |
|
476 | + $config_vars += array( |
|
467 | 477 | '', |
468 | 478 | array('int', 'warning_watch', 'subtext' => $txt['setting_warning_watch_note'] . ' ' . $txt['zero_to_disable']), |
469 | 479 | 'moderate' => array('int', 'warning_moderate', 'subtext' => $txt['setting_warning_moderate_note'] . ' ' . $txt['zero_to_disable']), |
@@ -472,15 +482,18 @@ discard block |
||
472 | 482 | 'rem2' => array('int', 'warning_decrement', 'subtext' => $txt['setting_warning_decrement_note'] . ' ' . $txt['zero_to_disable']), |
473 | 483 | array('permissions', 'view_warning'), |
474 | 484 | ); |
485 | + } |
|
475 | 486 | |
476 | 487 | call_integration_hook('integrate_warning_settings', array(&$config_vars)); |
477 | 488 | |
478 | - if ($return_config) |
|
479 | - return $config_vars; |
|
489 | + if ($return_config) { |
|
490 | + return $config_vars; |
|
491 | + } |
|
480 | 492 | |
481 | 493 | // Cannot use moderation if post moderation is not enabled. |
482 | - if (!$modSettings['postmod_active']) |
|
483 | - unset($config_vars['moderate']); |
|
494 | + if (!$modSettings['postmod_active']) { |
|
495 | + unset($config_vars['moderate']); |
|
496 | + } |
|
484 | 497 | |
485 | 498 | // Will need the utility functions from here. |
486 | 499 | require_once($sourcedir . '/ManageServer.php'); |
@@ -505,16 +518,16 @@ discard block |
||
505 | 518 | 'warning_watch' => 10, |
506 | 519 | 'warning_mute' => 60, |
507 | 520 | ); |
508 | - if ($modSettings['postmod_active']) |
|
509 | - $vars['warning_moderate'] = 35; |
|
521 | + if ($modSettings['postmod_active']) { |
|
522 | + $vars['warning_moderate'] = 35; |
|
523 | + } |
|
510 | 524 | |
511 | 525 | foreach ($vars as $var => $value) |
512 | 526 | { |
513 | 527 | $config_vars[] = array('int', $var); |
514 | 528 | $_POST[$var] = $value; |
515 | 529 | } |
516 | - } |
|
517 | - else |
|
530 | + } else |
|
518 | 531 | { |
519 | 532 | $_POST['warning_watch'] = min($_POST['warning_watch'], 100); |
520 | 533 | $_POST['warning_moderate'] = $modSettings['postmod_active'] ? min($_POST['warning_moderate'], 100) : 0; |
@@ -595,8 +608,9 @@ discard block |
||
595 | 608 | |
596 | 609 | call_integration_hook('integrate_spam_settings', array(&$config_vars)); |
597 | 610 | |
598 | - if ($return_config) |
|
599 | - return $config_vars; |
|
611 | + if ($return_config) { |
|
612 | + return $config_vars; |
|
613 | + } |
|
600 | 614 | |
601 | 615 | // You need to be an admin to edit settings! |
602 | 616 | isAllowedTo('admin_forum'); |
@@ -630,8 +644,9 @@ discard block |
||
630 | 644 | |
631 | 645 | if (empty($context['qa_by_lang'][strtr($language, array('-utf8' => ''))]) && !empty($context['question_answers'])) |
632 | 646 | { |
633 | - if (empty($context['settings_insert_above'])) |
|
634 | - $context['settings_insert_above'] = ''; |
|
647 | + if (empty($context['settings_insert_above'])) { |
|
648 | + $context['settings_insert_above'] = ''; |
|
649 | + } |
|
635 | 650 | |
636 | 651 | $context['settings_insert_above'] .= '<div class="noticebox">' . sprintf($txt['question_not_defined'], $context['languages'][$language]['name']) . '</div>'; |
637 | 652 | } |
@@ -674,8 +689,9 @@ discard block |
||
674 | 689 | $_POST['pm_spam_settings'] = (int) $_POST['max_pm_recipients'] . ',' . (int) $_POST['pm_posts_verification'] . ',' . (int) $_POST['pm_posts_per_hour']; |
675 | 690 | |
676 | 691 | // Hack in guest requiring verification! |
677 | - if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) |
|
678 | - $_POST['posts_require_captcha'] = -1; |
|
692 | + if (empty($_POST['posts_require_captcha']) && !empty($_POST['guests_require_captcha'])) { |
|
693 | + $_POST['posts_require_captcha'] = -1; |
|
694 | + } |
|
679 | 695 | |
680 | 696 | $save_vars = $config_vars; |
681 | 697 | unset($save_vars['pm1'], $save_vars['pm2'], $save_vars['pm3'], $save_vars['guest_verify']); |
@@ -692,14 +708,16 @@ discard block |
||
692 | 708 | foreach ($context['qa_languages'] as $lang_id => $dummy) |
693 | 709 | { |
694 | 710 | // If we had some questions for this language before, but don't now, delete everything from that language. |
695 | - if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) |
|
696 | - $changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]); |
|
711 | + if ((!isset($_POST['question'][$lang_id]) || !is_array($_POST['question'][$lang_id])) && !empty($context['qa_by_lang'][$lang_id])) { |
|
712 | + $changes['delete'] = array_merge($questions['delete'], $context['qa_by_lang'][$lang_id]); |
|
713 | + } |
|
697 | 714 | |
698 | 715 | // Now step through and see if any existing questions no longer exist. |
699 | - if (!empty($context['qa_by_lang'][$lang_id])) |
|
700 | - foreach ($context['qa_by_lang'][$lang_id] as $q_id) |
|
716 | + if (!empty($context['qa_by_lang'][$lang_id])) { |
|
717 | + foreach ($context['qa_by_lang'][$lang_id] as $q_id) |
|
701 | 718 | if (empty($_POST['question'][$lang_id][$q_id])) |
702 | 719 | $changes['delete'][] = $q_id; |
720 | + } |
|
703 | 721 | |
704 | 722 | // Now let's see if there are new questions or ones that need updating. |
705 | 723 | if (isset($_POST['question'][$lang_id])) |
@@ -708,14 +726,16 @@ discard block |
||
708 | 726 | { |
709 | 727 | // Ignore junky ids. |
710 | 728 | $q_id = (int) $q_id; |
711 | - if ($q_id <= 0) |
|
712 | - continue; |
|
729 | + if ($q_id <= 0) { |
|
730 | + continue; |
|
731 | + } |
|
713 | 732 | |
714 | 733 | // Check the question isn't empty (because they want to delete it?) |
715 | 734 | if (empty($question) || trim($question) == '') |
716 | 735 | { |
717 | - if (isset($context['question_answers'][$q_id])) |
|
718 | - $changes['delete'][] = $q_id; |
|
736 | + if (isset($context['question_answers'][$q_id])) { |
|
737 | + $changes['delete'][] = $q_id; |
|
738 | + } |
|
719 | 739 | continue; |
720 | 740 | } |
721 | 741 | $question = $smcFunc['htmlspecialchars'](trim($question)); |
@@ -723,19 +743,22 @@ discard block |
||
723 | 743 | // Get the answers. Firstly check there actually might be some. |
724 | 744 | if (!isset($_POST['answer'][$lang_id][$q_id]) || !is_array($_POST['answer'][$lang_id][$q_id])) |
725 | 745 | { |
726 | - if (isset($context['question_answers'][$q_id])) |
|
727 | - $changes['delete'][] = $q_id; |
|
746 | + if (isset($context['question_answers'][$q_id])) { |
|
747 | + $changes['delete'][] = $q_id; |
|
748 | + } |
|
728 | 749 | continue; |
729 | 750 | } |
730 | 751 | // Now get them and check that they might be viable. |
731 | 752 | $answers = array(); |
732 | - foreach ($_POST['answer'][$lang_id][$q_id] as $answer) |
|
733 | - if (!empty($answer) && trim($answer) !== '') |
|
753 | + foreach ($_POST['answer'][$lang_id][$q_id] as $answer) { |
|
754 | + if (!empty($answer) && trim($answer) !== '') |
|
734 | 755 | $answers[] = $smcFunc['htmlspecialchars'](trim($answer)); |
756 | + } |
|
735 | 757 | if (empty($answers)) |
736 | 758 | { |
737 | - if (isset($context['question_answers'][$q_id])) |
|
738 | - $changes['delete'][] = $q_id; |
|
759 | + if (isset($context['question_answers'][$q_id])) { |
|
760 | + $changes['delete'][] = $q_id; |
|
761 | + } |
|
739 | 762 | continue; |
740 | 763 | } |
741 | 764 | $answers = json_encode($answers); |
@@ -745,16 +768,17 @@ discard block |
||
745 | 768 | { |
746 | 769 | // New question. Now, we don't want to randomly consume ids, so we'll set those, rather than trusting the browser's supplied ids. |
747 | 770 | $changes['insert'][] = array($lang_id, $question, $answers); |
748 | - } |
|
749 | - else |
|
771 | + } else |
|
750 | 772 | { |
751 | 773 | // It's an existing question. Let's see what's changed, if anything. |
752 | - if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) |
|
753 | - $changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers); |
|
774 | + if ($lang_id != $context['question_answers'][$q_id]['lngfile'] || $question != $context['question_answers'][$q_id]['question'] || $answers != $context['question_answers'][$q_id]['answers']) { |
|
775 | + $changes['replace'][$q_id] = array('lngfile' => $lang_id, 'question' => $question, 'answers' => $answers); |
|
776 | + } |
|
754 | 777 | } |
755 | 778 | |
756 | - if (!isset($qs_per_lang[$lang_id])) |
|
757 | - $qs_per_lang[$lang_id] = 0; |
|
779 | + if (!isset($qs_per_lang[$lang_id])) { |
|
780 | + $qs_per_lang[$lang_id] = 0; |
|
781 | + } |
|
758 | 782 | $qs_per_lang[$lang_id]++; |
759 | 783 | } |
760 | 784 | } |
@@ -804,8 +828,9 @@ discard block |
||
804 | 828 | |
805 | 829 | // Lastly, the count of messages needs to be no more than the lowest number of questions for any one language. |
806 | 830 | $count_questions = empty($qs_per_lang) ? 0 : min($qs_per_lang); |
807 | - if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) |
|
808 | - $_POST['qa_verification_number'] = $count_questions; |
|
831 | + if (empty($count_questions) || $_POST['qa_verification_number'] > $count_questions) { |
|
832 | + $_POST['qa_verification_number'] = $count_questions; |
|
833 | + } |
|
809 | 834 | |
810 | 835 | call_integration_hook('integrate_save_spam_settings', array(&$save_vars)); |
811 | 836 | |
@@ -820,24 +845,27 @@ discard block |
||
820 | 845 | |
821 | 846 | $character_range = array_merge(range('A', 'H'), array('K', 'M', 'N', 'P', 'R'), range('T', 'Y')); |
822 | 847 | $_SESSION['visual_verification_code'] = ''; |
823 | - for ($i = 0; $i < 6; $i++) |
|
824 | - $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)]; |
|
848 | + for ($i = 0; $i < 6; $i++) { |
|
849 | + $_SESSION['visual_verification_code'] .= $character_range[array_rand($character_range)]; |
|
850 | + } |
|
825 | 851 | |
826 | 852 | // Some javascript for CAPTCHA. |
827 | 853 | $context['settings_post_javascript'] = ''; |
828 | - if ($context['use_graphic_library']) |
|
829 | - $context['settings_post_javascript'] .= ' |
|
854 | + if ($context['use_graphic_library']) { |
|
855 | + $context['settings_post_javascript'] .= ' |
|
830 | 856 | function refreshImages() |
831 | 857 | { |
832 | 858 | var imageType = document.getElementById(\'visual_verification_type\').value; |
833 | 859 | document.getElementById(\'verification_image\').src = \'' . $context['verification_image_href'] . ';type=\' + imageType; |
834 | 860 | }'; |
861 | + } |
|
835 | 862 | |
836 | 863 | // Show the image itself, or text saying we can't. |
837 | - if ($context['use_graphic_library']) |
|
838 | - $config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>'; |
|
839 | - else |
|
840 | - $config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>'; |
|
864 | + if ($context['use_graphic_library']) { |
|
865 | + $config_vars['vv']['postinput'] = '<br><img src="' . $context['verification_image_href'] . ';type=' . (empty($modSettings['visual_verification_type']) ? 0 : $modSettings['visual_verification_type']) . '" alt="' . $txt['setting_image_verification_sample'] . '" id="verification_image"><br>'; |
|
866 | + } else { |
|
867 | + $config_vars['vv']['postinput'] = '<br><span class="smalltext">' . $txt['setting_image_verification_nogd'] . '</span>'; |
|
868 | + } |
|
841 | 869 | |
842 | 870 | // Hack for PM spam settings. |
843 | 871 | list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']); |
@@ -847,9 +875,10 @@ discard block |
||
847 | 875 | $modSettings['posts_require_captcha'] = !isset($modSettings['posts_require_captcha']) || $modSettings['posts_require_captcha'] == -1 ? 0 : $modSettings['posts_require_captcha']; |
848 | 876 | |
849 | 877 | // Some minor javascript for the guest post setting. |
850 | - if ($modSettings['posts_require_captcha']) |
|
851 | - $context['settings_post_javascript'] .= ' |
|
878 | + if ($modSettings['posts_require_captcha']) { |
|
879 | + $context['settings_post_javascript'] .= ' |
|
852 | 880 | document.getElementById(\'guests_require_captcha\').disabled = true;'; |
881 | + } |
|
853 | 882 | |
854 | 883 | // And everything else. |
855 | 884 | $context['post_url'] = $scripturl . '?action=admin;area=antispam;save'; |
@@ -896,8 +925,9 @@ discard block |
||
896 | 925 | |
897 | 926 | call_integration_hook('integrate_signature_settings', array(&$config_vars)); |
898 | 927 | |
899 | - if ($return_config) |
|
900 | - return $config_vars; |
|
928 | + if ($return_config) { |
|
929 | + return $config_vars; |
|
930 | + } |
|
901 | 931 | |
902 | 932 | // Setup the template. |
903 | 933 | $context['page_title'] = $txt['signature_settings']; |
@@ -952,8 +982,9 @@ discard block |
||
952 | 982 | $sig = strtr($row['signature'], array('<br>' => "\n")); |
953 | 983 | |
954 | 984 | // Max characters... |
955 | - if (!empty($sig_limits[1])) |
|
956 | - $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]); |
|
985 | + if (!empty($sig_limits[1])) { |
|
986 | + $sig = $smcFunc['substr']($sig, 0, $sig_limits[1]); |
|
987 | + } |
|
957 | 988 | // Max lines... |
958 | 989 | if (!empty($sig_limits[2])) |
959 | 990 | { |
@@ -963,8 +994,9 @@ discard block |
||
963 | 994 | if ($sig[$i] == "\n") |
964 | 995 | { |
965 | 996 | $count++; |
966 | - if ($count >= $sig_limits[2]) |
|
967 | - $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' ')); |
|
997 | + if ($count >= $sig_limits[2]) { |
|
998 | + $sig = substr($sig, 0, $i) . strtr(substr($sig, $i), array("\n" => ' ')); |
|
999 | + } |
|
968 | 1000 | } |
969 | 1001 | } |
970 | 1002 | } |
@@ -975,17 +1007,19 @@ discard block |
||
975 | 1007 | { |
976 | 1008 | $limit_broke = 0; |
977 | 1009 | // Attempt to allow all sizes of abuse, so to speak. |
978 | - if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) |
|
979 | - $limit_broke = $sig_limits[7] . 'px'; |
|
980 | - elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) |
|
981 | - $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
982 | - elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) |
|
983 | - $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
984 | - elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) |
|
985 | - $limit_broke = 'large'; |
|
986 | - |
|
987 | - if ($limit_broke) |
|
988 | - $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig); |
|
1010 | + if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) { |
|
1011 | + $limit_broke = $sig_limits[7] . 'px'; |
|
1012 | + } elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) { |
|
1013 | + $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
1014 | + } elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) { |
|
1015 | + $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
1016 | + } elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) { |
|
1017 | + $limit_broke = 'large'; |
|
1018 | + } |
|
1019 | + |
|
1020 | + if ($limit_broke) { |
|
1021 | + $sig = str_replace($matches[0][$ind], '[size=' . $sig_limits[7] . 'px', $sig); |
|
1022 | + } |
|
989 | 1023 | } |
990 | 1024 | } |
991 | 1025 | |
@@ -1041,32 +1075,34 @@ discard block |
||
1041 | 1075 | $img_offset = false; |
1042 | 1076 | } |
1043 | 1077 | } |
1078 | + } else { |
|
1079 | + $replaces[$image] = ''; |
|
1044 | 1080 | } |
1045 | - else |
|
1046 | - $replaces[$image] = ''; |
|
1047 | 1081 | |
1048 | 1082 | continue; |
1049 | 1083 | } |
1050 | 1084 | |
1051 | 1085 | // Does it have predefined restraints? Width first. |
1052 | - if ($matches[6][$key]) |
|
1053 | - $matches[2][$key] = $matches[6][$key]; |
|
1086 | + if ($matches[6][$key]) { |
|
1087 | + $matches[2][$key] = $matches[6][$key]; |
|
1088 | + } |
|
1054 | 1089 | if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) |
1055 | 1090 | { |
1056 | 1091 | $width = $sig_limits[5]; |
1057 | 1092 | $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]); |
1093 | + } elseif ($matches[2][$key]) { |
|
1094 | + $width = $matches[2][$key]; |
|
1058 | 1095 | } |
1059 | - elseif ($matches[2][$key]) |
|
1060 | - $width = $matches[2][$key]; |
|
1061 | 1096 | // ... and height. |
1062 | 1097 | if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) |
1063 | 1098 | { |
1064 | 1099 | $height = $sig_limits[6]; |
1065 | - if ($width != -1) |
|
1066 | - $width = $width * ($height / $matches[4][$key]); |
|
1100 | + if ($width != -1) { |
|
1101 | + $width = $width * ($height / $matches[4][$key]); |
|
1102 | + } |
|
1103 | + } elseif ($matches[4][$key]) { |
|
1104 | + $height = $matches[4][$key]; |
|
1067 | 1105 | } |
1068 | - elseif ($matches[4][$key]) |
|
1069 | - $height = $matches[4][$key]; |
|
1070 | 1106 | |
1071 | 1107 | // If the dimensions are still not fixed - we need to check the actual image. |
1072 | 1108 | if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6])) |
@@ -1084,12 +1120,13 @@ discard block |
||
1084 | 1120 | if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) |
1085 | 1121 | { |
1086 | 1122 | $height = $sig_limits[6]; |
1087 | - if ($width == -1) |
|
1088 | - $width = $sizes[0]; |
|
1123 | + if ($width == -1) { |
|
1124 | + $width = $sizes[0]; |
|
1125 | + } |
|
1089 | 1126 | $width = $width * ($height / $sizes[1]); |
1127 | + } elseif ($width != -1) { |
|
1128 | + $height = $sizes[1]; |
|
1090 | 1129 | } |
1091 | - elseif ($width != -1) |
|
1092 | - $height = $sizes[1]; |
|
1093 | 1130 | } |
1094 | 1131 | } |
1095 | 1132 | |
@@ -1102,8 +1139,9 @@ discard block |
||
1102 | 1139 | // Record that we got one. |
1103 | 1140 | $image_count_holder[$image] = isset($image_count_holder[$image]) ? $image_count_holder[$image] + 1 : 1; |
1104 | 1141 | } |
1105 | - if (!empty($replaces)) |
|
1106 | - $sig = str_replace(array_keys($replaces), array_values($replaces), $sig); |
|
1142 | + if (!empty($replaces)) { |
|
1143 | + $sig = str_replace(array_keys($replaces), array_values($replaces), $sig); |
|
1144 | + } |
|
1107 | 1145 | } |
1108 | 1146 | } |
1109 | 1147 | // Try to fix disabled tags. |
@@ -1115,18 +1153,20 @@ discard block |
||
1115 | 1153 | |
1116 | 1154 | $sig = strtr($sig, array("\n" => '<br>')); |
1117 | 1155 | call_integration_hook('integrate_apply_signature_settings', array(&$sig, $sig_limits, $disabledTags)); |
1118 | - if ($sig != $row['signature']) |
|
1119 | - $changes[$row['id_member']] = $sig; |
|
1156 | + if ($sig != $row['signature']) { |
|
1157 | + $changes[$row['id_member']] = $sig; |
|
1158 | + } |
|
1159 | + } |
|
1160 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1161 | + $done = true; |
|
1120 | 1162 | } |
1121 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1122 | - $done = true; |
|
1123 | 1163 | $smcFunc['db_free_result']($request); |
1124 | 1164 | |
1125 | 1165 | // Do we need to delete what we have? |
1126 | 1166 | if (!empty($changes)) |
1127 | 1167 | { |
1128 | - foreach ($changes as $id => $sig) |
|
1129 | - $smcFunc['db_query']('', ' |
|
1168 | + foreach ($changes as $id => $sig) { |
|
1169 | + $smcFunc['db_query']('', ' |
|
1130 | 1170 | UPDATE {db_prefix}members |
1131 | 1171 | SET signature = {string:signature} |
1132 | 1172 | WHERE id_member = {int:id_member}', |
@@ -1135,11 +1175,13 @@ discard block |
||
1135 | 1175 | 'signature' => $sig, |
1136 | 1176 | ) |
1137 | 1177 | ); |
1178 | + } |
|
1138 | 1179 | } |
1139 | 1180 | |
1140 | 1181 | $_GET['step'] += 50; |
1141 | - if (!$done) |
|
1142 | - pauseSignatureApplySettings(); |
|
1182 | + if (!$done) { |
|
1183 | + pauseSignatureApplySettings(); |
|
1184 | + } |
|
1143 | 1185 | } |
1144 | 1186 | $settings_applied = true; |
1145 | 1187 | } |
@@ -1157,8 +1199,9 @@ discard block |
||
1157 | 1199 | ); |
1158 | 1200 | |
1159 | 1201 | // Temporarily make each setting a modSetting! |
1160 | - foreach ($context['signature_settings'] as $key => $value) |
|
1161 | - $modSettings['signature_' . $key] = $value; |
|
1202 | + foreach ($context['signature_settings'] as $key => $value) { |
|
1203 | + $modSettings['signature_' . $key] = $value; |
|
1204 | + } |
|
1162 | 1205 | |
1163 | 1206 | // Make sure we check the right tags! |
1164 | 1207 | $modSettings['bbc_disabled_signature_bbc'] = $disabledTags; |
@@ -1170,23 +1213,26 @@ discard block |
||
1170 | 1213 | |
1171 | 1214 | // Clean up the tag stuff! |
1172 | 1215 | $bbcTags = array(); |
1173 | - foreach (parse_bbc(false) as $tag) |
|
1174 | - $bbcTags[] = $tag['tag']; |
|
1216 | + foreach (parse_bbc(false) as $tag) { |
|
1217 | + $bbcTags[] = $tag['tag']; |
|
1218 | + } |
|
1175 | 1219 | |
1176 | - if (!isset($_POST['signature_bbc_enabledTags'])) |
|
1177 | - $_POST['signature_bbc_enabledTags'] = array(); |
|
1178 | - elseif (!is_array($_POST['signature_bbc_enabledTags'])) |
|
1179 | - $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']); |
|
1220 | + if (!isset($_POST['signature_bbc_enabledTags'])) { |
|
1221 | + $_POST['signature_bbc_enabledTags'] = array(); |
|
1222 | + } elseif (!is_array($_POST['signature_bbc_enabledTags'])) { |
|
1223 | + $_POST['signature_bbc_enabledTags'] = array($_POST['signature_bbc_enabledTags']); |
|
1224 | + } |
|
1180 | 1225 | |
1181 | 1226 | $sig_limits = array(); |
1182 | 1227 | foreach ($context['signature_settings'] as $key => $value) |
1183 | 1228 | { |
1184 | - if ($key == 'allow_smileys') |
|
1185 | - continue; |
|
1186 | - elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) |
|
1187 | - $sig_limits[] = -1; |
|
1188 | - else |
|
1189 | - $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0; |
|
1229 | + if ($key == 'allow_smileys') { |
|
1230 | + continue; |
|
1231 | + } elseif ($key == 'max_smileys' && empty($_POST['signature_allow_smileys'])) { |
|
1232 | + $sig_limits[] = -1; |
|
1233 | + } else { |
|
1234 | + $sig_limits[] = !empty($_POST['signature_' . $key]) ? max(1, (int) $_POST['signature_' . $key]) : 0; |
|
1235 | + } |
|
1190 | 1236 | } |
1191 | 1237 | |
1192 | 1238 | call_integration_hook('integrate_save_signature_settings', array(&$sig_limits, &$bbcTags)); |
@@ -1219,12 +1265,14 @@ discard block |
||
1219 | 1265 | |
1220 | 1266 | // Try get more time... |
1221 | 1267 | @set_time_limit(600); |
1222 | - if (function_exists('apache_reset_timeout')) |
|
1223 | - @apache_reset_timeout(); |
|
1268 | + if (function_exists('apache_reset_timeout')) { |
|
1269 | + @apache_reset_timeout(); |
|
1270 | + } |
|
1224 | 1271 | |
1225 | 1272 | // Have we exhausted all the time we allowed? |
1226 | - if (time() - array_sum(explode(' ', $sig_start)) < 3) |
|
1227 | - return; |
|
1273 | + if (time() - array_sum(explode(' ', $sig_start)) < 3) { |
|
1274 | + return; |
|
1275 | + } |
|
1228 | 1276 | |
1229 | 1277 | $context['continue_get_data'] = '?action=admin;area=featuresettings;sa=sig;apply;step=' . $_GET['step'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
1230 | 1278 | $context['page_title'] = $txt['not_done_title']; |
@@ -1270,9 +1318,10 @@ discard block |
||
1270 | 1318 | $disable_fields = array_flip($standard_fields); |
1271 | 1319 | if (!empty($_POST['active'])) |
1272 | 1320 | { |
1273 | - foreach ($_POST['active'] as $value) |
|
1274 | - if (isset($disable_fields[$value])) |
|
1321 | + foreach ($_POST['active'] as $value) { |
|
1322 | + if (isset($disable_fields[$value])) |
|
1275 | 1323 | unset($disable_fields[$value]); |
1324 | + } |
|
1276 | 1325 | } |
1277 | 1326 | // What we have left! |
1278 | 1327 | $changes['disabled_profile_fields'] = empty($disable_fields) ? '' : implode(',', array_keys($disable_fields)); |
@@ -1281,16 +1330,18 @@ discard block |
||
1281 | 1330 | $reg_fields = array(); |
1282 | 1331 | if (!empty($_POST['reg'])) |
1283 | 1332 | { |
1284 | - foreach ($_POST['reg'] as $value) |
|
1285 | - if (in_array($value, $standard_fields) && !isset($disable_fields[$value])) |
|
1333 | + foreach ($_POST['reg'] as $value) { |
|
1334 | + if (in_array($value, $standard_fields) && !isset($disable_fields[$value])) |
|
1286 | 1335 | $reg_fields[] = $value; |
1336 | + } |
|
1287 | 1337 | } |
1288 | 1338 | // What we have left! |
1289 | 1339 | $changes['registration_fields'] = empty($reg_fields) ? '' : implode(',', $reg_fields); |
1290 | 1340 | |
1291 | 1341 | $_SESSION['adm-save'] = true; |
1292 | - if (!empty($changes)) |
|
1293 | - updateSettings($changes); |
|
1342 | + if (!empty($changes)) { |
|
1343 | + updateSettings($changes); |
|
1344 | + } |
|
1294 | 1345 | } |
1295 | 1346 | |
1296 | 1347 | createToken('admin-scp'); |
@@ -1393,11 +1444,13 @@ discard block |
||
1393 | 1444 | { |
1394 | 1445 | $return = '<p class="centertext bold_text">'. $rowData['field_order'] .'<br />'; |
1395 | 1446 | |
1396 | - if ($rowData['field_order'] > 1) |
|
1397 | - $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>'; |
|
1447 | + if ($rowData['field_order'] > 1) { |
|
1448 | + $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=up"><span class="toggle_up" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_up'] .'"></span></a>'; |
|
1449 | + } |
|
1398 | 1450 | |
1399 | - if ($rowData['field_order'] < $context['custFieldsMaxOrder']) |
|
1400 | - $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>'; |
|
1451 | + if ($rowData['field_order'] < $context['custFieldsMaxOrder']) { |
|
1452 | + $return .= '<a href="' . $scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $rowData['id_field'] . ';move=down"><span class="toggle_down" title="'. $txt['custom_edit_order_move'] .' '. $txt['custom_edit_order_down'] .'"></span></a>'; |
|
1453 | + } |
|
1401 | 1454 | |
1402 | 1455 | $return .= '</p>'; |
1403 | 1456 | |
@@ -1535,16 +1588,16 @@ discard block |
||
1535 | 1588 | $disabled_fields = isset($modSettings['disabled_profile_fields']) ? explode(',', $modSettings['disabled_profile_fields']) : array(); |
1536 | 1589 | $registration_fields = isset($modSettings['registration_fields']) ? explode(',', $modSettings['registration_fields']) : array(); |
1537 | 1590 | |
1538 | - foreach ($standard_fields as $field) |
|
1539 | - $list[] = array( |
|
1591 | + foreach ($standard_fields as $field) { |
|
1592 | + $list[] = array( |
|
1540 | 1593 | 'id' => $field, |
1541 | 1594 | 'label' => isset($txt['standard_profile_field_' . $field]) ? $txt['standard_profile_field_' . $field] : (isset($txt[$field]) ? $txt[$field] : $field), |
1542 | 1595 | 'disabled' => in_array($field, $disabled_fields), |
1543 | 1596 | 'on_register' => in_array($field, $registration_fields) && !in_array($field, $fields_no_registration), |
1544 | 1597 | 'can_show_register' => !in_array($field, $fields_no_registration), |
1545 | 1598 | ); |
1546 | - } |
|
1547 | - else |
|
1599 | + } |
|
1600 | + } else |
|
1548 | 1601 | { |
1549 | 1602 | // Load all the fields. |
1550 | 1603 | $request = $smcFunc['db_query']('', ' |
@@ -1558,8 +1611,9 @@ discard block |
||
1558 | 1611 | 'items_per_page' => $items_per_page, |
1559 | 1612 | ) |
1560 | 1613 | ); |
1561 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1562 | - $list[] = $row; |
|
1614 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1615 | + $list[] = $row; |
|
1616 | + } |
|
1563 | 1617 | $smcFunc['db_free_result']($request); |
1564 | 1618 | } |
1565 | 1619 | |
@@ -1625,9 +1679,9 @@ discard block |
||
1625 | 1679 | $context['field'] = array(); |
1626 | 1680 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1627 | 1681 | { |
1628 | - if ($row['field_type'] == 'textarea') |
|
1629 | - @list ($rows, $cols) = @explode(',', $row['default_value']); |
|
1630 | - else |
|
1682 | + if ($row['field_type'] == 'textarea') { |
|
1683 | + @list ($rows, $cols) = @explode(',', $row['default_value']); |
|
1684 | + } else |
|
1631 | 1685 | { |
1632 | 1686 | $rows = 3; |
1633 | 1687 | $cols = 30; |
@@ -1663,8 +1717,8 @@ discard block |
||
1663 | 1717 | } |
1664 | 1718 | |
1665 | 1719 | // Setup the default values as needed. |
1666 | - if (empty($context['field'])) |
|
1667 | - $context['field'] = array( |
|
1720 | + if (empty($context['field'])) { |
|
1721 | + $context['field'] = array( |
|
1668 | 1722 | 'name' => '', |
1669 | 1723 | 'col_name' => '???', |
1670 | 1724 | 'desc' => '', |
@@ -1689,6 +1743,7 @@ discard block |
||
1689 | 1743 | 'enclose' => '', |
1690 | 1744 | 'placement' => 0, |
1691 | 1745 | ); |
1746 | + } |
|
1692 | 1747 | |
1693 | 1748 | // Are we moving it? |
1694 | 1749 | if (isset($_GET['move']) && in_array($smcFunc['htmlspecialchars']($_GET['move']), $move_to)) |
@@ -1697,8 +1752,10 @@ discard block |
||
1697 | 1752 | $new_order = ($_GET['move'] == 'up' ? ($context['field']['order'] - 1) : ($context['field']['order'] + 1)); |
1698 | 1753 | |
1699 | 1754 | // Is this a valid position? |
1700 | - if ($new_order <= 0 || $new_order > $order_count) |
|
1701 | - redirectexit('action=admin;area=featuresettings;sa=profile'); // @todo implement an error handler |
|
1755 | + if ($new_order <= 0 || $new_order > $order_count) { |
|
1756 | + redirectexit('action=admin;area=featuresettings;sa=profile'); |
|
1757 | + } |
|
1758 | + // @todo implement an error handler |
|
1702 | 1759 | |
1703 | 1760 | // All good, proceed. |
1704 | 1761 | $smcFunc['db_query']('',' |
@@ -1729,12 +1786,14 @@ discard block |
||
1729 | 1786 | validateToken('admin-ecp'); |
1730 | 1787 | |
1731 | 1788 | // Everyone needs a name - even the (bracket) unknown... |
1732 | - if (trim($_POST['field_name']) == '') |
|
1733 | - redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name'); |
|
1789 | + if (trim($_POST['field_name']) == '') { |
|
1790 | + redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=need_name'); |
|
1791 | + } |
|
1734 | 1792 | |
1735 | 1793 | // Regex you say? Do a very basic test to see if the pattern is valid |
1736 | - if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) |
|
1737 | - redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error'); |
|
1794 | + if (!empty($_POST['regex']) && @preg_match($_POST['regex'], 'dummy') === false) { |
|
1795 | + redirectexit($scripturl . '?action=admin;area=featuresettings;sa=profileedit;fid=' . $_GET['fid'] . ';msg=regex_error'); |
|
1796 | + } |
|
1738 | 1797 | |
1739 | 1798 | $_POST['field_name'] = $smcFunc['htmlspecialchars']($_POST['field_name']); |
1740 | 1799 | $_POST['field_desc'] = $smcFunc['htmlspecialchars']($_POST['field_desc']); |
@@ -1751,8 +1810,9 @@ discard block |
||
1751 | 1810 | |
1752 | 1811 | // Some masking stuff... |
1753 | 1812 | $mask = isset($_POST['mask']) ? $_POST['mask'] : ''; |
1754 | - if ($mask == 'regex' && isset($_POST['regex'])) |
|
1755 | - $mask .= $_POST['regex']; |
|
1813 | + if ($mask == 'regex' && isset($_POST['regex'])) { |
|
1814 | + $mask .= $_POST['regex']; |
|
1815 | + } |
|
1756 | 1816 | |
1757 | 1817 | $field_length = isset($_POST['max_length']) ? (int) $_POST['max_length'] : 255; |
1758 | 1818 | $enclose = isset($_POST['enclose']) ? $_POST['enclose'] : ''; |
@@ -1771,8 +1831,9 @@ discard block |
||
1771 | 1831 | $v = strtr($v, array(',' => '')); |
1772 | 1832 | |
1773 | 1833 | // Nada, zip, etc... |
1774 | - if (trim($v) == '') |
|
1775 | - continue; |
|
1834 | + if (trim($v) == '') { |
|
1835 | + continue; |
|
1836 | + } |
|
1776 | 1837 | |
1777 | 1838 | // Otherwise, save it boy. |
1778 | 1839 | $field_options .= $v . ','; |
@@ -1780,15 +1841,17 @@ discard block |
||
1780 | 1841 | $newOptions[$k] = $v; |
1781 | 1842 | |
1782 | 1843 | // Is it default? |
1783 | - if (isset($_POST['default_select']) && $_POST['default_select'] == $k) |
|
1784 | - $default = $v; |
|
1844 | + if (isset($_POST['default_select']) && $_POST['default_select'] == $k) { |
|
1845 | + $default = $v; |
|
1846 | + } |
|
1785 | 1847 | } |
1786 | 1848 | $field_options = substr($field_options, 0, -1); |
1787 | 1849 | } |
1788 | 1850 | |
1789 | 1851 | // Text area has default has dimensions |
1790 | - if ($_POST['field_type'] == 'textarea') |
|
1791 | - $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols']; |
|
1852 | + if ($_POST['field_type'] == 'textarea') { |
|
1853 | + $default = (int) $_POST['rows'] . ',' . (int) $_POST['cols']; |
|
1854 | + } |
|
1792 | 1855 | |
1793 | 1856 | // Come up with the unique name? |
1794 | 1857 | if (empty($context['fid'])) |
@@ -1797,32 +1860,36 @@ discard block |
||
1797 | 1860 | preg_match('~([\w\d_-]+)~', $col_name, $matches); |
1798 | 1861 | |
1799 | 1862 | // If there is nothing to the name, then let's start out own - for foreign languages etc. |
1800 | - if (isset($matches[1])) |
|
1801 | - $col_name = $initial_col_name = 'cust_' . strtolower($matches[1]); |
|
1802 | - else |
|
1803 | - $col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999); |
|
1863 | + if (isset($matches[1])) { |
|
1864 | + $col_name = $initial_col_name = 'cust_' . strtolower($matches[1]); |
|
1865 | + } else { |
|
1866 | + $col_name = $initial_col_name = 'cust_' . mt_rand(1, 9999); |
|
1867 | + } |
|
1804 | 1868 | |
1805 | 1869 | // Make sure this is unique. |
1806 | 1870 | $current_fields = array(); |
1807 | 1871 | $request = $smcFunc['db_query']('', ' |
1808 | 1872 | SELECT id_field, col_name |
1809 | 1873 | FROM {db_prefix}custom_fields'); |
1810 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1811 | - $current_fields[$row['id_field']] = $row['col_name']; |
|
1874 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1875 | + $current_fields[$row['id_field']] = $row['col_name']; |
|
1876 | + } |
|
1812 | 1877 | $smcFunc['db_free_result']($request); |
1813 | 1878 | |
1814 | 1879 | $unique = false; |
1815 | 1880 | for ($i = 0; !$unique && $i < 9; $i ++) |
1816 | 1881 | { |
1817 | - if (!in_array($col_name, $current_fields)) |
|
1818 | - $unique = true; |
|
1819 | - else |
|
1820 | - $col_name = $initial_col_name . $i; |
|
1882 | + if (!in_array($col_name, $current_fields)) { |
|
1883 | + $unique = true; |
|
1884 | + } else { |
|
1885 | + $col_name = $initial_col_name . $i; |
|
1886 | + } |
|
1821 | 1887 | } |
1822 | 1888 | |
1823 | 1889 | // Still not a unique column name? Leave it up to the user, then. |
1824 | - if (!$unique) |
|
1825 | - fatal_lang_error('custom_option_not_unique'); |
|
1890 | + if (!$unique) { |
|
1891 | + fatal_lang_error('custom_option_not_unique'); |
|
1892 | + } |
|
1826 | 1893 | } |
1827 | 1894 | // Work out what to do with the user data otherwise... |
1828 | 1895 | else |
@@ -1850,8 +1917,9 @@ discard block |
||
1850 | 1917 | // Work out what's changed! |
1851 | 1918 | foreach ($context['field']['options'] as $k => $option) |
1852 | 1919 | { |
1853 | - if (trim($option) == '') |
|
1854 | - continue; |
|
1920 | + if (trim($option) == '') { |
|
1921 | + continue; |
|
1922 | + } |
|
1855 | 1923 | |
1856 | 1924 | // Still exists? |
1857 | 1925 | if (in_array($option, $newOptions)) |
@@ -1865,8 +1933,8 @@ discard block |
||
1865 | 1933 | foreach ($optionChanges as $k => $option) |
1866 | 1934 | { |
1867 | 1935 | // Just been renamed? |
1868 | - if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) |
|
1869 | - $smcFunc['db_query']('', ' |
|
1936 | + if (!in_array($k, $takenKeys) && !empty($newOptions[$k])) { |
|
1937 | + $smcFunc['db_query']('', ' |
|
1870 | 1938 | UPDATE {db_prefix}themes |
1871 | 1939 | SET value = {string:new_value} |
1872 | 1940 | WHERE variable = {string:current_column} |
@@ -1879,6 +1947,7 @@ discard block |
||
1879 | 1947 | 'old_value' => $option, |
1880 | 1948 | ) |
1881 | 1949 | ); |
1950 | + } |
|
1882 | 1951 | } |
1883 | 1952 | } |
1884 | 1953 | // @todo Maybe we should adjust based on new text length limits? |
@@ -1921,8 +1990,8 @@ discard block |
||
1921 | 1990 | ); |
1922 | 1991 | |
1923 | 1992 | // Just clean up any old selects - these are a pain! |
1924 | - if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) |
|
1925 | - $smcFunc['db_query']('', ' |
|
1993 | + if (($_POST['field_type'] == 'select' || $_POST['field_type'] == 'radio') && !empty($newOptions)) { |
|
1994 | + $smcFunc['db_query']('', ' |
|
1926 | 1995 | DELETE FROM {db_prefix}themes |
1927 | 1996 | WHERE variable = {string:current_column} |
1928 | 1997 | AND value NOT IN ({array_string:new_option_values}) |
@@ -1933,8 +2002,8 @@ discard block |
||
1933 | 2002 | 'current_column' => $context['field']['col_name'], |
1934 | 2003 | ) |
1935 | 2004 | ); |
1936 | - } |
|
1937 | - else |
|
2005 | + } |
|
2006 | + } else |
|
1938 | 2007 | { |
1939 | 2008 | // Gotta figure it out the order. |
1940 | 2009 | $new_order = $order_count > 1 ? ($order_count + 1) : 1; |
@@ -2108,11 +2177,13 @@ discard block |
||
2108 | 2177 | call_integration_hook('integrate_prune_settings', array(&$config_vars, &$prune_toggle, false)); |
2109 | 2178 | |
2110 | 2179 | $prune_toggle_dt = array(); |
2111 | - foreach ($prune_toggle as $item) |
|
2112 | - $prune_toggle_dt[] = 'setting_' . $item; |
|
2180 | + foreach ($prune_toggle as $item) { |
|
2181 | + $prune_toggle_dt[] = 'setting_' . $item; |
|
2182 | + } |
|
2113 | 2183 | |
2114 | - if ($return_config) |
|
2115 | - return $config_vars; |
|
2184 | + if ($return_config) { |
|
2185 | + return $config_vars; |
|
2186 | + } |
|
2116 | 2187 | |
2117 | 2188 | addInlineJavaScript(' |
2118 | 2189 | function togglePruned() |
@@ -2150,15 +2221,16 @@ discard block |
||
2150 | 2221 | $vals = array(); |
2151 | 2222 | foreach ($config_vars as $index => $dummy) |
2152 | 2223 | { |
2153 | - if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) |
|
2154 | - continue; |
|
2224 | + if (!is_array($dummy) || $index == 'pruningOptions' || !in_array($dummy[1], $prune_toggle)) { |
|
2225 | + continue; |
|
2226 | + } |
|
2155 | 2227 | |
2156 | 2228 | $vals[] = empty($_POST[$dummy[1]]) || $_POST[$dummy[1]] < 0 ? 0 : (int) $_POST[$dummy[1]]; |
2157 | 2229 | } |
2158 | 2230 | $_POST['pruningOptions'] = implode(',', $vals); |
2231 | + } else { |
|
2232 | + $_POST['pruningOptions'] = ''; |
|
2159 | 2233 | } |
2160 | - else |
|
2161 | - $_POST['pruningOptions'] = ''; |
|
2162 | 2234 | |
2163 | 2235 | saveDBSettings($savevar); |
2164 | 2236 | $_SESSION['adm-save'] = true; |
@@ -2170,10 +2242,11 @@ discard block |
||
2170 | 2242 | $context['sub_template'] = 'show_settings'; |
2171 | 2243 | |
2172 | 2244 | // Get the actual values |
2173 | - if (!empty($modSettings['pruningOptions'])) |
|
2174 | - @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
2175 | - else |
|
2176 | - $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0; |
|
2245 | + if (!empty($modSettings['pruningOptions'])) { |
|
2246 | + @list ($modSettings['pruneErrorLog'], $modSettings['pruneModLog'], $modSettings['pruneBanLog'], $modSettings['pruneReportLog'], $modSettings['pruneScheduledTaskLog'], $modSettings['pruneSpiderHitLog']) = explode(',', $modSettings['pruningOptions']); |
|
2247 | + } else { |
|
2248 | + $modSettings['pruneErrorLog'] = $modSettings['pruneModLog'] = $modSettings['pruneBanLog'] = $modSettings['pruneReportLog'] = $modSettings['pruneScheduledTaskLog'] = $modSettings['pruneSpiderHitLog'] = 0; |
|
2249 | + } |
|
2177 | 2250 | |
2178 | 2251 | prepareDBSettingContext($config_vars); |
2179 | 2252 | } |
@@ -2195,8 +2268,9 @@ discard block |
||
2195 | 2268 | // Make it even easier to add new settings. |
2196 | 2269 | call_integration_hook('integrate_general_mod_settings', array(&$config_vars)); |
2197 | 2270 | |
2198 | - if ($return_config) |
|
2199 | - return $config_vars; |
|
2271 | + if ($return_config) { |
|
2272 | + return $config_vars; |
|
2273 | + } |
|
2200 | 2274 | |
2201 | 2275 | $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=general'; |
2202 | 2276 | $context['settings_title'] = $txt['mods_cat_modifications_misc']; |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('Hacking attempt...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Interface cache_api_interface |
@@ -186,8 +187,9 @@ discard block |
||
186 | 187 | { |
187 | 188 | global $cache_enable; |
188 | 189 | |
189 | - if ($test) |
|
190 | - return true; |
|
190 | + if ($test) { |
|
191 | + return true; |
|
192 | + } |
|
191 | 193 | return !empty($cache_enable); |
192 | 194 | } |
193 | 195 | |
@@ -206,10 +208,11 @@ discard block |
||
206 | 208 | global $boardurl, $cachedir; |
207 | 209 | |
208 | 210 | // Set the default if no prefix was specified. |
209 | - if (empty($prefix)) |
|
210 | - $this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-'; |
|
211 | - else |
|
212 | - $this->prefix = $prefix; |
|
211 | + if (empty($prefix)) { |
|
212 | + $this->prefix = md5($boardurl . filemtime($cachedir . '/' . 'index.php')) . '-SMF-'; |
|
213 | + } else { |
|
214 | + $this->prefix = $prefix; |
|
215 | + } |
|
213 | 216 | |
214 | 217 | return true; |
215 | 218 | } |
@@ -272,8 +275,9 @@ discard block |
||
272 | 275 | |
273 | 276 | // Invalidate cache, to be sure! |
274 | 277 | // ... as long as index.php can be modified, anyway. |
275 | - if (is_writable($cachedir . '/' . 'index.php')) |
|
276 | - @touch($cachedir . '/' . 'index.php'); |
|
278 | + if (is_writable($cachedir . '/' . 'index.php')) { |
|
279 | + @touch($cachedir . '/' . 'index.php'); |
|
280 | + } |
|
277 | 281 | |
278 | 282 | return true; |
279 | 283 | } |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 3 |
16 | 16 | */ |
17 | 17 | |
18 | -if (!defined('SMF')) |
|
18 | +if (!defined('SMF')) { |
|
19 | 19 | die('No direct access...'); |
20 | +} |
|
20 | 21 | |
21 | 22 | /** |
22 | 23 | * Begin the registration process. |
@@ -29,19 +30,23 @@ discard block |
||
29 | 30 | global $language, $scripturl, $smcFunc, $sourcedir, $cur_profile; |
30 | 31 | |
31 | 32 | // Is this an incoming AJAX check? |
32 | - if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') |
|
33 | - return RegisterCheckUsername(); |
|
33 | + if (isset($_GET['sa']) && $_GET['sa'] == 'usernamecheck') { |
|
34 | + return RegisterCheckUsername(); |
|
35 | + } |
|
34 | 36 | |
35 | 37 | // Check if the administrator has it disabled. |
36 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') |
|
37 | - fatal_lang_error('registration_disabled', false); |
|
38 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == '3') { |
|
39 | + fatal_lang_error('registration_disabled', false); |
|
40 | + } |
|
38 | 41 | |
39 | 42 | // If this user is an admin - redirect them to the admin registration page. |
40 | - if (allowedTo('moderate_forum') && !$user_info['is_guest']) |
|
41 | - redirectexit('action=admin;area=regcenter;sa=register'); |
|
43 | + if (allowedTo('moderate_forum') && !$user_info['is_guest']) { |
|
44 | + redirectexit('action=admin;area=regcenter;sa=register'); |
|
45 | + } |
|
42 | 46 | // You are not a guest, so you are a member - and members don't get to register twice! |
43 | - elseif (empty($user_info['is_guest'])) |
|
44 | - redirectexit(); |
|
47 | + elseif (empty($user_info['is_guest'])) { |
|
48 | + redirectexit(); |
|
49 | + } |
|
45 | 50 | |
46 | 51 | loadLanguage('Login'); |
47 | 52 | loadTemplate('Register'); |
@@ -82,16 +87,18 @@ discard block |
||
82 | 87 | } |
83 | 88 | } |
84 | 89 | // Make sure they don't squeeze through without agreeing. |
85 | - elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) |
|
86 | - $current_step = 1; |
|
90 | + elseif ($current_step > 1 && $context['require_agreement'] && !$context['registration_passed_agreement']) { |
|
91 | + $current_step = 1; |
|
92 | + } |
|
87 | 93 | |
88 | 94 | // Show the user the right form. |
89 | 95 | $context['sub_template'] = $current_step == 1 ? 'registration_agreement' : 'registration_form'; |
90 | 96 | $context['page_title'] = $current_step == 1 ? $txt['registration_agreement'] : $txt['registration_form']; |
91 | 97 | |
92 | 98 | // Kinda need this. |
93 | - if ($context['sub_template'] == 'registration_form') |
|
94 | - loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
99 | + if ($context['sub_template'] == 'registration_form') { |
|
100 | + loadJavaScriptFile('register.js', array('defer' => false), 'smf_register'); |
|
101 | + } |
|
95 | 102 | |
96 | 103 | // Add the register chain to the link tree. |
97 | 104 | $context['linktree'][] = array( |
@@ -100,24 +107,26 @@ discard block |
||
100 | 107 | ); |
101 | 108 | |
102 | 109 | // Prepare the time gate! Do it like so, in case later steps want to reset the limit for any reason, but make sure the time is the current one. |
103 | - if (!isset($_SESSION['register'])) |
|
104 | - $_SESSION['register'] = array( |
|
110 | + if (!isset($_SESSION['register'])) { |
|
111 | + $_SESSION['register'] = array( |
|
105 | 112 | 'timenow' => time(), |
106 | 113 | 'limit' => 10, // minimum number of seconds required on this page for registration |
107 | 114 | ); |
108 | - else |
|
109 | - $_SESSION['register']['timenow'] = time(); |
|
115 | + } else { |
|
116 | + $_SESSION['register']['timenow'] = time(); |
|
117 | + } |
|
110 | 118 | |
111 | 119 | // If you have to agree to the agreement, it needs to be fetched from the file. |
112 | 120 | if ($context['require_agreement']) |
113 | 121 | { |
114 | 122 | // Have we got a localized one? |
115 | - if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) |
|
116 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
117 | - elseif (file_exists($boarddir . '/agreement.txt')) |
|
118 | - $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
119 | - else |
|
120 | - $context['agreement'] = ''; |
|
123 | + if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt')) { |
|
124 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']); |
|
125 | + } elseif (file_exists($boarddir . '/agreement.txt')) { |
|
126 | + $context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement'); |
|
127 | + } else { |
|
128 | + $context['agreement'] = ''; |
|
129 | + } |
|
121 | 130 | |
122 | 131 | // Nothing to show, lets disable registration and inform the admin of this error |
123 | 132 | if (empty($context['agreement'])) |
@@ -133,8 +142,9 @@ discard block |
||
133 | 142 | $selectedLanguage = empty($_SESSION['language']) ? $language : $_SESSION['language']; |
134 | 143 | |
135 | 144 | // Do we have any languages? |
136 | - if (empty($context['languages'])) |
|
137 | - getLanguages(); |
|
145 | + if (empty($context['languages'])) { |
|
146 | + getLanguages(); |
|
147 | + } |
|
138 | 148 | |
139 | 149 | // Try to find our selected language. |
140 | 150 | foreach ($context['languages'] as $key => $lang) |
@@ -142,8 +152,9 @@ discard block |
||
142 | 152 | $context['languages'][$key]['name'] = strtr($lang['name'], array('-utf8' => '')); |
143 | 153 | |
144 | 154 | // Found it! |
145 | - if ($selectedLanguage == $lang['filename']) |
|
146 | - $context['languages'][$key]['selected'] = true; |
|
155 | + if ($selectedLanguage == $lang['filename']) { |
|
156 | + $context['languages'][$key]['selected'] = true; |
|
157 | + } |
|
147 | 158 | } |
148 | 159 | } |
149 | 160 | |
@@ -167,9 +178,10 @@ discard block |
||
167 | 178 | $reg_fields = explode(',', $modSettings['registration_fields']); |
168 | 179 | |
169 | 180 | // We might have had some submissions on this front - go check. |
170 | - foreach ($reg_fields as $field) |
|
171 | - if (isset($_POST[$field])) |
|
181 | + foreach ($reg_fields as $field) { |
|
182 | + if (isset($_POST[$field])) |
|
172 | 183 | $cur_profile[$field] = $smcFunc['htmlspecialchars']($_POST[$field]); |
184 | + } |
|
173 | 185 | |
174 | 186 | // Load all the fields in question. |
175 | 187 | setupProfileContext($reg_fields); |
@@ -186,8 +198,9 @@ discard block |
||
186 | 198 | $context['visual_verification_id'] = $verificationOptions['id']; |
187 | 199 | } |
188 | 200 | // Otherwise we have nothing to show. |
189 | - else |
|
190 | - $context['visual_verification'] = false; |
|
201 | + else { |
|
202 | + $context['visual_verification'] = false; |
|
203 | + } |
|
191 | 204 | |
192 | 205 | |
193 | 206 | $context += array( |
@@ -198,8 +211,9 @@ discard block |
||
198 | 211 | |
199 | 212 | // Were there any errors? |
200 | 213 | $context['registration_errors'] = array(); |
201 | - if (!empty($reg_errors)) |
|
202 | - $context['registration_errors'] = $reg_errors; |
|
214 | + if (!empty($reg_errors)) { |
|
215 | + $context['registration_errors'] = $reg_errors; |
|
216 | + } |
|
203 | 217 | |
204 | 218 | createToken('register'); |
205 | 219 | } |
@@ -216,27 +230,32 @@ discard block |
||
216 | 230 | validateToken('register'); |
217 | 231 | |
218 | 232 | // Check to ensure we're forcing SSL for authentication |
219 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
220 | - fatal_lang_error('register_ssl_required'); |
|
233 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
234 | + fatal_lang_error('register_ssl_required'); |
|
235 | + } |
|
221 | 236 | |
222 | 237 | // Start collecting together any errors. |
223 | 238 | $reg_errors = array(); |
224 | 239 | |
225 | 240 | // You can't register if it's disabled. |
226 | - if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) |
|
227 | - fatal_lang_error('registration_disabled', false); |
|
241 | + if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 3) { |
|
242 | + fatal_lang_error('registration_disabled', false); |
|
243 | + } |
|
228 | 244 | |
229 | 245 | // Well, if you don't agree, you can't register. |
230 | - if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) |
|
231 | - redirectexit(); |
|
246 | + if (!empty($modSettings['requireAgreement']) && empty($_SESSION['registration_agreed'])) { |
|
247 | + redirectexit(); |
|
248 | + } |
|
232 | 249 | |
233 | 250 | // Make sure they came from *somewhere*, have a session. |
234 | - if (!isset($_SESSION['old_url'])) |
|
235 | - redirectexit('action=signup'); |
|
251 | + if (!isset($_SESSION['old_url'])) { |
|
252 | + redirectexit('action=signup'); |
|
253 | + } |
|
236 | 254 | |
237 | 255 | // If we don't require an agreement, we need a extra check for coppa. |
238 | - if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) |
|
239 | - $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
256 | + if (empty($modSettings['requireAgreement']) && !empty($modSettings['coppaAge'])) { |
|
257 | + $_SESSION['skip_coppa'] = !empty($_POST['accept_agreement']); |
|
258 | + } |
|
240 | 259 | // Are they under age, and under age users are banned? |
241 | 260 | if (!empty($modSettings['coppaAge']) && empty($modSettings['coppaType']) && empty($_SESSION['skip_coppa'])) |
242 | 261 | { |
@@ -245,8 +264,9 @@ discard block |
||
245 | 264 | } |
246 | 265 | |
247 | 266 | // Check the time gate for miscreants. First make sure they came from somewhere that actually set it up. |
248 | - if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) |
|
249 | - redirectexit('action=signup'); |
|
267 | + if (empty($_SESSION['register']['timenow']) || empty($_SESSION['register']['limit'])) { |
|
268 | + redirectexit('action=signup'); |
|
269 | + } |
|
250 | 270 | // Failing that, check the time on it. |
251 | 271 | if (time() - $_SESSION['register']['timenow'] < $_SESSION['register']['limit']) |
252 | 272 | { |
@@ -266,15 +286,17 @@ discard block |
||
266 | 286 | if (is_array($context['visual_verification'])) |
267 | 287 | { |
268 | 288 | loadLanguage('Errors'); |
269 | - foreach ($context['visual_verification'] as $error) |
|
270 | - $reg_errors[] = $txt['error_' . $error]; |
|
289 | + foreach ($context['visual_verification'] as $error) { |
|
290 | + $reg_errors[] = $txt['error_' . $error]; |
|
291 | + } |
|
271 | 292 | } |
272 | 293 | } |
273 | 294 | |
274 | 295 | foreach ($_POST as $key => $value) |
275 | 296 | { |
276 | - if (!is_array($_POST[$key])) |
|
277 | - $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
297 | + if (!is_array($_POST[$key])) { |
|
298 | + $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); |
|
299 | + } |
|
278 | 300 | } |
279 | 301 | |
280 | 302 | // Collect all extra registration fields someone might have filled in. |
@@ -304,12 +326,14 @@ discard block |
||
304 | 326 | $reg_fields = explode(',', $modSettings['registration_fields']); |
305 | 327 | |
306 | 328 | // Website is a little different |
307 | - if (in_array('website', $reg_fields)) |
|
308 | - $possible_strings += array('website_url', 'website_title'); |
|
329 | + if (in_array('website', $reg_fields)) { |
|
330 | + $possible_strings += array('website_url', 'website_title'); |
|
331 | + } |
|
309 | 332 | } |
310 | 333 | |
311 | - if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') |
|
312 | - $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
334 | + if (isset($_POST['secret_answer']) && $_POST['secret_answer'] != '') { |
|
335 | + $_POST['secret_answer'] = md5($_POST['secret_answer']); |
|
336 | + } |
|
313 | 337 | |
314 | 338 | // Needed for isReservedName() and registerMember(). |
315 | 339 | require_once($sourcedir . '/Subs-Members.php'); |
@@ -318,32 +342,37 @@ discard block |
||
318 | 342 | if (isset($_POST['real_name']) && (allowedTo('profile_displayed_name') || allowedTo('moderate_forum'))) |
319 | 343 | { |
320 | 344 | $_POST['real_name'] = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $_POST['real_name'])); |
321 | - if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) |
|
322 | - $possible_strings[] = 'real_name'; |
|
345 | + if (trim($_POST['real_name']) != '' && !isReservedName($_POST['real_name']) && $smcFunc['strlen']($_POST['real_name']) < 60) { |
|
346 | + $possible_strings[] = 'real_name'; |
|
347 | + } |
|
323 | 348 | } |
324 | 349 | |
325 | 350 | // Handle a string as a birthdate... |
326 | - if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') |
|
327 | - $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
351 | + if (isset($_POST['birthdate']) && $_POST['birthdate'] != '') { |
|
352 | + $_POST['birthdate'] = strftime('%Y-%m-%d', strtotime($_POST['birthdate'])); |
|
353 | + } |
|
328 | 354 | // Or birthdate parts... |
329 | - elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) |
|
330 | - $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
355 | + elseif (!empty($_POST['bday1']) && !empty($_POST['bday2'])) { |
|
356 | + $_POST['birthdate'] = sprintf('%04d-%02d-%02d', empty($_POST['bday3']) ? 0 : (int) $_POST['bday3'], (int) $_POST['bday1'], (int) $_POST['bday2']); |
|
357 | + } |
|
331 | 358 | |
332 | 359 | // Validate the passed language file. |
333 | 360 | if (isset($_POST['lngfile']) && !empty($modSettings['userLanguage'])) |
334 | 361 | { |
335 | 362 | // Do we have any languages? |
336 | - if (empty($context['languages'])) |
|
337 | - getLanguages(); |
|
363 | + if (empty($context['languages'])) { |
|
364 | + getLanguages(); |
|
365 | + } |
|
338 | 366 | |
339 | 367 | // Did we find it? |
340 | - if (isset($context['languages'][$_POST['lngfile']])) |
|
341 | - $_SESSION['language'] = $_POST['lngfile']; |
|
342 | - else |
|
368 | + if (isset($context['languages'][$_POST['lngfile']])) { |
|
369 | + $_SESSION['language'] = $_POST['lngfile']; |
|
370 | + } else { |
|
371 | + unset($_POST['lngfile']); |
|
372 | + } |
|
373 | + } else { |
|
343 | 374 | unset($_POST['lngfile']); |
344 | 375 | } |
345 | - else |
|
346 | - unset($_POST['lngfile']); |
|
347 | 376 | |
348 | 377 | // Set the options needed for registration. |
349 | 378 | $regOptions = array( |
@@ -363,22 +392,27 @@ discard block |
||
363 | 392 | ); |
364 | 393 | |
365 | 394 | // Include the additional options that might have been filled in. |
366 | - foreach ($possible_strings as $var) |
|
367 | - if (isset($_POST[$var])) |
|
395 | + foreach ($possible_strings as $var) { |
|
396 | + if (isset($_POST[$var])) |
|
368 | 397 | $regOptions['extra_register_vars'][$var] = $smcFunc['htmlspecialchars']($_POST[$var], ENT_QUOTES); |
369 | - foreach ($possible_ints as $var) |
|
370 | - if (isset($_POST[$var])) |
|
398 | + } |
|
399 | + foreach ($possible_ints as $var) { |
|
400 | + if (isset($_POST[$var])) |
|
371 | 401 | $regOptions['extra_register_vars'][$var] = (int) $_POST[$var]; |
372 | - foreach ($possible_floats as $var) |
|
373 | - if (isset($_POST[$var])) |
|
402 | + } |
|
403 | + foreach ($possible_floats as $var) { |
|
404 | + if (isset($_POST[$var])) |
|
374 | 405 | $regOptions['extra_register_vars'][$var] = (float) $_POST[$var]; |
375 | - foreach ($possible_bools as $var) |
|
376 | - if (isset($_POST[$var])) |
|
406 | + } |
|
407 | + foreach ($possible_bools as $var) { |
|
408 | + if (isset($_POST[$var])) |
|
377 | 409 | $regOptions['extra_register_vars'][$var] = empty($_POST[$var]) ? 0 : 1; |
410 | + } |
|
378 | 411 | |
379 | 412 | // Registration options are always default options... |
380 | - if (isset($_POST['default_options'])) |
|
381 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
413 | + if (isset($_POST['default_options'])) { |
|
414 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
415 | + } |
|
382 | 416 | $regOptions['theme_vars'] = isset($_POST['options']) && is_array($_POST['options']) ? $_POST['options'] : array(); |
383 | 417 | |
384 | 418 | // Make sure they are clean, dammit! |
@@ -398,12 +432,14 @@ discard block |
||
398 | 432 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
399 | 433 | { |
400 | 434 | // Don't allow overriding of the theme variables. |
401 | - if (isset($regOptions['theme_vars'][$row['col_name']])) |
|
402 | - unset($regOptions['theme_vars'][$row['col_name']]); |
|
435 | + if (isset($regOptions['theme_vars'][$row['col_name']])) { |
|
436 | + unset($regOptions['theme_vars'][$row['col_name']]); |
|
437 | + } |
|
403 | 438 | |
404 | 439 | // Not actually showing it then? |
405 | - if (!$row['show_reg']) |
|
406 | - continue; |
|
440 | + if (!$row['show_reg']) { |
|
441 | + continue; |
|
442 | + } |
|
407 | 443 | |
408 | 444 | // Prepare the value! |
409 | 445 | $value = isset($_POST['customfield'][$row['col_name']]) ? trim($_POST['customfield'][$row['col_name']]) : ''; |
@@ -412,24 +448,27 @@ discard block |
||
412 | 448 | if (!in_array($row['field_type'], array('check', 'select', 'radio'))) |
413 | 449 | { |
414 | 450 | // Is it too long? |
415 | - if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) |
|
416 | - $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
451 | + if ($row['field_length'] && $row['field_length'] < $smcFunc['strlen']($value)) { |
|
452 | + $custom_field_errors[] = array('custom_field_too_long', array($row['field_name'], $row['field_length'])); |
|
453 | + } |
|
417 | 454 | |
418 | 455 | // Any masks to apply? |
419 | 456 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
420 | 457 | { |
421 | - if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
|
422 | - $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
423 | - elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) |
|
424 | - $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
425 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
426 | - $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
458 | + if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) { |
|
459 | + $custom_field_errors[] = array('custom_field_invalid_email', array($row['field_name'])); |
|
460 | + } elseif ($row['mask'] == 'number' && preg_match('~[^\d]~', $value)) { |
|
461 | + $custom_field_errors[] = array('custom_field_not_number', array($row['field_name'])); |
|
462 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) { |
|
463 | + $custom_field_errors[] = array('custom_field_inproper_format', array($row['field_name'])); |
|
464 | + } |
|
427 | 465 | } |
428 | 466 | } |
429 | 467 | |
430 | 468 | // Is this required but not there? |
431 | - if (trim($value) == '' && $row['show_reg'] > 1) |
|
432 | - $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
469 | + if (trim($value) == '' && $row['show_reg'] > 1) { |
|
470 | + $custom_field_errors[] = array('custom_field_empty', array($row['field_name'])); |
|
471 | + } |
|
433 | 472 | } |
434 | 473 | $smcFunc['db_free_result']($request); |
435 | 474 | |
@@ -437,8 +476,9 @@ discard block |
||
437 | 476 | if (!empty($custom_field_errors)) |
438 | 477 | { |
439 | 478 | loadLanguage('Errors'); |
440 | - foreach ($custom_field_errors as $error) |
|
441 | - $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
479 | + foreach ($custom_field_errors as $error) { |
|
480 | + $reg_errors[] = vsprintf($txt['error_' . $error[0]], $error[1]); |
|
481 | + } |
|
442 | 482 | } |
443 | 483 | |
444 | 484 | // Lets check for other errors before trying to register the member. |
@@ -483,8 +523,9 @@ discard block |
||
483 | 523 | } |
484 | 524 | |
485 | 525 | // If COPPA has been selected then things get complicated, setup the template. |
486 | - if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) |
|
487 | - redirectexit('action=coppa;member=' . $memberID); |
|
526 | + if (!empty($modSettings['coppaAge']) && empty($_SESSION['skip_coppa'])) { |
|
527 | + redirectexit('action=coppa;member=' . $memberID); |
|
528 | + } |
|
488 | 529 | // Basic template variable setup. |
489 | 530 | elseif (!empty($modSettings['registration_method'])) |
490 | 531 | { |
@@ -496,8 +537,7 @@ discard block |
||
496 | 537 | 'sub_template' => 'after', |
497 | 538 | 'description' => $modSettings['registration_method'] == 2 ? $txt['approval_after_registration'] : $txt['activate_after_registration'] |
498 | 539 | ); |
499 | - } |
|
500 | - else |
|
540 | + } else |
|
501 | 541 | { |
502 | 542 | call_integration_hook('integrate_activate', array($regOptions['username'])); |
503 | 543 | |
@@ -517,16 +557,18 @@ discard block |
||
517 | 557 | global $context, $txt, $modSettings, $scripturl, $sourcedir, $smcFunc, $language, $user_info; |
518 | 558 | |
519 | 559 | // Logged in users should not bother to activate their accounts |
520 | - if (!empty($user_info['id'])) |
|
521 | - redirectexit(); |
|
560 | + if (!empty($user_info['id'])) { |
|
561 | + redirectexit(); |
|
562 | + } |
|
522 | 563 | |
523 | 564 | loadLanguage('Login'); |
524 | 565 | loadTemplate('Login'); |
525 | 566 | |
526 | 567 | if (empty($_REQUEST['u']) && empty($_POST['user'])) |
527 | 568 | { |
528 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') |
|
529 | - fatal_lang_error('no_access', false); |
|
569 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == '3') { |
|
570 | + fatal_lang_error('no_access', false); |
|
571 | + } |
|
530 | 572 | |
531 | 573 | $context['member_id'] = 0; |
532 | 574 | $context['sub_template'] = 'resend'; |
@@ -566,11 +608,13 @@ discard block |
||
566 | 608 | // Change their email address? (they probably tried a fake one first :P.) |
567 | 609 | if (isset($_POST['new_email'], $_REQUEST['passwd']) && hash_password($row['member_name'], $_REQUEST['passwd']) == $row['passwd'] && ($row['is_activated'] == 0 || $row['is_activated'] == 2)) |
568 | 610 | { |
569 | - if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) |
|
570 | - fatal_lang_error('no_access', false); |
|
611 | + if (empty($modSettings['registration_method']) || $modSettings['registration_method'] == 3) { |
|
612 | + fatal_lang_error('no_access', false); |
|
613 | + } |
|
571 | 614 | |
572 | - if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) |
|
573 | - fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
615 | + if (!filter_var($_POST['new_email'], FILTER_VALIDATE_EMAIL)) { |
|
616 | + fatal_error(sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($_POST['new_email'])), false); |
|
617 | + } |
|
574 | 618 | |
575 | 619 | // Make sure their email isn't banned. |
576 | 620 | isBannedEmail($_POST['new_email'], 'cannot_register', $txt['ban_register_prohibited']); |
@@ -586,8 +630,9 @@ discard block |
||
586 | 630 | ) |
587 | 631 | ); |
588 | 632 | |
589 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
590 | - fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
633 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
634 | + fatal_lang_error('email_in_use', false, array($smcFunc['htmlspecialchars']($_POST['new_email']))); |
|
635 | + } |
|
591 | 636 | $smcFunc['db_free_result']($request); |
592 | 637 | |
593 | 638 | updateMemberData($row['id_member'], array('email_address' => $_POST['new_email'])); |
@@ -625,9 +670,9 @@ discard block |
||
625 | 670 | // Quit if this code is not right. |
626 | 671 | if (empty($_REQUEST['code']) || $row['validation_code'] != $_REQUEST['code']) |
627 | 672 | { |
628 | - if (!empty($row['is_activated'])) |
|
629 | - fatal_lang_error('already_activated', false); |
|
630 | - elseif ($row['validation_code'] == '') |
|
673 | + if (!empty($row['is_activated'])) { |
|
674 | + fatal_lang_error('already_activated', false); |
|
675 | + } elseif ($row['validation_code'] == '') |
|
631 | 676 | { |
632 | 677 | loadLanguage('Profile'); |
633 | 678 | fatal_error(sprintf($txt['registration_not_approved'], $scripturl . '?action=activate;user=' . $row['member_name']), false); |
@@ -677,8 +722,9 @@ discard block |
||
677 | 722 | loadTemplate('Register'); |
678 | 723 | |
679 | 724 | // No User ID?? |
680 | - if (!isset($_GET['member'])) |
|
681 | - fatal_lang_error('no_access', false); |
|
725 | + if (!isset($_GET['member'])) { |
|
726 | + fatal_lang_error('no_access', false); |
|
727 | + } |
|
682 | 728 | |
683 | 729 | // Get the user details... |
684 | 730 | $request = $smcFunc['db_query']('', ' |
@@ -691,8 +737,9 @@ discard block |
||
691 | 737 | 'is_coppa' => 5, |
692 | 738 | ) |
693 | 739 | ); |
694 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
695 | - fatal_lang_error('no_access', false); |
|
740 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
741 | + fatal_lang_error('no_access', false); |
|
742 | + } |
|
696 | 743 | list ($username) = $smcFunc['db_fetch_row']($request); |
697 | 744 | $smcFunc['db_free_result']($request); |
698 | 745 | |
@@ -730,8 +777,7 @@ discard block |
||
730 | 777 | echo $data; |
731 | 778 | obExit(false); |
732 | 779 | } |
733 | - } |
|
734 | - else |
|
780 | + } else |
|
735 | 781 | { |
736 | 782 | $context += array( |
737 | 783 | 'page_title' => $txt['coppa_title'], |
@@ -784,8 +830,9 @@ discard block |
||
784 | 830 | { |
785 | 831 | require_once($sourcedir . '/Subs-Graphics.php'); |
786 | 832 | |
787 | - if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) |
|
788 | - header('HTTP/1.1 400 Bad Request'); |
|
833 | + if (in_array('gd', get_loaded_extensions()) && !showCodeImage($code)) { |
|
834 | + header('HTTP/1.1 400 Bad Request'); |
|
835 | + } |
|
789 | 836 | |
790 | 837 | // Otherwise just show a pre-defined letter. |
791 | 838 | elseif (isset($_REQUEST['letter'])) |
@@ -803,14 +850,13 @@ discard block |
||
803 | 850 | header('Content-Type: image/gif'); |
804 | 851 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
805 | 852 | } |
806 | - } |
|
807 | - |
|
808 | - elseif ($_REQUEST['format'] === '.wav') |
|
853 | + } elseif ($_REQUEST['format'] === '.wav') |
|
809 | 854 | { |
810 | 855 | require_once($sourcedir . '/Subs-Sound.php'); |
811 | 856 | |
812 | - if (!createWaveFile($code)) |
|
813 | - header('HTTP/1.1 400 Bad Request'); |
|
857 | + if (!createWaveFile($code)) { |
|
858 | + header('HTTP/1.1 400 Bad Request'); |
|
859 | + } |
|
814 | 860 | } |
815 | 861 | |
816 | 862 | // We all die one day... |