Completed
Pull Request — release-2.1 (#4924)
by Jeremy
08:56
created
Sources/Subs-Post.php 1 patch
Braces   +526 added lines, -393 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
229
-	else
230
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	if (!$previewing) {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	} else {
247
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
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('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -270,8 +288,9 @@  discard block
 block discarded – undo
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('&nbsp;', ' ', $message));
@@ -352,8 +371,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
389 410
 	{
390 411
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
391 412
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $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
 block discarded – undo
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 . '=&quot;' . $replace . '&quot;]' . (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 . '=&quot;' . $replace . '&quot;]' . (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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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", '&#91;' => '[', '&#93;' => ']')))));
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
1169 1220
 		// Let's, for now, assume there are only &#021;'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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,33 +1395,39 @@  discard block
 block discarded – undo
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
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1339
-					return false;
1402
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1403
+									return false;
1404
+				}
1340 1405
 				// Send the EHLO command again
1341
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1342
-					return false;
1406
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1407
+									return false;
1408
+				}
1343 1409
 			}
1344 1410
 
1345
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1346
-				return false;
1411
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1412
+							return false;
1413
+			}
1347 1414
 			// Send the username and password, encoded.
1348
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1349
-				return false;
1415
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1416
+							return false;
1417
+			}
1350 1418
 			// The password is already encoded ;)
1351
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1352
-				return false;
1419
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1420
+							return false;
1421
+			}
1422
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1423
+					return false;
1353 1424
 		}
1354
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1355
-			return false;
1356
-	}
1357
-	else
1425
+	} else
1358 1426
 	{
1359 1427
 		// Just say "helo".
1360
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1361
-			return false;
1428
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1429
+					return false;
1430
+		}
1362 1431
 	}
1363 1432
 
1364 1433
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1371,31 +1440,38 @@  discard block
 block discarded – undo
1371 1440
 		// Reset the connection to send another email.
1372 1441
 		if ($i != 0)
1373 1442
 		{
1374
-			if (!server_parse('RSET', $socket, '250'))
1375
-				return false;
1443
+			if (!server_parse('RSET', $socket, '250')) {
1444
+							return false;
1445
+			}
1376 1446
 		}
1377 1447
 
1378 1448
 		// From, to, and then start the data...
1379
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1380
-			return false;
1381
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1382
-			return false;
1383
-		if (!server_parse('DATA', $socket, '354'))
1384
-			return false;
1449
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1450
+					return false;
1451
+		}
1452
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1453
+					return false;
1454
+		}
1455
+		if (!server_parse('DATA', $socket, '354')) {
1456
+					return false;
1457
+		}
1385 1458
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1386
-		if (strlen($mail_to) > 0)
1387
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1459
+		if (strlen($mail_to) > 0) {
1460
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1461
+		}
1388 1462
 		fputs($socket, $headers . "\r\n\r\n");
1389 1463
 		fputs($socket, $message . "\r\n");
1390 1464
 
1391 1465
 		// Send a ., or in other words "end of data".
1392
-		if (!server_parse('.', $socket, '250'))
1393
-			return false;
1466
+		if (!server_parse('.', $socket, '250')) {
1467
+					return false;
1468
+		}
1394 1469
 
1395 1470
 		// Almost done, almost done... don't stop me just yet!
1396 1471
 		@set_time_limit(300);
1397
-		if (function_exists('apache_reset_timeout'))
1398
-			@apache_reset_timeout();
1472
+		if (function_exists('apache_reset_timeout')) {
1473
+					@apache_reset_timeout();
1474
+		}
1399 1475
 	}
1400 1476
 	fputs($socket, 'QUIT' . "\r\n");
1401 1477
 	fclose($socket);
@@ -1419,8 +1495,9 @@  discard block
 block discarded – undo
1419 1495
 {
1420 1496
 	global $txt;
1421 1497
 
1422
-	if ($message !== null)
1423
-		fputs($socket, $message . "\r\n");
1498
+	if ($message !== null) {
1499
+			fputs($socket, $message . "\r\n");
1500
+	}
1424 1501
 
1425 1502
 	// No response yet.
1426 1503
 	$server_response = '';
@@ -1436,8 +1513,9 @@  discard block
 block discarded – undo
1436 1513
 		$response .= $server_response;
1437 1514
 	}
1438 1515
 
1439
-	if ($code === null)
1440
-		return substr($server_response, 0, 3);
1516
+	if ($code === null) {
1517
+			return substr($server_response, 0, 3);
1518
+	}
1441 1519
 
1442 1520
 	if (substr($server_response, 0, 3) != $code)
1443 1521
 	{
@@ -1467,8 +1545,9 @@  discard block
 block discarded – undo
1467 1545
 	// Create a pspell or enchant dictionary resource
1468 1546
 	$dict = spell_init();
1469 1547
 
1470
-	if (!isset($_POST['spellstring']) || !$dict)
1471
-		die;
1548
+	if (!isset($_POST['spellstring']) || !$dict) {
1549
+			die;
1550
+	}
1472 1551
 
1473 1552
 	// Construct a bit of Javascript code.
1474 1553
 	$context['spell_js'] = '
@@ -1486,8 +1565,9 @@  discard block
 block discarded – undo
1486 1565
 		$check_word = explode('|', $alphas[$i]);
1487 1566
 
1488 1567
 		// If the word is a known word, or spelled right...
1489
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1490
-			continue;
1568
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1569
+					continue;
1570
+		}
1491 1571
 
1492 1572
 		// Find the word, and move up the "last occurrence" to here.
1493 1573
 		$found_words = true;
@@ -1501,20 +1581,23 @@  discard block
 block discarded – undo
1501 1581
 		if (!empty($suggestions))
1502 1582
 		{
1503 1583
 			// But first check they aren't going to be censored - no naughty words!
1504
-			foreach ($suggestions as $k => $word)
1505
-				if ($suggestions[$k] != censorText($word))
1584
+			foreach ($suggestions as $k => $word) {
1585
+							if ($suggestions[$k] != censorText($word))
1506 1586
 					unset($suggestions[$k]);
1587
+			}
1507 1588
 
1508
-			if (!empty($suggestions))
1509
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1589
+			if (!empty($suggestions)) {
1590
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1591
+			}
1510 1592
 		}
1511 1593
 
1512 1594
 		$context['spell_js'] .= ']),';
1513 1595
 	}
1514 1596
 
1515 1597
 	// If words were found, take off the last comma.
1516
-	if ($found_words)
1517
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1598
+	if ($found_words) {
1599
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1600
+	}
1518 1601
 
1519 1602
 	$context['spell_js'] .= '
1520 1603
 		);';
@@ -1549,11 +1632,13 @@  discard block
 block discarded – undo
1549 1632
 	global $user_info, $smcFunc;
