@@ -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 | { |
@@ -1291,11 +1349,13 @@ discard block |
||
1291 | 1349 | if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) |
1292 | 1350 | { |
1293 | 1351 | // ssl:hostname can cause fsocketopen to fail with a lookup failure, ensure it exists for this test. |
1294 | - if (substr($modSettings['smtp_host'], 0, 6) != 'ssl://') |
|
1295 | - $modSettings['smtp_host'] = str_replace('ssl:', 'ss://', $modSettings['smtp_host']); |
|
1352 | + if (substr($modSettings['smtp_host'], 0, 6) != 'ssl://') { |
|
1353 | + $modSettings['smtp_host'] = str_replace('ssl:', 'ss://', $modSettings['smtp_host']); |
|
1354 | + } |
|
1296 | 1355 | |
1297 | - if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) |
|
1298 | - log_error($txt['smtp_port_ssl']); |
|
1356 | + if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) { |
|
1357 | + log_error($txt['smtp_port_ssl']); |
|
1358 | + } |
|
1299 | 1359 | } |
1300 | 1360 | |
1301 | 1361 | // Unable to connect! Don't show any error message, but just log one and try to continue anyway. |
@@ -1307,20 +1367,23 @@ discard block |
||
1307 | 1367 | } |
1308 | 1368 | |
1309 | 1369 | // Wait for a response of 220, without "-" continuer. |
1310 | - if (!server_parse(null, $socket, '220')) |
|
1311 | - return false; |
|
1370 | + if (!server_parse(null, $socket, '220')) { |
|
1371 | + return false; |
|
1372 | + } |
|
1312 | 1373 | |
1313 | 1374 | // Try and determine the servers name, fall back to the mail servers if not found |
1314 | 1375 | $helo = false; |
1315 | - if (function_exists('gethostname') && gethostname() !== false) |
|
1316 | - $helo = gethostname(); |
|
1317 | - elseif (function_exists('php_uname')) |
|
1318 | - $helo = php_uname('n'); |
|
1319 | - elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) |
|
1320 | - $helo = $_SERVER['SERVER_NAME']; |
|
1376 | + if (function_exists('gethostname') && gethostname() !== false) { |
|
1377 | + $helo = gethostname(); |
|
1378 | + } elseif (function_exists('php_uname')) { |
|
1379 | + $helo = php_uname('n'); |
|
1380 | + } elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) { |
|
1381 | + $helo = $_SERVER['SERVER_NAME']; |
|
1382 | + } |
|
1321 | 1383 | |
1322 | - if (empty($helo)) |
|
1323 | - $helo = $modSettings['smtp_host']; |
|
1384 | + if (empty($helo)) { |
|
1385 | + $helo = $modSettings['smtp_host']; |
|
1386 | + } |
|
1324 | 1387 | |
1325 | 1388 | // SMTP = 1, SMTP - STARTTLS = 2 |
1326 | 1389 | if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
@@ -1332,8 +1395,9 @@ discard block |
||
1332 | 1395 | if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response)) |
1333 | 1396 | { |
1334 | 1397 | // Send STARTTLS to enable encryption |
1335 | - if (!server_parse('STARTTLS', $socket, '220')) |
|
1336 | - return false; |
|
1398 | + if (!server_parse('STARTTLS', $socket, '220')) { |
|
1399 | + return false; |
|
1400 | + } |
|
1337 | 1401 | // Enable the encryption |
1338 | 1402 | // php 5.6+ fix |
1339 | 1403 | $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; |
@@ -1344,30 +1408,35 @@ discard block |
||
1344 | 1408 | $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT; |
1345 | 1409 | } |
1346 | 1410 | |
1347 | - if (!@stream_socket_enable_crypto($socket, true, $crypto_method)) |
|
1348 | - return false; |
|
1411 | + if (!@stream_socket_enable_crypto($socket, true, $crypto_method)) { |
|
1412 | + return false; |
|
1413 | + } |
|
1349 | 1414 | // Send the EHLO command again |
1350 | - if (!server_parse('EHLO ' . $helo, $socket, null) == '250') |
|
1351 | - return false; |
|
1415 | + if (!server_parse('EHLO ' . $helo, $socket, null) == '250') { |
|
1416 | + return false; |
|
1417 | + } |
|
1352 | 1418 | } |
1353 | 1419 | |
1354 | - if (!server_parse('AUTH LOGIN', $socket, '334')) |
|
1355 | - return false; |
|
1420 | + if (!server_parse('AUTH LOGIN', $socket, '334')) { |
|
1421 | + return false; |
|
1422 | + } |
|
1356 | 1423 | // Send the username and password, encoded. |
1357 | - if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) |
|
1358 | - return false; |
|
1424 | + if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) { |
|
1425 | + return false; |
|
1426 | + } |
|
1359 | 1427 | // The password is already encoded ;) |
1360 | - if (!server_parse($modSettings['smtp_password'], $socket, '235')) |
|
1361 | - return false; |
|
1428 | + if (!server_parse($modSettings['smtp_password'], $socket, '235')) { |
|
1429 | + return false; |
|
1430 | + } |
|
1431 | + } elseif (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1432 | + return false; |
|
1362 | 1433 | } |
1363 | - elseif (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1364 | - return false; |
|
1365 | - } |
|
1366 | - else |
|
1434 | + } else |
|
1367 | 1435 | { |
1368 | 1436 | // Just say "helo". |
1369 | - if (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1370 | - return false; |
|
1437 | + if (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1438 | + return false; |
|
1439 | + } |
|
1371 | 1440 | } |
1372 | 1441 | |
1373 | 1442 | // Fix the message for any lines beginning with a period! (the first is ignored, you see.) |
@@ -1380,31 +1449,38 @@ discard block |
||
1380 | 1449 | // Reset the connection to send another email. |
1381 | 1450 | if ($i != 0) |
1382 | 1451 | { |
1383 | - if (!server_parse('RSET', $socket, '250')) |
|
1384 | - return false; |
|
1452 | + if (!server_parse('RSET', $socket, '250')) { |
|
1453 | + return false; |
|
1454 | + } |
|
1385 | 1455 | } |
1386 | 1456 | |
1387 | 1457 | // From, to, and then start the data... |
1388 | - if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) |
|
1389 | - return false; |
|
1390 | - if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) |
|
1391 | - return false; |
|
1392 | - if (!server_parse('DATA', $socket, '354')) |
|
1393 | - return false; |
|
1458 | + if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) { |
|
1459 | + return false; |
|
1460 | + } |
|
1461 | + if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) { |
|
1462 | + return false; |
|
1463 | + } |
|
1464 | + if (!server_parse('DATA', $socket, '354')) { |
|
1465 | + return false; |
|
1466 | + } |
|
1394 | 1467 | fputs($socket, 'Subject: ' . $subject . "\r\n"); |
1395 | - if (strlen($mail_to) > 0) |
|
1396 | - fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1468 | + if (strlen($mail_to) > 0) { |
|
1469 | + fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1470 | + } |
|
1397 | 1471 | fputs($socket, $headers . "\r\n\r\n"); |
1398 | 1472 | fputs($socket, $message . "\r\n"); |
1399 | 1473 | |
1400 | 1474 | // Send a ., or in other words "end of data". |
1401 | - if (!server_parse('.', $socket, '250')) |
|
1402 | - return false; |
|
1475 | + if (!server_parse('.', $socket, '250')) { |
|
1476 | + return false; |
|
1477 | + } |
|
1403 | 1478 | |
1404 | 1479 | // Almost done, almost done... don't stop me just yet! |
1405 | 1480 | @set_time_limit(300); |
1406 | - if (function_exists('apache_reset_timeout')) |
|
1407 | - @apache_reset_timeout(); |
|
1481 | + if (function_exists('apache_reset_timeout')) { |
|
1482 | + @apache_reset_timeout(); |
|
1483 | + } |
|
1408 | 1484 | } |
1409 | 1485 | fputs($socket, 'QUIT' . "\r\n"); |
1410 | 1486 | fclose($socket); |
@@ -1428,8 +1504,9 @@ discard block |
||
1428 | 1504 | { |
1429 | 1505 | global $txt; |
1430 | 1506 | |
1431 | - if ($message !== null) |
|
1432 | - fputs($socket, $message . "\r\n"); |
|
1507 | + if ($message !== null) { |
|
1508 | + fputs($socket, $message . "\r\n"); |
|
1509 | + } |
|
1433 | 1510 | |
1434 | 1511 | // No response yet. |
1435 | 1512 | $server_response = ''; |
@@ -1445,8 +1522,9 @@ discard block |
||
1445 | 1522 | $response .= $server_response; |
1446 | 1523 | } |
1447 | 1524 | |
1448 | - if ($code === null) |
|
1449 | - return substr($server_response, 0, 3); |
|
1525 | + if ($code === null) { |
|
1526 | + return substr($server_response, 0, 3); |
|
1527 | + } |
|
1450 | 1528 | |
1451 | 1529 | if (substr($server_response, 0, 3) != $code) |
1452 | 1530 | { |
@@ -1476,8 +1554,9 @@ discard block |
||
1476 | 1554 | // Create a pspell or enchant dictionary resource |
1477 | 1555 | $dict = spell_init(); |
1478 | 1556 | |
1479 | - if (!isset($_POST['spellstring']) || !$dict) |
|
1480 | - die; |
|
1557 | + if (!isset($_POST['spellstring']) || !$dict) { |
|
1558 | + die; |
|
1559 | + } |
|
1481 | 1560 | |
1482 | 1561 | // Construct a bit of Javascript code. |
1483 | 1562 | $context['spell_js'] = ' |
@@ -1495,8 +1574,9 @@ discard block |
||
1495 | 1574 | $check_word = explode('|', $alphas[$i]); |
1496 | 1575 | |
1497 | 1576 | // If the word is a known word, or spelled right... |
1498 | - if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) |
|
1499 | - continue; |
|
1577 | + if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) { |
|
1578 | + continue; |
|
1579 | + } |
|
1500 | 1580 | |
1501 | 1581 | // Find the word, and move up the "last occurrence" to here. |
1502 | 1582 | $found_words = true; |
@@ -1510,20 +1590,23 @@ discard block |
||
1510 | 1590 | if (!empty($suggestions)) |
1511 | 1591 | { |
1512 | 1592 | // But first check they aren't going to be censored - no naughty words! |
1513 | - foreach ($suggestions as $k => $word) |
|
1514 | - if ($suggestions[$k] != censorText($word)) |
|
1593 | + foreach ($suggestions as $k => $word) { |
|
1594 | + if ($suggestions[$k] != censorText($word)) |
|
1515 | 1595 | unset($suggestions[$k]); |
1596 | + } |
|
1516 | 1597 | |
1517 | - if (!empty($suggestions)) |
|
1518 | - $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1598 | + if (!empty($suggestions)) { |
|
1599 | + $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1600 | + } |
|
1519 | 1601 | } |
1520 | 1602 | |
1521 | 1603 | $context['spell_js'] .= ']),'; |
1522 | 1604 | } |
1523 | 1605 | |
1524 | 1606 | // If words were found, take off the last comma. |
1525 | - if ($found_words) |
|
1526 | - $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1607 | + if ($found_words) { |
|
1608 | + $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1609 | + } |
|
1527 | 1610 | |
1528 | 1611 | $context['spell_js'] .= ' |
1529 | 1612 | );'; |
@@ -1558,11 +1641,13 @@ discard block |
||
1558 | 1641 | global $user_info, $smcFunc; |
1559 | 1642 | |
1560 | 1643 | // Can't do it if there's no topics. |
1561 | - if (empty($topics)) |
|
1562 | - return; |
|
1644 | + if (empty($topics)) { |
|
1645 | + return; |
|
1646 | + } |
|
1563 | 1647 | // It must be an array - it must! |
1564 | - if (!is_array($topics)) |
|
1565 | - $topics = array($topics); |
|
1648 | + if (!is_array($topics)) { |
|
1649 | + $topics = array($topics); |
|
1650 | + } |
|
1566 | 1651 | |
1567 | 1652 | // Get the subject and body... |
1568 | 1653 | $result = $smcFunc['db_query']('', ' |
@@ -1610,14 +1695,15 @@ discard block |
||
1610 | 1695 | } |
1611 | 1696 | $smcFunc['db_free_result']($result); |
1612 | 1697 | |
1613 | - if (!empty($task_rows)) |
|
1614 | - $smcFunc['db_insert']('', |
|
1698 | + if (!empty($task_rows)) { |
|
1699 | + $smcFunc['db_insert']('', |
|
1615 | 1700 | '{db_prefix}background_tasks', |
1616 | 1701 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1617 | 1702 | $task_rows, |
1618 | 1703 | array('id_task') |
1619 | 1704 | ); |
1620 | -} |
|
1705 | + } |
|
1706 | + } |
|
1621 | 1707 | |
1622 | 1708 | /** |
1623 | 1709 | * Create a post, either as new topic (id_topic = 0) or in an existing one. |
@@ -1655,9 +1741,9 @@ discard block |
||
1655 | 1741 | $msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true; |
1656 | 1742 | |
1657 | 1743 | // We need to know if the topic is approved. If we're told that's great - if not find out. |
1658 | - if (!$modSettings['postmod_active']) |
|
1659 | - $topicOptions['is_approved'] = true; |
|
1660 | - elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1744 | + if (!$modSettings['postmod_active']) { |
|
1745 | + $topicOptions['is_approved'] = true; |
|
1746 | + } elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1661 | 1747 | { |
1662 | 1748 | $request = $smcFunc['db_query']('', ' |
1663 | 1749 | SELECT approved |
@@ -1680,8 +1766,7 @@ discard block |
||
1680 | 1766 | $posterOptions['id'] = 0; |
1681 | 1767 | $posterOptions['name'] = $txt['guest_title']; |
1682 | 1768 | $posterOptions['email'] = ''; |
1683 | - } |
|
1684 | - elseif ($posterOptions['id'] != $user_info['id']) |
|
1769 | + } elseif ($posterOptions['id'] != $user_info['id']) |
|
1685 | 1770 | { |
1686 | 1771 | $request = $smcFunc['db_query']('', ' |
1687 | 1772 | SELECT member_name, email_address |
@@ -1699,12 +1784,11 @@ discard block |
||
1699 | 1784 | $posterOptions['id'] = 0; |
1700 | 1785 | $posterOptions['name'] = $txt['guest_title']; |
1701 | 1786 | $posterOptions['email'] = ''; |
1787 | + } else { |
|
1788 | + list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1702 | 1789 | } |
1703 | - else |
|
1704 | - list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1705 | 1790 | $smcFunc['db_free_result']($request); |
1706 | - } |
|
1707 | - else |
|
1791 | + } else |
|
1708 | 1792 | { |
1709 | 1793 | $posterOptions['name'] = $user_info['name']; |
1710 | 1794 | $posterOptions['email'] = $user_info['email']; |
@@ -1714,8 +1798,9 @@ discard block |
||
1714 | 1798 | if (!empty($modSettings['enable_mentions'])) |
1715 | 1799 | { |
1716 | 1800 | $msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']); |
1717 | - if (!empty($msgOptions['mentioned_members'])) |
|
1718 | - $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1801 | + if (!empty($msgOptions['mentioned_members'])) { |
|
1802 | + $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1803 | + } |
|
1719 | 1804 | } |
1720 | 1805 | |
1721 | 1806 | // It's do or die time: forget any user aborts! |
@@ -1748,12 +1833,13 @@ discard block |
||
1748 | 1833 | ); |
1749 | 1834 | |
1750 | 1835 | // Something went wrong creating the message... |
1751 | - if (empty($msgOptions['id'])) |
|
1752 | - return false; |
|
1836 | + if (empty($msgOptions['id'])) { |
|
1837 | + return false; |
|
1838 | + } |
|
1753 | 1839 | |
1754 | 1840 | // Fix the attachments. |
1755 | - if (!empty($msgOptions['attachments'])) |
|
1756 | - $smcFunc['db_query']('', ' |
|
1841 | + if (!empty($msgOptions['attachments'])) { |
|
1842 | + $smcFunc['db_query']('', ' |
|
1757 | 1843 | UPDATE {db_prefix}attachments |
1758 | 1844 | SET id_msg = {int:id_msg} |
1759 | 1845 | WHERE id_attach IN ({array_int:attachment_list})', |
@@ -1762,6 +1848,7 @@ discard block |
||
1762 | 1848 | 'id_msg' => $msgOptions['id'], |
1763 | 1849 | ) |
1764 | 1850 | ); |
1851 | + } |
|
1765 | 1852 | |
1766 | 1853 | // What if we want to export new posts out to a CMS? |
1767 | 1854 | call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters)); |
@@ -1838,20 +1925,23 @@ discard block |
||
1838 | 1925 | 'id_topic' => $topicOptions['id'], |
1839 | 1926 | 'counter_increment' => 1, |
1840 | 1927 | ); |
1841 | - if ($msgOptions['approved']) |
|
1842 | - $topics_columns = array( |
|
1928 | + if ($msgOptions['approved']) { |
|
1929 | + $topics_columns = array( |
|
1843 | 1930 | 'id_member_updated = {int:poster_id}', |
1844 | 1931 | 'id_last_msg = {int:id_msg}', |
1845 | 1932 | 'num_replies = num_replies + {int:counter_increment}', |
1846 | 1933 | ); |
1847 | - else |
|
1848 | - $topics_columns = array( |
|
1934 | + } else { |
|
1935 | + $topics_columns = array( |
|
1849 | 1936 | 'unapproved_posts = unapproved_posts + {int:counter_increment}', |
1850 | 1937 | ); |
1851 | - if ($topicOptions['lock_mode'] !== null) |
|
1852 | - $topics_columns[] = 'locked = {int:locked}'; |
|
1853 | - if ($topicOptions['sticky_mode'] !== null) |
|
1854 | - $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1938 | + } |
|
1939 | + if ($topicOptions['lock_mode'] !== null) { |
|
1940 | + $topics_columns[] = 'locked = {int:locked}'; |
|
1941 | + } |
|
1942 | + if ($topicOptions['sticky_mode'] !== null) { |
|
1943 | + $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1944 | + } |
|
1855 | 1945 | |
1856 | 1946 | call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions)); |
1857 | 1947 | |
@@ -1880,8 +1970,8 @@ discard block |
||
1880 | 1970 | ); |
1881 | 1971 | |
1882 | 1972 | // Increase the number of posts and topics on the board. |
1883 | - if ($msgOptions['approved']) |
|
1884 | - $smcFunc['db_query']('', ' |
|
1973 | + if ($msgOptions['approved']) { |
|
1974 | + $smcFunc['db_query']('', ' |
|
1885 | 1975 | UPDATE {db_prefix}boards |
1886 | 1976 | SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . ' |
1887 | 1977 | WHERE id_board = {int:id_board}', |
@@ -1889,7 +1979,7 @@ discard block |
||
1889 | 1979 | 'id_board' => $topicOptions['board'], |
1890 | 1980 | ) |
1891 | 1981 | ); |
1892 | - else |
|
1982 | + } else |
|
1893 | 1983 | { |
1894 | 1984 | $smcFunc['db_query']('', ' |
1895 | 1985 | UPDATE {db_prefix}boards |
@@ -1959,8 +2049,8 @@ discard block |
||
1959 | 2049 | } |
1960 | 2050 | } |
1961 | 2051 | |
1962 | - if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) |
|
1963 | - $smcFunc['db_insert']('', |
|
2052 | + if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) { |
|
2053 | + $smcFunc['db_insert']('', |
|
1964 | 2054 | '{db_prefix}background_tasks', |
1965 | 2055 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1966 | 2056 | array( |
@@ -1972,19 +2062,22 @@ discard block |
||
1972 | 2062 | ), |
1973 | 2063 | array('id_task') |
1974 | 2064 | ); |
2065 | + } |
|
1975 | 2066 | |
1976 | 2067 | // If there's a custom search index, it may need updating... |
1977 | 2068 | require_once($sourcedir . '/Search.php'); |
1978 | 2069 | $searchAPI = findSearchAPI(); |
1979 | - if (is_callable(array($searchAPI, 'postCreated'))) |
|
1980 | - $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2070 | + if (is_callable(array($searchAPI, 'postCreated'))) { |
|
2071 | + $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2072 | + } |
|
1981 | 2073 | |
1982 | 2074 | // Increase the post counter for the user that created the post. |
1983 | 2075 | if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved']) |
1984 | 2076 | { |
1985 | 2077 | // Are you the one that happened to create this post? |
1986 | - if ($user_info['id'] == $posterOptions['id']) |
|
1987 | - $user_info['posts']++; |
|
2078 | + if ($user_info['id'] == $posterOptions['id']) { |
|
2079 | + $user_info['posts']++; |
|
2080 | + } |
|
1988 | 2081 | updateMemberData($posterOptions['id'], array('posts' => '+')); |
1989 | 2082 | } |
1990 | 2083 | |
@@ -1992,19 +2085,21 @@ discard block |
||
1992 | 2085 | $_SESSION['last_read_topic'] = 0; |
1993 | 2086 | |
1994 | 2087 | // Better safe than sorry. |
1995 | - if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) |
|
1996 | - $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2088 | + if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) { |
|
2089 | + $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2090 | + } |
|
1997 | 2091 | |
1998 | 2092 | // Update all the stats so everyone knows about this new topic and message. |
1999 | 2093 | updateStats('message', true, $msgOptions['id']); |
2000 | 2094 | |
2001 | 2095 | // Update the last message on the board assuming it's approved AND the topic is. |
2002 | - if ($msgOptions['approved']) |
|
2003 | - updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2096 | + if ($msgOptions['approved']) { |
|
2097 | + updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2098 | + } |
|
2004 | 2099 | |
2005 | 2100 | // Queue createPost background notification |
2006 | - if ($msgOptions['send_notifications'] && $msgOptions['approved']) |
|
2007 | - $smcFunc['db_insert']('', |
|
2101 | + if ($msgOptions['send_notifications'] && $msgOptions['approved']) { |
|
2102 | + $smcFunc['db_insert']('', |
|
2008 | 2103 | '{db_prefix}background_tasks', |
2009 | 2104 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2010 | 2105 | array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array( |
@@ -2015,6 +2110,7 @@ discard block |
||
2015 | 2110 | )), 0), |
2016 | 2111 | array('id_task') |
2017 | 2112 | ); |
2113 | + } |
|
2018 | 2114 | |
2019 | 2115 | // Alright, done now... we can abort now, I guess... at least this much is done. |
2020 | 2116 | ignore_user_abort($previous_ignore_user_abort); |
@@ -2041,14 +2137,18 @@ discard block |
||
2041 | 2137 | |
2042 | 2138 | // This is longer than it has to be, but makes it so we only set/change what we have to. |
2043 | 2139 | $messages_columns = array(); |
2044 | - if (isset($posterOptions['name'])) |
|
2045 | - $messages_columns['poster_name'] = $posterOptions['name']; |
|
2046 | - if (isset($posterOptions['email'])) |
|
2047 | - $messages_columns['poster_email'] = $posterOptions['email']; |
|
2048 | - if (isset($msgOptions['icon'])) |
|
2049 | - $messages_columns['icon'] = $msgOptions['icon']; |
|
2050 | - if (isset($msgOptions['subject'])) |
|
2051 | - $messages_columns['subject'] = $msgOptions['subject']; |
|
2140 | + if (isset($posterOptions['name'])) { |
|
2141 | + $messages_columns['poster_name'] = $posterOptions['name']; |
|
2142 | + } |
|
2143 | + if (isset($posterOptions['email'])) { |
|
2144 | + $messages_columns['poster_email'] = $posterOptions['email']; |
|
2145 | + } |
|
2146 | + if (isset($msgOptions['icon'])) { |
|
2147 | + $messages_columns['icon'] = $msgOptions['icon']; |
|
2148 | + } |
|
2149 | + if (isset($msgOptions['subject'])) { |
|
2150 | + $messages_columns['subject'] = $msgOptions['subject']; |
|
2151 | + } |
|
2052 | 2152 | if (isset($msgOptions['body'])) |
2053 | 2153 | { |
2054 | 2154 | $messages_columns['body'] = $msgOptions['body']; |
@@ -2075,8 +2175,9 @@ discard block |
||
2075 | 2175 | $messages_columns['modified_reason'] = $msgOptions['modify_reason']; |
2076 | 2176 | $messages_columns['id_msg_modified'] = $modSettings['maxMsgID']; |
2077 | 2177 | } |
2078 | - if (isset($msgOptions['smileys_enabled'])) |
|
2079 | - $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2178 | + if (isset($msgOptions['smileys_enabled'])) { |
|
2179 | + $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2180 | + } |
|
2080 | 2181 | |
2081 | 2182 | // Which columns need to be ints? |
2082 | 2183 | $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled'); |
@@ -2087,8 +2188,9 @@ discard block |
||
2087 | 2188 | // Update search api |
2088 | 2189 | require_once($sourcedir . '/Search.php'); |
2089 | 2190 | $searchAPI = findSearchAPI(); |
2090 | - if ($searchAPI->supportsMethod('postRemoved')) |
|
2091 | - $searchAPI->postRemoved($msgOptions['id']); |
|
2191 | + if ($searchAPI->supportsMethod('postRemoved')) { |
|
2192 | + $searchAPI->postRemoved($msgOptions['id']); |
|
2193 | + } |
|
2092 | 2194 | |
2093 | 2195 | if (!empty($modSettings['enable_mentions']) && isset($msgOptions['body'])) |
2094 | 2196 | { |
@@ -2100,23 +2202,27 @@ discard block |
||
2100 | 2202 | { |
2101 | 2203 | preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match); |
2102 | 2204 | |
2103 | - if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) |
|
2104 | - foreach ($match[1] as $i => $oldID) |
|
2205 | + if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) { |
|
2206 | + foreach ($match[1] as $i => $oldID) |
|
2105 | 2207 | $oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]); |
2208 | + } |
|
2106 | 2209 | |
2107 | - if (empty($modSettings['search_custom_index_config'])) |
|
2108 | - unset($msgOptions['old_body']); |
|
2210 | + if (empty($modSettings['search_custom_index_config'])) { |
|
2211 | + unset($msgOptions['old_body']); |
|
2212 | + } |
|
2109 | 2213 | } |
2110 | 2214 | |
2111 | 2215 | $mentions = Mentions::getMentionedMembers($msgOptions['body']); |
2112 | 2216 | $messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions); |
2113 | 2217 | |
2114 | 2218 | // Remove the poster. |
2115 | - if (isset($mentions[$user_info['id']])) |
|
2116 | - unset($mentions[$user_info['id']]); |
|
2219 | + if (isset($mentions[$user_info['id']])) { |
|
2220 | + unset($mentions[$user_info['id']]); |
|
2221 | + } |
|
2117 | 2222 | |
2118 | - if (isset($oldmentions[$user_info['id']])) |
|
2119 | - unset($oldmentions[$user_info['id']]); |
|
2223 | + if (isset($oldmentions[$user_info['id']])) { |
|
2224 | + unset($oldmentions[$user_info['id']]); |
|
2225 | + } |
|
2120 | 2226 | |
2121 | 2227 | if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions)) |
2122 | 2228 | { |
@@ -2146,8 +2252,9 @@ discard block |
||
2146 | 2252 | } |
2147 | 2253 | |
2148 | 2254 | // Nothing to do? |
2149 | - if (empty($messages_columns)) |
|
2150 | - return true; |
|
2255 | + if (empty($messages_columns)) { |
|
2256 | + return true; |
|
2257 | + } |
|
2151 | 2258 | |
2152 | 2259 | // Change the post. |
2153 | 2260 | $smcFunc['db_query']('', ' |
@@ -2208,8 +2315,9 @@ discard block |
||
2208 | 2315 | // If there's a custom search index, it needs to be modified... |
2209 | 2316 | require_once($sourcedir . '/Search.php'); |
2210 | 2317 | $searchAPI = findSearchAPI(); |
2211 | - if (is_callable(array($searchAPI, 'postModified'))) |
|
2212 | - $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2318 | + if (is_callable(array($searchAPI, 'postModified'))) { |
|
2319 | + $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2320 | + } |
|
2213 | 2321 | |
2214 | 2322 | if (isset($msgOptions['subject'])) |
2215 | 2323 | { |
@@ -2223,14 +2331,16 @@ discard block |
||
2223 | 2331 | 'id_first_msg' => $msgOptions['id'], |
2224 | 2332 | ) |
2225 | 2333 | ); |
2226 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
2227 | - updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2334 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
2335 | + updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2336 | + } |
|
2228 | 2337 | $smcFunc['db_free_result']($request); |
2229 | 2338 | } |
2230 | 2339 | |
2231 | 2340 | // Finally, if we are setting the approved state we need to do much more work :( |
2232 | - if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) |
|
2233 | - approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2341 | + if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) { |
|
2342 | + approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2343 | + } |
|
2234 | 2344 | |
2235 | 2345 | return true; |
2236 | 2346 | } |
@@ -2247,11 +2357,13 @@ discard block |
||
2247 | 2357 | { |
2248 | 2358 | global $smcFunc; |
2249 | 2359 | |
2250 | - if (!is_array($msgs)) |
|
2251 | - $msgs = array($msgs); |
|
2360 | + if (!is_array($msgs)) { |
|
2361 | + $msgs = array($msgs); |
|
2362 | + } |
|
2252 | 2363 | |
2253 | - if (empty($msgs)) |
|
2254 | - return false; |
|
2364 | + if (empty($msgs)) { |
|
2365 | + return false; |
|
2366 | + } |
|
2255 | 2367 | |
2256 | 2368 | // May as well start at the beginning, working out *what* we need to change. |
2257 | 2369 | $request = $smcFunc['db_query']('', ' |
@@ -2283,20 +2395,22 @@ discard block |
||
2283 | 2395 | $topics[] = $row['id_topic']; |
2284 | 2396 | |
2285 | 2397 | // Ensure our change array exists already. |
2286 | - if (!isset($topic_changes[$row['id_topic']])) |
|
2287 | - $topic_changes[$row['id_topic']] = array( |
|
2398 | + if (!isset($topic_changes[$row['id_topic']])) { |
|
2399 | + $topic_changes[$row['id_topic']] = array( |
|
2288 | 2400 | 'id_last_msg' => $row['id_last_msg'], |
2289 | 2401 | 'approved' => $row['topic_approved'], |
2290 | 2402 | 'replies' => 0, |
2291 | 2403 | 'unapproved_posts' => 0, |
2292 | 2404 | ); |
2293 | - if (!isset($board_changes[$row['id_board']])) |
|
2294 | - $board_changes[$row['id_board']] = array( |
|
2405 | + } |
|
2406 | + if (!isset($board_changes[$row['id_board']])) { |
|
2407 | + $board_changes[$row['id_board']] = array( |
|
2295 | 2408 | 'posts' => 0, |
2296 | 2409 | 'topics' => 0, |
2297 | 2410 | 'unapproved_posts' => 0, |
2298 | 2411 | 'unapproved_topics' => 0, |
2299 | 2412 | ); |
2413 | + } |
|
2300 | 2414 | |
2301 | 2415 | // If it's the first message then the topic state changes! |
2302 | 2416 | if ($row['id_msg'] == $row['id_first_msg']) |
@@ -2317,14 +2431,13 @@ discard block |
||
2317 | 2431 | 'poster' => $row['id_member'], |
2318 | 2432 | 'new_topic' => true, |
2319 | 2433 | ); |
2320 | - } |
|
2321 | - else |
|
2434 | + } else |
|
2322 | 2435 | { |
2323 | 2436 | $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1; |
2324 | 2437 | |
2325 | 2438 | // This will be a post... but don't notify unless it's not followed by approved ones. |
2326 | - if ($row['id_msg'] > $row['id_last_msg']) |
|
2327 | - $notification_posts[$row['id_topic']] = array( |
|
2439 | + if ($row['id_msg'] > $row['id_last_msg']) { |
|
2440 | + $notification_posts[$row['id_topic']] = array( |
|
2328 | 2441 | 'id' => $row['id_msg'], |
2329 | 2442 | 'body' => $row['body'], |
2330 | 2443 | 'subject' => $row['subject'], |
@@ -2335,28 +2448,33 @@ discard block |
||
2335 | 2448 | 'new_topic' => false, |
2336 | 2449 | 'msg' => $row['id_msg'], |
2337 | 2450 | ); |
2451 | + } |
|
2338 | 2452 | } |
2339 | 2453 | |
2340 | 2454 | // If this is being approved and id_msg is higher than the current id_last_msg then it changes. |
2341 | - if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) |
|
2342 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2455 | + if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) { |
|
2456 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2457 | + } |
|
2343 | 2458 | // If this is being unapproved, and it's equal to the id_last_msg we need to find a new one! |
2344 | - elseif (!$approve) |
|
2345 | - // Default to the first message and then we'll override in a bit ;) |
|
2459 | + elseif (!$approve) { |
|
2460 | + // Default to the first message and then we'll override in a bit ;) |
|
2346 | 2461 | $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg']; |
2462 | + } |
|
2347 | 2463 | |
2348 | 2464 | $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1; |
2349 | 2465 | $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1; |
2350 | 2466 | $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1; |
2351 | 2467 | |
2352 | 2468 | // Post count for the user? |
2353 | - if ($row['id_member'] && empty($row['count_posts'])) |
|
2354 | - $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2469 | + if ($row['id_member'] && empty($row['count_posts'])) { |
|
2470 | + $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2471 | + } |
|
2355 | 2472 | } |
2356 | 2473 | $smcFunc['db_free_result']($request); |
2357 | 2474 | |
2358 | - if (empty($msgs)) |
|
2359 | - return; |
|
2475 | + if (empty($msgs)) { |
|
2476 | + return; |
|
2477 | + } |
|
2360 | 2478 | |
2361 | 2479 | // Now we have the differences make the changes, first the easy one. |
2362 | 2480 | $smcFunc['db_query']('', ' |
@@ -2383,14 +2501,15 @@ discard block |
||
2383 | 2501 | 'approved' => 1, |
2384 | 2502 | ) |
2385 | 2503 | ); |
2386 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2387 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2504 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2505 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2506 | + } |
|
2388 | 2507 | $smcFunc['db_free_result']($request); |
2389 | 2508 | } |
2390 | 2509 | |
2391 | 2510 | // ... next the topics... |
2392 | - foreach ($topic_changes as $id => $changes) |
|
2393 | - $smcFunc['db_query']('', ' |
|
2511 | + foreach ($topic_changes as $id => $changes) { |
|
2512 | + $smcFunc['db_query']('', ' |
|
2394 | 2513 | UPDATE {db_prefix}topics |
2395 | 2514 | SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2396 | 2515 | num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg} |
@@ -2403,10 +2522,11 @@ discard block |
||
2403 | 2522 | 'id_topic' => $id, |
2404 | 2523 | ) |
2405 | 2524 | ); |
2525 | + } |
|
2406 | 2526 | |
2407 | 2527 | // ... finally the boards... |
2408 | - foreach ($board_changes as $id => $changes) |
|
2409 | - $smcFunc['db_query']('', ' |
|
2528 | + foreach ($board_changes as $id => $changes) { |
|
2529 | + $smcFunc['db_query']('', ' |
|
2410 | 2530 | UPDATE {db_prefix}boards |
2411 | 2531 | SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2412 | 2532 | num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics} |
@@ -2419,13 +2539,14 @@ discard block |
||
2419 | 2539 | 'id_board' => $id, |
2420 | 2540 | ) |
2421 | 2541 | ); |
2542 | + } |
|
2422 | 2543 | |
2423 | 2544 | // Finally, least importantly, notifications! |
2424 | 2545 | if ($approve) |
2425 | 2546 | { |
2426 | 2547 | $task_rows = array(); |
2427 | - foreach (array_merge($notification_topics, $notification_posts) as $topic) |
|
2428 | - $task_rows[] = array( |
|
2548 | + foreach (array_merge($notification_topics, $notification_posts) as $topic) { |
|
2549 | + $task_rows[] = array( |
|
2429 | 2550 | '$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array( |
2430 | 2551 | 'msgOptions' => array( |
2431 | 2552 | 'id' => $topic['msg'], |
@@ -2443,14 +2564,16 @@ discard block |
||
2443 | 2564 | 'type' => $topic['new_topic'] ? 'topic' : 'reply', |
2444 | 2565 | )), 0 |
2445 | 2566 | ); |
2567 | + } |
|
2446 | 2568 | |
2447 | - if ($notify) |
|
2448 | - $smcFunc['db_insert']('', |
|
2569 | + if ($notify) { |
|
2570 | + $smcFunc['db_insert']('', |
|
2449 | 2571 | '{db_prefix}background_tasks', |
2450 | 2572 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2451 | 2573 | $task_rows, |
2452 | 2574 | array('id_task') |
2453 | 2575 | ); |
2576 | + } |
|
2454 | 2577 | |
2455 | 2578 | $smcFunc['db_query']('', ' |
2456 | 2579 | DELETE FROM {db_prefix}approval_queue |
@@ -2466,8 +2589,9 @@ discard block |
||
2466 | 2589 | else |
2467 | 2590 | { |
2468 | 2591 | $msgInserts = array(); |
2469 | - foreach ($msgs as $msg) |
|
2470 | - $msgInserts[] = array($msg); |
|
2592 | + foreach ($msgs as $msg) { |
|
2593 | + $msgInserts[] = array($msg); |
|
2594 | + } |
|
2471 | 2595 | |
2472 | 2596 | $smcFunc['db_insert']('ignore', |
2473 | 2597 | '{db_prefix}approval_queue', |
@@ -2481,9 +2605,10 @@ discard block |
||
2481 | 2605 | updateLastMessages(array_keys($board_changes)); |
2482 | 2606 | |
2483 | 2607 | // Post count for the members? |
2484 | - if (!empty($member_post_changes)) |
|
2485 | - foreach ($member_post_changes as $id_member => $count_change) |
|
2608 | + if (!empty($member_post_changes)) { |
|
2609 | + foreach ($member_post_changes as $id_member => $count_change) |
|
2486 | 2610 | updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change)); |
2611 | + } |
|
2487 | 2612 | |
2488 | 2613 | return true; |
2489 | 2614 | } |
@@ -2500,11 +2625,13 @@ discard block |
||
2500 | 2625 | { |
2501 | 2626 | global $smcFunc; |
2502 | 2627 | |
2503 | - if (!is_array($topics)) |
|
2504 | - $topics = array($topics); |
|
2628 | + if (!is_array($topics)) { |
|
2629 | + $topics = array($topics); |
|
2630 | + } |
|
2505 | 2631 | |
2506 | - if (empty($topics)) |
|
2507 | - return false; |
|
2632 | + if (empty($topics)) { |
|
2633 | + return false; |
|
2634 | + } |
|
2508 | 2635 | |
2509 | 2636 | $approve_type = $approve ? 0 : 1; |
2510 | 2637 | |
@@ -2520,8 +2647,9 @@ discard block |
||
2520 | 2647 | ) |
2521 | 2648 | ); |
2522 | 2649 | $msgs = array(); |
2523 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2524 | - $msgs[] = $row['id_msg']; |
|
2650 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2651 | + $msgs[] = $row['id_msg']; |
|
2652 | + } |
|
2525 | 2653 | $smcFunc['db_free_result']($request); |
2526 | 2654 | |
2527 | 2655 | return approvePosts($msgs, $approve); |
@@ -2544,11 +2672,13 @@ discard block |
||
2544 | 2672 | global $board_info, $board, $smcFunc; |
2545 | 2673 | |
2546 | 2674 | // Please - let's be sane. |
2547 | - if (empty($setboards)) |
|
2548 | - return false; |
|
2675 | + if (empty($setboards)) { |
|
2676 | + return false; |
|
2677 | + } |
|
2549 | 2678 | |
2550 | - if (!is_array($setboards)) |
|
2551 | - $setboards = array($setboards); |
|
2679 | + if (!is_array($setboards)) { |
|
2680 | + $setboards = array($setboards); |
|
2681 | + } |
|
2552 | 2682 | |
2553 | 2683 | // If we don't know the id_msg we need to find it. |
2554 | 2684 | if (!$id_msg) |
@@ -2566,15 +2696,16 @@ discard block |
||
2566 | 2696 | ) |
2567 | 2697 | ); |
2568 | 2698 | $lastMsg = array(); |
2569 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2570 | - $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2699 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2700 | + $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2701 | + } |
|
2571 | 2702 | $smcFunc['db_free_result']($request); |
2572 | - } |
|
2573 | - else |
|
2703 | + } else |
|
2574 | 2704 | { |
2575 | 2705 | // Just to note - there should only be one board passed if we are doing this. |
2576 | - foreach ($setboards as $id_board) |
|
2577 | - $lastMsg[$id_board] = $id_msg; |
|
2706 | + foreach ($setboards as $id_board) { |
|
2707 | + $lastMsg[$id_board] = $id_msg; |
|
2708 | + } |
|
2578 | 2709 | } |
2579 | 2710 | |
2580 | 2711 | $parent_boards = array(); |
@@ -2589,10 +2720,11 @@ discard block |
||
2589 | 2720 | $lastModified[$id_board] = 0; |
2590 | 2721 | } |
2591 | 2722 | |
2592 | - if (!empty($board) && $id_board == $board) |
|
2593 | - $parents = $board_info['parent_boards']; |
|
2594 | - else |
|
2595 | - $parents = getBoardParents($id_board); |
|
2723 | + if (!empty($board) && $id_board == $board) { |
|
2724 | + $parents = $board_info['parent_boards']; |
|
2725 | + } else { |
|
2726 | + $parents = getBoardParents($id_board); |
|
2727 | + } |
|
2596 | 2728 | |
2597 | 2729 | // Ignore any parents on the top child level. |
2598 | 2730 | // @todo Why? |
@@ -2601,10 +2733,11 @@ discard block |
||
2601 | 2733 | if ($parent['level'] != 0) |
2602 | 2734 | { |
2603 | 2735 | // If we're already doing this one as a board, is this a higher last modified? |
2604 | - if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) |
|
2605 | - $lastModified[$id] = $lastModified[$id_board]; |
|
2606 | - elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) |
|
2607 | - $parent_boards[$id] = $lastModified[$id_board]; |
|
2736 | + if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) { |
|
2737 | + $lastModified[$id] = $lastModified[$id_board]; |
|
2738 | + } elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) { |
|
2739 | + $parent_boards[$id] = $lastModified[$id_board]; |
|
2740 | + } |
|
2608 | 2741 | } |
2609 | 2742 | } |
2610 | 2743 | } |
@@ -2617,23 +2750,24 @@ discard block |
||
2617 | 2750 | // Finally, to save on queries make the changes... |
2618 | 2751 | foreach ($parent_boards as $id => $msg) |
2619 | 2752 | { |
2620 | - if (!isset($parent_updates[$msg])) |
|
2621 | - $parent_updates[$msg] = array($id); |
|
2622 | - else |
|
2623 | - $parent_updates[$msg][] = $id; |
|
2753 | + if (!isset($parent_updates[$msg])) { |
|
2754 | + $parent_updates[$msg] = array($id); |
|
2755 | + } else { |
|
2756 | + $parent_updates[$msg][] = $id; |
|
2757 | + } |
|
2624 | 2758 | } |
2625 | 2759 | |
2626 | 2760 | foreach ($lastMsg as $id => $msg) |
2627 | 2761 | { |
2628 | - if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) |
|
2629 | - $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2762 | + if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) { |
|
2763 | + $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2630 | 2764 | 'id' => $msg, |
2631 | 2765 | 'updated' => $lastModified[$id], |
2632 | 2766 | 'boards' => array($id) |
2633 | 2767 | ); |
2634 | - |
|
2635 | - else |
|
2636 | - $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2768 | + } else { |
|
2769 | + $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2770 | + } |
|
2637 | 2771 | } |
2638 | 2772 | |
2639 | 2773 | // Now commit the changes! |
@@ -2725,11 +2859,13 @@ discard block |
||
2725 | 2859 | global $txt, $mbname, $scripturl, $settings; |
2726 | 2860 | |
2727 | 2861 | // First things first, load up the email templates language file, if we need to. |
2728 | - if ($loadLang) |
|
2729 | - loadLanguage('EmailTemplates', $lang); |
|
2862 | + if ($loadLang) { |
|
2863 | + loadLanguage('EmailTemplates', $lang); |
|
2864 | + } |
|
2730 | 2865 | |
2731 | - if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) |
|
2732 | - fatal_lang_error('email_no_template', 'template', array($template)); |
|
2866 | + if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) { |
|
2867 | + fatal_lang_error('email_no_template', 'template', array($template)); |
|
2868 | + } |
|
2733 | 2869 | |
2734 | 2870 | $ret = array( |
2735 | 2871 | 'subject' => $txt[$template . '_subject'], |
@@ -2779,17 +2915,18 @@ discard block |
||
2779 | 2915 | function user_info_callback($matches) |
2780 | 2916 | { |
2781 | 2917 | global $user_info; |
2782 | - if (empty($matches[1])) |
|
2783 | - return ''; |
|
2918 | + if (empty($matches[1])) { |
|
2919 | + return ''; |
|
2920 | + } |
|
2784 | 2921 | |
2785 | 2922 | $use_ref = true; |
2786 | 2923 | $ref = &$user_info; |
2787 | 2924 | |
2788 | 2925 | foreach (explode('.', $matches[1]) as $index) |
2789 | 2926 | { |
2790 | - if ($use_ref && isset($ref[$index])) |
|
2791 | - $ref = &$ref[$index]; |
|
2792 | - else |
|
2927 | + if ($use_ref && isset($ref[$index])) { |
|
2928 | + $ref = &$ref[$index]; |
|
2929 | + } else |
|
2793 | 2930 | { |
2794 | 2931 | $use_ref = false; |
2795 | 2932 | break; |
@@ -2826,8 +2963,7 @@ discard block |
||
2826 | 2963 | if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale)) |
2827 | 2964 | { |
2828 | 2965 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale); |
2829 | - } |
|
2830 | - elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2966 | + } elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2831 | 2967 | { |
2832 | 2968 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']); |
2833 | 2969 | } |
@@ -2837,8 +2973,7 @@ discard block |
||
2837 | 2973 | { |
2838 | 2974 | $context['provider'] = 'enchant'; |
2839 | 2975 | return $enchant_link; |
2840 | - } |
|
2841 | - else |
|
2976 | + } else |
|
2842 | 2977 | { |
2843 | 2978 | // Free up any resources used... |
2844 | 2979 | @enchant_broker_free($context['enchant_broker']); |
@@ -2859,8 +2994,9 @@ discard block |
||
2859 | 2994 | $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER); |
2860 | 2995 | |
2861 | 2996 | // Most people don't have anything but English installed... So we use English as a last resort. |
2862 | - if (!$pspell_link) |
|
2863 | - $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
2997 | + if (!$pspell_link) { |
|
2998 | + $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
2999 | + } |
|
2864 | 3000 | |
2865 | 3001 | error_reporting($old); |
2866 | 3002 | ob_end_clean(); |
@@ -2900,8 +3036,7 @@ discard block |
||
2900 | 3036 | $word = iconv($txt['lang_character_set'], 'UTF-8', $word); |
2901 | 3037 | } |
2902 | 3038 | return enchant_dict_check($dict, $word); |
2903 | - } |
|
2904 | - elseif ($context['provider'] == 'pspell') |
|
3039 | + } elseif ($context['provider'] == 'pspell') |
|
2905 | 3040 | { |
2906 | 3041 | return pspell_check($dict, $word); |
2907 | 3042 | } |
@@ -2937,13 +3072,11 @@ discard block |
||
2937 | 3072 | } |
2938 | 3073 | |
2939 | 3074 | return $suggestions; |
2940 | - } |
|
2941 | - else |
|
3075 | + } else |
|
2942 | 3076 | { |
2943 | 3077 | return enchant_dict_suggest($dict, $word); |
2944 | 3078 | } |
2945 | - } |
|
2946 | - elseif ($context['provider'] == 'pspell') |
|
3079 | + } elseif ($context['provider'] == 'pspell') |
|
2947 | 3080 | { |
2948 | 3081 | return pspell_suggest($dict, $word); |
2949 | 3082 | } |