@@ -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. |
@@ -1270,8 +1327,9 @@ discard block |
||
1270 | 1327 | if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
1271 | 1328 | { |
1272 | 1329 | $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2); |
1273 | - if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) |
|
1274 | - $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
1330 | + if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) { |
|
1331 | + $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
1332 | + } |
|
1275 | 1333 | |
1276 | 1334 | if ($socket) |
1277 | 1335 | { |
@@ -1293,11 +1351,13 @@ discard block |
||
1293 | 1351 | if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) |
1294 | 1352 | { |
1295 | 1353 | // ssl:hostname can cause fsocketopen to fail with a lookup failure, ensure it exists for this test. |
1296 | - if (substr($modSettings['smtp_host'], 0, 6) != 'ssl://') |
|
1297 | - $modSettings['smtp_host'] = str_replace('ssl:', 'ss://', $modSettings['smtp_host']); |
|
1354 | + if (substr($modSettings['smtp_host'], 0, 6) != 'ssl://') { |
|
1355 | + $modSettings['smtp_host'] = str_replace('ssl:', 'ss://', $modSettings['smtp_host']); |
|
1356 | + } |
|
1298 | 1357 | |
1299 | - if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) |
|
1300 | - log_error($txt['smtp_port_ssl']); |
|
1358 | + if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) { |
|
1359 | + log_error($txt['smtp_port_ssl']); |
|
1360 | + } |
|
1301 | 1361 | } |
1302 | 1362 | |
1303 | 1363 | // Unable to connect! Don't show any error message, but just log one and try to continue anyway. |
@@ -1309,26 +1369,30 @@ discard block |
||
1309 | 1369 | } |
1310 | 1370 | |
1311 | 1371 | // Wait for a response of 220, without "-" continuer. |
1312 | - if (!server_parse(null, $socket, '220')) |
|
1313 | - return false; |
|
1372 | + if (!server_parse(null, $socket, '220')) { |
|
1373 | + return false; |
|
1374 | + } |
|
1314 | 1375 | |
1315 | 1376 | // Try to determine the server's fully qualified domain name |
1316 | 1377 | // Can't rely on $_SERVER['SERVER_NAME'] because it can be spoofed on Apache |
1317 | 1378 | if (empty($helo)) |
1318 | 1379 | { |
1319 | 1380 | // See if we can get the domain name from the host itself |
1320 | - if (function_exists('gethostname')) |
|
1321 | - $helo = gethostname(); |
|
1322 | - elseif (function_exists('php_uname')) |
|
1323 | - $helo = php_uname('n'); |
|
1381 | + if (function_exists('gethostname')) { |
|
1382 | + $helo = gethostname(); |
|
1383 | + } elseif (function_exists('php_uname')) { |
|
1384 | + $helo = php_uname('n'); |
|
1385 | + } |
|
1324 | 1386 | |
1325 | 1387 | // If the hostname isn't a fully qualified domain name, we can use the host name from $boardurl instead |
1326 | - if (empty($helo) || strpos($helo, '.') === false || substr_compare($helo, '.local', -6) === 0 || (!empty($modSettings['tld_regex']) && !preg_match('/\.' . $modSettings['tld_regex'] . '$/u', $helo))) |
|
1327 | - $helo = parse_url($boardurl, PHP_URL_HOST); |
|
1388 | + if (empty($helo) || strpos($helo, '.') === false || substr_compare($helo, '.local', -6) === 0 || (!empty($modSettings['tld_regex']) && !preg_match('/\.' . $modSettings['tld_regex'] . '$/u', $helo))) { |
|
1389 | + $helo = parse_url($boardurl, PHP_URL_HOST); |
|
1390 | + } |
|
1328 | 1391 | |
1329 | 1392 | // This is one of those situations where 'www.' is undesirable |
1330 | - if (strpos($helo, 'www.') === 0) |
|
1331 | - $helo = substr($helo, 4); |
|
1393 | + if (strpos($helo, 'www.') === 0) { |
|
1394 | + $helo = substr($helo, 4); |
|
1395 | + } |
|
1332 | 1396 | } |
1333 | 1397 | |
1334 | 1398 | // SMTP = 1, SMTP - STARTTLS = 2 |
@@ -1341,8 +1405,9 @@ discard block |
||
1341 | 1405 | if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response)) |
1342 | 1406 | { |
1343 | 1407 | // Send STARTTLS to enable encryption |
1344 | - if (!server_parse('STARTTLS', $socket, '220')) |
|
1345 | - return false; |
|
1408 | + if (!server_parse('STARTTLS', $socket, '220')) { |
|
1409 | + return false; |
|
1410 | + } |
|
1346 | 1411 | // Enable the encryption |
1347 | 1412 | // php 5.6+ fix |
1348 | 1413 | $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; |
@@ -1353,30 +1418,35 @@ discard block |
||
1353 | 1418 | $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT; |
1354 | 1419 | } |
1355 | 1420 | |
1356 | - if (!@stream_socket_enable_crypto($socket, true, $crypto_method)) |
|
1357 | - return false; |
|
1421 | + if (!@stream_socket_enable_crypto($socket, true, $crypto_method)) { |
|
1422 | + return false; |
|
1423 | + } |
|
1358 | 1424 | // Send the EHLO command again |
1359 | - if (!server_parse('EHLO ' . $helo, $socket, null) == '250') |
|
1360 | - return false; |
|
1425 | + if (!server_parse('EHLO ' . $helo, $socket, null) == '250') { |
|
1426 | + return false; |
|
1427 | + } |
|
1361 | 1428 | } |
1362 | 1429 | |
1363 | - if (!server_parse('AUTH LOGIN', $socket, '334')) |
|
1364 | - return false; |
|
1430 | + if (!server_parse('AUTH LOGIN', $socket, '334')) { |
|
1431 | + return false; |
|
1432 | + } |
|
1365 | 1433 | // Send the username and password, encoded. |
1366 | - if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) |
|
1367 | - return false; |
|
1434 | + if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) { |
|
1435 | + return false; |
|
1436 | + } |
|
1368 | 1437 | // The password is already encoded ;) |
1369 | - if (!server_parse($modSettings['smtp_password'], $socket, '235')) |
|
1370 | - return false; |
|
1438 | + if (!server_parse($modSettings['smtp_password'], $socket, '235')) { |
|
1439 | + return false; |
|
1440 | + } |
|
1441 | + } elseif (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1442 | + return false; |
|
1371 | 1443 | } |
1372 | - elseif (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1373 | - return false; |
|
1374 | - } |
|
1375 | - else |
|
1444 | + } else |
|
1376 | 1445 | { |
1377 | 1446 | // Just say "helo". |
1378 | - if (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1379 | - return false; |
|
1447 | + if (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1448 | + return false; |
|
1449 | + } |
|
1380 | 1450 | } |
1381 | 1451 | |
1382 | 1452 | // Fix the message for any lines beginning with a period! (the first is ignored, you see.) |
@@ -1389,31 +1459,38 @@ discard block |
||
1389 | 1459 | // Reset the connection to send another email. |
1390 | 1460 | if ($i != 0) |
1391 | 1461 | { |
1392 | - if (!server_parse('RSET', $socket, '250')) |
|
1393 | - return false; |
|
1462 | + if (!server_parse('RSET', $socket, '250')) { |
|
1463 | + return false; |
|
1464 | + } |
|
1394 | 1465 | } |
1395 | 1466 | |
1396 | 1467 | // From, to, and then start the data... |
1397 | - if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) |
|
1398 | - return false; |
|
1399 | - if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) |
|
1400 | - return false; |
|
1401 | - if (!server_parse('DATA', $socket, '354')) |
|
1402 | - return false; |
|
1468 | + if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) { |
|
1469 | + return false; |
|
1470 | + } |
|
1471 | + if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) { |
|
1472 | + return false; |
|
1473 | + } |
|
1474 | + if (!server_parse('DATA', $socket, '354')) { |
|
1475 | + return false; |
|
1476 | + } |
|
1403 | 1477 | fputs($socket, 'Subject: ' . $subject . "\r\n"); |
1404 | - if (strlen($mail_to) > 0) |
|
1405 | - fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1478 | + if (strlen($mail_to) > 0) { |
|
1479 | + fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1480 | + } |
|
1406 | 1481 | fputs($socket, $headers . "\r\n\r\n"); |
1407 | 1482 | fputs($socket, $message . "\r\n"); |
1408 | 1483 | |
1409 | 1484 | // Send a ., or in other words "end of data". |
1410 | - if (!server_parse('.', $socket, '250')) |
|
1411 | - return false; |
|
1485 | + if (!server_parse('.', $socket, '250')) { |
|
1486 | + return false; |
|
1487 | + } |
|
1412 | 1488 | |
1413 | 1489 | // Almost done, almost done... don't stop me just yet! |
1414 | 1490 | @set_time_limit(300); |
1415 | - if (function_exists('apache_reset_timeout')) |
|
1416 | - @apache_reset_timeout(); |
|
1491 | + if (function_exists('apache_reset_timeout')) { |
|
1492 | + @apache_reset_timeout(); |
|
1493 | + } |
|
1417 | 1494 | } |
1418 | 1495 | fputs($socket, 'QUIT' . "\r\n"); |
1419 | 1496 | fclose($socket); |
@@ -1437,8 +1514,9 @@ discard block |
||
1437 | 1514 | { |
1438 | 1515 | global $txt; |
1439 | 1516 | |
1440 | - if ($message !== null) |
|
1441 | - fputs($socket, $message . "\r\n"); |
|
1517 | + if ($message !== null) { |
|
1518 | + fputs($socket, $message . "\r\n"); |
|
1519 | + } |
|
1442 | 1520 | |
1443 | 1521 | // No response yet. |
1444 | 1522 | $server_response = ''; |
@@ -1454,8 +1532,9 @@ discard block |
||
1454 | 1532 | $response .= $server_response; |
1455 | 1533 | } |
1456 | 1534 | |
1457 | - if ($code === null) |
|
1458 | - return substr($server_response, 0, 3); |
|
1535 | + if ($code === null) { |
|
1536 | + return substr($server_response, 0, 3); |
|
1537 | + } |
|
1459 | 1538 | |
1460 | 1539 | if (substr($server_response, 0, 3) != $code) |
1461 | 1540 | { |
@@ -1485,8 +1564,9 @@ discard block |
||
1485 | 1564 | // Create a pspell or enchant dictionary resource |
1486 | 1565 | $dict = spell_init(); |
1487 | 1566 | |
1488 | - if (!isset($_POST['spellstring']) || !$dict) |
|
1489 | - die; |
|
1567 | + if (!isset($_POST['spellstring']) || !$dict) { |
|
1568 | + die; |
|
1569 | + } |
|
1490 | 1570 | |
1491 | 1571 | // Construct a bit of Javascript code. |
1492 | 1572 | $context['spell_js'] = ' |
@@ -1504,8 +1584,9 @@ discard block |
||
1504 | 1584 | $check_word = explode('|', $alphas[$i]); |
1505 | 1585 | |
1506 | 1586 | // If the word is a known word, or spelled right... |
1507 | - if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) |
|
1508 | - continue; |
|
1587 | + if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) { |
|
1588 | + continue; |
|
1589 | + } |
|
1509 | 1590 | |
1510 | 1591 | // Find the word, and move up the "last occurrence" to here. |
1511 | 1592 | $found_words = true; |
@@ -1519,20 +1600,23 @@ discard block |
||
1519 | 1600 | if (!empty($suggestions)) |
1520 | 1601 | { |
1521 | 1602 | // But first check they aren't going to be censored - no naughty words! |
1522 | - foreach ($suggestions as $k => $word) |
|
1523 | - if ($suggestions[$k] != censorText($word)) |
|
1603 | + foreach ($suggestions as $k => $word) { |
|
1604 | + if ($suggestions[$k] != censorText($word)) |
|
1524 | 1605 | unset($suggestions[$k]); |
1606 | + } |
|
1525 | 1607 | |
1526 | - if (!empty($suggestions)) |
|
1527 | - $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1608 | + if (!empty($suggestions)) { |
|
1609 | + $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1610 | + } |
|
1528 | 1611 | } |
1529 | 1612 | |
1530 | 1613 | $context['spell_js'] .= ']),'; |
1531 | 1614 | } |
1532 | 1615 | |
1533 | 1616 | // If words were found, take off the last comma. |
1534 | - if ($found_words) |
|
1535 | - $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1617 | + if ($found_words) { |
|
1618 | + $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1619 | + } |
|
1536 | 1620 | |
1537 | 1621 | $context['spell_js'] .= ' |
1538 | 1622 | );'; |
@@ -1567,11 +1651,13 @@ discard block |
||
1567 | 1651 | global $user_info, $smcFunc; |
1568 | 1652 | |
1569 | 1653 | // Can't do it if there's no topics. |
1570 | - if (empty($topics)) |
|
1571 | - return; |
|
1654 | + if (empty($topics)) { |
|
1655 | + return; |
|
1656 | + } |
|
1572 | 1657 | // It must be an array - it must! |
1573 | - if (!is_array($topics)) |
|
1574 | - $topics = array($topics); |
|
1658 | + if (!is_array($topics)) { |
|
1659 | + $topics = array($topics); |
|
1660 | + } |
|
1575 | 1661 | |
1576 | 1662 | // Get the subject and body... |
1577 | 1663 | $result = $smcFunc['db_query']('', ' |
@@ -1619,14 +1705,15 @@ discard block |
||
1619 | 1705 | } |
1620 | 1706 | $smcFunc['db_free_result']($result); |
1621 | 1707 | |
1622 | - if (!empty($task_rows)) |
|
1623 | - $smcFunc['db_insert']('', |
|
1708 | + if (!empty($task_rows)) { |
|
1709 | + $smcFunc['db_insert']('', |
|
1624 | 1710 | '{db_prefix}background_tasks', |
1625 | 1711 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1626 | 1712 | $task_rows, |
1627 | 1713 | array('id_task') |
1628 | 1714 | ); |
1629 | -} |
|
1715 | + } |
|
1716 | + } |
|
1630 | 1717 | |
1631 | 1718 | /** |
1632 | 1719 | * Create a post, either as new topic (id_topic = 0) or in an existing one. |
@@ -1664,9 +1751,9 @@ discard block |
||
1664 | 1751 | $msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true; |
1665 | 1752 | |
1666 | 1753 | // We need to know if the topic is approved. If we're told that's great - if not find out. |
1667 | - if (!$modSettings['postmod_active']) |
|
1668 | - $topicOptions['is_approved'] = true; |
|
1669 | - elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1754 | + if (!$modSettings['postmod_active']) { |
|
1755 | + $topicOptions['is_approved'] = true; |
|
1756 | + } elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1670 | 1757 | { |
1671 | 1758 | $request = $smcFunc['db_query']('', ' |
1672 | 1759 | SELECT approved |
@@ -1689,8 +1776,7 @@ discard block |
||
1689 | 1776 | $posterOptions['id'] = 0; |
1690 | 1777 | $posterOptions['name'] = $txt['guest_title']; |
1691 | 1778 | $posterOptions['email'] = ''; |
1692 | - } |
|
1693 | - elseif ($posterOptions['id'] != $user_info['id']) |
|
1779 | + } elseif ($posterOptions['id'] != $user_info['id']) |
|
1694 | 1780 | { |
1695 | 1781 | $request = $smcFunc['db_query']('', ' |
1696 | 1782 | SELECT member_name, email_address |
@@ -1708,12 +1794,11 @@ discard block |
||
1708 | 1794 | $posterOptions['id'] = 0; |
1709 | 1795 | $posterOptions['name'] = $txt['guest_title']; |
1710 | 1796 | $posterOptions['email'] = ''; |
1797 | + } else { |
|
1798 | + list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1711 | 1799 | } |
1712 | - else |
|
1713 | - list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1714 | 1800 | $smcFunc['db_free_result']($request); |
1715 | - } |
|
1716 | - else |
|
1801 | + } else |
|
1717 | 1802 | { |
1718 | 1803 | $posterOptions['name'] = $user_info['name']; |
1719 | 1804 | $posterOptions['email'] = $user_info['email']; |
@@ -1723,8 +1808,9 @@ discard block |
||
1723 | 1808 | if (!empty($modSettings['enable_mentions'])) |
1724 | 1809 | { |
1725 | 1810 | $msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']); |
1726 | - if (!empty($msgOptions['mentioned_members'])) |
|
1727 | - $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1811 | + if (!empty($msgOptions['mentioned_members'])) { |
|
1812 | + $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1813 | + } |
|
1728 | 1814 | } |
1729 | 1815 | |
1730 | 1816 | // It's do or die time: forget any user aborts! |
@@ -1757,12 +1843,13 @@ discard block |
||
1757 | 1843 | ); |
1758 | 1844 | |
1759 | 1845 | // Something went wrong creating the message... |
1760 | - if (empty($msgOptions['id'])) |
|
1761 | - return false; |
|
1846 | + if (empty($msgOptions['id'])) { |
|
1847 | + return false; |
|
1848 | + } |
|
1762 | 1849 | |
1763 | 1850 | // Fix the attachments. |
1764 | - if (!empty($msgOptions['attachments'])) |
|
1765 | - $smcFunc['db_query']('', ' |
|
1851 | + if (!empty($msgOptions['attachments'])) { |
|
1852 | + $smcFunc['db_query']('', ' |
|
1766 | 1853 | UPDATE {db_prefix}attachments |
1767 | 1854 | SET id_msg = {int:id_msg} |
1768 | 1855 | WHERE id_attach IN ({array_int:attachment_list})', |
@@ -1771,6 +1858,7 @@ discard block |
||
1771 | 1858 | 'id_msg' => $msgOptions['id'], |
1772 | 1859 | ) |
1773 | 1860 | ); |
1861 | + } |
|
1774 | 1862 | |
1775 | 1863 | // What if we want to export new posts out to a CMS? |
1776 | 1864 | call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters)); |
@@ -1847,20 +1935,23 @@ discard block |
||
1847 | 1935 | 'id_topic' => $topicOptions['id'], |
1848 | 1936 | 'counter_increment' => 1, |
1849 | 1937 | ); |
1850 | - if ($msgOptions['approved']) |
|
1851 | - $topics_columns = array( |
|
1938 | + if ($msgOptions['approved']) { |
|
1939 | + $topics_columns = array( |
|
1852 | 1940 | 'id_member_updated = {int:poster_id}', |
1853 | 1941 | 'id_last_msg = {int:id_msg}', |
1854 | 1942 | 'num_replies = num_replies + {int:counter_increment}', |
1855 | 1943 | ); |
1856 | - else |
|
1857 | - $topics_columns = array( |
|
1944 | + } else { |
|
1945 | + $topics_columns = array( |
|
1858 | 1946 | 'unapproved_posts = unapproved_posts + {int:counter_increment}', |
1859 | 1947 | ); |
1860 | - if ($topicOptions['lock_mode'] !== null) |
|
1861 | - $topics_columns[] = 'locked = {int:locked}'; |
|
1862 | - if ($topicOptions['sticky_mode'] !== null) |
|
1863 | - $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1948 | + } |
|
1949 | + if ($topicOptions['lock_mode'] !== null) { |
|
1950 | + $topics_columns[] = 'locked = {int:locked}'; |
|
1951 | + } |
|
1952 | + if ($topicOptions['sticky_mode'] !== null) { |
|
1953 | + $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1954 | + } |
|
1864 | 1955 | |
1865 | 1956 | call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions)); |
1866 | 1957 | |
@@ -1889,8 +1980,8 @@ discard block |
||
1889 | 1980 | ); |
1890 | 1981 | |
1891 | 1982 | // Increase the number of posts and topics on the board. |
1892 | - if ($msgOptions['approved']) |
|
1893 | - $smcFunc['db_query']('', ' |
|
1983 | + if ($msgOptions['approved']) { |
|
1984 | + $smcFunc['db_query']('', ' |
|
1894 | 1985 | UPDATE {db_prefix}boards |
1895 | 1986 | SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . ' |
1896 | 1987 | WHERE id_board = {int:id_board}', |
@@ -1898,7 +1989,7 @@ discard block |
||
1898 | 1989 | 'id_board' => $topicOptions['board'], |
1899 | 1990 | ) |
1900 | 1991 | ); |
1901 | - else |
|
1992 | + } else |
|
1902 | 1993 | { |
1903 | 1994 | $smcFunc['db_query']('', ' |
1904 | 1995 | UPDATE {db_prefix}boards |
@@ -1968,8 +2059,8 @@ discard block |
||
1968 | 2059 | } |
1969 | 2060 | } |
1970 | 2061 | |
1971 | - if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) |
|
1972 | - $smcFunc['db_insert']('', |
|
2062 | + if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) { |
|
2063 | + $smcFunc['db_insert']('', |
|
1973 | 2064 | '{db_prefix}background_tasks', |
1974 | 2065 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1975 | 2066 | array( |
@@ -1981,19 +2072,22 @@ discard block |
||
1981 | 2072 | ), |
1982 | 2073 | array('id_task') |
1983 | 2074 | ); |
2075 | + } |
|
1984 | 2076 | |
1985 | 2077 | // If there's a custom search index, it may need updating... |
1986 | 2078 | require_once($sourcedir . '/Search.php'); |
1987 | 2079 | $searchAPI = findSearchAPI(); |
1988 | - if (is_callable(array($searchAPI, 'postCreated'))) |
|
1989 | - $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2080 | + if (is_callable(array($searchAPI, 'postCreated'))) { |
|
2081 | + $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2082 | + } |
|
1990 | 2083 | |
1991 | 2084 | // Increase the post counter for the user that created the post. |
1992 | 2085 | if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved']) |
1993 | 2086 | { |
1994 | 2087 | // Are you the one that happened to create this post? |
1995 | - if ($user_info['id'] == $posterOptions['id']) |
|
1996 | - $user_info['posts']++; |
|
2088 | + if ($user_info['id'] == $posterOptions['id']) { |
|
2089 | + $user_info['posts']++; |
|
2090 | + } |
|
1997 | 2091 | updateMemberData($posterOptions['id'], array('posts' => '+')); |
1998 | 2092 | } |
1999 | 2093 | |
@@ -2001,19 +2095,21 @@ discard block |
||
2001 | 2095 | $_SESSION['last_read_topic'] = 0; |
2002 | 2096 | |
2003 | 2097 | // Better safe than sorry. |
2004 | - if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) |
|
2005 | - $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2098 | + if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) { |
|
2099 | + $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2100 | + } |
|
2006 | 2101 | |
2007 | 2102 | // Update all the stats so everyone knows about this new topic and message. |
2008 | 2103 | updateStats('message', true, $msgOptions['id']); |
2009 | 2104 | |
2010 | 2105 | // Update the last message on the board assuming it's approved AND the topic is. |
2011 | - if ($msgOptions['approved']) |
|
2012 | - updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2106 | + if ($msgOptions['approved']) { |
|
2107 | + updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2108 | + } |
|
2013 | 2109 | |
2014 | 2110 | // Queue createPost background notification |
2015 | - if ($msgOptions['send_notifications'] && $msgOptions['approved']) |
|
2016 | - $smcFunc['db_insert']('', |
|
2111 | + if ($msgOptions['send_notifications'] && $msgOptions['approved']) { |
|
2112 | + $smcFunc['db_insert']('', |
|
2017 | 2113 | '{db_prefix}background_tasks', |
2018 | 2114 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2019 | 2115 | array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array( |
@@ -2024,6 +2120,7 @@ discard block |
||
2024 | 2120 | )), 0), |
2025 | 2121 | array('id_task') |
2026 | 2122 | ); |
2123 | + } |
|
2027 | 2124 | |
2028 | 2125 | // Alright, done now... we can abort now, I guess... at least this much is done. |
2029 | 2126 | ignore_user_abort($previous_ignore_user_abort); |
@@ -2050,14 +2147,18 @@ discard block |
||
2050 | 2147 | |
2051 | 2148 | // This is longer than it has to be, but makes it so we only set/change what we have to. |
2052 | 2149 | $messages_columns = array(); |
2053 | - if (isset($posterOptions['name'])) |
|
2054 | - $messages_columns['poster_name'] = $posterOptions['name']; |
|
2055 | - if (isset($posterOptions['email'])) |
|
2056 | - $messages_columns['poster_email'] = $posterOptions['email']; |
|
2057 | - if (isset($msgOptions['icon'])) |
|
2058 | - $messages_columns['icon'] = $msgOptions['icon']; |
|
2059 | - if (isset($msgOptions['subject'])) |
|
2060 | - $messages_columns['subject'] = $msgOptions['subject']; |
|
2150 | + if (isset($posterOptions['name'])) { |
|
2151 | + $messages_columns['poster_name'] = $posterOptions['name']; |
|
2152 | + } |
|
2153 | + if (isset($posterOptions['email'])) { |
|
2154 | + $messages_columns['poster_email'] = $posterOptions['email']; |
|
2155 | + } |
|
2156 | + if (isset($msgOptions['icon'])) { |
|
2157 | + $messages_columns['icon'] = $msgOptions['icon']; |
|
2158 | + } |
|
2159 | + if (isset($msgOptions['subject'])) { |
|
2160 | + $messages_columns['subject'] = $msgOptions['subject']; |
|
2161 | + } |
|
2061 | 2162 | if (isset($msgOptions['body'])) |
2062 | 2163 | { |
2063 | 2164 | $messages_columns['body'] = $msgOptions['body']; |
@@ -2084,8 +2185,9 @@ discard block |
||
2084 | 2185 | $messages_columns['modified_reason'] = $msgOptions['modify_reason']; |
2085 | 2186 | $messages_columns['id_msg_modified'] = $modSettings['maxMsgID']; |
2086 | 2187 | } |
2087 | - if (isset($msgOptions['smileys_enabled'])) |
|
2088 | - $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2188 | + if (isset($msgOptions['smileys_enabled'])) { |
|
2189 | + $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2190 | + } |
|
2089 | 2191 | |
2090 | 2192 | // Which columns need to be ints? |
2091 | 2193 | $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled'); |
@@ -2096,8 +2198,9 @@ discard block |
||
2096 | 2198 | // Update search api |
2097 | 2199 | require_once($sourcedir . '/Search.php'); |
2098 | 2200 | $searchAPI = findSearchAPI(); |
2099 | - if ($searchAPI->supportsMethod('postRemoved')) |
|
2100 | - $searchAPI->postRemoved($msgOptions['id']); |
|
2201 | + if ($searchAPI->supportsMethod('postRemoved')) { |
|
2202 | + $searchAPI->postRemoved($msgOptions['id']); |
|
2203 | + } |
|
2101 | 2204 | |
2102 | 2205 | if (!empty($modSettings['enable_mentions']) && isset($msgOptions['body'])) |
2103 | 2206 | { |
@@ -2109,23 +2212,27 @@ discard block |
||
2109 | 2212 | { |
2110 | 2213 | preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match); |
2111 | 2214 | |
2112 | - if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) |
|
2113 | - foreach ($match[1] as $i => $oldID) |
|
2215 | + if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) { |
|
2216 | + foreach ($match[1] as $i => $oldID) |
|
2114 | 2217 | $oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]); |
2218 | + } |
|
2115 | 2219 | |
2116 | - if (empty($modSettings['search_custom_index_config'])) |
|
2117 | - unset($msgOptions['old_body']); |
|
2220 | + if (empty($modSettings['search_custom_index_config'])) { |
|
2221 | + unset($msgOptions['old_body']); |
|
2222 | + } |
|
2118 | 2223 | } |
2119 | 2224 | |
2120 | 2225 | $mentions = Mentions::getMentionedMembers($msgOptions['body']); |
2121 | 2226 | $messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions); |
2122 | 2227 | |
2123 | 2228 | // Remove the poster. |
2124 | - if (isset($mentions[$user_info['id']])) |
|
2125 | - unset($mentions[$user_info['id']]); |
|
2229 | + if (isset($mentions[$user_info['id']])) { |
|
2230 | + unset($mentions[$user_info['id']]); |
|
2231 | + } |
|
2126 | 2232 | |
2127 | - if (isset($oldmentions[$user_info['id']])) |
|
2128 | - unset($oldmentions[$user_info['id']]); |
|
2233 | + if (isset($oldmentions[$user_info['id']])) { |
|
2234 | + unset($oldmentions[$user_info['id']]); |
|
2235 | + } |
|
2129 | 2236 | |
2130 | 2237 | if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions)) |
2131 | 2238 | { |
@@ -2155,8 +2262,9 @@ discard block |
||
2155 | 2262 | } |
2156 | 2263 | |
2157 | 2264 | // Nothing to do? |
2158 | - if (empty($messages_columns)) |
|
2159 | - return true; |
|
2265 | + if (empty($messages_columns)) { |
|
2266 | + return true; |
|
2267 | + } |
|
2160 | 2268 | |
2161 | 2269 | // Change the post. |
2162 | 2270 | $smcFunc['db_query']('', ' |
@@ -2217,8 +2325,9 @@ discard block |
||
2217 | 2325 | // If there's a custom search index, it needs to be modified... |
2218 | 2326 | require_once($sourcedir . '/Search.php'); |
2219 | 2327 | $searchAPI = findSearchAPI(); |
2220 | - if (is_callable(array($searchAPI, 'postModified'))) |
|
2221 | - $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2328 | + if (is_callable(array($searchAPI, 'postModified'))) { |
|
2329 | + $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2330 | + } |
|
2222 | 2331 | |
2223 | 2332 | if (isset($msgOptions['subject'])) |
2224 | 2333 | { |
@@ -2232,14 +2341,16 @@ discard block |
||
2232 | 2341 | 'id_first_msg' => $msgOptions['id'], |
2233 | 2342 | ) |
2234 | 2343 | ); |
2235 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
2236 | - updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2344 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
2345 | + updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2346 | + } |
|
2237 | 2347 | $smcFunc['db_free_result']($request); |
2238 | 2348 | } |
2239 | 2349 | |
2240 | 2350 | // Finally, if we are setting the approved state we need to do much more work :( |
2241 | - if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) |
|
2242 | - approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2351 | + if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) { |
|
2352 | + approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2353 | + } |
|
2243 | 2354 | |
2244 | 2355 | return true; |
2245 | 2356 | } |
@@ -2256,11 +2367,13 @@ discard block |
||
2256 | 2367 | { |
2257 | 2368 | global $smcFunc; |
2258 | 2369 | |
2259 | - if (!is_array($msgs)) |
|
2260 | - $msgs = array($msgs); |
|
2370 | + if (!is_array($msgs)) { |
|
2371 | + $msgs = array($msgs); |
|
2372 | + } |
|
2261 | 2373 | |
2262 | - if (empty($msgs)) |
|
2263 | - return false; |
|
2374 | + if (empty($msgs)) { |
|
2375 | + return false; |
|
2376 | + } |
|
2264 | 2377 | |
2265 | 2378 | // May as well start at the beginning, working out *what* we need to change. |
2266 | 2379 | $request = $smcFunc['db_query']('', ' |
@@ -2292,20 +2405,22 @@ discard block |
||
2292 | 2405 | $topics[] = $row['id_topic']; |
2293 | 2406 | |
2294 | 2407 | // Ensure our change array exists already. |
2295 | - if (!isset($topic_changes[$row['id_topic']])) |
|
2296 | - $topic_changes[$row['id_topic']] = array( |
|
2408 | + if (!isset($topic_changes[$row['id_topic']])) { |
|
2409 | + $topic_changes[$row['id_topic']] = array( |
|
2297 | 2410 | 'id_last_msg' => $row['id_last_msg'], |
2298 | 2411 | 'approved' => $row['topic_approved'], |
2299 | 2412 | 'replies' => 0, |
2300 | 2413 | 'unapproved_posts' => 0, |
2301 | 2414 | ); |
2302 | - if (!isset($board_changes[$row['id_board']])) |
|
2303 | - $board_changes[$row['id_board']] = array( |
|
2415 | + } |
|
2416 | + if (!isset($board_changes[$row['id_board']])) { |
|
2417 | + $board_changes[$row['id_board']] = array( |
|
2304 | 2418 | 'posts' => 0, |
2305 | 2419 | 'topics' => 0, |
2306 | 2420 | 'unapproved_posts' => 0, |
2307 | 2421 | 'unapproved_topics' => 0, |
2308 | 2422 | ); |
2423 | + } |
|
2309 | 2424 | |
2310 | 2425 | // If it's the first message then the topic state changes! |
2311 | 2426 | if ($row['id_msg'] == $row['id_first_msg']) |
@@ -2326,14 +2441,13 @@ discard block |
||
2326 | 2441 | 'poster' => $row['id_member'], |
2327 | 2442 | 'new_topic' => true, |
2328 | 2443 | ); |
2329 | - } |
|
2330 | - else |
|
2444 | + } else |
|
2331 | 2445 | { |
2332 | 2446 | $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1; |
2333 | 2447 | |
2334 | 2448 | // This will be a post... but don't notify unless it's not followed by approved ones. |
2335 | - if ($row['id_msg'] > $row['id_last_msg']) |
|
2336 | - $notification_posts[$row['id_topic']] = array( |
|
2449 | + if ($row['id_msg'] > $row['id_last_msg']) { |
|
2450 | + $notification_posts[$row['id_topic']] = array( |
|
2337 | 2451 | 'id' => $row['id_msg'], |
2338 | 2452 | 'body' => $row['body'], |
2339 | 2453 | 'subject' => $row['subject'], |
@@ -2344,28 +2458,33 @@ discard block |
||
2344 | 2458 | 'new_topic' => false, |
2345 | 2459 | 'msg' => $row['id_msg'], |
2346 | 2460 | ); |
2461 | + } |
|
2347 | 2462 | } |
2348 | 2463 | |
2349 | 2464 | // If this is being approved and id_msg is higher than the current id_last_msg then it changes. |
2350 | - if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) |
|
2351 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2465 | + if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) { |
|
2466 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2467 | + } |
|
2352 | 2468 | // If this is being unapproved, and it's equal to the id_last_msg we need to find a new one! |
2353 | - elseif (!$approve) |
|
2354 | - // Default to the first message and then we'll override in a bit ;) |
|
2469 | + elseif (!$approve) { |
|
2470 | + // Default to the first message and then we'll override in a bit ;) |
|
2355 | 2471 | $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg']; |
2472 | + } |
|
2356 | 2473 | |
2357 | 2474 | $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1; |
2358 | 2475 | $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1; |
2359 | 2476 | $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1; |
2360 | 2477 | |
2361 | 2478 | // Post count for the user? |
2362 | - if ($row['id_member'] && empty($row['count_posts'])) |
|
2363 | - $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2479 | + if ($row['id_member'] && empty($row['count_posts'])) { |
|
2480 | + $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2481 | + } |
|
2364 | 2482 | } |
2365 | 2483 | $smcFunc['db_free_result']($request); |
2366 | 2484 | |
2367 | - if (empty($msgs)) |
|
2368 | - return; |
|
2485 | + if (empty($msgs)) { |
|
2486 | + return; |
|
2487 | + } |
|
2369 | 2488 | |
2370 | 2489 | // Now we have the differences make the changes, first the easy one. |
2371 | 2490 | $smcFunc['db_query']('', ' |
@@ -2392,14 +2511,15 @@ discard block |
||
2392 | 2511 | 'approved' => 1, |
2393 | 2512 | ) |
2394 | 2513 | ); |
2395 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2396 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2514 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2515 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2516 | + } |
|
2397 | 2517 | $smcFunc['db_free_result']($request); |
2398 | 2518 | } |
2399 | 2519 | |
2400 | 2520 | // ... next the topics... |
2401 | - foreach ($topic_changes as $id => $changes) |
|
2402 | - $smcFunc['db_query']('', ' |
|
2521 | + foreach ($topic_changes as $id => $changes) { |
|
2522 | + $smcFunc['db_query']('', ' |
|
2403 | 2523 | UPDATE {db_prefix}topics |
2404 | 2524 | SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2405 | 2525 | num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg} |
@@ -2412,10 +2532,11 @@ discard block |
||
2412 | 2532 | 'id_topic' => $id, |
2413 | 2533 | ) |
2414 | 2534 | ); |
2535 | + } |
|
2415 | 2536 | |
2416 | 2537 | // ... finally the boards... |
2417 | - foreach ($board_changes as $id => $changes) |
|
2418 | - $smcFunc['db_query']('', ' |
|
2538 | + foreach ($board_changes as $id => $changes) { |
|
2539 | + $smcFunc['db_query']('', ' |
|
2419 | 2540 | UPDATE {db_prefix}boards |
2420 | 2541 | SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2421 | 2542 | num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics} |
@@ -2428,13 +2549,14 @@ discard block |
||
2428 | 2549 | 'id_board' => $id, |
2429 | 2550 | ) |
2430 | 2551 | ); |
2552 | + } |
|
2431 | 2553 | |
2432 | 2554 | // Finally, least importantly, notifications! |
2433 | 2555 | if ($approve) |
2434 | 2556 | { |
2435 | 2557 | $task_rows = array(); |
2436 | - foreach (array_merge($notification_topics, $notification_posts) as $topic) |
|
2437 | - $task_rows[] = array( |
|
2558 | + foreach (array_merge($notification_topics, $notification_posts) as $topic) { |
|
2559 | + $task_rows[] = array( |
|
2438 | 2560 | '$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array( |
2439 | 2561 | 'msgOptions' => array( |
2440 | 2562 | 'id' => $topic['msg'], |
@@ -2452,14 +2574,16 @@ discard block |
||
2452 | 2574 | 'type' => $topic['new_topic'] ? 'topic' : 'reply', |
2453 | 2575 | )), 0 |
2454 | 2576 | ); |
2577 | + } |
|
2455 | 2578 | |
2456 | - if ($notify) |
|
2457 | - $smcFunc['db_insert']('', |
|
2579 | + if ($notify) { |
|
2580 | + $smcFunc['db_insert']('', |
|
2458 | 2581 | '{db_prefix}background_tasks', |
2459 | 2582 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2460 | 2583 | $task_rows, |
2461 | 2584 | array('id_task') |
2462 | 2585 | ); |
2586 | + } |
|
2463 | 2587 | |
2464 | 2588 | $smcFunc['db_query']('', ' |
2465 | 2589 | DELETE FROM {db_prefix}approval_queue |
@@ -2475,8 +2599,9 @@ discard block |
||
2475 | 2599 | else |
2476 | 2600 | { |
2477 | 2601 | $msgInserts = array(); |
2478 | - foreach ($msgs as $msg) |
|
2479 | - $msgInserts[] = array($msg); |
|
2602 | + foreach ($msgs as $msg) { |
|
2603 | + $msgInserts[] = array($msg); |
|
2604 | + } |
|
2480 | 2605 | |
2481 | 2606 | $smcFunc['db_insert']('ignore', |
2482 | 2607 | '{db_prefix}approval_queue', |
@@ -2490,9 +2615,10 @@ discard block |
||
2490 | 2615 | updateLastMessages(array_keys($board_changes)); |
2491 | 2616 | |
2492 | 2617 | // Post count for the members? |
2493 | - if (!empty($member_post_changes)) |
|
2494 | - foreach ($member_post_changes as $id_member => $count_change) |
|
2618 | + if (!empty($member_post_changes)) { |
|
2619 | + foreach ($member_post_changes as $id_member => $count_change) |
|
2495 | 2620 | updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change)); |
2621 | + } |
|
2496 | 2622 | |
2497 | 2623 | return true; |
2498 | 2624 | } |
@@ -2509,11 +2635,13 @@ discard block |
||
2509 | 2635 | { |
2510 | 2636 | global $smcFunc; |
2511 | 2637 | |
2512 | - if (!is_array($topics)) |
|
2513 | - $topics = array($topics); |
|
2638 | + if (!is_array($topics)) { |
|
2639 | + $topics = array($topics); |
|
2640 | + } |
|
2514 | 2641 | |
2515 | - if (empty($topics)) |
|
2516 | - return false; |
|
2642 | + if (empty($topics)) { |
|
2643 | + return false; |
|
2644 | + } |
|
2517 | 2645 | |
2518 | 2646 | $approve_type = $approve ? 0 : 1; |
2519 | 2647 | |
@@ -2529,8 +2657,9 @@ discard block |
||
2529 | 2657 | ) |
2530 | 2658 | ); |
2531 | 2659 | $msgs = array(); |
2532 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2533 | - $msgs[] = $row['id_msg']; |
|
2660 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2661 | + $msgs[] = $row['id_msg']; |
|
2662 | + } |
|
2534 | 2663 | $smcFunc['db_free_result']($request); |
2535 | 2664 | |
2536 | 2665 | return approvePosts($msgs, $approve); |
@@ -2553,11 +2682,13 @@ discard block |
||
2553 | 2682 | global $board_info, $board, $smcFunc; |
2554 | 2683 | |
2555 | 2684 | // Please - let's be sane. |
2556 | - if (empty($setboards)) |
|
2557 | - return false; |
|
2685 | + if (empty($setboards)) { |
|
2686 | + return false; |
|
2687 | + } |
|
2558 | 2688 | |
2559 | - if (!is_array($setboards)) |
|
2560 | - $setboards = array($setboards); |
|
2689 | + if (!is_array($setboards)) { |
|
2690 | + $setboards = array($setboards); |
|
2691 | + } |
|
2561 | 2692 | |
2562 | 2693 | // If we don't know the id_msg we need to find it. |
2563 | 2694 | if (!$id_msg) |
@@ -2575,15 +2706,16 @@ discard block |
||
2575 | 2706 | ) |
2576 | 2707 | ); |
2577 | 2708 | $lastMsg = array(); |
2578 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2579 | - $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2709 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2710 | + $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2711 | + } |
|
2580 | 2712 | $smcFunc['db_free_result']($request); |
2581 | - } |
|
2582 | - else |
|
2713 | + } else |
|
2583 | 2714 | { |
2584 | 2715 | // Just to note - there should only be one board passed if we are doing this. |
2585 | - foreach ($setboards as $id_board) |
|
2586 | - $lastMsg[$id_board] = $id_msg; |
|
2716 | + foreach ($setboards as $id_board) { |
|
2717 | + $lastMsg[$id_board] = $id_msg; |
|
2718 | + } |
|
2587 | 2719 | } |
2588 | 2720 | |
2589 | 2721 | $parent_boards = array(); |
@@ -2598,10 +2730,11 @@ discard block |
||
2598 | 2730 | $lastModified[$id_board] = 0; |
2599 | 2731 | } |
2600 | 2732 | |
2601 | - if (!empty($board) && $id_board == $board) |
|
2602 | - $parents = $board_info['parent_boards']; |
|
2603 | - else |
|
2604 | - $parents = getBoardParents($id_board); |
|
2733 | + if (!empty($board) && $id_board == $board) { |
|
2734 | + $parents = $board_info['parent_boards']; |
|
2735 | + } else { |
|
2736 | + $parents = getBoardParents($id_board); |
|
2737 | + } |
|
2605 | 2738 | |
2606 | 2739 | // Ignore any parents on the top child level. |
2607 | 2740 | // @todo Why? |
@@ -2610,10 +2743,11 @@ discard block |
||
2610 | 2743 | if ($parent['level'] != 0) |
2611 | 2744 | { |
2612 | 2745 | // If we're already doing this one as a board, is this a higher last modified? |
2613 | - if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) |
|
2614 | - $lastModified[$id] = $lastModified[$id_board]; |
|
2615 | - elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) |
|
2616 | - $parent_boards[$id] = $lastModified[$id_board]; |
|
2746 | + if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) { |
|
2747 | + $lastModified[$id] = $lastModified[$id_board]; |
|
2748 | + } elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) { |
|
2749 | + $parent_boards[$id] = $lastModified[$id_board]; |
|
2750 | + } |
|
2617 | 2751 | } |
2618 | 2752 | } |
2619 | 2753 | } |
@@ -2626,23 +2760,24 @@ discard block |
||
2626 | 2760 | // Finally, to save on queries make the changes... |
2627 | 2761 | foreach ($parent_boards as $id => $msg) |
2628 | 2762 | { |
2629 | - if (!isset($parent_updates[$msg])) |
|
2630 | - $parent_updates[$msg] = array($id); |
|
2631 | - else |
|
2632 | - $parent_updates[$msg][] = $id; |
|
2763 | + if (!isset($parent_updates[$msg])) { |
|
2764 | + $parent_updates[$msg] = array($id); |
|
2765 | + } else { |
|
2766 | + $parent_updates[$msg][] = $id; |
|
2767 | + } |
|
2633 | 2768 | } |
2634 | 2769 | |
2635 | 2770 | foreach ($lastMsg as $id => $msg) |
2636 | 2771 | { |
2637 | - if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) |
|
2638 | - $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2772 | + if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) { |
|
2773 | + $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2639 | 2774 | 'id' => $msg, |
2640 | 2775 | 'updated' => $lastModified[$id], |
2641 | 2776 | 'boards' => array($id) |
2642 | 2777 | ); |
2643 | - |
|
2644 | - else |
|
2645 | - $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2778 | + } else { |
|
2779 | + $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2780 | + } |
|
2646 | 2781 | } |
2647 | 2782 | |
2648 | 2783 | // Now commit the changes! |
@@ -2734,11 +2869,13 @@ discard block |
||
2734 | 2869 | global $txt, $mbname, $scripturl, $settings; |
2735 | 2870 | |
2736 | 2871 | // First things first, load up the email templates language file, if we need to. |
2737 | - if ($loadLang) |
|
2738 | - loadLanguage('EmailTemplates', $lang); |
|
2872 | + if ($loadLang) { |
|
2873 | + loadLanguage('EmailTemplates', $lang); |
|
2874 | + } |
|
2739 | 2875 | |
2740 | - if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) |
|
2741 | - fatal_lang_error('email_no_template', 'template', array($template)); |
|
2876 | + if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) { |
|
2877 | + fatal_lang_error('email_no_template', 'template', array($template)); |
|
2878 | + } |
|
2742 | 2879 | |
2743 | 2880 | $ret = array( |
2744 | 2881 | 'subject' => $txt[$template . '_subject'], |
@@ -2788,17 +2925,18 @@ discard block |
||
2788 | 2925 | function user_info_callback($matches) |
2789 | 2926 | { |
2790 | 2927 | global $user_info; |
2791 | - if (empty($matches[1])) |
|
2792 | - return ''; |
|
2928 | + if (empty($matches[1])) { |
|
2929 | + return ''; |
|
2930 | + } |
|
2793 | 2931 | |
2794 | 2932 | $use_ref = true; |
2795 | 2933 | $ref = &$user_info; |
2796 | 2934 | |
2797 | 2935 | foreach (explode('.', $matches[1]) as $index) |
2798 | 2936 | { |
2799 | - if ($use_ref && isset($ref[$index])) |
|
2800 | - $ref = &$ref[$index]; |
|
2801 | - else |
|
2937 | + if ($use_ref && isset($ref[$index])) { |
|
2938 | + $ref = &$ref[$index]; |
|
2939 | + } else |
|
2802 | 2940 | { |
2803 | 2941 | $use_ref = false; |
2804 | 2942 | break; |
@@ -2835,8 +2973,7 @@ discard block |
||
2835 | 2973 | if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale)) |
2836 | 2974 | { |
2837 | 2975 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale); |
2838 | - } |
|
2839 | - elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2976 | + } elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2840 | 2977 | { |
2841 | 2978 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']); |
2842 | 2979 | } |
@@ -2846,8 +2983,7 @@ discard block |
||
2846 | 2983 | { |
2847 | 2984 | $context['provider'] = 'enchant'; |
2848 | 2985 | return $enchant_link; |
2849 | - } |
|
2850 | - else |
|
2986 | + } else |
|
2851 | 2987 | { |
2852 | 2988 | // Free up any resources used... |
2853 | 2989 | @enchant_broker_free($context['enchant_broker']); |
@@ -2868,8 +3004,9 @@ discard block |
||
2868 | 3004 | $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER); |
2869 | 3005 | |
2870 | 3006 | // Most people don't have anything but English installed... So we use English as a last resort. |
2871 | - if (!$pspell_link) |
|
2872 | - $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
3007 | + if (!$pspell_link) { |
|
3008 | + $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
3009 | + } |
|
2873 | 3010 | |
2874 | 3011 | error_reporting($old); |
2875 | 3012 | ob_end_clean(); |
@@ -2909,8 +3046,7 @@ discard block |
||
2909 | 3046 | $word = iconv($txt['lang_character_set'], 'UTF-8', $word); |
2910 | 3047 | } |
2911 | 3048 | return enchant_dict_check($dict, $word); |
2912 | - } |
|
2913 | - elseif ($context['provider'] == 'pspell') |
|
3049 | + } elseif ($context['provider'] == 'pspell') |
|
2914 | 3050 | { |
2915 | 3051 | return pspell_check($dict, $word); |
2916 | 3052 | } |
@@ -2946,13 +3082,11 @@ discard block |
||
2946 | 3082 | } |
2947 | 3083 | |
2948 | 3084 | return $suggestions; |
2949 | - } |
|
2950 | - else |
|
3085 | + } else |
|
2951 | 3086 | { |
2952 | 3087 | return enchant_dict_suggest($dict, $word); |
2953 | 3088 | } |
2954 | - } |
|
2955 | - elseif ($context['provider'] == 'pspell') |
|
3089 | + } elseif ($context['provider'] == 'pspell') |
|
2956 | 3090 | { |
2957 | 3091 | return pspell_suggest($dict, $word); |
2958 | 3092 | } |