1550 1633
 
1551 1634
 	// Can't do it if there's no topics.
1552
-	if (empty($topics))
1553
-		return;
1635
+	if (empty($topics)) {
1636
+			return;
1637
+	}
1554 1638
 	// It must be an array - it must!
1555
-	if (!is_array($topics))
1556
-		$topics = array($topics);
1639
+	if (!is_array($topics)) {
1640
+			$topics = array($topics);
1641
+	}
1557 1642
 
1558 1643
 	// Get the subject and body...
1559 1644
 	$result = $smcFunc['db_query']('', '
@@ -1601,14 +1686,15 @@  discard block
 block discarded – undo
1601 1686
 	}
1602 1687
 	$smcFunc['db_free_result']($result);
1603 1688
 
1604
-	if (!empty($task_rows))
1605
-		$smcFunc['db_insert']('',
1689
+	if (!empty($task_rows)) {
1690
+			$smcFunc['db_insert']('',
1606 1691
 			'{db_prefix}background_tasks',
1607 1692
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1608 1693
 			$task_rows,
1609 1694
 			array('id_task')
1610 1695
 		);
1611
-}
1696
+	}
1697
+	}
1612 1698
 
1613 1699
 /**
1614 1700
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1646,9 +1732,9 @@  discard block
 block discarded – undo
1646 1732
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1647 1733
 
1648 1734
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1649
-	if (!$modSettings['postmod_active'])
1650
-		$topicOptions['is_approved'] = true;
1651
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1735
+	if (!$modSettings['postmod_active']) {
1736
+			$topicOptions['is_approved'] = true;
1737
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1652 1738
 	{
1653 1739
 		$request = $smcFunc['db_query']('', '
1654 1740
 			SELECT approved
@@ -1671,8 +1757,7 @@  discard block
 block discarded – undo
1671 1757
 			$posterOptions['id'] = 0;
1672 1758
 			$posterOptions['name'] = $txt['guest_title'];
1673 1759
 			$posterOptions['email'] = '';
1674
-		}
1675
-		elseif ($posterOptions['id'] != $user_info['id'])
1760
+		} elseif ($posterOptions['id'] != $user_info['id'])
1676 1761
 		{
1677 1762
 			$request = $smcFunc['db_query']('', '
1678 1763
 				SELECT member_name, email_address
@@ -1690,12 +1775,11 @@  discard block
 block discarded – undo
1690 1775
 				$posterOptions['id'] = 0;
1691 1776
 				$posterOptions['name'] = $txt['guest_title'];
1692 1777
 				$posterOptions['email'] = '';
1778
+			} else {
1779
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1693 1780
 			}
1694
-			else
1695
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1696 1781
 			$smcFunc['db_free_result']($request);
1697
-		}
1698
-		else
1782
+		} else
1699 1783
 		{
1700 1784
 			$posterOptions['name'] = $user_info['name'];
1701 1785
 			$posterOptions['email'] = $user_info['email'];
@@ -1705,8 +1789,9 @@  discard block
 block discarded – undo
1705 1789
 	if (!empty($modSettings['enable_mentions']))
1706 1790
 	{
1707 1791
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1708
-		if (!empty($msgOptions['mentioned_members']))
1709
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1792
+		if (!empty($msgOptions['mentioned_members'])) {
1793
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1794
+		}
1710 1795
 	}
1711 1796
 
1712 1797
 	// It's do or die time: forget any user aborts!
@@ -1739,12 +1824,13 @@  discard block
 block discarded – undo
1739 1824
 	);
1740 1825
 
1741 1826
 	// Something went wrong creating the message...
1742
-	if (empty($msgOptions['id']))
1743
-		return false;
1827
+	if (empty($msgOptions['id'])) {
1828
+			return false;
1829
+	}
1744 1830
 
1745 1831
 	// Fix the attachments.
1746
-	if (!empty($msgOptions['attachments']))
1747
-		$smcFunc['db_query']('', '
1832
+	if (!empty($msgOptions['attachments'])) {
1833
+			$smcFunc['db_query']('', '
1748 1834
 			UPDATE {db_prefix}attachments
1749 1835
 			SET id_msg = {int:id_msg}
1750 1836
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1753,6 +1839,7 @@  discard block
 block discarded – undo
1753 1839
 				'id_msg' => $msgOptions['id'],
1754 1840
 			)
1755 1841
 		);
1842
+	}
1756 1843
 
1757 1844
 	// What if we want to export new posts out to a CMS?
1758 1845
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1829,20 +1916,23 @@  discard block
 block discarded – undo
1829 1916
 			'id_topic' => $topicOptions['id'],
1830 1917
 			'counter_increment' => 1,
1831 1918
 		);
1832
-		if ($msgOptions['approved'])
1833
-			$topics_columns = array(
1919
+		if ($msgOptions['approved']) {
1920
+					$topics_columns = array(
1834 1921
 				'id_member_updated = {int:poster_id}',
1835 1922
 				'id_last_msg = {int:id_msg}',
1836 1923
 				'num_replies = num_replies + {int:counter_increment}',
1837 1924
 			);
1838
-		else
1839
-			$topics_columns = array(
1925
+		} else {
1926
+					$topics_columns = array(
1840 1927
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1841 1928
 			);
1842
-		if ($topicOptions['lock_mode'] !== null)
1843
-			$topics_columns[] = 'locked = {int:locked}';
1844
-		if ($topicOptions['sticky_mode'] !== null)
1845
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1929
+		}
1930
+		if ($topicOptions['lock_mode'] !== null) {
1931
+					$topics_columns[] = 'locked = {int:locked}';
1932
+		}
1933
+		if ($topicOptions['sticky_mode'] !== null) {
1934
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1935
+		}
1846 1936
 
1847 1937
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1848 1938
 
@@ -1871,8 +1961,8 @@  discard block
 block discarded – undo
1871 1961
 	);
1872 1962
 
1873 1963
 	// Increase the number of posts and topics on the board.
1874
-	if ($msgOptions['approved'])
1875
-		$smcFunc['db_query']('', '
1964
+	if ($msgOptions['approved']) {
1965
+			$smcFunc['db_query']('', '
1876 1966
 			UPDATE {db_prefix}boards
1877 1967
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1878 1968
 			WHERE id_board = {int:id_board}',
@@ -1880,7 +1970,7 @@  discard block
 block discarded – undo
1880 1970
 				'id_board' => $topicOptions['board'],
1881 1971
 			)
1882 1972
 		);
1883
-	else
1973
+	} else
1884 1974
 	{
1885 1975
 		$smcFunc['db_query']('', '
1886 1976
 			UPDATE {db_prefix}boards
@@ -1950,8 +2040,8 @@  discard block
 block discarded – undo
1950 2040
 		}
1951 2041
 	}
1952 2042
 
1953
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1954
-		$smcFunc['db_insert']('',
2043
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2044
+			$smcFunc['db_insert']('',
1955 2045
 			'{db_prefix}background_tasks',
1956 2046
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1957 2047
 			array(
@@ -1963,19 +2053,22 @@  discard block
 block discarded – undo
1963 2053
 			),
1964 2054
 			array('id_task')
1965 2055
 		);
2056
+	}
1966 2057
 
1967 2058
 	// If there's a custom search index, it may need updating...
1968 2059
 	require_once($sourcedir . '/Search.php');
1969 2060
 	$searchAPI = findSearchAPI();
1970
-	if (is_callable(array($searchAPI, 'postCreated')))
1971
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2061
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2062
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2063
+	}
1972 2064
 
1973 2065
 	// Increase the post counter for the user that created the post.
1974 2066
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
1975 2067
 	{
1976 2068
 		// Are you the one that happened to create this post?
1977
-		if ($user_info['id'] == $posterOptions['id'])
1978
-			$user_info['posts']++;
2069
+		if ($user_info['id'] == $posterOptions['id']) {
2070
+					$user_info['posts']++;
2071
+		}
1979 2072
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
1980 2073
 	}
1981 2074
 
@@ -1983,19 +2076,21 @@  discard block
 block discarded – undo
1983 2076
 	$_SESSION['last_read_topic'] = 0;
1984 2077
 
1985 2078
 	// Better safe than sorry.
1986
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
1987
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2079
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2080
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2081
+	}
1988 2082
 
1989 2083
 	// Update all the stats so everyone knows about this new topic and message.
1990 2084
 	updateStats('message', true, $msgOptions['id']);
1991 2085
 
1992 2086
 	// Update the last message on the board assuming it's approved AND the topic is.
1993
-	if ($msgOptions['approved'])
1994
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2087
+	if ($msgOptions['approved']) {
2088
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2089
+	}
1995 2090
 
1996 2091
 	// Queue createPost background notification
1997
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
1998
-		$smcFunc['db_insert']('',
2092
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2093
+			$smcFunc['db_insert']('',
1999 2094
 			'{db_prefix}background_tasks',
2000 2095
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2001 2096
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
@@ -2006,6 +2101,7 @@  discard block
 block discarded – undo
2006 2101
 			)), 0),
2007 2102
 			array('id_task')
2008 2103
 		);
2104
+	}
2009 2105
 
2010 2106
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2011 2107
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2032,14 +2128,18 @@  discard block
 block discarded – undo
2032 2128
 
2033 2129
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2034 2130
 	$messages_columns = array();
2035
-	if (isset($posterOptions['name']))
2036
-		$messages_columns['poster_name'] = $posterOptions['name'];
2037
-	if (isset($posterOptions['email']))
2038
-		$messages_columns['poster_email'] = $posterOptions['email'];
2039
-	if (isset($msgOptions['icon']))
2040
-		$messages_columns['icon'] = $msgOptions['icon'];
2041
-	if (isset($msgOptions['subject']))
2042
-		$messages_columns['subject'] = $msgOptions['subject'];
2131
+	if (isset($posterOptions['name'])) {
2132
+			$messages_columns['poster_name'] = $posterOptions['name'];
2133
+	}
2134
+	if (isset($posterOptions['email'])) {
2135
+			$messages_columns['poster_email'] = $posterOptions['email'];
2136
+	}
2137
+	if (isset($msgOptions['icon'])) {
2138
+			$messages_columns['icon'] = $msgOptions['icon'];
2139
+	}
2140
+	if (isset($msgOptions['subject'])) {
2141
+			$messages_columns['subject'] = $msgOptions['subject'];
2142
+	}
2043 2143
 	if (isset($msgOptions['body']))
2044 2144
 	{
2045 2145
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2066,8 +2166,9 @@  discard block
 block discarded – undo
2066 2166
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2067 2167
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2068 2168
 	}
2069
-	if (isset($msgOptions['smileys_enabled']))
2070
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2169
+	if (isset($msgOptions['smileys_enabled'])) {
2170
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2171
+	}
2071 2172
 
2072 2173
 	// Which columns need to be ints?
2073 2174
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2078,8 +2179,9 @@  discard block
 block discarded – undo
2078 2179
 	// Update search api
2079 2180
 	require_once($sourcedir . '/Search.php');
2080 2181
 	$searchAPI = findSearchAPI();
2081
-	if ($searchAPI->supportsMethod('postRemoved'))
2082
-		$searchAPI->postRemoved($msgOptions['id']);
2182
+	if ($searchAPI->supportsMethod('postRemoved')) {
2183
+			$searchAPI->postRemoved($msgOptions['id']);
2184
+	}
2083 2185
 
2084 2186
 	if (!empty($modSettings['enable_mentions']) && isset($msgOptions['body']))
2085 2187
 	{
@@ -2091,23 +2193,27 @@  discard block
 block discarded – undo
2091 2193
 		{
2092 2194
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2093 2195
 
2094
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2095
-				foreach ($match[1] as $i => $oldID)
2196
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2197
+							foreach ($match[1] as $i => $oldID)
2096 2198
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2199
+			}
2097 2200
 
2098
-			if (empty($modSettings['search_custom_index_config']))
2099
-				unset($msgOptions['old_body']);
2201
+			if (empty($modSettings['search_custom_index_config'])) {
2202
+							unset($msgOptions['old_body']);
2203
+			}
2100 2204
 		}
2101 2205
 
2102 2206
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2103 2207
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2104 2208
 
2105 2209
 		// Remove the poster.
2106
-		if (isset($mentions[$user_info['id']]))
2107
-			unset($mentions[$user_info['id']]);
2210
+		if (isset($mentions[$user_info['id']])) {
2211
+					unset($mentions[$user_info['id']]);
2212
+		}
2108 2213
 
2109
-		if (isset($oldmentions[$user_info['id']]))
2110
-			unset($oldmentions[$user_info['id']]);
2214
+		if (isset($oldmentions[$user_info['id']])) {
2215
+					unset($oldmentions[$user_info['id']]);
2216
+		}
2111 2217
 
2112 2218
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2113 2219
 		{
@@ -2137,8 +2243,9 @@  discard block
 block discarded – undo
2137 2243
 	}
2138 2244
 
2139 2245
 	// Nothing to do?
2140
-	if (empty($messages_columns))
2141
-		return true;
2246
+	if (empty($messages_columns)) {
2247
+			return true;
2248
+	}
2142 2249
 
2143 2250
 	// Change the post.
2144 2251
 	$smcFunc['db_query']('', '
@@ -2199,8 +2306,9 @@  discard block
 block discarded – undo
2199 2306
 	// If there's a custom search index, it needs to be modified...
2200 2307
 	require_once($sourcedir . '/Search.php');
2201 2308
 	$searchAPI = findSearchAPI();
2202
-	if (is_callable(array($searchAPI, 'postModified')))
2203
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2309
+	if (is_callable(array($searchAPI, 'postModified'))) {
2310
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2311
+	}
2204 2312
 
2205 2313
 	if (isset($msgOptions['subject']))
2206 2314
 	{
@@ -2214,14 +2322,16 @@  discard block
 block discarded – undo
2214 2322
 				'id_first_msg' => $msgOptions['id'],
2215 2323
 			)
2216 2324
 		);
2217
-		if ($smcFunc['db_num_rows']($request) == 1)
2218
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2325
+		if ($smcFunc['db_num_rows']($request) == 1) {
2326
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2327
+		}
2219 2328
 		$smcFunc['db_free_result']($request);
2220 2329
 	}
2221 2330
 
2222 2331
 	// Finally, if we are setting the approved state we need to do much more work :(
2223
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2224
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2332
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2333
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2334
+	}
2225 2335
 
2226 2336
 	return true;
2227 2337
 }
@@ -2238,11 +2348,13 @@  discard block
 block discarded – undo
2238 2348
 {
2239 2349
 	global $smcFunc;
2240 2350
 
2241
-	if (!is_array($msgs))
2242
-		$msgs = array($msgs);
2351
+	if (!is_array($msgs)) {
2352
+			$msgs = array($msgs);
2353
+	}
2243 2354
 
2244
-	if (empty($msgs))
2245
-		return false;
2355
+	if (empty($msgs)) {
2356
+			return false;
2357
+	}
2246 2358
 
2247 2359
 	// May as well start at the beginning, working out *what* we need to change.
2248 2360
 	$request = $smcFunc['db_query']('', '
@@ -2274,20 +2386,22 @@  discard block
 block discarded – undo
2274 2386
 		$topics[] = $row['id_topic'];
2275 2387
 
2276 2388
 		// Ensure our change array exists already.
2277
-		if (!isset($topic_changes[$row['id_topic']]))
2278
-			$topic_changes[$row['id_topic']] = array(
2389
+		if (!isset($topic_changes[$row['id_topic']])) {
2390
+					$topic_changes[$row['id_topic']] = array(
2279 2391
 				'id_last_msg' => $row['id_last_msg'],
2280 2392
 				'approved' => $row['topic_approved'],
2281 2393
 				'replies' => 0,
2282 2394
 				'unapproved_posts' => 0,
2283 2395
 			);
2284
-		if (!isset($board_changes[$row['id_board']]))
2285
-			$board_changes[$row['id_board']] = array(
2396
+		}
2397
+		if (!isset($board_changes[$row['id_board']])) {
2398
+					$board_changes[$row['id_board']] = array(
2286 2399
 				'posts' => 0,
2287 2400
 				'topics' => 0,
2288 2401
 				'unapproved_posts' => 0,
2289 2402
 				'unapproved_topics' => 0,
2290 2403
 			);
2404
+		}
2291 2405
 
2292 2406
 		// If it's the first message then the topic state changes!
2293 2407
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2308,14 +2422,13 @@  discard block
 block discarded – undo
2308 2422
 				'poster' => $row['id_member'],
2309 2423
 				'new_topic' => true,
2310 2424
 			);
2311
-		}
2312
-		else
2425
+		} else
2313 2426
 		{
2314 2427
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2315 2428
 
2316 2429
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2317
-			if ($row['id_msg'] > $row['id_last_msg'])
2318
-				$notification_posts[$row['id_topic']] = array(
2430
+			if ($row['id_msg'] > $row['id_last_msg']) {
2431
+							$notification_posts[$row['id_topic']] = array(
2319 2432
 					'id' => $row['id_msg'],
2320 2433
 					'body' => $row['body'],
2321 2434
 					'subject' => $row['subject'],
@@ -2326,28 +2439,33 @@  discard block
 block discarded – undo
2326 2439
 					'new_topic' => false,
2327 2440
 					'msg' => $row['id_msg'],
2328 2441
 				);
2442
+			}
2329 2443
 		}
2330 2444
 
2331 2445
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2332
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2333
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2446
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2447
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2448
+		}
2334 2449
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2335
-		elseif (!$approve)
2336
-			// Default to the first message and then we'll override in a bit ;)
2450
+		elseif (!$approve) {
2451
+					// Default to the first message and then we'll override in a bit ;)
2337 2452
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2453
+		}
2338 2454
 
2339 2455
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2340 2456
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2341 2457
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2342 2458
 
2343 2459
 		// Post count for the user?
2344
-		if ($row['id_member'] && empty($row['count_posts']))
2345
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2460
+		if ($row['id_member'] && empty($row['count_posts'])) {
2461
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2462
+		}
2346 2463
 	}
2347 2464
 	$smcFunc['db_free_result']($request);
2348 2465
 
2349
-	if (empty($msgs))
2350
-		return;
2466
+	if (empty($msgs)) {
2467
+			return;
2468
+	}
2351 2469
 
2352 2470
 	// Now we have the differences make the changes, first the easy one.
2353 2471
 	$smcFunc['db_query']('', '
@@ -2374,14 +2492,15 @@  discard block
 block discarded – undo
2374 2492
 				'approved' => 1,
2375 2493
 			)
2376 2494
 		);
2377
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2378
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2495
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2496
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2497
+		}
2379 2498
 		$smcFunc['db_free_result']($request);
2380 2499
 	}
2381 2500
 
2382 2501
 	// ... next the topics...
2383
-	foreach ($topic_changes as $id => $changes)
2384
-		$smcFunc['db_query']('', '
2502
+	foreach ($topic_changes as $id => $changes) {
2503
+			$smcFunc['db_query']('', '
2385 2504
 			UPDATE {db_prefix}topics
2386 2505
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2387 2506
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2394,10 +2513,11 @@  discard block
 block discarded – undo
2394 2513
 				'id_topic' => $id,
2395 2514
 			)
2396 2515
 		);
2516
+	}
2397 2517
 
2398 2518
 	// ... finally the boards...
2399
-	foreach ($board_changes as $id => $changes)
2400
-		$smcFunc['db_query']('', '
2519
+	foreach ($board_changes as $id => $changes) {
2520
+			$smcFunc['db_query']('', '
2401 2521
 			UPDATE {db_prefix}boards
2402 2522
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2403 2523
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2410,13 +2530,14 @@  discard block
 block discarded – undo
2410 2530
 				'id_board' => $id,
2411 2531
 			)
2412 2532
 		);
2533
+	}
2413 2534
 
2414 2535
 	// Finally, least importantly, notifications!
2415 2536
 	if ($approve)
2416 2537
 	{
2417 2538
 		$task_rows = array();
2418
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2419
-			$task_rows[] = array(
2539
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2540
+					$task_rows[] = array(
2420 2541
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
2421 2542
 					'msgOptions' => array(
2422 2543
 						'id' => $topic['msg'],
@@ -2434,14 +2555,16 @@  discard block
 block discarded – undo
2434 2555
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2435 2556
 				)), 0
2436 2557
 			);
2558
+		}
2437 2559
 
2438
-		if ($notify)
2439
-			$smcFunc['db_insert']('',
2560
+		if ($notify) {
2561
+					$smcFunc['db_insert']('',
2440 2562
 				'{db_prefix}background_tasks',
2441 2563
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2442 2564
 				$task_rows,
2443 2565
 				array('id_task')
2444 2566
 			);
2567
+		}
2445 2568
 
2446 2569
 		$smcFunc['db_query']('', '
2447 2570
 			DELETE FROM {db_prefix}approval_queue
@@ -2457,8 +2580,9 @@  discard block
 block discarded – undo
2457 2580
 	else
2458 2581
 	{
2459 2582
 		$msgInserts = array();
2460
-		foreach ($msgs as $msg)
2461
-			$msgInserts[] = array($msg);
2583
+		foreach ($msgs as $msg) {
2584
+					$msgInserts[] = array($msg);
2585
+		}
2462 2586
 
2463 2587
 		$smcFunc['db_insert']('ignore',
2464 2588
 			'{db_prefix}approval_queue',
@@ -2472,9 +2596,10 @@  discard block
 block discarded – undo
2472 2596
 	updateLastMessages(array_keys($board_changes));
2473 2597
 
2474 2598
 	// Post count for the members?
2475
-	if (!empty($member_post_changes))
2476
-		foreach ($member_post_changes as $id_member => $count_change)
2599
+	if (!empty($member_post_changes)) {
2600
+			foreach ($member_post_changes as $id_member => $count_change)
2477 2601
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2602
+	}
2478 2603
 
2479 2604
 	return true;
2480 2605
 }
@@ -2491,11 +2616,13 @@  discard block
 block discarded – undo
2491 2616
 {
2492 2617
 	global $smcFunc;
2493 2618
 
2494
-	if (!is_array($topics))
2495
-		$topics = array($topics);
2619
+	if (!is_array($topics)) {
2620
+			$topics = array($topics);
2621
+	}
2496 2622
 
2497
-	if (empty($topics))
2498
-		return false;
2623
+	if (empty($topics)) {
2624
+			return false;
2625
+	}
2499 2626
 
2500 2627
 	$approve_type = $approve ? 0 : 1;
2501 2628
 
@@ -2511,8 +2638,9 @@  discard block
 block discarded – undo
2511 2638
 		)
2512 2639
 	);
2513 2640
 	$msgs = array();
2514
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2515
-		$msgs[] = $row['id_msg'];
2641
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2642
+			$msgs[] = $row['id_msg'];
2643
+	}
2516 2644
 	$smcFunc['db_free_result']($request);
2517 2645
 
2518 2646
 	return approvePosts($msgs, $approve);
@@ -2535,11 +2663,13 @@  discard block
 block discarded – undo
2535 2663
 	global $board_info, $board, $smcFunc;
2536 2664
 
2537 2665
 	// Please - let's be sane.
2538
-	if (empty($setboards))
2539
-		return false;
2666
+	if (empty($setboards)) {
2667
+			return false;
2668
+	}
2540 2669
 
2541
-	if (!is_array($setboards))
2542
-		$setboards = array($setboards);
2670
+	if (!is_array($setboards)) {
2671
+			$setboards = array($setboards);
2672
+	}
2543 2673
 
2544 2674
 	// If we don't know the id_msg we need to find it.
2545 2675
 	if (!$id_msg)
@@ -2557,15 +2687,16 @@  discard block
 block discarded – undo
2557 2687
 			)
2558 2688
 		);
2559 2689
 		$lastMsg = array();
2560
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2561
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2690
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2691
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2692
+		}
2562 2693
 		$smcFunc['db_free_result']($request);
2563
-	}
2564
-	else
2694
+	} else
2565 2695
 	{
2566 2696
 		// Just to note - there should only be one board passed if we are doing this.
2567
-		foreach ($setboards as $id_board)
2568
-			$lastMsg[$id_board] = $id_msg;
2697
+		foreach ($setboards as $id_board) {
2698
+					$lastMsg[$id_board] = $id_msg;
2699
+		}
2569 2700
 	}
2570 2701
 
2571 2702
 	$parent_boards = array();
@@ -2580,10 +2711,11 @@  discard block
 block discarded – undo
2580 2711
 			$lastModified[$id_board] = 0;
2581 2712
 		}
2582 2713
 
2583
-		if (!empty($board) && $id_board == $board)
2584
-			$parents = $board_info['parent_boards'];
2585
-		else
2586
-			$parents = getBoardParents($id_board);
2714
+		if (!empty($board) && $id_board == $board) {
2715
+					$parents = $board_info['parent_boards'];
2716
+		} else {
2717
+					$parents = getBoardParents($id_board);
2718
+		}
2587 2719
 
2588 2720
 		// Ignore any parents on the top child level.
2589 2721
 		// @todo Why?
@@ -2592,10 +2724,11 @@  discard block
 block discarded – undo
2592 2724
 			if ($parent['level'] != 0)
2593 2725
 			{
2594 2726
 				// If we're already doing this one as a board, is this a higher last modified?
2595
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2596
-					$lastModified[$id] = $lastModified[$id_board];
2597
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2598
-					$parent_boards[$id] = $lastModified[$id_board];
2727
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2728
+									$lastModified[$id] = $lastModified[$id_board];
2729
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2730
+									$parent_boards[$id] = $lastModified[$id_board];
2731
+				}
2599 2732
 			}
2600 2733
 		}
2601 2734
 	}
@@ -2608,23 +2741,24 @@  discard block
 block discarded – undo
2608 2741
 	// Finally, to save on queries make the changes...
2609 2742
 	foreach ($parent_boards as $id => $msg)
2610 2743
 	{
2611
-		if (!isset($parent_updates[$msg]))
2612
-			$parent_updates[$msg] = array($id);
2613
-		else
2614
-			$parent_updates[$msg][] = $id;
2744
+		if (!isset($parent_updates[$msg])) {
2745
+					$parent_updates[$msg] = array($id);
2746
+		} else {
2747
+					$parent_updates[$msg][] = $id;
2748
+		}
2615 2749
 	}
2616 2750
 
2617 2751
 	foreach ($lastMsg as $id => $msg)
2618 2752
 	{
2619
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2620
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2753
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2754
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2621 2755
 				'id' => $msg,
2622 2756
 				'updated' => $lastModified[$id],
2623 2757
 				'boards' => array($id)
2624 2758
 			);
2625
-
2626
-		else
2627
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2759
+		} else {
2760
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2761
+		}
2628 2762
 	}
2629 2763
 
2630 2764
 	// Now commit the changes!
@@ -2716,11 +2850,13 @@  discard block
 block discarded – undo
2716 2850
 	global $txt, $mbname, $scripturl, $settings;
2717 2851
 
2718 2852
 	// First things first, load up the email templates language file, if we need to.
2719
-	if ($loadLang)
2720
-		loadLanguage('EmailTemplates', $lang);
2853
+	if ($loadLang) {
2854
+			loadLanguage('EmailTemplates', $lang);
2855
+	}
2721 2856
 
2722
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2723
-		fatal_lang_error('email_no_template', 'template', array($template));
2857
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2858
+			fatal_lang_error('email_no_template', 'template', array($template));
2859
+	}
2724 2860
 
2725 2861
 	$ret = array(
2726 2862
 		'subject' => $txt[$template . '_subject'],
@@ -2770,17 +2906,18 @@  discard block
 block discarded – undo
2770 2906
 function user_info_callback($matches)
2771 2907
 {
2772 2908
 	global $user_info;
2773
-	if (empty($matches[1]))
2774
-		return '';
2909
+	if (empty($matches[1])) {
2910
+			return '';
2911
+	}
2775 2912
 
2776 2913
 	$use_ref = true;
2777 2914
 	$ref = &$user_info;
2778 2915
 
2779 2916
 	foreach (explode('.', $matches[1]) as $index)
2780 2917
 	{
2781
-		if ($use_ref && isset($ref[$index]))
2782
-			$ref = &$ref[$index];
2783
-		else
2918
+		if ($use_ref && isset($ref[$index])) {
2919
+					$ref = &$ref[$index];
2920
+		} else
2784 2921
 		{
2785 2922
 			$use_ref = false;
2786 2923
 			break;
@@ -2817,8 +2954,7 @@  discard block
 block discarded – undo
2817 2954
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2818 2955
 		{
2819 2956
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2820
-		}
2821
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2957
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2822 2958
 		{
2823 2959
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2824 2960
 		}
@@ -2828,8 +2964,7 @@  discard block
 block discarded – undo
2828 2964
 		{
2829 2965
 			$context['provider'] = 'enchant';
2830 2966
 			return $enchant_link;
2831
-		}
2832
-		else
2967
+		} else
2833 2968
 		{
2834 2969
 			// Free up any resources used...
2835 2970
 			@enchant_broker_free($context['enchant_broker']);
@@ -2850,8 +2985,9 @@  discard block
 block discarded – undo
2850 2985
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2851 2986
 
2852 2987
 		// Most people don't have anything but English installed... So we use English as a last resort.
2853
-		if (!$pspell_link)
2854
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
2988
+		if (!$pspell_link) {
2989
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
2990
+		}
2855 2991
 
2856 2992
 		error_reporting($old);
2857 2993
 		ob_end_clean();
@@ -2891,8 +3027,7 @@  discard block
 block discarded – undo
2891 3027
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2892 3028
 		}
2893 3029
 		return enchant_dict_check($dict, $word);
2894
-	}
2895
-	elseif ($context['provider'] == 'pspell')
3030
+	} elseif ($context['provider'] == 'pspell')
2896 3031
 	{
2897 3032
 		return pspell_check($dict, $word);
2898 3033
 	}
@@ -2928,13 +3063,11 @@  discard block
 block discarded – undo
2928 3063
 			}
2929 3064
 
2930 3065
 			return $suggestions;
2931
-		}
2932
-		else
3066
+		} else
2933 3067
 		{
2934 3068
 			return enchant_dict_suggest($dict, $word);
2935 3069
 		}
2936
-	}
2937
-	elseif ($context['provider'] == 'pspell')
3070
+	} elseif ($context['provider'] == 'pspell')
2938 3071
 	{
2939 3072
 		return pspell_suggest($dict, $word);
2940 3073
 	}
Please login to merge, or discard this patch.
Sources/tasks/CreatePost-Notify.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,13 +19,13 @@  discard block
 block discarded – undo
19 19
 {
20 20
 	/**
21 21
 	 * Constants for receiving email notfications.
22
-	*/
22
+	 */
23 23
 	const RECEIVE_NOTIFY_EMAIL = 0x02;
