@@ -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,15 +49,17 @@ 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 | list($in_tag, $had_tag, $codeopen, $alltags, $codes) = array(false, false, 0, array(), array()); |
57 | - if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) |
|
58 | - foreach ($matches[0] as $index => $dummy) |
|
61 | + if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) { |
|
62 | + foreach ($matches[0] as $index => $dummy) |
|
59 | 63 | { |
60 | 64 | // Closing? |
61 | 65 | if (!empty($matches[2][$index])) |
@@ -63,6 +67,7 @@ discard block |
||
63 | 67 | // If it's closing and we're not in a tag we need to open it... |
64 | 68 | if (!$in_tag) |
65 | 69 | $codeopen = true; |
70 | + } |
|
66 | 71 | // Either way we ain't in one any more. |
67 | 72 | $in_tag = false; |
68 | 73 | } |
@@ -71,17 +76,20 @@ discard block |
||
71 | 76 | { |
72 | 77 | $had_tag = true; |
73 | 78 | // If we're in a tag don't do nought! |
74 | - if (!$in_tag) |
|
75 | - $in_tag = true; |
|
79 | + if (!$in_tag) { |
|
80 | + $in_tag = true; |
|
81 | + } |
|
76 | 82 | } |
77 | 83 | } |
78 | 84 | |
79 | 85 | // If we have an open tag, close it. |
80 | - if ($in_tag) |
|
81 | - $message .= '[/code]'; |
|
86 | + if ($in_tag) { |
|
87 | + $message .= '[/code]'; |
|
88 | + } |
|
82 | 89 | // Open any ones that need to be open, only if we've never had a tag. |
83 | - if ($codeopen && !$had_tag) |
|
84 | - $message = '[code]' . $message; |
|
90 | + if ($codeopen && !$had_tag) { |
|
91 | + $message = '[code]' . $message; |
|
92 | + } |
|
85 | 93 | |
86 | 94 | // Now that we've fixed all the code tags, let's fix the img and url tags... |
87 | 95 | $parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE); |
@@ -107,23 +115,26 @@ discard block |
||
107 | 115 | fixTags($message); |
108 | 116 | |
109 | 117 | // Replace /me.+?\n with [me=name]dsf[/me]\n. |
110 | - if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) |
|
111 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
112 | - else |
|
113 | - $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
118 | + if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) { |
|
119 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me="' . $user_info['name'] . '"]$2[/me]', $message); |
|
120 | + } else { |
|
121 | + $message = preg_replace('~(\A|\n)/me(?: | )([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message); |
|
122 | + } |
|
114 | 123 | |
115 | 124 | if (!$previewing && strpos($message, '[html]') !== false) |
116 | 125 | { |
117 | - if (allowedTo('admin_forum')) |
|
118 | - $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) { |
|
126 | + if (allowedTo('admin_forum')) { |
|
127 | + $message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) { |
|
119 | 128 | return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => ' ', ' ' => '  ', '[' => '[', ']' => ']')) . '[/html]'; |
129 | + } |
|
120 | 130 | }, $message); |
121 | 131 | |
122 | 132 | // We should edit them out, or else if an admin edits the message they will get shown... |
123 | 133 | else |
124 | 134 | { |
125 | - while (strpos($message, '[html]') !== false) |
|
126 | - $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
135 | + while (strpos($message, '[html]') !== false) { |
|
136 | + $message = preg_replace('~\[[/]?html\]~i', '', $message); |
|
137 | + } |
|
127 | 138 | } |
128 | 139 | } |
129 | 140 | |
@@ -145,10 +156,12 @@ discard block |
||
145 | 156 | |
146 | 157 | $list_open = substr_count($message, '[list]') + substr_count($message, '[list '); |
147 | 158 | $list_close = substr_count($message, '[/list]'); |
148 | - if ($list_close - $list_open > 0) |
|
149 | - $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
150 | - if ($list_open - $list_close > 0) |
|
151 | - $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
159 | + if ($list_close - $list_open > 0) { |
|
160 | + $message = str_repeat('[list]', $list_close - $list_open) . $message; |
|
161 | + } |
|
162 | + if ($list_open - $list_close > 0) { |
|
163 | + $message = $message . str_repeat('[/list]', $list_open - $list_close); |
|
164 | + } |
|
152 | 165 | |
153 | 166 | $mistake_fixes = array( |
154 | 167 | // Find [table]s not followed by [tr]. |
@@ -197,8 +210,9 @@ discard block |
||
197 | 210 | ); |
198 | 211 | |
199 | 212 | // Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.) |
200 | - for ($j = 0; $j < 3; $j++) |
|
201 | - $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
213 | + for ($j = 0; $j < 3; $j++) { |
|
214 | + $message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message); |
|
215 | + } |
|
202 | 216 | |
203 | 217 | // Remove empty bbc from the sections outside the code tags |
204 | 218 | $allowedEmpty = array( |
@@ -208,24 +222,28 @@ discard block |
||
208 | 222 | |
209 | 223 | require_once($sourcedir . '/Subs.php'); |
210 | 224 | |
211 | - foreach ($codes as $code) |
|
212 | - if (!in_array($code['tag'], $allowedEmpty)) |
|
225 | + foreach ($codes as $code) { |
|
226 | + if (!in_array($code['tag'], $allowedEmpty)) |
|
213 | 227 | $alltags[] = $code['tag']; |
228 | + } |
|
214 | 229 | |
215 | 230 | $alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b'; |
216 | 231 | |
217 | - while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) |
|
218 | - $message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message); |
|
232 | + while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) { |
|
233 | + $message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message); |
|
234 | + } |
|
219 | 235 | |
220 | 236 | // Restore code blocks |
221 | - if (!empty($code_tags)) |
|
222 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
237 | + if (!empty($code_tags)) { |
|
238 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
239 | + } |
|
223 | 240 | |
224 | 241 | // Restore white space entities |
225 | - if (!$previewing) |
|
226 | - $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
227 | - else |
|
228 | - $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
242 | + if (!$previewing) { |
|
243 | + $message = strtr($message, array(' ' => ' ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
244 | + } else { |
|
245 | + $message = strtr($message, array(' ' => ' ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' ')); |
|
246 | + } |
|
229 | 247 | |
230 | 248 | // Now let's quickly clean up things that will slow our parser (which are common in posted code.) |
231 | 249 | $message = strtr($message, array('[]' => '[]', '['' => '['')); |
@@ -268,8 +286,9 @@ discard block |
||
268 | 286 | return "[time]" . timeformat("$m[1]", false) . "[/time]"; |
269 | 287 | }, $message); |
270 | 288 | |
271 | - if (!empty($code_tags)) |
|
272 | - $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
289 | + if (!empty($code_tags)) { |
|
290 | + $message = str_replace(array_keys($code_tags), array_values($code_tags), $message); |
|
291 | + } |
|
273 | 292 | |
274 | 293 | // Change breaks back to \n's and &nsbp; back to spaces. |
275 | 294 | return preg_replace('~<br( /)?' . '>~', "\n", str_replace(' ', ' ', $message)); |
@@ -350,8 +369,9 @@ discard block |
||
350 | 369 | ); |
351 | 370 | |
352 | 371 | // Fix each type of tag. |
353 | - foreach ($fixArray as $param) |
|
354 | - fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
372 | + foreach ($fixArray as $param) { |
|
373 | + fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra'])); |
|
374 | + } |
|
355 | 375 | |
356 | 376 | // Now fix possible security problems with images loading links automatically... |
357 | 377 | $message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m) |
@@ -387,16 +407,19 @@ discard block |
||
387 | 407 | $desired_height = $height; |
388 | 408 | } |
389 | 409 | // Scale it to the width... |
390 | - elseif (empty($desired_width) && !empty($height)) |
|
391 | - $desired_width = (int) (($desired_height * $width) / $height); |
|
410 | + elseif (empty($desired_width) && !empty($height)) { |
|
411 | + $desired_width = (int) (($desired_height * $width) / $height); |
|
412 | + } |
|
392 | 413 | // Scale if to the height. |
393 | - elseif (!empty($width)) |
|
394 | - $desired_height = (int) (($desired_width * $height) / $width); |
|
414 | + elseif (!empty($width)) { |
|
415 | + $desired_height = (int) (($desired_width * $height) / $width); |
|
416 | + } |
|
395 | 417 | } |
396 | 418 | |
397 | 419 | // If the width and height are fine, just continue along... |
398 | - if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) |
|
399 | - continue; |
|
420 | + if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) { |
|
421 | + continue; |
|
422 | + } |
|
400 | 423 | |
401 | 424 | // Too bad, it's too wide. Make it as wide as the maximum. |
402 | 425 | if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width'])) |
@@ -416,8 +439,9 @@ discard block |
||
416 | 439 | } |
417 | 440 | |
418 | 441 | // If any img tags were actually changed... |
419 | - if (!empty($replaces)) |
|
420 | - $message = strtr($message, $replaces); |
|
442 | + if (!empty($replaces)) { |
|
443 | + $message = strtr($message, $replaces); |
|
444 | + } |
|
421 | 445 | } |
422 | 446 | } |
423 | 447 | |
@@ -436,10 +460,11 @@ discard block |
||
436 | 460 | { |
437 | 461 | global $boardurl, $scripturl; |
438 | 462 | |
439 | - if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) |
|
440 | - $domain_url = $match[1]; |
|
441 | - else |
|
442 | - $domain_url = $boardurl . '/'; |
|
463 | + if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) { |
|
464 | + $domain_url = $match[1]; |
|
465 | + } else { |
|
466 | + $domain_url = $boardurl . '/'; |
|
467 | + } |
|
443 | 468 | |
444 | 469 | $replaces = array(); |
445 | 470 | |
@@ -447,11 +472,11 @@ discard block |
||
447 | 472 | { |
448 | 473 | $quoted = preg_match('~\[(' . $myTag . ')="~', $message); |
449 | 474 | preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '"(.*?)"' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
475 | + } elseif ($hasEqualSign) { |
|
476 | + preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
477 | + } else { |
|
478 | + preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
450 | 479 | } |
451 | - elseif ($hasEqualSign) |
|
452 | - preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches); |
|
453 | - else |
|
454 | - preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches); |
|
455 | 480 | |
456 | 481 | foreach ($matches[0] as $k => $dummy) |
457 | 482 | { |
@@ -464,49 +489,53 @@ discard block |
||
464 | 489 | foreach ($protocols as $protocol) |
465 | 490 | { |
466 | 491 | $found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0; |
467 | - if ($found) |
|
468 | - break; |
|
492 | + if ($found) { |
|
493 | + break; |
|
494 | + } |
|
469 | 495 | } |
470 | 496 | |
471 | 497 | if (!$found && $protocols[0] == 'http') |
472 | 498 | { |
473 | - if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') |
|
474 | - $replace = $domain_url . $replace; |
|
475 | - elseif (substr($replace, 0, 1) == '?') |
|
476 | - $replace = $scripturl . $replace; |
|
477 | - elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
499 | + if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') { |
|
500 | + $replace = $domain_url . $replace; |
|
501 | + } elseif (substr($replace, 0, 1) == '?') { |
|
502 | + $replace = $scripturl . $replace; |
|
503 | + } elseif (substr($replace, 0, 1) == '#' && $embeddedUrl) |
|
478 | 504 | { |
479 | 505 | $replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1)); |
480 | 506 | $this_tag = 'iurl'; |
481 | 507 | $this_close = 'iurl'; |
508 | + } elseif (substr($replace, 0, 2) != '//') { |
|
509 | + $replace = $protocols[0] . '://' . $replace; |
|
482 | 510 | } |
483 | - elseif (substr($replace, 0, 2) != '//') |
|
484 | - $replace = $protocols[0] . '://' . $replace; |
|
485 | - } |
|
486 | - elseif (!$found && $protocols[0] == 'ftp') |
|
487 | - $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
488 | - elseif (!$found) |
|
489 | - $replace = $protocols[0] . '://' . $replace; |
|
490 | - |
|
491 | - if ($hasEqualSign && $embeddedUrl) |
|
492 | - $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
493 | - elseif ($hasEqualSign) |
|
494 | - $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
495 | - elseif ($embeddedUrl) |
|
496 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
497 | - else |
|
498 | - $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
511 | + } elseif (!$found && $protocols[0] == 'ftp') { |
|
512 | + $replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace); |
|
513 | + } elseif (!$found) { |
|
514 | + $replace = $protocols[0] . '://' . $replace; |
|
515 | + } |
|
516 | + |
|
517 | + if ($hasEqualSign && $embeddedUrl) { |
|
518 | + $replaces[$matches[0][$k]] = '[' . $this_tag . '="' . $replace . '"]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']'); |
|
519 | + } elseif ($hasEqualSign) { |
|
520 | + $replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']'; |
|
521 | + } elseif ($embeddedUrl) { |
|
522 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']'; |
|
523 | + } else { |
|
524 | + $replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']'; |
|
525 | + } |
|
499 | 526 | } |
500 | 527 | |
501 | 528 | foreach ($replaces as $k => $v) |
502 | 529 | { |
503 | - if ($k == $v) |
|
504 | - unset($replaces[$k]); |
|
530 | + if ($k == $v) { |
|
531 | + unset($replaces[$k]); |
|
532 | + } |
|
505 | 533 | } |
506 | 534 | |
507 | - if (!empty($replaces)) |
|
508 | - $message = strtr($message, $replaces); |
|
509 | -} |
|
535 | + if (!empty($replaces)) { |
|
536 | + $message = strtr($message, $replaces); |
|
537 | + } |
|
538 | + } |
|
510 | 539 | |
511 | 540 | /** |
512 | 541 | * This function sends an email to the specified recipient(s). |
@@ -550,8 +579,9 @@ discard block |
||
550 | 579 | } |
551 | 580 | |
552 | 581 | // Nothing left? Nothing else to do |
553 | - if (empty($to_array)) |
|
554 | - return true; |
|
582 | + if (empty($to_array)) { |
|
583 | + return true; |
|
584 | + } |
|
555 | 585 | |
556 | 586 | // Once upon a time, Hotmail could not interpret non-ASCII mails. |
557 | 587 | // In honour of those days, it's still called the 'hotmail fix'. |
@@ -568,15 +598,17 @@ discard block |
||
568 | 598 | } |
569 | 599 | |
570 | 600 | // Call this function recursively for the hotmail addresses. |
571 | - if (!empty($hotmail_to)) |
|
572 | - $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
601 | + if (!empty($hotmail_to)) { |
|
602 | + $mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private); |
|
603 | + } |
|
573 | 604 | |
574 | 605 | // The remaining addresses no longer need the fix. |
575 | 606 | $hotmail_fix = false; |
576 | 607 | |
577 | 608 | // No other addresses left? Return instantly. |
578 | - if (empty($to_array)) |
|
579 | - return $mail_result; |
|
609 | + if (empty($to_array)) { |
|
610 | + return $mail_result; |
|
611 | + } |
|
580 | 612 | } |
581 | 613 | |
582 | 614 | // Get rid of entities. |
@@ -601,13 +633,15 @@ discard block |
||
601 | 633 | $headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break; |
602 | 634 | $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break; |
603 | 635 | |
604 | - if ($message_id !== null && empty($modSettings['mail_no_message_id'])) |
|
605 | - $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
636 | + if ($message_id !== null && empty($modSettings['mail_no_message_id'])) { |
|
637 | + $headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break; |
|
638 | + } |
|
606 | 639 | $headers .= 'X-Mailer: SMF' . $line_break; |
607 | 640 | |
608 | 641 | // Pass this to the integration before we start modifying the output -- it'll make it easier later. |
609 | - if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) |
|
610 | - return false; |
|
642 | + if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) { |
|
643 | + return false; |
|
644 | + } |
|
611 | 645 | |
612 | 646 | // Save the original message... |
613 | 647 | $orig_message = $message; |
@@ -656,17 +690,19 @@ discard block |
||
656 | 690 | } |
657 | 691 | |
658 | 692 | // Are we using the mail queue, if so this is where we butt in... |
659 | - if ($priority != 0) |
|
660 | - return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
693 | + if ($priority != 0) { |
|
694 | + return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private); |
|
695 | + } |
|
661 | 696 | |
662 | 697 | // If it's a priority mail, send it now - note though that this should NOT be used for sending many at once. |
663 | 698 | elseif (!empty($modSettings['mail_limit'])) |
664 | 699 | { |
665 | 700 | list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']); |
666 | - if (empty($mails_this_minute) || time() > $last_mail_time + 60) |
|
667 | - $new_queue_stat = time() . '|' . 1; |
|
668 | - else |
|
669 | - $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
701 | + if (empty($mails_this_minute) || time() > $last_mail_time + 60) { |
|
702 | + $new_queue_stat = time() . '|' . 1; |
|
703 | + } else { |
|
704 | + $new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1); |
|
705 | + } |
|
670 | 706 | |
671 | 707 | updateSettings(array('mail_recent' => $new_queue_stat)); |
672 | 708 | } |
@@ -691,12 +727,13 @@ discard block |
||
691 | 727 | |
692 | 728 | // Wait, wait, I'm still sending here! |
693 | 729 | @set_time_limit(300); |
694 | - if (function_exists('apache_reset_timeout')) |
|
695 | - @apache_reset_timeout(); |
|
730 | + if (function_exists('apache_reset_timeout')) { |
|
731 | + @apache_reset_timeout(); |
|
732 | + } |
|
696 | 733 | } |
734 | + } else { |
|
735 | + $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
697 | 736 | } |
698 | - else |
|
699 | - $mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers); |
|
700 | 737 | |
701 | 738 | // Everything go smoothly? |
702 | 739 | return $mail_result; |
@@ -722,8 +759,9 @@ discard block |
||
722 | 759 | static $cur_insert = array(); |
723 | 760 | static $cur_insert_len = 0; |
724 | 761 | |
725 | - if ($cur_insert_len == 0) |
|
726 | - $cur_insert = array(); |
|
762 | + if ($cur_insert_len == 0) { |
|
763 | + $cur_insert = array(); |
|
764 | + } |
|
727 | 765 | |
728 | 766 | // If we're flushing, make the final inserts - also if we're near the MySQL length limit! |
729 | 767 | if (($flush || $cur_insert_len > 800000) && !empty($cur_insert)) |
@@ -798,8 +836,9 @@ discard block |
||
798 | 836 | } |
799 | 837 | |
800 | 838 | // If they are using SSI there is a good chance obExit will never be called. So lets be nice and flush it for them. |
801 | - if (SMF === 'SSI' || SMF === 'BACKGROUND') |
|
802 | - return AddMailQueue(true); |
|
839 | + if (SMF === 'SSI' || SMF === 'BACKGROUND') { |
|
840 | + return AddMailQueue(true); |
|
841 | + } |
|
803 | 842 | |
804 | 843 | return true; |
805 | 844 | } |
@@ -830,23 +869,26 @@ discard block |
||
830 | 869 | 'sent' => array() |
831 | 870 | ); |
832 | 871 | |
833 | - if ($from === null) |
|
834 | - $from = array( |
|
872 | + if ($from === null) { |
|
873 | + $from = array( |
|
835 | 874 | 'id' => $user_info['id'], |
836 | 875 | 'name' => $user_info['name'], |
837 | 876 | 'username' => $user_info['username'] |
838 | 877 | ); |
878 | + } |
|
839 | 879 | |
840 | 880 | // This is the one that will go in their inbox. |
841 | 881 | $htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES); |
842 | 882 | preparsecode($htmlmessage); |
843 | 883 | $htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => '')); |
844 | - if ($smcFunc['strlen']($htmlsubject) > 100) |
|
845 | - $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
884 | + if ($smcFunc['strlen']($htmlsubject) > 100) { |
|
885 | + $htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100); |
|
886 | + } |
|
846 | 887 | |
847 | 888 | // Make sure is an array |
848 | - if (!is_array($recipients)) |
|
849 | - $recipients = array($recipients); |
|
889 | + if (!is_array($recipients)) { |
|
890 | + $recipients = array($recipients); |
|
891 | + } |
|
850 | 892 | |
851 | 893 | // Integrated PMs |
852 | 894 | call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message)); |
@@ -874,21 +916,23 @@ discard block |
||
874 | 916 | 'usernames' => array_keys($usernames), |
875 | 917 | ) |
876 | 918 | ); |
877 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
878 | - if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
919 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
920 | + if (isset($usernames[$smcFunc['strtolower']($row['member_name'])])) |
|
879 | 921 | $usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member']; |
922 | + } |
|
880 | 923 | $smcFunc['db_free_result']($request); |
881 | 924 | |
882 | 925 | // Replace the usernames with IDs. Drop usernames that couldn't be found. |
883 | - foreach ($recipients as $rec_type => $rec) |
|
884 | - foreach ($rec as $id => $member) |
|
926 | + foreach ($recipients as $rec_type => $rec) { |
|
927 | + foreach ($rec as $id => $member) |
|
885 | 928 | { |
886 | 929 | if (is_numeric($recipients[$rec_type][$id])) |
887 | 930 | continue; |
931 | + } |
|
888 | 932 | |
889 | - if (!empty($usernames[$member])) |
|
890 | - $recipients[$rec_type][$id] = $usernames[$member]; |
|
891 | - else |
|
933 | + if (!empty($usernames[$member])) { |
|
934 | + $recipients[$rec_type][$id] = $usernames[$member]; |
|
935 | + } else |
|
892 | 936 | { |
893 | 937 | $log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]); |
894 | 938 | unset($recipients[$rec_type][$id]); |
@@ -926,8 +970,9 @@ discard block |
||
926 | 970 | $delete = false; |
927 | 971 | foreach ($criteria as $criterium) |
928 | 972 | { |
929 | - 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)) |
|
930 | - $delete = true; |
|
973 | + 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)) { |
|
974 | + $delete = true; |
|
975 | + } |
|
931 | 976 | // If we're adding and one criteria don't match then we stop! |
932 | 977 | elseif (!$row['is_or']) |
933 | 978 | { |
@@ -935,8 +980,9 @@ discard block |
||
935 | 980 | break; |
936 | 981 | } |
937 | 982 | } |
938 | - if ($delete) |
|
939 | - $deletes[$row['id_member']] = 1; |
|
983 | + if ($delete) { |
|
984 | + $deletes[$row['id_member']] = 1; |
|
985 | + } |
|
940 | 986 | } |
941 | 987 | $smcFunc['db_free_result']($request); |
942 | 988 | |
@@ -951,8 +997,9 @@ discard block |
||
951 | 997 | array( |
952 | 998 | ) |
953 | 999 | ); |
954 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
955 | - $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
1000 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1001 | + $message_limit_cache[$row['id_group']] = $row['max_messages']; |
|
1002 | + } |
|
956 | 1003 | $smcFunc['db_free_result']($request); |
957 | 1004 | } |
958 | 1005 | |
@@ -960,8 +1007,9 @@ discard block |
||
960 | 1007 | require_once($sourcedir . '/Subs-Members.php'); |
961 | 1008 | $pmReadGroups = groupsAllowedTo('pm_read'); |
962 | 1009 | |
963 | - if (empty($modSettings['permission_enable_deny'])) |
|
964 | - $pmReadGroups['denied'] = array(); |
|
1010 | + if (empty($modSettings['permission_enable_deny'])) { |
|
1011 | + $pmReadGroups['denied'] = array(); |
|
1012 | + } |
|
965 | 1013 | |
966 | 1014 | // Load their alert preferences |
967 | 1015 | require_once($sourcedir . '/Subs-Notify.php'); |
@@ -993,8 +1041,9 @@ discard block |
||
993 | 1041 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
994 | 1042 | { |
995 | 1043 | // Don't do anything for members to be deleted! |
996 | - if (isset($deletes[$row['id_member']])) |
|
997 | - continue; |
|
1044 | + if (isset($deletes[$row['id_member']])) { |
|
1045 | + continue; |
|
1046 | + } |
|
998 | 1047 | |
999 | 1048 | // Load the preferences for this member (if any) |
1000 | 1049 | $prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array(); |
@@ -1015,8 +1064,9 @@ discard block |
||
1015 | 1064 | { |
1016 | 1065 | foreach ($groups as $id) |
1017 | 1066 | { |
1018 | - if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) |
|
1019 | - $message_limit = $message_limit_cache[$id]; |
|
1067 | + if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) { |
|
1068 | + $message_limit = $message_limit_cache[$id]; |
|
1069 | + } |
|
1020 | 1070 | } |
1021 | 1071 | |
1022 | 1072 | if ($message_limit > 0 && $message_limit <= $row['instant_messages']) |
@@ -1064,8 +1114,9 @@ discard block |
||
1064 | 1114 | $smcFunc['db_free_result']($request); |
1065 | 1115 | |
1066 | 1116 | // Only 'send' the message if there are any recipients left. |
1067 | - if (empty($all_to)) |
|
1068 | - return $log; |
|
1117 | + if (empty($all_to)) { |
|
1118 | + return $log; |
|
1119 | + } |
|
1069 | 1120 | |
1070 | 1121 | // Insert the message itself and then grab the last insert id. |
1071 | 1122 | $id_pm = $smcFunc['db_insert']('', |
@@ -1086,8 +1137,8 @@ discard block |
||
1086 | 1137 | if (!empty($id_pm)) |
1087 | 1138 | { |
1088 | 1139 | // If this is new we need to set it part of it's own conversation. |
1089 | - if (empty($pm_head)) |
|
1090 | - $smcFunc['db_query']('', ' |
|
1140 | + if (empty($pm_head)) { |
|
1141 | + $smcFunc['db_query']('', ' |
|
1091 | 1142 | UPDATE {db_prefix}personal_messages |
1092 | 1143 | SET id_pm_head = {int:id_pm_head} |
1093 | 1144 | WHERE id_pm = {int:id_pm_head}', |
@@ -1095,6 +1146,7 @@ discard block |
||
1095 | 1146 | 'id_pm_head' => $id_pm, |
1096 | 1147 | ) |
1097 | 1148 | ); |
1149 | + } |
|
1098 | 1150 | |
1099 | 1151 | // Some people think manually deleting personal_messages is fun... it's not. We protect against it though :) |
1100 | 1152 | $smcFunc['db_query']('', ' |
@@ -1110,8 +1162,9 @@ discard block |
||
1110 | 1162 | foreach ($all_to as $to) |
1111 | 1163 | { |
1112 | 1164 | $insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1); |
1113 | - if (!in_array($to, $recipients['bcc'])) |
|
1114 | - $to_list[] = $to; |
|
1165 | + if (!in_array($to, $recipients['bcc'])) { |
|
1166 | + $to_list[] = $to; |
|
1167 | + } |
|
1115 | 1168 | } |
1116 | 1169 | |
1117 | 1170 | $smcFunc['db_insert']('insert', |
@@ -1129,9 +1182,9 @@ discard block |
||
1129 | 1182 | { |
1130 | 1183 | censorText($message); |
1131 | 1184 | $message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '[' => '[', ']' => ']'))))); |
1185 | + } else { |
|
1186 | + $message = ''; |
|
1132 | 1187 | } |
1133 | - else |
|
1134 | - $message = ''; |
|
1135 | 1188 | |
1136 | 1189 | $to_names = array(); |
1137 | 1190 | if (count($to_list) > 1) |
@@ -1144,8 +1197,9 @@ discard block |
||
1144 | 1197 | 'to_members' => $to_list, |
1145 | 1198 | ) |
1146 | 1199 | ); |
1147 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1148 | - $to_names[] = un_htmlspecialchars($row['real_name']); |
|
1200 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1201 | + $to_names[] = un_htmlspecialchars($row['real_name']); |
|
1202 | + } |
|
1149 | 1203 | $smcFunc['db_free_result']($request); |
1150 | 1204 | } |
1151 | 1205 | $replacements = array( |
@@ -1173,11 +1227,13 @@ discard block |
||
1173 | 1227 | loadLanguage('index+PersonalMessage'); |
1174 | 1228 | |
1175 | 1229 | // Add one to their unread and read message counts. |
1176 | - foreach ($all_to as $k => $id) |
|
1177 | - if (isset($deletes[$id])) |
|
1230 | + foreach ($all_to as $k => $id) { |
|
1231 | + if (isset($deletes[$id])) |
|
1178 | 1232 | unset($all_to[$k]); |
1179 | - if (!empty($all_to)) |
|
1180 | - updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
1233 | + } |
|
1234 | + if (!empty($all_to)) { |
|
1235 | + updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1)); |
|
1236 | + } |
|
1181 | 1237 | |
1182 | 1238 | return $log; |
1183 | 1239 | } |
@@ -1207,15 +1263,17 @@ discard block |
||
1207 | 1263 | // Let's, for now, assume there are only 'ish characters. |
1208 | 1264 | $simple = true; |
1209 | 1265 | |
1210 | - foreach ($matches[1] as $entity) |
|
1211 | - if ($entity > 128) |
|
1266 | + foreach ($matches[1] as $entity) { |
|
1267 | + if ($entity > 128) |
|
1212 | 1268 | $simple = false; |
1269 | + } |
|
1213 | 1270 | unset($matches); |
1214 | 1271 | |
1215 | - if ($simple) |
|
1216 | - $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
1272 | + if ($simple) { |
|
1273 | + $string = preg_replace_callback('~&#(\d{3,8});~', function($m) |
|
1217 | 1274 | { |
1218 | 1275 | return chr("$m[1]"); |
1276 | + } |
|
1219 | 1277 | }, $string); |
1220 | 1278 | else |
1221 | 1279 | { |
@@ -1223,8 +1281,9 @@ discard block |
||
1223 | 1281 | if (!$context['utf8'] && function_exists('iconv')) |
1224 | 1282 | { |
1225 | 1283 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
1226 | - if ($newstring) |
|
1227 | - $string = $newstring; |
|
1284 | + if ($newstring) { |
|
1285 | + $string = $newstring; |
|
1286 | + } |
|
1228 | 1287 | } |
1229 | 1288 | |
1230 | 1289 | $string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string); |
@@ -1240,23 +1299,25 @@ discard block |
||
1240 | 1299 | if (!$context['utf8'] && function_exists('iconv')) |
1241 | 1300 | { |
1242 | 1301 | $newstring = @iconv($context['character_set'], 'UTF-8', $string); |
1243 | - if ($newstring) |
|
1244 | - $string = $newstring; |
|
1302 | + if ($newstring) { |
|
1303 | + $string = $newstring; |
|
1304 | + } |
|
1245 | 1305 | } |
1246 | 1306 | |
1247 | 1307 | $entityConvert = function($m) |
1248 | 1308 | { |
1249 | 1309 | $c = $m[1]; |
1250 | - if (strlen($c) === 1 && ord($c[0]) <= 0x7F) |
|
1251 | - return $c; |
|
1252 | - elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) |
|
1253 | - return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
1254 | - elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) |
|
1255 | - return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
1256 | - elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) |
|
1257 | - return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
1258 | - else |
|
1259 | - return ""; |
|
1310 | + if (strlen($c) === 1 && ord($c[0]) <= 0x7F) { |
|
1311 | + return $c; |
|
1312 | + } elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) { |
|
1313 | + return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";"; |
|
1314 | + } elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) { |
|
1315 | + return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";"; |
|
1316 | + } elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) { |
|
1317 | + return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";"; |
|
1318 | + } else { |
|
1319 | + return ""; |
|
1320 | + } |
|
1260 | 1321 | }; |
1261 | 1322 | |
1262 | 1323 | // Convert all 'special' characters to HTML entities. |
@@ -1270,19 +1331,20 @@ discard block |
||
1270 | 1331 | $string = base64_encode($string); |
1271 | 1332 | |
1272 | 1333 | // Show the characterset and the transfer-encoding for header strings. |
1273 | - if ($with_charset) |
|
1274 | - $string = '=?' . $charset . '?B?' . $string . '?='; |
|
1334 | + if ($with_charset) { |
|
1335 | + $string = '=?' . $charset . '?B?' . $string . '?='; |
|
1336 | + } |
|
1275 | 1337 | |
1276 | 1338 | // Break it up in lines (mail body). |
1277 | - else |
|
1278 | - $string = chunk_split($string, 76, $line_break); |
|
1339 | + else { |
|
1340 | + $string = chunk_split($string, 76, $line_break); |
|
1341 | + } |
|
1279 | 1342 | |
1280 | 1343 | return array($charset, $string, 'base64'); |
1344 | + } else { |
|
1345 | + return array($charset, $string, '7bit'); |
|
1346 | + } |
|
1281 | 1347 | } |
1282 | - |
|
1283 | - else |
|
1284 | - return array($charset, $string, '7bit'); |
|
1285 | -} |
|
1286 | 1348 | |
1287 | 1349 | /** |
1288 | 1350 | * Sends mail, like mail() but over SMTP. |
@@ -1306,8 +1368,9 @@ discard block |
||
1306 | 1368 | if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
1307 | 1369 | { |
1308 | 1370 | $socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2); |
1309 | - if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) |
|
1310 | - $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
1371 | + if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) { |
|
1372 | + $socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2); |
|
1373 | + } |
|
1311 | 1374 | |
1312 | 1375 | if ($socket) |
1313 | 1376 | { |
@@ -1328,8 +1391,9 @@ discard block |
||
1328 | 1391 | // Maybe we can still save this? The port might be wrong. |
1329 | 1392 | if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25)) |
1330 | 1393 | { |
1331 | - if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) |
|
1332 | - log_error($txt['smtp_port_ssl']); |
|
1394 | + if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) { |
|
1395 | + log_error($txt['smtp_port_ssl']); |
|
1396 | + } |
|
1333 | 1397 | } |
1334 | 1398 | |
1335 | 1399 | // Unable to connect! Don't show any error message, but just log one and try to continue anyway. |
@@ -1341,20 +1405,23 @@ discard block |
||
1341 | 1405 | } |
1342 | 1406 | |
1343 | 1407 | // Wait for a response of 220, without "-" continuer. |
1344 | - if (!server_parse(null, $socket, '220')) |
|
1345 | - return false; |
|
1408 | + if (!server_parse(null, $socket, '220')) { |
|
1409 | + return false; |
|
1410 | + } |
|
1346 | 1411 | |
1347 | 1412 | // Try and determine the servers name, fall back to the mail servers if not found |
1348 | 1413 | $helo = false; |
1349 | - if (function_exists('gethostname') && gethostname() !== false) |
|
1350 | - $helo = gethostname(); |
|
1351 | - elseif (function_exists('php_uname')) |
|
1352 | - $helo = php_uname('n'); |
|
1353 | - elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) |
|
1354 | - $helo = $_SERVER['SERVER_NAME']; |
|
1414 | + if (function_exists('gethostname') && gethostname() !== false) { |
|
1415 | + $helo = gethostname(); |
|
1416 | + } elseif (function_exists('php_uname')) { |
|
1417 | + $helo = php_uname('n'); |
|
1418 | + } elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) { |
|
1419 | + $helo = $_SERVER['SERVER_NAME']; |
|
1420 | + } |
|
1355 | 1421 | |
1356 | - if (empty($helo)) |
|
1357 | - $helo = $modSettings['smtp_host']; |
|
1422 | + if (empty($helo)) { |
|
1423 | + $helo = $modSettings['smtp_host']; |
|
1424 | + } |
|
1358 | 1425 | |
1359 | 1426 | // SMTP = 1, SMTP - STARTTLS = 2 |
1360 | 1427 | if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '') |
@@ -1366,33 +1433,39 @@ discard block |
||
1366 | 1433 | if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response)) |
1367 | 1434 | { |
1368 | 1435 | // Send STARTTLS to enable encryption |
1369 | - if (!server_parse('STARTTLS', $socket, '220')) |
|
1370 | - return false; |
|
1436 | + if (!server_parse('STARTTLS', $socket, '220')) { |
|
1437 | + return false; |
|
1438 | + } |
|
1371 | 1439 | // Enable the encryption |
1372 | - if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) |
|
1373 | - return false; |
|
1440 | + if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) { |
|
1441 | + return false; |
|
1442 | + } |
|
1374 | 1443 | // Send the EHLO command again |
1375 | - if (!server_parse('EHLO ' . $helo, $socket, null) == '250') |
|
1376 | - return false; |
|
1444 | + if (!server_parse('EHLO ' . $helo, $socket, null) == '250') { |
|
1445 | + return false; |
|
1446 | + } |
|
1377 | 1447 | } |
1378 | 1448 | |
1379 | - if (!server_parse('AUTH LOGIN', $socket, '334')) |
|
1380 | - return false; |
|
1449 | + if (!server_parse('AUTH LOGIN', $socket, '334')) { |
|
1450 | + return false; |
|
1451 | + } |
|
1381 | 1452 | // Send the username and password, encoded. |
1382 | - if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) |
|
1383 | - return false; |
|
1453 | + if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) { |
|
1454 | + return false; |
|
1455 | + } |
|
1384 | 1456 | // The password is already encoded ;) |
1385 | - if (!server_parse($modSettings['smtp_password'], $socket, '235')) |
|
1386 | - return false; |
|
1457 | + if (!server_parse($modSettings['smtp_password'], $socket, '235')) { |
|
1458 | + return false; |
|
1459 | + } |
|
1460 | + } elseif (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1461 | + return false; |
|
1387 | 1462 | } |
1388 | - elseif (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1389 | - return false; |
|
1390 | - } |
|
1391 | - else |
|
1463 | + } else |
|
1392 | 1464 | { |
1393 | 1465 | // Just say "helo". |
1394 | - if (!server_parse('HELO ' . $helo, $socket, '250')) |
|
1395 | - return false; |
|
1466 | + if (!server_parse('HELO ' . $helo, $socket, '250')) { |
|
1467 | + return false; |
|
1468 | + } |
|
1396 | 1469 | } |
1397 | 1470 | |
1398 | 1471 | // Fix the message for any lines beginning with a period! (the first is ignored, you see.) |
@@ -1405,31 +1478,38 @@ discard block |
||
1405 | 1478 | // Reset the connection to send another email. |
1406 | 1479 | if ($i != 0) |
1407 | 1480 | { |
1408 | - if (!server_parse('RSET', $socket, '250')) |
|
1409 | - return false; |
|
1481 | + if (!server_parse('RSET', $socket, '250')) { |
|
1482 | + return false; |
|
1483 | + } |
|
1410 | 1484 | } |
1411 | 1485 | |
1412 | 1486 | // From, to, and then start the data... |
1413 | - if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) |
|
1414 | - return false; |
|
1415 | - if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) |
|
1416 | - return false; |
|
1417 | - if (!server_parse('DATA', $socket, '354')) |
|
1418 | - return false; |
|
1487 | + if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) { |
|
1488 | + return false; |
|
1489 | + } |
|
1490 | + if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) { |
|
1491 | + return false; |
|
1492 | + } |
|
1493 | + if (!server_parse('DATA', $socket, '354')) { |
|
1494 | + return false; |
|
1495 | + } |
|
1419 | 1496 | fputs($socket, 'Subject: ' . $subject . "\r\n"); |
1420 | - if (strlen($mail_to) > 0) |
|
1421 | - fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1497 | + if (strlen($mail_to) > 0) { |
|
1498 | + fputs($socket, 'To: <' . $mail_to . '>' . "\r\n"); |
|
1499 | + } |
|
1422 | 1500 | fputs($socket, $headers . "\r\n\r\n"); |
1423 | 1501 | fputs($socket, $message . "\r\n"); |
1424 | 1502 | |
1425 | 1503 | // Send a ., or in other words "end of data". |
1426 | - if (!server_parse('.', $socket, '250')) |
|
1427 | - return false; |
|
1504 | + if (!server_parse('.', $socket, '250')) { |
|
1505 | + return false; |
|
1506 | + } |
|
1428 | 1507 | |
1429 | 1508 | // Almost done, almost done... don't stop me just yet! |
1430 | 1509 | @set_time_limit(300); |
1431 | - if (function_exists('apache_reset_timeout')) |
|
1432 | - @apache_reset_timeout(); |
|
1510 | + if (function_exists('apache_reset_timeout')) { |
|
1511 | + @apache_reset_timeout(); |
|
1512 | + } |
|
1433 | 1513 | } |
1434 | 1514 | fputs($socket, 'QUIT' . "\r\n"); |
1435 | 1515 | fclose($socket); |
@@ -1453,8 +1533,9 @@ discard block |
||
1453 | 1533 | { |
1454 | 1534 | global $txt; |
1455 | 1535 | |
1456 | - if ($message !== null) |
|
1457 | - fputs($socket, $message . "\r\n"); |
|
1536 | + if ($message !== null) { |
|
1537 | + fputs($socket, $message . "\r\n"); |
|
1538 | + } |
|
1458 | 1539 | |
1459 | 1540 | // No response yet. |
1460 | 1541 | $server_response = ''; |
@@ -1470,8 +1551,9 @@ discard block |
||
1470 | 1551 | $response .= $server_response; |
1471 | 1552 | } |
1472 | 1553 | |
1473 | - if ($code === null) |
|
1474 | - return substr($server_response, 0, 3); |
|
1554 | + if ($code === null) { |
|
1555 | + return substr($server_response, 0, 3); |
|
1556 | + } |
|
1475 | 1557 | |
1476 | 1558 | if (substr($server_response, 0, 3) != $code) |
1477 | 1559 | { |
@@ -1501,8 +1583,9 @@ discard block |
||
1501 | 1583 | // Create a pspell or enchant dictionary resource |
1502 | 1584 | $dict = spell_init(); |
1503 | 1585 | |
1504 | - if (!isset($_POST['spellstring']) || !$dict) |
|
1505 | - die; |
|
1586 | + if (!isset($_POST['spellstring']) || !$dict) { |
|
1587 | + die; |
|
1588 | + } |
|
1506 | 1589 | |
1507 | 1590 | // Construct a bit of Javascript code. |
1508 | 1591 | $context['spell_js'] = ' |
@@ -1520,8 +1603,9 @@ discard block |
||
1520 | 1603 | $check_word = explode('|', $alphas[$i]); |
1521 | 1604 | |
1522 | 1605 | // If the word is a known word, or spelled right... |
1523 | - if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) |
|
1524 | - continue; |
|
1606 | + if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) { |
|
1607 | + continue; |
|
1608 | + } |
|
1525 | 1609 | |
1526 | 1610 | // Find the word, and move up the "last occurrence" to here. |
1527 | 1611 | $found_words = true; |
@@ -1535,20 +1619,23 @@ discard block |
||
1535 | 1619 | if (!empty($suggestions)) |
1536 | 1620 | { |
1537 | 1621 | // But first check they aren't going to be censored - no naughty words! |
1538 | - foreach ($suggestions as $k => $word) |
|
1539 | - if ($suggestions[$k] != censorText($word)) |
|
1622 | + foreach ($suggestions as $k => $word) { |
|
1623 | + if ($suggestions[$k] != censorText($word)) |
|
1540 | 1624 | unset($suggestions[$k]); |
1625 | + } |
|
1541 | 1626 | |
1542 | - if (!empty($suggestions)) |
|
1543 | - $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1627 | + if (!empty($suggestions)) { |
|
1628 | + $context['spell_js'] .= '"' . implode('", "', $suggestions) . '"'; |
|
1629 | + } |
|
1544 | 1630 | } |
1545 | 1631 | |
1546 | 1632 | $context['spell_js'] .= ']),'; |
1547 | 1633 | } |
1548 | 1634 | |
1549 | 1635 | // If words were found, take off the last comma. |
1550 | - if ($found_words) |
|
1551 | - $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1636 | + if ($found_words) { |
|
1637 | + $context['spell_js'] = substr($context['spell_js'], 0, -1); |
|
1638 | + } |
|
1552 | 1639 | |
1553 | 1640 | $context['spell_js'] .= ' |
1554 | 1641 | );'; |
@@ -1583,11 +1670,13 @@ discard block |
||
1583 | 1670 | global $user_info, $smcFunc; |
1584 | 1671 | |
1585 | 1672 | // Can't do it if there's no topics. |
1586 | - if (empty($topics)) |
|
1587 | - return; |
|
1673 | + if (empty($topics)) { |
|
1674 | + return; |
|
1675 | + } |
|
1588 | 1676 | // It must be an array - it must! |
1589 | - if (!is_array($topics)) |
|
1590 | - $topics = array($topics); |
|
1677 | + if (!is_array($topics)) { |
|
1678 | + $topics = array($topics); |
|
1679 | + } |
|
1591 | 1680 | |
1592 | 1681 | // Get the subject and body... |
1593 | 1682 | $result = $smcFunc['db_query']('', ' |
@@ -1635,14 +1724,15 @@ discard block |
||
1635 | 1724 | } |
1636 | 1725 | $smcFunc['db_free_result']($result); |
1637 | 1726 | |
1638 | - if (!empty($task_rows)) |
|
1639 | - $smcFunc['db_insert']('', |
|
1727 | + if (!empty($task_rows)) { |
|
1728 | + $smcFunc['db_insert']('', |
|
1640 | 1729 | '{db_prefix}background_tasks', |
1641 | 1730 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1642 | 1731 | $task_rows, |
1643 | 1732 | array('id_task') |
1644 | 1733 | ); |
1645 | -} |
|
1734 | + } |
|
1735 | + } |
|
1646 | 1736 | |
1647 | 1737 | /** |
1648 | 1738 | * Create a post, either as new topic (id_topic = 0) or in an existing one. |
@@ -1680,9 +1770,9 @@ discard block |
||
1680 | 1770 | $msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true; |
1681 | 1771 | |
1682 | 1772 | // We need to know if the topic is approved. If we're told that's great - if not find out. |
1683 | - if (!$modSettings['postmod_active']) |
|
1684 | - $topicOptions['is_approved'] = true; |
|
1685 | - elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1773 | + if (!$modSettings['postmod_active']) { |
|
1774 | + $topicOptions['is_approved'] = true; |
|
1775 | + } elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved'])) |
|
1686 | 1776 | { |
1687 | 1777 | $request = $smcFunc['db_query']('', ' |
1688 | 1778 | SELECT approved |
@@ -1705,8 +1795,7 @@ discard block |
||
1705 | 1795 | $posterOptions['id'] = 0; |
1706 | 1796 | $posterOptions['name'] = $txt['guest_title']; |
1707 | 1797 | $posterOptions['email'] = ''; |
1708 | - } |
|
1709 | - elseif ($posterOptions['id'] != $user_info['id']) |
|
1798 | + } elseif ($posterOptions['id'] != $user_info['id']) |
|
1710 | 1799 | { |
1711 | 1800 | $request = $smcFunc['db_query']('', ' |
1712 | 1801 | SELECT member_name, email_address |
@@ -1724,12 +1813,11 @@ discard block |
||
1724 | 1813 | $posterOptions['id'] = 0; |
1725 | 1814 | $posterOptions['name'] = $txt['guest_title']; |
1726 | 1815 | $posterOptions['email'] = ''; |
1816 | + } else { |
|
1817 | + list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1727 | 1818 | } |
1728 | - else |
|
1729 | - list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request); |
|
1730 | 1819 | $smcFunc['db_free_result']($request); |
1731 | - } |
|
1732 | - else |
|
1820 | + } else |
|
1733 | 1821 | { |
1734 | 1822 | $posterOptions['name'] = $user_info['name']; |
1735 | 1823 | $posterOptions['email'] = $user_info['email']; |
@@ -1739,8 +1827,9 @@ discard block |
||
1739 | 1827 | if (!empty($modSettings['enable_mentions'])) |
1740 | 1828 | { |
1741 | 1829 | $msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']); |
1742 | - if (!empty($msgOptions['mentioned_members'])) |
|
1743 | - $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1830 | + if (!empty($msgOptions['mentioned_members'])) { |
|
1831 | + $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']); |
|
1832 | + } |
|
1744 | 1833 | } |
1745 | 1834 | |
1746 | 1835 | // It's do or die time: forget any user aborts! |
@@ -1773,12 +1862,13 @@ discard block |
||
1773 | 1862 | ); |
1774 | 1863 | |
1775 | 1864 | // Something went wrong creating the message... |
1776 | - if (empty($msgOptions['id'])) |
|
1777 | - return false; |
|
1865 | + if (empty($msgOptions['id'])) { |
|
1866 | + return false; |
|
1867 | + } |
|
1778 | 1868 | |
1779 | 1869 | // Fix the attachments. |
1780 | - if (!empty($msgOptions['attachments'])) |
|
1781 | - $smcFunc['db_query']('', ' |
|
1870 | + if (!empty($msgOptions['attachments'])) { |
|
1871 | + $smcFunc['db_query']('', ' |
|
1782 | 1872 | UPDATE {db_prefix}attachments |
1783 | 1873 | SET id_msg = {int:id_msg} |
1784 | 1874 | WHERE id_attach IN ({array_int:attachment_list})', |
@@ -1787,6 +1877,7 @@ discard block |
||
1787 | 1877 | 'id_msg' => $msgOptions['id'], |
1788 | 1878 | ) |
1789 | 1879 | ); |
1880 | + } |
|
1790 | 1881 | |
1791 | 1882 | // What if we want to export new posts out to a CMS? |
1792 | 1883 | call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters)); |
@@ -1863,20 +1954,23 @@ discard block |
||
1863 | 1954 | 'id_topic' => $topicOptions['id'], |
1864 | 1955 | 'counter_increment' => 1, |
1865 | 1956 | ); |
1866 | - if ($msgOptions['approved']) |
|
1867 | - $topics_columns = array( |
|
1957 | + if ($msgOptions['approved']) { |
|
1958 | + $topics_columns = array( |
|
1868 | 1959 | 'id_member_updated = {int:poster_id}', |
1869 | 1960 | 'id_last_msg = {int:id_msg}', |
1870 | 1961 | 'num_replies = num_replies + {int:counter_increment}', |
1871 | 1962 | ); |
1872 | - else |
|
1873 | - $topics_columns = array( |
|
1963 | + } else { |
|
1964 | + $topics_columns = array( |
|
1874 | 1965 | 'unapproved_posts = unapproved_posts + {int:counter_increment}', |
1875 | 1966 | ); |
1876 | - if ($topicOptions['lock_mode'] !== null) |
|
1877 | - $topics_columns[] = 'locked = {int:locked}'; |
|
1878 | - if ($topicOptions['sticky_mode'] !== null) |
|
1879 | - $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1967 | + } |
|
1968 | + if ($topicOptions['lock_mode'] !== null) { |
|
1969 | + $topics_columns[] = 'locked = {int:locked}'; |
|
1970 | + } |
|
1971 | + if ($topicOptions['sticky_mode'] !== null) { |
|
1972 | + $topics_columns[] = 'is_sticky = {int:is_sticky}'; |
|
1973 | + } |
|
1880 | 1974 | |
1881 | 1975 | call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions)); |
1882 | 1976 | |
@@ -1905,8 +1999,8 @@ discard block |
||
1905 | 1999 | ); |
1906 | 2000 | |
1907 | 2001 | // Increase the number of posts and topics on the board. |
1908 | - if ($msgOptions['approved']) |
|
1909 | - $smcFunc['db_query']('', ' |
|
2002 | + if ($msgOptions['approved']) { |
|
2003 | + $smcFunc['db_query']('', ' |
|
1910 | 2004 | UPDATE {db_prefix}boards |
1911 | 2005 | SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . ' |
1912 | 2006 | WHERE id_board = {int:id_board}', |
@@ -1914,7 +2008,7 @@ discard block |
||
1914 | 2008 | 'id_board' => $topicOptions['board'], |
1915 | 2009 | ) |
1916 | 2010 | ); |
1917 | - else |
|
2011 | + } else |
|
1918 | 2012 | { |
1919 | 2013 | $smcFunc['db_query']('', ' |
1920 | 2014 | UPDATE {db_prefix}boards |
@@ -1984,8 +2078,8 @@ discard block |
||
1984 | 2078 | } |
1985 | 2079 | } |
1986 | 2080 | |
1987 | - if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) |
|
1988 | - $smcFunc['db_insert']('', |
|
2081 | + if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) { |
|
2082 | + $smcFunc['db_insert']('', |
|
1989 | 2083 | '{db_prefix}background_tasks', |
1990 | 2084 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
1991 | 2085 | array( |
@@ -1997,19 +2091,22 @@ discard block |
||
1997 | 2091 | ), |
1998 | 2092 | array('id_task') |
1999 | 2093 | ); |
2094 | + } |
|
2000 | 2095 | |
2001 | 2096 | // If there's a custom search index, it may need updating... |
2002 | 2097 | require_once($sourcedir . '/Search.php'); |
2003 | 2098 | $searchAPI = findSearchAPI(); |
2004 | - if (is_callable(array($searchAPI, 'postCreated'))) |
|
2005 | - $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2099 | + if (is_callable(array($searchAPI, 'postCreated'))) { |
|
2100 | + $searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions); |
|
2101 | + } |
|
2006 | 2102 | |
2007 | 2103 | // Increase the post counter for the user that created the post. |
2008 | 2104 | if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved']) |
2009 | 2105 | { |
2010 | 2106 | // Are you the one that happened to create this post? |
2011 | - if ($user_info['id'] == $posterOptions['id']) |
|
2012 | - $user_info['posts']++; |
|
2107 | + if ($user_info['id'] == $posterOptions['id']) { |
|
2108 | + $user_info['posts']++; |
|
2109 | + } |
|
2013 | 2110 | updateMemberData($posterOptions['id'], array('posts' => '+')); |
2014 | 2111 | } |
2015 | 2112 | |
@@ -2017,19 +2114,21 @@ discard block |
||
2017 | 2114 | $_SESSION['last_read_topic'] = 0; |
2018 | 2115 | |
2019 | 2116 | // Better safe than sorry. |
2020 | - if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) |
|
2021 | - $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2117 | + if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) { |
|
2118 | + $_SESSION['topicseen_cache'][$topicOptions['board']]--; |
|
2119 | + } |
|
2022 | 2120 | |
2023 | 2121 | // Update all the stats so everyone knows about this new topic and message. |
2024 | 2122 | updateStats('message', true, $msgOptions['id']); |
2025 | 2123 | |
2026 | 2124 | // Update the last message on the board assuming it's approved AND the topic is. |
2027 | - if ($msgOptions['approved']) |
|
2028 | - updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2125 | + if ($msgOptions['approved']) { |
|
2126 | + updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0); |
|
2127 | + } |
|
2029 | 2128 | |
2030 | 2129 | // Queue createPost background notification |
2031 | - if ($msgOptions['send_notifications'] && $msgOptions['approved']) |
|
2032 | - $smcFunc['db_insert']('', |
|
2130 | + if ($msgOptions['send_notifications'] && $msgOptions['approved']) { |
|
2131 | + $smcFunc['db_insert']('', |
|
2033 | 2132 | '{db_prefix}background_tasks', |
2034 | 2133 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2035 | 2134 | array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array( |
@@ -2040,6 +2139,7 @@ discard block |
||
2040 | 2139 | )), 0), |
2041 | 2140 | array('id_task') |
2042 | 2141 | ); |
2142 | + } |
|
2043 | 2143 | |
2044 | 2144 | // Alright, done now... we can abort now, I guess... at least this much is done. |
2045 | 2145 | ignore_user_abort($previous_ignore_user_abort); |
@@ -2066,14 +2166,18 @@ discard block |
||
2066 | 2166 | |
2067 | 2167 | // This is longer than it has to be, but makes it so we only set/change what we have to. |
2068 | 2168 | $messages_columns = array(); |
2069 | - if (isset($posterOptions['name'])) |
|
2070 | - $messages_columns['poster_name'] = $posterOptions['name']; |
|
2071 | - if (isset($posterOptions['email'])) |
|
2072 | - $messages_columns['poster_email'] = $posterOptions['email']; |
|
2073 | - if (isset($msgOptions['icon'])) |
|
2074 | - $messages_columns['icon'] = $msgOptions['icon']; |
|
2075 | - if (isset($msgOptions['subject'])) |
|
2076 | - $messages_columns['subject'] = $msgOptions['subject']; |
|
2169 | + if (isset($posterOptions['name'])) { |
|
2170 | + $messages_columns['poster_name'] = $posterOptions['name']; |
|
2171 | + } |
|
2172 | + if (isset($posterOptions['email'])) { |
|
2173 | + $messages_columns['poster_email'] = $posterOptions['email']; |
|
2174 | + } |
|
2175 | + if (isset($msgOptions['icon'])) { |
|
2176 | + $messages_columns['icon'] = $msgOptions['icon']; |
|
2177 | + } |
|
2178 | + if (isset($msgOptions['subject'])) { |
|
2179 | + $messages_columns['subject'] = $msgOptions['subject']; |
|
2180 | + } |
|
2077 | 2181 | if (isset($msgOptions['body'])) |
2078 | 2182 | { |
2079 | 2183 | $messages_columns['body'] = $msgOptions['body']; |
@@ -2100,8 +2204,9 @@ discard block |
||
2100 | 2204 | $messages_columns['modified_reason'] = $msgOptions['modify_reason']; |
2101 | 2205 | $messages_columns['id_msg_modified'] = $modSettings['maxMsgID']; |
2102 | 2206 | } |
2103 | - if (isset($msgOptions['smileys_enabled'])) |
|
2104 | - $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2207 | + if (isset($msgOptions['smileys_enabled'])) { |
|
2208 | + $messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1; |
|
2209 | + } |
|
2105 | 2210 | |
2106 | 2211 | // Which columns need to be ints? |
2107 | 2212 | $messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled'); |
@@ -2119,23 +2224,27 @@ discard block |
||
2119 | 2224 | { |
2120 | 2225 | preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match); |
2121 | 2226 | |
2122 | - if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) |
|
2123 | - foreach ($match[1] as $i => $oldID) |
|
2227 | + if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) { |
|
2228 | + foreach ($match[1] as $i => $oldID) |
|
2124 | 2229 | $oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]); |
2230 | + } |
|
2125 | 2231 | |
2126 | - if (empty($modSettings['search_custom_index_config'])) |
|
2127 | - unset($msgOptions['old_body']); |
|
2232 | + if (empty($modSettings['search_custom_index_config'])) { |
|
2233 | + unset($msgOptions['old_body']); |
|
2234 | + } |
|
2128 | 2235 | } |
2129 | 2236 | |
2130 | 2237 | $mentions = Mentions::getMentionedMembers($msgOptions['body']); |
2131 | 2238 | $messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions); |
2132 | 2239 | |
2133 | 2240 | // Remove the poster. |
2134 | - if (isset($mentions[$user_info['id']])) |
|
2135 | - unset($mentions[$user_info['id']]); |
|
2241 | + if (isset($mentions[$user_info['id']])) { |
|
2242 | + unset($mentions[$user_info['id']]); |
|
2243 | + } |
|
2136 | 2244 | |
2137 | - if (isset($oldmentions[$user_info['id']])) |
|
2138 | - unset($oldmentions[$user_info['id']]); |
|
2245 | + if (isset($oldmentions[$user_info['id']])) { |
|
2246 | + unset($oldmentions[$user_info['id']]); |
|
2247 | + } |
|
2139 | 2248 | |
2140 | 2249 | if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions)) |
2141 | 2250 | { |
@@ -2165,8 +2274,9 @@ discard block |
||
2165 | 2274 | } |
2166 | 2275 | |
2167 | 2276 | // Nothing to do? |
2168 | - if (empty($messages_columns)) |
|
2169 | - return true; |
|
2277 | + if (empty($messages_columns)) { |
|
2278 | + return true; |
|
2279 | + } |
|
2170 | 2280 | |
2171 | 2281 | // Change the post. |
2172 | 2282 | $smcFunc['db_query']('', ' |
@@ -2227,8 +2337,9 @@ discard block |
||
2227 | 2337 | // If there's a custom search index, it needs to be modified... |
2228 | 2338 | require_once($sourcedir . '/Search.php'); |
2229 | 2339 | $searchAPI = findSearchAPI(); |
2230 | - if (is_callable(array($searchAPI, 'postModified'))) |
|
2231 | - $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2340 | + if (is_callable(array($searchAPI, 'postModified'))) { |
|
2341 | + $searchAPI->postModified($msgOptions, $topicOptions, $posterOptions); |
|
2342 | + } |
|
2232 | 2343 | |
2233 | 2344 | if (isset($msgOptions['subject'])) |
2234 | 2345 | { |
@@ -2242,14 +2353,16 @@ discard block |
||
2242 | 2353 | 'id_first_msg' => $msgOptions['id'], |
2243 | 2354 | ) |
2244 | 2355 | ); |
2245 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
2246 | - updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2356 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
2357 | + updateStats('subject', $topicOptions['id'], $msgOptions['subject']); |
|
2358 | + } |
|
2247 | 2359 | $smcFunc['db_free_result']($request); |
2248 | 2360 | } |
2249 | 2361 | |
2250 | 2362 | // Finally, if we are setting the approved state we need to do much more work :( |
2251 | - if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) |
|
2252 | - approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2363 | + if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) { |
|
2364 | + approvePosts($msgOptions['id'], $msgOptions['approved']); |
|
2365 | + } |
|
2253 | 2366 | |
2254 | 2367 | return true; |
2255 | 2368 | } |
@@ -2266,11 +2379,13 @@ discard block |
||
2266 | 2379 | { |
2267 | 2380 | global $smcFunc; |
2268 | 2381 | |
2269 | - if (!is_array($msgs)) |
|
2270 | - $msgs = array($msgs); |
|
2382 | + if (!is_array($msgs)) { |
|
2383 | + $msgs = array($msgs); |
|
2384 | + } |
|
2271 | 2385 | |
2272 | - if (empty($msgs)) |
|
2273 | - return false; |
|
2386 | + if (empty($msgs)) { |
|
2387 | + return false; |
|
2388 | + } |
|
2274 | 2389 | |
2275 | 2390 | // May as well start at the beginning, working out *what* we need to change. |
2276 | 2391 | $request = $smcFunc['db_query']('', ' |
@@ -2302,20 +2417,22 @@ discard block |
||
2302 | 2417 | $topics[] = $row['id_topic']; |
2303 | 2418 | |
2304 | 2419 | // Ensure our change array exists already. |
2305 | - if (!isset($topic_changes[$row['id_topic']])) |
|
2306 | - $topic_changes[$row['id_topic']] = array( |
|
2420 | + if (!isset($topic_changes[$row['id_topic']])) { |
|
2421 | + $topic_changes[$row['id_topic']] = array( |
|
2307 | 2422 | 'id_last_msg' => $row['id_last_msg'], |
2308 | 2423 | 'approved' => $row['topic_approved'], |
2309 | 2424 | 'replies' => 0, |
2310 | 2425 | 'unapproved_posts' => 0, |
2311 | 2426 | ); |
2312 | - if (!isset($board_changes[$row['id_board']])) |
|
2313 | - $board_changes[$row['id_board']] = array( |
|
2427 | + } |
|
2428 | + if (!isset($board_changes[$row['id_board']])) { |
|
2429 | + $board_changes[$row['id_board']] = array( |
|
2314 | 2430 | 'posts' => 0, |
2315 | 2431 | 'topics' => 0, |
2316 | 2432 | 'unapproved_posts' => 0, |
2317 | 2433 | 'unapproved_topics' => 0, |
2318 | 2434 | ); |
2435 | + } |
|
2319 | 2436 | |
2320 | 2437 | // If it's the first message then the topic state changes! |
2321 | 2438 | if ($row['id_msg'] == $row['id_first_msg']) |
@@ -2336,14 +2453,13 @@ discard block |
||
2336 | 2453 | 'poster' => $row['id_member'], |
2337 | 2454 | 'new_topic' => true, |
2338 | 2455 | ); |
2339 | - } |
|
2340 | - else |
|
2456 | + } else |
|
2341 | 2457 | { |
2342 | 2458 | $topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1; |
2343 | 2459 | |
2344 | 2460 | // This will be a post... but don't notify unless it's not followed by approved ones. |
2345 | - if ($row['id_msg'] > $row['id_last_msg']) |
|
2346 | - $notification_posts[$row['id_topic']] = array( |
|
2461 | + if ($row['id_msg'] > $row['id_last_msg']) { |
|
2462 | + $notification_posts[$row['id_topic']] = array( |
|
2347 | 2463 | 'id' => $row['id_msg'], |
2348 | 2464 | 'body' => $row['body'], |
2349 | 2465 | 'subject' => $row['subject'], |
@@ -2354,28 +2470,33 @@ discard block |
||
2354 | 2470 | 'new_topic' => false, |
2355 | 2471 | 'msg' => $row['id_msg'], |
2356 | 2472 | ); |
2473 | + } |
|
2357 | 2474 | } |
2358 | 2475 | |
2359 | 2476 | // If this is being approved and id_msg is higher than the current id_last_msg then it changes. |
2360 | - if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) |
|
2361 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2477 | + if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) { |
|
2478 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg']; |
|
2479 | + } |
|
2362 | 2480 | // If this is being unapproved, and it's equal to the id_last_msg we need to find a new one! |
2363 | - elseif (!$approve) |
|
2364 | - // Default to the first message and then we'll override in a bit ;) |
|
2481 | + elseif (!$approve) { |
|
2482 | + // Default to the first message and then we'll override in a bit ;) |
|
2365 | 2483 | $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg']; |
2484 | + } |
|
2366 | 2485 | |
2367 | 2486 | $topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1; |
2368 | 2487 | $board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1; |
2369 | 2488 | $board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1; |
2370 | 2489 | |
2371 | 2490 | // Post count for the user? |
2372 | - if ($row['id_member'] && empty($row['count_posts'])) |
|
2373 | - $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2491 | + if ($row['id_member'] && empty($row['count_posts'])) { |
|
2492 | + $member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1; |
|
2493 | + } |
|
2374 | 2494 | } |
2375 | 2495 | $smcFunc['db_free_result']($request); |
2376 | 2496 | |
2377 | - if (empty($msgs)) |
|
2378 | - return; |
|
2497 | + if (empty($msgs)) { |
|
2498 | + return; |
|
2499 | + } |
|
2379 | 2500 | |
2380 | 2501 | // Now we have the differences make the changes, first the easy one. |
2381 | 2502 | $smcFunc['db_query']('', ' |
@@ -2402,14 +2523,15 @@ discard block |
||
2402 | 2523 | 'approved' => 1, |
2403 | 2524 | ) |
2404 | 2525 | ); |
2405 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2406 | - $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2526 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2527 | + $topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg']; |
|
2528 | + } |
|
2407 | 2529 | $smcFunc['db_free_result']($request); |
2408 | 2530 | } |
2409 | 2531 | |
2410 | 2532 | // ... next the topics... |
2411 | - foreach ($topic_changes as $id => $changes) |
|
2412 | - $smcFunc['db_query']('', ' |
|
2533 | + foreach ($topic_changes as $id => $changes) { |
|
2534 | + $smcFunc['db_query']('', ' |
|
2413 | 2535 | UPDATE {db_prefix}topics |
2414 | 2536 | SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2415 | 2537 | num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg} |
@@ -2422,10 +2544,11 @@ discard block |
||
2422 | 2544 | 'id_topic' => $id, |
2423 | 2545 | ) |
2424 | 2546 | ); |
2547 | + } |
|
2425 | 2548 | |
2426 | 2549 | // ... finally the boards... |
2427 | - foreach ($board_changes as $id => $changes) |
|
2428 | - $smcFunc['db_query']('', ' |
|
2550 | + foreach ($board_changes as $id => $changes) { |
|
2551 | + $smcFunc['db_query']('', ' |
|
2429 | 2552 | UPDATE {db_prefix}boards |
2430 | 2553 | SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts}, |
2431 | 2554 | num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics} |
@@ -2438,13 +2561,14 @@ discard block |
||
2438 | 2561 | 'id_board' => $id, |
2439 | 2562 | ) |
2440 | 2563 | ); |
2564 | + } |
|
2441 | 2565 | |
2442 | 2566 | // Finally, least importantly, notifications! |
2443 | 2567 | if ($approve) |
2444 | 2568 | { |
2445 | 2569 | $task_rows = array(); |
2446 | - foreach (array_merge($notification_topics, $notification_posts) as $topic) |
|
2447 | - $task_rows[] = array( |
|
2570 | + foreach (array_merge($notification_topics, $notification_posts) as $topic) { |
|
2571 | + $task_rows[] = array( |
|
2448 | 2572 | '$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array( |
2449 | 2573 | 'msgOptions' => array( |
2450 | 2574 | 'id' => $topic['msg'], |
@@ -2462,14 +2586,16 @@ discard block |
||
2462 | 2586 | 'type' => $topic['new_topic'] ? 'topic' : 'reply', |
2463 | 2587 | )), 0 |
2464 | 2588 | ); |
2589 | + } |
|
2465 | 2590 | |
2466 | - if ($notify) |
|
2467 | - $smcFunc['db_insert']('', |
|
2591 | + if ($notify) { |
|
2592 | + $smcFunc['db_insert']('', |
|
2468 | 2593 | '{db_prefix}background_tasks', |
2469 | 2594 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
2470 | 2595 | $task_rows, |
2471 | 2596 | array('id_task') |
2472 | 2597 | ); |
2598 | + } |
|
2473 | 2599 | |
2474 | 2600 | $smcFunc['db_query']('', ' |
2475 | 2601 | DELETE FROM {db_prefix}approval_queue |
@@ -2485,8 +2611,9 @@ discard block |
||
2485 | 2611 | else |
2486 | 2612 | { |
2487 | 2613 | $msgInserts = array(); |
2488 | - foreach ($msgs as $msg) |
|
2489 | - $msgInserts[] = array($msg); |
|
2614 | + foreach ($msgs as $msg) { |
|
2615 | + $msgInserts[] = array($msg); |
|
2616 | + } |
|
2490 | 2617 | |
2491 | 2618 | $smcFunc['db_insert']('ignore', |
2492 | 2619 | '{db_prefix}approval_queue', |
@@ -2500,9 +2627,10 @@ discard block |
||
2500 | 2627 | updateLastMessages(array_keys($board_changes)); |
2501 | 2628 | |
2502 | 2629 | // Post count for the members? |
2503 | - if (!empty($member_post_changes)) |
|
2504 | - foreach ($member_post_changes as $id_member => $count_change) |
|
2630 | + if (!empty($member_post_changes)) { |
|
2631 | + foreach ($member_post_changes as $id_member => $count_change) |
|
2505 | 2632 | updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change)); |
2633 | + } |
|
2506 | 2634 | |
2507 | 2635 | return true; |
2508 | 2636 | } |
@@ -2519,11 +2647,13 @@ discard block |
||
2519 | 2647 | { |
2520 | 2648 | global $smcFunc; |
2521 | 2649 | |
2522 | - if (!is_array($topics)) |
|
2523 | - $topics = array($topics); |
|
2650 | + if (!is_array($topics)) { |
|
2651 | + $topics = array($topics); |
|
2652 | + } |
|
2524 | 2653 | |
2525 | - if (empty($topics)) |
|
2526 | - return false; |
|
2654 | + if (empty($topics)) { |
|
2655 | + return false; |
|
2656 | + } |
|
2527 | 2657 | |
2528 | 2658 | $approve_type = $approve ? 0 : 1; |
2529 | 2659 | |
@@ -2539,8 +2669,9 @@ discard block |
||
2539 | 2669 | ) |
2540 | 2670 | ); |
2541 | 2671 | $msgs = array(); |
2542 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2543 | - $msgs[] = $row['id_msg']; |
|
2672 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2673 | + $msgs[] = $row['id_msg']; |
|
2674 | + } |
|
2544 | 2675 | $smcFunc['db_free_result']($request); |
2545 | 2676 | |
2546 | 2677 | return approvePosts($msgs, $approve); |
@@ -2563,11 +2694,13 @@ discard block |
||
2563 | 2694 | global $board_info, $board, $smcFunc; |
2564 | 2695 | |
2565 | 2696 | // Please - let's be sane. |
2566 | - if (empty($setboards)) |
|
2567 | - return false; |
|
2697 | + if (empty($setboards)) { |
|
2698 | + return false; |
|
2699 | + } |
|
2568 | 2700 | |
2569 | - if (!is_array($setboards)) |
|
2570 | - $setboards = array($setboards); |
|
2701 | + if (!is_array($setboards)) { |
|
2702 | + $setboards = array($setboards); |
|
2703 | + } |
|
2571 | 2704 | |
2572 | 2705 | // If we don't know the id_msg we need to find it. |
2573 | 2706 | if (!$id_msg) |
@@ -2585,15 +2718,16 @@ discard block |
||
2585 | 2718 | ) |
2586 | 2719 | ); |
2587 | 2720 | $lastMsg = array(); |
2588 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
2589 | - $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2721 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2722 | + $lastMsg[$row['id_board']] = $row['id_msg']; |
|
2723 | + } |
|
2590 | 2724 | $smcFunc['db_free_result']($request); |
2591 | - } |
|
2592 | - else |
|
2725 | + } else |
|
2593 | 2726 | { |
2594 | 2727 | // Just to note - there should only be one board passed if we are doing this. |
2595 | - foreach ($setboards as $id_board) |
|
2596 | - $lastMsg[$id_board] = $id_msg; |
|
2728 | + foreach ($setboards as $id_board) { |
|
2729 | + $lastMsg[$id_board] = $id_msg; |
|
2730 | + } |
|
2597 | 2731 | } |
2598 | 2732 | |
2599 | 2733 | $parent_boards = array(); |
@@ -2608,10 +2742,11 @@ discard block |
||
2608 | 2742 | $lastModified[$id_board] = 0; |
2609 | 2743 | } |
2610 | 2744 | |
2611 | - if (!empty($board) && $id_board == $board) |
|
2612 | - $parents = $board_info['parent_boards']; |
|
2613 | - else |
|
2614 | - $parents = getBoardParents($id_board); |
|
2745 | + if (!empty($board) && $id_board == $board) { |
|
2746 | + $parents = $board_info['parent_boards']; |
|
2747 | + } else { |
|
2748 | + $parents = getBoardParents($id_board); |
|
2749 | + } |
|
2615 | 2750 | |
2616 | 2751 | // Ignore any parents on the top child level. |
2617 | 2752 | // @todo Why? |
@@ -2620,10 +2755,11 @@ discard block |
||
2620 | 2755 | if ($parent['level'] != 0) |
2621 | 2756 | { |
2622 | 2757 | // If we're already doing this one as a board, is this a higher last modified? |
2623 | - if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) |
|
2624 | - $lastModified[$id] = $lastModified[$id_board]; |
|
2625 | - elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) |
|
2626 | - $parent_boards[$id] = $lastModified[$id_board]; |
|
2758 | + if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) { |
|
2759 | + $lastModified[$id] = $lastModified[$id_board]; |
|
2760 | + } elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) { |
|
2761 | + $parent_boards[$id] = $lastModified[$id_board]; |
|
2762 | + } |
|
2627 | 2763 | } |
2628 | 2764 | } |
2629 | 2765 | } |
@@ -2636,23 +2772,24 @@ discard block |
||
2636 | 2772 | // Finally, to save on queries make the changes... |
2637 | 2773 | foreach ($parent_boards as $id => $msg) |
2638 | 2774 | { |
2639 | - if (!isset($parent_updates[$msg])) |
|
2640 | - $parent_updates[$msg] = array($id); |
|
2641 | - else |
|
2642 | - $parent_updates[$msg][] = $id; |
|
2775 | + if (!isset($parent_updates[$msg])) { |
|
2776 | + $parent_updates[$msg] = array($id); |
|
2777 | + } else { |
|
2778 | + $parent_updates[$msg][] = $id; |
|
2779 | + } |
|
2643 | 2780 | } |
2644 | 2781 | |
2645 | 2782 | foreach ($lastMsg as $id => $msg) |
2646 | 2783 | { |
2647 | - if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) |
|
2648 | - $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2784 | + if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) { |
|
2785 | + $board_updates[$msg . '-' . $lastModified[$id]] = array( |
|
2649 | 2786 | 'id' => $msg, |
2650 | 2787 | 'updated' => $lastModified[$id], |
2651 | 2788 | 'boards' => array($id) |
2652 | 2789 | ); |
2653 | - |
|
2654 | - else |
|
2655 | - $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2790 | + } else { |
|
2791 | + $board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id; |
|
2792 | + } |
|
2656 | 2793 | } |
2657 | 2794 | |
2658 | 2795 | // Now commit the changes! |
@@ -2744,11 +2881,13 @@ discard block |
||
2744 | 2881 | global $txt, $mbname, $scripturl, $settings; |
2745 | 2882 | |
2746 | 2883 | // First things first, load up the email templates language file, if we need to. |
2747 | - if ($loadLang) |
|
2748 | - loadLanguage('EmailTemplates', $lang); |
|
2884 | + if ($loadLang) { |
|
2885 | + loadLanguage('EmailTemplates', $lang); |
|
2886 | + } |
|
2749 | 2887 | |
2750 | - if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) |
|
2751 | - fatal_lang_error('email_no_template', 'template', array($template)); |
|
2888 | + if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) { |
|
2889 | + fatal_lang_error('email_no_template', 'template', array($template)); |
|
2890 | + } |
|
2752 | 2891 | |
2753 | 2892 | $ret = array( |
2754 | 2893 | 'subject' => $txt[$template . '_subject'], |
@@ -2798,17 +2937,18 @@ discard block |
||
2798 | 2937 | function user_info_callback($matches) |
2799 | 2938 | { |
2800 | 2939 | global $user_info; |
2801 | - if (empty($matches[1])) |
|
2802 | - return ''; |
|
2940 | + if (empty($matches[1])) { |
|
2941 | + return ''; |
|
2942 | + } |
|
2803 | 2943 | |
2804 | 2944 | $use_ref = true; |
2805 | 2945 | $ref = &$user_info; |
2806 | 2946 | |
2807 | 2947 | foreach (explode('.', $matches[1]) as $index) |
2808 | 2948 | { |
2809 | - if ($use_ref && isset($ref[$index])) |
|
2810 | - $ref = &$ref[$index]; |
|
2811 | - else |
|
2949 | + if ($use_ref && isset($ref[$index])) { |
|
2950 | + $ref = &$ref[$index]; |
|
2951 | + } else |
|
2812 | 2952 | { |
2813 | 2953 | $use_ref = false; |
2814 | 2954 | break; |
@@ -2845,8 +2985,7 @@ discard block |
||
2845 | 2985 | if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale)) |
2846 | 2986 | { |
2847 | 2987 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale); |
2848 | - } |
|
2849 | - elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2988 | + } elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary'])) |
|
2850 | 2989 | { |
2851 | 2990 | $enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']); |
2852 | 2991 | } |
@@ -2856,8 +2995,7 @@ discard block |
||
2856 | 2995 | { |
2857 | 2996 | $context['provider'] = 'enchant'; |
2858 | 2997 | return $enchant_link; |
2859 | - } |
|
2860 | - else |
|
2998 | + } else |
|
2861 | 2999 | { |
2862 | 3000 | // Free up any resources used... |
2863 | 3001 | @enchant_broker_free($context['enchant_broker']); |
@@ -2878,8 +3016,9 @@ discard block |
||
2878 | 3016 | $pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER); |
2879 | 3017 | |
2880 | 3018 | // Most people don't have anything but English installed... So we use English as a last resort. |
2881 | - if (!$pspell_link) |
|
2882 | - $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
3019 | + if (!$pspell_link) { |
|
3020 | + $pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER); |
|
3021 | + } |
|
2883 | 3022 | |
2884 | 3023 | error_reporting($old); |
2885 | 3024 | ob_end_clean(); |
@@ -2919,8 +3058,7 @@ discard block |
||
2919 | 3058 | $word = iconv($txt['lang_character_set'], 'UTF-8', $word); |
2920 | 3059 | } |
2921 | 3060 | return enchant_dict_check($dict, $word); |
2922 | - } |
|
2923 | - elseif ($context['provider'] == 'pspell') |
|
3061 | + } elseif ($context['provider'] == 'pspell') |
|
2924 | 3062 | { |
2925 | 3063 | return pspell_check($dict, $word); |
2926 | 3064 | } |
@@ -2956,13 +3094,11 @@ discard block |
||
2956 | 3094 | } |
2957 | 3095 | |
2958 | 3096 | return $suggestions; |
2959 | - } |
|
2960 | - else |
|
3097 | + } else |
|
2961 | 3098 | { |
2962 | 3099 | return enchant_dict_suggest($dict, $word); |
2963 | 3100 | } |
2964 | - } |
|
2965 | - elseif ($context['provider'] == 'pspell') |
|
3101 | + } elseif ($context['provider'] == 'pspell') |
|
2966 | 3102 | { |
2967 | 3103 | return pspell_suggest($dict, $word); |
2968 | 3104 | } |