@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * @version 2.1 Beta 4 |
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 | * Takes a message and parses it, returning nothing. |
@@ -31,8 +32,9 @@ discard block |
||
31 | 32 | global $user_info, $modSettings, $context, $sourcedir; |
32 | 33 | |
33 | 34 | // This line makes all languages *theoretically* work even with the wrong charset ;). |
34 | - if (empty($context['utf8'])) |
|
35 | - $message = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message); |
|
35 | + if (empty($context['utf8'])) { |
|
36 | + $message = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message); |
|
37 | + } |
|
36 | 38 | |
37 | 39 | // Clean up after nobbc ;). |
38 | 40 | $message = preg_replace_callback('~\[nobbc\](.+?)\[/nobbc\]~is', function($a) |
@@ -47,17 +49,19 @@ discard block |
||
47 | 49 | $message = preg_replace('~\.{100,}~', '...', $message); |
48 | 50 | |
49 | 51 | // Trim off trailing quotes - these often happen by accident. |
50 | - while (substr($message, -7) == '[quote]') |
|
51 | - $message = substr($message, 0, -7); |
|
52 | - while (substr($message, 0, 8) == '[/quote]') |
|
53 | - $message = substr($message, 8); |
|
52 | + while (substr($message, -7) == '[quote]') { |
|
53 | + $message = substr($message, 0, -7); |
|
54 | + } |
|
55 | + while (substr($message, 0, 8) == '[/quote]') { |
|
56 | + $message = substr($message, 8); |
|
57 | + } |
|
54 | 58 | |
55 | 59 | // Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed. |
56 | 60 | $in_tag = false; |
57 | 61 | $had_tag = false; |
58 | 62 | $codeopen = 0; |
59 | - if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) |
|
60 | - foreach ($matches[0] as $index => $dummy) |
|
63 | + if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) { |
|
64 | + foreach ($matches[0] as $index => $dummy) |
|
61 | 65 | { |
62 | 66 | // Closing? |
63 | 67 | if (!empty($matches[2][$index])) |
@@ -65,6 +69,7 @@ discard block |
||
65 | 69 | // If it's closing and we're not in a tag we need to open it... |
66 | 70 | if (!$in_tag) |
67 | 71 | $codeopen = true; |
72 | + } |
|
68 | 73 | // Either way we ain't in one any more. |
69 | 74 | $in_tag = false; |
70 | 75 | } |
@@ -73,17 +78,20 @@ discard block |
||
73 | 78 | { |
74 | 79 | $had_tag = true; |
75 | 80 | // If we're in a tag don't do nought! |
76 | - if (!$in_tag) |
|
77 | - $in_tag = true; |
|
81 | + if (!$in_tag) { |
|
82 | + $in_tag = true; |
|
83 | + } |
|
78 | 84 | } |
79 | 85 | } |
80 | 86 | |
81 | 87 | // If we have an open tag, close it. |
82 | - if ($in_tag) |
|
83 | - $message .= '[/code]'; |
|
88 | + if ($in_tag) { |
|
89 | + $message .= '[/code]'; |
|
90 | + } |
|
84 | 91 | // Open any ones that need to be open, only if we've never had a tag. |
85 | - if ($codeopen && !$had_tag) |
|
86 | - $message = '[code]' . $message; |
|
92 | + if ($codeopen && !$had_tag) { |
|
93 | + $message = '[code]' . $message; |
|
94 | + } |
|
87 | 95 | |
88 | 96 | // Replace code BBC with placeholders. We'll restore them at the end. |
89 | 97 | $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE); |
@@ -108,23 +116,26 @@ discard block |
||
108 | 116 | fixTags($message); |
109 | 117 | |
110 | 118 | // Replace /me.+?\n with [me=name]dsf[/me]\n. |
111 | - if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) |
|
112 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
113 | - else |
|
114 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
119 | + if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) { |
|
120 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
121 | + } else { |
|
122 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
123 | + } |
|
115 | 124 | |
116 | 125 | if (!$previewing && strpos($message, '[html]') !== false) |
117 | 126 | { |
118 | - if (allowedTo('admin_forum')) |
|
119 | - $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) { |
|
127 | + if (allowedTo('admin_forum')) { |
|
128 | + $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) { |
|
120 | 129 | return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => ' ', ' ' => '  ', '[' => '[', ']' => ']')) . '[/html]'; |
130 | + } |
|
121 | 131 | }, $message); |
122 | 132 | |
123 | 133 | // We should edit them out, or else if an admin edits the message they will get shown... |
124 | 134 | else |
125 | 135 | { |
126 | - while (strpos($message, '[html]') !== false) |
|
127 | - $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
136 | + while (strpos($message, '[html]') !== false) { |
|
137 | + $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
138 | + } |
|
128 | 139 | } |
129 | 140 | } |
130 | 141 | |
@@ -146,10 +157,12 @@ discard block |
||
146 | 157 | |
147 | 158 | $list_open = substr_count($message, '[list]') + substr_count($message, '[list '); |
148 | 159 | $list_close = substr_count($message, '[/list]'); |
149 | - if ($list_close - $list_open > 0) |
|
150 | - $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
151 | - if ($list_open - $list_close > 0) |
|
152 | - $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
160 | + if ($list_close - $list_open > 0) { |
|
161 | + $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
162 | + } |
|
163 | + if ($list_open - $list_close > 0) { |
|
164 | + $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
165 | + } |
|
153 | 166 | |
154 | 167 | $mistake_fixes = array( |
155 | 168 | // Find [table]s not followed by [tr]. |
@@ -198,8 +211,9 @@ discard block |
||
198 | 211 | ); |
199 | 212 | |
200 | 213 | // Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.) |
201 | - for ($j = 0; $j < 3; $j++) |
|
202 | - $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
214 | + for ($j = 0; $j < 3; $j++) { |
|
215 | + $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
216 | + } |
|
203 | 217 | |
204 | 218 | // Remove empty bbc from the sections outside the code tags |
205 | 219 | $allowedEmpty = array( |
@@ -210,24 +224,28 @@ discard block |
||
210 | 224 | require_once($sourcedir . '/Subs.php'); |
211 | 225 | |
212 | 226 | $alltags = array(); |
213 | - foreach (($codes = parse_bbc(false)) as $code) |
|
214 | - if (!in_array($code['tag'], $allowedEmpty)) |
|
227 | + foreach (($codes = parse_bbc(false)) as $code) { |
|
228 | + if (!in_array($code['tag'], $allowedEmpty)) |
|
215 | 229 | $alltags[] = $code['tag']; |
230 | + } |
|
216 | 231 | |
217 | 232 | $alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b'; |
218 | 233 | |
219 | - while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) |
|
220 | - $message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message); |
|
234 | + while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) { |
|
235 | + $message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message); |
|
236 | + } |
|
221 | 237 | |
222 | 238 | // Restore code blocks |
223 | - if (!empty($code_tags)) |
|
224 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
239 | + if (!empty($code_tags)) { |
|
240 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
241 | + } |
|
225 | 242 | |
226 | 243 | // Restore white space entities |
227 | - if (!$previewing) |
|
228 | - $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
229 | - else |
|
230 | - $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
244 | + if (!$previewing) { |
|
245 | + $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
246 | + } else { |
|
247 | + $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
248 | + } |
|
231 | 249 | |
232 | 250 | // Now let's quickly clean up things that will slow our parser (which are common in posted code.) |
233 | 251 | $message = strtr($message, array('[]' => '[]', '['' => '['')); |
@@ -270,8 +288,9 @@ discard block |
||
270 | 288 | return "[time]" . timeformat("$m[1]", false) . "[/time]"; |
271 | 289 | }, $message); |
272 | 290 | |
273 | - if (!empty($code_tags)) |
|
274 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
291 | + if (!empty($code_tags)) { |
|
292 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
293 | + } |
|
275 | 294 | |
276 | 295 | // Change breaks back to \n's and &nsbp; back to spaces. |
277 | 296 | return preg_replace('~<br( /)?' . '>~', "\n", str_replace(' ', ' ', $message)); |
@@ -352,8 +371,9 @@ discard block |
||
352 | 371 | ); |
353 | 372 | |
354 | 373 | // Fix each type of tag. |
355 | - foreach ($fixArray as $param) |
|
356 | - fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
374 | + foreach ($fixArray as $param) { |
|
375 | + fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
376 | + } |
|
357 | 377 | |
358 | 378 | // Now fix possible security problems with images loading links automatically... |
359 | 379 | $message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m) |
@@ -378,10 +398,11 @@ discard block |
||
378 | 398 | { |
379 | 399 | global $boardurl, $scripturl; |
380 | 400 | |
381 | - if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) |
|
382 | - $domain_url = $match[1]; |
|
383 | - else |
|
384 | - $domain_url = $boardurl . '/'; |
|
401 | + if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) { |
|
402 | + $domain_url = $match[1]; |
|
403 | + } else { |
|
404 | + $domain_url = $boardurl . '/'; |
|
405 | + } |
|
385 | 406 | |
386 | 407 | $replaces = array(); |
387 | 408 | |
@@ -389,11 +410,11 @@ discard block |
||
389 | 410 | { |
390 | 411 | $quoted = preg_match('~\[(' . $myTag . ')="~', $message); |
391 | 412 | preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '"(.*?)"' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
413 | + } elseif ($hasEqualSign) { |
|
414 | + preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
415 | + } else { |
|
416 | + preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
392 | 417 | } |
393 | - elseif ($hasEqualSign) |
|
394 | - preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
395 | - else |
|
396 | - preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
397 | 418 | |
398 | 419 | foreach ($matches[0] as $k => $dummy) |
399 | 420 | { |
@@ -406,49 +427,53 @@ discard block |
||
406 | 427 | foreach ($protocols as $protocol) |
407 | 428 | { |
408 | 429 | $found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0; |
409 | - if ($found) |
|
410 | - break; |
|
430 | + if ($found) { |
|
431 | + break; |
|
432 | + } |
|
411 | 433 | } |
412 | 434 | |
413 | 435 | if (!$found && $protocols[0] == 'http') |
414 | 436 | { |
415 | - if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') |
|
416 | - $replace = $domain_url . $replace; |
|
417 | - elseif (substr($replace, 0, 1) == '?') |
|
418 | - $replace = $scripturl . $replace; |
|
419 | - elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
437 | + if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') { |
|
438 | + $replace = $domain_url . $replace; |
|
439 | + } elseif (substr($replace, 0, 1) == '?') { |
|
440 | + $replace = $scripturl . $replace; |
|
441 | + } elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
420 | 442 | { |
421 | 443 | $replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1)); |
422 | 444 | $this_tag = 'iurl'; |
423 | 445 | $this_close = 'iurl'; |
446 | + } elseif (substr($replace, 0, 2) != '//') { |
|
447 | + $replace = $protocols[0] . '://' . $replace; |
|
424 | 448 | } |
425 | - elseif (substr($replace, 0, 2) != '//') |
|
426 | - $replace = $protocols[0] . '://' . $replace; |
|
427 | - } |
|
428 | - elseif (!$found && $protocols[0] == 'ftp') |
|
429 | - $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
430 | - elseif (!$found) |
|
431 | - $replace = $protocols[0] . '://' . $replace; |
|
432 | - |
|
433 | - if ($hasEqualSign && $embeddedUrl) |
|
434 | - $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
435 | - elseif ($hasEqualSign) |
|
436 | - $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
437 | - elseif ($embeddedUrl) |
|
438 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
439 | - else |
|
440 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
449 | + } elseif (!$found && $protocols[0] == 'ftp') { |
|
450 | + $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
451 | + } elseif (!$found) { |
|
452 | + $replace = $protocols[0] . '://' . $replace; |
|
453 | + } |
|
454 | + |
|
455 | + if ($hasEqualSign && $embeddedUrl) { |
|
456 | + $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
457 | + } elseif ($hasEqualSign) { |
|
458 | + $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
459 | + } elseif ($embeddedUrl) { |
|
460 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
461 | + } else { |
|
462 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
463 | + } |
|
441 | 464 | } |
442 | 465 | |
443 | 466 | foreach ($replaces as $k => $v) |
444 | 467 | { |
445 | - if ($k == $v) |
|
446 | - unset($replaces[$k]); |
|
468 | + if ($k == $v) { |
|
469 | + unset($replaces[$k]); |
|
470 | + } |
|
447 | 471 | } |
448 | 472 | |
449 | - if (!empty($replaces)) |
|
450 | - $message = strtr($message, $replaces); |
|
451 | -} |
|
473 | + if (!empty($replaces)) { |
|
474 | + $message = strtr($message, $replaces); |
|
475 | + } |
|
476 | + } |
|
452 | 477 | |
453 | 478 | /** |
454 | 479 | * This function sends an email to the specified recipient(s). |
@@ -492,8 +517,9 @@ discard block |
||
492 | 517 | } |
493 | 518 | |
494 | 519 | // Nothing left? Nothing else to do |
495 | - if (empty($to_array)) |
|
496 | - return true; |
|
520 | + if (empty($to_array)) { |
|
521 | + return true; |
|
522 | + } |
|
497 | 523 | |
498 | 524 | // Once upon a time, Hotmail could not interpret non-ASCII mails. |
499 | 525 | // In honour of those days, it's still called the 'hotmail fix'. |
@@ -510,15 +536,17 @@ discard block |
||
510 | 536 | } |
511 | 537 | |
512 | 538 | // Call this function recursively for the hotmail addresses. |
513 | - if (!empty($hotmail_to)) |
|
514 | - $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
539 | + if (!empty($hotmail_to)) { |
|
540 | + $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
541 | + } |
|
515 | 542 | |
516 | 543 | // The remaining addresses no longer need the fix. |
517 | 544 | $hotmail_fix = false; |
518 | 545 | |
519 | 546 | // No other addresses left? Return instantly. |
520 | - if (empty($to_array)) |
|
521 | - return $mail_result; |
|
547 | + if (empty($to_array)) { |
|
548 | + return $mail_result; |
|
549 | + } |
|
522 | 550 | } |
523 | 551 | |
524 | 552 | // Get rid of entities. |
@@ -543,13 +571,15 @@ discard block |
||
543 | 571 | $headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break; |
544 | 572 | $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break; |
545 | 573 | |
546 | - if ($message_id !== null && empty($modSettings['mail_no_message_id'])) |
|
547 | - $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
574 | + if ($message_id !== null && empty($modSettings['mail_no_message_id'])) { |
|
575 | + $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
576 | + } |
|
548 | 577 | $headers .= 'X-Mailer: SMF' . $line_break; |
549 | 578 | |
550 | 579 | // Pass this to the integration before we start modifying the output -- it'll make it easier later. |
551 | - if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) |
|
552 | - return false; |
|
580 | + if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) { |
|
581 | + return false; |
|
582 | + } |
|
553 | 583 | |
554 | 584 | // Save the original message... |
555 | 585 | $orig_message = $message; |
@@ -598,17 +628,19 @@ discard block |
||
598 | 628 | } |
599 | 629 | |
600 | 630 | // Are we using the mail queue, if so this is where we butt in... |
601 | - if ($priority != 0) |
|
602 | - return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
631 | + if ($priority != 0) { |
|
632 | + return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
633 | + } |
|
603 | 634 | |
604 | 635 | // If it's a priority mail, send it now - note though that this should NOT be used for sending many at once. |
605 | 636 | elseif (!empty($modSettings['mail_limit'])) |
606 | 637 | { |
607 | 638 | list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']); |
608 | - if (empty($mails_this_minute) || time() > $last_mail_time + 60) |
|
609 | - $new_queue_stat = time() . '|' . 1; |
|
610 | - else |
|
611 | - $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
639 | + if (empty($mails_this_minute) || time() > $last_mail_time + 60) { |
|
640 | + $new_queue_stat = time() . '|' . 1; |
|
641 | + } else { |
|
642 | + $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
643 | + } |
|
612 | 644 | |
613 | 645 | updateSettings(array('mail_recent' => $new_queue_stat)); |
614 | 646 | } |
@@ -642,8 +674,7 @@ discard block |
||
642 | 674 | log_error(sprintf($txt['mail_send_unable'], $to)); |
643 | 675 | $mail_result = false; |
644 | 676 | } |
645 | - } |
|
646 | - catch(ErrorException $e) |
|
677 | + } catch(ErrorException $e) |
|
647 | 678 | { |
648 | 679 | log_error($e->getMessage(), 'general', $e->getFile(), $e->getLine()); |
649 | 680 | log_error(sprintf($txt['mail_send_unable'], $to)); |
@@ -653,12 +684,13 @@ discard block |
||
653 | 684 | |
654 | 685 | // Wait, wait, I'm still sending here! |
655 | 686 | @set_time_limit(300); |
656 | - if (function_exists('apache_reset_timeout')) |
|
657 | - @apache_reset_timeout(); |
|
687 | + if (function_exists('apache_reset_timeout')) { |
|
688 | + @apache_reset_timeout(); |
|
689 | + } |
|
658 | 690 | } |
691 | + } else { |
|
692 | + $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
659 | 693 | } |
660 | - else |
|
661 | - $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
662 | 694 | |
663 | 695 | // Everything go smoothly? |
664 | 696 | return $mail_result; |
@@ -684,8 +716,9 @@ discard block |
||
684 | 716 | static $cur_insert = array(); |
685 | 717 | static $cur_insert_len = 0; |
686 | 718 | |
687 | - if ($cur_insert_len == 0) |
|
688 | - $cur_insert = array(); |
|
719 | + if ($cur_insert_len == 0) { |
|
720 | + $cur_insert = array(); |
|
721 | + } |
|
689 | 722 | |
690 | 723 | // If we're flushing, make the final inserts - also if we're near the MySQL length limit! |
691 | 724 | if (($flush || $cur_insert_len > 800000) && !empty($cur_insert)) |
@@ -760,8 +793,9 @@ discard block |
||
760 | 793 | } |
761 | 794 | |
762 | 795 | // If they are using SSI there is a good chance obExit will never be called. So lets be nice and flush it for them. |
763 | - if (SMF === 'SSI' || SMF === 'BACKGROUND') |
|
764 | - return AddMailQueue(true); |
|
796 | + if (SMF === 'SSI' || SMF === 'BACKGROUND') { |
|
797 | + return AddMailQueue(true); |
|
798 | + } |
|
765 | 799 | |
766 | 800 | return true; |
767 | 801 | } |
@@ -792,23 +826,26 @@ discard block |
||
792 | 826 | 'sent' => array() |
793 | 827 | ); |
794 | 828 | |
795 | - if ($from === null) |
|
796 | - $from = array( |
|
829 | + if ($from === null) { |
|
830 | + $from = array( |
|
797 | 831 | 'id' => $user_info['id'], |
798 | 832 | 'name' => $user_info['name'], |
799 | 833 | 'username' => $user_info['username'] |
800 | 834 | ); |
835 | + } |
|
801 | 836 | |
802 | 837 | // This is the one that will go in their inbox. |
803 | 838 | $htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES); |
804 | 839 | preparsecode($htmlmessage); |
805 | 840 | $htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => '')); |
806 | - if ($smcFunc['strlen']($htmlsubject) > 100) |
|
807 | - $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
841 | + if ($smcFunc['strlen']($htmlsubject) > 100) { |
|
842 | + $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
843 | + } |
|
808 | 844 | |
809 | 845 | // Make sure is an array |
810 | - if (!is_array($recipients)) |
|
811 | - $recipients = array($recipients); |
|
846 | + if (!is_array($recipients)) { |
|
847 | + $recipients = array($recipients); |
|
848 | + } |
|
812 | 849 | |
813 | 850 | // Integrated PMs |
814 | 851 | call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message)); |
@@ -836,21 +873,23 @@ discard block |
||
836 | 873 | 'usernames' => array_keys($usernames), |
837 | 874 | ) |
838 | 875 | ); |
839 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
840 | - if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
876 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
877 | + if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
841 | 878 | $usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member']; |
879 | + } |
|
842 | 880 | $smcFunc['db_free_result']($request); |
843 | 881 | |
844 | 882 | // Replace the usernames with IDs. Drop usernames that couldn't be found. |
845 | - foreach ($recipients as $rec_type => $rec) |
|
846 | - foreach ($rec as $id => $member) |
|
883 | + foreach ($recipients as $rec_type => $rec) { |
|
884 | + foreach ($rec as $id => $member) |
|
847 | 885 | { |
848 | 886 | if (is_numeric($recipients[$rec_type][$id])) |
849 | 887 | continue; |
888 | + } |
|
850 | 889 | |
851 | - if (!empty($usernames[$member])) |
|
852 | - $recipients[$rec_type][$id] = $usernames[$member]; |
|
853 | - else |
|
890 | + if (!empty($usernames[$member])) { |
|
891 | + $recipients[$rec_type][$id] = $usernames[$member]; |
|
892 | + } else |
|
854 | 893 | { |
855 | 894 | $log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]); |
856 | 895 | unset($recipients[$rec_type][$id]); |
@@ -888,8 +927,9 @@ discard block |
||
888 | 927 | $delete = false; |
889 | 928 | foreach ($criteria as $criterium) |
890 | 929 | { |
891 | - if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) |
|
892 | - $delete = true; |
|
930 | + if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) { |
|
931 | + $delete = true; |
|
932 | + } |
|
893 | 933 | // If we're adding and one criteria don't match then we stop! |
894 | 934 | elseif (!$row['is_or']) |
895 | 935 | { |
@@ -897,8 +937,9 @@ discard block |
||
897 | 937 | break; |
898 | 938 | } |
899 | 939 | } |
900 | - if ($delete) |
|
901 | - $deletes[$row['id_member']] = 1; |
|
940 | + if ($delete) { |
|
941 | + $deletes[$row['id_member']] = 1; |
|
942 | + } |
|
902 | 943 | } |
903 | 944 | $smcFunc['db_free_result']($request); |
904 | 945 | |
@@ -913,8 +954,9 @@ discard block |
||
913 | 954 | array( |
914 | 955 | ) |
915 | 956 | ); |
916 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
917 | - $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
957 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
958 | + $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
959 | + } |
|
918 | 960 | $smcFunc['db_free_result']($request); |
919 | 961 | } |
920 | 962 | |
@@ -922,8 +964,9 @@ discard block |
||
922 | 964 | require_once($sourcedir . '/Subs-Members.php'); |
923 | 965 | $pmReadGroups = groupsAllowedTo('pm_read'); |
924 | 966 | |
925 | - if (empty($modSettings['permission_enable_deny'])) |
|
926 | - $pmReadGroups['denied'] = array(); |
|
967 | + if (empty($modSettings['permission_enable_deny'])) { |
|
968 | + $pmReadGroups['denied'] = array(); |
|
969 | + } |
|
927 | 970 | |
928 | 971 | // Load their alert preferences |
929 | 972 | require_once($sourcedir . '/Subs-Notify.php'); |
@@ -955,8 +998,9 @@ discard block |
||
955 | 998 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
956 | 999 | { |
957 | 1000 | // Don't do anything for members to be deleted! |
958 | - if (isset($deletes[$row['id_member']])) |
|
959 | - continue; |
|
1001 | + if (isset($deletes[$row['id_member']])) { |
|
1002 | + continue; |
|
1003 | + } |
|
960 | 1004 | |
961 | 1005 | // Load the preferences for this member (if any) |
962 | 1006 | $prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array(); |
@@ -977,8 +1021,9 @@ discard block |
||
977 | 1021 | { |
978 | 1022 | foreach ($groups as $id) |
979 | 1023 | { |
980 | - if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) |
|
981 | - $message_limit = $message_limit_cache[$id]; |
|
1024 | + if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) { |
|
1025 | + $message_limit = $message_limit_cache[$id]; |
|
1026 | + } |
|
982 | 1027 | } |
983 | 1028 | |
984 | 1029 | if ($message_limit > 0 && $message_limit <= $row['instant_messages']) |
@@ -1026,8 +1071,9 @@ discard block |
||
1026 | 1071 | $smcFunc['db_free_result']($request); |
1027 | 1072 | |
1028 | 1073 | // Only 'send' the message if there are any recipients left. |
1029 | - if (empty($all_to)) |
|
1030 | - return $log; |
|
1074 | + if (empty($all_to)) { |
|
1075 | + return $log; |
|
1076 | + } |
|
1031 | 1077 | |
1032 | 1078 | // Insert the message itself and then grab the last insert id. |
1033 | 1079 | $id_pm = $smcFunc['db_insert']('', |
@@ -1048,8 +1094,8 @@ discard block |
||
1048 | 1094 | if (!empty($id_pm)) |
1049 | 1095 | { |
1050 | 1096 | // If this is new we need to set it part of it's own conversation. |
1051 | - if (empty($pm_head)) |
|
1052 | - $smcFunc['db_query']('', ' |
|
1097 | + if (empty($pm_head)) { |
|
1098 | + $smcFunc['db_query']('', ' |
|
1053 | 1099 | UPDATE {db_prefix}personal_messages |
1054 | 1100 | SET id_pm_head = {int:id_pm_head} |
1055 | 1101 | WHERE id_pm = {int:id_pm_head}', |
@@ -1057,6 +1103,7 @@ discard block |
||
1057 | 1103 | 'id_pm_head' => $id_pm, |
1058 | 1104 | ) |
1059 | 1105 | ); |
1106 | + } |
|
1060 | 1107 | |
1061 | 1108 | // Some people think manually deleting personal_messages is fun... it's not. We protect against it though :) |
1062 | 1109 | $smcFunc['db_query']('', ' |
@@ -1072,8 +1119,9 @@ discard block |
||
1072 | 1119 | foreach ($all_to as $to) |
1073 | 1120 | { |
1074 | 1121 | $insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1); |
1075 | - if (!in_array($to, $recipients['bcc'])) |
|
1076 | - $to_list[] = $to; |
|
1122 | + if (!in_array($to, $recipients['bcc'])) { |
|
1123 | + $to_list[] = $to; |
|
1124 | + } |
|
1077 | 1125 | } |
1078 | 1126 | |
1079 | 1127 | $smcFunc['db_insert']('insert', |
@@ -1091,9 +1139,9 @@ discard block |
||
1091 | 1139 | { |
1092 | 1140 | censorText($message); |
1093 | 1141 | $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']'))))); |
1142 | + } else { |
|
1143 | + $message = ''; |
|
1094 | 1144 | } |
1095 | - else |
|
1096 | - $message = ''; |
|
1097 | 1145 | |
1098 | 1146 | $to_names = array(); |
1099 | 1147 | if (count($to_list) > 1) |
@@ -1106,8 +1154,9 @@ discard block |
||
1106 | 1154 | 'to_members' => $to_list, |
1107 | 1155 | ) |
1108 | 1156 | ); |
1109 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1110 | - $to_names[] = un_htmlspecialchars($row['real_name']); |
|
1157 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1158 | + $to_names[] = un_htmlspecialchars($row['real_name']); |
|
1159 | + } |
|
1111 | 1160 | $smcFunc['db_free_result']($request); |
1112 | 1161 | } |
1113 | 1162 | $replacements = array( |
@@ -1135,11 +1184,13 @@ discard block |
||
1135 | 1184 | loadLanguage('index+PersonalMessage'); |
1136 | 1185 | |
1137 | 1186 | // Add one to their unread and read message counts. |
1138 | - foreach ($all_to as $k => $id) |
|
1139 | - if (isset($deletes[$id])) |
|
1187 | + foreach ($all_to as $k => $id) { |
|
1188 | + if (isset($deletes[$id])) |
|
1140 | 1189 | unset($all_to[$k]); |
1141 | - if (!empty($all_to)) |
|
1142 | - updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
1190 | + } |
|
1191 | + if (!empty($all_to)) { |
|
1192 | + updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
1193 | + } |
|
1143 | 1194 | |
1144 | 1195 | return $log; |
1145 | 1196 | } |
@@ -1169,15 +1220,17 @@ discard block |
||
1169 | 1220 | // Let's, for now, assume there are only 'ish characters. |
1170 | 1221 | $simple = true; |
1171 | 1222 | |
1172 | - foreach ($matches[1] as $entity) |
|
1173 | - if ($entity > 128) |
|
1223 | + foreach ($matches[1] as $entity) { |
|
1224 | + if ($entity > 128) |
|
1174 | 1225 | $simple = false; |
1226 | + } |
|
1175 | 1227 | unset($matches); |
1176 | 1228 | |
1177 | - if ($simple) |
|
1178 | - $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
1229 | + if ($simple) { |
|
1230 | + $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
1179 | 1231 | { |
1180 | 1232 | return chr("$m[1]"); |
1233 | + } |
|
1181 | 1234 | }, $string); |
1182 | 1235 | else |
1183 | 1236 | { |
@@ -1185,8 +1238,9 @@ discard block |
||
1185 | 1238 | if (!$context['utf8'] && function_exists('iconv')) |
1186 | 1239 | { |
1187 | 1240 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
1188 | - if ($newstring) |
|
1189 | - $string = $newstring; |
|
1241 | + if ($newstring) { |
|
1242 | + $string = $newstring; |
|
1243 | + } |
|
1190 | 1244 | } |
1191 | 1245 | |
1192 | 1246 | $string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string); |
@@ -1202,23 +1256,25 @@ discard block |
||
1202 | 1256 | if (!$context['utf8'] && function_exists('iconv')) |
1203 | 1257 | { |
1204 | 1258 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
1205 | - if ($newstring) |
|
1206 | - $string = $newstring; |
|
1259 | + if ($newstring) { |
|
1260 | + $string = $newstring; |
|
1261 | + } |
|
1207 | 1262 | } |
1208 | 1263 | |
1209 | 1264 | $entityConvert = function($m) |
1210 | 1265 | { |
1211 | 1266 | $c = $m[1]; |
1212 | - if (strlen($c) === 1 && ord($c[0]) <= 0x7F) |
|
1213 | - return $c; |
|
1214 | - elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) |
|
1215 | - return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
1216 | - elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) |
|
1217 | - return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
1218 | - elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) |
|
1219 | - return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
1220 | - else |
|
1221 | - return ""; |
|
1267 | + if (strlen($c) === 1 && ord($c[0]) <= 0x7F) { |
|
1268 | + return $c; |
|
1269 | + } elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) { |
|
1270 | + return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
1271 | + } elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) { |
|
1272 | + return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
1273 | + } elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) { |
|
1274 | + return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
1275 | + } else { |
|
1276 | + return ""; |
|
1277 | + } |
|
1222 | 1278 | }; |
1223 | 1279 | |
1224 | 1280 | // Convert all 'special' characters to HTML entities. |
@@ -1232,19 +1288,20 @@ discard block |
||
1232 | 1288 | $string = base64_encode($string); |
1233 | 1289 | |
1234 | 1290 | // Show the characterset and the transfer-encoding for header strings. |
1235 | - if ($with_charset) |
|
1236 | - $string = '=?' . $charset . '?B?' . $string . '?='; |
|
1291 | + if ($with_charset) { |
|
1292 | + $string = '=?' . $charset . '?B?' . $string . '?='; |
|
1293 | + } |
|
1237 | 1294 | |
1238 | 1295 | // Break it up in lines (mail body). |
1239 | - else |
|
1240 | - $string = chunk_split($string, 76, $line_break); |
|
1296 | + else { |
|
1297 | + $string = chunk_split($string, 76, $line_break); |
|
1298 | + } |
|
1241 | 1299 | |
1242 | 1300 | return array($charset, $string, 'base64'); |
1301 | + } else { |
|
1302 | + return array($charset, $string, '7bit'); |
|
1303 | + } |
|
1243 | 1304 | } |
1244 | - |
|
1245 | - else |
|
1246 | - return array($charset, $string, '7bit'); |
|
1247 | -} |
|
1248 | 1305 | |
1249 | 1306 | /** |
1250 | 1307 | * Sends mail, like mail() but over SMTP. |
@@ -1268,8 +1325,9 @@ discard block |
||
1268 | 1325 | if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
1269 | 1326 | { |
1270 | 1327 | $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2); |
1271 | - if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) |
|
1272 | - $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
1328 | + if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) { |
|
1329 | + $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
1330 | + } |
|
1273 | 1331 | |
1274 | 1332 | if ($socket) |
1275 | 1333 | { |
@@ -1290,8 +1348,9 @@ discard block |
||
1290 | 1348 | // Maybe we can still save this? The port might be wrong. |
1291 | 1349 | if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) |
1292 | 1350 | { |
1293 | - if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) |
|
1294 | - log_error($txt['smtp_port_ssl']); |
|
1351 | + if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) { |
|
1352 | + log_error($txt['smtp_port_ssl']); |
|
1353 | + } |
|
1295 | 1354 | } |
1296 | 1355 | |
1297 | 1356 | // Unable to connect! Don't show any error message, but just log one and try to continue anyway. |
@@ -1303,20 +1362,23 @@ discard block |
||
1303 | 1362 | } |
1304 | 1363 | |
1305 | 1364 | // Wait for a response of 220, without "-" continuer. |
1306 | - if (!server_parse(null, $socket, '220')) |
|
1307 | - return false; |
|
1365 | + if (!server_parse(null, $socket, '220')) { |
|
1366 | + return false; |
|
1367 | + } |
|
1308 | 1368 | |
1309 | 1369 | // Try and determine the servers name, fall back to the mail servers if not found |
1310 | 1370 | $helo = false; |
1311 | - if (function_exists('gethostname') && gethostname() !== false) |
|
1312 | - $helo = gethostname(); |
|
1313 | - elseif (function_exists('php_uname')) |
|
1314 | - $helo = php_uname('n'); |
|
1315 | - elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) |
|
1316 | - $helo = $_SERVER['SERVER_NAME']; |
|
1371 | + if (function_exists('gethostname') && gethostname() !== false) { |
|
1372 | + $helo = gethostname(); |
|
1373 | + } elseif (function_exists('php_uname')) { |
|
1374 | + $helo = php_uname('n'); |
|
1375 | + } elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) { |
|
1376 | + $helo = $_SERVER['SERVER_NAME']; |
|
1377 | + } |
|
1317 | 1378 | |
1318 | - if (empty($helo)) |
|
1319 | - $helo = $modSettings['smtp_host']; |
|
1379 | + if (empty($helo)) { |
|
1380 | + $helo = $modSettings['smtp_host']; |
|
1381 | + } |
|
1320 | 1382 | |
1321 | 1383 | // SMTP = 1, SMTP - STARTTLS = 2 |
1322 | 1384 | if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
@@ -1328,33 +1390,39 @@ discard block |
||
1328 | 1390 | if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response)) |
1329 | 1391 | { |
1330 | 1392 | // Send STARTTLS to enable encryption |
1331 | - if (!server_parse('STARTTLS', $socket, '220')) |
|
1332 | - return false; |
|
1393 | + if (!server_parse('STARTTLS', $socket, '220')) { |
|
1394 | + return false; |
|
1395 | + } |
|
1333 | 1396 | // Enable the encryption |
1334 | - if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) |
|
1335 | - return false; |
|
1397 | + if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
1398 | + return false; |
|
1399 | + } |
|
1336 | 1400 | // Send the EHLO command again |
1337 | - if (!server_parse('EHLO ' . $helo, $socket, null) == '250') |
|
1338 | - return false; |
|
1401 | + if (!server_parse('EHLO ' . $helo, $socket, null) == '250') { |
|
1402 | + return false; |
|
1403 | + } |
|
1339 | 1404 | } |
1340 | 1405 | |
1341 | - if (!server_parse('AUTH LOGIN', $socket, '334')) |
|
1342 | - return false; |
|
1406 | + if (!server_parse('AUTH LOGIN', $socket, '334')) { |
|
1407 | + return false; |
|
1408 | + } |
|
1343 | 1409 | // Send the username and password, encoded. |
1344 | - if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) |
|
1345 | - return false; |
|
1410 | + if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) { |
|
1411 | + return false; |
|
1412 | + } |
|
1346 | 1413 | // The password is already encoded ;) |
1347 | - if (!server_parse($modSettings['smtp_password'], $socket, '235')) |
|
1348 | - return false; |
|
1414 | + if (!server_parse($modSettings['smtp_password'], $socket, '235')) { |
|
1415 | + return false; |
|
1416 | + } |
|
1417 | + } elseif (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1418 | + return false; |
|
1349 | 1419 | } |
1350 | - elseif (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1351 | - return false; |
|
1352 | - } |
|
1353 | - else |
|
1420 | + } else |
|
1354 | 1421 | { |
1355 | 1422 | // Just say "helo". |
1356 | - if (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1357 | - return false; |
|
1423 | + if (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1424 | + return false; |
|
1425 | + } |
|
1358 | 1426 | } |
1359 | 1427 | |
1360 | 1428 | // Fix the message for any lines beginning with a period! (the first is ignored, you see.) |
@@ -1367,31 +1435,38 @@ discard block |
||
1367 | 1435 | // Reset the connection to send another email. |
1368 | 1436 | if ($i != 0) |
1369 | 1437 | { |
1370 | - if (!server_parse('RSET', $socket, '250')) |
|
1371 | - return false; |
|
1438 | + if (!server_parse('RSET', $socket, '250')) { |
|
1439 | + return false; |
|
1440 | + } |
|
1372 | 1441 | } |
1373 | 1442 | |
1374 | 1443 | // From, to, and then start the data... |
1375 | - if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) |
|
1376 | - return false; |
|
1377 | - if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) |
|
1378 | - return false; |
|
1379 | - if (!server_parse('DATA', $socket, '354')) |
|
1380 | - return false; |
|
1444 | + if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) { |
|
1445 | + return false; |
|
1446 | + } |
|
1447 | + if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) { |
|
1448 | + return false; |
|
1449 | + } |
|
1450 | + if (!server_parse('DATA', $socket, '354')) { |
|
1451 | + return false; |
|
1452 | + } |
|
1381 | 1453 | fputs($socket, 'Subject: ' . $subject . "\r\n"); |
1382 | - if (strlen($mail_to) > 0) |
|
1383 | - fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1454 | + if (strlen($mail_to) > 0) { |
|
1455 | + fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1456 | + } |
|
1384 | 1457 | fputs($socket, $headers . "\r\n\r\n"); |
1385 | 1458 | fputs($socket, $message . "\r\n"); |
1386 | 1459 | |
1387 | 1460 | // Send a ., or in other words "end of data". |
1388 | - if (!server_parse('.', $socket, '250')) |
|
1389 | - return false; |
|
1461 | + if (!server_parse('.', $socket, '250')) { |
|
1462 | + return false; |
|
1463 | + } |
|
1390 | 1464 | |
1391 | 1465 | // Almost done, almost done... don't stop me just yet! |
1392 | 1466 | @set_time_limit(300); |
1393 | - if (function_exists('apache_reset_timeout')) |
|
1394 | - @apache_reset_timeout(); |
|
1467 | + if (function_exists('apache_reset_timeout')) { |
|
1468 | + @apache_reset_timeout(); |
|
1469 | + } |
|
1395 | 1470 | } |
1396 | 1471 | fputs($socket, 'QUIT' . "\r\n"); |
1397 | 1472 | fclose($socket); |
@@ -1415,8 +1490,9 @@ discard block |
||
1415 | 1490 | { |
1416 | 1491 | global $txt; |
1417 | 1492 | |
1418 | - if ($message !== null) |
|
1419 | - fputs($socket, $message . "\r\n"); |
|
1493 | + if ($message !== null) { |
|
1494 | + fputs($socket, $message . "\r\n"); |
|
1495 | + } |
|
1420 | 1496 | |
1421 | 1497 | // No response yet. |
1422 | 1498 | $server_response = ''; |
@@ -1432,8 +1508,9 @@ discard block |
||
1432 | 1508 | $response .= $server_response; |
1433 | 1509 | } |
1434 | 1510 | |
1435 | - if ($code === null) |
|
1436 | - return substr($server_response, 0, 3); |
|
1511 | + if ($code === null) { |
|
1512 | + return substr($server_response, 0, 3); |
|
1513 | + } |
|
1437 | 1514 | |
1438 | 1515 | if (substr($server_response, 0, 3) != $code) |
1439 | 1516 | { |
@@ -1463,8 +1540,9 @@ discard block |
||
1463 | 1540 | // Create a pspell or enchant dictionary resource |
1464 | 1541 | $dict = spell_init(); |
1465 | 1542 | |
1466 | - if (!isset($_POST['spellstring']) || !$dict) |
|
1467 | - die; |
|
1543 | + if (!isset($_POST['spellstring']) || !$dict) { |
|
1544 | + die; |
|
1545 | + } |
|
1468 | 1546 | |
1469 | 1547 | // Construct a bit of Javascript code. |
1470 | 1548 | $context['spell_js'] = ' |
@@ -1482,8 +1560,9 @@ discard block |
||
1482 | 1560 | $check_word = explode('|', $alphas[$i]); |
1483 | 1561 | |
1484 | 1562 | // If the word is a known word, or spelled right... |
1485 | - if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) |
|
1486 | - continue; |
|
1563 | + if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) { |
|
1564 | + continue; |
|
1565 | + } |
|
1487 | 1566 | |
1488 | 1567 | // Find the word, and move up the "last occurrence" to here. |
1489 | 1568 | $found_words = true; |
@@ -1497,20 +1576,23 @@ discard block |
||
1497 | 1576 | if (!empty($suggestions)) |
1498 | 1577 | { |
1499 | 1578 | // But first check they aren't going to be censored - no naughty words! |
1500 | - foreach ($suggestions as $k => $word) |
|
1501 | - if ($suggestions[$k] != censorText($word)) |
|
1579 | + foreach ($suggestions as $k => $word) { |
|
1580 | + if ($suggestions[$k] != censorText($word)) |
|
1502 | 1581 | unset($suggestions[$k]); |
1582 | + } |
|
1503 | 1583 | |
1504 | - if (!empty($suggestions)) |
|
1505 | - $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1584 | + if (!empty($suggestions)) { |
|
1585 | + $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1586 | + } |
|
1506 | 1587 | } |
1507 | 1588 | |
1508 | 1589 | $context['spell_js'] .= ']),'; |
1509 | 1590 | } |
1510 | 1591 | |
1511 | 1592 | // If words were found, take off the last comma. |
1512 | - if ($found_words) |
|
1513 | - $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1593 | + if ($found_words) { |
|
1594 | + $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1595 | + } |
|
1514 | 1596 | |
1515 | 1597 | $context['spell_js'] .= ' |
1516 | 1598 | );'; |
@@ -1545,11 +1627,13 @@ discard block |
||
1545 | 1627 | global $user_info, $smcFunc; |
1546 | 1628 | |
1547 | 1629 | // Can't do it if there's no topics. |
1548 | - if (empty($topics)) |
|
1549 | - return; |
|
1630 | + if (empty($topics)) { |
|
1631 | + return; |
|
1632 | + } |
|
1550 | 1633 | // It must be an array - it must! |
1551 | - if (!is_array($topics)) |
|
1552 | - $topics = array($topics); |
|
1634 | + if (!is_array($topics)) { |
|
1635 | + $topics = array($topics); |
|
1636 | + } |
|
1553 | 1637 | |
1554 | 1638 | // Get the subject and body... |
1555 | 1639 | $result = $smcFunc['db_query']('', ' |
@@ -1597,14 +1681,15 @@ discard block |
||
1597 | 1681 | } |
1598 | 1682 | $smcFunc['db_free_result']($result); |
1599 | 1683 | |
1600 | - if (!empty($task_rows)) |
|
1601 | - $smcFunc['db_insert']('', |
|
1684 | + if (!empty($task_rows)) { |
|
1685 | + $smcFunc['db_insert']('', |
|
1602 | 1686 | '{db_prefix}background_tasks', |
1603 | 1687 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1604 | 1688 | $task_rows, |
1605 | 1689 | array('id_task') |
1606 | 1690 | ); |
1607 | -} |
|
1691 | + } |
|
1692 | + } |
|
1608 | 1693 | |
1609 | 1694 | /** |
1610 | 1695 | * Create a post, either as new topic (id_topic = 0) or in an existing one. |
@@ -1642,9 +1727,9 @@ discard block |
||
1642 | 1727 | $msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true; |
1643 | 1728 | |
1644 | 1729 | // We need to know if the topic is approved. If we're told that's great - if not find out. |
1645 | - if (!$modSettings['postmod_active']) |
|
1646 | - $topicOptions['is_approved'] = true; |
|
1647 | - elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1730 | + if (!$modSettings['postmod_active']) { |
|
1731 | + $topicOptions['is_approved'] = true; |
|
1732 | + } elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1648 | 1733 | { |
1649 | 1734 | $request = $smcFunc['db_query']('', ' |
1650 | 1735 | SELECT approved |
@@ -1667,8 +1752,7 @@ discard block |
||
1667 | 1752 | $posterOptions['id'] = 0; |
1668 | 1753 | $posterOptions['name'] = $txt['guest_title']; |
1669 | 1754 | $posterOptions['email'] = ''; |
1670 | - } |
|
1671 | - elseif ($posterOptions['id'] != $user_info['id']) |
|
1755 | + } elseif ($posterOptions['id'] != $user_info['id']) |
|
1672 | 1756 | { |
1673 | 1757 | $request = $smcFunc['db_query']('', ' |
1674 | 1758 | SELECT member_name, email_address |
@@ -1686,12 +1770,11 @@ discard block |
||
1686 | 1770 | $posterOptions['id'] = 0; |
1687 | 1771 | $posterOptions['name'] = $txt['guest_title']; |
1688 | 1772 | $posterOptions['email'] = ''; |
1773 | + } else { |
|
1774 | + list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1689 | 1775 | } |
1690 | - else |
|
1691 | - list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1692 | 1776 | $smcFunc['db_free_result']($request); |
1693 | - } |
|
1694 | - else |
|
1777 | + } else |
|
1695 | 1778 | { |
1696 | 1779 | $posterOptions['name'] = $user_info['name']; |
1697 | 1780 | $posterOptions['email'] = $user_info['email']; |
@@ -1701,8 +1784,9 @@ discard block |
||
1701 | 1784 | if (!empty($modSettings['enable_mentions'])) |
1702 | 1785 | { |
1703 | 1786 | $msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']); |
1704 | - if (!empty($msgOptions['mentioned_members'])) |
|
1705 | - $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1787 | + if (!empty($msgOptions['mentioned_members'])) { |
|
1788 | + $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1789 | + } |
|
1706 | 1790 | } |
1707 | 1791 | |
1708 | 1792 | // It's do or die time: forget any user aborts! |
@@ -1735,12 +1819,13 @@ discard block |
||
1735 | 1819 | ); |
1736 | 1820 | |
1737 | 1821 | // Something went wrong creating the message... |
1738 | - if (empty($msgOptions['id'])) |
|
1739 | - return false; |
|
1822 | + if (empty($msgOptions['id'])) { |
|
1823 | + return false; |
|
1824 | + } |
|
1740 | 1825 | |
1741 | 1826 | // Fix the attachments. |
1742 | - if (!empty($msgOptions['attachments'])) |
|
1743 | - $smcFunc['db_query']('', ' |
|
1827 | + if (!empty($msgOptions['attachments'])) { |
|
1828 | + $smcFunc['db_query']('', ' |
|
1744 | 1829 | UPDATE {db_prefix}attachments |
1745 | 1830 | SET id_msg = {int:id_msg} |
1746 | 1831 | WHERE id_attach IN ({array_int:attachment_list})', |
@@ -1749,6 +1834,7 @@ discard block |
||
1749 | 1834 | 'id_msg' => $msgOptions['id'], |
1750 | 1835 | ) |
1751 | 1836 | ); |
1837 | + } |
|
1752 | 1838 | |
1753 | 1839 | // What if we want to export new posts out to a CMS? |
1754 | 1840 | call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters)); |
@@ -1825,20 +1911,23 @@ discard block |
||
1825 | 1911 | 'id_topic' => $topicOptions['id'], |
1826 | 1912 | 'counter_increment' => 1, |
1827 | 1913 | ); |
1828 | - if ($msgOptions['approved']) |
|
1829 | - $topics_columns = array( |
|
1914 | + if ($msgOptions['approved']) { |
|
1915 | + $topics_columns = array( |
|
1830 | 1916 | 'id_member_updated = {int:poster_id}', |
1831 | 1917 | 'id_last_msg = {int:id_msg}', |
1832 | 1918 | 'num_replies = num_replies + {int:counter_increment}', |
1833 | 1919 | ); |
1834 | - else |
|
1835 | - $topics_columns = array( |
|
1920 | + } else { |
|
1921 | + $topics_columns = array( |
|
1836 | 1922 | 'unapproved_posts = unapproved_posts + {int:counter_increment}', |
1837 | 1923 | ); |
1838 | - if ($topicOptions['lock_mode'] !== null) |
|
1839 | - $topics_columns[] = 'locked = {int:locked}'; |
|
1840 | - if ($topicOptions['sticky_mode'] !== null) |
|
1841 | - $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1924 | + } |
|
1925 | + if ($topicOptions['lock_mode'] !== null) { |
|
1926 | + $topics_columns[] = 'locked = {int:locked}'; |
|
1927 | + } |
|
1928 | + if ($topicOptions['sticky_mode'] !== null) { |
|
1929 | + $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1930 | + } |
|
1842 | 1931 | |
1843 | 1932 | call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions)); |
1844 | 1933 | |
@@ -1867,8 +1956,8 @@ discard block |
||
1867 | 1956 | ); |
1868 | 1957 | |
1869 | 1958 | // Increase the number of posts and topics on the board. |
1870 | - if ($msgOptions['approved']) |
|
1871 | - $smcFunc['db_query']('', ' |
|
1959 | + if ($msgOptions['approved']) { |
|
1960 | + $smcFunc['db_query']('', ' |
|
1872 | 1961 | UPDATE {db_prefix}boards |
1873 | 1962 | SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . ' |
1874 | 1963 | WHERE id_board = {int:id_board}', |
@@ -1876,7 +1965,7 @@ discard block |
||
1876 | 1965 | 'id_board' => $topicOptions['board'], |
1877 | 1966 | ) |
1878 | 1967 | ); |
1879 | - else |
|
1968 | + } else |
|
1880 | 1969 | { |
1881 | 1970 | $smcFunc['db_query']('', ' |
1882 | 1971 | UPDATE {db_prefix}boards |
@@ -1946,8 +2035,8 @@ discard block |
||
1946 | 2035 | } |
1947 | 2036 | } |
1948 | 2037 | |
1949 | - if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) |
|
1950 | - $smcFunc['db_insert']('', |
|
2038 | + if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) { |
|
2039 | + $smcFunc['db_insert']('', |
|
1951 | 2040 | '{db_prefix}background_tasks', |
1952 | 2041 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1953 | 2042 | array( |
@@ -1959,19 +2048,22 @@ discard block |
||
1959 | 2048 | ), |
1960 | 2049 | array('id_task') |
1961 | 2050 | ); |
2051 | + } |
|
1962 | 2052 | |
1963 | 2053 | // If there's a custom search index, it may need updating... |
1964 | 2054 | require_once($sourcedir . '/Search.php'); |
1965 | 2055 | $searchAPI = findSearchAPI(); |
1966 | - if (is_callable(array($searchAPI, 'postCreated'))) |
|
1967 | - $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2056 | + if (is_callable(array($searchAPI, 'postCreated'))) { |
|
2057 | + $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2058 | + } |
|
1968 | 2059 | |
1969 | 2060 | // Increase the post counter for the user that created the post. |
1970 | 2061 | if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved']) |
1971 | 2062 | { |
1972 | 2063 | // Are you the one that happened to create this post? |
1973 | - if ($user_info['id'] == $posterOptions['id']) |
|
1974 | - $user_info['posts']++; |
|
2064 | + if ($user_info['id'] == $posterOptions['id']) { |
|
2065 | + $user_info['posts']++; |
|
2066 | + } |
|
1975 | 2067 | updateMemberData($posterOptions['id'], array('posts' => '+')); |
1976 | 2068 | } |
1977 | 2069 | |
@@ -1979,19 +2071,21 @@ discard block |
||
1979 | 2071 | $_SESSION['last_read_topic'] = 0; |
1980 | 2072 | |
1981 | 2073 | // Better safe than sorry. |
1982 | - if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) |
|
1983 | - $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2074 | + if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) { |
|
2075 | + $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2076 | + } |
|
1984 | 2077 | |
1985 | 2078 | // Update all the stats so everyone knows about this new topic and message. |
1986 | 2079 | updateStats('message', true, $msgOptions['id']); |
1987 | 2080 | |
1988 | 2081 | // Update the last message on the board assuming it's approved AND the topic is. |
1989 | - if ($msgOptions['approved']) |
|
1990 | - updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2082 | + if ($msgOptions['approved']) { |
|
2083 | + updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2084 | + } |
|
1991 | 2085 | |
1992 | 2086 | // Queue createPost background notification |
1993 | - if ($msgOptions['send_notifications'] && $msgOptions['approved']) |
|
1994 | - $smcFunc['db_insert']('', |
|
2087 | + if ($msgOptions['send_notifications'] && $msgOptions['approved']) { |
|
2088 | + $smcFunc['db_insert']('', |
|
1995 | 2089 | '{db_prefix}background_tasks', |
1996 | 2090 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1997 | 2091 | array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array( |
@@ -2002,6 +2096,7 @@ discard block |
||
2002 | 2096 | )), 0), |
2003 | 2097 | array('id_task') |
2004 | 2098 | ); |
2099 | + } |
|
2005 | 2100 | |
2006 | 2101 | // Alright, done now... we can abort now, I guess... at least this much is done. |
2007 | 2102 | ignore_user_abort($previous_ignore_user_abort); |
@@ -2028,14 +2123,18 @@ discard block |
||
2028 | 2123 | |
2029 | 2124 | // This is longer than it has to be, but makes it so we only set/change what we have to. |
2030 | 2125 | $messages_columns = array(); |
2031 | - if (isset($posterOptions['name'])) |
|
2032 | - $messages_columns['poster_name'] = $posterOptions['name']; |
|
2033 | - if (isset($posterOptions['email'])) |
|
2034 | - $messages_columns['poster_email'] = $posterOptions['email']; |
|
2035 | - if (isset($msgOptions['icon'])) |
|
2036 | - $messages_columns['icon'] = $msgOptions['icon']; |
|
2037 | - if (isset($msgOptions['subject'])) |
|
2038 | - $messages_columns['subject'] = $msgOptions['subject']; |
|
2126 | + if (isset($posterOptions['name'])) { |
|
2127 | + $messages_columns['poster_name'] = $posterOptions['name']; |
|
2128 | + } |
|
2129 | + if (isset($posterOptions['email'])) { |
|
2130 | + $messages_columns['poster_email'] = $posterOptions['email']; |
|
2131 | + } |
|
2132 | + if (isset($msgOptions['icon'])) { |
|
2133 | + $messages_columns['icon'] = $msgOptions['icon']; |
|
2134 | + } |
|
2135 | + if (isset($msgOptions['subject'])) { |
|
2136 | + $messages_columns['subject'] = $msgOptions['subject']; |
|
2137 | + } |
|
2039 | 2138 | if (isset($msgOptions['body'])) |
2040 | 2139 | { |
2041 | 2140 | $messages_columns['body'] = $msgOptions['body']; |
@@ -2062,8 +2161,9 @@ discard block |
||
2062 | 2161 | $messages_columns['modified_reason'] = $msgOptions['modify_reason']; |
2063 | 2162 | $messages_columns['id_msg_modified'] = $modSettings['maxMsgID']; |
2064 | 2163 | } |
2065 | - if (isset($msgOptions['smileys_enabled'])) |
|
2066 | - $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2164 | + if (isset($msgOptions['smileys_enabled'])) { |
|
2165 | + $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2166 | + } |
|
2067 | 2167 | |
2068 | 2168 | // Which columns need to be ints? |
2069 | 2169 | $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled'); |
@@ -2074,8 +2174,9 @@ discard block |
||
2074 | 2174 | // Update search api |
2075 | 2175 | require_once($sourcedir . '/Search.php'); |
2076 | 2176 | $searchAPI = findSearchAPI(); |
2077 | - if ($searchAPI->supportsMethod('postRemoved')) |
|
2078 | - $searchAPI->postRemoved($msgOptions['id']); |
|
2177 | + if ($searchAPI->supportsMethod('postRemoved')) { |
|
2178 | + $searchAPI->postRemoved($msgOptions['id']); |
|
2179 | + } |
|
2079 | 2180 | |
2080 | 2181 | if (!empty($modSettings['enable_mentions']) && isset($msgOptions['body'])) |
2081 | 2182 | { |
@@ -2087,23 +2188,27 @@ discard block |
||
2087 | 2188 | { |
2088 | 2189 | preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match); |
2089 | 2190 | |
2090 | - if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) |
|
2091 | - foreach ($match[1] as $i => $oldID) |
|
2191 | + if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) { |
|
2192 | + foreach ($match[1] as $i => $oldID) |
|
2092 | 2193 | $oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]); |
2194 | + } |
|
2093 | 2195 | |
2094 | - if (empty($modSettings['search_custom_index_config'])) |
|
2095 | - unset($msgOptions['old_body']); |
|
2196 | + if (empty($modSettings['search_custom_index_config'])) { |
|
2197 | + unset($msgOptions['old_body']); |
|
2198 | + } |
|
2096 | 2199 | } |
2097 | 2200 | |
2098 | 2201 | $mentions = Mentions::getMentionedMembers($msgOptions['body']); |
2099 | 2202 | $messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions); |
2100 | 2203 | |
2101 | 2204 | // Remove the poster. |
2102 | - if (isset($mentions[$user_info['id']])) |
|
2103 | - unset($mentions[$user_info['id']]); |
|
2205 | + if (isset($mentions[$user_info['id']])) { |
|
2206 | + unset($mentions[$user_info['id']]); |
|
2207 | + } |
|
2104 | 2208 | |
2105 | - if (isset($oldmentions[$user_info['id']])) |
|
2106 | - unset($oldmentions[$user_info['id']]); |
|
2209 | + if (isset($oldmentions[$user_info['id']])) { |
|
2210 | + unset($oldmentions[$user_info['id']]); |
|
2211 | + } |
|
2107 | 2212 | |
2108 | 2213 | if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions)) |
2109 | 2214 | { |
@@ -2133,8 +2238,9 @@ discard block |
||
2133 | 2238 | } |
2134 | 2239 | |
2135 | 2240 | // Nothing to do? |
2136 | - if (empty($messages_columns)) |
|
2137 | - return true; |
|
2241 | + if (empty($messages_columns)) { |
|
2242 | + return true; |
|
2243 | + } |
|
2138 | 2244 | |
2139 | 2245 | // Change the post. |
2140 | 2246 | $smcFunc['db_query']('', ' |
@@ -2195,8 +2301,9 @@ discard block |
||
2195 | 2301 | // If there's a custom search index, it needs to be modified... |
2196 | 2302 | require_once($sourcedir . '/Search.php'); |
2197 | 2303 | $searchAPI = findSearchAPI(); |
2198 | - if (is_callable(array($searchAPI, 'postModified'))) |
|
2199 | - $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2304 | + if (is_callable(array($searchAPI, 'postModified'))) { |
|
2305 | + $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2306 | + } |
|
2200 | 2307 | |
2201 | 2308 | if (isset($msgOptions['subject'])) |
2202 | 2309 | { |
@@ -2210,14 +2317,16 @@ discard block |
||
2210 | 2317 | 'id_first_msg' => $msgOptions['id'], |
2211 | 2318 | ) |
2212 | 2319 | ); |
2213 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
2214 | - updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2320 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
2321 | + updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2322 | + } |
|
2215 | 2323 | $smcFunc['db_free_result']($request); |
2216 | 2324 | } |
2217 | 2325 | |
2218 | 2326 | // Finally, if we are setting the approved state we need to do much more work :( |
2219 | - if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) |
|
2220 | - approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2327 | + if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) { |
|
2328 | + approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2329 | + } |
|
2221 | 2330 | |
2222 | 2331 | return true; |
2223 | 2332 | } |
@@ -2234,11 +2343,13 @@ discard block |
||
2234 | 2343 | { |
2235 | 2344 | global $smcFunc; |
2236 | 2345 | |
2237 | - if (!is_array($msgs)) |
|
2238 | - $msgs = array($msgs); |
|
2346 | + if (!is_array($msgs)) { |
|
2347 | + $msgs = array($msgs); |
|
2348 | + } |
|
2239 | 2349 | |
2240 | - if (empty($msgs)) |
|
2241 | - return false; |
|
2350 | + if (empty($msgs)) { |
|
2351 | + return false; |
|
2352 | + } |
|
2242 | 2353 | |
2243 | 2354 | // May as well start at the beginning, working out *what* we need to change. |
2244 | 2355 | $request = $smcFunc['db_query']('', ' |
@@ -2270,20 +2381,22 @@ discard block |
||
2270 | 2381 | $topics[] = $row['id_topic']; |
2271 | 2382 | |
2272 | 2383 | // Ensure our change array exists already. |
2273 | - if (!isset($topic_changes[$row['id_topic']])) |
|
2274 | - $topic_changes[$row['id_topic']] = array( |
|
2384 | + if (!isset($topic_changes[$row['id_topic']])) { |
|
2385 | + $topic_changes[$row['id_topic']] = array( |
|
2275 | 2386 | 'id_last_msg' => $row['id_last_msg'], |
2276 | 2387 | 'approved' => $row['topic_approved'], |
2277 | 2388 | 'replies' => 0, |
2278 | 2389 | 'unapproved_posts' => 0, |
2279 | 2390 | ); |
2280 | - if (!isset($board_changes[$row['id_board']])) |
|
2281 | - $board_changes[$row['id_board']] = array( |
|
2391 | + } |
|
2392 | + if (!isset($board_changes[$row['id_board']])) { |
|
2393 | + $board_changes[$row['id_board']] = array( |
|
2282 | 2394 | 'posts' => 0, |
2283 | 2395 | 'topics' => 0, |
2284 | 2396 | 'unapproved_posts' => 0, |
2285 | 2397 | 'unapproved_topics' => 0, |
2286 | 2398 | ); |
2399 | + } |
|
2287 | 2400 | |
2288 | 2401 | // If it's the first message then the topic state changes! |
2289 | 2402 | if ($row['id_msg'] == $row['id_first_msg']) |
@@ -2304,14 +2417,13 @@ discard block |
||
2304 | 2417 | 'poster' => $row['id_member'], |
2305 | 2418 | 'new_topic' => true, |
2306 | 2419 | ); |
2307 | - } |
|
2308 | - else |
|
2420 | + } else |
|
2309 | 2421 | { |
2310 | 2422 | $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1; |
2311 | 2423 | |
2312 | 2424 | // This will be a post... but don't notify unless it's not followed by approved ones. |
2313 | - if ($row['id_msg'] > $row['id_last_msg']) |
|
2314 | - $notification_posts[$row['id_topic']] = array( |
|
2425 | + if ($row['id_msg'] > $row['id_last_msg']) { |
|
2426 | + $notification_posts[$row['id_topic']] = array( |
|
2315 | 2427 | 'id' => $row['id_msg'], |
2316 | 2428 | 'body' => $row['body'], |
2317 | 2429 | 'subject' => $row['subject'], |
@@ -2322,28 +2434,33 @@ discard block |
||
2322 | 2434 | 'new_topic' => false, |
2323 | 2435 | 'msg' => $row['id_msg'], |
2324 | 2436 | ); |
2437 | + } |
|
2325 | 2438 | } |
2326 | 2439 | |
2327 | 2440 | // If this is being approved and id_msg is higher than the current id_last_msg then it changes. |
2328 | - if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) |
|
2329 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2441 | + if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) { |
|
2442 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2443 | + } |
|
2330 | 2444 | // If this is being unapproved, and it's equal to the id_last_msg we need to find a new one! |
2331 | - elseif (!$approve) |
|
2332 | - // Default to the first message and then we'll override in a bit ;) |
|
2445 | + elseif (!$approve) { |
|
2446 | + // Default to the first message and then we'll override in a bit ;) |
|
2333 | 2447 | $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg']; |
2448 | + } |
|
2334 | 2449 | |
2335 | 2450 | $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1; |
2336 | 2451 | $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1; |
2337 | 2452 | $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1; |
2338 | 2453 | |
2339 | 2454 | // Post count for the user? |
2340 | - if ($row['id_member'] && empty($row['count_posts'])) |
|
2341 | - $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2455 | + if ($row['id_member'] && empty($row['count_posts'])) { |
|
2456 | + $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2457 | + } |
|
2342 | 2458 | } |
2343 | 2459 | $smcFunc['db_free_result']($request); |
2344 | 2460 | |
2345 | - if (empty($msgs)) |
|
2346 | - return; |
|
2461 | + if (empty($msgs)) { |
|
2462 | + return; |
|
2463 | + } |
|
2347 | 2464 | |
2348 | 2465 | // Now we have the differences make the changes, first the easy one. |
2349 | 2466 | $smcFunc['db_query']('', ' |
@@ -2370,14 +2487,15 @@ discard block |
||
2370 | 2487 | 'approved' => 1, |
2371 | 2488 | ) |
2372 | 2489 | ); |
2373 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2374 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2490 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2491 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2492 | + } |
|
2375 | 2493 | $smcFunc['db_free_result']($request); |
2376 | 2494 | } |
2377 | 2495 | |
2378 | 2496 | // ... next the topics... |
2379 | - foreach ($topic_changes as $id => $changes) |
|
2380 | - $smcFunc['db_query']('', ' |
|
2497 | + foreach ($topic_changes as $id => $changes) { |
|
2498 | + $smcFunc['db_query']('', ' |
|
2381 | 2499 | UPDATE {db_prefix}topics |
2382 | 2500 | SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2383 | 2501 | num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg} |
@@ -2390,10 +2508,11 @@ discard block |
||
2390 | 2508 | 'id_topic' => $id, |
2391 | 2509 | ) |
2392 | 2510 | ); |
2511 | + } |
|
2393 | 2512 | |
2394 | 2513 | // ... finally the boards... |
2395 | - foreach ($board_changes as $id => $changes) |
|
2396 | - $smcFunc['db_query']('', ' |
|
2514 | + foreach ($board_changes as $id => $changes) { |
|
2515 | + $smcFunc['db_query']('', ' |
|
2397 | 2516 | UPDATE {db_prefix}boards |
2398 | 2517 | SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2399 | 2518 | num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics} |
@@ -2406,13 +2525,14 @@ discard block |
||
2406 | 2525 | 'id_board' => $id, |
2407 | 2526 | ) |
2408 | 2527 | ); |
2528 | + } |
|
2409 | 2529 | |
2410 | 2530 | // Finally, least importantly, notifications! |
2411 | 2531 | if ($approve) |
2412 | 2532 | { |
2413 | 2533 | $task_rows = array(); |
2414 | - foreach (array_merge($notification_topics, $notification_posts) as $topic) |
|
2415 | - $task_rows[] = array( |
|
2534 | + foreach (array_merge($notification_topics, $notification_posts) as $topic) { |
|
2535 | + $task_rows[] = array( |
|
2416 | 2536 | '$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array( |
2417 | 2537 | 'msgOptions' => array( |
2418 | 2538 | 'id' => $topic['msg'], |
@@ -2430,14 +2550,16 @@ discard block |
||
2430 | 2550 | 'type' => $topic['new_topic'] ? 'topic' : 'reply', |
2431 | 2551 | )), 0 |
2432 | 2552 | ); |
2553 | + } |
|
2433 | 2554 | |
2434 | - if ($notify) |
|
2435 | - $smcFunc['db_insert']('', |
|
2555 | + if ($notify) { |
|
2556 | + $smcFunc['db_insert']('', |
|
2436 | 2557 | '{db_prefix}background_tasks', |
2437 | 2558 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2438 | 2559 | $task_rows, |
2439 | 2560 | array('id_task') |
2440 | 2561 | ); |
2562 | + } |
|
2441 | 2563 | |
2442 | 2564 | $smcFunc['db_query']('', ' |
2443 | 2565 | DELETE FROM {db_prefix}approval_queue |
@@ -2453,8 +2575,9 @@ discard block |
||
2453 | 2575 | else |
2454 | 2576 | { |
2455 | 2577 | $msgInserts = array(); |
2456 | - foreach ($msgs as $msg) |
|
2457 | - $msgInserts[] = array($msg); |
|
2578 | + foreach ($msgs as $msg) { |
|
2579 | + $msgInserts[] = array($msg); |
|
2580 | + } |
|
2458 | 2581 | |
2459 | 2582 | $smcFunc['db_insert']('ignore', |
2460 | 2583 | '{db_prefix}approval_queue', |
@@ -2468,9 +2591,10 @@ discard block |
||
2468 | 2591 | updateLastMessages(array_keys($board_changes)); |
2469 | 2592 | |
2470 | 2593 | // Post count for the members? |
2471 | - if (!empty($member_post_changes)) |
|
2472 | - foreach ($member_post_changes as $id_member => $count_change) |
|
2594 | + if (!empty($member_post_changes)) { |
|
2595 | + foreach ($member_post_changes as $id_member => $count_change) |
|
2473 | 2596 | updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change)); |
2597 | + } |
|
2474 | 2598 | |
2475 | 2599 | return true; |
2476 | 2600 | } |
@@ -2487,11 +2611,13 @@ discard block |
||
2487 | 2611 | { |
2488 | 2612 | global $smcFunc; |
2489 | 2613 | |
2490 | - if (!is_array($topics)) |
|
2491 | - $topics = array($topics); |
|
2614 | + if (!is_array($topics)) { |
|
2615 | + $topics = array($topics); |
|
2616 | + } |
|
2492 | 2617 | |
2493 | - if (empty($topics)) |
|
2494 | - return false; |
|
2618 | + if (empty($topics)) { |
|
2619 | + return false; |
|
2620 | + } |
|
2495 | 2621 | |
2496 | 2622 | $approve_type = $approve ? 0 : 1; |
2497 | 2623 | |
@@ -2507,8 +2633,9 @@ discard block |
||
2507 | 2633 | ) |
2508 | 2634 | ); |
2509 | 2635 | $msgs = array(); |
2510 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2511 | - $msgs[] = $row['id_msg']; |
|
2636 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2637 | + $msgs[] = $row['id_msg']; |
|
2638 | + } |
|
2512 | 2639 | $smcFunc['db_free_result']($request); |
2513 | 2640 | |
2514 | 2641 | return approvePosts($msgs, $approve); |
@@ -2531,11 +2658,13 @@ discard block |
||
2531 | 2658 | global $board_info, $board, $smcFunc; |
2532 | 2659 | |
2533 | 2660 | // Please - let's be sane. |
2534 | - if (empty($setboards)) |
|
2535 | - return false; |
|
2661 | + if (empty($setboards)) { |
|
2662 | + return false; |
|
2663 | + } |
|
2536 | 2664 | |
2537 | - if (!is_array($setboards)) |
|
2538 | - $setboards = array($setboards); |
|
2665 | + if (!is_array($setboards)) { |
|
2666 | + $setboards = array($setboards); |
|
2667 | + } |
|
2539 | 2668 | |
2540 | 2669 | // If we don't know the id_msg we need to find it. |
2541 | 2670 | if (!$id_msg) |
@@ -2553,15 +2682,16 @@ discard block |
||
2553 | 2682 | ) |
2554 | 2683 | ); |
2555 | 2684 | $lastMsg = array(); |
2556 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2557 | - $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2685 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2686 | + $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2687 | + } |
|
2558 | 2688 | $smcFunc['db_free_result']($request); |
2559 | - } |
|
2560 | - else |
|
2689 | + } else |
|
2561 | 2690 | { |
2562 | 2691 | // Just to note - there should only be one board passed if we are doing this. |
2563 | - foreach ($setboards as $id_board) |
|
2564 | - $lastMsg[$id_board] = $id_msg; |
|
2692 | + foreach ($setboards as $id_board) { |
|
2693 | + $lastMsg[$id_board] = $id_msg; |
|
2694 | + } |
|
2565 | 2695 | } |
2566 | 2696 | |
2567 | 2697 | $parent_boards = array(); |
@@ -2576,10 +2706,11 @@ discard block |
||
2576 | 2706 | $lastModified[$id_board] = 0; |
2577 | 2707 | } |
2578 | 2708 | |
2579 | - if (!empty($board) && $id_board == $board) |
|
2580 | - $parents = $board_info['parent_boards']; |
|
2581 | - else |
|
2582 | - $parents = getBoardParents($id_board); |
|
2709 | + if (!empty($board) && $id_board == $board) { |
|
2710 | + $parents = $board_info['parent_boards']; |
|
2711 | + } else { |
|
2712 | + $parents = getBoardParents($id_board); |
|
2713 | + } |
|
2583 | 2714 | |
2584 | 2715 | // Ignore any parents on the top child level. |
2585 | 2716 | // @todo Why? |
@@ -2588,10 +2719,11 @@ discard block |
||
2588 | 2719 | if ($parent['level'] != 0) |
2589 | 2720 | { |
2590 | 2721 | // If we're already doing this one as a board, is this a higher last modified? |
2591 | - if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) |
|
2592 | - $lastModified[$id] = $lastModified[$id_board]; |
|
2593 | - elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) |
|
2594 | - $parent_boards[$id] = $lastModified[$id_board]; |
|
2722 | + if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) { |
|
2723 | + $lastModified[$id] = $lastModified[$id_board]; |
|
2724 | + } elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) { |
|
2725 | + $parent_boards[$id] = $lastModified[$id_board]; |
|
2726 | + } |
|
2595 | 2727 | } |
2596 | 2728 | } |
2597 | 2729 | } |
@@ -2604,23 +2736,24 @@ discard block |
||
2604 | 2736 | // Finally, to save on queries make the changes... |
2605 | 2737 | foreach ($parent_boards as $id => $msg) |
2606 | 2738 | { |
2607 | - if (!isset($parent_updates[$msg])) |
|
2608 | - $parent_updates[$msg] = array($id); |
|
2609 | - else |
|
2610 | - $parent_updates[$msg][] = $id; |
|
2739 | + if (!isset($parent_updates[$msg])) { |
|
2740 | + $parent_updates[$msg] = array($id); |
|
2741 | + } else { |
|
2742 | + $parent_updates[$msg][] = $id; |
|
2743 | + } |
|
2611 | 2744 | } |
2612 | 2745 | |
2613 | 2746 | foreach ($lastMsg as $id => $msg) |
2614 | 2747 | { |
2615 | - if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) |
|
2616 | - $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2748 | + if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) { |
|
2749 | + $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2617 | 2750 | 'id' => $msg, |
2618 | 2751 | 'updated' => $lastModified[$id], |
2619 | 2752 | 'boards' => array($id) |
2620 | 2753 | ); |
2621 | - |
|
2622 | - else |
|
2623 | - $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2754 | + } else { |
|
2755 | + $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2756 | + } |
|
2624 | 2757 | } |
2625 | 2758 | |
2626 | 2759 | // Now commit the changes! |
@@ -2712,11 +2845,13 @@ discard block |
||
2712 | 2845 | global $txt, $mbname, $scripturl, $settings; |
2713 | 2846 | |
2714 | 2847 | // First things first, load up the email templates language file, if we need to. |
2715 | - if ($loadLang) |
|
2716 | - loadLanguage('EmailTemplates', $lang); |
|
2848 | + if ($loadLang) { |
|
2849 | + loadLanguage('EmailTemplates', $lang); |
|
2850 | + } |
|
2717 | 2851 | |
2718 | - if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) |
|
2719 | - fatal_lang_error('email_no_template', 'template', array($template)); |
|
2852 | + if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) { |
|
2853 | + fatal_lang_error('email_no_template', 'template', array($template)); |
|
2854 | + } |
|
2720 | 2855 | |
2721 | 2856 | $ret = array( |
2722 | 2857 | 'subject' => $txt[$template . '_subject'], |
@@ -2766,17 +2901,18 @@ discard block |
||
2766 | 2901 | function user_info_callback($matches) |
2767 | 2902 | { |
2768 | 2903 | global $user_info; |
2769 | - if (empty($matches[1])) |
|
2770 | - return ''; |
|
2904 | + if (empty($matches[1])) { |
|
2905 | + return ''; |
|
2906 | + } |
|
2771 | 2907 | |
2772 | 2908 | $use_ref = true; |
2773 | 2909 | $ref = &$user_info; |
2774 | 2910 | |
2775 | 2911 | foreach (explode('.', $matches[1]) as $index) |
2776 | 2912 | { |
2777 | - if ($use_ref && isset($ref[$index])) |
|
2778 | - $ref = &$ref[$index]; |
|
2779 | - else |
|
2913 | + if ($use_ref && isset($ref[$index])) { |
|
2914 | + $ref = &$ref[$index]; |
|
2915 | + } else |
|
2780 | 2916 | { |
2781 | 2917 | $use_ref = false; |
2782 | 2918 | break; |
@@ -2813,8 +2949,7 @@ discard block |
||
2813 | 2949 | if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale)) |
2814 | 2950 | { |
2815 | 2951 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale); |
2816 | - } |
|
2817 | - elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2952 | + } elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2818 | 2953 | { |
2819 | 2954 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']); |
2820 | 2955 | } |
@@ -2824,8 +2959,7 @@ discard block |
||
2824 | 2959 | { |
2825 | 2960 | $context['provider'] = 'enchant'; |
2826 | 2961 | return $enchant_link; |
2827 | - } |
|
2828 | - else |
|
2962 | + } else |
|
2829 | 2963 | { |
2830 | 2964 | // Free up any resources used... |
2831 | 2965 | @enchant_broker_free($context['enchant_broker']); |
@@ -2846,8 +2980,9 @@ discard block |
||
2846 | 2980 | $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER); |
2847 | 2981 | |
2848 | 2982 | // Most people don't have anything but English installed... So we use English as a last resort. |
2849 | - if (!$pspell_link) |
|
2850 | - $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
2983 | + if (!$pspell_link) { |
|
2984 | + $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
2985 | + } |
|
2851 | 2986 | |
2852 | 2987 | error_reporting($old); |
2853 | 2988 | ob_end_clean(); |
@@ -2887,8 +3022,7 @@ discard block |
||
2887 | 3022 | $word = iconv($txt['lang_character_set'], 'UTF-8', $word); |
2888 | 3023 | } |
2889 | 3024 | return enchant_dict_check($dict, $word); |
2890 | - } |
|
2891 | - elseif ($context['provider'] == 'pspell') |
|
3025 | + } elseif ($context['provider'] == 'pspell') |
|
2892 | 3026 | { |
2893 | 3027 | return pspell_check($dict, $word); |
2894 | 3028 | } |
@@ -2924,13 +3058,11 @@ discard block |
||
2924 | 3058 | } |
2925 | 3059 | |
2926 | 3060 | return $suggestions; |
2927 | - } |
|
2928 | - else |
|
3061 | + } else |
|
2929 | 3062 | { |
2930 | 3063 | return enchant_dict_suggest($dict, $word); |
2931 | 3064 | } |
2932 | - } |
|
2933 | - elseif ($context['provider'] == 'pspell') |
|
3065 | + } elseif ($context['provider'] == 'pspell') |
|
2934 | 3066 | { |
2935 | 3067 | return pspell_suggest($dict, $word); |
2936 | 3068 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | |
224 | 224 | global $smcFunc; |
225 | 225 | |
226 | - $result = $smcFunc['db_query']('',' |
|
226 | + $result = $smcFunc['db_query']('', ' |
|
227 | 227 | SELECT DISTINCT id_search |
228 | 228 | FROM {db_prefix}log_search_results |
229 | 229 | WHERE id_msg = {int:id_msg}', |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | if (count($id_searchs) < 1) |
240 | 240 | return; |
241 | 241 | |
242 | - $smcFunc['db_query']('',' |
|
242 | + $smcFunc['db_query']('', ' |
|
243 | 243 | DELETE FROM {db_prefix}log_search_results |
244 | 244 | WHERE id_search in ({array_int:id_searchs})', |
245 | 245 | array( |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | ) |
248 | 248 | ); |
249 | 249 | |
250 | - $smcFunc['db_query']('',' |
|
250 | + $smcFunc['db_query']('', ' |
|
251 | 251 | DELETE FROM {db_prefix}log_search_topics |
252 | 252 | WHERE id_search in ({array_int:id_searchs})', |
253 | 253 | array( |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | ) |
256 | 256 | ); |
257 | 257 | |
258 | - $smcFunc['db_query']('',' |
|
258 | + $smcFunc['db_query']('', ' |
|
259 | 259 | DELETE FROM {db_prefix}log_search_messages |
260 | 260 | WHERE id_search in ({array_int:id_searchs})', |
261 | 261 | array( |
@@ -233,11 +233,13 @@ |
||
233 | 233 | ); |
234 | 234 | |
235 | 235 | $id_searchs = array(); |
236 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
237 | - $id_searchs[] = $row['id_search']; |
|
236 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
237 | + $id_searchs[] = $row['id_search']; |
|
238 | + } |
|
238 | 239 | |
239 | - if (count($id_searchs) < 1) |
|
240 | - return; |
|
240 | + if (count($id_searchs) < 1) { |
|
241 | + return; |
|
242 | + } |
|
241 | 243 | |
242 | 244 | $smcFunc['db_query']('',' |
243 | 245 | DELETE FROM {db_prefix}log_search_results |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * @var array Which databases support this method? |
35 | 35 | */ |
36 | - protected $supported_databases = array('mysql','postgresql'); |
|
36 | + protected $supported_databases = array('mysql', 'postgresql'); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * The constructor function |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $query_where = array(); |
177 | 177 | $query_params = $search_data['params']; |
178 | 178 | |
179 | - if( $smcFunc['db_title'] == "PostgreSQL") |
|
179 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
180 | 180 | $modSettings['search_simple_fulltext'] = true; |
181 | 181 | |
182 | 182 | if ($query_params['id_search']) |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | // if we have bool terms to search, add them in |
257 | 257 | if ($query_params['boolean_match']) |
258 | 258 | { |
259 | - if($smcFunc['db_title'] == "PostgreSQL") |
|
259 | + if ($smcFunc['db_title'] == "PostgreSQL") |
|
260 | 260 | { |
261 | 261 | $language_ftx = $smcFunc['db_search_language'](); |
262 | 262 | |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
271 | - $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? ( ' |
|
271 | + $ignoreRequest = $smcFunc['db_search_query']('insert_into_log_messages_fulltext', ($smcFunc['db_support_ignore'] ? (' |
|
272 | 272 | INSERT IGNORE INTO {db_prefix}' . $search_data['insert_into'] . ' |
273 | 273 | (' . implode(', ', array_keys($query_select)) . ')') : '') . ' |
274 | 274 | SELECT ' . implode(', ', $query_select) . ' |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 4 |
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 | * Class fulltext_search |
@@ -75,8 +76,9 @@ discard block |
||
75 | 76 | } |
76 | 77 | |
77 | 78 | // Maybe parent got support |
78 | - if (!$return) |
|
79 | - $return = parent::supportsMethod($methodName, $query_params); |
|
79 | + if (!$return) { |
|
80 | + $return = parent::supportsMethod($methodName, $query_params); |
|
81 | + } |
|
80 | 82 | |
81 | 83 | return $return; |
82 | 84 | } |
@@ -92,8 +94,9 @@ discard block |
||
92 | 94 | { |
93 | 95 | global $smcFunc, $db_type; |
94 | 96 | |
95 | - if ($db_type == 'postgresql') |
|
96 | - return 0; |
|
97 | + if ($db_type == 'postgresql') { |
|
98 | + return 0; |
|
99 | + } |
|
97 | 100 | // Try to determine the minimum number of letters for a fulltext search. |
98 | 101 | $request = $smcFunc['db_search_query']('max_fulltext_length', ' |
99 | 102 | SHOW VARIABLES |
@@ -108,8 +111,9 @@ discard block |
||
108 | 111 | $smcFunc['db_free_result']($request); |
109 | 112 | } |
110 | 113 | // 4 is the MySQL default... |
111 | - else |
|
112 | - $min_word_length = 4; |
|
114 | + else { |
|
115 | + $min_word_length = 4; |
|
116 | + } |
|
113 | 117 | |
114 | 118 | return $min_word_length; |
115 | 119 | } |
@@ -148,8 +152,7 @@ discard block |
||
148 | 152 | $wordsSearch['words'][] = trim($word, "/*- "); |
149 | 153 | $wordsSearch['complex_words'][] = count($subwords) === 1 ? $word : '"' . $word . '"'; |
150 | 154 | } |
151 | - } |
|
152 | - elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
155 | + } elseif ($smcFunc['strlen'](trim($word, "/*- ")) < $this->min_word_length) |
|
153 | 156 | { |
154 | 157 | // short words have feelings too |
155 | 158 | $wordsSearch['words'][] = trim($word, "/*- "); |
@@ -159,8 +162,9 @@ discard block |
||
159 | 162 | |
160 | 163 | $fulltextWord = count($subwords) === 1 ? $word : '"' . $word . '"'; |
161 | 164 | $wordsSearch['indexed_words'][] = $fulltextWord; |
162 | - if ($isExcluded) |
|
163 | - $wordsExclude[] = $fulltextWord; |
|
165 | + if ($isExcluded) { |
|
166 | + $wordsExclude[] = $fulltextWord; |
|
167 | + } |
|
164 | 168 | } |
165 | 169 | |
166 | 170 | /** |
@@ -176,44 +180,54 @@ discard block |
||
176 | 180 | $query_where = array(); |
177 | 181 | $query_params = $search_data['params']; |
178 | 182 | |
179 | - if( $smcFunc['db_title'] == "PostgreSQL") |
|
180 | - $modSettings['search_simple_fulltext'] = true; |
|
183 | + if( $smcFunc['db_title'] == "PostgreSQL") { |
|
184 | + $modSettings['search_simple_fulltext'] = true; |
|
185 | + } |
|
181 | 186 | |
182 | - if ($query_params['id_search']) |
|
183 | - $query_select['id_search'] = '{int:id_search}'; |
|
187 | + if ($query_params['id_search']) { |
|
188 | + $query_select['id_search'] = '{int:id_search}'; |
|
189 | + } |
|
184 | 190 | |
185 | 191 | $count = 0; |
186 | - if (empty($modSettings['search_simple_fulltext'])) |
|
187 | - foreach ($words['words'] as $regularWord) |
|
192 | + if (empty($modSettings['search_simple_fulltext'])) { |
|
193 | + foreach ($words['words'] as $regularWord) |
|
188 | 194 | { |
189 | 195 | $query_where[] = 'm.body' . (in_array($regularWord, $query_params['excluded_words']) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:complex_body_' . $count . '}'; |
196 | + } |
|
190 | 197 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
191 | 198 | } |
192 | 199 | |
193 | - if ($query_params['user_query']) |
|
194 | - $query_where[] = '{raw:user_query}'; |
|
195 | - if ($query_params['board_query']) |
|
196 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
200 | + if ($query_params['user_query']) { |
|
201 | + $query_where[] = '{raw:user_query}'; |
|
202 | + } |
|
203 | + if ($query_params['board_query']) { |
|
204 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
205 | + } |
|
197 | 206 | |
198 | - if ($query_params['topic']) |
|
199 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
200 | - if ($query_params['min_msg_id']) |
|
201 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
202 | - if ($query_params['max_msg_id']) |
|
203 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
207 | + if ($query_params['topic']) { |
|
208 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
209 | + } |
|
210 | + if ($query_params['min_msg_id']) { |
|
211 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
212 | + } |
|
213 | + if ($query_params['max_msg_id']) { |
|
214 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
215 | + } |
|
204 | 216 | |
205 | 217 | $count = 0; |
206 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
207 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
218 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
219 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
208 | 220 | { |
209 | 221 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_phrase_' . $count . '}'; |
222 | + } |
|
210 | 223 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
211 | 224 | } |
212 | 225 | $count = 0; |
213 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
214 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
226 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
227 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
215 | 228 | { |
216 | 229 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : 'RLIKE') . '{string:exclude_subject_words_' . $count . '}'; |
230 | + } |
|
217 | 231 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
218 | 232 | } |
219 | 233 | |
@@ -225,12 +239,11 @@ discard block |
||
225 | 239 | |
226 | 240 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:body_match})'; |
227 | 241 | $query_params['language_ftx'] = $language_ftx; |
242 | + } else { |
|
243 | + $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
228 | 244 | } |
229 | - else |
|
230 | - $query_where[] = 'MATCH (body) AGAINST ({string:body_match})'; |
|
231 | 245 | $query_params['body_match'] = implode(' ', array_diff($words['indexed_words'], $query_params['excluded_index_words'])); |
232 | - } |
|
233 | - else |
|
246 | + } else |
|
234 | 247 | { |
235 | 248 | $query_params['boolean_match'] = ''; |
236 | 249 | |
@@ -246,10 +259,10 @@ discard block |
||
246 | 259 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '!' : '') . $fulltextWord . ' '; |
247 | 260 | $row++; |
248 | 261 | } |
249 | - } |
|
250 | - else |
|
251 | - foreach ($words['indexed_words'] as $fulltextWord) |
|
262 | + } else { |
|
263 | + foreach ($words['indexed_words'] as $fulltextWord) |
|
252 | 264 | $query_params['boolean_match'] .= (in_array($fulltextWord, $query_params['excluded_index_words']) ? '-' : '+') . $fulltextWord . ' '; |
265 | + } |
|
253 | 266 | |
254 | 267 | $query_params['boolean_match'] = substr($query_params['boolean_match'], 0, -1); |
255 | 268 | |
@@ -262,9 +275,9 @@ discard block |
||
262 | 275 | |
263 | 276 | $query_where[] = 'to_tsvector({string:language_ftx},body) @@ plainto_tsquery({string:language_ftx},{string:boolean_match})'; |
264 | 277 | $query_params['language_ftx'] = $language_ftx; |
278 | + } else { |
|
279 | + $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
265 | 280 | } |
266 | - else |
|
267 | - $query_where[] = 'MATCH (body) AGAINST ({string:boolean_match} IN BOOLEAN MODE)'; |
|
268 | 281 | } |
269 | 282 | } |
270 | 283 |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 4 |
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 | * Standard non full index, non custom index search |
@@ -27,8 +28,9 @@ discard block |
||
27 | 28 | $return = false; |
28 | 29 | |
29 | 30 | // Maybe parent got support |
30 | - if (!$return) |
|
31 | - $return = parent::supportsMethod($methodName, $query_params); |
|
31 | + if (!$return) { |
|
32 | + $return = parent::supportsMethod($methodName, $query_params); |
|
33 | + } |
|
32 | 34 | |
33 | 35 | return $return; |
34 | 36 | } |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 4 |
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 | * Used for the "custom search index" option |
@@ -54,8 +55,9 @@ discard block |
||
54 | 55 | return; |
55 | 56 | } |
56 | 57 | |
57 | - if (empty($modSettings['search_custom_index_config'])) |
|
58 | - return; |
|
58 | + if (empty($modSettings['search_custom_index_config'])) { |
|
59 | + return; |
|
60 | + } |
|
59 | 61 | |
60 | 62 | $this->indexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true); |
61 | 63 | |
@@ -86,8 +88,9 @@ discard block |
||
86 | 88 | } |
87 | 89 | |
88 | 90 | // Maybe parent got support |
89 | - if (!$return) |
|
90 | - $return = parent::supportsMethod($methodName, $query_params); |
|
91 | + if (!$return) { |
|
92 | + $return = parent::supportsMethod($methodName, $query_params); |
|
93 | + } |
|
91 | 94 | |
92 | 95 | return $return; |
93 | 96 | } |
@@ -124,21 +127,23 @@ discard block |
||
124 | 127 | |
125 | 128 | $subwords = text2words($word, $this->min_word_length, true); |
126 | 129 | |
127 | - if (empty($modSettings['search_force_index'])) |
|
128 | - $wordsSearch['words'][] = $word; |
|
130 | + if (empty($modSettings['search_force_index'])) { |
|
131 | + $wordsSearch['words'][] = $word; |
|
132 | + } |
|
129 | 133 | |
130 | 134 | // Excluded phrases don't benefit from being split into subwords. |
131 | - if (count($subwords) > 1 && $isExcluded) |
|
132 | - return; |
|
133 | - else |
|
135 | + if (count($subwords) > 1 && $isExcluded) { |
|
136 | + return; |
|
137 | + } else |
|
134 | 138 | { |
135 | 139 | foreach ($subwords as $subword) |
136 | 140 | { |
137 | 141 | if ($smcFunc['strlen']($subword) >= $this->min_word_length && !in_array($subword, $this->bannedWords)) |
138 | 142 | { |
139 | 143 | $wordsSearch['indexed_words'][] = $subword; |
140 | - if ($isExcluded) |
|
141 | - $wordsExclude[] = $subword; |
|
144 | + if ($isExcluded) { |
|
145 | + $wordsExclude[] = $subword; |
|
146 | + } |
|
142 | 147 | } |
143 | 148 | } |
144 | 149 | } |
@@ -159,8 +164,9 @@ discard block |
||
159 | 164 | $query_where = array(); |
160 | 165 | $query_params = $search_data['params']; |
161 | 166 | |
162 | - if ($query_params['id_search']) |
|
163 | - $query_select['id_search'] = '{int:id_search}'; |
|
167 | + if ($query_params['id_search']) { |
|
168 | + $query_select['id_search'] = '{int:id_search}'; |
|
169 | + } |
|
164 | 170 | |
165 | 171 | $count = 0; |
166 | 172 | foreach ($words['words'] as $regularWord) |
@@ -169,30 +175,37 @@ discard block |
||
169 | 175 | $query_params['complex_body_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
170 | 176 | } |
171 | 177 | |
172 | - if ($query_params['user_query']) |
|
173 | - $query_where[] = '{raw:user_query}'; |
|
174 | - if ($query_params['board_query']) |
|
175 | - $query_where[] = 'm.id_board {raw:board_query}'; |
|
178 | + if ($query_params['user_query']) { |
|
179 | + $query_where[] = '{raw:user_query}'; |
|
180 | + } |
|
181 | + if ($query_params['board_query']) { |
|
182 | + $query_where[] = 'm.id_board {raw:board_query}'; |
|
183 | + } |
|
176 | 184 | |
177 | - if ($query_params['topic']) |
|
178 | - $query_where[] = 'm.id_topic = {int:topic}'; |
|
179 | - if ($query_params['min_msg_id']) |
|
180 | - $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
181 | - if ($query_params['max_msg_id']) |
|
182 | - $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
185 | + if ($query_params['topic']) { |
|
186 | + $query_where[] = 'm.id_topic = {int:topic}'; |
|
187 | + } |
|
188 | + if ($query_params['min_msg_id']) { |
|
189 | + $query_where[] = 'm.id_msg >= {int:min_msg_id}'; |
|
190 | + } |
|
191 | + if ($query_params['max_msg_id']) { |
|
192 | + $query_where[] = 'm.id_msg <= {int:max_msg_id}'; |
|
193 | + } |
|
183 | 194 | |
184 | 195 | $count = 0; |
185 | - if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) |
|
186 | - foreach ($query_params['excluded_phrases'] as $phrase) |
|
196 | + if (!empty($query_params['excluded_phrases']) && empty($modSettings['search_force_index'])) { |
|
197 | + foreach ($query_params['excluded_phrases'] as $phrase) |
|
187 | 198 | { |
188 | 199 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_phrase_' . $count . '}'; |
200 | + } |
|
189 | 201 | $query_params['exclude_subject_phrase_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($phrase, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $phrase), '\\\'') . '[[:>:]]'; |
190 | 202 | } |
191 | 203 | $count = 0; |
192 | - if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) |
|
193 | - foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
204 | + if (!empty($query_params['excluded_subject_words']) && empty($modSettings['search_force_index'])) { |
|
205 | + foreach ($query_params['excluded_subject_words'] as $excludedWord) |
|
194 | 206 | { |
195 | 207 | $query_where[] = 'subject NOT ' . (empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? ' LIKE ' : ' RLIKE ') . '{string:exclude_subject_words_' . $count . '}'; |
208 | + } |
|
196 | 209 | $query_params['exclude_subject_words_' . $count++] = empty($modSettings['search_match_words']) || $search_data['no_regexp'] ? '%' . strtr($excludedWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $excludedWord), '\\\'') . '[[:>:]]'; |
197 | 210 | } |
198 | 211 | |
@@ -205,8 +218,7 @@ discard block |
||
205 | 218 | { |
206 | 219 | $query_left_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_word = ' . $indexedWord . ' AND lsw' . $numTables . '.id_msg = m.id_msg)'; |
207 | 220 | $query_where[] = '(lsw' . $numTables . '.id_word IS NULL)'; |
208 | - } |
|
209 | - else |
|
221 | + } else |
|
210 | 222 | { |
211 | 223 | $query_inner_join[] = '{db_prefix}log_search_words AS lsw' . $numTables . ' ON (lsw' . $numTables . '.id_msg = ' . ($prev_join === 0 ? 'm' : 'lsw' . $prev_join) . '.id_msg)'; |
212 | 224 | $query_where[] = 'lsw' . $numTables . '.id_word = ' . $indexedWord; |
@@ -242,16 +254,18 @@ discard block |
||
242 | 254 | $customIndexSettings = $smcFunc['json_decode']($modSettings['search_custom_index_config'], true); |
243 | 255 | |
244 | 256 | $inserts = array(); |
245 | - foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) |
|
246 | - $inserts[] = array($word, $msgOptions['id']); |
|
257 | + foreach (text2words($msgOptions['body'], $customIndexSettings['bytes_per_word'], true) as $word) { |
|
258 | + $inserts[] = array($word, $msgOptions['id']); |
|
259 | + } |
|
247 | 260 | |
248 | - if (!empty($inserts)) |
|
249 | - $smcFunc['db_insert']('ignore', |
|
261 | + if (!empty($inserts)) { |
|
262 | + $smcFunc['db_insert']('ignore', |
|
250 | 263 | '{db_prefix}log_search_words', |
251 | 264 | array('id_word' => 'int', 'id_msg' => 'int'), |
252 | 265 | $inserts, |
253 | 266 | array('id_word', 'id_msg') |
254 | 267 | ); |
268 | + } |
|
255 | 269 | } |
256 | 270 | |
257 | 271 | /** |
@@ -294,8 +308,9 @@ discard block |
||
294 | 308 | if (!empty($inserted_words)) |
295 | 309 | { |
296 | 310 | $inserts = array(); |
297 | - foreach ($inserted_words as $word) |
|
298 | - $inserts[] = array($word, $msgOptions['id']); |
|
311 | + foreach ($inserted_words as $word) { |
|
312 | + $inserts[] = array($word, $msgOptions['id']); |
|
313 | + } |
|
299 | 314 | $smcFunc['db_insert']('insert', |
300 | 315 | '{db_prefix}log_search_words', |
301 | 316 | array('id_word' => 'string', 'id_msg' => 'int'), |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
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 | * Handles showing the post screen, loading the post to be modified, and loading any post quoted. |
@@ -35,12 +36,14 @@ discard block |
||
35 | 36 | global $sourcedir, $smcFunc, $language; |
36 | 37 | |
37 | 38 | loadLanguage('Post'); |
38 | - if (!empty($modSettings['drafts_post_enabled'])) |
|
39 | - loadLanguage('Drafts'); |
|
39 | + if (!empty($modSettings['drafts_post_enabled'])) { |
|
40 | + loadLanguage('Drafts'); |
|
41 | + } |
|
40 | 42 | |
41 | 43 | // You can't reply with a poll... hacker. |
42 | - if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) |
|
43 | - unset($_REQUEST['poll']); |
|
44 | + if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) { |
|
45 | + unset($_REQUEST['poll']); |
|
46 | + } |
|
44 | 47 | |
45 | 48 | // Posting an event? |
46 | 49 | $context['make_event'] = isset($_REQUEST['calendar']); |
@@ -58,12 +61,14 @@ discard block |
||
58 | 61 | { |
59 | 62 | // Get ids of all the boards they can post in. |
60 | 63 | $post_permissions = array('post_new'); |
61 | - if ($modSettings['postmod_active']) |
|
62 | - $post_permissions[] = 'post_unapproved_topics'; |
|
64 | + if ($modSettings['postmod_active']) { |
|
65 | + $post_permissions[] = 'post_unapproved_topics'; |
|
66 | + } |
|
63 | 67 | |
64 | 68 | $boards = boardsAllowedTo($post_permissions); |
65 | - if (empty($boards)) |
|
66 | - fatal_lang_error('cannot_post_new', false); |
|
69 | + if (empty($boards)) { |
|
70 | + fatal_lang_error('cannot_post_new', false); |
|
71 | + } |
|
67 | 72 | |
68 | 73 | // Get a list of boards for the select menu |
69 | 74 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
@@ -76,8 +81,9 @@ discard block |
||
76 | 81 | $board_list = getBoardList($boardListOptions); |
77 | 82 | } |
78 | 83 | // Let's keep things simple for ourselves below |
79 | - else |
|
80 | - $boards = array($board); |
|
84 | + else { |
|
85 | + $boards = array($board); |
|
86 | + } |
|
81 | 87 | |
82 | 88 | require_once($sourcedir . '/Subs-Post.php'); |
83 | 89 | |
@@ -100,10 +106,11 @@ discard block |
||
100 | 106 | array( |
101 | 107 | 'msg' => (int) $_REQUEST['msg'], |
102 | 108 | )); |
103 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
104 | - unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
105 | - else |
|
106 | - list ($topic) = $smcFunc['db_fetch_row']($request); |
|
109 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
110 | + unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
111 | + } else { |
|
112 | + list ($topic) = $smcFunc['db_fetch_row']($request); |
|
113 | + } |
|
107 | 114 | $smcFunc['db_free_result']($request); |
108 | 115 | } |
109 | 116 | |
@@ -130,33 +137,36 @@ discard block |
||
130 | 137 | $smcFunc['db_free_result']($request); |
131 | 138 | |
132 | 139 | // If this topic already has a poll, they sure can't add another. |
133 | - if (isset($_REQUEST['poll']) && $pollID > 0) |
|
134 | - unset($_REQUEST['poll']); |
|
140 | + if (isset($_REQUEST['poll']) && $pollID > 0) { |
|
141 | + unset($_REQUEST['poll']); |
|
142 | + } |
|
135 | 143 | |
136 | 144 | if (empty($_REQUEST['msg'])) |
137 | 145 | { |
138 | - if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) |
|
139 | - is_not_guest(); |
|
146 | + if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) { |
|
147 | + is_not_guest(); |
|
148 | + } |
|
140 | 149 | |
141 | 150 | // By default the reply will be approved... |
142 | 151 | $context['becomes_approved'] = true; |
143 | 152 | if ($id_member_poster != $user_info['id'] || $user_info['is_guest']) |
144 | 153 | { |
145 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
146 | - $context['becomes_approved'] = false; |
|
147 | - else |
|
148 | - isAllowedTo('post_reply_any'); |
|
149 | - } |
|
150 | - elseif (!allowedTo('post_reply_any')) |
|
154 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
155 | + $context['becomes_approved'] = false; |
|
156 | + } else { |
|
157 | + isAllowedTo('post_reply_any'); |
|
158 | + } |
|
159 | + } elseif (!allowedTo('post_reply_any')) |
|
151 | 160 | { |
152 | - if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) |
|
153 | - $context['becomes_approved'] = false; |
|
154 | - else |
|
155 | - isAllowedTo('post_reply_own'); |
|
161 | + if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) { |
|
162 | + $context['becomes_approved'] = false; |
|
163 | + } else { |
|
164 | + isAllowedTo('post_reply_own'); |
|
165 | + } |
|
156 | 166 | } |
167 | + } else { |
|
168 | + $context['becomes_approved'] = true; |
|
157 | 169 | } |
158 | - else |
|
159 | - $context['becomes_approved'] = true; |
|
160 | 170 | |
161 | 171 | $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own')); |
162 | 172 | $context['can_sticky'] = allowedTo('make_sticky'); |
@@ -171,17 +181,18 @@ discard block |
||
171 | 181 | $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky; |
172 | 182 | |
173 | 183 | // Check whether this is a really old post being bumped... |
174 | - if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) |
|
175 | - $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
176 | - } |
|
177 | - else |
|
184 | + if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) { |
|
185 | + $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
186 | + } |
|
187 | + } else |
|
178 | 188 | { |
179 | 189 | // @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu |
180 | 190 | $context['becomes_approved'] = true; |
181 | - if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) |
|
182 | - $context['becomes_approved'] = false; |
|
183 | - else |
|
184 | - isAllowedTo('post_new', $boards, true); |
|
191 | + if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) { |
|
192 | + $context['becomes_approved'] = false; |
|
193 | + } else { |
|
194 | + isAllowedTo('post_new', $boards, true); |
|
195 | + } |
|
185 | 196 | |
186 | 197 | $locked = 0; |
187 | 198 | $context['already_locked'] = 0; |
@@ -211,27 +222,32 @@ discard block |
||
211 | 222 | if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached'])) |
212 | 223 | { |
213 | 224 | require_once($sourcedir . '/ManageAttachments.php'); |
214 | - foreach ($_SESSION['already_attached'] as $attachID => $attachment) |
|
215 | - removeAttachments(array('id_attach' => $attachID)); |
|
225 | + foreach ($_SESSION['already_attached'] as $attachID => $attachment) { |
|
226 | + removeAttachments(array('id_attach' => $attachID)); |
|
227 | + } |
|
216 | 228 | |
217 | 229 | unset($_SESSION['already_attached']); |
218 | 230 | } |
219 | 231 | |
220 | 232 | // Don't allow a post if it's locked and you aren't all powerful. |
221 | - if ($locked && !allowedTo('moderate_board')) |
|
222 | - fatal_lang_error('topic_locked', false); |
|
233 | + if ($locked && !allowedTo('moderate_board')) { |
|
234 | + fatal_lang_error('topic_locked', false); |
|
235 | + } |
|
223 | 236 | // Check the users permissions - is the user allowed to add or post a poll? |
224 | 237 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
225 | 238 | { |
226 | 239 | // New topic, new poll. |
227 | - if (empty($topic)) |
|
228 | - isAllowedTo('poll_post'); |
|
240 | + if (empty($topic)) { |
|
241 | + isAllowedTo('poll_post'); |
|
242 | + } |
|
229 | 243 | // This is an old topic - but it is yours! Can you add to it? |
230 | - elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) |
|
231 | - isAllowedTo('poll_add_own'); |
|
244 | + elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) { |
|
245 | + isAllowedTo('poll_add_own'); |
|
246 | + } |
|
232 | 247 | // If you're not the owner, can you add to any poll? |
233 | - else |
|
234 | - isAllowedTo('poll_add_any'); |
|
248 | + else { |
|
249 | + isAllowedTo('poll_add_any'); |
|
250 | + } |
|
235 | 251 | |
236 | 252 | if (!empty($board)) |
237 | 253 | { |
@@ -240,8 +256,9 @@ discard block |
||
240 | 256 | $guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']); |
241 | 257 | } |
242 | 258 | // No board, so we'll have to check this again in Post2 |
243 | - else |
|
244 | - $guest_vote_enabled = true; |
|
259 | + else { |
|
260 | + $guest_vote_enabled = true; |
|
261 | + } |
|
245 | 262 | |
246 | 263 | // Set up the poll options. |
247 | 264 | $context['poll_options'] = array( |
@@ -267,8 +284,9 @@ discard block |
||
267 | 284 | if ($context['make_event']) |
268 | 285 | { |
269 | 286 | // They might want to pick a board. |
270 | - if (!isset($context['current_board'])) |
|
271 | - $context['current_board'] = 0; |
|
287 | + if (!isset($context['current_board'])) { |
|
288 | + $context['current_board'] = 0; |
|
289 | + } |
|
272 | 290 | |
273 | 291 | // Start loading up the event info. |
274 | 292 | $context['event'] = array(); |
@@ -282,10 +300,11 @@ discard block |
||
282 | 300 | isAllowedTo('calendar_post'); |
283 | 301 | |
284 | 302 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
285 | - if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
286 | - $time_string = '%k:%M'; |
|
287 | - else |
|
288 | - $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
303 | + if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
304 | + $time_string = '%k:%M'; |
|
305 | + } else { |
|
306 | + $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
307 | + } |
|
289 | 308 | |
290 | 309 | $js_time_string = str_replace( |
291 | 310 | array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'), |
@@ -307,8 +326,7 @@ discard block |
||
307 | 326 | require_once($sourcedir . '/Subs-Calendar.php'); |
308 | 327 | $eventProperties = getEventProperties($context['event']['id']); |
309 | 328 | $context['event'] = array_merge($context['event'], $eventProperties); |
310 | - } |
|
311 | - else |
|
329 | + } else |
|
312 | 330 | { |
313 | 331 | // Get the current event information. |
314 | 332 | require_once($sourcedir . '/Subs-Calendar.php'); |
@@ -316,10 +334,12 @@ discard block |
||
316 | 334 | $context['event'] = array_merge($context['event'], $eventProperties); |
317 | 335 | |
318 | 336 | // Make sure the year and month are in the valid range. |
319 | - if ($context['event']['month'] < 1 || $context['event']['month'] > 12) |
|
320 | - fatal_lang_error('invalid_month', false); |
|
321 | - if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) |
|
322 | - fatal_lang_error('invalid_year', false); |
|
337 | + if ($context['event']['month'] < 1 || $context['event']['month'] > 12) { |
|
338 | + fatal_lang_error('invalid_month', false); |
|
339 | + } |
|
340 | + if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) { |
|
341 | + fatal_lang_error('invalid_year', false); |
|
342 | + } |
|
323 | 343 | |
324 | 344 | $context['event']['categories'] = $board_list; |
325 | 345 | } |
@@ -430,10 +450,11 @@ discard block |
||
430 | 450 | |
431 | 451 | if (!empty($context['new_replies'])) |
432 | 452 | { |
433 | - if ($context['new_replies'] == 1) |
|
434 | - $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
435 | - else |
|
436 | - $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
453 | + if ($context['new_replies'] == 1) { |
|
454 | + $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
455 | + } else { |
|
456 | + $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
457 | + } |
|
437 | 458 | |
438 | 459 | $post_errors[] = 'new_replies'; |
439 | 460 | |
@@ -445,9 +466,9 @@ discard block |
||
445 | 466 | // Get a response prefix (like 'Re:') in the default forum language. |
446 | 467 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
447 | 468 | { |
448 | - if ($language === $user_info['language']) |
|
449 | - $context['response_prefix'] = $txt['response_prefix']; |
|
450 | - else |
|
469 | + if ($language === $user_info['language']) { |
|
470 | + $context['response_prefix'] = $txt['response_prefix']; |
|
471 | + } else |
|
451 | 472 | { |
452 | 473 | loadLanguage('index', $language, false); |
453 | 474 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -460,23 +481,26 @@ discard block |
||
460 | 481 | // Do we have a body, but an error happened. |
461 | 482 | if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error'])) |
462 | 483 | { |
463 | - if (isset($_REQUEST['quickReply'])) |
|
464 | - $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
484 | + if (isset($_REQUEST['quickReply'])) { |
|
485 | + $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
486 | + } |
|
465 | 487 | |
466 | 488 | // Validate inputs. |
467 | 489 | if (empty($context['post_error'])) |
468 | 490 | { |
469 | 491 | // This means they didn't click Post and get an error. |
470 | 492 | $really_previewing = true; |
471 | - } |
|
472 | - else |
|
493 | + } else |
|
473 | 494 | { |
474 | - if (!isset($_REQUEST['subject'])) |
|
475 | - $_REQUEST['subject'] = ''; |
|
476 | - if (!isset($_REQUEST['message'])) |
|
477 | - $_REQUEST['message'] = ''; |
|
478 | - if (!isset($_REQUEST['icon'])) |
|
479 | - $_REQUEST['icon'] = 'xx'; |
|
495 | + if (!isset($_REQUEST['subject'])) { |
|
496 | + $_REQUEST['subject'] = ''; |
|
497 | + } |
|
498 | + if (!isset($_REQUEST['message'])) { |
|
499 | + $_REQUEST['message'] = ''; |
|
500 | + } |
|
501 | + if (!isset($_REQUEST['icon'])) { |
|
502 | + $_REQUEST['icon'] = 'xx'; |
|
503 | + } |
|
480 | 504 | |
481 | 505 | // They are previewing if they asked to preview (i.e. came from quick reply). |
482 | 506 | $really_previewing = !empty($_POST['preview']); |
@@ -492,8 +516,9 @@ discard block |
||
492 | 516 | $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES); |
493 | 517 | |
494 | 518 | // Make sure the subject isn't too long - taking into account special characters. |
495 | - if ($smcFunc['strlen']($form_subject) > 100) |
|
496 | - $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
519 | + if ($smcFunc['strlen']($form_subject) > 100) { |
|
520 | + $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
521 | + } |
|
497 | 522 | |
498 | 523 | if (isset($_REQUEST['poll'])) |
499 | 524 | { |
@@ -505,8 +530,9 @@ discard block |
||
505 | 530 | $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']); |
506 | 531 | foreach ($_POST['options'] as $option) |
507 | 532 | { |
508 | - if (trim($option) == '') |
|
509 | - continue; |
|
533 | + if (trim($option) == '') { |
|
534 | + continue; |
|
535 | + } |
|
510 | 536 | |
511 | 537 | $context['choices'][] = array( |
512 | 538 | 'id' => $choice_id++, |
@@ -568,13 +594,14 @@ discard block |
||
568 | 594 | $context['preview_subject'] = $form_subject; |
569 | 595 | |
570 | 596 | censorText($context['preview_subject']); |
597 | + } else { |
|
598 | + $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
571 | 599 | } |
572 | - else |
|
573 | - $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
574 | 600 | |
575 | 601 | // Protect any CDATA blocks. |
576 | - if (isset($_REQUEST['xml'])) |
|
577 | - $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>')); |
|
602 | + if (isset($_REQUEST['xml'])) { |
|
603 | + $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]>< == 0) |
|
617 | - fatal_lang_error('no_board', false); |
|
643 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
644 | + fatal_lang_error('no_board', false); |
|
645 | + } |
|
618 | 646 | $row = $smcFunc['db_fetch_assoc']($request); |
619 | 647 | |
620 | 648 | $attachment_stuff = array($row); |
621 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
622 | - $attachment_stuff[] = $row2; |
|
649 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
650 | + $attachment_stuff[] = $row2; |
|
651 | + } |
|
623 | 652 | $smcFunc['db_free_result']($request); |
624 | 653 | |
625 | 654 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
626 | 655 | { |
627 | 656 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
628 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
629 | - fatal_lang_error('modify_post_time_passed', false); |
|
630 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
631 | - isAllowedTo('modify_replies'); |
|
632 | - else |
|
633 | - isAllowedTo('modify_own'); |
|
657 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
658 | + fatal_lang_error('modify_post_time_passed', false); |
|
659 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
660 | + isAllowedTo('modify_replies'); |
|
661 | + } else { |
|
662 | + isAllowedTo('modify_own'); |
|
663 | + } |
|
664 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
665 | + isAllowedTo('modify_replies'); |
|
666 | + } else { |
|
667 | + isAllowedTo('modify_any'); |
|
634 | 668 | } |
635 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
636 | - isAllowedTo('modify_replies'); |
|
637 | - else |
|
638 | - isAllowedTo('modify_any'); |
|
639 | 669 | |
640 | 670 | if ($context['can_announce'] && !empty($row['id_action'])) |
641 | 671 | { |
@@ -659,8 +689,9 @@ discard block |
||
659 | 689 | |
660 | 690 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
661 | 691 | { |
662 | - if ($row['filesize'] <= 0) |
|
663 | - continue; |
|
692 | + if ($row['filesize'] <= 0) { |
|
693 | + continue; |
|
694 | + } |
|
664 | 695 | $context['current_attachments'][$row['id_attach']] = array( |
665 | 696 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
666 | 697 | 'size' => $row['filesize'], |
@@ -730,29 +761,32 @@ discard block |
||
730 | 761 | ) |
731 | 762 | ); |
732 | 763 | // The message they were trying to edit was most likely deleted. |
733 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
734 | - fatal_lang_error('no_message', false); |
|
764 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
765 | + fatal_lang_error('no_message', false); |
|
766 | + } |
|
735 | 767 | $row = $smcFunc['db_fetch_assoc']($request); |
736 | 768 | |
737 | 769 | $attachment_stuff = array($row); |
738 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
739 | - $attachment_stuff[] = $row2; |
|
770 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
771 | + $attachment_stuff[] = $row2; |
|
772 | + } |
|
740 | 773 | $smcFunc['db_free_result']($request); |
741 | 774 | |
742 | 775 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
743 | 776 | { |
744 | 777 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
745 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
746 | - fatal_lang_error('modify_post_time_passed', false); |
|
747 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
748 | - isAllowedTo('modify_replies'); |
|
749 | - else |
|
750 | - isAllowedTo('modify_own'); |
|
778 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
779 | + fatal_lang_error('modify_post_time_passed', false); |
|
780 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
781 | + isAllowedTo('modify_replies'); |
|
782 | + } else { |
|
783 | + isAllowedTo('modify_own'); |
|
784 | + } |
|
785 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
786 | + isAllowedTo('modify_replies'); |
|
787 | + } else { |
|
788 | + isAllowedTo('modify_any'); |
|
751 | 789 | } |
752 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
753 | - isAllowedTo('modify_replies'); |
|
754 | - else |
|
755 | - isAllowedTo('modify_any'); |
|
756 | 790 | |
757 | 791 | if ($context['can_announce'] && !empty($row['id_action'])) |
758 | 792 | { |
@@ -779,15 +813,17 @@ discard block |
||
779 | 813 | $context['icon'] = $row['icon']; |
780 | 814 | |
781 | 815 | // Show an "approve" box if the user can approve it, and the message isn't approved. |
782 | - if (!$row['approved'] && !$context['show_approval']) |
|
783 | - $context['show_approval'] = allowedTo('approve_posts'); |
|
816 | + if (!$row['approved'] && !$context['show_approval']) { |
|
817 | + $context['show_approval'] = allowedTo('approve_posts'); |
|
818 | + } |
|
784 | 819 | |
785 | 820 | // Sort the attachments so they are in the order saved |
786 | 821 | $temp = array(); |
787 | 822 | foreach ($attachment_stuff as $attachment) |
788 | 823 | { |
789 | - if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) |
|
790 | - $temp[$attachment['id_attach']] = $attachment; |
|
824 | + if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) { |
|
825 | + $temp[$attachment['id_attach']] = $attachment; |
|
826 | + } |
|
791 | 827 | } |
792 | 828 | ksort($temp); |
793 | 829 | |
@@ -848,14 +884,16 @@ discard block |
||
848 | 884 | 'is_approved' => 1, |
849 | 885 | ) |
850 | 886 | ); |
851 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
852 | - fatal_lang_error('quoted_post_deleted', false); |
|
887 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
888 | + fatal_lang_error('quoted_post_deleted', false); |
|
889 | + } |
|
853 | 890 | list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request); |
854 | 891 | $smcFunc['db_free_result']($request); |
855 | 892 | |
856 | 893 | // Add 'Re: ' to the front of the quoted subject. |
857 | - if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
858 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
894 | + if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
895 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
896 | + } |
|
859 | 897 | |
860 | 898 | // Censor the message and subject. |
861 | 899 | censorText($form_message); |
@@ -868,10 +906,11 @@ discard block |
||
868 | 906 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
869 | 907 | { |
870 | 908 | // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. |
871 | - if ($i % 4 == 0) |
|
872 | - $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) |
|
909 | + if ($i % 4 == 0) { |
|
910 | + $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) |
|
873 | 911 | { |
874 | 912 | return '[html]' . preg_replace('~<br\s?/?' . '>~i', '<br /><br>', "$m[1]") . '[/html]'; |
913 | + } |
|
875 | 914 | }, $parts[$i]); |
876 | 915 | } |
877 | 916 | $form_message = implode('', $parts); |
@@ -880,8 +919,9 @@ discard block |
||
880 | 919 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message); |
881 | 920 | |
882 | 921 | // Remove any nested quotes, if necessary. |
883 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
884 | - $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
922 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
923 | + $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
924 | + } |
|
885 | 925 | |
886 | 926 | // Add a quote string on the front and end. |
887 | 927 | $form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]'; |
@@ -893,15 +933,15 @@ discard block |
||
893 | 933 | $form_subject = $first_subject; |
894 | 934 | |
895 | 935 | // Add 'Re: ' to the front of the subject. |
896 | - if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
897 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
936 | + if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
937 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
938 | + } |
|
898 | 939 | |
899 | 940 | // Censor the subject. |
900 | 941 | censorText($form_subject); |
901 | 942 | |
902 | 943 | $form_message = ''; |
903 | - } |
|
904 | - else |
|
944 | + } else |
|
905 | 945 | { |
906 | 946 | $form_subject = isset($_GET['subject']) ? $_GET['subject'] : ''; |
907 | 947 | $form_message = ''; |
@@ -920,13 +960,15 @@ discard block |
||
920 | 960 | if (isset($_REQUEST['msg'])) |
921 | 961 | { |
922 | 962 | $context['attachments']['quantity'] = count($context['current_attachments']); |
923 | - foreach ($context['current_attachments'] as $attachment) |
|
924 | - $context['attachments']['total_size'] += $attachment['size']; |
|
963 | + foreach ($context['current_attachments'] as $attachment) { |
|
964 | + $context['attachments']['total_size'] += $attachment['size']; |
|
965 | + } |
|
925 | 966 | } |
926 | 967 | |
927 | 968 | // A bit of house keeping first. |
928 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
929 | - unset($_SESSION['temp_attachments']); |
|
969 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
970 | + unset($_SESSION['temp_attachments']); |
|
971 | + } |
|
930 | 972 | |
931 | 973 | if (!empty($_SESSION['temp_attachments'])) |
932 | 974 | { |
@@ -935,9 +977,10 @@ discard block |
||
935 | 977 | { |
936 | 978 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
937 | 979 | { |
938 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
939 | - if (file_exists($attachment['tmp_name'])) |
|
980 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) { |
|
981 | + if (file_exists($attachment['tmp_name'])) |
|
940 | 982 | unlink($attachment['tmp_name']); |
983 | + } |
|
941 | 984 | } |
942 | 985 | $post_errors[] = 'temp_attachments_gone'; |
943 | 986 | $_SESSION['temp_attachments'] = array(); |
@@ -951,8 +994,9 @@ discard block |
||
951 | 994 | // See if any files still exist before showing the warning message and the files attached. |
952 | 995 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
953 | 996 | { |
954 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
955 | - continue; |
|
997 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
998 | + continue; |
|
999 | + } |
|
956 | 1000 | |
957 | 1001 | if (file_exists($attachment['tmp_name'])) |
958 | 1002 | { |
@@ -962,20 +1006,21 @@ discard block |
||
962 | 1006 | break; |
963 | 1007 | } |
964 | 1008 | } |
965 | - } |
|
966 | - else |
|
1009 | + } else |
|
967 | 1010 | { |
968 | 1011 | // Since, they don't belong here. Let's inform the user that they exist.. |
969 | - if (!empty($topic)) |
|
970 | - $delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
971 | - else |
|
972 | - $delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp'; |
|
1012 | + if (!empty($topic)) { |
|
1013 | + $delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
1014 | + } else { |
|
1015 | + $delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp'; |
|
1016 | + } |
|
973 | 1017 | |
974 | 1018 | // Compile a list of the files to show the user. |
975 | 1019 | $file_list = array(); |
976 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
977 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
1020 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
1021 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
978 | 1022 | $file_list[] = $attachment['name']; |
1023 | + } |
|
979 | 1024 | |
980 | 1025 | $_SESSION['temp_attachments']['post']['files'] = $file_list; |
981 | 1026 | $file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>'; |
@@ -987,8 +1032,7 @@ discard block |
||
987 | 1032 | |
988 | 1033 | $post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list)); |
989 | 1034 | $context['ignore_temp_attachments'] = true; |
990 | - } |
|
991 | - else |
|
1035 | + } else |
|
992 | 1036 | { |
993 | 1037 | $post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list)); |
994 | 1038 | $context['ignore_temp_attachments'] = true; |
@@ -996,16 +1040,19 @@ discard block |
||
996 | 1040 | } |
997 | 1041 | } |
998 | 1042 | |
999 | - if (!empty($context['we_are_history'])) |
|
1000 | - $post_errors[] = $context['we_are_history']; |
|
1043 | + if (!empty($context['we_are_history'])) { |
|
1044 | + $post_errors[] = $context['we_are_history']; |
|
1045 | + } |
|
1001 | 1046 | |
1002 | 1047 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
1003 | 1048 | { |
1004 | - if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) |
|
1005 | - break; |
|
1049 | + if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) { |
|
1050 | + break; |
|
1051 | + } |
|
1006 | 1052 | |
1007 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
1008 | - continue; |
|
1053 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
1054 | + continue; |
|
1055 | + } |
|
1009 | 1056 | |
1010 | 1057 | if ($attachID == 'initial_error') |
1011 | 1058 | { |
@@ -1020,15 +1067,17 @@ discard block |
||
1020 | 1067 | { |
1021 | 1068 | $txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : ''; |
1022 | 1069 | $txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">'; |
1023 | - foreach ($attachment['errors'] as $error) |
|
1024 | - $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
1070 | + foreach ($attachment['errors'] as $error) { |
|
1071 | + $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
1072 | + } |
|
1025 | 1073 | $txt['error_attach_errors'] .= '</div>'; |
1026 | 1074 | $post_errors[] = 'attach_errors'; |
1027 | 1075 | |
1028 | 1076 | // Take out the trash. |
1029 | 1077 | unset($_SESSION['temp_attachments'][$attachID]); |
1030 | - if (file_exists($attachment['tmp_name'])) |
|
1031 | - unlink($attachment['tmp_name']); |
|
1078 | + if (file_exists($attachment['tmp_name'])) { |
|
1079 | + unlink($attachment['tmp_name']); |
|
1080 | + } |
|
1032 | 1081 | continue; |
1033 | 1082 | } |
1034 | 1083 | |
@@ -1041,8 +1090,9 @@ discard block |
||
1041 | 1090 | |
1042 | 1091 | $context['attachments']['quantity']++; |
1043 | 1092 | $context['attachments']['total_size'] += $attachment['size']; |
1044 | - if (!isset($context['files_in_session_warning'])) |
|
1045 | - $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
1093 | + if (!isset($context['files_in_session_warning'])) { |
|
1094 | + $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
1095 | + } |
|
1046 | 1096 | |
1047 | 1097 | $context['current_attachments'][$attachID] = array( |
1048 | 1098 | 'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>', |
@@ -1070,8 +1120,9 @@ discard block |
||
1070 | 1120 | } |
1071 | 1121 | |
1072 | 1122 | // If they came from quick reply, and have to enter verification details, give them some notice. |
1073 | - if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) |
|
1074 | - $post_errors[] = 'need_qr_verification'; |
|
1123 | + if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) { |
|
1124 | + $post_errors[] = 'need_qr_verification'; |
|
1125 | + } |
|
1075 | 1126 | |
1076 | 1127 | /* |
1077 | 1128 | * There are two error types: serious and minor. Serious errors |
@@ -1088,52 +1139,56 @@ discard block |
||
1088 | 1139 | { |
1089 | 1140 | loadLanguage('Errors'); |
1090 | 1141 | $context['error_type'] = 'minor'; |
1091 | - foreach ($post_errors as $post_error) |
|
1092 | - if (is_array($post_error)) |
|
1142 | + foreach ($post_errors as $post_error) { |
|
1143 | + if (is_array($post_error)) |
|
1093 | 1144 | { |
1094 | 1145 | $post_error_id = $post_error[0]; |
1146 | + } |
|
1095 | 1147 | $context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]); |
1096 | 1148 | |
1097 | 1149 | // If it's not a minor error flag it as such. |
1098 | - if (!in_array($post_error_id, $minor_errors)) |
|
1099 | - $context['error_type'] = 'serious'; |
|
1100 | - } |
|
1101 | - else |
|
1150 | + if (!in_array($post_error_id, $minor_errors)) { |
|
1151 | + $context['error_type'] = 'serious'; |
|
1152 | + } |
|
1153 | + } else |
|
1102 | 1154 | { |
1103 | 1155 | $context['post_error'][$post_error] = $txt['error_' . $post_error]; |
1104 | 1156 | |
1105 | 1157 | // If it's not a minor error flag it as such. |
1106 | - if (!in_array($post_error, $minor_errors)) |
|
1107 | - $context['error_type'] = 'serious'; |
|
1158 | + if (!in_array($post_error, $minor_errors)) { |
|
1159 | + $context['error_type'] = 'serious'; |
|
1160 | + } |
|
1108 | 1161 | } |
1109 | 1162 | } |
1110 | 1163 | |
1111 | 1164 | // What are you doing? Posting a poll, modifying, previewing, new post, or reply... |
1112 | - if (isset($_REQUEST['poll'])) |
|
1113 | - $context['page_title'] = $txt['new_poll']; |
|
1114 | - elseif ($context['make_event']) |
|
1115 | - $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
1116 | - elseif (isset($_REQUEST['msg'])) |
|
1117 | - $context['page_title'] = $txt['modify_msg']; |
|
1118 | - elseif (isset($_REQUEST['subject'], $context['preview_subject'])) |
|
1119 | - $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
1120 | - elseif (empty($topic)) |
|
1121 | - $context['page_title'] = $txt['start_new_topic']; |
|
1122 | - else |
|
1123 | - $context['page_title'] = $txt['post_reply']; |
|
1165 | + if (isset($_REQUEST['poll'])) { |
|
1166 | + $context['page_title'] = $txt['new_poll']; |
|
1167 | + } elseif ($context['make_event']) { |
|
1168 | + $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
1169 | + } elseif (isset($_REQUEST['msg'])) { |
|
1170 | + $context['page_title'] = $txt['modify_msg']; |
|
1171 | + } elseif (isset($_REQUEST['subject'], $context['preview_subject'])) { |
|
1172 | + $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
1173 | + } elseif (empty($topic)) { |
|
1174 | + $context['page_title'] = $txt['start_new_topic']; |
|
1175 | + } else { |
|
1176 | + $context['page_title'] = $txt['post_reply']; |
|
1177 | + } |
|
1124 | 1178 | |
1125 | 1179 | // Build the link tree. |
1126 | - if (empty($topic)) |
|
1127 | - $context['linktree'][] = array( |
|
1180 | + if (empty($topic)) { |
|
1181 | + $context['linktree'][] = array( |
|
1128 | 1182 | 'name' => '<em>' . $txt['start_new_topic'] . '</em>' |
1129 | 1183 | ); |
1130 | - else |
|
1131 | - $context['linktree'][] = array( |
|
1184 | + } else { |
|
1185 | + $context['linktree'][] = array( |
|
1132 | 1186 | 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], |
1133 | 1187 | 'name' => $form_subject, |
1134 | 1188 | 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>', |
1135 | 1189 | 'extra_after' => '<span><strong class="nav">)</strong></span>' |
1136 | 1190 | ); |
1191 | + } |
|
1137 | 1192 | |
1138 | 1193 | $context['subject'] = addcslashes($form_subject, '"'); |
1139 | 1194 | $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); |
@@ -1177,8 +1232,9 @@ discard block |
||
1177 | 1232 | // Message icons - customized icons are off? |
1178 | 1233 | $context['icons'] = getMessageIcons(!empty($board) ? $board : 0); |
1179 | 1234 | |
1180 | - if (!empty($context['icons'])) |
|
1181 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1235 | + if (!empty($context['icons'])) { |
|
1236 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
1237 | + } |
|
1182 | 1238 | |
1183 | 1239 | // Are we starting a poll? if set the poll icon as selected if its available |
1184 | 1240 | if (isset($_REQUEST['poll'])) |
@@ -1198,8 +1254,9 @@ discard block |
||
1198 | 1254 | for ($i = 0, $n = count($context['icons']); $i < $n; $i++) |
1199 | 1255 | { |
1200 | 1256 | $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value']; |
1201 | - if ($context['icons'][$i]['selected']) |
|
1202 | - $context['icon_url'] = $context['icons'][$i]['url']; |
|
1257 | + if ($context['icons'][$i]['selected']) { |
|
1258 | + $context['icon_url'] = $context['icons'][$i]['url']; |
|
1259 | + } |
|
1203 | 1260 | } |
1204 | 1261 | if (empty($context['icon_url'])) |
1205 | 1262 | { |
@@ -1213,8 +1270,9 @@ discard block |
||
1213 | 1270 | )); |
1214 | 1271 | } |
1215 | 1272 | |
1216 | - if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) |
|
1217 | - getTopic(); |
|
1273 | + if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) { |
|
1274 | + getTopic(); |
|
1275 | + } |
|
1218 | 1276 | |
1219 | 1277 | // If the user can post attachments prepare the warning labels. |
1220 | 1278 | if ($context['can_post_attachment']) |
@@ -1225,12 +1283,13 @@ discard block |
||
1225 | 1283 | $context['attachment_restrictions'] = array(); |
1226 | 1284 | $context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', ')); |
1227 | 1285 | $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit'); |
1228 | - foreach ($attachmentRestrictionTypes as $type) |
|
1229 | - if (!empty($modSettings[$type])) |
|
1286 | + foreach ($attachmentRestrictionTypes as $type) { |
|
1287 | + if (!empty($modSettings[$type])) |
|
1230 | 1288 | { |
1231 | 1289 | // Show the max number of attachments if not 0. |
1232 | 1290 | if ($type == 'attachmentNumPerPostLimit') |
1233 | 1291 | $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']); |
1292 | + } |
|
1234 | 1293 | } |
1235 | 1294 | } |
1236 | 1295 | |
@@ -1264,8 +1323,8 @@ discard block |
||
1264 | 1323 | |
1265 | 1324 | if (!empty($context['current_attachments'])) |
1266 | 1325 | { |
1267 | - foreach ($context['current_attachments'] as $key => $mock) |
|
1268 | - addInlineJavaScript(' |
|
1326 | + foreach ($context['current_attachments'] as $key => $mock) { |
|
1327 | + addInlineJavaScript(' |
|
1269 | 1328 | current_attachments.push({ |
1270 | 1329 | name: '. JavaScriptEscape($mock['name']) . ', |
1271 | 1330 | size: '. $mock['size'] . ', |
@@ -1274,6 +1333,7 @@ discard block |
||
1274 | 1333 | type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ', |
1275 | 1334 | thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . ' |
1276 | 1335 | });'); |
1336 | + } |
|
1277 | 1337 | } |
1278 | 1338 | |
1279 | 1339 | // File Upload. |
@@ -1348,9 +1408,10 @@ discard block |
||
1348 | 1408 | $context['posting_fields']['board']['dd'] .= ' |
1349 | 1409 | <optgroup label="' . $category['name'] . '">'; |
1350 | 1410 | |
1351 | - foreach ($category['boards'] as $brd) |
|
1352 | - $context['posting_fields']['board']['dd'] .= ' |
|
1411 | + foreach ($category['boards'] as $brd) { |
|
1412 | + $context['posting_fields']['board']['dd'] .= ' |
|
1353 | 1413 | <option value="' . $brd['id'] . '"' . ($brd['selected'] ? ' selected' : '') . '>' . ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=>' : '') . ' ' . $brd['name'] . '</option>'; |
1414 | + } |
|
1354 | 1415 | |
1355 | 1416 | $context['posting_fields']['board']['dd'] .= ' |
1356 | 1417 | </optgroup>'; |
@@ -1381,8 +1442,9 @@ discard block |
||
1381 | 1442 | |
1382 | 1443 | |
1383 | 1444 | // Finally, load the template. |
1384 | - if (!isset($_REQUEST['xml'])) |
|
1385 | - loadTemplate('Post'); |
|
1445 | + if (!isset($_REQUEST['xml'])) { |
|
1446 | + loadTemplate('Post'); |
|
1447 | + } |
|
1386 | 1448 | |
1387 | 1449 | call_integration_hook('integrate_post_end'); |
1388 | 1450 | } |
@@ -1403,13 +1465,14 @@ discard block |
||
1403 | 1465 | // Sneaking off, are we? |
1404 | 1466 | if (empty($_POST) && empty($topic)) |
1405 | 1467 | { |
1406 | - if (empty($_SERVER['CONTENT_LENGTH'])) |
|
1407 | - redirectexit('action=post;board=' . $board . '.0'); |
|
1408 | - else |
|
1409 | - fatal_lang_error('post_upload_error', false); |
|
1468 | + if (empty($_SERVER['CONTENT_LENGTH'])) { |
|
1469 | + redirectexit('action=post;board=' . $board . '.0'); |
|
1470 | + } else { |
|
1471 | + fatal_lang_error('post_upload_error', false); |
|
1472 | + } |
|
1473 | + } elseif (empty($_POST) && !empty($topic)) { |
|
1474 | + redirectexit('action=post;topic=' . $topic . '.0'); |
|
1410 | 1475 | } |
1411 | - elseif (empty($_POST) && !empty($topic)) |
|
1412 | - redirectexit('action=post;topic=' . $topic . '.0'); |
|
1413 | 1476 | |
1414 | 1477 | // No need! |
1415 | 1478 | $context['robot_no_index'] = true; |
@@ -1421,8 +1484,9 @@ discard block |
||
1421 | 1484 | $post_errors = array(); |
1422 | 1485 | |
1423 | 1486 | // If the session has timed out, let the user re-submit their form. |
1424 | - if (checkSession('post', '', false) != '') |
|
1425 | - $post_errors[] = 'session_timeout'; |
|
1487 | + if (checkSession('post', '', false) != '') { |
|
1488 | + $post_errors[] = 'session_timeout'; |
|
1489 | + } |
|
1426 | 1490 | |
1427 | 1491 | // Wrong verification code? |
1428 | 1492 | if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1))) |
@@ -1432,33 +1496,38 @@ discard block |
||
1432 | 1496 | 'id' => 'post', |
1433 | 1497 | ); |
1434 | 1498 | $context['require_verification'] = create_control_verification($verificationOptions, true); |
1435 | - if (is_array($context['require_verification'])) |
|
1436 | - $post_errors = array_merge($post_errors, $context['require_verification']); |
|
1499 | + if (is_array($context['require_verification'])) { |
|
1500 | + $post_errors = array_merge($post_errors, $context['require_verification']); |
|
1501 | + } |
|
1437 | 1502 | } |
1438 | 1503 | |
1439 | 1504 | require_once($sourcedir . '/Subs-Post.php'); |
1440 | 1505 | loadLanguage('Post'); |
1441 | 1506 | |
1442 | 1507 | // Drafts enabled and needed? |
1443 | - if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) |
|
1444 | - require_once($sourcedir . '/Drafts.php'); |
|
1508 | + if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) { |
|
1509 | + require_once($sourcedir . '/Drafts.php'); |
|
1510 | + } |
|
1445 | 1511 | |
1446 | 1512 | // First check to see if they are trying to delete any current attachments. |
1447 | 1513 | if (isset($_POST['attach_del'])) |
1448 | 1514 | { |
1449 | 1515 | $keep_temp = array(); |
1450 | 1516 | $keep_ids = array(); |
1451 | - foreach ($_POST['attach_del'] as $dummy) |
|
1452 | - if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
1517 | + foreach ($_POST['attach_del'] as $dummy) { |
|
1518 | + if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
1453 | 1519 | $keep_temp[] = $dummy; |
1454 | - else |
|
1455 | - $keep_ids[] = (int) $dummy; |
|
1520 | + } |
|
1521 | + else { |
|
1522 | + $keep_ids[] = (int) $dummy; |
|
1523 | + } |
|
1456 | 1524 | |
1457 | - if (isset($_SESSION['temp_attachments'])) |
|
1458 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
1525 | + if (isset($_SESSION['temp_attachments'])) { |
|
1526 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
1459 | 1527 | { |
1460 | 1528 | if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
1461 | 1529 | continue; |
1530 | + } |
|
1462 | 1531 | |
1463 | 1532 | unset($_SESSION['temp_attachments'][$attachID]); |
1464 | 1533 | unlink($attachment['tmp_name']); |
@@ -1490,8 +1559,9 @@ discard block |
||
1490 | 1559 | { |
1491 | 1560 | require_once($sourcedir . '/ManageAttachments.php'); |
1492 | 1561 | |
1493 | - foreach ($_SESSION['already_attached'] as $attachID => $attachment) |
|
1494 | - removeAttachments(array('id_attach' => $attachID)); |
|
1562 | + foreach ($_SESSION['already_attached'] as $attachID => $attachment) { |
|
1563 | + removeAttachments(array('id_attach' => $attachID)); |
|
1564 | + } |
|
1495 | 1565 | |
1496 | 1566 | unset($_SESSION['already_attached']); |
1497 | 1567 | |
@@ -1514,12 +1584,14 @@ discard block |
||
1514 | 1584 | $smcFunc['db_free_result']($request); |
1515 | 1585 | |
1516 | 1586 | // Though the topic should be there, it might have vanished. |
1517 | - if (!is_array($topic_info)) |
|
1518 | - fatal_lang_error('topic_doesnt_exist', 404); |
|
1587 | + if (!is_array($topic_info)) { |
|
1588 | + fatal_lang_error('topic_doesnt_exist', 404); |
|
1589 | + } |
|
1519 | 1590 | |
1520 | 1591 | // Did this topic suddenly move? Just checking... |
1521 | - if ($topic_info['id_board'] != $board) |
|
1522 | - fatal_lang_error('not_a_topic'); |
|
1592 | + if ($topic_info['id_board'] != $board) { |
|
1593 | + fatal_lang_error('not_a_topic'); |
|
1594 | + } |
|
1523 | 1595 | |
1524 | 1596 | // Do the permissions and approval stuff... |
1525 | 1597 | $becomesApproved = true; |
@@ -1542,49 +1614,50 @@ discard block |
||
1542 | 1614 | if (!empty($topic) && !isset($_REQUEST['msg'])) |
1543 | 1615 | { |
1544 | 1616 | // Don't allow a post if it's locked. |
1545 | - if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) |
|
1546 | - fatal_lang_error('topic_locked', false); |
|
1617 | + if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) { |
|
1618 | + fatal_lang_error('topic_locked', false); |
|
1619 | + } |
|
1547 | 1620 | |
1548 | 1621 | // Sorry, multiple polls aren't allowed... yet. You should stop giving me ideas :P. |
1549 | - if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) |
|
1550 | - unset($_REQUEST['poll']); |
|
1551 | - |
|
1552 | - elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
1553 | - { |
|
1554 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
1555 | - $becomesApproved = false; |
|
1556 | - |
|
1557 | - else |
|
1558 | - isAllowedTo('post_reply_any'); |
|
1559 | - } |
|
1560 | - elseif (!allowedTo('post_reply_any')) |
|
1622 | + if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) { |
|
1623 | + unset($_REQUEST['poll']); |
|
1624 | + } elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
1625 | + { |
|
1626 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
1627 | + $becomesApproved = false; |
|
1628 | + } else { |
|
1629 | + isAllowedTo('post_reply_any'); |
|
1630 | + } |
|
1631 | + } elseif (!allowedTo('post_reply_any')) |
|
1561 | 1632 | { |
1562 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) |
|
1563 | - $becomesApproved = false; |
|
1564 | - |
|
1565 | - else |
|
1566 | - isAllowedTo('post_reply_own'); |
|
1633 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) { |
|
1634 | + $becomesApproved = false; |
|
1635 | + } else { |
|
1636 | + isAllowedTo('post_reply_own'); |
|
1637 | + } |
|
1567 | 1638 | } |
1568 | 1639 | |
1569 | 1640 | if (isset($_POST['lock'])) |
1570 | 1641 | { |
1571 | 1642 | // Nothing is changed to the lock. |
1572 | - if (empty($topic_info['locked']) == empty($_POST['lock'])) |
|
1573 | - unset($_POST['lock']); |
|
1643 | + if (empty($topic_info['locked']) == empty($_POST['lock'])) { |
|
1644 | + unset($_POST['lock']); |
|
1645 | + } |
|
1574 | 1646 | |
1575 | 1647 | // You're have no permission to lock this topic. |
1576 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
1577 | - unset($_POST['lock']); |
|
1648 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
1649 | + unset($_POST['lock']); |
|
1650 | + } |
|
1578 | 1651 | |
1579 | 1652 | // You are allowed to (un)lock your own topic only. |
1580 | 1653 | elseif (!allowedTo('lock_any')) |
1581 | 1654 | { |
1582 | 1655 | // You cannot override a moderator lock. |
1583 | - if ($topic_info['locked'] == 1) |
|
1584 | - unset($_POST['lock']); |
|
1585 | - |
|
1586 | - else |
|
1587 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
1656 | + if ($topic_info['locked'] == 1) { |
|
1657 | + unset($_POST['lock']); |
|
1658 | + } else { |
|
1659 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
1660 | + } |
|
1588 | 1661 | } |
1589 | 1662 | // Hail mighty moderator, (un)lock this topic immediately. |
1590 | 1663 | else |
@@ -1592,19 +1665,21 @@ discard block |
||
1592 | 1665 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
1593 | 1666 | |
1594 | 1667 | // Did someone (un)lock this while you were posting? |
1595 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
1596 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
1668 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
1669 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
1670 | + } |
|
1597 | 1671 | } |
1598 | 1672 | } |
1599 | 1673 | |
1600 | 1674 | // So you wanna (un)sticky this...let's see. |
1601 | - if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) |
|
1602 | - unset($_POST['sticky']); |
|
1603 | - elseif (isset($_POST['sticky'])) |
|
1675 | + if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) { |
|
1676 | + unset($_POST['sticky']); |
|
1677 | + } elseif (isset($_POST['sticky'])) |
|
1604 | 1678 | { |
1605 | 1679 | // Did someone (un)sticky this while you were posting? |
1606 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
1607 | - $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
1680 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
1681 | + $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
1682 | + } |
|
1608 | 1683 | } |
1609 | 1684 | |
1610 | 1685 | // If drafts are enabled, then pass this off |
@@ -1631,26 +1706,31 @@ discard block |
||
1631 | 1706 | |
1632 | 1707 | // Do like, the permissions, for safety and stuff... |
1633 | 1708 | $becomesApproved = true; |
1634 | - if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
|
1635 | - $becomesApproved = false; |
|
1636 | - else |
|
1637 | - isAllowedTo('post_new'); |
|
1709 | + if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { |
|
1710 | + $becomesApproved = false; |
|
1711 | + } else { |
|
1712 | + isAllowedTo('post_new'); |
|
1713 | + } |
|
1638 | 1714 | |
1639 | 1715 | if (isset($_POST['lock'])) |
1640 | 1716 | { |
1641 | 1717 | // New topics are by default not locked. |
1642 | - if (empty($_POST['lock'])) |
|
1643 | - unset($_POST['lock']); |
|
1718 | + if (empty($_POST['lock'])) { |
|
1719 | + unset($_POST['lock']); |
|
1720 | + } |
|
1644 | 1721 | // Besides, you need permission. |
1645 | - elseif (!allowedTo(array('lock_any', 'lock_own'))) |
|
1646 | - unset($_POST['lock']); |
|
1722 | + elseif (!allowedTo(array('lock_any', 'lock_own'))) { |
|
1723 | + unset($_POST['lock']); |
|
1724 | + } |
|
1647 | 1725 | // A moderator-lock (1) can override a user-lock (2). |
1648 | - else |
|
1649 | - $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
1726 | + else { |
|
1727 | + $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
1728 | + } |
|
1650 | 1729 | } |
1651 | 1730 | |
1652 | - if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) |
|
1653 | - unset($_POST['sticky']); |
|
1731 | + if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) { |
|
1732 | + unset($_POST['sticky']); |
|
1733 | + } |
|
1654 | 1734 | |
1655 | 1735 | // Saving your new topic as a draft first? |
1656 | 1736 | if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft'])) |
@@ -1675,31 +1755,37 @@ discard block |
||
1675 | 1755 | 'id_msg' => $_REQUEST['msg'], |
1676 | 1756 | ) |
1677 | 1757 | ); |
1678 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
1679 | - fatal_lang_error('cant_find_messages', false); |
|
1758 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
1759 | + fatal_lang_error('cant_find_messages', false); |
|
1760 | + } |
|
1680 | 1761 | $row = $smcFunc['db_fetch_assoc']($request); |
1681 | 1762 | $smcFunc['db_free_result']($request); |
1682 | 1763 | |
1683 | - if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) |
|
1684 | - fatal_lang_error('topic_locked', false); |
|
1764 | + if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) { |
|
1765 | + fatal_lang_error('topic_locked', false); |
|
1766 | + } |
|
1685 | 1767 | |
1686 | 1768 | if (isset($_POST['lock'])) |
1687 | 1769 | { |
1688 | 1770 | // Nothing changes to the lock status. |
1689 | - if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) |
|
1690 | - unset($_POST['lock']); |
|
1771 | + if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) { |
|
1772 | + unset($_POST['lock']); |
|
1773 | + } |
|
1691 | 1774 | // You're simply not allowed to (un)lock this. |
1692 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
1693 | - unset($_POST['lock']); |
|
1775 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
1776 | + unset($_POST['lock']); |
|
1777 | + } |
|
1694 | 1778 | // You're only allowed to lock your own topics. |
1695 | 1779 | elseif (!allowedTo('lock_any')) |
1696 | 1780 | { |
1697 | 1781 | // You're not allowed to break a moderator's lock. |
1698 | - if ($topic_info['locked'] == 1) |
|
1699 | - unset($_POST['lock']); |
|
1782 | + if ($topic_info['locked'] == 1) { |
|
1783 | + unset($_POST['lock']); |
|
1784 | + } |
|
1700 | 1785 | // Lock it with a soft lock or unlock it. |
1701 | - else |
|
1702 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
1786 | + else { |
|
1787 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
1788 | + } |
|
1703 | 1789 | } |
1704 | 1790 | // You must be the moderator. |
1705 | 1791 | else |
@@ -1707,44 +1793,46 @@ discard block |
||
1707 | 1793 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
1708 | 1794 | |
1709 | 1795 | // Did someone (un)lock this while you were posting? |
1710 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
1711 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
1796 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
1797 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
1798 | + } |
|
1712 | 1799 | } |
1713 | 1800 | } |
1714 | 1801 | |
1715 | 1802 | // Change the sticky status of this topic? |
1716 | - if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) |
|
1717 | - unset($_POST['sticky']); |
|
1718 | - elseif (isset($_POST['sticky'])) |
|
1803 | + if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) { |
|
1804 | + unset($_POST['sticky']); |
|
1805 | + } elseif (isset($_POST['sticky'])) |
|
1719 | 1806 | { |
1720 | 1807 | // Did someone (un)sticky this while you were posting? |
1721 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
1722 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
1808 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
1809 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
1810 | + } |
|
1723 | 1811 | } |
1724 | 1812 | |
1725 | 1813 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
1726 | 1814 | { |
1727 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
1728 | - fatal_lang_error('modify_post_time_passed', false); |
|
1729 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
1730 | - isAllowedTo('modify_replies'); |
|
1731 | - else |
|
1732 | - isAllowedTo('modify_own'); |
|
1733 | - } |
|
1734 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
1815 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
1816 | + fatal_lang_error('modify_post_time_passed', false); |
|
1817 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
1818 | + isAllowedTo('modify_replies'); |
|
1819 | + } else { |
|
1820 | + isAllowedTo('modify_own'); |
|
1821 | + } |
|
1822 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
1735 | 1823 | { |
1736 | 1824 | isAllowedTo('modify_replies'); |
1737 | 1825 | |
1738 | 1826 | // If you're modifying a reply, I say it better be logged... |
1739 | 1827 | $moderationAction = true; |
1740 | - } |
|
1741 | - else |
|
1828 | + } else |
|
1742 | 1829 | { |
1743 | 1830 | isAllowedTo('modify_any'); |
1744 | 1831 | |
1745 | 1832 | // Log it, assuming you're not modifying your own post. |
1746 | - if ($row['id_member'] != $user_info['id']) |
|
1747 | - $moderationAction = true; |
|
1833 | + if ($row['id_member'] != $user_info['id']) { |
|
1834 | + $moderationAction = true; |
|
1835 | + } |
|
1748 | 1836 | } |
1749 | 1837 | |
1750 | 1838 | // If drafts are enabled, then lets send this off to save |
@@ -1771,8 +1859,9 @@ discard block |
||
1771 | 1859 | // Update search api |
1772 | 1860 | require_once($sourcedir . '/Search.php'); |
1773 | 1861 | $searchAPI = findSearchAPI(); |
1774 | - if ($searchAPI->supportsMethod('postRemoved')) |
|
1775 | - $searchAPI->postRemoved($_REQUEST['msg']); |
|
1862 | + if ($searchAPI->supportsMethod('postRemoved')) { |
|
1863 | + $searchAPI->postRemoved($_REQUEST['msg']); |
|
1864 | + } |
|
1776 | 1865 | |
1777 | 1866 | } |
1778 | 1867 | |
@@ -1790,20 +1879,24 @@ discard block |
||
1790 | 1879 | $_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']); |
1791 | 1880 | $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']); |
1792 | 1881 | |
1793 | - if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') |
|
1794 | - $post_errors[] = 'no_name'; |
|
1795 | - if ($smcFunc['strlen']($_POST['guestname']) > 25) |
|
1796 | - $post_errors[] = 'long_name'; |
|
1882 | + if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') { |
|
1883 | + $post_errors[] = 'no_name'; |
|
1884 | + } |
|
1885 | + if ($smcFunc['strlen']($_POST['guestname']) > 25) { |
|
1886 | + $post_errors[] = 'long_name'; |
|
1887 | + } |
|
1797 | 1888 | |
1798 | 1889 | if (empty($modSettings['guest_post_no_email'])) |
1799 | 1890 | { |
1800 | 1891 | // Only check if they changed it! |
1801 | 1892 | if (!isset($row) || $row['poster_email'] != $_POST['email']) |
1802 | 1893 | { |
1803 | - if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) |
|
1804 | - $post_errors[] = 'no_email'; |
|
1805 | - if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) |
|
1806 | - $post_errors[] = 'bad_email'; |
|
1894 | + if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) { |
|
1895 | + $post_errors[] = 'no_email'; |
|
1896 | + } |
|
1897 | + if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { |
|
1898 | + $post_errors[] = 'bad_email'; |
|
1899 | + } |
|
1807 | 1900 | } |
1808 | 1901 | |
1809 | 1902 | // Now make sure this email address is not banned from posting. |
@@ -1819,81 +1912,95 @@ discard block |
||
1819 | 1912 | } |
1820 | 1913 | |
1821 | 1914 | // Coming from the quickReply? |
1822 | - if (isset($_POST['quickReply'])) |
|
1823 | - $_POST['message'] = $_POST['quickReply']; |
|
1915 | + if (isset($_POST['quickReply'])) { |
|
1916 | + $_POST['message'] = $_POST['quickReply']; |
|
1917 | + } |
|
1824 | 1918 | |
1825 | 1919 | // Check the subject and message. |
1826 | - if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') |
|
1827 | - $post_errors[] = 'no_subject'; |
|
1828 | - if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') |
|
1829 | - $post_errors[] = 'no_message'; |
|
1830 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
1831 | - $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
1832 | - else |
|
1920 | + if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') { |
|
1921 | + $post_errors[] = 'no_subject'; |
|
1922 | + } |
|
1923 | + if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') { |
|
1924 | + $post_errors[] = 'no_message'; |
|
1925 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) { |
|
1926 | + $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
1927 | + } else |
|
1833 | 1928 | { |
1834 | 1929 | // Prepare the message a bit for some additional testing. |
1835 | 1930 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
1836 | 1931 | |
1837 | 1932 | // Preparse code. (Zef) |
1838 | - if ($user_info['is_guest']) |
|
1839 | - $user_info['name'] = $_POST['guestname']; |
|
1933 | + if ($user_info['is_guest']) { |
|
1934 | + $user_info['name'] = $_POST['guestname']; |
|
1935 | + } |
|
1840 | 1936 | preparsecode($_POST['message']); |
1841 | 1937 | |
1842 | 1938 | // Youtube BBC would be stripped out in the next check without this |
1843 | 1939 | $context['allowed_html_tags'][] = '<iframe>'; |
1844 | 1940 | |
1845 | 1941 | // Let's see if there's still some content left without the tags. |
1846 | - if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) |
|
1847 | - $post_errors[] = 'no_message'; |
|
1942 | + if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) { |
|
1943 | + $post_errors[] = 'no_message'; |
|
1944 | + } |
|
1848 | 1945 | |
1849 | 1946 | // Remove iframe from the list |
1850 | 1947 | array_pop($context['allowed_html_tags']); |
1851 | 1948 | } |
1852 | - if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
1853 | - $post_errors[] = 'no_event'; |
|
1949 | + if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
1950 | + $post_errors[] = 'no_event'; |
|
1951 | + } |
|
1854 | 1952 | // You are not! |
1855 | - if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) |
|
1856 | - fatal_error('Knave! Masquerader! Charlatan!', false); |
|
1953 | + if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) { |
|
1954 | + fatal_error('Knave! Masquerader! Charlatan!', false); |
|
1955 | + } |
|
1857 | 1956 | |
1858 | 1957 | // Validate the poll... |
1859 | 1958 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
1860 | 1959 | { |
1861 | - if (!empty($topic) && !isset($_REQUEST['msg'])) |
|
1862 | - fatal_lang_error('no_access', false); |
|
1960 | + if (!empty($topic) && !isset($_REQUEST['msg'])) { |
|
1961 | + fatal_lang_error('no_access', false); |
|
1962 | + } |
|
1863 | 1963 | |
1864 | 1964 | // This is a new topic... so it's a new poll. |
1865 | - if (empty($topic)) |
|
1866 | - isAllowedTo('poll_post'); |
|
1965 | + if (empty($topic)) { |
|
1966 | + isAllowedTo('poll_post'); |
|
1967 | + } |
|
1867 | 1968 | // Can you add to your own topics? |
1868 | - elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) |
|
1869 | - isAllowedTo('poll_add_own'); |
|
1969 | + elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) { |
|
1970 | + isAllowedTo('poll_add_own'); |
|
1971 | + } |
|
1870 | 1972 | // Can you add polls to any topic, then? |
1871 | - else |
|
1872 | - isAllowedTo('poll_add_any'); |
|
1973 | + else { |
|
1974 | + isAllowedTo('poll_add_any'); |
|
1975 | + } |
|
1873 | 1976 | |
1874 | - if (!isset($_POST['question']) || trim($_POST['question']) == '') |
|
1875 | - $post_errors[] = 'no_question'; |
|
1977 | + if (!isset($_POST['question']) || trim($_POST['question']) == '') { |
|
1978 | + $post_errors[] = 'no_question'; |
|
1979 | + } |
|
1876 | 1980 | |
1877 | 1981 | $_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']); |
1878 | 1982 | |
1879 | 1983 | // Get rid of empty ones. |
1880 | - foreach ($_POST['options'] as $k => $option) |
|
1881 | - if ($option == '') |
|
1984 | + foreach ($_POST['options'] as $k => $option) { |
|
1985 | + if ($option == '') |
|
1882 | 1986 | unset($_POST['options'][$k], $_POST['options'][$k]); |
1987 | + } |
|
1883 | 1988 | |
1884 | 1989 | // What are you going to vote between with one choice?!? |
1885 | - if (count($_POST['options']) < 2) |
|
1886 | - $post_errors[] = 'poll_few'; |
|
1887 | - elseif (count($_POST['options']) > 256) |
|
1888 | - $post_errors[] = 'poll_many'; |
|
1990 | + if (count($_POST['options']) < 2) { |
|
1991 | + $post_errors[] = 'poll_few'; |
|
1992 | + } elseif (count($_POST['options']) > 256) { |
|
1993 | + $post_errors[] = 'poll_many'; |
|
1994 | + } |
|
1889 | 1995 | } |
1890 | 1996 | |
1891 | 1997 | if ($posterIsGuest) |
1892 | 1998 | { |
1893 | 1999 | // If user is a guest, make sure the chosen name isn't taken. |
1894 | 2000 | require_once($sourcedir . '/Subs-Members.php'); |
1895 | - if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) |
|
1896 | - $post_errors[] = 'bad_name'; |
|
2001 | + if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) { |
|
2002 | + $post_errors[] = 'bad_name'; |
|
2003 | + } |
|
1897 | 2004 | } |
1898 | 2005 | // If the user isn't a guest, get his or her name and email. |
1899 | 2006 | elseif (!isset($_REQUEST['msg'])) |
@@ -1924,8 +2031,9 @@ discard block |
||
1924 | 2031 | } |
1925 | 2032 | |
1926 | 2033 | // Make sure the user isn't spamming the board. |
1927 | - if (!isset($_REQUEST['msg'])) |
|
1928 | - spamProtection('post'); |
|
2034 | + if (!isset($_REQUEST['msg'])) { |
|
2035 | + spamProtection('post'); |
|
2036 | + } |
|
1929 | 2037 | |
1930 | 2038 | // At about this point, we're posting and that's that. |
1931 | 2039 | ignore_user_abort(true); |
@@ -1938,32 +2046,36 @@ discard block |
||
1938 | 2046 | $_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
1939 | 2047 | |
1940 | 2048 | // At this point, we want to make sure the subject isn't too long. |
1941 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
1942 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
2049 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
2050 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
2051 | + } |
|
1943 | 2052 | |
1944 | 2053 | // Same with the "why did you edit this" text. |
1945 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
1946 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
2054 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
2055 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
2056 | + } |
|
1947 | 2057 | |
1948 | 2058 | // Make the poll... |
1949 | 2059 | if (isset($_REQUEST['poll'])) |
1950 | 2060 | { |
1951 | 2061 | // Make sure that the user has not entered a ridiculous number of options.. |
1952 | - if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) |
|
1953 | - $_POST['poll_max_votes'] = 1; |
|
1954 | - elseif ($_POST['poll_max_votes'] > count($_POST['options'])) |
|
1955 | - $_POST['poll_max_votes'] = count($_POST['options']); |
|
1956 | - else |
|
1957 | - $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
2062 | + if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) { |
|
2063 | + $_POST['poll_max_votes'] = 1; |
|
2064 | + } elseif ($_POST['poll_max_votes'] > count($_POST['options'])) { |
|
2065 | + $_POST['poll_max_votes'] = count($_POST['options']); |
|
2066 | + } else { |
|
2067 | + $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
2068 | + } |
|
1958 | 2069 | |
1959 | 2070 | $_POST['poll_expire'] = (int) $_POST['poll_expire']; |
1960 | 2071 | $_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']); |
1961 | 2072 | |
1962 | 2073 | // Just set it to zero if it's not there.. |
1963 | - if (!isset($_POST['poll_hide'])) |
|
1964 | - $_POST['poll_hide'] = 0; |
|
1965 | - else |
|
1966 | - $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
2074 | + if (!isset($_POST['poll_hide'])) { |
|
2075 | + $_POST['poll_hide'] = 0; |
|
2076 | + } else { |
|
2077 | + $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
2078 | + } |
|
1967 | 2079 | $_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0; |
1968 | 2080 | |
1969 | 2081 | $_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0; |
@@ -1972,16 +2084,19 @@ discard block |
||
1972 | 2084 | { |
1973 | 2085 | require_once($sourcedir . '/Subs-Members.php'); |
1974 | 2086 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
1975 | - if (!in_array(-1, $allowedVoteGroups['allowed'])) |
|
1976 | - $_POST['poll_guest_vote'] = 0; |
|
2087 | + if (!in_array(-1, $allowedVoteGroups['allowed'])) { |
|
2088 | + $_POST['poll_guest_vote'] = 0; |
|
2089 | + } |
|
1977 | 2090 | } |
1978 | 2091 | |
1979 | 2092 | // If the user tries to set the poll too far in advance, don't let them. |
1980 | - if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) |
|
1981 | - fatal_lang_error('poll_range_error', false); |
|
2093 | + if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) { |
|
2094 | + fatal_lang_error('poll_range_error', false); |
|
2095 | + } |
|
1982 | 2096 | // Don't allow them to select option 2 for hidden results if it's not time limited. |
1983 | - elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) |
|
1984 | - $_POST['poll_hide'] = 1; |
|
2097 | + elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) { |
|
2098 | + $_POST['poll_hide'] = 1; |
|
2099 | + } |
|
1985 | 2100 | |
1986 | 2101 | // Clean up the question and answers. |
1987 | 2102 | $_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']); |
@@ -1995,13 +2110,15 @@ discard block |
||
1995 | 2110 | { |
1996 | 2111 | $attachIDs = array(); |
1997 | 2112 | $attach_errors = array(); |
1998 | - if (!empty($context['we_are_history'])) |
|
1999 | - $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
2113 | + if (!empty($context['we_are_history'])) { |
|
2114 | + $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
2115 | + } |
|
2000 | 2116 | |
2001 | 2117 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
2002 | 2118 | { |
2003 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
2004 | - continue; |
|
2119 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
2120 | + continue; |
|
2121 | + } |
|
2005 | 2122 | |
2006 | 2123 | // If there was an initial error just show that message. |
2007 | 2124 | if ($attachID == 'initial_error') |
@@ -2030,12 +2147,13 @@ discard block |
||
2030 | 2147 | if (createAttachment($attachmentOptions)) |
2031 | 2148 | { |
2032 | 2149 | $attachIDs[] = $attachmentOptions['id']; |
2033 | - if (!empty($attachmentOptions['thumb'])) |
|
2034 | - $attachIDs[] = $attachmentOptions['thumb']; |
|
2150 | + if (!empty($attachmentOptions['thumb'])) { |
|
2151 | + $attachIDs[] = $attachmentOptions['thumb']; |
|
2152 | + } |
|
2035 | 2153 | } |
2154 | + } else { |
|
2155 | + $attach_errors[] = '<dt> </dt>'; |
|
2036 | 2156 | } |
2037 | - else |
|
2038 | - $attach_errors[] = '<dt> </dt>'; |
|
2039 | 2157 | |
2040 | 2158 | if (!empty($attachmentOptions['errors'])) |
2041 | 2159 | { |
@@ -2047,14 +2165,16 @@ discard block |
||
2047 | 2165 | if (!is_array($error)) |
2048 | 2166 | { |
2049 | 2167 | $attach_errors[] = '<dd>' . $txt[$error] . '</dd>'; |
2050 | - if (in_array($error, $log_these)) |
|
2051 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
2168 | + if (in_array($error, $log_these)) { |
|
2169 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
2170 | + } |
|
2171 | + } else { |
|
2172 | + $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
2052 | 2173 | } |
2053 | - else |
|
2054 | - $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
2055 | 2174 | } |
2056 | - if (file_exists($attachment['tmp_name'])) |
|
2057 | - unlink($attachment['tmp_name']); |
|
2175 | + if (file_exists($attachment['tmp_name'])) { |
|
2176 | + unlink($attachment['tmp_name']); |
|
2177 | + } |
|
2058 | 2178 | } |
2059 | 2179 | } |
2060 | 2180 | unset($_SESSION['temp_attachments']); |
@@ -2095,24 +2215,24 @@ discard block |
||
2095 | 2215 | ); |
2096 | 2216 | |
2097 | 2217 | call_integration_hook('integrate_poll_add_edit', array($id_poll, false)); |
2218 | + } else { |
|
2219 | + $id_poll = 0; |
|
2098 | 2220 | } |
2099 | - else |
|
2100 | - $id_poll = 0; |
|
2101 | 2221 | |
2102 | 2222 | // Creating a new topic? |
2103 | 2223 | $newTopic = empty($_REQUEST['msg']) && empty($topic); |
2104 | 2224 | |
2105 | 2225 | // Check the icon. |
2106 | - if (!isset($_POST['icon'])) |
|
2107 | - $_POST['icon'] = 'xx'; |
|
2108 | - |
|
2109 | - else |
|
2226 | + if (!isset($_POST['icon'])) { |
|
2227 | + $_POST['icon'] = 'xx'; |
|
2228 | + } else |
|
2110 | 2229 | { |
2111 | 2230 | $_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']); |
2112 | 2231 | |
2113 | 2232 | // Need to figure it out if this is a valid icon name. |
2114 | - if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) |
|
2115 | - $_POST['icon'] = 'xx'; |
|
2233 | + if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) { |
|
2234 | + $_POST['icon'] = 'xx'; |
|
2235 | + } |
|
2116 | 2236 | } |
2117 | 2237 | |
2118 | 2238 | // Collect all parameters for the creation or modification of a post. |
@@ -2153,8 +2273,9 @@ discard block |
||
2153 | 2273 | } |
2154 | 2274 | |
2155 | 2275 | // This will save some time... |
2156 | - if (empty($approve_has_changed)) |
|
2157 | - unset($msgOptions['approved']); |
|
2276 | + if (empty($approve_has_changed)) { |
|
2277 | + unset($msgOptions['approved']); |
|
2278 | + } |
|
2158 | 2279 | |
2159 | 2280 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
2160 | 2281 | } |
@@ -2163,8 +2284,9 @@ discard block |
||
2163 | 2284 | { |
2164 | 2285 | createPost($msgOptions, $topicOptions, $posterOptions); |
2165 | 2286 | |
2166 | - if (isset($topicOptions['id'])) |
|
2167 | - $topic = $topicOptions['id']; |
|
2287 | + if (isset($topicOptions['id'])) { |
|
2288 | + $topic = $topicOptions['id']; |
|
2289 | + } |
|
2168 | 2290 | } |
2169 | 2291 | |
2170 | 2292 | // Are there attachments already uploaded and waiting to be assigned? |
@@ -2176,8 +2298,9 @@ discard block |
||
2176 | 2298 | } |
2177 | 2299 | |
2178 | 2300 | // If we had a draft for this, its time to remove it since it was just posted |
2179 | - if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) |
|
2180 | - DeleteDraft($_POST['id_draft']); |
|
2301 | + if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) { |
|
2302 | + DeleteDraft($_POST['id_draft']); |
|
2303 | + } |
|
2181 | 2304 | |
2182 | 2305 | // Editing or posting an event? |
2183 | 2306 | if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1)) |
@@ -2196,8 +2319,7 @@ discard block |
||
2196 | 2319 | 'member' => $user_info['id'], |
2197 | 2320 | ); |
2198 | 2321 | insertEvent($eventOptions); |
2199 | - } |
|
2200 | - elseif (isset($_POST['calendar'])) |
|
2322 | + } elseif (isset($_POST['calendar'])) |
|
2201 | 2323 | { |
2202 | 2324 | $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; |
2203 | 2325 | |
@@ -2225,14 +2347,15 @@ discard block |
||
2225 | 2347 | } |
2226 | 2348 | |
2227 | 2349 | // Delete it? |
2228 | - if (isset($_REQUEST['deleteevent'])) |
|
2229 | - $smcFunc['db_query']('', ' |
|
2350 | + if (isset($_REQUEST['deleteevent'])) { |
|
2351 | + $smcFunc['db_query']('', ' |
|
2230 | 2352 | DELETE FROM {db_prefix}calendar |
2231 | 2353 | WHERE id_event = {int:id_event}', |
2232 | 2354 | array( |
2233 | 2355 | 'id_event' => $_REQUEST['eventid'], |
2234 | 2356 | ) |
2235 | 2357 | ); |
2358 | + } |
|
2236 | 2359 | // ... or just update it? |
2237 | 2360 | else |
2238 | 2361 | { |
@@ -2274,9 +2397,8 @@ discard block |
||
2274 | 2397 | array($user_info['id'], $topic, 0), |
2275 | 2398 | array('id_member', 'id_topic', 'id_board') |
2276 | 2399 | ); |
2277 | - } |
|
2278 | - elseif (!$newTopic) |
|
2279 | - $smcFunc['db_query']('', ' |
|
2400 | + } elseif (!$newTopic) { |
|
2401 | + $smcFunc['db_query']('', ' |
|
2280 | 2402 | DELETE FROM {db_prefix}log_notify |
2281 | 2403 | WHERE id_member = {int:current_member} |
2282 | 2404 | AND id_topic = {int:current_topic}', |
@@ -2285,16 +2407,20 @@ discard block |
||
2285 | 2407 | 'current_topic' => $topic, |
2286 | 2408 | ) |
2287 | 2409 | ); |
2410 | + } |
|
2288 | 2411 | |
2289 | 2412 | // Log an act of moderation - modifying. |
2290 | - if (!empty($moderationAction)) |
|
2291 | - logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
2413 | + if (!empty($moderationAction)) { |
|
2414 | + logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
2415 | + } |
|
2292 | 2416 | |
2293 | - if (isset($_POST['lock']) && $_POST['lock'] != 2) |
|
2294 | - logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
2417 | + if (isset($_POST['lock']) && $_POST['lock'] != 2) { |
|
2418 | + logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
2419 | + } |
|
2295 | 2420 | |
2296 | - if (isset($_POST['sticky'])) |
|
2297 | - logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
2421 | + if (isset($_POST['sticky'])) { |
|
2422 | + logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
2423 | + } |
|
2298 | 2424 | |
2299 | 2425 | // Returning to the topic? |
2300 | 2426 | if (!empty($_REQUEST['goback'])) |
@@ -2313,26 +2439,31 @@ discard block |
||
2313 | 2439 | ); |
2314 | 2440 | } |
2315 | 2441 | |
2316 | - if ($board_info['num_topics'] == 0) |
|
2317 | - cache_put_data('board-' . $board, null, 120); |
|
2442 | + if ($board_info['num_topics'] == 0) { |
|
2443 | + cache_put_data('board-' . $board, null, 120); |
|
2444 | + } |
|
2318 | 2445 | |
2319 | 2446 | call_integration_hook('integrate_post2_end'); |
2320 | 2447 | |
2321 | - if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) |
|
2322 | - redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2448 | + if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) { |
|
2449 | + redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2450 | + } |
|
2323 | 2451 | |
2324 | - if (!empty($_POST['move']) && allowedTo('move_any')) |
|
2325 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2452 | + if (!empty($_POST['move']) && allowedTo('move_any')) { |
|
2453 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2454 | + } |
|
2326 | 2455 | |
2327 | 2456 | // Return to post if the mod is on. |
2328 | - if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) |
|
2329 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
2330 | - elseif (!empty($_REQUEST['goback'])) |
|
2331 | - redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
2457 | + if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) { |
|
2458 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
2459 | + } elseif (!empty($_REQUEST['goback'])) { |
|
2460 | + redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
2461 | + } |
|
2332 | 2462 | // Dut-dut-duh-duh-DUH-duh-dut-duh-duh! *dances to the Final Fantasy Fanfare...* |
2333 | - else |
|
2334 | - redirectexit('board=' . $board . '.0'); |
|
2335 | -} |
|
2463 | + else { |
|
2464 | + redirectexit('board=' . $board . '.0'); |
|
2465 | + } |
|
2466 | + } |
|
2336 | 2467 | |
2337 | 2468 | /** |
2338 | 2469 | * Handle the announce topic function (action=announce). |
@@ -2350,8 +2481,9 @@ discard block |
||
2350 | 2481 | |
2351 | 2482 | validateSession(); |
2352 | 2483 | |
2353 | - if (empty($topic)) |
|
2354 | - fatal_lang_error('topic_gone', false); |
|
2484 | + if (empty($topic)) { |
|
2485 | + fatal_lang_error('topic_gone', false); |
|
2486 | + } |
|
2355 | 2487 | |
2356 | 2488 | loadLanguage('Post'); |
2357 | 2489 | loadTemplate('Post'); |
@@ -2378,8 +2510,9 @@ discard block |
||
2378 | 2510 | global $txt, $context, $topic, $board_info, $smcFunc; |
2379 | 2511 | |
2380 | 2512 | $groups = array_merge($board_info['groups'], array(1)); |
2381 | - foreach ($groups as $id => $group) |
|
2382 | - $groups[$id] = (int) $group; |
|
2513 | + foreach ($groups as $id => $group) { |
|
2514 | + $groups[$id] = (int) $group; |
|
2515 | + } |
|
2383 | 2516 | |
2384 | 2517 | $context['groups'] = array(); |
2385 | 2518 | if (in_array(0, $groups)) |
@@ -2422,8 +2555,9 @@ discard block |
||
2422 | 2555 | 'group_list' => $groups, |
2423 | 2556 | ) |
2424 | 2557 | ); |
2425 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2426 | - $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
2558 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2559 | + $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
2560 | + } |
|
2427 | 2561 | $smcFunc['db_free_result']($request); |
2428 | 2562 | |
2429 | 2563 | // Get the subject of the topic we're about to announce. |
@@ -2465,16 +2599,19 @@ discard block |
||
2465 | 2599 | $context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start']; |
2466 | 2600 | $groups = array_merge($board_info['groups'], array(1)); |
2467 | 2601 | |
2468 | - if (isset($_POST['membergroups'])) |
|
2469 | - $_POST['who'] = explode(',', $_POST['membergroups']); |
|
2602 | + if (isset($_POST['membergroups'])) { |
|
2603 | + $_POST['who'] = explode(',', $_POST['membergroups']); |
|
2604 | + } |
|
2470 | 2605 | |
2471 | 2606 | // Check whether at least one membergroup was selected. |
2472 | - if (empty($_POST['who'])) |
|
2473 | - fatal_lang_error('no_membergroup_selected'); |
|
2607 | + if (empty($_POST['who'])) { |
|
2608 | + fatal_lang_error('no_membergroup_selected'); |
|
2609 | + } |
|
2474 | 2610 | |
2475 | 2611 | // Make sure all membergroups are integers and can access the board of the announcement. |
2476 | - foreach ($_POST['who'] as $id => $mg) |
|
2477 | - $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
2612 | + foreach ($_POST['who'] as $id => $mg) { |
|
2613 | + $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
2614 | + } |
|
2478 | 2615 | |
2479 | 2616 | // Get the topic subject and censor it. |
2480 | 2617 | $request = $smcFunc['db_query']('', ' |
@@ -2520,12 +2657,13 @@ discard block |
||
2520 | 2657 | if ($smcFunc['db_num_rows']($request) == 0) |
2521 | 2658 | { |
2522 | 2659 | logAction('announce_topic', array('topic' => $topic), 'user'); |
2523 | - if (!empty($_REQUEST['move']) && allowedTo('move_any')) |
|
2524 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2525 | - elseif (!empty($_REQUEST['goback'])) |
|
2526 | - redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
2527 | - else |
|
2528 | - redirectexit('board=' . $board . '.0'); |
|
2660 | + if (!empty($_REQUEST['move']) && allowedTo('move_any')) { |
|
2661 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
2662 | + } elseif (!empty($_REQUEST['goback'])) { |
|
2663 | + redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
2664 | + } else { |
|
2665 | + redirectexit('board=' . $board . '.0'); |
|
2666 | + } |
|
2529 | 2667 | } |
2530 | 2668 | |
2531 | 2669 | $announcements = array(); |
@@ -2544,8 +2682,9 @@ discard block |
||
2544 | 2682 | foreach ($rows as $row) |
2545 | 2683 | { |
2546 | 2684 | // Force them to have it? |
2547 | - if (empty($prefs[$row['id_member']]['announcements'])) |
|
2548 | - continue; |
|
2685 | + if (empty($prefs[$row['id_member']]['announcements'])) { |
|
2686 | + continue; |
|
2687 | + } |
|
2549 | 2688 | |
2550 | 2689 | $cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']; |
2551 | 2690 | |
@@ -2573,8 +2712,9 @@ discard block |
||
2573 | 2712 | } |
2574 | 2713 | |
2575 | 2714 | // For each language send a different mail - low priority... |
2576 | - foreach ($announcements as $lang => $mail) |
|
2577 | - sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
2715 | + foreach ($announcements as $lang => $mail) { |
|
2716 | + sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
2717 | + } |
|
2578 | 2718 | |
2579 | 2719 | $context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1); |
2580 | 2720 | |
@@ -2584,9 +2724,10 @@ discard block |
||
2584 | 2724 | $context['sub_template'] = 'announcement_send'; |
2585 | 2725 | |
2586 | 2726 | // Go back to the correct language for the user ;). |
2587 | - if (!empty($modSettings['userLanguage'])) |
|
2588 | - loadLanguage('Post'); |
|
2589 | -} |
|
2727 | + if (!empty($modSettings['userLanguage'])) { |
|
2728 | + loadLanguage('Post'); |
|
2729 | + } |
|
2730 | + } |
|
2590 | 2731 | |
2591 | 2732 | /** |
2592 | 2733 | * Get the topic for display purposes. |
@@ -2599,12 +2740,13 @@ discard block |
||
2599 | 2740 | { |
2600 | 2741 | global $topic, $modSettings, $context, $smcFunc, $counter, $options; |
2601 | 2742 | |
2602 | - if (isset($_REQUEST['xml'])) |
|
2603 | - $limit = ' |
|
2743 | + if (isset($_REQUEST['xml'])) { |
|
2744 | + $limit = ' |
|
2604 | 2745 | LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']); |
2605 | - else |
|
2606 | - $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
2746 | + } else { |
|
2747 | + $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
2607 | 2748 | LIMIT ' . (int) $modSettings['topicSummaryPosts']; |
2749 | + } |
|
2608 | 2750 | |
2609 | 2751 | // If you're modifying, get only those posts before the current one. (otherwise get all.) |
2610 | 2752 | $request = $smcFunc['db_query']('', ' |
@@ -2642,8 +2784,9 @@ discard block |
||
2642 | 2784 | 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']), |
2643 | 2785 | ); |
2644 | 2786 | |
2645 | - if (!empty($context['new_replies'])) |
|
2646 | - $context['new_replies']--; |
|
2787 | + if (!empty($context['new_replies'])) { |
|
2788 | + $context['new_replies']--; |
|
2789 | + } |
|
2647 | 2790 | } |
2648 | 2791 | $smcFunc['db_free_result']($request); |
2649 | 2792 | } |
@@ -2660,8 +2803,9 @@ discard block |
||
2660 | 2803 | global $sourcedir, $smcFunc; |
2661 | 2804 | |
2662 | 2805 | loadLanguage('Post'); |
2663 | - if (!isset($_REQUEST['xml'])) |
|
2664 | - loadTemplate('Post'); |
|
2806 | + if (!isset($_REQUEST['xml'])) { |
|
2807 | + loadTemplate('Post'); |
|
2808 | + } |
|
2665 | 2809 | |
2666 | 2810 | include_once($sourcedir . '/Subs-Post.php'); |
2667 | 2811 | |
@@ -2692,8 +2836,9 @@ discard block |
||
2692 | 2836 | $smcFunc['db_free_result']($request); |
2693 | 2837 | |
2694 | 2838 | $context['sub_template'] = 'quotefast'; |
2695 | - if (!empty($row)) |
|
2696 | - $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
2839 | + if (!empty($row)) { |
|
2840 | + $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
2841 | + } |
|
2697 | 2842 | |
2698 | 2843 | if (!empty($can_view_post)) |
2699 | 2844 | { |
@@ -2726,8 +2871,9 @@ discard block |
||
2726 | 2871 | } |
2727 | 2872 | |
2728 | 2873 | // Remove any nested quotes. |
2729 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
2730 | - $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
2874 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
2875 | + $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
2876 | + } |
|
2731 | 2877 | |
2732 | 2878 | $lb = "\n"; |
2733 | 2879 | |
@@ -2753,14 +2899,14 @@ discard block |
||
2753 | 2899 | 'time' => '', |
2754 | 2900 | ), |
2755 | 2901 | ); |
2756 | - } |
|
2757 | - else |
|
2758 | - $context['quote'] = array( |
|
2902 | + } else { |
|
2903 | + $context['quote'] = array( |
|
2759 | 2904 | 'xml' => '', |
2760 | 2905 | 'mozilla' => '', |
2761 | 2906 | 'text' => '', |
2762 | 2907 | ); |
2763 | -} |
|
2908 | + } |
|
2909 | + } |
|
2764 | 2910 | |
2765 | 2911 | /** |
2766 | 2912 | * Used to edit the body or subject of a message inline |
@@ -2772,8 +2918,9 @@ discard block |
||
2772 | 2918 | global $user_info, $context, $smcFunc, $language, $board_info; |
2773 | 2919 | |
2774 | 2920 | // We have to have a topic! |
2775 | - if (empty($topic)) |
|
2776 | - obExit(false); |
|
2921 | + if (empty($topic)) { |
|
2922 | + obExit(false); |
|
2923 | + } |
|
2777 | 2924 | |
2778 | 2925 | checkSession('get'); |
2779 | 2926 | require_once($sourcedir . '/Subs-Post.php'); |
@@ -2799,31 +2946,35 @@ discard block |
||
2799 | 2946 | 'guest_id' => 0, |
2800 | 2947 | ) |
2801 | 2948 | ); |
2802 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
2803 | - fatal_lang_error('no_board', false); |
|
2949 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
2950 | + fatal_lang_error('no_board', false); |
|
2951 | + } |
|
2804 | 2952 | $row = $smcFunc['db_fetch_assoc']($request); |
2805 | 2953 | $smcFunc['db_free_result']($request); |
2806 | 2954 | |
2807 | 2955 | // Change either body or subject requires permissions to modify messages. |
2808 | 2956 | if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon'])) |
2809 | 2957 | { |
2810 | - if (!empty($row['locked'])) |
|
2811 | - isAllowedTo('moderate_board'); |
|
2958 | + if (!empty($row['locked'])) { |
|
2959 | + isAllowedTo('moderate_board'); |
|
2960 | + } |
|
2812 | 2961 | |
2813 | 2962 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
2814 | 2963 | { |
2815 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
2816 | - fatal_lang_error('modify_post_time_passed', false); |
|
2817 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
2818 | - isAllowedTo('modify_replies'); |
|
2819 | - else |
|
2820 | - isAllowedTo('modify_own'); |
|
2964 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
2965 | + fatal_lang_error('modify_post_time_passed', false); |
|
2966 | + } elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
2967 | + isAllowedTo('modify_replies'); |
|
2968 | + } else { |
|
2969 | + isAllowedTo('modify_own'); |
|
2970 | + } |
|
2821 | 2971 | } |
2822 | 2972 | // Otherwise, they're locked out; someone who can modify the replies is needed. |
2823 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
2824 | - isAllowedTo('modify_replies'); |
|
2825 | - else |
|
2826 | - isAllowedTo('modify_any'); |
|
2973 | + elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
2974 | + isAllowedTo('modify_replies'); |
|
2975 | + } else { |
|
2976 | + isAllowedTo('modify_any'); |
|
2977 | + } |
|
2827 | 2978 | |
2828 | 2979 | // Only log this action if it wasn't your message. |
2829 | 2980 | $moderationAction = $row['id_member'] != $user_info['id']; |
@@ -2835,10 +2986,10 @@ discard block |
||
2835 | 2986 | $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => '')); |
2836 | 2987 | |
2837 | 2988 | // Maximum number of characters. |
2838 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
2839 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
2840 | - } |
|
2841 | - elseif (isset($_POST['subject'])) |
|
2989 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
2990 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
2991 | + } |
|
2992 | + } elseif (isset($_POST['subject'])) |
|
2842 | 2993 | { |
2843 | 2994 | $post_errors[] = 'no_subject'; |
2844 | 2995 | unset($_POST['subject']); |
@@ -2850,13 +3001,11 @@ discard block |
||
2850 | 3001 | { |
2851 | 3002 | $post_errors[] = 'no_message'; |
2852 | 3003 | unset($_POST['message']); |
2853 | - } |
|
2854 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
3004 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
2855 | 3005 | { |
2856 | 3006 | $post_errors[] = 'long_message'; |
2857 | 3007 | unset($_POST['message']); |
2858 | - } |
|
2859 | - else |
|
3008 | + } else |
|
2860 | 3009 | { |
2861 | 3010 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
2862 | 3011 | |
@@ -2872,31 +3021,34 @@ discard block |
||
2872 | 3021 | |
2873 | 3022 | if (isset($_POST['lock'])) |
2874 | 3023 | { |
2875 | - if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) |
|
2876 | - unset($_POST['lock']); |
|
2877 | - elseif (!allowedTo('lock_any')) |
|
3024 | + if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) { |
|
3025 | + unset($_POST['lock']); |
|
3026 | + } elseif (!allowedTo('lock_any')) |
|
2878 | 3027 | { |
2879 | - if ($row['locked'] == 1) |
|
2880 | - unset($_POST['lock']); |
|
2881 | - else |
|
2882 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
3028 | + if ($row['locked'] == 1) { |
|
3029 | + unset($_POST['lock']); |
|
3030 | + } else { |
|
3031 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
3032 | + } |
|
3033 | + } elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) { |
|
3034 | + unset($_POST['lock']); |
|
3035 | + } else { |
|
3036 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
2883 | 3037 | } |
2884 | - elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) |
|
2885 | - unset($_POST['lock']); |
|
2886 | - else |
|
2887 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
2888 | 3038 | } |
2889 | 3039 | |
2890 | - if (isset($_POST['sticky']) && !allowedTo('make_sticky')) |
|
2891 | - unset($_POST['sticky']); |
|
3040 | + if (isset($_POST['sticky']) && !allowedTo('make_sticky')) { |
|
3041 | + unset($_POST['sticky']); |
|
3042 | + } |
|
2892 | 3043 | |
2893 | 3044 | if (isset($_POST['modify_reason'])) |
2894 | 3045 | { |
2895 | 3046 | $_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
2896 | 3047 | |
2897 | 3048 | // Maximum number of characters. |
2898 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
2899 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
3049 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
3050 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
3051 | + } |
|
2900 | 3052 | } |
2901 | 3053 | |
2902 | 3054 | if (empty($post_errors)) |
@@ -2933,8 +3085,9 @@ discard block |
||
2933 | 3085 | } |
2934 | 3086 | } |
2935 | 3087 | // If nothing was changed there's no need to add an entry to the moderation log. |
2936 | - else |
|
2937 | - $moderationAction = false; |
|
3088 | + else { |
|
3089 | + $moderationAction = false; |
|
3090 | + } |
|
2938 | 3091 | |
2939 | 3092 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
2940 | 3093 | |
@@ -2952,9 +3105,9 @@ discard block |
||
2952 | 3105 | // Get the proper (default language) response prefix first. |
2953 | 3106 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
2954 | 3107 | { |
2955 | - if ($language === $user_info['language']) |
|
2956 | - $context['response_prefix'] = $txt['response_prefix']; |
|
2957 | - else |
|
3108 | + if ($language === $user_info['language']) { |
|
3109 | + $context['response_prefix'] = $txt['response_prefix']; |
|
3110 | + } else |
|
2958 | 3111 | { |
2959 | 3112 | loadLanguage('index', $language, false); |
2960 | 3113 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -2976,8 +3129,9 @@ discard block |
||
2976 | 3129 | ); |
2977 | 3130 | } |
2978 | 3131 | |
2979 | - if (!empty($moderationAction)) |
|
2980 | - logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
3132 | + if (!empty($moderationAction)) { |
|
3133 | + logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
3134 | + } |
|
2981 | 3135 | } |
2982 | 3136 | |
2983 | 3137 | if (isset($_REQUEST['xml'])) |
@@ -3018,8 +3172,7 @@ discard block |
||
3018 | 3172 | ); |
3019 | 3173 | |
3020 | 3174 | censorText($context['message']['subject']); |
3021 | - } |
|
3022 | - else |
|
3175 | + } else |
|
3023 | 3176 | { |
3024 | 3177 | $context['message'] = array( |
3025 | 3178 | 'id' => $row['id_msg'], |
@@ -3031,15 +3184,16 @@ discard block |
||
3031 | 3184 | loadLanguage('Errors'); |
3032 | 3185 | foreach ($post_errors as $post_error) |
3033 | 3186 | { |
3034 | - if ($post_error == 'long_message') |
|
3035 | - $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
3036 | - else |
|
3037 | - $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
3187 | + if ($post_error == 'long_message') { |
|
3188 | + $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
3189 | + } else { |
|
3190 | + $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
3191 | + } |
|
3038 | 3192 | } |
3039 | 3193 | } |
3194 | + } else { |
|
3195 | + obExit(false); |
|
3196 | + } |
|
3040 | 3197 | } |
3041 | - else |
|
3042 | - obExit(false); |
|
3043 | -} |
|
3044 | 3198 | |
3045 | 3199 | ?> |
3046 | 3200 | \ No newline at end of file |
@@ -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(); |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | // Are the result fresh? |
998 | 998 | if (!$update_cache && !empty($_SESSION['search_cache']['id_search'])) |
999 | 999 | { |
1000 | - $request = $smcFunc['db_query']('',' |
|
1000 | + $request = $smcFunc['db_query']('', ' |
|
1001 | 1001 | SELECT id_search |
1002 | 1002 | FROM {db_prefix}log_search_results |
1003 | 1003 | WHERE id_search = {int:search_id} |
@@ -1119,7 +1119,7 @@ discard block |
||
1119 | 1119 | SELECT |
1120 | 1120 | {int:id_search}, |
1121 | 1121 | t.id_topic, |
1122 | - ' . $relevance. ', |
|
1122 | + ' . $relevance . ', |
|
1123 | 1123 | ' . (empty($userQuery) ? 't.id_first_msg' : 'm.id_msg') . ', |
1124 | 1124 | 1 |
1125 | 1125 | FROM ' . $subject_query['from'] . (empty($subject_query['inner_join']) ? '' : ' |
@@ -1352,7 +1352,7 @@ discard block |
||
1352 | 1352 | if (empty($subject_query['where'])) |
1353 | 1353 | continue; |
1354 | 1354 | |
1355 | - $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( ' |
|
1355 | + $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? (' |
|
1356 | 1356 | INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics |
1357 | 1357 | (' . ($createTemporary ? '' : 'id_search, ') . 'id_topic)') : '') . ' |
1358 | 1358 | SELECT ' . ($createTemporary ? '' : $_SESSION['search_cache']['id_search'] . ', ') . 't.id_topic |
@@ -1579,7 +1579,7 @@ discard block |
||
1579 | 1579 | } |
1580 | 1580 | $main_query['select']['relevance'] = substr($relevance, 0, -3) . ') / ' . $new_weight_total . ' AS relevance'; |
1581 | 1581 | |
1582 | - $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_no_index', ($smcFunc['db_support_ignore'] ? ( ' |
|
1582 | + $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_no_index', ($smcFunc['db_support_ignore'] ? (' |
|
1583 | 1583 | INSERT IGNORE INTO ' . '{db_prefix}log_search_results |
1584 | 1584 | (' . implode(', ', array_keys($main_query['select'])) . ')') : '') . ' |
1585 | 1585 | SELECT |
@@ -1647,7 +1647,7 @@ discard block |
||
1647 | 1647 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
1648 | 1648 | |
1649 | 1649 | $usedIDs = array_flip(empty($inserts) ? array() : array_keys($inserts)); |
1650 | - $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_sub_only', ($smcFunc['db_support_ignore'] ? ( ' |
|
1650 | + $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_results_sub_only', ($smcFunc['db_support_ignore'] ? (' |
|
1651 | 1651 | INSERT IGNORE INTO {db_prefix}log_search_results |
1652 | 1652 | (id_search, id_topic, relevance, id_msg, num_matches)') : '') . ' |
1653 | 1653 | SELECT |
@@ -2116,7 +2116,7 @@ discard block |
||
2116 | 2116 | if (strlen($query) == 0) |
2117 | 2117 | continue; |
2118 | 2118 | |
2119 | - $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => ''')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function ($m) |
|
2119 | + $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => ''')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function($m) |
|
2120 | 2120 | { |
2121 | 2121 | return isset($m[2]) && "$m[2]" == "$m[1]" ? stripslashes("$m[1]") : "<strong class=\"highlight\">$m[1]</strong>"; |
2122 | 2122 | }, $body_highlighted); |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | // This defines two version types for checking the API's are compatible with this version of SMF. |
20 | 21 | $GLOBALS['search_versions'] = array( |
@@ -39,8 +40,9 @@ discard block |
||
39 | 40 | global $txt, $scripturl, $modSettings, $user_info, $context, $smcFunc, $sourcedir; |
40 | 41 | |
41 | 42 | // Is the load average too high to allow searching just now? |
42 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
43 | - fatal_lang_error('loadavg_search_disabled', false); |
|
43 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
44 | + fatal_lang_error('loadavg_search_disabled', false); |
|
45 | + } |
|
44 | 46 | |
45 | 47 | loadLanguage('Search'); |
46 | 48 | // Don't load this in XML mode. |
@@ -88,23 +90,30 @@ discard block |
||
88 | 90 | @list ($k, $v) = explode('|\'|', $data); |
89 | 91 | $context['search_params'][$k] = $v; |
90 | 92 | } |
91 | - if (isset($context['search_params']['brd'])) |
|
92 | - $context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']); |
|
93 | + if (isset($context['search_params']['brd'])) { |
|
94 | + $context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']); |
|
95 | + } |
|
93 | 96 | } |
94 | 97 | |
95 | - if (isset($_REQUEST['search'])) |
|
96 | - $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
98 | + if (isset($_REQUEST['search'])) { |
|
99 | + $context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']); |
|
100 | + } |
|
97 | 101 | |
98 | - if (isset($context['search_params']['search'])) |
|
99 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
100 | - if (isset($context['search_params']['userspec'])) |
|
101 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
102 | - if (!empty($context['search_params']['searchtype'])) |
|
103 | - $context['search_params']['searchtype'] = 2; |
|
104 | - if (!empty($context['search_params']['minage'])) |
|
105 | - $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
106 | - if (!empty($context['search_params']['maxage'])) |
|
107 | - $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
102 | + if (isset($context['search_params']['search'])) { |
|
103 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
104 | + } |
|
105 | + if (isset($context['search_params']['userspec'])) { |
|
106 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
107 | + } |
|
108 | + if (!empty($context['search_params']['searchtype'])) { |
|
109 | + $context['search_params']['searchtype'] = 2; |
|
110 | + } |
|
111 | + if (!empty($context['search_params']['minage'])) { |
|
112 | + $context['search_params']['minage'] = (int) $context['search_params']['minage']; |
|
113 | + } |
|
114 | + if (!empty($context['search_params']['maxage'])) { |
|
115 | + $context['search_params']['maxage'] = (int) $context['search_params']['maxage']; |
|
116 | + } |
|
108 | 117 | |
109 | 118 | $context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']); |
110 | 119 | $context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']); |
@@ -116,11 +125,13 @@ discard block |
||
116 | 125 | $context['search_errors']['messages'] = array(); |
117 | 126 | foreach ($context['search_errors'] as $search_error => $dummy) |
118 | 127 | { |
119 | - if ($search_error === 'messages') |
|
120 | - continue; |
|
128 | + if ($search_error === 'messages') { |
|
129 | + continue; |
|
130 | + } |
|
121 | 131 | |
122 | - if ($search_error == 'string_too_long') |
|
123 | - $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
|
132 | + if ($search_error == 'string_too_long') { |
|
133 | + $txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']); |
|
134 | + } |
|
124 | 135 | |
125 | 136 | $context['search_errors']['messages'][] = $txt['error_' . $search_error]; |
126 | 137 | } |
@@ -143,12 +154,13 @@ discard block |
||
143 | 154 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
144 | 155 | { |
145 | 156 | // This category hasn't been set up yet.. |
146 | - if (!isset($context['categories'][$row['id_cat']])) |
|
147 | - $context['categories'][$row['id_cat']] = array( |
|
157 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
158 | + $context['categories'][$row['id_cat']] = array( |
|
148 | 159 | 'id' => $row['id_cat'], |
149 | 160 | 'name' => $row['cat_name'], |
150 | 161 | 'boards' => array() |
151 | 162 | ); |
163 | + } |
|
152 | 164 | |
153 | 165 | // Set this board up, and let the template know when it's a child. (indent them..) |
154 | 166 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -159,8 +171,9 @@ discard block |
||
159 | 171 | ); |
160 | 172 | |
161 | 173 | // If a board wasn't checked that probably should have been ensure the board selection is selected, yo! |
162 | - if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) |
|
163 | - $context['boards_check_all'] = false; |
|
174 | + if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) { |
|
175 | + $context['boards_check_all'] = false; |
|
176 | + } |
|
164 | 177 | } |
165 | 178 | $smcFunc['db_free_result']($request); |
166 | 179 | |
@@ -182,18 +195,20 @@ discard block |
||
182 | 195 | } |
183 | 196 | |
184 | 197 | $max_boards = ceil(count($temp_boards) / 2); |
185 | - if ($max_boards == 1) |
|
186 | - $max_boards = 2; |
|
198 | + if ($max_boards == 1) { |
|
199 | + $max_boards = 2; |
|
200 | + } |
|
187 | 201 | |
188 | 202 | // Now, alternate them so they can be shown left and right ;). |
189 | 203 | $context['board_columns'] = array(); |
190 | 204 | for ($i = 0; $i < $max_boards; $i++) |
191 | 205 | { |
192 | 206 | $context['board_columns'][] = $temp_boards[$i]; |
193 | - if (isset($temp_boards[$i + $max_boards])) |
|
194 | - $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
195 | - else |
|
196 | - $context['board_columns'][] = array(); |
|
207 | + if (isset($temp_boards[$i + $max_boards])) { |
|
208 | + $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
209 | + } else { |
|
210 | + $context['board_columns'][] = array(); |
|
211 | + } |
|
197 | 212 | } |
198 | 213 | |
199 | 214 | if (!empty($_REQUEST['topic'])) |
@@ -225,8 +240,9 @@ discard block |
||
225 | 240 | ) |
226 | 241 | ); |
227 | 242 | |
228 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
229 | - fatal_lang_error('topic_gone', false); |
|
243 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
244 | + fatal_lang_error('topic_gone', false); |
|
245 | + } |
|
230 | 246 | |
231 | 247 | list ($context['search_topic']['subject']) = $smcFunc['db_fetch_row']($request); |
232 | 248 | $smcFunc['db_free_result']($request); |
@@ -256,11 +272,13 @@ discard block |
||
256 | 272 | global $excludedWords, $participants, $smcFunc; |
257 | 273 | |
258 | 274 | // if comming from the quick search box, and we want to search on members, well we need to do that ;) |
259 | - if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') |
|
260 | - redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search'])); |
|
275 | + if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') { |
|
276 | + redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search'])); |
|
277 | + } |
|
261 | 278 | |
262 | - if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) |
|
263 | - fatal_lang_error('loadavg_search_disabled', false); |
|
279 | + if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) { |
|
280 | + fatal_lang_error('loadavg_search_disabled', false); |
|
281 | + } |
|
264 | 282 | |
265 | 283 | // No, no, no... this is a bit hard on the server, so don't you go prefetching it! |
266 | 284 | if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') |
@@ -307,8 +325,9 @@ discard block |
||
307 | 325 | } |
308 | 326 | |
309 | 327 | // Zero weight. Weightless :P. |
310 | - if (empty($weight_total)) |
|
311 | - fatal_lang_error('search_invalid_weights'); |
|
328 | + if (empty($weight_total)) { |
|
329 | + fatal_lang_error('search_invalid_weights'); |
|
330 | + } |
|
312 | 331 | |
313 | 332 | // These vars don't require an interface, they're just here for tweaking. |
314 | 333 | $recentPercentage = 0.30; |
@@ -326,11 +345,13 @@ discard block |
||
326 | 345 | $context['search_string_limit'] = 100; |
327 | 346 | |
328 | 347 | loadLanguage('Search'); |
329 | - if (!isset($_REQUEST['xml'])) |
|
330 | - loadTemplate('Search'); |
|
348 | + if (!isset($_REQUEST['xml'])) { |
|
349 | + loadTemplate('Search'); |
|
350 | + } |
|
331 | 351 | //If we're doing XML we need to use the results template regardless really. |
332 | - else |
|
333 | - $context['sub_template'] = 'results'; |
|
352 | + else { |
|
353 | + $context['sub_template'] = 'results'; |
|
354 | + } |
|
334 | 355 | |
335 | 356 | // Are you allowed? |
336 | 357 | isAllowedTo('search_posts'); |
@@ -363,34 +384,39 @@ discard block |
||
363 | 384 | $search_params[$k] = $v; |
364 | 385 | } |
365 | 386 | |
366 | - if (isset($search_params['brd'])) |
|
367 | - $search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']); |
|
387 | + if (isset($search_params['brd'])) { |
|
388 | + $search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']); |
|
389 | + } |
|
368 | 390 | } |
369 | 391 | |
370 | 392 | // Store whether simple search was used (needed if the user wants to do another query). |
371 | - if (!isset($search_params['advanced'])) |
|
372 | - $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
393 | + if (!isset($search_params['advanced'])) { |
|
394 | + $search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1; |
|
395 | + } |
|
373 | 396 | |
374 | 397 | // 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'. |
375 | - if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) |
|
376 | - $search_params['searchtype'] = 2; |
|
398 | + if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) { |
|
399 | + $search_params['searchtype'] = 2; |
|
400 | + } |
|
377 | 401 | |
378 | 402 | // Minimum age of messages. Default to zero (don't set param in that case). |
379 | - if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) |
|
380 | - $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
403 | + if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) { |
|
404 | + $search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage']; |
|
405 | + } |
|
381 | 406 | |
382 | 407 | // Maximum age of messages. Default to infinite (9999 days: param not set). |
383 | - if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) |
|
384 | - $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
408 | + if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) { |
|
409 | + $search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage']; |
|
410 | + } |
|
385 | 411 | |
386 | 412 | // Searching a specific topic? |
387 | 413 | if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic')) |
388 | 414 | { |
389 | 415 | $search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : ''); |
390 | 416 | $search_params['show_complete'] = true; |
417 | + } elseif (!empty($search_params['topic'])) { |
|
418 | + $search_params['topic'] = (int) $search_params['topic']; |
|
391 | 419 | } |
392 | - elseif (!empty($search_params['topic'])) |
|
393 | - $search_params['topic'] = (int) $search_params['topic']; |
|
394 | 420 | |
395 | 421 | if (!empty($search_params['minage']) || !empty($search_params['maxage'])) |
396 | 422 | { |
@@ -408,19 +434,21 @@ discard block |
||
408 | 434 | ) |
409 | 435 | ); |
410 | 436 | list ($minMsgID, $maxMsgID) = $smcFunc['db_fetch_row']($request); |
411 | - if ($minMsgID < 0 || $maxMsgID < 0) |
|
412 | - $context['search_errors']['no_messages_in_time_frame'] = true; |
|
437 | + if ($minMsgID < 0 || $maxMsgID < 0) { |
|
438 | + $context['search_errors']['no_messages_in_time_frame'] = true; |
|
439 | + } |
|
413 | 440 | $smcFunc['db_free_result']($request); |
414 | 441 | } |
415 | 442 | |
416 | 443 | // Default the user name to a wildcard matching every user (*). |
417 | - if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) |
|
418 | - $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
444 | + if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) { |
|
445 | + $search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec']; |
|
446 | + } |
|
419 | 447 | |
420 | 448 | // If there's no specific user, then don't mention it in the main query. |
421 | - if (empty($search_params['userspec'])) |
|
422 | - $userQuery = ''; |
|
423 | - else |
|
449 | + if (empty($search_params['userspec'])) { |
|
450 | + $userQuery = ''; |
|
451 | + } else |
|
424 | 452 | { |
425 | 453 | $userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('"' => '"')); |
426 | 454 | $userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')); |
@@ -432,19 +460,21 @@ discard block |
||
432 | 460 | { |
433 | 461 | $possible_users[$k] = trim($possible_users[$k]); |
434 | 462 | |
435 | - if (strlen($possible_users[$k]) == 0) |
|
436 | - unset($possible_users[$k]); |
|
463 | + if (strlen($possible_users[$k]) == 0) { |
|
464 | + unset($possible_users[$k]); |
|
465 | + } |
|
437 | 466 | } |
438 | 467 | |
439 | 468 | // Create a list of database-escaped search names. |
440 | 469 | $realNameMatches = array(); |
441 | - foreach ($possible_users as $possible_user) |
|
442 | - $realNameMatches[] = $smcFunc['db_quote']( |
|
470 | + foreach ($possible_users as $possible_user) { |
|
471 | + $realNameMatches[] = $smcFunc['db_quote']( |
|
443 | 472 | '{string:possible_user}', |
444 | 473 | array( |
445 | 474 | 'possible_user' => $possible_user |
446 | 475 | ) |
447 | 476 | ); |
477 | + } |
|
448 | 478 | |
449 | 479 | // Retrieve a list of possible members. |
450 | 480 | $request = $smcFunc['db_query']('', ' |
@@ -456,9 +486,9 @@ discard block |
||
456 | 486 | ) |
457 | 487 | ); |
458 | 488 | // Simply do nothing if there're too many members matching the criteria. |
459 | - if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) |
|
460 | - $userQuery = ''; |
|
461 | - elseif ($smcFunc['db_num_rows']($request) == 0) |
|
489 | + if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) { |
|
490 | + $userQuery = ''; |
|
491 | + } elseif ($smcFunc['db_num_rows']($request) == 0) |
|
462 | 492 | { |
463 | 493 | $userQuery = $smcFunc['db_quote']( |
464 | 494 | 'm.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})', |
@@ -467,12 +497,12 @@ discard block |
||
467 | 497 | 'match_possible_guest_names' => 'm.poster_name LIKE ' . implode(' OR m.poster_name LIKE ', $realNameMatches), |
468 | 498 | ) |
469 | 499 | ); |
470 | - } |
|
471 | - else |
|
500 | + } else |
|
472 | 501 | { |
473 | 502 | $memberlist = array(); |
474 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
475 | - $memberlist[] = $row['id_member']; |
|
503 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
504 | + $memberlist[] = $row['id_member']; |
|
505 | + } |
|
476 | 506 | $userQuery = $smcFunc['db_quote']( |
477 | 507 | '(m.id_member IN ({array_int:matched_members}) OR (m.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})))', |
478 | 508 | array( |
@@ -486,22 +516,25 @@ discard block |
||
486 | 516 | } |
487 | 517 | |
488 | 518 | // If the boards were passed by URL (params=), temporarily put them back in $_REQUEST. |
489 | - if (!empty($search_params['brd']) && is_array($search_params['brd'])) |
|
490 | - $_REQUEST['brd'] = $search_params['brd']; |
|
519 | + if (!empty($search_params['brd']) && is_array($search_params['brd'])) { |
|
520 | + $_REQUEST['brd'] = $search_params['brd']; |
|
521 | + } |
|
491 | 522 | |
492 | 523 | // Ensure that brd is an array. |
493 | 524 | if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board')) |
494 | 525 | { |
495 | - if (!empty($_REQUEST['brd'])) |
|
496 | - $_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']); |
|
497 | - else |
|
498 | - $_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array(); |
|
526 | + if (!empty($_REQUEST['brd'])) { |
|
527 | + $_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']); |
|
528 | + } else { |
|
529 | + $_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array(); |
|
530 | + } |
|
499 | 531 | } |
500 | 532 | |
501 | 533 | // Make sure all boards are integers. |
502 | - if (!empty($_REQUEST['brd'])) |
|
503 | - foreach ($_REQUEST['brd'] as $id => $brd) |
|
534 | + if (!empty($_REQUEST['brd'])) { |
|
535 | + foreach ($_REQUEST['brd'] as $id => $brd) |
|
504 | 536 | $_REQUEST['brd'][$id] = (int) $brd; |
537 | + } |
|
505 | 538 | |
506 | 539 | // Special case for boards: searching just one topic? |
507 | 540 | if (!empty($search_params['topic'])) |
@@ -520,17 +553,18 @@ discard block |
||
520 | 553 | ) |
521 | 554 | ); |
522 | 555 | |
523 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
524 | - fatal_lang_error('topic_gone', false); |
|
556 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
557 | + fatal_lang_error('topic_gone', false); |
|
558 | + } |
|
525 | 559 | |
526 | 560 | $search_params['brd'] = array(); |
527 | 561 | list ($search_params['brd'][0]) = $smcFunc['db_fetch_row']($request); |
528 | 562 | $smcFunc['db_free_result']($request); |
529 | 563 | } |
530 | 564 | // Select all boards you've selected AND are allowed to see. |
531 | - elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) |
|
532 | - $search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd']; |
|
533 | - else |
|
565 | + elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) { |
|
566 | + $search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd']; |
|
567 | + } else |
|
534 | 568 | { |
535 | 569 | $see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board'; |
536 | 570 | $request = $smcFunc['db_query']('', ' |
@@ -548,19 +582,22 @@ discard block |
||
548 | 582 | ) |
549 | 583 | ); |
550 | 584 | $search_params['brd'] = array(); |
551 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
552 | - $search_params['brd'][] = $row['id_board']; |
|
585 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
586 | + $search_params['brd'][] = $row['id_board']; |
|
587 | + } |
|
553 | 588 | $smcFunc['db_free_result']($request); |
554 | 589 | |
555 | 590 | // This error should pro'bly only happen for hackers. |
556 | - if (empty($search_params['brd'])) |
|
557 | - $context['search_errors']['no_boards_selected'] = true; |
|
591 | + if (empty($search_params['brd'])) { |
|
592 | + $context['search_errors']['no_boards_selected'] = true; |
|
593 | + } |
|
558 | 594 | } |
559 | 595 | |
560 | 596 | if (count($search_params['brd']) != 0) |
561 | 597 | { |
562 | - foreach ($search_params['brd'] as $k => $v) |
|
563 | - $search_params['brd'][$k] = (int) $v; |
|
598 | + foreach ($search_params['brd'] as $k => $v) { |
|
599 | + $search_params['brd'][$k] = (int) $v; |
|
600 | + } |
|
564 | 601 | |
565 | 602 | // If we've selected all boards, this parameter can be left empty. |
566 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -574,15 +611,16 @@ discard block |
||
574 | 611 | list ($num_boards) = $smcFunc['db_fetch_row']($request); |
575 | 612 | $smcFunc['db_free_result']($request); |
576 | 613 | |
577 | - if (count($search_params['brd']) == $num_boards) |
|
614 | + if (count($search_params['brd']) == $num_boards) { |
|
615 | + $boardQuery = ''; |
|
616 | + } elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) { |
|
617 | + $boardQuery = '!= ' . $modSettings['recycle_board']; |
|
618 | + } else { |
|
619 | + $boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')'; |
|
620 | + } |
|
621 | + } else { |
|
578 | 622 | $boardQuery = ''; |
579 | - elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) |
|
580 | - $boardQuery = '!= ' . $modSettings['recycle_board']; |
|
581 | - else |
|
582 | - $boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')'; |
|
583 | 623 | } |
584 | - else |
|
585 | - $boardQuery = ''; |
|
586 | 624 | |
587 | 625 | $search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']); |
588 | 626 | $search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']); |
@@ -596,11 +634,13 @@ discard block |
||
596 | 634 | 'id_msg', |
597 | 635 | ); |
598 | 636 | call_integration_hook('integrate_search_sort_columns', array(&$sort_columns)); |
599 | - if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) |
|
600 | - list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
637 | + if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) { |
|
638 | + list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, ''); |
|
639 | + } |
|
601 | 640 | $search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'relevance'; |
602 | - if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') |
|
603 | - $search_params['sort'] = 'id_msg'; |
|
641 | + if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') { |
|
642 | + $search_params['sort'] = 'id_msg'; |
|
643 | + } |
|
604 | 644 | |
605 | 645 | // Sorting direction: descending unless stated otherwise. |
606 | 646 | $search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc'; |
@@ -624,17 +664,19 @@ discard block |
||
624 | 664 | // What are we searching for? |
625 | 665 | if (empty($search_params['search'])) |
626 | 666 | { |
627 | - if (isset($_GET['search'])) |
|
628 | - $search_params['search'] = un_htmlspecialchars($_GET['search']); |
|
629 | - elseif (isset($_POST['search'])) |
|
630 | - $search_params['search'] = $_POST['search']; |
|
631 | - else |
|
632 | - $search_params['search'] = ''; |
|
667 | + if (isset($_GET['search'])) { |
|
668 | + $search_params['search'] = un_htmlspecialchars($_GET['search']); |
|
669 | + } elseif (isset($_POST['search'])) { |
|
670 | + $search_params['search'] = $_POST['search']; |
|
671 | + } else { |
|
672 | + $search_params['search'] = ''; |
|
673 | + } |
|
633 | 674 | } |
634 | 675 | |
635 | 676 | // Nothing?? |
636 | - if (!isset($search_params['search']) || $search_params['search'] == '') |
|
637 | - $context['search_errors']['invalid_search_string'] = true; |
|
677 | + if (!isset($search_params['search']) || $search_params['search'] == '') { |
|
678 | + $context['search_errors']['invalid_search_string'] = true; |
|
679 | + } |
|
638 | 680 | // Too long? |
639 | 681 | elseif ($smcFunc['strlen']($search_params['search']) > $context['search_string_limit']) |
640 | 682 | { |
@@ -648,8 +690,9 @@ discard block |
||
648 | 690 | $stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query)); |
649 | 691 | |
650 | 692 | // This (hidden) setting will do fulltext searching in the most basic way. |
651 | - if (!empty($modSettings['search_simple_fulltext'])) |
|
652 | - $stripped_query = strtr($stripped_query, array('"' => '')); |
|
693 | + if (!empty($modSettings['search_simple_fulltext'])) { |
|
694 | + $stripped_query = strtr($stripped_query, array('"' => '')); |
|
695 | + } |
|
653 | 696 | |
654 | 697 | $no_regexp = preg_match('~&#(?:\d{1,7}|x[0-9a-fA-F]{1,6});~', $stripped_query) === 1; |
655 | 698 | |
@@ -672,8 +715,9 @@ discard block |
||
672 | 715 | { |
673 | 716 | if ($word === '-') |
674 | 717 | { |
675 | - if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) |
|
676 | - $excludedWords[] = $word; |
|
718 | + if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { |
|
719 | + $excludedWords[] = $word; |
|
720 | + } |
|
677 | 721 | unset($phraseArray[$index]); |
678 | 722 | } |
679 | 723 | } |
@@ -683,8 +727,9 @@ discard block |
||
683 | 727 | { |
684 | 728 | if (strpos(trim($word), '-') === 0) |
685 | 729 | { |
686 | - if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) |
|
687 | - $excludedWords[] = $word; |
|
730 | + if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) { |
|
731 | + $excludedWords[] = $word; |
|
732 | + } |
|
688 | 733 | unset($wordArray[$index]); |
689 | 734 | } |
690 | 735 | } |
@@ -697,8 +742,9 @@ discard block |
||
697 | 742 | foreach ($searchArray as $index => $value) |
698 | 743 | { |
699 | 744 | // Skip anything practically empty. |
700 | - if (($searchArray[$index] = trim($value, '-_\' ')) === '') |
|
701 | - unset($searchArray[$index]); |
|
745 | + if (($searchArray[$index] = trim($value, '-_\' ')) === '') { |
|
746 | + unset($searchArray[$index]); |
|
747 | + } |
|
702 | 748 | // Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing. |
703 | 749 | elseif (in_array($searchArray[$index], $blacklisted_words)) |
704 | 750 | { |
@@ -716,31 +762,37 @@ discard block |
||
716 | 762 | |
717 | 763 | // Create an array of replacements for highlighting. |
718 | 764 | $context['mark'] = array(); |
719 | - foreach ($searchArray as $word) |
|
720 | - $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
765 | + foreach ($searchArray as $word) { |
|
766 | + $context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>'; |
|
767 | + } |
|
721 | 768 | |
722 | 769 | // Initialize two arrays storing the words that have to be searched for. |
723 | 770 | $orParts = array(); |
724 | 771 | $searchWords = array(); |
725 | 772 | |
726 | 773 | // Make sure at least one word is being searched for. |
727 | - if (empty($searchArray)) |
|
728 | - $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true; |
|
774 | + if (empty($searchArray)) { |
|
775 | + $context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true; |
|
776 | + } |
|
729 | 777 | // All words/sentences must match. |
730 | - elseif (empty($search_params['searchtype'])) |
|
731 | - $orParts[0] = $searchArray; |
|
778 | + elseif (empty($search_params['searchtype'])) { |
|
779 | + $orParts[0] = $searchArray; |
|
780 | + } |
|
732 | 781 | // Any word/sentence must match. |
733 | - else |
|
734 | - foreach ($searchArray as $index => $value) |
|
782 | + else { |
|
783 | + foreach ($searchArray as $index => $value) |
|
735 | 784 | $orParts[$index] = array($value); |
785 | + } |
|
736 | 786 | |
737 | 787 | // Don't allow duplicate error messages if one string is too short. |
738 | - if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) |
|
739 | - unset($context['search_errors']['invalid_search_string']); |
|
788 | + if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) { |
|
789 | + unset($context['search_errors']['invalid_search_string']); |
|
790 | + } |
|
740 | 791 | // Make sure the excluded words are in all or-branches. |
741 | - foreach ($orParts as $orIndex => $andParts) |
|
742 | - foreach ($excludedWords as $word) |
|
792 | + foreach ($orParts as $orIndex => $andParts) { |
|
793 | + foreach ($excludedWords as $word) |
|
743 | 794 | $orParts[$orIndex][] = $word; |
795 | + } |
|
744 | 796 | |
745 | 797 | // Determine the or-branches and the fulltext search words. |
746 | 798 | foreach ($orParts as $orIndex => $andParts) |
@@ -754,8 +806,9 @@ discard block |
||
754 | 806 | ); |
755 | 807 | |
756 | 808 | // Sort the indexed words (large words -> small words -> excluded words). |
757 | - if ($searchAPI->supportsMethod('searchSort')) |
|
758 | - usort($orParts[$orIndex], 'searchSort'); |
|
809 | + if ($searchAPI->supportsMethod('searchSort')) { |
|
810 | + usort($orParts[$orIndex], 'searchSort'); |
|
811 | + } |
|
759 | 812 | |
760 | 813 | foreach ($orParts[$orIndex] as $word) |
761 | 814 | { |
@@ -767,15 +820,17 @@ discard block |
||
767 | 820 | if (!$is_excluded || count($subjectWords) === 1) |
768 | 821 | { |
769 | 822 | $searchWords[$orIndex]['subject_words'] = array_merge($searchWords[$orIndex]['subject_words'], $subjectWords); |
770 | - if ($is_excluded) |
|
771 | - $excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords); |
|
823 | + if ($is_excluded) { |
|
824 | + $excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords); |
|
825 | + } |
|
826 | + } else { |
|
827 | + $excludedPhrases[] = $word; |
|
772 | 828 | } |
773 | - else |
|
774 | - $excludedPhrases[] = $word; |
|
775 | 829 | |
776 | 830 | // Have we got indexes to prepare? |
777 | - if ($searchAPI->supportsMethod('prepareIndexes')) |
|
778 | - $searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded); |
|
831 | + if ($searchAPI->supportsMethod('prepareIndexes')) { |
|
832 | + $searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded); |
|
833 | + } |
|
779 | 834 | } |
780 | 835 | |
781 | 836 | // Search_force_index requires all AND parts to have at least one fulltext word. |
@@ -783,8 +838,7 @@ discard block |
||
783 | 838 | { |
784 | 839 | $context['search_errors']['query_not_specific_enough'] = true; |
785 | 840 | break; |
786 | - } |
|
787 | - elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords)) |
|
841 | + } elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords)) |
|
788 | 842 | { |
789 | 843 | $context['search_errors']['query_not_specific_enough'] = true; |
790 | 844 | break; |
@@ -812,8 +866,9 @@ discard block |
||
812 | 866 | $found_misspelling = false; |
813 | 867 | foreach ($searchArray as $word) |
814 | 868 | { |
815 | - if (empty($link)) |
|
816 | - continue; |
|
869 | + if (empty($link)) { |
|
870 | + continue; |
|
871 | + } |
|
817 | 872 | |
818 | 873 | // Don't check phrases. |
819 | 874 | if (preg_match('~^\w+$~', $word) === 0) |
@@ -828,8 +883,7 @@ discard block |
||
828 | 883 | $did_you_mean['search'][] = $word; |
829 | 884 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
830 | 885 | continue; |
831 | - } |
|
832 | - elseif (spell_check($link, $word)) |
|
886 | + } elseif (spell_check($link, $word)) |
|
833 | 887 | { |
834 | 888 | $did_you_mean['search'][] = $word; |
835 | 889 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
@@ -840,11 +894,13 @@ discard block |
||
840 | 894 | foreach ($suggestions as $i => $s) |
841 | 895 | { |
842 | 896 | // Search is case insensitive. |
843 | - if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) |
|
844 | - unset($suggestions[$i]); |
|
897 | + if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) { |
|
898 | + unset($suggestions[$i]); |
|
899 | + } |
|
845 | 900 | // Plus, don't suggest something the user thinks is rude! |
846 | - elseif ($suggestions[$i] != censorText($s)) |
|
847 | - unset($suggestions[$i]); |
|
901 | + elseif ($suggestions[$i] != censorText($s)) { |
|
902 | + unset($suggestions[$i]); |
|
903 | + } |
|
848 | 904 | } |
849 | 905 | |
850 | 906 | // Anything found? If so, correct it! |
@@ -854,8 +910,7 @@ discard block |
||
854 | 910 | $did_you_mean['search'][] = $suggestions[0]; |
855 | 911 | $did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>'; |
856 | 912 | $found_misspelling = true; |
857 | - } |
|
858 | - else |
|
913 | + } else |
|
859 | 914 | { |
860 | 915 | $did_you_mean['search'][] = $word; |
861 | 916 | $did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word); |
@@ -872,8 +927,7 @@ discard block |
||
872 | 927 | { |
873 | 928 | $temp_excluded['search'][] = '-"' . $word . '"'; |
874 | 929 | $temp_excluded['display'][] = '-"' . $smcFunc['htmlspecialchars']($word) . '"'; |
875 | - } |
|
876 | - else |
|
930 | + } else |
|
877 | 931 | { |
878 | 932 | $temp_excluded['search'][] = '-' . $word; |
879 | 933 | $temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word); |
@@ -885,11 +939,13 @@ discard block |
||
885 | 939 | |
886 | 940 | $temp_params = $search_params; |
887 | 941 | $temp_params['search'] = implode(' ', $did_you_mean['search']); |
888 | - if (isset($temp_params['brd'])) |
|
889 | - $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
942 | + if (isset($temp_params['brd'])) { |
|
943 | + $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
944 | + } |
|
890 | 945 | $context['params'] = array(); |
891 | - foreach ($temp_params as $k => $v) |
|
892 | - $context['did_you_mean_params'][] = $k . '|\'|' . $v; |
|
946 | + foreach ($temp_params as $k => $v) { |
|
947 | + $context['did_you_mean_params'][] = $k . '|\'|' . $v; |
|
948 | + } |
|
893 | 949 | $context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params'])); |
894 | 950 | $context['did_you_mean'] = implode(' ', $did_you_mean['display']); |
895 | 951 | } |
@@ -897,18 +953,20 @@ discard block |
||
897 | 953 | |
898 | 954 | // Let the user adjust the search query, should they wish? |
899 | 955 | $context['search_params'] = $search_params; |
900 | - if (isset($context['search_params']['search'])) |
|
901 | - $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
902 | - if (isset($context['search_params']['userspec'])) |
|
903 | - $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
956 | + if (isset($context['search_params']['search'])) { |
|
957 | + $context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']); |
|
958 | + } |
|
959 | + if (isset($context['search_params']['userspec'])) { |
|
960 | + $context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']); |
|
961 | + } |
|
904 | 962 | |
905 | 963 | // Do we have captcha enabled? |
906 | 964 | if ($user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search'])) |
907 | 965 | { |
908 | 966 | // If we come from another search box tone down the error... |
909 | - if (!isset($_REQUEST['search_vv'])) |
|
910 | - $context['search_errors']['need_verification_code'] = true; |
|
911 | - else |
|
967 | + if (!isset($_REQUEST['search_vv'])) { |
|
968 | + $context['search_errors']['need_verification_code'] = true; |
|
969 | + } else |
|
912 | 970 | { |
913 | 971 | require_once($sourcedir . '/Subs-Editor.php'); |
914 | 972 | $verificationOptions = array( |
@@ -918,12 +976,14 @@ discard block |
||
918 | 976 | |
919 | 977 | if (is_array($context['require_verification'])) |
920 | 978 | { |
921 | - foreach ($context['require_verification'] as $error) |
|
922 | - $context['search_errors'][$error] = true; |
|
979 | + foreach ($context['require_verification'] as $error) { |
|
980 | + $context['search_errors'][$error] = true; |
|
981 | + } |
|
923 | 982 | } |
924 | 983 | // Don't keep asking for it - they've proven themselves worthy. |
925 | - else |
|
926 | - $_SESSION['ss_vv_passed'] = true; |
|
984 | + else { |
|
985 | + $_SESSION['ss_vv_passed'] = true; |
|
986 | + } |
|
927 | 987 | } |
928 | 988 | } |
929 | 989 | |
@@ -931,19 +991,22 @@ discard block |
||
931 | 991 | |
932 | 992 | // All search params have been checked, let's compile them to a single string... made less simple by PHP 4.3.9 and below. |
933 | 993 | $temp_params = $search_params; |
934 | - if (isset($temp_params['brd'])) |
|
935 | - $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
994 | + if (isset($temp_params['brd'])) { |
|
995 | + $temp_params['brd'] = implode(',', $temp_params['brd']); |
|
996 | + } |
|
936 | 997 | $context['params'] = array(); |
937 | - foreach ($temp_params as $k => $v) |
|
938 | - $context['params'][] = $k . '|\'|' . $v; |
|
998 | + foreach ($temp_params as $k => $v) { |
|
999 | + $context['params'][] = $k . '|\'|' . $v; |
|
1000 | + } |
|
939 | 1001 | |
940 | 1002 | if (!empty($context['params'])) |
941 | 1003 | { |
942 | 1004 | // Due to old IE's 2083 character limit, we have to compress long search strings |
943 | 1005 | $params = @gzcompress(implode('|"|', $context['params'])); |
944 | 1006 | // Gzcompress failed, use try non-gz |
945 | - if (empty($params)) |
|
946 | - $params = implode('|"|', $context['params']); |
|
1007 | + if (empty($params)) { |
|
1008 | + $params = implode('|"|', $context['params']); |
|
1009 | + } |
|
947 | 1010 | // Base64 encode, then replace +/= with uri safe ones that can be reverted |
948 | 1011 | $context['params'] = str_replace(array('+', '/', '='), array('-', '_', '.'), base64_encode($params)); |
949 | 1012 | } |
@@ -969,8 +1032,9 @@ discard block |
||
969 | 1032 | } |
970 | 1033 | |
971 | 1034 | // Spam me not, Spam-a-lot? |
972 | - if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) |
|
973 | - spamProtection('search'); |
|
1035 | + if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) { |
|
1036 | + spamProtection('search'); |
|
1037 | + } |
|
974 | 1038 | // Store the last search string to allow pages of results to be browsed. |
975 | 1039 | $_SESSION['last_ss'] = $search_params['search']; |
976 | 1040 | |
@@ -1007,8 +1071,9 @@ discard block |
||
1007 | 1071 | ) |
1008 | 1072 | ); |
1009 | 1073 | |
1010 | - if ($smcFunc['db_affected_rows']($request) === 0) |
|
1011 | - $update_cache = true; |
|
1074 | + if ($smcFunc['db_affected_rows']($request) === 0) { |
|
1075 | + $update_cache = true; |
|
1076 | + } |
|
1012 | 1077 | } |
1013 | 1078 | |
1014 | 1079 | if ($update_cache) |
@@ -1047,8 +1112,9 @@ discard block |
||
1047 | 1112 | 'where' => array(), |
1048 | 1113 | ); |
1049 | 1114 | |
1050 | - if ($modSettings['postmod_active']) |
|
1051 | - $subject_query['where'][] = 't.approved = {int:is_approved}'; |
|
1115 | + if ($modSettings['postmod_active']) { |
|
1116 | + $subject_query['where'][] = 't.approved = {int:is_approved}'; |
|
1117 | + } |
|
1052 | 1118 | |
1053 | 1119 | $numTables = 0; |
1054 | 1120 | $prev_join = 0; |
@@ -1060,8 +1126,7 @@ discard block |
||
1060 | 1126 | { |
1061 | 1127 | $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)'; |
1062 | 1128 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
1063 | - } |
|
1064 | - else |
|
1129 | + } else |
|
1065 | 1130 | { |
1066 | 1131 | $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)'; |
1067 | 1132 | $subject_query['where'][] = 'subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}'); |
@@ -1079,14 +1144,18 @@ discard block |
||
1079 | 1144 | } |
1080 | 1145 | $subject_query['where'][] = $userQuery; |
1081 | 1146 | } |
1082 | - if (!empty($search_params['topic'])) |
|
1083 | - $subject_query['where'][] = 't.id_topic = ' . $search_params['topic']; |
|
1084 | - if (!empty($minMsgID)) |
|
1085 | - $subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID; |
|
1086 | - if (!empty($maxMsgID)) |
|
1087 | - $subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID; |
|
1088 | - if (!empty($boardQuery)) |
|
1089 | - $subject_query['where'][] = 't.id_board ' . $boardQuery; |
|
1147 | + if (!empty($search_params['topic'])) { |
|
1148 | + $subject_query['where'][] = 't.id_topic = ' . $search_params['topic']; |
|
1149 | + } |
|
1150 | + if (!empty($minMsgID)) { |
|
1151 | + $subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID; |
|
1152 | + } |
|
1153 | + if (!empty($maxMsgID)) { |
|
1154 | + $subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID; |
|
1155 | + } |
|
1156 | + if (!empty($boardQuery)) { |
|
1157 | + $subject_query['where'][] = 't.id_board ' . $boardQuery; |
|
1158 | + } |
|
1090 | 1159 | if (!empty($excludedPhrases)) |
1091 | 1160 | { |
1092 | 1161 | if ($subject_query['from'] != '{db_prefix}messages AS m') |
@@ -1106,8 +1175,9 @@ discard block |
||
1106 | 1175 | foreach ($weight_factors as $type => $value) |
1107 | 1176 | { |
1108 | 1177 | $relevance .= $weight[$type]; |
1109 | - if (!empty($value['results'])) |
|
1110 | - $relevance .= ' * ' . $value['results']; |
|
1178 | + if (!empty($value['results'])) { |
|
1179 | + $relevance .= ' * ' . $value['results']; |
|
1180 | + } |
|
1111 | 1181 | $relevance .= ' + '; |
1112 | 1182 | } |
1113 | 1183 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1145,20 +1215,23 @@ discard block |
||
1145 | 1215 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1146 | 1216 | { |
1147 | 1217 | // No duplicates! |
1148 | - if (isset($inserts[$row[1]])) |
|
1149 | - continue; |
|
1218 | + if (isset($inserts[$row[1]])) { |
|
1219 | + continue; |
|
1220 | + } |
|
1150 | 1221 | |
1151 | - foreach ($row as $key => $value) |
|
1152 | - $inserts[$row[1]][] = (int) $row[$key]; |
|
1222 | + foreach ($row as $key => $value) { |
|
1223 | + $inserts[$row[1]][] = (int) $row[$key]; |
|
1224 | + } |
|
1153 | 1225 | } |
1154 | 1226 | $smcFunc['db_free_result']($ignoreRequest); |
1155 | 1227 | $numSubjectResults = count($inserts); |
1228 | + } else { |
|
1229 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1156 | 1230 | } |
1157 | - else |
|
1158 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1159 | 1231 | |
1160 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
1161 | - break; |
|
1232 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
1233 | + break; |
|
1234 | + } |
|
1162 | 1235 | } |
1163 | 1236 | |
1164 | 1237 | // If there's data to be inserted for non-IGNORE databases do it here! |
@@ -1173,8 +1246,7 @@ discard block |
||
1173 | 1246 | } |
1174 | 1247 | |
1175 | 1248 | $_SESSION['search_cache']['num_results'] = $numSubjectResults; |
1176 | - } |
|
1177 | - else |
|
1249 | + } else |
|
1178 | 1250 | { |
1179 | 1251 | $main_query = array( |
1180 | 1252 | 'select' => array( |
@@ -1206,8 +1278,7 @@ discard block |
||
1206 | 1278 | $main_query['weights'] = $weight_factors; |
1207 | 1279 | |
1208 | 1280 | $main_query['group_by'][] = 't.id_topic'; |
1209 | - } |
|
1210 | - else |
|
1281 | + } else |
|
1211 | 1282 | { |
1212 | 1283 | // This is outrageous! |
1213 | 1284 | $main_query['select']['id_topic'] = 'm.id_msg AS id_topic'; |
@@ -1228,8 +1299,9 @@ discard block |
||
1228 | 1299 | $main_query['where'][] = 't.id_topic = {int:topic}'; |
1229 | 1300 | $main_query['parameters']['topic'] = $search_params['topic']; |
1230 | 1301 | } |
1231 | - if (!empty($search_params['show_complete'])) |
|
1232 | - $main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg'; |
|
1302 | + if (!empty($search_params['show_complete'])) { |
|
1303 | + $main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg'; |
|
1304 | + } |
|
1233 | 1305 | } |
1234 | 1306 | |
1235 | 1307 | // *** Get the subject results. |
@@ -1254,14 +1326,15 @@ discard block |
||
1254 | 1326 | ) !== false; |
1255 | 1327 | |
1256 | 1328 | // Clean up some previous cache. |
1257 | - if (!$createTemporary) |
|
1258 | - $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
1329 | + if (!$createTemporary) { |
|
1330 | + $smcFunc['db_search_query']('delete_log_search_topics', ' |
|
1259 | 1331 | DELETE FROM {db_prefix}log_search_topics |
1260 | 1332 | WHERE id_search = {int:search_id}', |
1261 | 1333 | array( |
1262 | 1334 | 'search_id' => $_SESSION['search_cache']['id_search'], |
1263 | 1335 | ) |
1264 | 1336 | ); |
1337 | + } |
|
1265 | 1338 | |
1266 | 1339 | foreach ($searchWords as $orIndex => $words) |
1267 | 1340 | { |
@@ -1293,8 +1366,7 @@ discard block |
||
1293 | 1366 | $subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)'; |
1294 | 1367 | $subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}'; |
1295 | 1368 | $subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]'; |
1296 | - } |
|
1297 | - else |
|
1369 | + } else |
|
1298 | 1370 | { |
1299 | 1371 | $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)'; |
1300 | 1372 | $subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}'; |
@@ -1349,8 +1421,9 @@ discard block |
||
1349 | 1421 | call_integration_hook('integrate_subject_search_query', array(&$subject_query)); |
1350 | 1422 | |
1351 | 1423 | // Nothing to search for? |
1352 | - if (empty($subject_query['where'])) |
|
1353 | - continue; |
|
1424 | + if (empty($subject_query['where'])) { |
|
1425 | + continue; |
|
1426 | + } |
|
1354 | 1427 | |
1355 | 1428 | $ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( ' |
1356 | 1429 | INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics |
@@ -1373,19 +1446,21 @@ discard block |
||
1373 | 1446 | { |
1374 | 1447 | $ind = $createTemporary ? 0 : 1; |
1375 | 1448 | // No duplicates! |
1376 | - if (isset($inserts[$row[$ind]])) |
|
1377 | - continue; |
|
1449 | + if (isset($inserts[$row[$ind]])) { |
|
1450 | + continue; |
|
1451 | + } |
|
1378 | 1452 | |
1379 | 1453 | $inserts[$row[$ind]] = $row; |
1380 | 1454 | } |
1381 | 1455 | $smcFunc['db_free_result']($ignoreRequest); |
1382 | 1456 | $numSubjectResults = count($inserts); |
1457 | + } else { |
|
1458 | + $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1383 | 1459 | } |
1384 | - else |
|
1385 | - $numSubjectResults += $smcFunc['db_affected_rows'](); |
|
1386 | 1460 | |
1387 | - if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) |
|
1388 | - break; |
|
1461 | + if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) { |
|
1462 | + break; |
|
1463 | + } |
|
1389 | 1464 | } |
1390 | 1465 | |
1391 | 1466 | // Got some non-MySQL data to plonk in? |
@@ -1403,8 +1478,9 @@ discard block |
||
1403 | 1478 | { |
1404 | 1479 | $main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END'; |
1405 | 1480 | $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)'; |
1406 | - if (!$createTemporary) |
|
1407 | - $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
1481 | + if (!$createTemporary) { |
|
1482 | + $main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search']; |
|
1483 | + } |
|
1408 | 1484 | } |
1409 | 1485 | } |
1410 | 1486 | |
@@ -1430,14 +1506,15 @@ discard block |
||
1430 | 1506 | ) !== false; |
1431 | 1507 | |
1432 | 1508 | // Clear, all clear! |
1433 | - if (!$createTemporary) |
|
1434 | - $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
1509 | + if (!$createTemporary) { |
|
1510 | + $smcFunc['db_search_query']('delete_log_search_messages', ' |
|
1435 | 1511 | DELETE FROM {db_prefix}log_search_messages |
1436 | 1512 | WHERE id_search = {int:id_search}', |
1437 | 1513 | array( |
1438 | 1514 | 'id_search' => $_SESSION['search_cache']['id_search'], |
1439 | 1515 | ) |
1440 | 1516 | ); |
1517 | + } |
|
1441 | 1518 | |
1442 | 1519 | foreach ($searchWords as $orIndex => $words) |
1443 | 1520 | { |
@@ -1471,19 +1548,21 @@ discard block |
||
1471 | 1548 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1472 | 1549 | { |
1473 | 1550 | // No duplicates! |
1474 | - if (isset($inserts[$row[0]])) |
|
1475 | - continue; |
|
1551 | + if (isset($inserts[$row[0]])) { |
|
1552 | + continue; |
|
1553 | + } |
|
1476 | 1554 | |
1477 | 1555 | $inserts[$row[0]] = $row; |
1478 | 1556 | } |
1479 | 1557 | $smcFunc['db_free_result']($ignoreRequest); |
1480 | 1558 | $indexedResults = count($inserts); |
1559 | + } else { |
|
1560 | + $indexedResults += $smcFunc['db_affected_rows'](); |
|
1481 | 1561 | } |
1482 | - else |
|
1483 | - $indexedResults += $smcFunc['db_affected_rows'](); |
|
1484 | 1562 | |
1485 | - if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) |
|
1486 | - break; |
|
1563 | + if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) { |
|
1564 | + break; |
|
1565 | + } |
|
1487 | 1566 | } |
1488 | 1567 | } |
1489 | 1568 | |
@@ -1503,8 +1582,7 @@ discard block |
||
1503 | 1582 | $context['search_errors']['query_not_specific_enough'] = true; |
1504 | 1583 | $_REQUEST['params'] = $context['params']; |
1505 | 1584 | return PlushSearch1(); |
1506 | - } |
|
1507 | - elseif (!empty($indexedResults)) |
|
1585 | + } elseif (!empty($indexedResults)) |
|
1508 | 1586 | { |
1509 | 1587 | $main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)'; |
1510 | 1588 | if (!$createTemporary) |
@@ -1526,15 +1604,18 @@ discard block |
||
1526 | 1604 | foreach ($words['all_words'] as $regularWord) |
1527 | 1605 | { |
1528 | 1606 | $where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
1529 | - if (in_array($regularWord, $excludedWords)) |
|
1530 | - $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
1607 | + if (in_array($regularWord, $excludedWords)) { |
|
1608 | + $where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}'; |
|
1609 | + } |
|
1531 | 1610 | $main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]'; |
1532 | 1611 | } |
1533 | - if (!empty($where)) |
|
1534 | - $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
1612 | + if (!empty($where)) { |
|
1613 | + $orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0]; |
|
1614 | + } |
|
1615 | + } |
|
1616 | + if (!empty($orWhere)) { |
|
1617 | + $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
1535 | 1618 | } |
1536 | - if (!empty($orWhere)) |
|
1537 | - $main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0]; |
|
1538 | 1619 | |
1539 | 1620 | if (!empty($userQuery)) |
1540 | 1621 | { |
@@ -1572,8 +1653,9 @@ discard block |
||
1572 | 1653 | foreach ($main_query['weights'] as $type => $value) |
1573 | 1654 | { |
1574 | 1655 | $relevance .= $weight[$type]; |
1575 | - if (!empty($value['search'])) |
|
1576 | - $relevance .= ' * ' . $value['search']; |
|
1656 | + if (!empty($value['search'])) { |
|
1657 | + $relevance .= ' * ' . $value['search']; |
|
1658 | + } |
|
1577 | 1659 | $relevance .= ' + '; |
1578 | 1660 | $new_weight_total += $weight[$type]; |
1579 | 1661 | } |
@@ -1604,11 +1686,13 @@ discard block |
||
1604 | 1686 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1605 | 1687 | { |
1606 | 1688 | // No duplicates! |
1607 | - if (isset($inserts[$row[2]])) |
|
1608 | - continue; |
|
1689 | + if (isset($inserts[$row[2]])) { |
|
1690 | + continue; |
|
1691 | + } |
|
1609 | 1692 | |
1610 | - foreach ($row as $key => $value) |
|
1611 | - $inserts[$row[2]][] = (int) $row[$key]; |
|
1693 | + foreach ($row as $key => $value) { |
|
1694 | + $inserts[$row[2]][] = (int) $row[$key]; |
|
1695 | + } |
|
1612 | 1696 | } |
1613 | 1697 | $smcFunc['db_free_result']($ignoreRequest); |
1614 | 1698 | |
@@ -1616,8 +1700,9 @@ discard block |
||
1616 | 1700 | if (!empty($inserts)) |
1617 | 1701 | { |
1618 | 1702 | $query_columns = array(); |
1619 | - foreach ($main_query['select'] as $k => $v) |
|
1620 | - $query_columns[$k] = 'int'; |
|
1703 | + foreach ($main_query['select'] as $k => $v) { |
|
1704 | + $query_columns[$k] = 'int'; |
|
1705 | + } |
|
1621 | 1706 | |
1622 | 1707 | $smcFunc['db_insert']('', |
1623 | 1708 | '{db_prefix}log_search_results', |
@@ -1627,21 +1712,23 @@ discard block |
||
1627 | 1712 | ); |
1628 | 1713 | } |
1629 | 1714 | $_SESSION['search_cache']['num_results'] += count($inserts); |
1715 | + } else { |
|
1716 | + $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
1630 | 1717 | } |
1631 | - else |
|
1632 | - $_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows'](); |
|
1633 | 1718 | } |
1634 | 1719 | |
1635 | 1720 | // Insert subject-only matches. |
1636 | 1721 | if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0) |
1637 | 1722 | { |
1638 | 1723 | $relevance = '1000 * ('; |
1639 | - foreach ($weight_factors as $type => $value) |
|
1640 | - if (isset($value['results'])) |
|
1724 | + foreach ($weight_factors as $type => $value) { |
|
1725 | + if (isset($value['results'])) |
|
1641 | 1726 | { |
1642 | 1727 | $relevance .= $weight[$type]; |
1643 | - if (!empty($value['results'])) |
|
1644 | - $relevance .= ' * ' . $value['results']; |
|
1728 | + } |
|
1729 | + if (!empty($value['results'])) { |
|
1730 | + $relevance .= ' * ' . $value['results']; |
|
1731 | + } |
|
1645 | 1732 | $relevance .= ' + '; |
1646 | 1733 | } |
1647 | 1734 | $relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance'; |
@@ -1675,8 +1762,9 @@ discard block |
||
1675 | 1762 | while ($row = $smcFunc['db_fetch_row']($ignoreRequest)) |
1676 | 1763 | { |
1677 | 1764 | // No duplicates! |
1678 | - if (isset($usedIDs[$row[1]])) |
|
1679 | - continue; |
|
1765 | + if (isset($usedIDs[$row[1]])) { |
|
1766 | + continue; |
|
1767 | + } |
|
1680 | 1768 | |
1681 | 1769 | $usedIDs[$row[1]] = true; |
1682 | 1770 | $inserts[] = $row; |
@@ -1694,12 +1782,12 @@ discard block |
||
1694 | 1782 | ); |
1695 | 1783 | } |
1696 | 1784 | $_SESSION['search_cache']['num_results'] += count($inserts); |
1785 | + } else { |
|
1786 | + $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
1697 | 1787 | } |
1698 | - else |
|
1699 | - $_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows'](); |
|
1788 | + } elseif ($_SESSION['search_cache']['num_results'] == -1) { |
|
1789 | + $_SESSION['search_cache']['num_results'] = 0; |
|
1700 | 1790 | } |
1701 | - elseif ($_SESSION['search_cache']['num_results'] == -1) |
|
1702 | - $_SESSION['search_cache']['num_results'] = 0; |
|
1703 | 1791 | } |
1704 | 1792 | } |
1705 | 1793 | |
@@ -1769,14 +1857,16 @@ discard block |
||
1769 | 1857 | ) |
1770 | 1858 | ); |
1771 | 1859 | $posters = array(); |
1772 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1773 | - $posters[] = $row['id_member']; |
|
1860 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1861 | + $posters[] = $row['id_member']; |
|
1862 | + } |
|
1774 | 1863 | $smcFunc['db_free_result']($request); |
1775 | 1864 | |
1776 | 1865 | call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters)); |
1777 | 1866 | |
1778 | - if (!empty($posters)) |
|
1779 | - loadMemberData(array_unique($posters)); |
|
1867 | + if (!empty($posters)) { |
|
1868 | + loadMemberData(array_unique($posters)); |
|
1869 | + } |
|
1780 | 1870 | |
1781 | 1871 | // Get the messages out for the callback - select enough that it can be made to look just like Display. |
1782 | 1872 | $messages_request = $smcFunc['db_query']('', ' |
@@ -1809,8 +1899,9 @@ discard block |
||
1809 | 1899 | ); |
1810 | 1900 | |
1811 | 1901 | // If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore. |
1812 | - if ($smcFunc['db_num_rows']($messages_request) == 0) |
|
1813 | - $context['topics'] = array(); |
|
1902 | + if ($smcFunc['db_num_rows']($messages_request) == 0) { |
|
1903 | + $context['topics'] = array(); |
|
1904 | + } |
|
1814 | 1905 | |
1815 | 1906 | // If we want to know who participated in what then load this now. |
1816 | 1907 | if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest']) |
@@ -1828,8 +1919,9 @@ discard block |
||
1828 | 1919 | 'limit' => count($participants), |
1829 | 1920 | ) |
1830 | 1921 | ); |
1831 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1832 | - $participants[$row['id_topic']] = true; |
|
1922 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
1923 | + $participants[$row['id_topic']] = true; |
|
1924 | + } |
|
1833 | 1925 | $smcFunc['db_free_result']($result); |
1834 | 1926 | } |
1835 | 1927 | } |
@@ -1838,15 +1930,17 @@ discard block |
||
1838 | 1930 | $context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false); |
1839 | 1931 | |
1840 | 1932 | // Consider the search complete! |
1841 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1842 | - cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
1933 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1934 | + cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90); |
|
1935 | + } |
|
1843 | 1936 | |
1844 | 1937 | $context['key_words'] = &$searchArray; |
1845 | 1938 | |
1846 | 1939 | // Setup the default topic icons... for checking they exist and the like! |
1847 | 1940 | $context['icon_sources'] = array(); |
1848 | - foreach ($context['stable_icons'] as $icon) |
|
1849 | - $context['icon_sources'][$icon] = 'images_url'; |
|
1941 | + foreach ($context['stable_icons'] as $icon) { |
|
1942 | + $context['icon_sources'][$icon] = 'images_url'; |
|
1943 | + } |
|
1850 | 1944 | |
1851 | 1945 | $context['sub_template'] = 'results'; |
1852 | 1946 | $context['page_title'] = $txt['search_results']; |
@@ -1877,26 +1971,31 @@ discard block |
||
1877 | 1971 | global $boards_can, $participants, $smcFunc; |
1878 | 1972 | static $recycle_board = null; |
1879 | 1973 | |
1880 | - if ($recycle_board === null) |
|
1881 | - $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
1974 | + if ($recycle_board === null) { |
|
1975 | + $recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0; |
|
1976 | + } |
|
1882 | 1977 | |
1883 | 1978 | // Remember which message this is. (ie. reply #83) |
1884 | 1979 | static $counter = null; |
1885 | - if ($counter == null || $reset) |
|
1886 | - $counter = $_REQUEST['start'] + 1; |
|
1980 | + if ($counter == null || $reset) { |
|
1981 | + $counter = $_REQUEST['start'] + 1; |
|
1982 | + } |
|
1887 | 1983 | |
1888 | 1984 | // If the query returned false, bail. |
1889 | - if ($messages_request == false) |
|
1890 | - return false; |
|
1985 | + if ($messages_request == false) { |
|
1986 | + return false; |
|
1987 | + } |
|
1891 | 1988 | |
1892 | 1989 | // Start from the beginning... |
1893 | - if ($reset) |
|
1894 | - return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1990 | + if ($reset) { |
|
1991 | + return @$smcFunc['db_data_seek']($messages_request, 0); |
|
1992 | + } |
|
1895 | 1993 | |
1896 | 1994 | // Attempt to get the next message. |
1897 | 1995 | $message = $smcFunc['db_fetch_assoc']($messages_request); |
1898 | - if (!$message) |
|
1899 | - return false; |
|
1996 | + if (!$message) { |
|
1997 | + return false; |
|
1998 | + } |
|
1900 | 1999 | |
1901 | 2000 | // Can't have an empty subject can we? |
1902 | 2001 | $message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject']; |
@@ -1935,9 +2034,9 @@ discard block |
||
1935 | 2034 | |
1936 | 2035 | if ($smcFunc['strlen']($message['body']) > $charLimit) |
1937 | 2036 | { |
1938 | - if (empty($context['key_words'])) |
|
1939 | - $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
1940 | - else |
|
2037 | + if (empty($context['key_words'])) { |
|
2038 | + $message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>'; |
|
2039 | + } else |
|
1941 | 2040 | { |
1942 | 2041 | $matchString = ''; |
1943 | 2042 | $force_partial_word = false; |
@@ -1946,18 +2045,20 @@ discard block |
||
1946 | 2045 | $keyword = un_htmlspecialchars($keyword); |
1947 | 2046 | $keyword = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&'))); |
1948 | 2047 | |
1949 | - if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) |
|
1950 | - $force_partial_word = true; |
|
2048 | + if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) { |
|
2049 | + $force_partial_word = true; |
|
2050 | + } |
|
1951 | 2051 | $matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|'; |
1952 | 2052 | } |
1953 | 2053 | $matchString = un_htmlspecialchars(substr($matchString, 0, -1)); |
1954 | 2054 | |
1955 | 2055 | $message['body'] = un_htmlspecialchars(strtr($message['body'], array(' ' => ' ', '<br>' => "\n", '[' => '[', ']' => ']', ':' => ':', '@' => '@'))); |
1956 | 2056 | |
1957 | - if (empty($modSettings['search_method']) || $force_partial_word) |
|
1958 | - 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); |
|
1959 | - else |
|
1960 | - 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); |
|
2057 | + if (empty($modSettings['search_method']) || $force_partial_word) { |
|
2058 | + 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); |
|
2059 | + } else { |
|
2060 | + 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); |
|
2061 | + } |
|
1961 | 2062 | |
1962 | 2063 | $message['body'] = ''; |
1963 | 2064 | foreach ($matches[0] as $index => $match) |
@@ -1970,8 +2071,7 @@ discard block |
||
1970 | 2071 | // Re-fix the international characters. |
1971 | 2072 | $message['body'] = preg_replace_callback('~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']); |
1972 | 2073 | } |
1973 | - } |
|
1974 | - else |
|
2074 | + } else |
|
1975 | 2075 | { |
1976 | 2076 | // Run BBC interpreter on the message. |
1977 | 2077 | $message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']); |
@@ -1990,21 +2090,26 @@ discard block |
||
1990 | 2090 | // Sadly, we need to check the icon ain't broke. |
1991 | 2091 | if (!empty($modSettings['messageIconChecks_enable'])) |
1992 | 2092 | { |
1993 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
1994 | - $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1995 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
1996 | - $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1997 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
1998 | - $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
1999 | - } |
|
2000 | - else |
|
2093 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
2094 | + $context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2095 | + } |
|
2096 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
2097 | + $context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2098 | + } |
|
2099 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
2100 | + $context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url'; |
|
2101 | + } |
|
2102 | + } else |
|
2001 | 2103 | { |
2002 | - if (!isset($context['icon_sources'][$message['first_icon']])) |
|
2003 | - $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
2004 | - if (!isset($context['icon_sources'][$message['last_icon']])) |
|
2005 | - $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
2006 | - if (!isset($context['icon_sources'][$message['icon']])) |
|
2007 | - $context['icon_sources'][$message['icon']] = 'images_url'; |
|
2104 | + if (!isset($context['icon_sources'][$message['first_icon']])) { |
|
2105 | + $context['icon_sources'][$message['first_icon']] = 'images_url'; |
|
2106 | + } |
|
2107 | + if (!isset($context['icon_sources'][$message['last_icon']])) { |
|
2108 | + $context['icon_sources'][$message['last_icon']] = 'images_url'; |
|
2109 | + } |
|
2110 | + if (!isset($context['icon_sources'][$message['icon']])) { |
|
2111 | + $context['icon_sources'][$message['icon']] = 'images_url'; |
|
2112 | + } |
|
2008 | 2113 | } |
2009 | 2114 | |
2010 | 2115 | // Do we have quote tag enabled? |
@@ -2014,12 +2119,14 @@ discard block |
||
2014 | 2119 | $colorClass = 'windowbg'; |
2015 | 2120 | |
2016 | 2121 | // Sticky topics should get a different color, too. |
2017 | - if ($message['is_sticky']) |
|
2018 | - $colorClass .= ' sticky'; |
|
2122 | + if ($message['is_sticky']) { |
|
2123 | + $colorClass .= ' sticky'; |
|
2124 | + } |
|
2019 | 2125 | |
2020 | 2126 | // Locked topics get special treatment as well. |
2021 | - if ($message['locked']) |
|
2022 | - $colorClass .= ' locked'; |
|
2127 | + if ($message['locked']) { |
|
2128 | + $colorClass .= ' locked'; |
|
2129 | + } |
|
2023 | 2130 | |
2024 | 2131 | $output = array_merge($context['topics'][$message['id_msg']], array( |
2025 | 2132 | 'id' => $message['id_topic'], |
@@ -2113,8 +2220,9 @@ discard block |
||
2113 | 2220 | $query = strtr($smcFunc['htmlspecialchars']($query), array('\\\'' => '\'')); |
2114 | 2221 | |
2115 | 2222 | // Highlighting empty strings would make a terrible mess... |
2116 | - if (strlen($query) == 0) |
|
2117 | - continue; |
|
2223 | + if (strlen($query) == 0) { |
|
2224 | + continue; |
|
2225 | + } |
|
2118 | 2226 | |
2119 | 2227 | $body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => ''')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function ($m) |
2120 | 2228 | { |
@@ -2167,8 +2275,9 @@ discard block |
||
2167 | 2275 | |
2168 | 2276 | // Load up the search API we are going to use. |
2169 | 2277 | $modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index']; |
2170 | - if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) |
|
2171 | - fatal_lang_error('search_api_missing'); |
|
2278 | + if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) { |
|
2279 | + fatal_lang_error('search_api_missing'); |
|
2280 | + } |
|
2172 | 2281 | require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'); |
2173 | 2282 | |
2174 | 2283 | // Create an instance of the search API and check it is valid for this version of SMF. |