24 24
 	const RECEIVE_NOTIFY_ALERT = 0x01;
25 25
 
26 26
 	/**
27 27
 	 * Constants for reply types.
28
-	*/
28
+	 */
29 29
 	const NOTIFY_TYPE_REPLY_AND_MODIFY = 1;
30 30
 	const NOTIFY_TYPE_REPLY_AND_TOPIC_START_FOLLOWING = 2;
31 31
 	const NOTIFY_TYPE_ONLY_REPLIES = 3;
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 	/**
35 35
 	 * Constants for frequencies.
36
-	*/
36
+	 */
37 37
 	const FREQUENCY_NOTHING = 0;
38 38
 	const FREQUENCY_EVERYTHING = 1;
39 39
 	const FREQUENCY_FIRST_UNREAD_MSG = 2;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	const FREQUENCY_WEEKLY_DIGEST = 4;
42 42
 
43 43
 	/**
44
-     * This handles notifications when a new post is created - new topic, reply, quotes and mentions.
44
+	 * This handles notifications when a new post is created - new topic, reply, quotes and mentions.
45 45
 	 * @return bool Always returns true
46 46
 	 */
47 47
 	public function execute()
Please login to merge, or discard this patch.
Braces   +68 added lines, -50 removed lines patch added patch discarded remove patch
@@ -96,8 +96,9 @@  discard block
 block discarded – undo
96 96
 		while ($row = $smcFunc['db_fetch_assoc']($request))
97 97
 		{
98 98
 			$groups = array_merge(array($row['id_group'], $row['id_post_group']), (empty($row['additional_groups']) ? array() : explode(',', $row['additional_groups'])));
99
-			if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0)
100
-				continue;
99
+			if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0) {
100
+							continue;
101
+			}
101 102
 
102 103
 			$members[] = $row['id_member'];
103 104
 			$watched[$row['id_member']] = $row;
@@ -105,8 +106,9 @@  discard block
 block discarded – undo
105 106
 
106 107
 		$smcFunc['db_free_result']($request);
107 108
 
108
-		if (empty($members))
109
-			return true;
109
+		if (empty($members)) {
110
+					return true;
111
+		}
110 112
 
111 113
 		$members = array_unique($members);
112 114
 		$prefs = getNotifyPrefs($members, '', true);
@@ -122,8 +124,9 @@  discard block
 block discarded – undo
122 124
 		self::handleQuoteNotifications($msgOptions, $posterOptions, $quotedMembers, $prefs, $done_members, $alert_rows);
123 125
 
124 126
 		// Save ourselves a bit of work in the big loop below
125
-		foreach ($done_members as $done_member)
126
-			unset($watched[$done_member]);
127
+		foreach ($done_members as $done_member) {
128
+					unset($watched[$done_member]);
129
+		}
127 130
 
128 131
 		// Handle rest of the notifications for watched topics and boards
129 132
 		foreach ($watched as $member => $data)
@@ -132,20 +135,23 @@  discard block
 block discarded – undo
132 135
 			$notify_types = !empty($prefs[$member]['msg_notify_type']) ? $prefs[$member]['msg_notify_type'] : self::NOTIFY_TYPE_REPLY_AND_MODIFY;
133 136
 
134 137
 			// Don't send a notification if the watching member ignored the member who made the action.
135
-			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list'])))
136
-				continue;
137
-			if (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_REPLY_AND_TOPIC_START_FOLLOWING && $member != $data['id_member_started'])
138
-				continue;
139
-			elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id'])
140
-				continue;
141
-			elseif (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_ONLY_REPLIES)
142
-				continue;
143
-			elseif ($notify_types == self::NOTIFY_TYPE_NOTHING)
144
-				continue;
138
+			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list']))) {
139
+							continue;
140
+			}
141
+			if (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_REPLY_AND_TOPIC_START_FOLLOWING && $member != $data['id_member_started']) {
142
+							continue;
143
+			} elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id']) {
144
+							continue;
145
+			} elseif (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_ONLY_REPLIES) {
146
+							continue;
147
+			} elseif ($notify_types == self::NOTIFY_TYPE_NOTHING) {
148
+							continue;
149
+			}
145 150
 
146 151
 			if (empty($frequency) || $frequency > self::FREQUENCY_FIRST_UNREAD_MSG || $data['sent']
147
-				|| (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only'])))
148
-				continue;
152
+				|| (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only']))) {
153
+							continue;
154
+			}
149 155
 
150 156
 			// Watched topic?
151 157
 			if (!empty($data['id_topic']) && $type != 'topic' && !empty($prefs[$member]))
@@ -155,10 +161,12 @@  discard block
 block discarded – undo
155 161
 
156 162
 				if ($type == 'reply')
157 163
 				{
158
-					if (!empty($prefs[$member]['msg_receive_body']))
159
-						$message_type .= '_body';
160
-					if (!empty($frequency))
161
-						$message_type .= '_once';
164
+					if (!empty($prefs[$member]['msg_receive_body'])) {
165
+											$message_type .= '_body';
166
+					}
167
+					if (!empty($frequency)) {
168
+											$message_type .= '_once';
169
+					}
162 170
 				}
163 171
 
164 172
 				$content_type = 'topic';
@@ -171,12 +179,14 @@  discard block
 block discarded – undo
171 179
 				$content_type = 'board';
172 180
 
173 181
 				$message_type = !empty($frequency) ? 'notify_boards_once' : 'notify_boards';
174
-				if (!empty($prefs[$member]['msg_receive_body']))
175
-					$message_type .= '_body';
182
+				if (!empty($prefs[$member]['msg_receive_body'])) {
183
+									$message_type .= '_body';
184
+				}
176 185
 			}
177 186
 			// If neither of the above, this might be a redundent row due to the OR clause in our SQL query, skip
178
-			else
179
-				continue;
187
+			else {
188
+							continue;
189
+			}
180 190
 
181 191
 			// Bitwise check: Receiving a email notification?
182 192
 			if ($pref & self::RECEIVE_NOTIFY_EMAIL)
@@ -193,8 +203,9 @@  discard block
 block discarded – undo
193 203
 				$mail_result = sendmail($data['email_address'], $emaildata['subject'], $emaildata['body'], null, 'm' . $topicOptions['id'], $emaildata['is_html']);
194 204
 
195 205
 				// We failed, don't trigger a alert as we don't have a way to attempt to resend just the email currently.
196
-				if ($mail_result === false)
197
-					continue;
206
+				if ($mail_result === false) {
207
+									continue;
208
+				}
198 209
 			}
199 210
 
200 211
 			// Bitwise check: Receiving a alert?
@@ -245,14 +256,15 @@  discard block
 block discarded – undo
245 256
 		);
246 257
 
247 258
 		// Insert the alerts if any
248
-		if (!empty($alert_rows))
249
-			$smcFunc['db_insert']('',
259
+		if (!empty($alert_rows)) {
260
+					$smcFunc['db_insert']('',
250 261
 				'{db_prefix}user_alerts',
251 262
 				array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
252 263
 					'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
253 264
 				$alert_rows,
254 265
 				array()
255 266
 			);
267
+		}
256 268
 
257 269
 		return true;
258 270
 	}
@@ -263,8 +275,9 @@  discard block
 block discarded – undo
263 275
 
264 276
 		foreach ($quotedMembers as $id => $member)
265 277
 		{
266
-			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote']))
267
-				continue;
278
+			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote'])) {
279
+							continue;
280
+			}
268 281
 
269 282
 			$done_members[] = $id;
270 283
 
@@ -318,32 +331,35 @@  discard block
 block discarded – undo
318 331
 		{
319 332
 			if (preg_match('/\[quote(.*)?\]/i', $block, $matches))
320 333
 			{
321
-				if ($quote_level == 0)
322
-					$message .= '[quote' . $matches[1] . ']';
334
+				if ($quote_level == 0) {
335
+									$message .= '[quote' . $matches[1] . ']';
336
+				}
323 337
 				$quote_level++;
324
-			}
325
-			elseif (preg_match('/\[\/quote\]/i', $block))
338
+			} elseif (preg_match('/\[\/quote\]/i', $block))
326 339
 			{
327
-				if ($quote_level <= 1)
328
-					$message .= '[/quote]';
340
+				if ($quote_level <= 1) {
341
+									$message .= '[/quote]';
342
+				}
329 343
 				if ($quote_level >= 1)
330 344
 				{
331 345
 					$quote_level--;
332 346
 					$message .= "\n";
333 347
 				}
348
+			} elseif ($quote_level <= 1) {
349
+							$message .= $block;
334 350
 			}
335
-			elseif ($quote_level <= 1)
336
-				$message .= $block;
337 351
 		}
338 352
 
339 353
 		preg_match_all('/\[quote.*?link=msg=([0-9]+).*?\]/i', $message, $matches);
340 354
 
341 355
 		$id_msgs = $matches[1];
342
-		foreach ($id_msgs as $k => $id_msg)
343
-			$id_msgs[$k] = (int) $id_msg;
356
+		foreach ($id_msgs as $k => $id_msg) {
357
+					$id_msgs[$k] = (int) $id_msg;
358
+		}
344 359
 
345
-		if (empty($id_msgs))
346
-			return array();
360
+		if (empty($id_msgs)) {
361
+					return array();
362
+		}
347 363
 
348 364
 		// Get the messages
349 365
 		$request = $smcFunc['db_query']('', '
@@ -361,8 +377,9 @@  discard block
 block discarded – undo
361 377
 		$members = array();
362 378
 		while ($row = $smcFunc['db_fetch_assoc']($request))
363 379
 		{
364
-			if ($posterOptions['id'] == $row['id_member'])
365
-				continue;
380
+			if ($posterOptions['id'] == $row['id_member']) {
381
+							continue;
382
+			}
366 383
 
367 384
 			$members[$row['id_member']] = $row;
368 385
 		}
@@ -376,10 +393,11 @@  discard block
 block discarded – undo
376 393
 
377 394
 		foreach ($members as $id => $member)
378 395
 		{
379
-			if (!empty($prefs[$id]['msg_mention']))
380
-				$done_members[] = $id;
381
-			else
382
-				continue;
396
+			if (!empty($prefs[$id]['msg_mention'])) {
397
+							$done_members[] = $id;
398
+			} else {
399
+							continue;
400
+			}
383 401
 
384 402
 			// Alerts' emails are always instant
385 403
 			if ($prefs[$id]['msg_mention'] & self::RECEIVE_NOTIFY_EMAIL)
Please login to merge, or discard this patch.
Sources/ManageMail.php 1 patch
Braces   +30 added lines, -21 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
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
  * Main dispatcher. This function checks permissions and passes control through to the relevant section.
@@ -246,8 +247,9 @@  discard block
 block discarded – undo
246 247
 	while ($row = $smcFunc['db_fetch_assoc']($request))
247 248
 	{
248 249
 		// Private PM/email subjects and similar shouldn't be shown in the mailbox area.
249
-		if (!empty($row['private']))
250
-			$row['subject'] = $txt['personal_message'];
250
+		if (!empty($row['private'])) {
251
+					$row['subject'] = $txt['personal_message'];
252
+		}
251 253
 
252 254
 		$mails[] = $row;
253 255
 	}
@@ -301,8 +303,9 @@  discard block
 block discarded – undo
301 303
 		$element = substr($key, strrpos($key, '_') + 1);
302 304
 		$processedBirthdayEmails[$index][$element] = $value;
303 305
 	}
304
-	foreach ($processedBirthdayEmails as $index => $dummy)
305
-		$emails[$index] = $index;
306
+	foreach ($processedBirthdayEmails as $index => $dummy) {
307
+			$emails[$index] = $index;
308
+	}
306 309
 
307 310
 	$config_vars = array(
308 311
 			// Mail queue stuff, this rocks ;)
@@ -323,8 +326,9 @@  discard block
 block discarded – undo
323 326
 
324 327
 	call_integration_hook('integrate_modify_mail_settings', array(&$config_vars));
325 328
 
326
-	if ($return_config)
327
-		return $config_vars;
329
+	if ($return_config) {
330
+			return $config_vars;
331
+	}
328 332
 
329 333
 	// Saving?
330 334
 	if (isset($_GET['save']))
@@ -399,9 +403,9 @@  discard block
 block discarded – undo
399 403
 		);
400 404
 		list ($_GET['te']) = $smcFunc['db_fetch_row']($request);
401 405
 		$smcFunc['db_free_result']($request);
406
+	} else {
407
+			$_GET['te'] = (int) $_GET['te'];
402 408
 	}
403
-	else
404
-		$_GET['te'] = (int) $_GET['te'];
405 409
 
406 410
 	$_GET['sent'] = isset($_GET['sent']) ? (int) $_GET['sent'] : 0;
407 411
 
@@ -425,12 +429,14 @@  discard block
 block discarded – undo
425 429
 
426 430
 	// Try get more time...
427 431
 	@set_time_limit(600);
428
-	if (function_exists('apache_reset_timeout'))
429
-		@apache_reset_timeout();
432
+	if (function_exists('apache_reset_timeout')) {
433
+			@apache_reset_timeout();
434
+	}
430 435
 
431 436
 	// Have we already used our maximum time?
432
-	if ((time() - $time_start) < 5)
433
-		return;
437
+	if ((time() - $time_start) < 5) {
438
+			return;
439
+	}
434 440
 
435 441
 	$context['continue_get_data'] = '?action=admin;area=mailqueue;sa=clear;te=' . $_GET['te'] . ';sent=' . $_GET['sent'] . ';' . $context['session_var'] . '=' . $context['session_id'];
436 442
 	$context['page_title'] = $txt['not_done_title'];
@@ -480,9 +486,10 @@  discard block
 block discarded – undo
480 486
 	}
481 487
 
482 488
 	// The result.
483
-	if (isset($_GET['result']))
484
-		$context['result'] = ($_GET['result'] == 'success' ? 'success' : 'failure');
485
-}
489
+	if (isset($_GET['result'])) {
490
+			$context['result'] = ($_GET['result'] == 'success' ? 'success' : 'failure');
491
+	}
492
+	}
486 493
 
487 494
 /**
488 495
  * Little utility function to calculate how long ago a time was.
@@ -494,8 +501,9 @@  discard block
 block discarded – undo
494 501
 {
495 502
 	global $txt;
496 503
 
497
-	if ($time_diff < 0)
498
-		$time_diff = 0;
504
+	if ($time_diff < 0) {
505
+			$time_diff = 0;
506
+	}
499 507
 
500 508
 	// Just do a bit of an if fest...
501 509
 	if ($time_diff > 86400)
@@ -516,8 +524,9 @@  discard block
 block discarded – undo
516 524
 		return sprintf($minutes == 1 ? $txt['mq_minute'] : $txt['mq_minutes'], $minutes);
517 525
 	}
518 526
 	// Otherwise must be second
519
-	else
520
-		return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff);
521
-}
527
+	else {
528
+			return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff);
529
+	}
530
+	}
522 531
 
523 532
 ?>
524 533
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/ManageMail.template.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,9 +48,10 @@
 block discarded – undo
48 48
 	global $context, $txt;
49 49
 
50 50
 	// The results.
51
-	if (!empty($context['result']))
52
-		echo '
51
+	if (!empty($context['result'])) {
52
+			echo '
53 53
 					<div class="', $context['result'] == 'success' ? 'infobox' : 'errorbox', '">', $txt['mailtest_result_' . $context['result']], '</div>';
54
+	}
54 55
 
55 56
 	echo '
56 57
 	<form id="admin_form_wrapper" action="', $context['post_url'], '" method="post">
Please login to merge, or discard this patch.