Completed
Pull Request — release-2.1 (#4959)
by Jeremy
07:43
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 1 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.
Themes/default/PersonalMessage.template.php 1 patch
Braces   +285 added lines, -199 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 	<div id="personal_messages">';
22 22
 
23 23
 	// Show the capacity bar, if available.
24
-	if (!empty($context['limit_bar']))
25
-		echo '
24
+	if (!empty($context['limit_bar'])) {
25
+			echo '
26 26
 		<div class="cat_bar">
27 27
 			<h3 class="catbg">
28 28
 				<span class="floatleft">', $txt['pm_capacity'], ':</span>
@@ -32,14 +32,16 @@  discard block
 block discarded – undo
32 32
 				<span class="floatright', $context['limit_bar']['percent'] > 90 ? ' alert' : '', '">', $context['limit_bar']['text'], '</span>
33 33
 			</h3>
34 34
 		</div>';
35
+	}
35 36
 
36 37
 	// Message sent? Show a small indication.
37
-	if (isset($context['pm_sent']))
38
-		echo '
38
+	if (isset($context['pm_sent'])) {
39
+			echo '
39 40
 		<div class="infobox">
40 41
 			', $txt['pm_sent'], '
41 42
 		</div>';
42
-}
43
+	}
44
+	}
43 45
 
44 46
 /**
45 47
  * Just the end of the index bar, nothing special.
@@ -68,13 +70,13 @@  discard block
 block discarded – undo
68 70
 		</div>
69 71
 		<div class="pm_unread">';
70 72
 
71
-	if (empty($context['unread_pms']))
72
-		echo '
73
+	if (empty($context['unread_pms'])) {
74
+			echo '
73 75
 			<div class="no_unread">', $txt['pm_no_unread'], '</div>';
74
-	else
76
+	} else
75 77
 	{
76
-		foreach ($context['unread_pms'] as $id_pm => $pm_details)
77
-			echo '
78
+		foreach ($context['unread_pms'] as $id_pm => $pm_details) {
79
+					echo '
78 80
 			<div class="unread">
79 81
 				', !empty($pm_details['member']) ? $pm_details['member']['avatar']['image'] : '', '
80 82
 				<div class="details">
@@ -85,6 +87,7 @@  discard block
 block discarded – undo
85 87
 					</div>
86 88
 				</div>
87 89
 			</div>';
90
+		}
88 91
 	}
89 92
 
90 93
 	echo '
@@ -193,14 +196,15 @@  discard block
 block discarded – undo
193 196
 	if ($context['get_pmessage']('message', true))
194 197
 	{
195 198
 		// Show the helpful titlebar - generally.
196
-		if ($context['display_mode'] != 1)
197
-			echo '
199
+		if ($context['display_mode'] != 1) {
200
+					echo '
198 201
 			<div class="cat_bar">
199 202
 				<h3 class="catbg">
200 203
 					<span id="author">', $txt['author'], '</span>
201 204
 					<span id="topic_title">', $txt[$context['display_mode'] == 0 ? 'messages' : 'conversation'], '</span>
202 205
 				</h3>
203 206
 			</div>';
207
+		}
204 208
 
205 209
 		// Show a few buttons if we are in conversation mode and outputting the first message.
206 210
 		if ($context['display_mode'] == 2)
@@ -228,9 +232,10 @@  discard block
 block discarded – undo
228 232
 					<div class="custom_fields_above_member">
229 233
 						<ul class="nolist">';
230 234
 
231
-				foreach ($message['custom_fields']['above_member'] as $custom)
232
-					echo '
235
+				foreach ($message['custom_fields']['above_member'] as $custom) {
236
+									echo '
233 237
 							<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
238
+				}
234 239
 
235 240
 				echo '
236 241
 						</ul>
@@ -242,25 +247,28 @@  discard block
 block discarded – undo
242 247
 						<a id="msg', $message['id'], '"></a>';
243 248
 
244 249
 			// Show online and offline buttons?
245
-			if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
246
-				echo '
250
+			if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest']) {
251
+							echo '
247 252
 						<span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>';
253
+			}
248 254
 
249 255
 			// Custom fields BEFORE the username?
250
-			if (!empty($message['custom_fields']['before_member']))
251
-				foreach ($message['custom_fields']['before_member'] as $custom)
256
+			if (!empty($message['custom_fields']['before_member'])) {
257
+							foreach ($message['custom_fields']['before_member'] as $custom)
252 258
 					echo '
253 259
 						<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
260
+			}
254 261
 
255 262
 			// Show a link to the member's profile.
256 263
 			echo '
257 264
 				', $message['member']['link'];
258 265
 
259 266
 				// Custom fields AFTER the username?
260
-				if (!empty($message['custom_fields']['after_member']))
261
-					foreach ($message['custom_fields']['after_member'] as $custom)
267
+				if (!empty($message['custom_fields']['after_member'])) {
268
+									foreach ($message['custom_fields']['after_member'] as $custom)
262 269
 						echo '
263 270
 						<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
271
+				}
264 272
 
265 273
 			echo '
266 274
 					</h4>';
@@ -269,48 +277,56 @@  discard block
 block discarded – undo
269 277
 					<ul class="user_info">';
270 278
 
271 279
 			// Show the user's avatar.
272
-			if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
273
-				echo '
280
+			if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image'])) {
281
+							echo '
274 282
 						<li class="avatar">
275 283
 							<a href="', $scripturl, '?action=profile;u=', $message['member']['id'], '">', $message['member']['avatar']['image'], '</a>
276 284
 						</li>';
285
+			}
277 286
 
278 287
 			// Are there any custom fields below the avatar?
279
-			if (!empty($message['custom_fields']['below_avatar']))
280
-				foreach ($message['custom_fields']['below_avatar'] as $custom)
288
+			if (!empty($message['custom_fields']['below_avatar'])) {
289
+							foreach ($message['custom_fields']['below_avatar'] as $custom)
281 290
 					echo '
282 291
 						<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
292
+			}
283 293
 
284
-			if (!$message['member']['is_guest'])
285
-				echo '
294
+			if (!$message['member']['is_guest']) {
295
+							echo '
286 296
 						<li class="icons">', $message['member']['group_icons'], '</li>';
297
+			}
287 298
 			// Show the member's primary group (like 'Administrator') if they have one.
288
-			if (isset($message['member']['group']) && $message['member']['group'] != '')
289
-				echo '
299
+			if (isset($message['member']['group']) && $message['member']['group'] != '') {
300
+							echo '
290 301
 						<li class="membergroup">', $message['member']['group'], '</li>';
302
+			}
291 303
 
292 304
 			// Show the member's custom title, if they have one.
293
-			if (isset($message['member']['title']) && $message['member']['title'] != '')
294
-				echo '
305
+			if (isset($message['member']['title']) && $message['member']['title'] != '') {
306
+							echo '
295 307
 						<li class="title">', $message['member']['title'], '</li>';
308
+			}
296 309
 
297 310
 			// Don't show these things for guests.
298 311
 			if (!$message['member']['is_guest'])
299 312
 			{
300 313
 				// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
301
-				if ((empty($modSettings['hide_post_group']) || $message['member']['group'] == '') && $message['member']['post_group'] != '')
302
-					echo '
314
+				if ((empty($modSettings['hide_post_group']) || $message['member']['group'] == '') && $message['member']['post_group'] != '') {
315
+									echo '
303 316
 						<li class="postgroup">', $message['member']['post_group'], '</li>';
317
+				}
304 318
 
305 319
 				// Show how many posts they have made.
306
-				if (!isset($context['disabled_fields']['posts']))
307
-					echo '
320
+				if (!isset($context['disabled_fields']['posts'])) {
321
+									echo '
308 322
 						<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
323
+				}
309 324
 
310 325
 				// Show their personal text?
311
-				if (!empty($modSettings['show_blurb']) && $message['member']['blurb'] != '')
312
-					echo '
326
+				if (!empty($modSettings['show_blurb']) && $message['member']['blurb'] != '') {
327
+									echo '
313 328
 						<li class="blurb">', $message['member']['blurb'], '</li>';
329
+				}
314 330
 
315 331
 				// Any custom fields to show as icons?
316 332
 				if (!empty($message['custom_fields']['icons']))
@@ -319,9 +335,10 @@  discard block
 block discarded – undo
319 335
 						<li class="im_icons">
320 336
 							<ol>';
321 337
 
322
-					foreach ($message['custom_fields']['icons'] as $custom)
323
-						echo '
338
+					foreach ($message['custom_fields']['icons'] as $custom) {
339
+											echo '
324 340
 								<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
341
+					}
325 342
 
326 343
 					echo '
327 344
 							</ol>
@@ -329,25 +346,28 @@  discard block
 block discarded – undo
329 346
 				}
330 347
 
331 348
 				// Show the IP to this user for this post - because you can moderate?
332
-				if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip']))
333
-					echo '
349
+				if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip'])) {
350
+									echo '
334 351
 						<li class="poster_ip">
335 352
 							<a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">(?)</a>
336 353
 						</li>';
354
+				}
337 355
 
338 356
 				// Or, should we show it because this is you?
339
-				elseif ($message['can_see_ip'])
340
-					echo '
357
+				elseif ($message['can_see_ip']) {
358
+									echo '
341 359
 						<li class="poster_ip">
342 360
 							<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $message['member']['ip'], '</a>
343 361
 						</li>';
362
+				}
344 363
 
345 364
 				// Okay, you are logged in, then we can show something about why IPs are logged...
346
-				else
347
-					echo '
365
+				else {
366
+									echo '
348 367
 						<li class="poster_ip">
349 368
 							<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a>
350 369
 						</li>';
370
+				}
351 371
 
352 372
 				// Show the profile, website, email address, and personal message buttons.
353 373
 				if ($message['member']['show_profile_buttons'])
@@ -357,24 +377,28 @@  discard block
 block discarded – undo
357 377
 							<ol class="profile_icons">';
358 378
 
359 379
 					// Show the profile button
360
-					if ($message['member']['can_view_profile'])
361
-						echo '
380
+					if ($message['member']['can_view_profile']) {
381
+											echo '
362 382
 								<li><a href="', $message['member']['href'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/icons/profile_sm.png" alt="' . $txt['view_profile'] . '" title="' . $txt['view_profile'] . '">' : $txt['view_profile']), '</a></li>';
383
+					}
363 384
 
364 385
 					// Don't show an icon if they haven't specified a website.
365
-					if ($message['member']['website']['url'] != '' && !isset($context['disabled_fields']['website']))
366
-						echo '
386
+					if ($message['member']['website']['url'] != '' && !isset($context['disabled_fields']['website'])) {
387
+											echo '
367 388
 								<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" rel="noopener">', ($settings['use_image_buttons'] ? '<span class="generic_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
389
+					}
368 390
 
369 391
 					// Don't show the email address if they want it hidden.
370
-					if ($message['member']['show_email'])
371
-						echo '
392
+					if ($message['member']['show_email']) {
393
+											echo '
372 394
 								<li><a href="mailto:', $message['member']['email'], '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
395
+					}
373 396
 
374 397
 					// Since we know this person isn't a guest, you *can* message them.
375
-					if ($context['can_send_pm'])
376
-						echo '
398
+					if ($context['can_send_pm']) {
399
+											echo '
377 400
 								<li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<span class="generic_icons im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . ' centericon" title="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '"></span> ' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>';
401
+					}
378 402
 
379 403
 					echo '
380 404
 							</ol>
@@ -382,21 +406,24 @@  discard block
 block discarded – undo
382 406
 				}
383 407
 
384 408
 				// Any custom fields for standard placement?
385
-				if (!empty($message['custom_fields']['standard']))
386
-					foreach ($message['custom_fields']['standard'] as $custom)
409
+				if (!empty($message['custom_fields']['standard'])) {
410
+									foreach ($message['custom_fields']['standard'] as $custom)
387 411
 						echo '
388 412
 						<li class="custom ', $custom['col_name'] ,'">', $custom['title'], ': ', $custom['value'], '</li>';
413
+				}
389 414
 
390 415
 				// Are we showing the warning status?
391
-				if ($message['member']['can_see_warning'])
392
-					echo '
416
+				if ($message['member']['can_see_warning']) {
417
+									echo '
393 418
 						<li class="warning">', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="generic_icons warning_', $message['member']['warning_status'], '"></span>', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span></li>';
419
+				}
394 420
 
395 421
 				// Are there any custom fields to show at the bottom of the poster info?
396
-				if (!empty($message['custom_fields']['bottom_poster']))
397
-					foreach ($message['custom_fields']['bottom_poster'] as $custom)
422
+				if (!empty($message['custom_fields']['bottom_poster'])) {
423
+									foreach ($message['custom_fields']['bottom_poster'] as $custom)
398 424
 						echo '
399 425
 						<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
426
+				}
400 427
 			}
401 428
 
402 429
 			// Done with the information about the poster... on to the post itself.
@@ -415,25 +442,29 @@  discard block
 block discarded – undo
415 442
 							<span class="smalltext">&#171; <strong> ', $txt['sent_to'], ':</strong> ';
416 443
 
417 444
 			// People it was sent directly to....
418
-			if (!empty($message['recipients']['to']))
419
-				echo implode(', ', $message['recipients']['to']);
445
+			if (!empty($message['recipients']['to'])) {
446
+							echo implode(', ', $message['recipients']['to']);
447
+			}
420 448
 
421 449
 			// Otherwise, we're just going to say "some people"...
422
-			elseif ($context['folder'] != 'sent')
423
-				echo '(', $txt['pm_undisclosed_recipients'], ')';
450
+			elseif ($context['folder'] != 'sent') {
451
+							echo '(', $txt['pm_undisclosed_recipients'], ')';
452
+			}
424 453
 
425 454
 			echo '
426 455
 								<strong> ', $txt['on'], ':</strong> ', $message['time'], ' &#187;
427 456
 							</span>';
428 457
 
429 458
 			// If we're in the sent items, show who it was sent to besides the "To:" people.
430
-			if (!empty($message['recipients']['bcc']))
431
-				echo '<br>
459
+			if (!empty($message['recipients']['bcc'])) {
460
+							echo '<br>
432 461
 							<span class="smalltext">&#171; <strong> ', $txt['pm_bcc'], ':</strong> ', implode(', ', $message['recipients']['bcc']), ' &#187;</span>';
462
+			}
433 463
 
434
-			if (!empty($message['is_replied_to']))
435
-				echo '<br>
464
+			if (!empty($message['is_replied_to'])) {
465
+							echo '<br>
436 466
 							<span class="smalltext">&#171; ', $context['folder'] == 'sent' ? $txt['pm_sent_is_replied_to'] : $txt['pm_is_replied_to'], ' &#187;</span>';
467
+			}
437 468
 
438 469
 			echo '
439 470
 						</div><!-- .keyinfo -->
@@ -443,13 +474,15 @@  discard block
 block discarded – undo
443 474
 							', $message['body'], '
444 475
 						</div>';
445 476
 
446
-			if ($message['can_report'] || $context['can_send_pm'])
447
-				echo '
477
+			if ($message['can_report'] || $context['can_send_pm']) {
478
+							echo '
448 479
 						<div class="under_message">';
480
+			}
449 481
 
450
-			if ($message['can_report'])
451
-				echo '
482
+			if ($message['can_report']) {
483
+							echo '
452 484
 							<a href="' . $scripturl . '?action=pm;sa=report;l=' . $context['current_label_id'] . ';pmsg=' . $message['id'] . '" class="floatright">' . $txt['pm_report_to_admin'] . '</a>';
485
+			}
453 486
 
454 487
 			echo '
455 488
 							<ul class="quickbuttons">';
@@ -461,32 +494,36 @@  discard block
 block discarded – undo
461 494
 				if (!$message['member']['is_guest'])
462 495
 				{
463 496
 					// Is there than more than one recipient you can reply to?
464
-					if ($message['number_recipients'] > 1)
465
-						echo '
497
+					if ($message['number_recipients'] > 1) {
498
+											echo '
466 499
 								<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote;u=all"><span class="generic_icons reply_all_button"></span>', $txt['reply_to_all'], '</a></li>';
500
+					}
467 501
 
468 502
 					echo '
469 503
 								<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';u=', $message['member']['id'], '"><span class="generic_icons reply_button"></span>', $txt['reply'], '</a></li>
470 504
 								<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote', $context['folder'] == 'sent' ? '' : ';u=' . $message['member']['id'], '"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>';
471 505
 				}
472 506
 				// This is for "forwarding" - even if the member is gone.
473
-				else
474
-					echo '
507
+				else {
508
+									echo '
475 509
 								<li><a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote"><span class="generic_icons quote"></span>', $txt['reply_quote'], '</a></li>';
510
+				}
476 511
 			}
477 512
 			echo '
478 513
 								<li><a href="', $scripturl, '?action=pm;sa=pmactions;pm_actions%5b', $message['id'], '%5D=delete;f=', $context['folder'], ';start=', $context['start'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', addslashes($txt['remove_message_question']), '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['delete'], '</a></li>';
479 514
 
480
-			if (empty($context['display_mode']))
481
-				echo '
515
+			if (empty($context['display_mode'])) {
516
+							echo '
482 517
 								<li><input type="checkbox" name="pms[]" id="deletedisplay', $message['id'], '" value="', $message['id'], '" onclick="document.getElementById(\'deletelisting', $message['id'], '\').checked = this.checked;"></li>';
518
+			}
483 519
 
484 520
 			echo '
485 521
 							</ul>';
486 522
 
487
-			if ($message['can_report'] || $context['can_send_pm'])
488
-			echo '
523
+			if ($message['can_report'] || $context['can_send_pm']) {
524
+						echo '
489 525
 						</div><!-- .under_message -->';
526
+			}
490 527
 
491 528
 			// Are there any custom profile fields for above the signature?
492 529
 			if (!empty($message['custom_fields']['above_signature']))
@@ -495,9 +532,10 @@  discard block
 block discarded – undo
495 532
 						<div class="custom_fields_above_signature">
496 533
 							<ul class="nolist">';
497 534
 
498
-				foreach ($message['custom_fields']['above_signature'] as $custom)
499
-					echo '
535
+				foreach ($message['custom_fields']['above_signature'] as $custom) {
536
+									echo '
500 537
 								<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
538
+				}
501 539
 
502 540
 				echo '
503 541
 							</ul>
@@ -505,11 +543,12 @@  discard block
 block discarded – undo
505 543
 			}
506 544
 
507 545
 			// Show the member's signature?
508
-			if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
509
-				echo '
546
+			if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled']) {
547
+							echo '
510 548
 						<div class="signature">
511 549
 							', $message['member']['signature'], '
512 550
 						</div>';
551
+			}
513 552
 
514 553
 			// Are there any custom profile fields for below the signature?
515 554
 			if (!empty($message['custom_fields']['below_signature']))
@@ -518,9 +557,10 @@  discard block
 block discarded – undo
518 557
 						<div class="custom_fields_below_signature">
519 558
 							<ul class="nolist">';
520 559
 
521
-				foreach ($message['custom_fields']['below_signature'] as $custom)
522
-					echo '
560
+				foreach ($message['custom_fields']['below_signature'] as $custom) {
561
+									echo '
523 562
 								<li class="custom ', $custom['col_name'] ,'">', $custom['value'], '</li>';
563
+				}
524 564
 
525 565
 				echo '
526 566
 							</ul>
@@ -547,10 +587,11 @@  discard block
 block discarded – undo
547 587
 						echo '
548 588
 								<option value="" disabled>', $txt['pm_msg_label_apply'], ':</option>';
549 589
 
550
-						foreach ($context['labels'] as $label)
551
-							if (!isset($message['labels'][$label['id']]))
590
+						foreach ($context['labels'] as $label) {
591
+													if (!isset($message['labels'][$label['id']]))
552 592
 								echo '
553 593
 								<option value="', $label['id'], '">', $label['name'], '</option>';
594
+						}
554 595
 					}
555 596
 
556 597
 					// ... and are there any that can be removed?
@@ -559,9 +600,10 @@  discard block
 block discarded – undo
559 600
 						echo '
560 601
 								<option value="" disabled>', $txt['pm_msg_label_remove'], ':</option>';
561 602
 
562
-						foreach ($message['labels'] as $label)
563
-							echo '
603
+						foreach ($message['labels'] as $label) {
604
+													echo '
564 605
 								<option value="', $label['id'], '">&nbsp;', $label['name'], '</option>';
606
+						}
565 607
 					}
566 608
 					echo '
567 609
 							</select>
@@ -580,14 +622,15 @@  discard block
 block discarded – undo
580 622
 			</div><!-- .windowbg -->';
581 623
 		}
582 624
 
583
-		if (empty($context['display_mode']))
584
-			echo '
625
+		if (empty($context['display_mode'])) {
626
+					echo '
585 627
 			<div class="pagesection">
586 628
 				<div class="floatleft">', $context['page_index'], '</div>
587 629
 				<div class="floatright">
588 630
 					<input type="submit" name="del_selected" value="', $txt['quickmod_delete_selected'], '" onclick="if (!confirm(\'', $txt['delete_selected_confirm'], '\')) return false;" class="button">
589 631
 				</div>
590 632
 			</div>';
633
+		}
591 634
 
592 635
 		// Show a few buttons if we are in conversation mode and outputting the first message.
593 636
 		elseif ($context['display_mode'] == 2 && isset($context['conversation_buttons']))
@@ -647,11 +690,12 @@  discard block
 block discarded – undo
647 690
 		</thead>
648 691
 		<tbody>';
649 692
 
650
-	if (!$context['show_delete'])
651
-		echo '
693
+	if (!$context['show_delete']) {
694
+			echo '
652 695
 			<tr class="windowbg">
653 696
 				<td colspan="5">', $txt['pm_alert_none'], '</td>
654 697
 			</tr>';
698
+	}
655 699
 
656 700
 	while ($message = $context['get_pmessage']('subject'))
657 701
 	{
@@ -709,17 +753,19 @@  discard block
 block discarded – undo
709 753
 
710 754
 			foreach ($context['labels'] as $label)
711 755
 			{
712
-				if ($label['id'] != $context['current_label_id'])
713
-					echo '
756
+				if ($label['id'] != $context['current_label_id']) {
757
+									echo '
714 758
 				<option value="add_', $label['id'], '">&nbsp;', $label['name'], '</option>';
759
+				}
715 760
 			}
716 761
 
717 762
 			echo '
718 763
 				<option value="" disabled>', $txt['pm_msg_label_remove'], ':</option>';
719 764
 
720
-			foreach ($context['labels'] as $label)
721
-				echo '
765
+			foreach ($context['labels'] as $label) {
766
+							echo '
722 767
 				<option value="rem_', $label['id'], '">&nbsp;', $label['name'], '</option>';
768
+			}
723 769
 
724 770
 			echo '
725 771
 			</select>
@@ -744,11 +790,12 @@  discard block
 block discarded – undo
744 790
 {
745 791
 	global $context, $scripturl, $txt;
746 792
 
747
-	if (!empty($context['search_errors']))
748
-		echo '
793
+	if (!empty($context['search_errors'])) {
794
+			echo '
749 795
 		<div class="errorbox">
750 796
 			', implode('<br>', $context['search_errors']['messages']), '
751 797
 		</div>';
798
+	}
752 799
 
753 800
 	echo '
754 801
 	<form action="', $scripturl, '?action=pm;sa=search2" method="post" accept-charset="', $context['character_set'], '" name="searchform" id="searchform">
@@ -816,9 +863,10 @@  discard block
 block discarded – undo
816 863
 				</dd>
817 864
 			</dl>';
818 865
 
819
-	if (!$context['currently_using_labels'])
820
-		echo '
866
+	if (!$context['currently_using_labels']) {
867
+			echo '
821 868
 				<input type="submit" name="pm_search" value="', $txt['pm_search_go'], '" class="button floatright">';
869
+	}
822 870
 
823 871
 	echo '
824 872
 		</div><!-- .roundframe -->';
@@ -837,12 +885,13 @@  discard block
 block discarded – undo
837 885
 				<div id="advanced_panel_div">
838 886
 					<ul id="searchLabelsExpand">';
839 887
 
840
-		foreach ($context['search_labels'] as $label)
841
-			echo '
888
+		foreach ($context['search_labels'] as $label) {
889
+					echo '
842 890
 						<li>
843 891
 							<label for="searchlabel_', $label['id'], '"><input type="checkbox" id="searchlabel_', $label['id'], '" name="searchlabel[', $label['id'], ']" value="', $label['id'], '"', $label['checked'] ? ' checked' : '', '>
844 892
 							', $label['name'], '</label>
845 893
 						</li>';
894
+		}
846 895
 
847 896
 		echo '
848 897
 					</ul>
@@ -904,8 +953,8 @@  discard block
 block discarded – undo
904 953
 		</div>';
905 954
 
906 955
 	// Complete results?
907
-	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
908
-		echo '
956
+	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages'])) {
957
+			echo '
909 958
 		<table class="table_grid">
910 959
 			<thead>
911 960
 				<tr class="title_bar">
@@ -915,6 +964,7 @@  discard block
 block discarded – undo
915 964
 				</tr>
916 965
 			</thead>
917 966
 			<tbody>';
967
+	}
918 968
 
919 969
 	// Print each message out...
920 970
 	foreach ($context['personal_messages'] as $message)
@@ -934,12 +984,14 @@  discard block
 block discarded – undo
934 984
 
935 985
 			// Show the recipients.
936 986
 			// @todo This doesn't deal with the sent item searching quite right for bcc.
937
-			if (!empty($message['recipients']['to']))
938
-				echo implode(', ', $message['recipients']['to']);
987
+			if (!empty($message['recipients']['to'])) {
988
+							echo implode(', ', $message['recipients']['to']);
989
+			}
939 990
 
940 991
 			// Otherwise, we're just going to say "some people"...
941
-			elseif ($context['folder'] != 'sent')
942
-				echo '(', $txt['pm_undisclosed_recipients'], ')';
992
+			elseif ($context['folder'] != 'sent') {
993
+							echo '(', $txt['pm_undisclosed_recipients'], ')';
994
+			}
943 995
 
944 996
 			echo '
945 997
 				</h3>
@@ -954,15 +1006,17 @@  discard block
 block discarded – undo
954 1006
 				$reply_button = create_button('im_reply.png', 'reply', 'reply', 'class="centericon"');
955 1007
 
956 1008
 				// You can only reply if they are not a guest...
957
-				if (!$message['member']['is_guest'])
958
-					echo '
1009
+				if (!$message['member']['is_guest']) {
1010
+									echo '
959 1011
 					<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote;u=', $context['folder'] == 'sent' ? '' : $message['member']['id'], '">', $quote_button , '</a>', $context['menu_separator'], '
960 1012
 					<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';u=', $message['member']['id'], '">', $reply_button , '</a> ', $context['menu_separator'];
1013
+				}
961 1014
 
962 1015
 				// This is for "forwarding" - even if the member is gone.
963
-				else
964
-					echo '
1016
+				else {
1017
+									echo '
965 1018
 					<a href="', $scripturl, '?action=pm;sa=send;f=', $context['folder'], $context['current_label_id'] != -1 ? ';l=' . $context['current_label_id'] : '', ';pmsg=', $message['id'], ';quote">', $quote_button , '</a>', $context['menu_separator'];
1019
+				}
966 1020
 			}
967 1021
 
968 1022
 			echo '
@@ -971,27 +1025,30 @@  discard block
 block discarded – undo
971 1025
 		}
972 1026
 		// Otherwise just a simple list!
973 1027
 		// @todo No context at all of the search?
974
-		else
975
-			echo '
1028
+		else {
1029
+					echo '
976 1030
 				<tr class="windowbg">
977 1031
 					<td>', $message['time'], '</td>
978 1032
 					<td>', $message['link'], '</td>
979 1033
 					<td>', $message['member']['link'], '</td>
980 1034
 				</tr>';
1035
+		}
981 1036
 	}
982 1037
 
983 1038
 	// Finish off the page...
984
-	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages']))
985
-		echo '
1039
+	if (empty($context['search_params']['show_complete']) && !empty($context['personal_messages'])) {
1040
+			echo '
986 1041
 			</tbody>
987 1042
 		</table>';
1043
+	}
988 1044
 
989 1045
 	// No results?
990
-	if (empty($context['personal_messages']))
991
-		echo '
1046
+	if (empty($context['personal_messages'])) {
1047
+			echo '
992 1048
 		<div class="windowbg">
993 1049
 			<p class="centertext">', $txt['pm_search_none_found'], '</p>
994 1050
 		</div>';
1051
+	}
995 1052
 
996 1053
 	echo '
997 1054
 		<div class="pagesection">
@@ -1016,15 +1073,17 @@  discard block
 block discarded – undo
1016 1073
 		</div>
1017 1074
 		<div class="windowbg">';
1018 1075
 
1019
-		if (!empty($context['send_log']['sent']))
1020
-			foreach ($context['send_log']['sent'] as $log_entry)
1076
+		if (!empty($context['send_log']['sent'])) {
1077
+					foreach ($context['send_log']['sent'] as $log_entry)
1021 1078
 				echo '
1022 1079
 			<span class="error">', $log_entry, '</span><br>';
1080
+		}
1023 1081
 
1024
-		if (!empty($context['send_log']['failed']))
1025
-			foreach ($context['send_log']['failed'] as $log_entry)
1082
+		if (!empty($context['send_log']['failed'])) {
1083
+					foreach ($context['send_log']['failed'] as $log_entry)
1026 1084
 				echo '
1027 1085
 			<span class="error">', $log_entry, '</span><br>';
1086
+		}
1028 1087
 
1029 1088
 		echo '
1030 1089
 		</div>
@@ -1070,12 +1129,13 @@  discard block
 block discarded – undo
1070 1129
 					</dl>
1071 1130
 				</div>';
1072 1131
 
1073
-	if (!empty($modSettings['drafts_pm_enabled']))
1074
-		echo '
1132
+	if (!empty($modSettings['drafts_pm_enabled'])) {
1133
+			echo '
1075 1134
 				<div id="draft_section" class="infobox"', isset($context['draft_saved']) ? '' : ' style="display: none;"', '>',
1076 1135
 					sprintf($txt['draft_pm_saved'], $scripturl . '?action=pm;sa=showpmdrafts'), '
1077 1136
 					', (!empty($modSettings['drafts_keep_days']) ? ' <strong>' . sprintf($txt['draft_save_warning'], $modSettings['drafts_keep_days']) . '</strong>' : ''), '
1078 1137
 				</div>';
1138
+	}
1079 1139
 
1080 1140
 	echo '
1081 1141
 				<dl id="post_header">';
@@ -1141,22 +1201,24 @@  discard block
 block discarded – undo
1141 1201
 						<dt><strong>', $txt['subject'], '</strong></dt>
1142 1202
 						<dd><strong>', $txt['draft_saved_on'], '</strong></dd>';
1143 1203
 
1144
-		foreach ($context['drafts'] as $draft)
1145
-			echo '
1204
+		foreach ($context['drafts'] as $draft) {
1205
+					echo '
1146 1206
 						<dt>', $draft['link'], '</dt>
1147 1207
 						<dd>', $draft['poster_time'], '</dd>';
1208
+		}
1148 1209
 		echo '
1149 1210
 					</dl>
1150 1211
 				</div>';
1151 1212
 	}
1152 1213
 
1153 1214
 	// Require an image to be typed to save spamming?
1154
-	if ($context['require_verification'])
1155
-		echo '
1215
+	if ($context['require_verification']) {
1216
+			echo '
1156 1217
 				<div class="post_verification">
1157 1218
 					<strong>', $txt['pm_visual_verification_label'], ':</strong>
1158 1219
 					', template_control_verification($context['visual_verification_id'], 'all'), '
1159 1220
 				</div>';
1221
+	}
1160 1222
 
1161 1223
 	// Send, Preview, spellcheck buttons.
1162 1224
 	echo '
@@ -1274,8 +1336,8 @@  discard block
 block discarded – undo
1274 1336
 			}';
1275 1337
 
1276 1338
 	// Code for showing and hiding drafts
1277
-	if (!empty($context['drafts']))
1278
-		echo '
1339
+	if (!empty($context['drafts'])) {
1340
+			echo '
1279 1341
 			var oSwapDraftOptions = new smc_Toggle({
1280 1342
 				bToggleEnabled: true,
1281 1343
 				bCurrentlyCollapsed: true,
@@ -1297,13 +1359,14 @@  discard block
 block discarded – undo
1297 1359
 					}
1298 1360
 				]
1299 1361
 			});';
1362
+	}
1300 1363
 
1301 1364
 	echo '
1302 1365
 		</script>';
1303 1366
 
1304 1367
 	// Show the message you're replying to.
1305
-	if ($context['reply'])
1306
-		echo '
1368
+	if ($context['reply']) {
1369
+			echo '
1307 1370
 		<br><br>
1308 1371
 		<div class="cat_bar">
1309 1372
 			<h3 class="catbg">', $txt['subject'], ': ', $context['quoted_message']['subject'], '</h3>
@@ -1317,6 +1380,7 @@  discard block
 block discarded – undo
1317 1380
 			', $context['quoted_message']['body'], '
1318 1381
 		</div>
1319 1382
 		<br class="clear">';
1383
+	}
1320 1384
 
1321 1385
 	echo '
1322 1386
 		<script>
@@ -1328,23 +1392,25 @@  discard block
 block discarded – undo
1328 1392
 				sToControlId: \'to_control\',
1329 1393
 				aToRecipients: [';
1330 1394
 
1331
-	foreach ($context['recipients']['to'] as $i => $member)
1332
-		echo '
1395
+	foreach ($context['recipients']['to'] as $i => $member) {
1396
+			echo '
1333 1397
 					{
1334 1398
 						sItemId: ', JavaScriptEscape($member['id']), ',
1335 1399
 						sItemName: ', JavaScriptEscape($member['name']), '
1336 1400
 					}', $i == count($context['recipients']['to']) - 1 ? '' : ',';
1401
+	}
1337 1402
 
1338 1403
 	echo '
1339 1404
 				],
1340 1405
 				aBccRecipients: [';
1341 1406
 
1342
-	foreach ($context['recipients']['bcc'] as $i => $member)
1343
-		echo '
1407
+	foreach ($context['recipients']['bcc'] as $i => $member) {
1408
+			echo '
1344 1409
 					{
1345 1410
 						sItemId: ', JavaScriptEscape($member['id']), ',
1346 1411
 						sItemName: ', JavaScriptEscape($member['name']), '
1347 1412
 					}', $i == count($context['recipients']['bcc']) - 1 ? '' : ',';
1413
+	}
1348 1414
 
1349 1415
 	echo '
1350 1416
 				],
@@ -1433,26 +1499,28 @@  discard block
 block discarded – undo
1433 1499
 					</th>
1434 1500
 					<th class="centertext table_icon">';
1435 1501
 
1436
-	if (count($context['labels']) > 2)
1437
-		echo '
1502
+	if (count($context['labels']) > 2) {
1503
+			echo '
1438 1504
 						<input type="checkbox" onclick="invertAll(this, this.form);">';
1505
+	}
1439 1506
 
1440 1507
 	echo '
1441 1508
 					</th>
1442 1509
 				</tr>
1443 1510
 			</thead>
1444 1511
 			<tbody>';
1445
-	if (count($context['labels']) < 2)
1446
-		echo '
1512
+	if (count($context['labels']) < 2) {
1513
+			echo '
1447 1514
 				<tr class="windowbg">
1448 1515
 					<td colspan="2">', $txt['pm_labels_no_exist'], '</td>
1449 1516
 				</tr>';
1450
-	else
1517
+	} else
1451 1518
 	{
1452 1519
 		foreach ($context['labels'] as $label)
1453 1520
 		{
1454
-			if ($label['id'] == -1)
1455
-				continue;
1521
+			if ($label['id'] == -1) {
1522
+							continue;
1523
+			}
1456 1524
 
1457 1525
 				echo '
1458 1526
 				<tr class="windowbg">
@@ -1467,12 +1535,13 @@  discard block
 block discarded – undo
1467 1535
 			</tbody>
1468 1536
 		</table>';
1469 1537
 
1470
-	if (!count($context['labels']) < 2)
1471
-		echo '
1538
+	if (!count($context['labels']) < 2) {
1539
+			echo '
1472 1540
 		<div class="block righttext">
1473 1541
 			<input type="submit" name="save" value="', $txt['save'], '" class="button">
1474 1542
 			<input type="submit" name="delete" value="', $txt['quickmod_delete_selected'], '" data-confirm="', $txt['pm_labels_delete'] ,'" class="button you_sure">
1475 1543
 		</div>';
1544
+	}
1476 1545
 
1477 1546
 	echo '
1478 1547
 		<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -1528,9 +1597,10 @@  discard block
 block discarded – undo
1528 1597
 					<select name="id_admin">
1529 1598
 						<option value="0">', $txt['pm_report_all_admins'], '</option>';
1530 1599
 
1531
-		foreach ($context['admins'] as $id => $name)
1532
-			echo '
1600
+		foreach ($context['admins'] as $id => $name) {
1601
+					echo '
1533 1602
 						<option value="', $id, '">', $name, '</option>';
1603
+		}
1534 1604
 
1535 1605
 		echo '
1536 1606
 					</select>
@@ -1593,9 +1663,10 @@  discard block
 block discarded – undo
1593 1663
 					</th>
1594 1664
 					<th class="centertext table_icon">';
1595 1665
 
1596
-	if (!empty($context['rules']))
1597
-		echo '
1666
+	if (!empty($context['rules'])) {
1667
+			echo '
1598 1668
 						<input type="checkbox" onclick="invertAll(this, this.form);">';
1669
+	}
1599 1670
 
1600 1671
 	echo '
1601 1672
 					</th>
@@ -1603,16 +1674,17 @@  discard block
 block discarded – undo
1603 1674
 			</thead>
1604 1675
 			<tbody>';
1605 1676
 
1606
-	if (empty($context['rules']))
1607
-		echo '
1677
+	if (empty($context['rules'])) {
1678
+			echo '
1608 1679
 				<tr class="windowbg">
1609 1680
 					<td colspan="2">
1610 1681
 						', $txt['pm_rules_none'], '
1611 1682
 					</td>
1612 1683
 				</tr>';
1684
+	}
1613 1685
 
1614
-	foreach ($context['rules'] as $rule)
1615
-		echo '
1686
+	foreach ($context['rules'] as $rule) {
1687
+			echo '
1616 1688
 				<tr class="windowbg">
1617 1689
 					<td>
1618 1690
 						<a href="', $scripturl, '?action=pm;sa=manrules;add;rid=', $rule['id'], '">', $rule['name'], '</a>
@@ -1621,6 +1693,7 @@  discard block
 block discarded – undo
1621 1693
 						<input type="checkbox" name="delrule[', $rule['id'], ']">
1622 1694
 					</td>
1623 1695
 				</tr>';
1696
+	}
1624 1697
 
1625 1698
 	echo '
1626 1699
 			</tbody>
@@ -1628,14 +1701,16 @@  discard block
 block discarded – undo
1628 1701
 		<div class="righttext">
1629 1702
 			<a class="button" href="', $scripturl, '?action=pm;sa=manrules;add;rid=0">', $txt['pm_add_rule'], '</a>';
1630 1703
 
1631
-	if (!empty($context['rules']))
1632
-		echo '
1704
+	if (!empty($context['rules'])) {
1705
+			echo '
1633 1706
 			[<a href="', $scripturl, '?action=pm;sa=manrules;apply;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['pm_js_apply_rules_confirm'], '\');">', $txt['pm_apply_rules'], '</a>]';
1707
+	}
1634 1708
 
1635
-	if (!empty($context['rules']))
1636
-		echo '
1709
+	if (!empty($context['rules'])) {
1710
+			echo '
1637 1711
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1638 1712
 			<input type="submit" name="delselected" value="', $txt['pm_delete_selected_rule'], '" data-confirm="', $txt['pm_js_delete_rule_confirm'] ,'" class="button smalltext you_sure">';
1713
+	}
1639 1714
 
1640 1715
 	echo '
1641 1716
 		</div>
@@ -1657,14 +1732,16 @@  discard block
 block discarded – undo
1657 1732
 		var groups = new Array()
1658 1733
 		var labels = new Array()';
1659 1734
 
1660
-	foreach ($context['groups'] as $id => $title)
1661
-		echo '
1735
+	foreach ($context['groups'] as $id => $title) {
1736
+			echo '
1662 1737
 		groups[', $id, '] = "', addslashes($title), '";';
1738
+	}
1663 1739
 
1664
-	foreach ($context['labels'] as $label)
1665
-		if ($label['id'] != -1)
1740
+	foreach ($context['labels'] as $label) {
1741
+			if ($label['id'] != -1)
1666 1742
 			echo '
1667 1743
 		labels[', ($label['id']), '] = "', addslashes($label['name']), '";';
1744
+	}
1668 1745
 
1669 1746
 	echo '
1670 1747
 		function addCriteriaOption()
@@ -1679,8 +1756,9 @@  discard block
 block discarded – undo
1679 1756
 
1680 1757
 			setOuterHTML(document.getElementById("criteriaAddHere"), \'<br><select name="ruletype[\' + criteriaNum + \']" id="ruletype\' + criteriaNum + \'" onchange="updateRuleDef(\' + criteriaNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_criteria_pick']), ':<\' + \'/option><option value="mid">', addslashes($txt['pm_rule_mid']), '<\' + \'/option><option value="gid">', addslashes($txt['pm_rule_gid']), '<\' + \'/option><option value="sub">', addslashes($txt['pm_rule_sub']), '<\' + \'/option><option value="msg">', addslashes($txt['pm_rule_msg']), '<\' + \'/option><option value="bud">', addslashes($txt['pm_rule_bud']), '<\' + \'/option><\' + \'/select>&nbsp;<span id="defdiv\' + criteriaNum + \'" style="display: none;"><input type="text" name="ruledef[\' + criteriaNum + \']" id="ruledef\' + criteriaNum + \'" onkeyup="rebuildRuleDesc();" value=""><\' + \'/span><span id="defseldiv\' + criteriaNum + \'" style="display: none;"><select name="ruledefgroup[\' + criteriaNum + \']" id="ruledefgroup\' + criteriaNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_group']), '<\' + \'/option>';
1681 1758
 
1682
-	foreach ($context['groups'] as $id => $group)
1683
-		echo '<option value="', $id, '">', strtr($group, array("'" => "\'")), '<\' + \'/option>';
1759
+	foreach ($context['groups'] as $id => $group) {
1760
+			echo '<option value="', $id, '">', strtr($group, array("'" => "\'")), '<\' + \'/option>';
1761
+	}
1684 1762
 
1685 1763
 	echo '<\' + \'/select><\' + \'/span><span id="criteriaAddHere"><\' + \'/span>\');
1686 1764
 			}
@@ -1697,9 +1775,10 @@  discard block
 block discarded – undo
1697 1775
 
1698 1776
 				setOuterHTML(document.getElementById("actionAddHere"), \'<br><select name="acttype[\' + actionNum + \']" id="acttype\' + actionNum + \'" onchange="updateActionDef(\' + actionNum + \'); rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_action']), ':<\' + \'/option><option value="lab">', addslashes($txt['pm_rule_label']), '<\' + \'/option><option value="del">', addslashes($txt['pm_rule_delete']), '<\' + \'/option><\' + \'/select>&nbsp;<span id="labdiv\' + actionNum + \'" style="display: none;"><select name="labdef[\' + actionNum + \']" id="labdef\' + actionNum + \'" onchange="rebuildRuleDesc();"><option value="">', addslashes($txt['pm_rule_sel_label']), '<\' + \'/option>';
1699 1777
 
1700
-	foreach ($context['labels'] as $label)
1701
-		if ($label['id'] != -1)
1778
+	foreach ($context['labels'] as $label) {
1779
+			if ($label['id'] != -1)
1702 1780
 			echo '<option value="', ($label['id']), '">', addslashes($label['name']), '<\' + \'/option>';
1781
+	}
1703 1782
 
1704 1783
 	echo '<\' + \'/select><\' + \'/span><span id="actionAddHere"><\' + \'/span>\');
1705 1784
 			}
@@ -1813,19 +1892,20 @@  discard block
 block discarded – undo
1813 1892
 	$isFirst = true;
1814 1893
 	foreach ($context['rule']['criteria'] as $k => $criteria)
1815 1894
 	{
1816
-		if (!$isFirst && $criteria['t'] == '')
1817
-			echo '<div id="removeonjs1">';
1818
-
1819
-		elseif (!$isFirst)
1820
-			echo '<br>';
1895
+		if (!$isFirst && $criteria['t'] == '') {
1896
+					echo '<div id="removeonjs1">';
1897
+		} elseif (!$isFirst) {
1898
+					echo '<br>';
1899
+		}
1821 1900
 
1822 1901
 		echo '
1823 1902
 				<select name="ruletype[', $k, ']" id="ruletype', $k, '" onchange="updateRuleDef(', $k, '); rebuildRuleDesc();">
1824 1903
 					<option value="">', $txt['pm_rule_criteria_pick'], ':</option>';
1825 1904
 
1826
-		foreach (array('mid', 'gid', 'sub', 'msg', 'bud') as $cr)
1827
-			echo '
1905
+		foreach (array('mid', 'gid', 'sub', 'msg', 'bud') as $cr) {
1906
+					echo '
1828 1907
 					<option value="', $cr, '"', $criteria['t'] == $cr ? ' selected' : '', '>', $txt['pm_rule_' . $cr], '</option>';
1908
+		}
1829 1909
 
1830 1910
 		echo '
1831 1911
 				</select>
@@ -1836,19 +1916,20 @@  discard block
 block discarded – undo
1836 1916
 					<select name="ruledefgroup[', $k, ']" id="ruledefgroup', $k, '" onchange="rebuildRuleDesc();">
1837 1917
 						<option value="">', $txt['pm_rule_sel_group'], '</option>';
1838 1918
 
1839
-		foreach ($context['groups'] as $id => $group)
1840
-			echo '
1919
+		foreach ($context['groups'] as $id => $group) {
1920
+					echo '
1841 1921
 						<option value="', $id, '"', $criteria['t'] == 'gid' && $criteria['v'] == $id ? ' selected' : '', '>', $group, '</option>';
1922
+		}
1842 1923
 		echo '
1843 1924
 					</select>
1844 1925
 				</span>';
1845 1926
 
1846 1927
 		// If this is the dummy we add a means to hide for non js users.
1847
-		if ($isFirst)
1848
-			$isFirst = false;
1849
-
1850
-		elseif ($criteria['t'] == '')
1851
-			echo '</div><!-- .removeonjs1 -->';
1928
+		if ($isFirst) {
1929
+					$isFirst = false;
1930
+		} elseif ($criteria['t'] == '') {
1931
+					echo '</div><!-- .removeonjs1 -->';
1932
+		}
1852 1933
 	}
1853 1934
 
1854 1935
 	echo '
@@ -1871,10 +1952,11 @@  discard block
 block discarded – undo
1871 1952
 	$isFirst = true;
1872 1953
 	foreach ($context['rule']['actions'] as $k => $action)
1873 1954
 	{
1874
-		if (!$isFirst && $action['t'] == '')
1875
-			echo '<div id="removeonjs2">';
1876
-		elseif (!$isFirst)
1877
-			echo '<br>';
1955
+		if (!$isFirst && $action['t'] == '') {
1956
+					echo '<div id="removeonjs2">';
1957
+		} elseif (!$isFirst) {
1958
+					echo '<br>';
1959
+		}
1878 1960
 
1879 1961
 		echo '
1880 1962
 				<select name="acttype[', $k, ']" id="acttype', $k, '" onchange="updateActionDef(', $k, '); rebuildRuleDesc();">
@@ -1886,20 +1968,21 @@  discard block
 block discarded – undo
1886 1968
 					<select name="labdef[', $k, ']" id="labdef', $k, '" onchange="rebuildRuleDesc();">
1887 1969
 						<option value="">', $txt['pm_rule_sel_label'], '</option>';
1888 1970
 
1889
-		foreach ($context['labels'] as $label)
1890
-			if ($label['id'] != -1)
1971
+		foreach ($context['labels'] as $label) {
1972
+					if ($label['id'] != -1)
1891 1973
 				echo '
1892 1974
 						<option value="', ($label['id']), '"', $action['t'] == 'lab' && $action['v'] == $label['id'] ? ' selected' : '', '>', $label['name'], '</option>';
1975
+		}
1893 1976
 
1894 1977
 		echo '
1895 1978
 					</select>
1896 1979
 				</span>';
1897 1980
 
1898
-		if ($isFirst)
1899
-			$isFirst = false;
1900
-
1901
-		elseif ($action['t'] == '')
1902
-			echo '</div><!-- .removeonjs2 -->';
1981
+		if ($isFirst) {
1982
+					$isFirst = false;
1983
+		} elseif ($action['t'] == '') {
1984
+					echo '</div><!-- .removeonjs2 -->';
1985
+		}
1903 1986
 	}
1904 1987
 
1905 1988
 	echo '
@@ -1923,22 +2006,25 @@  discard block
 block discarded – undo
1923 2006
 		echo '
1924 2007
 	<script>';
1925 2008
 
1926
-	foreach ($context['rule']['criteria'] as $k => $c)
1927
-		echo '
2009
+	foreach ($context['rule']['criteria'] as $k => $c) {
2010
+			echo '
1928 2011
 			updateRuleDef(', $k, ');';
2012
+	}
1929 2013
 
1930
-	foreach ($context['rule']['actions'] as $k => $c)
1931
-		echo '
2014
+	foreach ($context['rule']['actions'] as $k => $c) {
2015
+			echo '
1932 2016
 			updateActionDef(', $k, ');';
2017
+	}
1933 2018
 
1934 2019
 	echo '
1935 2020
 			rebuildRuleDesc();';
1936 2021
 
1937 2022
 	// If this isn't a new rule and we have JS enabled remove the JS compatibility stuff.
1938
-	if ($context['rid'])
1939
-		echo '
2023
+	if ($context['rid']) {
2024
+			echo '
1940 2025
 			document.getElementById("removeonjs1").style.display = "none";
1941 2026
 			document.getElementById("removeonjs2").style.display = "none";';
2027
+	}
1942 2028
 
1943 2029
 	echo '
1944 2030
 			document.getElementById("addonjs1").style.display = "";
@@ -1966,12 +2052,12 @@  discard block
 block discarded – undo
1966 2052
 		</div>';
1967 2053
 
1968 2054
 	// No drafts? Just show an informative message.
1969
-	if (empty($context['drafts']))
1970
-		echo '
2055
+	if (empty($context['drafts'])) {
2056
+			echo '
1971 2057
 		<div class="windowbg centertext">
1972 2058
 			', $txt['draft_none'], '
1973 2059
 		</div>';
1974
-	else
2060
+	} else
1975 2061
 	{
1976 2062
 		// For every draft to be displayed, give it its own div, and show the important details of the draft.
1977 2063
 		foreach ($context['drafts'] as $draft)
Please login to merge, or discard this patch.
Sources/PersonalMessage.php 1 patch
Braces   +673 added lines, -510 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'))
19
-	die('No direct access...');
18
+if (!defined('SMF')) {
19
+	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * This helps organize things...
@@ -37,13 +38,14 @@  discard block
 block discarded – undo
37 38
 
38 39
 	loadLanguage('PersonalMessage+Drafts');
39 40
 
40
-	if (!isset($_REQUEST['xml']))
41
-		loadTemplate('PersonalMessage');
41
+	if (!isset($_REQUEST['xml'])) {
42
+			loadTemplate('PersonalMessage');
43
+	}
42 44
 
43 45
 	// Load up the members maximum message capacity.
44
-	if ($user_info['is_admin'])
45
-		$context['message_limit'] = 0;
46
-	elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
46
+	if ($user_info['is_admin']) {
47
+			$context['message_limit'] = 0;
48
+	} elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null)
47 49
 	{
48 50
 		// @todo Why do we do this?  It seems like if they have any limit we should use it.
49 51
 		$request = $smcFunc['db_query']('', '
@@ -78,8 +80,9 @@  discard block
 block discarded – undo
78 80
 	}
79 81
 
80 82
 	// a previous message was sent successfully? show a small indication.
81
-	if (isset($_GET['done']) && ($_GET['done'] == 'sent'))
82
-		$context['pm_sent'] = true;
83
+	if (isset($_GET['done']) && ($_GET['done'] == 'sent')) {
84
+			$context['pm_sent'] = true;
85
+	}
83 86
 
84 87
 	$context['labels'] = array();
85 88
 
@@ -210,11 +213,11 @@  discard block
 block discarded – undo
210 213
 	{
211 214
 		$_REQUEST['sa'] = '';
212 215
 		MessageFolder();
213
-	}
214
-	else
216
+	} else
215 217
 	{
216
-		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup')
217
-			messageIndexBar($_REQUEST['sa']);
218
+		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup') {
219
+					messageIndexBar($_REQUEST['sa']);
220
+		}
218 221
 
219 222
 		call_helper($subActions[$_REQUEST['sa']]);
220 223
 	}
@@ -291,16 +294,17 @@  discard block
 block discarded – undo
291 294
 	);
292 295
 
293 296
 	// Handle labels.
294
-	if (empty($context['currently_using_labels']))
295
-		unset($pm_areas['labels']);
296
-	else
297
+	if (empty($context['currently_using_labels'])) {
298
+			unset($pm_areas['labels']);
299
+	} else
297 300
 	{
298 301
 		// Note we send labels by id as it will have less problems in the querystring.
299 302
 		$unread_in_labels = 0;
300 303
 		foreach ($context['labels'] as $label)
301 304
 		{
302
-			if ($label['id'] == -1)
303
-				continue;
305
+			if ($label['id'] == -1) {
306
+							continue;
307
+			}
304 308
 
305 309
 			// Count the amount of unread items in labels.
306 310
 			$unread_in_labels += $label['unread_messages'];
@@ -314,8 +318,9 @@  discard block
 block discarded – undo
314 318
 			);
315 319
 		}
316 320
 
317
-		if (!empty($unread_in_labels))
318
-			$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
321
+		if (!empty($unread_in_labels)) {
322
+					$pm_areas['labels']['title'] .= ' <span class="amt">' . $unread_in_labels . '</span>';
323
+		}
319 324
 	}
320 325
 
321 326
 	$pm_areas['folders']['areas']['inbox']['unread_messages'] = &$context['labels'][-1]['unread_messages'];
@@ -353,8 +358,9 @@  discard block
 block discarded – undo
353 358
 	unset($pm_areas);
354 359
 
355 360
 	// No menu means no access.
356
-	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession()))
357
-		fatal_lang_error('no_access', false);
361
+	if (!$pm_include_data && (!$user_info['is_guest'] || validateSession())) {
362
+			fatal_lang_error('no_access', false);
363
+	}
358 364
 
359 365
 	// Make a note of the Unique ID for this menu.
360 366
 	$context['pm_menu_id'] = $context['max_menu_id'];
@@ -365,9 +371,10 @@  discard block
 block discarded – undo
365 371
 	$context['menu_item_selected'] = $current_area;
366 372
 
367 373
 	// Set the template for this area and add the profile layer.
368
-	if (!isset($_REQUEST['xml']))
369
-		$context['template_layers'][] = 'pm';
370
-}
374
+	if (!isset($_REQUEST['xml'])) {
375
+			$context['template_layers'][] = 'pm';
376
+	}
377
+	}
371 378
 
372 379
 /**
373 380
  * The popup for when we ask for the popup from the user.
@@ -399,8 +406,9 @@  discard block
 block discarded – undo
399 406
 		)
400 407
 	);
401 408
 	$pms = array();
402
-	while ($row = $smcFunc['db_fetch_row']($request))
403
-		$pms[] = $row[0];
409
+	while ($row = $smcFunc['db_fetch_row']($request)) {
410
+			$pms[] = $row[0];
411
+	}
404 412
 	$smcFunc['db_free_result']($request);
405 413
 
406 414
 	if (!empty($pms))
@@ -428,8 +436,9 @@  discard block
 block discarded – undo
428 436
 		);
429 437
 		while ($row = $smcFunc['db_fetch_assoc']($request))
430 438
 		{
431
-			if (!empty($row['id_member_from']))
432
-				$senders[] = $row['id_member_from'];
439
+			if (!empty($row['id_member_from'])) {
440
+							$senders[] = $row['id_member_from'];
441
+			}
433 442
 
434 443
 			$row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head'];
435 444
 			$row['time'] = timeformat($row['timestamp']);
@@ -439,13 +448,15 @@  discard block
 block discarded – undo
439 448
 		$smcFunc['db_free_result']($request);
440 449
 
441 450
 		$senders = loadMemberData($senders);
442
-		foreach ($senders as $member)
443
-			loadMemberContext($member);
451
+		foreach ($senders as $member) {
452
+					loadMemberContext($member);
453
+		}
444 454
 
445 455
 		// Having loaded everyone, attach them to the PMs.
446
-		foreach ($context['unread_pms'] as $id_pm => $details)
447
-			if (!empty($memberContext[$details['id_member_from']]))
448
-				$context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']];
456
+		foreach ($context['unread_pms'] as $id_pm => $details) {
457
+					if (!empty($memberContext[$details['id_member_from']]))
458
+				$context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']];
459
+		}
449 460
 	}
450 461
 }
451 462
 
@@ -465,12 +476,13 @@  discard block
 block discarded – undo
465 476
 	}
466 477
 
467 478
 	// Make sure the starting location is valid.
468
-	if (isset($_GET['start']) && $_GET['start'] != 'new')
469
-		$_GET['start'] = (int) $_GET['start'];
470
-	elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first']))
471
-		$_GET['start'] = 0;
472
-	else
473
-		$_GET['start'] = 'new';
479
+	if (isset($_GET['start']) && $_GET['start'] != 'new') {
480
+			$_GET['start'] = (int) $_GET['start'];
481
+	} elseif (!isset($_GET['start']) && !empty($options['view_newest_pm_first'])) {
482
+			$_GET['start'] = 0;
483
+	} else {
484
+			$_GET['start'] = 'new';
485
+	}
474 486
 
475 487
 	// Set up some basic theme stuff.
476 488
 	$context['from_or_to'] = $context['folder'] != 'sent' ? 'from' : 'to';
@@ -484,9 +496,10 @@  discard block
 block discarded – undo
484 496
 		list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
485 497
 		$sig_limits = explode(',', $sig_limits);
486 498
 
487
-		if (!empty($sig_limits[5]) || !empty($sig_limits[6]))
488
-			addInlineCss('
489
-	.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}');
499
+		if (!empty($sig_limits[5]) || !empty($sig_limits[6])) {
500
+					addInlineCss('
501
+	.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}');
502
+		}
490 503
 	}
491 504
 
492 505
 	$labelJoin = '';
@@ -498,8 +511,7 @@  discard block
 block discarded – undo
498 511
 	{
499 512
 		$labelQuery = '
500 513
 			AND pmr.in_inbox = 1';
501
-	}
502
-	elseif ($context['folder'] != 'sent')
514
+	} elseif ($context['folder'] != 'sent')
503 515
 	{
504 516
 		$labelJoin = '
505 517
 			INNER JOIN {db_prefix}pm_labeled_messages AS pl ON (pl.id_pm = pmr.id_pm)';
@@ -541,22 +553,24 @@  discard block
 block discarded – undo
541 553
 	$txt['delete_all'] = str_replace('PMBOX', $pmbox, $txt['delete_all']);
542 554
 
543 555
 	// Now, build the link tree!
544
-	if ($context['current_label_id'] == -1)
545
-		$context['linktree'][] = array(
556
+	if ($context['current_label_id'] == -1) {
557
+			$context['linktree'][] = array(
546 558
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'],
547 559
 			'name' => $pmbox
548
-		);
560
+		);
561
+	}
549 562
 
550 563
 	// Build it further for a label.
551
-	if ($context['current_label_id'] != -1)
552
-		$context['linktree'][] = array(
564
+	if ($context['current_label_id'] != -1) {
565
+			$context['linktree'][] = array(
553 566
 			'url' => $scripturl . '?action=pm;f=' . $context['folder'] . ';l=' . $context['current_label_id'],
554 567
 			'name' => $txt['pm_current_label'] . ': ' . $context['current_label']
555
-		);
568
+		);
569
+	}
556 570
 
557 571
 	// Figure out how many messages there are.
558
-	if ($context['folder'] == 'sent')
559
-		$request = $smcFunc['db_query']('', '
572
+	if ($context['folder'] == 'sent') {
573
+			$request = $smcFunc['db_query']('', '
560 574
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
561 575
 			FROM {db_prefix}personal_messages AS pm
562 576
 			WHERE pm.id_member_from = {int:current_member}
@@ -565,9 +579,9 @@  discard block
 block discarded – undo
565 579
 				'current_member' => $user_info['id'],
566 580
 				'not_deleted' => 0,
567 581
 			)
568
-		);
569
-	else
570
-		$request = $smcFunc['db_query']('', '
582
+		);
583
+	} else {
584
+			$request = $smcFunc['db_query']('', '
571 585
 			SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
572 586
 			FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
573 587
 				INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -577,7 +591,8 @@  discard block
 block discarded – undo
577 591
 				'current_member' => $user_info['id'],
578 592
 				'not_deleted' => 0,
579 593
 			)
580
-		);
594
+		);
595
+	}
581 596
 	list ($max_messages) = $smcFunc['db_fetch_row']($request);
582 597
 	$smcFunc['db_free_result']($request);
583 598
 
@@ -586,10 +601,11 @@  discard block
 block discarded – undo
586 601
 	$maxPerPage = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
587 602
 
588 603
 	// Start on the last page.
589
-	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages)
590
-		$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
591
-	elseif ($_GET['start'] < 0)
592
-		$_GET['start'] = 0;
604
+	if (!is_numeric($_GET['start']) || $_GET['start'] >= $max_messages) {
605
+			$_GET['start'] = ($max_messages - 1) - (($max_messages - 1) % $maxPerPage);
606
+	} elseif ($_GET['start'] < 0) {
607
+			$_GET['start'] = 0;
608
+	}
593 609
 
594 610
 	// ... but wait - what if we want to start from a specific message?
595 611
 	if (isset($_GET['pmid']))
@@ -597,19 +613,21 @@  discard block
 block discarded – undo
597 613
 		$pmID = (int) $_GET['pmid'];
598 614
 
599 615
 		// Make sure you have access to this PM.
600
-		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
601
-			fatal_lang_error('no_access', false);
616
+		if (!isAccessiblePM($pmID, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
617
+					fatal_lang_error('no_access', false);
618
+		}
602 619
 
603 620
 		$context['current_pm'] = $pmID;
604 621
 
605 622
 		// With only one page of PM's we're gonna want page 1.
606
-		if ($max_messages <= $maxPerPage)
607
-			$_GET['start'] = 0;
623
+		if ($max_messages <= $maxPerPage) {
624
+					$_GET['start'] = 0;
625
+		}
608 626
 		// If we pass kstart we assume we're in the right place.
609 627
 		elseif (!isset($_GET['kstart']))
610 628
 		{
611
-			if ($context['folder'] == 'sent')
612
-				$request = $smcFunc['db_query']('', '
629
+			if ($context['folder'] == 'sent') {
630
+							$request = $smcFunc['db_query']('', '
613 631
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
614 632
 					FROM {db_prefix}personal_messages
615 633
 					WHERE id_member_from = {int:current_member}
@@ -620,9 +638,9 @@  discard block
 block discarded – undo
620 638
 						'not_deleted' => 0,
621 639
 						'id_pm' => $pmID,
622 640
 					)
623
-				);
624
-			else
625
-				$request = $smcFunc['db_query']('', '
641
+				);
642
+			} else {
643
+							$request = $smcFunc['db_query']('', '
626 644
 					SELECT COUNT(' . ($context['display_mode'] == 2 ? 'DISTINCT pm.id_pm_head' : '*') . ')
627 645
 					FROM {db_prefix}pm_recipients AS pmr' . ($context['display_mode'] == 2 ? '
628 646
 						INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)' : '') . $labelJoin . '
@@ -634,7 +652,8 @@  discard block
 block discarded – undo
634 652
 						'not_deleted' => 0,
635 653
 						'id_pm' => $pmID,
636 654
 					)
637
-				);
655
+				);
656
+			}
638 657
 
639 658
 			list ($_GET['start']) = $smcFunc['db_fetch_row']($request);
640 659
 			$smcFunc['db_free_result']($request);
@@ -649,8 +668,9 @@  discard block
 block discarded – undo
649 668
 	{
650 669
 		$pmsg = (int) $_GET['pmsg'];
651 670
 
652
-		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox'))
653
-			fatal_lang_error('no_access', false);
671
+		if (!isAccessiblePM($pmsg, $context['folder'] == 'sent' ? 'outbox' : 'inbox')) {
672
+					fatal_lang_error('no_access', false);
673
+		}
654 674
 	}
655 675
 
656 676
 	// Set up the page index.
@@ -744,8 +764,9 @@  discard block
 block discarded – undo
744 764
 	{
745 765
 		if (!isset($recipients[$row['id_pm']]))
746 766
 		{
747
-			if (isset($row['id_member_from']))
748
-				$posters[$row['id_pm']] = $row['id_member_from'];
767
+			if (isset($row['id_member_from'])) {
768
+							$posters[$row['id_pm']] = $row['id_member_from'];
769
+			}
749 770
 			$pms[$row['id_pm']] = $row['id_pm'];
750 771
 			$recipients[$row['id_pm']] = array(
751 772
 				'to' => array(),
@@ -754,29 +775,33 @@  discard block
 block discarded – undo
754 775
 		}
755 776
 
756 777
 		// Keep track of the last message so we know what the head is without another query!
757
-		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm']))
758
-			$lastData = array(
778
+		if ((empty($pmID) && (empty($options['view_newest_pm_first']) || !isset($lastData))) || empty($lastData) || (!empty($pmID) && $pmID == $row['id_pm'])) {
779
+					$lastData = array(
759 780
 				'id' => $row['id_pm'],
760 781
 				'head' => $row['id_pm_head'],
761
-			);
782
+			);
783
+		}
762 784
 	}
763 785
 	$smcFunc['db_free_result']($request);
764 786
 
765 787
 	// Make sure that we have been given a correct head pm id!
766
-	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id'])
767
-		fatal_lang_error('no_access', false);
788
+	if ($context['display_mode'] == 2 && !empty($pmID) && $pmID != $lastData['id']) {
789
+			fatal_lang_error('no_access', false);
790
+	}
768 791
 
769 792
 	if (!empty($pms))
770 793
 	{
771 794
 		// Select the correct current message.
772
-		if (empty($pmID))
773
-			$context['current_pm'] = $lastData['id'];
795
+		if (empty($pmID)) {
796
+					$context['current_pm'] = $lastData['id'];
797
+		}
774 798
 
775 799
 		// This is a list of the pm's that are used for "full" display.
776
-		if ($context['display_mode'] == 0)
777
-			$display_pms = $pms;
778
-		else
779
-			$display_pms = array($context['current_pm']);
800
+		if ($context['display_mode'] == 0) {
801
+					$display_pms = $pms;
802
+		} else {
803
+					$display_pms = array($context['current_pm']);
804
+		}
780 805
 
781 806
 		// At this point we know the main id_pm's. But - if we are looking at conversations we need the others!
782 807
 		if ($context['display_mode'] == 2)
@@ -798,16 +823,18 @@  discard block
 block discarded – undo
798 823
 			while ($row = $smcFunc['db_fetch_assoc']($request))
799 824
 			{
800 825
 				// This is, frankly, a joke. We will put in a workaround for people sending to themselves - yawn!
801
-				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1)
802
-					continue;
803
-				elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1)
804
-					continue;
805
-
806
-				if (!isset($recipients[$row['id_pm']]))
807
-					$recipients[$row['id_pm']] = array(
826
+				if ($context['folder'] == 'sent' && $row['id_member_from'] == $user_info['id'] && $row['deleted_by_sender'] == 1) {
827
+									continue;
828
+				} elseif ($row['id_member'] == $user_info['id'] & $row['deleted'] == 1) {
829
+									continue;
830
+				}
831
+
832
+				if (!isset($recipients[$row['id_pm']])) {
833
+									$recipients[$row['id_pm']] = array(
808 834
 						'to' => array(),
809 835
 						'bcc' => array()
810
-					);
836
+					);
837
+				}
811 838
 				$display_pms[] = $row['id_pm'];
812 839
 				$posters[$row['id_pm']] = $row['id_member_from'];
813 840
 			}
@@ -858,8 +885,9 @@  discard block
 block discarded – undo
858 885
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
859 886
 				{
860 887
 					$l_id = $row2['id_label'];
861
-					if (isset($context['labels'][$l_id]))
862
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
888
+					if (isset($context['labels'][$l_id])) {
889
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
890
+					}
863 891
 				}
864 892
 
865 893
 				$smcFunc['db_free_result']($request2);
@@ -876,9 +904,10 @@  discard block
 block discarded – undo
876 904
 		// Make sure we don't load unnecessary data.
877 905
 		if ($context['display_mode'] == 1)
878 906
 		{
879
-			foreach ($posters as $k => $v)
880
-				if (!in_array($k, $display_pms))
881
-					unset($posters[$k]);
907
+			foreach ($posters as $k => $v) {
908
+							if (!in_array($k, $display_pms))
909
+					unset($posters[$k]);
910
+			}
882 911
 		}
883 912
 
884 913
 		// Load any users....
@@ -889,8 +918,9 @@  discard block
 block discarded – undo
889 918
 		{
890 919
 			// Get the order right.
891 920
 			$orderBy = array();
892
-			foreach (array_reverse($pms) as $pm)
893
-				$orderBy[] = 'pm.id_pm = ' . $pm;
921
+			foreach (array_reverse($pms) as $pm) {
922
+							$orderBy[] = 'pm.id_pm = ' . $pm;
923
+			}
894 924
 
895 925
 			// Seperate query for these bits!
896 926
 			$subjects_request = $smcFunc['db_query']('', '
@@ -936,9 +966,9 @@  discard block
 block discarded – undo
936 966
 			// Allow mods to add additional buttons here
937 967
 			call_integration_hook('integrate_conversation_buttons');
938 968
 		}
939
-	}
940
-	else
941
-		$messages_request = false;
969
+	} else {
970
+			$messages_request = false;
971
+	}
942 972
 
943 973
 	$context['can_send_pm'] = allowedTo('pm_send');
944 974
 	$context['can_send_email'] = allowedTo('moderate_forum');
@@ -949,11 +979,13 @@  discard block
 block discarded – undo
949 979
 	if ($context['folder'] != 'sent' && !empty($context['labels'][(int) $context['current_label_id']]['unread_messages']))
950 980
 	{
951 981
 		// If the display mode is "old sk00l" do them all...
952
-		if ($context['display_mode'] == 0)
953
-			markMessages(null, $context['current_label_id']);
982
+		if ($context['display_mode'] == 0) {
983
+					markMessages(null, $context['current_label_id']);
984
+		}
954 985
 		// Otherwise do just the current one!
955
-		elseif (!empty($context['current_pm']))
956
-			markMessages($display_pms, $context['current_label_id']);
986
+		elseif (!empty($context['current_pm'])) {
987
+					markMessages($display_pms, $context['current_label_id']);
988
+		}
957 989
 	}
958 990
 }
959 991
 
@@ -971,8 +1003,9 @@  discard block
 block discarded – undo
971 1003
 
972 1004
 	// Count the current message number....
973 1005
 	static $counter = null;
974
-	if ($counter === null || $reset)
975
-		$counter = $context['start'];
1006
+	if ($counter === null || $reset) {
1007
+			$counter = $context['start'];
1008
+	}
976 1009
 
977 1010
 	static $temp_pm_selected = null;
978 1011
 	if ($temp_pm_selected === null)
@@ -1017,19 +1050,22 @@  discard block
 block discarded – undo
1017 1050
 	}
1018 1051
 
1019 1052
 	// Bail if it's false, ie. no messages.
1020
-	if ($messages_request == false)
1021
-		return false;
1053
+	if ($messages_request == false) {
1054
+			return false;
1055
+	}
1022 1056
 
1023 1057
 	// Reset the data?
1024
-	if ($reset == true)
1025
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1058
+	if ($reset == true) {
1059
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1060
+	}
1026 1061
 
1027 1062
 	// Get the next one... bail if anything goes wrong.
1028 1063
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1029 1064
 	if (!$message)
1030 1065
 	{
1031
-		if ($type != 'subject')
1032
-			$smcFunc['db_free_result']($messages_request);
1066
+		if ($type != 'subject') {
1067
+					$smcFunc['db_free_result']($messages_request);
1068
+		}
1033 1069
 
1034 1070
 		return false;
1035 1071
 	}
@@ -1049,8 +1085,7 @@  discard block
 block discarded – undo
1049 1085
 		$memberContext[$message['id_member_from']]['email'] = '';
1050 1086
 		$memberContext[$message['id_member_from']]['show_email'] = false;
1051 1087
 		$memberContext[$message['id_member_from']]['is_guest'] = true;
1052
-	}
1053
-	else
1088
+	} else
1054 1089
 	{
1055 1090
 		$memberContext[$message['id_member_from']]['can_view_profile'] = allowedTo('profile_view') || ($message['id_member_from'] == $user_info['id'] && !$user_info['is_guest']);
1056 1091
 		$memberContext[$message['id_member_from']]['can_see_warning'] = !isset($context['disabled_fields']['warning_status']) && $memberContext[$message['id_member_from']]['warning_status'] && ($context['user']['can_mod'] || (!empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $message['id_member_from'] == $user_info['id'])));
@@ -1091,9 +1126,10 @@  discard block
 block discarded – undo
1091 1126
 	$counter++;
1092 1127
 
1093 1128
 	// Any custom profile fields?
1094
-	if (!empty($memberContext[$message['id_member_from']]['custom_fields']))
1095
-		foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1096
-			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1129
+	if (!empty($memberContext[$message['id_member_from']]['custom_fields'])) {
1130
+			foreach ($memberContext[$message['id_member_from']]['custom_fields'] as $custom)
1131
+			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1132
+	}
1097 1133
 
1098 1134
 	call_integration_hook('integrate_prepare_pm_context', array(&$output, &$message, $counter));
1099 1135
 
@@ -1117,22 +1153,28 @@  discard block
 block discarded – undo
1117 1153
 			$context['search_params'][$k] = $v;
1118 1154
 		}
1119 1155
 	}
1120
-	if (isset($_REQUEST['search']))
1121
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1156
+	if (isset($_REQUEST['search'])) {
1157
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
1158
+	}
1122 1159
 
1123
-	if (isset($context['search_params']['search']))
1124
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1125
-	if (isset($context['search_params']['userspec']))
1126
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1160
+	if (isset($context['search_params']['search'])) {
1161
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1162
+	}
1163
+	if (isset($context['search_params']['userspec'])) {
1164
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1165
+	}
1127 1166
 
1128
-	if (!empty($context['search_params']['searchtype']))
1129
-		$context['search_params']['searchtype'] = 2;
1167
+	if (!empty($context['search_params']['searchtype'])) {
1168
+			$context['search_params']['searchtype'] = 2;
1169
+	}
1130 1170
 
1131
-	if (!empty($context['search_params']['minage']))
1132
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1171
+	if (!empty($context['search_params']['minage'])) {
1172
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
1173
+	}
1133 1174
 
1134
-	if (!empty($context['search_params']['maxage']))
1135
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1175
+	if (!empty($context['search_params']['maxage'])) {
1176
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
1177
+	}
1136 1178
 
1137 1179
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
1138 1180
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
@@ -1159,8 +1201,9 @@  discard block
 block discarded – undo
1159 1201
 		$context['search_errors']['messages'] = array();
1160 1202
 		foreach ($context['search_errors'] as $search_error => $dummy)
1161 1203
 		{
1162
-			if ($search_error == 'messages')
1163
-				continue;
1204
+			if ($search_error == 'messages') {
1205
+							continue;
1206
+			}
1164 1207
 
1165 1208
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
1166 1209
 		}
@@ -1182,8 +1225,9 @@  discard block
 block discarded – undo
1182 1225
 	global $scripturl, $modSettings, $user_info, $context, $txt;
1183 1226
 	global $memberContext, $smcFunc;
1184 1227
 
1185
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
1186
-		fatal_lang_error('loadavg_search_disabled', false);
1228
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
1229
+			fatal_lang_error('loadavg_search_disabled', false);
1230
+	}
1187 1231
 
1188 1232
 	/**
1189 1233
 	 * @todo For the moment force the folder to the inbox.
@@ -1212,35 +1256,40 @@  discard block
 block discarded – undo
1212 1256
 	$context['start'] = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1213 1257
 
1214 1258
 	// Store whether simple search was used (needed if the user wants to do another query).
1215
-	if (!isset($search_params['advanced']))
1216
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1259
+	if (!isset($search_params['advanced'])) {
1260
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
1261
+	}
1217 1262
 
1218 1263
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
1219
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
1220
-		$search_params['searchtype'] = 2;
1264
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
1265
+			$search_params['searchtype'] = 2;
1266
+	}
1221 1267
 
1222 1268
 	// Minimum age of messages. Default to zero (don't set param in that case).
1223
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
1224
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1269
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
1270
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
1271
+	}
1225 1272
 
1226 1273
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
1227
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999))
1228
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1274
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] != 9999)) {
1275
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
1276
+	}
1229 1277
 
1230 1278
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
1231 1279
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
1232 1280
 
1233 1281
 	// Default the user name to a wildcard matching every user (*).
1234
-	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
1235
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1282
+	if (!empty($search_params['user_spec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
1283
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
1284
+	}
1236 1285
 
1237 1286
 	// This will be full of all kinds of parameters!
1238 1287
 	$searchq_parameters = array();
1239 1288
 
1240 1289
 	// If there's no specific user, then don't mention it in the main query.
1241
-	if (empty($search_params['userspec']))
1242
-		$userQuery = '';
1243
-	else
1290
+	if (empty($search_params['userspec'])) {
1291
+			$userQuery = '';
1292
+	} else
1244 1293
 	{
1245 1294
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
1246 1295
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -1252,8 +1301,9 @@  discard block
 block discarded – undo
1252 1301
 		{
1253 1302
 			$possible_users[$k] = trim($possible_users[$k]);
1254 1303
 
1255
-			if (strlen($possible_users[$k]) == 0)
1256
-				unset($possible_users[$k]);
1304
+			if (strlen($possible_users[$k]) == 0) {
1305
+							unset($possible_users[$k]);
1306
+			}
1257 1307
 		}
1258 1308
 
1259 1309
 		if (!empty($possible_users))
@@ -1265,8 +1315,9 @@  discard block
 block discarded – undo
1265 1315
 			{
1266 1316
 				$where_params['name_' . $k] = $v;
1267 1317
 				$where_clause[] = '{raw:real_name} LIKE {string:name_' . $k . '}';
1268
-				if (!isset($where_params['real_name']))
1269
-					$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1318
+				if (!isset($where_params['real_name'])) {
1319
+									$where_params['real_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(real_name)' : 'real_name';
1320
+				}
1270 1321
 			}
1271 1322
 
1272 1323
 			// Who matches those criteria?
@@ -1279,28 +1330,28 @@  discard block
 block discarded – undo
1279 1330
 			);
1280 1331
 
1281 1332
 			// Simply do nothing if there're too many members matching the criteria.
1282
-			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
1283
-				$userQuery = '';
1284
-			elseif ($smcFunc['db_num_rows']($request) == 0)
1333
+			if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
1334
+							$userQuery = '';
1335
+			} elseif ($smcFunc['db_num_rows']($request) == 0)
1285 1336
 			{
1286 1337
 				$userQuery = 'AND pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})';
1287 1338
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1288 1339
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1289
-			}
1290
-			else
1340
+			} else
1291 1341
 			{
1292 1342
 				$memberlist = array();
1293
-				while ($row = $smcFunc['db_fetch_assoc']($request))
1294
-					$memberlist[] = $row['id_member'];
1343
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
1344
+									$memberlist[] = $row['id_member'];
1345
+				}
1295 1346
 				$userQuery = 'AND (pm.id_member_from IN ({array_int:member_list}) OR (pm.id_member_from = 0 AND ({raw:pm_from_name} LIKE {raw:guest_user_name_implode})))';
1296 1347
 				$searchq_parameters['guest_user_name_implode'] = '\'' . implode('\' OR ' . ($smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name') . ' LIKE \'', $possible_users) . '\'';
1297 1348
 				$searchq_parameters['member_list'] = $memberlist;
1298 1349
 				$searchq_parameters['pm_from_name'] = $smcFunc['db_case_sensitive'] ? 'LOWER(pm.from_name)' : 'pm.from_name';
1299 1350
 			}
1300 1351
 			$smcFunc['db_free_result']($request);
1301
-		}
1302
-		else
1303
-			$userQuery = '';
1352
+		} else {
1353
+					$userQuery = '';
1354
+		}
1304 1355
 	}
1305 1356
 
1306 1357
 	// Setup the sorting variables...
@@ -1308,8 +1359,9 @@  discard block
 block discarded – undo
1308 1359
 	$sort_columns = array(
1309 1360
 		'pm.id_pm',
1310 1361
 	);
1311
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
1312
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1362
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
1363
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
1364
+	}
1313 1365
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'pm.id_pm';
1314 1366
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
1315 1367
 
@@ -1319,24 +1371,27 @@  discard block
 block discarded – undo
1319 1371
 	if ($context['folder'] == 'inbox' && !empty($search_params['advanced']) && $context['currently_using_labels'])
1320 1372
 	{
1321 1373
 		// Came here from pagination?  Put them back into $_REQUEST for sanitization.
1322
-		if (isset($search_params['labels']))
1323
-			$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1374
+		if (isset($search_params['labels'])) {
1375
+					$_REQUEST['searchlabel'] = explode(',', $search_params['labels']);
1376
+		}
1324 1377
 
1325 1378
 		// Assuming we have some labels - make them all integers.
1326 1379
 		if (!empty($_REQUEST['searchlabel']) && is_array($_REQUEST['searchlabel']))
1327 1380
 		{
1328
-			foreach ($_REQUEST['searchlabel'] as $key => $id)
1329
-				$_REQUEST['searchlabel'][$key] = (int) $id;
1330
-		}
1331
-		else
1332
-			$_REQUEST['searchlabel'] = array();
1381
+			foreach ($_REQUEST['searchlabel'] as $key => $id) {
1382
+							$_REQUEST['searchlabel'][$key] = (int) $id;
1383
+			}
1384
+		} else {
1385
+					$_REQUEST['searchlabel'] = array();
1386
+		}
1333 1387
 
1334 1388
 		// Now that everything is cleaned up a bit, make the labels a param.
1335 1389
 		$search_params['labels'] = implode(',', $_REQUEST['searchlabel']);
1336 1390
 
1337 1391
 		// No labels selected? That must be an error!
1338
-		if (empty($_REQUEST['searchlabel']))
1339
-			$context['search_errors']['no_labels_selected'] = true;
1392
+		if (empty($_REQUEST['searchlabel'])) {
1393
+					$context['search_errors']['no_labels_selected'] = true;
1394
+		}
1340 1395
 		// Otherwise prepare the query!
1341 1396
 		elseif (count($_REQUEST['searchlabel']) != count($context['labels']))
1342 1397
 		{
@@ -1359,8 +1414,7 @@  discard block
 block discarded – undo
1359 1414
 					// Not searching the inbox - PM must be labeled
1360 1415
 					$labelQuery = ' AND pml.id_label IN ({array_int:labels})';
1361 1416
 					$labelJoin = ' INNER JOIN {db_prefix}pm_labeled_messages AS pml ON (pml.id_pm = pmr.id_pm)';
1362
-				}
1363
-				else
1417
+				} else
1364 1418
 				{
1365 1419
 					// Searching the inbox - PM doesn't have to be labeled
1366 1420
 					$labelQuery = ' AND (' . substr($labelQuery, 5) . ' OR pml.id_label IN ({array_int:labels}))';
@@ -1375,8 +1429,9 @@  discard block
 block discarded – undo
1375 1429
 	// What are we actually searching for?
1376 1430
 	$search_params['search'] = !empty($search_params['search']) ? $search_params['search'] : (isset($_REQUEST['search']) ? $_REQUEST['search'] : '');
1377 1431
 	// If we ain't got nothing - we should error!
1378
-	if (!isset($search_params['search']) || $search_params['search'] == '')
1379
-		$context['search_errors']['invalid_search_string'] = true;
1432
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
1433
+			$context['search_errors']['invalid_search_string'] = true;
1434
+	}
1380 1435
 
1381 1436
 	// Extract phrase parts first (e.g. some words "this is a phrase" some more words.)
1382 1437
 	preg_match_all('~(?:^|\s)([-]?)"([^"]+)"(?:$|\s)~' . ($context['utf8'] ? 'u' : ''), $search_params['search'], $matches, PREG_PATTERN_ORDER);
@@ -1389,12 +1444,14 @@  discard block
 block discarded – undo
1389 1444
 	$excludedWords = array();
1390 1445
 
1391 1446
 	// .. first, we check for things like -"some words", but not "-some words".
1392
-	foreach ($matches[1] as $index => $word)
1393
-		if ($word == '-')
1447
+	foreach ($matches[1] as $index => $word) {
1448
+			if ($word == '-')
1394 1449
 		{
1395
-			$word = $smcFunc['strtolower'](trim($searchArray[$index]));
1396
-			if (strlen($word) > 0)
1397
-				$excludedWords[] = $word;
1450
+			$word = $smcFunc['strtolower'](trim($searchArray[$index]));
1451
+	}
1452
+			if (strlen($word) > 0) {
1453
+							$excludedWords[] = $word;
1454
+			}
1398 1455
 			unset($searchArray[$index]);
1399 1456
 		}
1400 1457
 
@@ -1404,8 +1461,9 @@  discard block
 block discarded – undo
1404 1461
 		if (strpos(trim($word), '-') === 0)
1405 1462
 		{
1406 1463
 			$word = substr($smcFunc['strtolower']($word), 1);
1407
-			if (strlen($word) > 0)
1408
-				$excludedWords[] = $word;
1464
+			if (strlen($word) > 0) {
1465
+							$excludedWords[] = $word;
1466
+			}
1409 1467
 			unset($tempSearch[$index]);
1410 1468
 		}
1411 1469
 	}
@@ -1416,9 +1474,9 @@  discard block
 block discarded – undo
1416 1474
 	foreach ($searchArray as $index => $value)
1417 1475
 	{
1418 1476
 		$searchArray[$index] = $smcFunc['strtolower'](trim($value));
1419
-		if ($searchArray[$index] == '')
1420
-			unset($searchArray[$index]);
1421
-		else
1477
+		if ($searchArray[$index] == '') {
1478
+					unset($searchArray[$index]);
1479
+		} else
1422 1480
 		{
1423 1481
 			// Sort out entities first.
1424 1482
 			$searchArray[$index] = $smcFunc['htmlspecialchars']($searchArray[$index]);
@@ -1428,27 +1486,32 @@  discard block
 block discarded – undo
1428 1486
 
1429 1487
 	// Create an array of replacements for highlighting.
1430 1488
 	$context['mark'] = array();
1431
-	foreach ($searchArray as $word)
1432
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1489
+	foreach ($searchArray as $word) {
1490
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
1491
+	}
1433 1492
 
1434 1493
 	// This contains *everything*
1435 1494
 	$searchWords = array_merge($searchArray, $excludedWords);
1436 1495
 
1437 1496
 	// Make sure at least one word is being searched for.
1438
-	if (empty($searchArray))
1439
-		$context['search_errors']['invalid_search_string'] = true;
1497
+	if (empty($searchArray)) {
1498
+			$context['search_errors']['invalid_search_string'] = true;
1499
+	}
1440 1500
 
1441 1501
 	// Sort out the search query so the user can edit it - if they want.
1442 1502
 	$context['search_params'] = $search_params;
1443
-	if (isset($context['search_params']['search']))
1444
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1445
-	if (isset($context['search_params']['userspec']))
1446
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1503
+	if (isset($context['search_params']['search'])) {
1504
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
1505
+	}
1506
+	if (isset($context['search_params']['userspec'])) {
1507
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
1508
+	}
1447 1509
 
1448 1510
 	// Now we have all the parameters, combine them together for pagination and the like...
1449 1511
 	$context['params'] = array();
1450
-	foreach ($search_params as $k => $v)
1451
-		$context['params'][] = $k . '|\'|' . $v;
1512
+	foreach ($search_params as $k => $v) {
1513
+			$context['params'][] = $k . '|\'|' . $v;
1514
+	}
1452 1515
 	$context['params'] = base64_encode(implode('|"|', $context['params']));
1453 1516
 
1454 1517
 	// Compile the subject query part.
@@ -1456,26 +1519,31 @@  discard block
 block discarded – undo
1456 1519
 
1457 1520
 	foreach ($searchWords as $index => $word)
1458 1521
 	{
1459
-		if ($word == '')
1460
-			continue;
1461
-
1462
-		if ($search_params['subject_only'])
1463
-			$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1464
-		else
1465
-			$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1522
+		if ($word == '') {
1523
+					continue;
1524
+		}
1525
+
1526
+		if ($search_params['subject_only']) {
1527
+					$andQueryParts[] = 'pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '}';
1528
+		} else {
1529
+					$andQueryParts[] = '(pm.subject' . (in_array($word, $excludedWords) ? ' NOT' : '') . ' LIKE {string:search_' . $index . '} ' . (in_array($word, $excludedWords) ? 'AND pm.body NOT' : 'OR pm.body') . ' LIKE {string:search_' . $index . '})';
1530
+		}
1466 1531
 		$searchq_parameters['search_' . $index] = '%' . strtr($word, array('_' => '\\_', '%' => '\\%')) . '%';
1467 1532
 	}
1468 1533
 
1469 1534
 	$searchQuery = ' 1=1';
1470
-	if (!empty($andQueryParts))
1471
-		$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1535
+	if (!empty($andQueryParts)) {
1536
+			$searchQuery = implode(!empty($search_params['searchtype']) && $search_params['searchtype'] == 2 ? ' OR ' : ' AND ', $andQueryParts);
1537
+	}
1472 1538
 
1473 1539
 	// Age limits?
1474 1540
 	$timeQuery = '';
1475
-	if (!empty($search_params['minage']))
1476
-		$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1477
-	if (!empty($search_params['maxage']))
1478
-		$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1541
+	if (!empty($search_params['minage'])) {
1542
+			$timeQuery .= ' AND pm.msgtime < ' . (time() - $search_params['minage'] * 86400);
1543
+	}
1544
+	if (!empty($search_params['maxage'])) {
1545
+			$timeQuery .= ' AND pm.msgtime > ' . (time() - $search_params['maxage'] * 86400);
1546
+	}
1479 1547
 
1480 1548
 	// If we have errors - return back to the first screen...
1481 1549
 	if (!empty($context['search_errors']))
@@ -1561,8 +1629,9 @@  discard block
 block discarded – undo
1561 1629
 			)
1562 1630
 		);
1563 1631
 		$real_pm_ids = array();
1564
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1565
-			$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1632
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1633
+					$real_pm_ids[$row['id_pm_head']] = $row['id_pm'];
1634
+		}
1566 1635
 		$smcFunc['db_free_result']($request);
1567 1636
 	}
1568 1637
 
@@ -1592,8 +1661,9 @@  discard block
 block discarded – undo
1592 1661
 		);
1593 1662
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1594 1663
 		{
1595
-			if ($context['folder'] == 'sent' || empty($row['bcc']))
1596
-				$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1664
+			if ($context['folder'] == 'sent' || empty($row['bcc'])) {
1665
+							$recipients[$row['id_pm']][empty($row['bcc']) ? 'to' : 'bcc'][] = empty($row['id_member_to']) ? $txt['guest_title'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . '">' . $row['to_name'] . '</a>';
1666
+			}
1597 1667
 
1598 1668
 			if ($row['id_member_to'] == $user_info['id'] && $context['folder'] != 'sent')
1599 1669
 			{
@@ -1614,12 +1684,14 @@  discard block
 block discarded – undo
1614 1684
 				while ($row2 = $smcFunc['db_fetch_assoc']($request2))
1615 1685
 				{
1616 1686
 					$l_id = $row2['id_label'];
1617
-					if (isset($context['labels'][$l_id]))
1618
-						$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1687
+					if (isset($context['labels'][$l_id])) {
1688
+											$context['message_labels'][$row['id_pm']][$l_id] = array('id' => $l_id, 'name' => $context['labels'][$l_id]['name']);
1689
+					}
1619 1690
 
1620 1691
 					// Here we find the first label on a message - for linking to posts in results
1621
-					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1)
1622
-						$context['first_label'][$row['id_pm']] = $l_id;
1692
+					if (!isset($context['first_label'][$row['id_pm']]) && $row['in_inbox'] != 1) {
1693
+											$context['first_label'][$row['id_pm']] = $l_id;
1694
+					}
1623 1695
 				}
1624 1696
 
1625 1697
 				$smcFunc['db_free_result']($request2);
@@ -1746,8 +1818,9 @@  discard block
 block discarded – undo
1746 1818
 		list ($postCount) = $smcFunc['db_fetch_row']($request);
1747 1819
 		$smcFunc['db_free_result']($request);
1748 1820
 
1749
-		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
1750
-			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1821
+		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour']) {
1822
+					fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
1823
+		}
1751 1824
 	}
1752 1825
 
1753 1826
 	// Quoting/Replying to a message?
@@ -1756,8 +1829,9 @@  discard block
 block discarded – undo
1756 1829
 		$pmsg = (int) $_REQUEST['pmsg'];
1757 1830
 
1758 1831
 		// Make sure this is yours.
1759
-		if (!isAccessiblePM($pmsg))
1760
-			fatal_lang_error('no_access', false);
1832
+		if (!isAccessiblePM($pmsg)) {
1833
+					fatal_lang_error('no_access', false);
1834
+		}
1761 1835
 
1762 1836
 		// Work out whether this is one you've received?
1763 1837
 		$request = $smcFunc['db_query']('', '
@@ -1794,8 +1868,9 @@  discard block
 block discarded – undo
1794 1868
 				'id_pm' => $pmsg,
1795 1869
 			)
1796 1870
 		);
1797
-		if ($smcFunc['db_num_rows']($request) == 0)
1798
-			fatal_lang_error('pm_not_yours', false);
1871
+		if ($smcFunc['db_num_rows']($request) == 0) {
1872
+					fatal_lang_error('pm_not_yours', false);
1873
+		}
1799 1874
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
1800 1875
 		$smcFunc['db_free_result']($request);
1801 1876
 
@@ -1806,9 +1881,9 @@  discard block
 block discarded – undo
1806 1881
 		// Add 'Re: ' to it....
1807 1882
 		if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
1808 1883
 		{
1809
-			if ($language === $user_info['language'])
1810
-				$context['response_prefix'] = $txt['response_prefix'];
1811
-			else
1884
+			if ($language === $user_info['language']) {
1885
+							$context['response_prefix'] = $txt['response_prefix'];
1886
+			} else
1812 1887
 			{
1813 1888
 				loadLanguage('index', $language, false);
1814 1889
 				$context['response_prefix'] = $txt['response_prefix'];
@@ -1817,22 +1892,25 @@  discard block
 block discarded – undo
1817 1892
 			cache_put_data('response_prefix', $context['response_prefix'], 600);
1818 1893
 		}
1819 1894
 		$form_subject = $row_quoted['subject'];
1820
-		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
1821
-			$form_subject = $context['response_prefix'] . $form_subject;
1895
+		if ($context['reply'] && trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
1896
+					$form_subject = $context['response_prefix'] . $form_subject;
1897
+		}
1822 1898
 
1823 1899
 		if (isset($_REQUEST['quote']))
1824 1900
 		{
1825 1901
 			// Remove any nested quotes and <br>...
1826 1902
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $row_quoted['body']);
1827
-			if (!empty($modSettings['removeNestedQuotes']))
1828
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1829
-			if (empty($row_quoted['id_member']))
1830
-				$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1831
-			else
1832
-				$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1833
-		}
1834
-		else
1835
-			$form_message = '';
1903
+			if (!empty($modSettings['removeNestedQuotes'])) {
1904
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
1905
+			}
1906
+			if (empty($row_quoted['id_member'])) {
1907
+							$form_message = '[quote author=&quot;' . $row_quoted['real_name'] . '&quot;]' . "\n" . $form_message . "\n" . '[/quote]';
1908
+			} else {
1909
+							$form_message = '[quote author=' . $row_quoted['real_name'] . ' link=action=profile;u=' . $row_quoted['id_member'] . ' date=' . $row_quoted['msgtime'] . ']' . "\n" . $form_message . "\n" . '[/quote]';
1910
+			}
1911
+		} else {
1912
+					$form_message = '';
1913
+		}
1836 1914
 
1837 1915
 		// Do the BBC thang on the message.
1838 1916
 		$row_quoted['body'] = parse_bbc($row_quoted['body'], true, 'pm' . $row_quoted['id_pm']);
@@ -1853,8 +1931,7 @@  discard block
 block discarded – undo
1853 1931
 			'timestamp' => forum_time(true, $row_quoted['msgtime']),
1854 1932
 			'body' => $row_quoted['body']
1855 1933
 		);
1856
-	}
1857
-	else
1934
+	} else
1858 1935
 	{
1859 1936
 		$context['quoted_message'] = false;
1860 1937
 		$form_subject = '';
@@ -1873,11 +1950,12 @@  discard block
 block discarded – undo
1873 1950
 		if ($_REQUEST['u'] == 'all' && isset($row_quoted))
1874 1951
 		{
1875 1952
 			// Firstly, to reply to all we clearly already have $row_quoted - so have the original member from.
1876
-			if ($row_quoted['id_member'] != $user_info['id'])
1877
-				$context['recipients']['to'][] = array(
1953
+			if ($row_quoted['id_member'] != $user_info['id']) {
1954
+							$context['recipients']['to'][] = array(
1878 1955
 					'id' => $row_quoted['id_member'],
1879 1956
 					'name' => $smcFunc['htmlspecialchars']($row_quoted['real_name']),
1880
-				);
1957
+				);
1958
+			}
1881 1959
 
1882 1960
 			// Now to get the others.
1883 1961
 			$request = $smcFunc['db_query']('', '
@@ -1893,18 +1971,19 @@  discard block
 block discarded – undo
1893 1971
 					'not_bcc' => 0,
1894 1972
 				)
1895 1973
 			);
1896
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1897
-				$context['recipients']['to'][] = array(
1974
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1975
+							$context['recipients']['to'][] = array(
1898 1976
 					'id' => $row['id_member'],
1899 1977
 					'name' => $row['real_name'],
1900
-				);
1978
+				);
1979
+			}
1901 1980
 			$smcFunc['db_free_result']($request);
1902
-		}
1903
-		else
1981
+		} else
1904 1982
 		{
1905 1983
 			$_REQUEST['u'] = explode(',', $_REQUEST['u']);
1906
-			foreach ($_REQUEST['u'] as $key => $uID)
1907
-				$_REQUEST['u'][$key] = (int) $uID;
1984
+			foreach ($_REQUEST['u'] as $key => $uID) {
1985
+							$_REQUEST['u'][$key] = (int) $uID;
1986
+			}
1908 1987
 
1909 1988
 			$_REQUEST['u'] = array_unique($_REQUEST['u']);
1910 1989
 
@@ -1918,22 +1997,24 @@  discard block
 block discarded – undo
1918 1997
 					'limit' => count($_REQUEST['u']),
1919 1998
 				)
1920 1999
 			);
1921
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1922
-				$context['recipients']['to'][] = array(
2000
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2001
+							$context['recipients']['to'][] = array(
1923 2002
 					'id' => $row['id_member'],
1924 2003
 					'name' => $row['real_name'],
1925
-				);
2004
+				);
2005
+			}
1926 2006
 			$smcFunc['db_free_result']($request);
1927 2007
 		}
1928 2008
 
1929 2009
 		// Get a literal name list in case the user has JavaScript disabled.
1930 2010
 		$names = array();
1931
-		foreach ($context['recipients']['to'] as $to)
1932
-			$names[] = $to['name'];
2011
+		foreach ($context['recipients']['to'] as $to) {
2012
+					$names[] = $to['name'];
2013
+		}
1933 2014
 		$context['to_value'] = empty($names) ? '' : '&quot;' . implode('&quot;, &quot;', $names) . '&quot;';
1934
-	}
1935
-	else
1936
-		$context['to_value'] = '';
2015
+	} else {
2016
+			$context['to_value'] = '';
2017
+	}
1937 2018
 
1938 2019
 	// Set the defaults...
1939 2020
 	$context['subject'] = $form_subject;
@@ -2003,8 +2084,9 @@  discard block
 block discarded – undo
2003 2084
 
2004 2085
 	// validate with loadMemberData()
2005 2086
 	$memberResult = loadMemberData($user_info['id'], false);
2006
-	if (!$memberResult)
2007
-		fatal_lang_error('not_a_user', false);
2087
+	if (!$memberResult) {
2088
+			fatal_lang_error('not_a_user', false);
2089
+	}
2008 2090
 	list ($memID) = $memberResult;
2009 2091
 
2010 2092
 	// drafts is where the functions reside
@@ -2030,9 +2112,9 @@  discard block
 block discarded – undo
2030 2112
 		$context['sub_template'] = 'send';
2031 2113
 		loadJavaScriptFile('PersonalMessage.js', array('defer' => false, 'minimize' => true), 'smf_pms');
2032 2114
 		loadJavaScriptFile('suggest.js', array('defer' => false, 'minimize' => true), 'smf_suggest');
2033
-	}
2034
-	else
2035
-		$context['sub_template'] = 'pm';
2115
+	} else {
2116
+			$context['sub_template'] = 'pm';
2117
+	}
2036 2118
 
2037 2119
 	$context['page_title'] = $txt['send_message'];
2038 2120
 
@@ -2093,10 +2175,11 @@  discard block
 block discarded – undo
2093 2175
 		);
2094 2176
 		if ($smcFunc['db_num_rows']($request) == 0)
2095 2177
 		{
2096
-			if (!isset($_REQUEST['xml']))
2097
-				fatal_lang_error('pm_not_yours', false);
2098
-			else
2099
-				$error_types[] = 'pm_not_yours';
2178
+			if (!isset($_REQUEST['xml'])) {
2179
+							fatal_lang_error('pm_not_yours', false);
2180
+			} else {
2181
+							$error_types[] = 'pm_not_yours';
2182
+			}
2100 2183
 		}
2101 2184
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
2102 2185
 		$smcFunc['db_free_result']($request);
@@ -2143,14 +2226,16 @@  discard block
 block discarded – undo
2143 2226
 		$context['post_error'][$error_type] = true;
2144 2227
 		if (isset($txt['error_' . $error_type]))
2145 2228
 		{
2146
-			if ($error_type == 'long_message')
2147
-				$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2229
+			if ($error_type == 'long_message') {
2230
+							$txt['error_' . $error_type] = sprintf($txt['error_' . $error_type], $modSettings['max_messageLength']);
2231
+			}
2148 2232
 			$context['post_error']['messages'][] = $txt['error_' . $error_type];
2149 2233
 		}
2150 2234
 
2151 2235
 		// If it's not a minor error flag it as such.
2152
-		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject')))
2153
-			$context['error_type'] = 'serious';
2236
+		if (!in_array($error_type, array('new_reply', 'not_approved', 'new_replies', 'old_topic', 'need_qr_verification', 'no_subject'))) {
2237
+					$context['error_type'] = 'serious';
2238
+		}
2154 2239
 	}
2155 2240
 
2156 2241
 	// We need to load the editor once more.
@@ -2208,8 +2293,9 @@  discard block
 block discarded – undo
2208 2293
 	require_once($sourcedir . '/Subs-Auth.php');
2209 2294
 
2210 2295
 	// PM Drafts enabled and needed?
2211
-	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft'])))
2212
-		require_once($sourcedir . '/Drafts.php');
2296
+	if ($context['drafts_pm_save'] && (isset($_POST['save_draft']) || isset($_POST['id_pm_draft']))) {
2297
+			require_once($sourcedir . '/Drafts.php');
2298
+	}
2213 2299
 
2214 2300
 	loadLanguage('PersonalMessage', '', false);
2215 2301
 
@@ -2239,24 +2325,27 @@  discard block
 block discarded – undo
2239 2325
 
2240 2326
 		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
2241 2327
 		{
2242
-			if (!isset($_REQUEST['xml']))
2243
-				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2244
-			else
2245
-				$post_errors[] = 'pm_too_many_per_hour';
2328
+			if (!isset($_REQUEST['xml'])) {
2329
+							fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
2330
+			} else {
2331
+							$post_errors[] = 'pm_too_many_per_hour';
2332
+			}
2246 2333
 		}
2247 2334
 	}
2248 2335
 
2249 2336
 	// If your session timed out, show an error, but do allow to re-submit.
2250
-	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '')
2251
-		$post_errors[] = 'session_timeout';
2337
+	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '') {
2338
+			$post_errors[] = 'session_timeout';
2339
+	}
2252 2340
 
2253 2341
 	$_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
2254 2342
 	$_REQUEST['to'] = empty($_POST['to']) ? (empty($_GET['to']) ? '' : $_GET['to']) : $_POST['to'];
2255 2343
 	$_REQUEST['bcc'] = empty($_POST['bcc']) ? (empty($_GET['bcc']) ? '' : $_GET['bcc']) : $_POST['bcc'];
2256 2344
 
2257 2345
 	// Route the input from the 'u' parameter to the 'to'-list.
2258
-	if (!empty($_POST['u']))
2259
-		$_POST['recipient_to'] = explode(',', $_POST['u']);
2346
+	if (!empty($_POST['u'])) {
2347
+			$_POST['recipient_to'] = explode(',', $_POST['u']);
2348
+	}
2260 2349
 
2261 2350
 	// Construct the list of recipients.
2262 2351
 	$recipientList = array();
@@ -2268,8 +2357,9 @@  discard block
 block discarded – undo
2268 2357
 		$recipientList[$recipientType] = array();
2269 2358
 		if (!empty($_POST['recipient_' . $recipientType]) && is_array($_POST['recipient_' . $recipientType]))
2270 2359
 		{
2271
-			foreach ($_POST['recipient_' . $recipientType] as $recipient)
2272
-				$recipientList[$recipientType][] = (int) $recipient;
2360
+			foreach ($_POST['recipient_' . $recipientType] as $recipient) {
2361
+							$recipientList[$recipientType][] = (int) $recipient;
2362
+			}
2273 2363
 		}
2274 2364
 
2275 2365
 		// Are there also literal names set?
@@ -2283,10 +2373,11 @@  discard block
 block discarded – undo
2283 2373
 
2284 2374
 			foreach ($namedRecipientList[$recipientType] as $index => $recipient)
2285 2375
 			{
2286
-				if (strlen(trim($recipient)) > 0)
2287
-					$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2288
-				else
2289
-					unset($namedRecipientList[$recipientType][$index]);
2376
+				if (strlen(trim($recipient)) > 0) {
2377
+									$namedRecipientList[$recipientType][$index] = $smcFunc['htmlspecialchars']($smcFunc['strtolower'](trim($recipient)));
2378
+				} else {
2379
+									unset($namedRecipientList[$recipientType][$index]);
2380
+				}
2290 2381
 			}
2291 2382
 
2292 2383
 			if (!empty($namedRecipientList[$recipientType]))
@@ -2316,8 +2407,9 @@  discard block
 block discarded – undo
2316 2407
 		}
2317 2408
 
2318 2409
 		// Selected a recipient to be deleted? Remove them now.
2319
-		if (!empty($_POST['delete_recipient']))
2320
-			$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2410
+		if (!empty($_POST['delete_recipient'])) {
2411
+					$recipientList[$recipientType] = array_diff($recipientList[$recipientType], array((int) $_POST['delete_recipient']));
2412
+		}
2321 2413
 
2322 2414
 		// Make sure we don't include the same name twice
2323 2415
 		$recipientList[$recipientType] = array_unique($recipientList[$recipientType]);
@@ -2327,8 +2419,9 @@  discard block
 block discarded – undo
2327 2419
 	$is_recipient_change = !empty($_POST['delete_recipient']) || !empty($_POST['to_submit']) || !empty($_POST['bcc_submit']);
2328 2420
 
2329 2421
 	// Check if there's at least one recipient.
2330
-	if (empty($recipientList['to']) && empty($recipientList['bcc']))
2331
-		$post_errors[] = 'no_to';
2422
+	if (empty($recipientList['to']) && empty($recipientList['bcc'])) {
2423
+			$post_errors[] = 'no_to';
2424
+	}
2332 2425
 
2333 2426
 	// Make sure that we remove the members who did get it from the screen.
2334 2427
 	if (!$is_recipient_change)
@@ -2342,28 +2435,31 @@  discard block
 block discarded – undo
2342 2435
 				// Since we already have a post error, remove the previous one.
2343 2436
 				$post_errors = array_diff($post_errors, array('no_to'));
2344 2437
 
2345
-				foreach ($namesNotFound[$recipientType] as $name)
2346
-					$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2438
+				foreach ($namesNotFound[$recipientType] as $name) {
2439
+									$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2440
+				}
2347 2441
 			}
2348 2442
 		}
2349 2443
 	}
2350 2444
 
2351 2445
 	// Did they make any mistakes?
2352
-	if ($_REQUEST['subject'] == '')
2353
-		$post_errors[] = 'no_subject';
2354
-	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '')
2355
-		$post_errors[] = 'no_message';
2356
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength'])
2357
-		$post_errors[] = 'long_message';
2358
-	else
2446
+	if ($_REQUEST['subject'] == '') {
2447
+			$post_errors[] = 'no_subject';
2448
+	}
2449
+	if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
2450
+			$post_errors[] = 'no_message';
2451
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_REQUEST['message']) > $modSettings['max_messageLength']) {
2452
+			$post_errors[] = 'long_message';
2453
+	} else
2359 2454
 	{
2360 2455
 		// Preparse the message.
2361 2456
 		$message = $_REQUEST['message'];
2362 2457
 		preparsecode($message);
2363 2458
 
2364 2459
 		// Make sure there's still some content left without the tags.
2365
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false))
2366
-			$post_errors[] = 'no_message';
2460
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($smcFunc['htmlspecialchars']($message, ENT_QUOTES), false), '<img>')) === '' && (!allowedTo('admin_forum') || strpos($message, '[html]') === false)) {
2461
+					$post_errors[] = 'no_message';
2462
+		}
2367 2463
 	}
2368 2464
 
2369 2465
 	// Wrong verification code?
@@ -2375,13 +2471,15 @@  discard block
 block discarded – undo
2375 2471
 		);
2376 2472
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
2377 2473
 
2378
-		if (is_array($context['require_verification']))
2379
-			$post_errors = array_merge($post_errors, $context['require_verification']);
2474
+		if (is_array($context['require_verification'])) {
2475
+					$post_errors = array_merge($post_errors, $context['require_verification']);
2476
+		}
2380 2477
 	}
2381 2478
 
2382 2479
 	// If they did, give a chance to make ammends.
2383
-	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml']))
2384
-		return messagePostError($post_errors, $namedRecipientList, $recipientList);
2480
+	if (!empty($post_errors) && !$is_recipient_change && !isset($_REQUEST['preview']) && !isset($_REQUEST['xml'])) {
2481
+			return messagePostError($post_errors, $namedRecipientList, $recipientList);
2482
+	}
2385 2483
 
2386 2484
 	// Want to take a second glance before you send?
2387 2485
 	if (isset($_REQUEST['preview']))
@@ -2412,8 +2510,9 @@  discard block
 block discarded – undo
2412 2510
 		foreach ($namesNotFound as $recipientType => $names)
2413 2511
 		{
2414 2512
 			$post_errors[] = 'bad_' . $recipientType;
2415
-			foreach ($names as $name)
2416
-				$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2513
+			foreach ($names as $name) {
2514
+							$context['send_log']['failed'][] = sprintf($txt['pm_error_user_not_found'], $name);
2515
+			}
2417 2516
 		}
2418 2517
 
2419 2518
 		return messagePostError(array(), $namedRecipientList, $recipientList);
@@ -2443,13 +2542,14 @@  discard block
 block discarded – undo
2443 2542
 	checkSubmitOnce('check');
2444 2543
 
2445 2544
 	// Do the actual sending of the PM.
2446
-	if (!empty($recipientList['to']) || !empty($recipientList['bcc']))
2447
-		$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2448
-	else
2449
-		$context['send_log'] = array(
2545
+	if (!empty($recipientList['to']) || !empty($recipientList['bcc'])) {
2546
+			$context['send_log'] = sendpm($recipientList, $_REQUEST['subject'], $_REQUEST['message'], true, null, !empty($_REQUEST['pm_head']) ? (int) $_REQUEST['pm_head'] : 0);
2547
+	} else {
2548
+			$context['send_log'] = array(
2450 2549
 			'sent' => array(),
2451 2550
 			'failed' => array()
2452
-		);
2551
+		);
2552
+	}
2453 2553
 
2454 2554
 	// Mark the message as "replied to".
2455 2555
 	if (!empty($context['send_log']['sent']) && !empty($_REQUEST['replied_to']) && isset($_REQUEST['f']) && $_REQUEST['f'] == 'inbox')
@@ -2467,11 +2567,12 @@  discard block
 block discarded – undo
2467 2567
 	}
2468 2568
 
2469 2569
 	// If one or more of the recipient were invalid, go back to the post screen with the failed usernames.
2470
-	if (!empty($context['send_log']['failed']))
2471
-		return messagePostError($post_errors, $namesNotFound, array(
2570
+	if (!empty($context['send_log']['failed'])) {
2571
+			return messagePostError($post_errors, $namesNotFound, array(
2472 2572
 			'to' => array_intersect($recipientList['to'], $context['send_log']['failed']),
2473 2573
 			'bcc' => array_intersect($recipientList['bcc'], $context['send_log']['failed'])
2474
-		));
2574
+		));
2575
+	}
2475 2576
 
2476 2577
 	// Message sent successfully?
2477 2578
 	if (!empty($context['send_log']) && empty($context['send_log']['failed']))
@@ -2479,8 +2580,9 @@  discard block
 block discarded – undo
2479 2580
 		$context['current_label_redirect'] = $context['current_label_redirect'] . ';done=sent';
2480 2581
 
2481 2582
 		// If we had a PM draft for this one, then its time to remove it since it was just sent
2482
-		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft']))
2483
-			DeleteDraft($_POST['id_pm_draft']);
2583
+		if ($context['drafts_pm_save'] && !empty($_POST['id_pm_draft'])) {
2584
+					DeleteDraft($_POST['id_pm_draft']);
2585
+		}
2484 2586
 	}
2485 2587
 
2486 2588
 	// Go back to the where they sent from, if possible...
@@ -2495,24 +2597,28 @@  discard block
 block discarded – undo
2495 2597
 
2496 2598
 	checkSession('request');
2497 2599
 
2498
-	if (isset($_REQUEST['del_selected']))
2499
-		$_REQUEST['pm_action'] = 'delete';
2600
+	if (isset($_REQUEST['del_selected'])) {
2601
+			$_REQUEST['pm_action'] = 'delete';
2602
+	}
2500 2603
 
2501 2604
 	if (isset($_REQUEST['pm_action']) && $_REQUEST['pm_action'] != '' && !empty($_REQUEST['pms']) && is_array($_REQUEST['pms']))
2502 2605
 	{
2503
-		foreach ($_REQUEST['pms'] as $pm)
2504
-			$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2606
+		foreach ($_REQUEST['pms'] as $pm) {
2607
+					$_REQUEST['pm_actions'][(int) $pm] = $_REQUEST['pm_action'];
2608
+		}
2505 2609
 	}
2506 2610
 
2507
-	if (empty($_REQUEST['pm_actions']))
2508
-		redirectexit($context['current_label_redirect']);
2611
+	if (empty($_REQUEST['pm_actions'])) {
2612
+			redirectexit($context['current_label_redirect']);
2613
+	}
2509 2614
 
2510 2615
 	// If we are in conversation, we may need to apply this to every message in the conversation.
2511 2616
 	if ($context['display_mode'] == 2 && isset($_REQUEST['conversation']))
2512 2617
 	{
2513 2618
 		$id_pms = array();
2514
-		foreach ($_REQUEST['pm_actions'] as $pm => $dummy)
2515
-			$id_pms[] = (int) $pm;
2619
+		foreach ($_REQUEST['pm_actions'] as $pm => $dummy) {
2620
+					$id_pms[] = (int) $pm;
2621
+		}
2516 2622
 
2517 2623
 		$request = $smcFunc['db_query']('', '
2518 2624
 			SELECT id_pm_head, id_pm
@@ -2523,8 +2629,9 @@  discard block
 block discarded – undo
2523 2629
 			)
2524 2630
 		);
2525 2631
 		$pm_heads = array();
2526
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2527
-			$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2632
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2633
+					$pm_heads[$row['id_pm_head']] = $row['id_pm'];
2634
+		}
2528 2635
 		$smcFunc['db_free_result']($request);
2529 2636
 
2530 2637
 		$request = $smcFunc['db_query']('', '
@@ -2538,8 +2645,9 @@  discard block
 block discarded – undo
2538 2645
 		// Copy the action from the single to PM to the others.
2539 2646
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2540 2647
 		{
2541
-			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]]))
2542
-				$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2648
+			if (isset($pm_heads[$row['id_pm_head']]) && isset($_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]])) {
2649
+							$_REQUEST['pm_actions'][$row['id_pm']] = $_REQUEST['pm_actions'][$pm_heads[$row['id_pm_head']]];
2650
+			}
2543 2651
 		}
2544 2652
 		$smcFunc['db_free_result']($request);
2545 2653
 	}
@@ -2550,22 +2658,21 @@  discard block
 block discarded – undo
2550 2658
 	$labels = array();
2551 2659
 	foreach ($_REQUEST['pm_actions'] as $pm => $action)
2552 2660
 	{
2553
-		if ($action === 'delete')
2554
-			$to_delete[] = (int) $pm;
2555
-		else
2661
+		if ($action === 'delete') {
2662
+					$to_delete[] = (int) $pm;
2663
+		} else
2556 2664
 		{
2557 2665
 			if (substr($action, 0, 4) == 'add_')
2558 2666
 			{
2559 2667
 				$type = 'add';
2560 2668
 				$action = substr($action, 4);
2561
-			}
2562
-			elseif (substr($action, 0, 4) == 'rem_')
2669
+			} elseif (substr($action, 0, 4) == 'rem_')
2563 2670
 			{
2564 2671
 				$type = 'rem';
2565 2672
 				$action = substr($action, 4);
2566
-			}
2567
-			else
2568
-				$type = 'unk';
2673
+			} else {
2674
+							$type = 'unk';
2675
+			}
2569 2676
 
2570 2677
 			if ($action == '-1' || (int) $action > 0)
2571 2678
 			{
@@ -2576,8 +2683,9 @@  discard block
 block discarded – undo
2576 2683
 	}
2577 2684
 
2578 2685
 	// Deleting, it looks like?
2579
-	if (!empty($to_delete))
2580
-		deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2686
+	if (!empty($to_delete)) {
2687
+			deleteMessages($to_delete, $context['display_mode'] == 2 ? null : $context['folder']);
2688
+	}
2581 2689
 
2582 2690
 	// Are we labeling anything?
2583 2691
 	if (!empty($to_label) && $context['folder'] == 'inbox')
@@ -2643,8 +2751,7 @@  discard block
 block discarded – undo
2643 2751
 				}
2644 2752
 
2645 2753
 				$smcFunc['db_free_result']($request2);
2646
-			}
2647
-			elseif ($type == 'rem')
2754
+			} elseif ($type == 'rem')
2648 2755
 			{
2649 2756
 				// If we're removing from the inbox, see if we have at least one other label.
2650 2757
 				// This query is faster than the one above
@@ -2676,21 +2783,25 @@  discard block
 block discarded – undo
2676 2783
 			if ($to_label[$row['id_pm']] != '-1')
2677 2784
 			{
2678 2785
 				// If this label is in the list and we're not adding it, remove it
2679
-				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add')
2680
-					unset($labels[$to_label[$row['id_pm']]]);
2681
-				else if ($type !== 'rem')
2682
-					$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2786
+				if (array_key_exists($to_label[$row['id_pm']], $labels) && $type !== 'add') {
2787
+									unset($labels[$to_label[$row['id_pm']]]);
2788
+				} else if ($type !== 'rem') {
2789
+									$labels[$to_label[$row['id_pm']]] = $to_label[$row['id_pm']];
2790
+				}
2683 2791
 			}
2684 2792
 
2685 2793
 			// Removing all labels or just removing the inbox label
2686
-			if ($type == 'rem' && empty($labels))
2687
-				$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2794
+			if ($type == 'rem' && empty($labels)) {
2795
+							$in_inbox = (empty($context['can_remove_inbox']) ? 1 : 0);
2796
+			}
2688 2797
 			// Adding new labels, but removing inbox and applying new ones
2689
-			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels))
2690
-				$in_inbox = 0;
2798
+			elseif ($type == 'add' && !empty($options['pm_remove_inbox_label']) && !empty($labels)) {
2799
+							$in_inbox = 0;
2800
+			}
2691 2801
 			// Just adding it to the inbox
2692
-			else
2693
-				$in_inbox = 1;
2802
+			else {
2803
+							$in_inbox = 1;
2804
+			}
2694 2805
 
2695 2806
 			// Are we adding it to or removing it from the inbox?
2696 2807
 			if ($in_inbox != $row['in_inbox'])
@@ -2732,8 +2843,9 @@  discard block
 block discarded – undo
2732 2843
 			if (!empty($labels_to_apply))
2733 2844
 			{
2734 2845
 				$inserts = array();
2735
-				foreach ($labels_to_apply as $label)
2736
-					$inserts[] = array($row['id_pm'], $label);
2846
+				foreach ($labels_to_apply as $label) {
2847
+									$inserts[] = array($row['id_pm'], $label);
2848
+				}
2737 2849
 
2738 2850
 				$smcFunc['db_insert']('',
2739 2851
 					'{db_prefix}pm_labeled_messages',
@@ -2777,11 +2889,13 @@  discard block
 block discarded – undo
2777 2889
 	checkSession('get');
2778 2890
 
2779 2891
 	// If all then delete all messages the user has.
2780
-	if ($_REQUEST['f'] == 'all')
2781
-		deleteMessages(null, null);
2892
+	if ($_REQUEST['f'] == 'all') {
2893
+			deleteMessages(null, null);
2894
+	}
2782 2895
 	// Otherwise just the selected folder.
2783
-	else
2784
-		deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2896
+	else {
2897
+			deleteMessages(null, $_REQUEST['f'] != 'sent' ? 'inbox' : 'sent');
2898
+	}
2785 2899
 
2786 2900
 	// Done... all gone.
2787 2901
 	redirectexit($context['current_label_redirect']);
@@ -2818,8 +2932,9 @@  discard block
 block discarded – undo
2818 2932
 				'msgtime' => $deleteTime,
2819 2933
 			)
2820 2934
 		);
2821
-		while ($row = $smcFunc['db_fetch_row']($request))
2822
-			$toDelete[] = $row[0];
2935
+		while ($row = $smcFunc['db_fetch_row']($request)) {
2936
+					$toDelete[] = $row[0];
2937
+		}
2823 2938
 		$smcFunc['db_free_result']($request);
2824 2939
 
2825 2940
 		// Select all messages in their inbox older than $deleteTime.
@@ -2836,8 +2951,9 @@  discard block
 block discarded – undo
2836 2951
 				'msgtime' => $deleteTime,
2837 2952
 			)
2838 2953
 		);
2839
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2840
-			$toDelete[] = $row['id_pm'];
2954
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2955
+					$toDelete[] = $row['id_pm'];
2956
+		}
2841 2957
 		$smcFunc['db_free_result']($request);
2842 2958
 
2843 2959
 		// Delete the actual messages.
@@ -2868,26 +2984,29 @@  discard block
 block discarded – undo
2868 2984
 {
2869 2985
 	global $user_info, $smcFunc;
2870 2986
 
2871
-	if ($owner === null)
2872
-		$owner = array($user_info['id']);
2873
-	elseif (empty($owner))
2874
-		return;
2875
-	elseif (!is_array($owner))
2876
-		$owner = array($owner);
2987
+	if ($owner === null) {
2988
+			$owner = array($user_info['id']);
2989
+	} elseif (empty($owner)) {
2990
+			return;
2991
+	} elseif (!is_array($owner)) {
2992
+			$owner = array($owner);
2993
+	}
2877 2994
 
2878 2995
 	if ($personal_messages !== null)
2879 2996
 	{
2880
-		if (empty($personal_messages) || !is_array($personal_messages))
2881
-			return;
2997
+		if (empty($personal_messages) || !is_array($personal_messages)) {
2998
+					return;
2999
+		}
2882 3000
 
2883
-		foreach ($personal_messages as $index => $delete_id)
2884
-			$personal_messages[$index] = (int) $delete_id;
3001
+		foreach ($personal_messages as $index => $delete_id) {
3002
+					$personal_messages[$index] = (int) $delete_id;
3003
+		}
2885 3004
 
2886 3005
 		$where = '
2887 3006
 				AND id_pm IN ({array_int:pm_list})';
2888
-	}
2889
-	else
2890
-		$where = '';
3007
+	} else {
3008
+			$where = '';
3009
+	}
2891 3010
 
2892 3011
 	if ($folder == 'sent' || $folder === null)
2893 3012
 	{
@@ -2922,17 +3041,19 @@  discard block
 block discarded – undo
2922 3041
 		// ...And update the statistics accordingly - now including unread messages!.
2923 3042
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2924 3043
 		{
2925
-			if ($row['is_read'])
2926
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
2927
-			else
2928
-				updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3044
+			if ($row['is_read']) {
3045
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages']));
3046
+			} else {
3047
+							updateMemberData($row['id_member'], array('instant_messages' => $where == '' ? 0 : 'instant_messages - ' . $row['num_deleted_messages'], 'unread_messages' => $where == '' ? 0 : 'unread_messages - ' . $row['num_deleted_messages']));
3048
+			}
2929 3049
 
2930 3050
 			// If this is the current member we need to make their message count correct.
2931 3051
 			if ($user_info['id'] == $row['id_member'])
2932 3052
 			{
2933 3053
 				$user_info['messages'] -= $row['num_deleted_messages'];
2934
-				if (!($row['is_read']))
2935
-					$user_info['unread_messages'] -= $row['num_deleted_messages'];
3054
+				if (!($row['is_read'])) {
3055
+									$user_info['unread_messages'] -= $row['num_deleted_messages'];
3056
+				}
2936 3057
 			}
2937 3058
 		}
2938 3059
 		$smcFunc['db_free_result']($request);
@@ -3000,8 +3121,9 @@  discard block
 block discarded – undo
3000 3121
 		)
3001 3122
 	);
3002 3123
 	$remove_pms = array();
3003
-	while ($row = $smcFunc['db_fetch_assoc']($request))
3004
-		$remove_pms[] = $row['sender'];
3124
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
3125
+			$remove_pms[] = $row['sender'];
3126
+	}
3005 3127
 	$smcFunc['db_free_result']($request);
3006 3128
 
3007 3129
 	if (!empty($remove_pms))
@@ -3046,8 +3168,9 @@  discard block
 block discarded – undo
3046 3168
 {
3047 3169
 	global $user_info, $context, $smcFunc;
3048 3170
 
3049
-	if ($owner === null)
3050
-		$owner = $user_info['id'];
3171
+	if ($owner === null) {
3172
+			$owner = $user_info['id'];
3173
+	}
3051 3174
 
3052 3175
 	$in_inbox = '';
3053 3176
 
@@ -3071,8 +3194,7 @@  discard block
 block discarded – undo
3071 3194
 		}
3072 3195
 
3073 3196
 		$smcFunc['db_free_result']($get_messages);
3074
-	}
3075
-	elseif ($label = '-1')
3197
+	} elseif ($label = '-1')
3076 3198
 	{
3077 3199
 		// Marking all PMs in your inbox read
3078 3200
 		$in_inbox = '
@@ -3097,8 +3219,9 @@  discard block
 block discarded – undo
3097 3219
 	{
3098 3220
 		if ($owner == $user_info['id'])
3099 3221
 		{
3100
-			foreach ($context['labels'] as $label)
3101
-				$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3222
+			foreach ($context['labels'] as $label) {
3223
+							$context['labels'][(int) $label['id']]['unread_messages'] = 0;
3224
+			}
3102 3225
 		}
3103 3226
 
3104 3227
 		$result = $smcFunc['db_query']('', '
@@ -3118,8 +3241,9 @@  discard block
 block discarded – undo
3118 3241
 		{
3119 3242
 			$total_unread += $row['num'];
3120 3243
 
3121
-			if ($owner != $user_info['id'] || empty($row['id_pm']))
3122
-				continue;
3244
+			if ($owner != $user_info['id'] || empty($row['id_pm'])) {
3245
+							continue;
3246
+			}
3123 3247
 
3124 3248
 			$this_labels = array();
3125 3249
 
@@ -3143,11 +3267,13 @@  discard block
 block discarded – undo
3143 3267
 
3144 3268
 			$smcFunc['db_free_result']($result2);
3145 3269
 
3146
-			foreach ($this_labels as $this_label)
3147
-				$context['labels'][$this_label]['unread_messages'] += $row['num'];
3270
+			foreach ($this_labels as $this_label) {
3271
+							$context['labels'][$this_label]['unread_messages'] += $row['num'];
3272
+			}
3148 3273
 
3149
-			if ($row['in_inbox'] == 1)
3150
-				$context['labels'][-1]['unread_messages'] += $row['num'];
3274
+			if ($row['in_inbox'] == 1) {
3275
+							$context['labels'][-1]['unread_messages'] += $row['num'];
3276
+			}
3151 3277
 		}
3152 3278
 		$smcFunc['db_free_result']($result);
3153 3279
 
@@ -3156,8 +3282,9 @@  discard block
 block discarded – undo
3156 3282
 		updateMemberData($owner, array('unread_messages' => $total_unread));
3157 3283
 
3158 3284
 		// If it was for the current member, reflect this in the $user_info array too.
3159
-		if ($owner == $user_info['id'])
3160
-			$user_info['unread_messages'] = $total_unread;
3285
+		if ($owner == $user_info['id']) {
3286
+					$user_info['unread_messages'] = $total_unread;
3287
+		}
3161 3288
 	}
3162 3289
 }
3163 3290
 
@@ -3185,8 +3312,9 @@  discard block
 block discarded – undo
3185 3312
 	// Add all existing labels to the array to save, slashing them as necessary...
3186 3313
 	foreach ($context['labels'] as $label)
3187 3314
 	{
3188
-		if ($label['id'] != -1)
3189
-			$the_labels[$label['id']] = $label['name'];
3315
+		if ($label['id'] != -1) {
3316
+					$the_labels[$label['id']] = $label['name'];
3317
+		}
3190 3318
 	}
3191 3319
 
3192 3320
 	if (isset($_POST[$context['session_var']]))
@@ -3205,8 +3333,9 @@  discard block
 block discarded – undo
3205 3333
 		{
3206 3334
 			$_POST['label'] = strtr($smcFunc['htmlspecialchars'](trim($_POST['label'])), array(',' => '&#044;'));
3207 3335
 
3208
-			if ($smcFunc['strlen']($_POST['label']) > 30)
3209
-				$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3336
+			if ($smcFunc['strlen']($_POST['label']) > 30) {
3337
+							$_POST['label'] = $smcFunc['substr']($_POST['label'], 0, 30);
3338
+			}
3210 3339
 			if ($_POST['label'] != '')
3211 3340
 			{
3212 3341
 				$the_labels[] = $_POST['label'];
@@ -3227,23 +3356,24 @@  discard block
 block discarded – undo
3227 3356
 		{
3228 3357
 			foreach ($the_labels as $id => $name)
3229 3358
 			{
3230
-				if ($id == -1)
3231
-					continue;
3232
-				elseif (isset($_POST['label_name'][$id]))
3359
+				if ($id == -1) {
3360
+									continue;
3361
+				} elseif (isset($_POST['label_name'][$id]))
3233 3362
 				{
3234 3363
 					$_POST['label_name'][$id] = trim(strtr($smcFunc['htmlspecialchars']($_POST['label_name'][$id]), array(',' => '&#044;')));
3235 3364
 
3236
-					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30)
3237
-						$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3365
+					if ($smcFunc['strlen']($_POST['label_name'][$id]) > 30) {
3366
+											$_POST['label_name'][$id] = $smcFunc['substr']($_POST['label_name'][$id], 0, 30);
3367
+					}
3238 3368
 					if ($_POST['label_name'][$id] != '')
3239 3369
 					{
3240 3370
 						// Changing the name of this label?
3241
-						if ($the_labels[$id] != $_POST['label_name'][$id])
3242
-							$label_updates[$id] = $_POST['label_name'][$id];
3371
+						if ($the_labels[$id] != $_POST['label_name'][$id]) {
3372
+													$label_updates[$id] = $_POST['label_name'][$id];
3373
+						}
3243 3374
 
3244 3375
 						$the_labels[(int) $id] = $_POST['label_name'][$id];
3245
-					}
3246
-					else
3376
+					} else
3247 3377
 					{
3248 3378
 						unset($the_labels[(int) $id]);
3249 3379
 						$labels_to_remove[] = $id;
@@ -3257,8 +3387,9 @@  discard block
 block discarded – undo
3257 3387
 		if (!empty($labels_to_add))
3258 3388
 		{
3259 3389
 			$inserts = array();
3260
-			foreach ($labels_to_add AS $label)
3261
-				$inserts[] = array($user_info['id'], $label);
3390
+			foreach ($labels_to_add AS $label) {
3391
+							$inserts[] = array($user_info['id'], $label);
3392
+			}
3262 3393
 
3263 3394
 			$smcFunc['db_insert']('', '{db_prefix}pm_labels', array('id_member' => 'int', 'name' => 'string-30'), $inserts, array());
3264 3395
 		}
@@ -3348,8 +3479,9 @@  discard block
 block discarded – undo
3348 3479
 				// Each action...
3349 3480
 				foreach ($rule['actions'] as $k2 => $action)
3350 3481
 				{
3351
-					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove))
3352
-						continue;
3482
+					if ($action['t'] != 'lab' || !in_array($action['v'], $labels_to_remove)) {
3483
+											continue;
3484
+					}
3353 3485
 
3354 3486
 					$rule_changes[] = $rule['id'];
3355 3487
 
@@ -3364,8 +3496,8 @@  discard block
 block discarded – undo
3364 3496
 		{
3365 3497
 			$rule_changes = array_unique($rule_changes);
3366 3498
 			// Update/delete as appropriate.
3367
-			foreach ($rule_changes as $k => $id)
3368
-				if (!empty($context['rules'][$id]['actions']))
3499
+			foreach ($rule_changes as $k => $id) {
3500
+							if (!empty($context['rules'][$id]['actions']))
3369 3501
 				{
3370 3502
 					$smcFunc['db_query']('', '
3371 3503
 						UPDATE {db_prefix}pm_rules
@@ -3377,13 +3509,14 @@  discard block
 block discarded – undo
3377 3509
 							'id_rule' => $id,
3378 3510
 							'actions' => $smcFunc['json_encode']($context['rules'][$id]['actions']),
3379 3511
 						)
3380
-					);
3512
+					);
3513
+			}
3381 3514
 					unset($rule_changes[$k]);
3382 3515
 				}
3383 3516
 
3384 3517
 			// Anything left here means it's lost all actions...
3385
-			if (!empty($rule_changes))
3386
-				$smcFunc['db_query']('', '
3518
+			if (!empty($rule_changes)) {
3519
+							$smcFunc['db_query']('', '
3387 3520
 					DELETE FROM {db_prefix}pm_rules
3388 3521
 					WHERE id_rule IN ({array_int:rule_list})
3389 3522
 							AND id_member = {int:current_member}',
@@ -3391,7 +3524,8 @@  discard block
 block discarded – undo
3391 3524
 						'current_member' => $user_info['id'],
3392 3525
 						'rule_list' => $rule_changes,
3393 3526
 					)
3394
-				);
3527
+				);
3528
+			}
3395 3529
 		}
3396 3530
 
3397 3531
 		// Make sure we're not caching this!
@@ -3461,8 +3595,9 @@  discard block
 block discarded – undo
3461 3595
 		// Save the fields.
3462 3596
 		saveProfileFields();
3463 3597
 
3464
-		if (!empty($profile_vars))
3465
-			updateMemberData($user_info['id'], $profile_vars);
3598
+		if (!empty($profile_vars)) {
3599
+					updateMemberData($user_info['id'], $profile_vars);
3600
+		}
3466 3601
 	}
3467 3602
 
3468 3603
 	setupProfileContext(
@@ -3487,13 +3622,15 @@  discard block
 block discarded – undo
3487 3622
 	global $user_info, $language, $modSettings, $smcFunc;
3488 3623
 
3489 3624
 	// Check that this feature is even enabled!
3490
-	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg']))
3491
-		fatal_lang_error('no_access', false);
3625
+	if (empty($modSettings['enableReportPM']) || empty($_REQUEST['pmsg'])) {
3626
+			fatal_lang_error('no_access', false);
3627
+	}
3492 3628
 
3493 3629
 	$pmsg = (int) $_REQUEST['pmsg'];
3494 3630
 
3495
-	if (!isAccessiblePM($pmsg, 'inbox'))
3496
-		fatal_lang_error('no_access', false);
3631
+	if (!isAccessiblePM($pmsg, 'inbox')) {
3632
+			fatal_lang_error('no_access', false);
3633
+	}
3497 3634
 
3498 3635
 	$context['pm_id'] = $pmsg;
3499 3636
 	$context['page_title'] = $txt['pm_report_title'];
@@ -3515,8 +3652,9 @@  discard block
 block discarded – undo
3515 3652
 			)
3516 3653
 		);
3517 3654
 		$context['admins'] = array();
3518
-		while ($row = $smcFunc['db_fetch_assoc']($request))
3519
-			$context['admins'][$row['id_member']] = $row['real_name'];
3655
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
3656
+					$context['admins'][$row['id_member']] = $row['real_name'];
3657
+		}
3520 3658
 		$smcFunc['db_free_result']($request);
3521 3659
 
3522 3660
 		// How many admins in total?
@@ -3545,8 +3683,9 @@  discard block
 block discarded – undo
3545 3683
 			)
3546 3684
 		);
3547 3685
 		// Can only be a hacker here!
3548
-		if ($smcFunc['db_num_rows']($request) == 0)
3549
-			fatal_lang_error('no_access', false);
3686
+		if ($smcFunc['db_num_rows']($request) == 0) {
3687
+					fatal_lang_error('no_access', false);
3688
+		}
3550 3689
 		list ($subject, $body, $time, $memberFromID, $memberFromName) = $smcFunc['db_fetch_row']($request);
3551 3690
 		$smcFunc['db_free_result']($request);
3552 3691
 
@@ -3570,15 +3709,17 @@  discard block
 block discarded – undo
3570 3709
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3571 3710
 		{
3572 3711
 			// If it's hidden still don't reveal their names - privacy after all ;)
3573
-			if ($row['bcc'])
3574
-				$hidden_recipients++;
3575
-			else
3576
-				$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3712
+			if ($row['bcc']) {
3713
+							$hidden_recipients++;
3714
+			} else {
3715
+							$recipients[] = '[url=' . $scripturl . '?action=profile;u=' . $row['id_member_to'] . ']' . $row['to_name'] . '[/url]';
3716
+			}
3577 3717
 		}
3578 3718
 		$smcFunc['db_free_result']($request);
3579 3719
 
3580
-		if ($hidden_recipients)
3581
-			$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3720
+		if ($hidden_recipients) {
3721
+					$recipients[] = sprintf($txt['pm_report_pm_hidden'], $hidden_recipients);
3722
+		}
3582 3723
 
3583 3724
 		// Now let's get out and loop through the admins.
3584 3725
 		$request = $smcFunc['db_query']('', '
@@ -3594,8 +3735,9 @@  discard block
 block discarded – undo
3594 3735
 		);
3595 3736
 
3596 3737
 		// Maybe we shouldn't advertise this?
3597
-		if ($smcFunc['db_num_rows']($request) == 0)
3598
-			fatal_lang_error('no_access', false);
3738
+		if ($smcFunc['db_num_rows']($request) == 0) {
3739
+					fatal_lang_error('no_access', false);
3740
+		}
3599 3741
 
3600 3742
 		$memberFromName = un_htmlspecialchars($memberFromName);
3601 3743
 
@@ -3614,8 +3756,9 @@  discard block
 block discarded – undo
3614 3756
 				// Make the body.
3615 3757
 				$report_body = str_replace(array('{REPORTER}', '{SENDER}'), array(un_htmlspecialchars($user_info['name']), $memberFromName), $txt['pm_report_pm_user_sent']);
3616 3758
 				$report_body .= "\n" . '[b]' . $_POST['reason'] . '[/b]' . "\n\n";
3617
-				if (!empty($recipients))
3618
-					$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3759
+				if (!empty($recipients)) {
3760
+									$report_body .= $txt['pm_report_pm_other_recipients'] . ' ' . implode(', ', $recipients) . "\n\n";
3761
+				}
3619 3762
 				$report_body .= $txt['pm_report_pm_unedited_below'] . "\n" . '[quote author=' . (empty($memberFromID) ? '&quot;' . $memberFromName . '&quot;' : $memberFromName . ' link=action=profile;u=' . $memberFromID . ' date=' . $time) . ']' . "\n" . un_htmlspecialchars($body) . '[/quote]';
3620 3763
 
3621 3764
 				// Plonk it in the array ;)
@@ -3635,12 +3778,14 @@  discard block
 block discarded – undo
3635 3778
 		$smcFunc['db_free_result']($request);
3636 3779
 
3637 3780
 		// Send a different email for each language.
3638
-		foreach ($messagesToSend as $lang => $message)
3639
-			sendpm($message['recipients'], $message['subject'], $message['body']);
3781
+		foreach ($messagesToSend as $lang => $message) {
3782
+					sendpm($message['recipients'], $message['subject'], $message['body']);
3783
+		}
3640 3784
 
3641 3785
 		// Give the user their own language back!
3642
-		if (!empty($modSettings['userLanguage']))
3643
-			loadLanguage('PersonalMessage', '', false);
3786
+		if (!empty($modSettings['userLanguage'])) {
3787
+					loadLanguage('PersonalMessage', '', false);
3788
+		}
3644 3789
 
3645 3790
 		// Leave them with a template.
3646 3791
 		$context['sub_template'] = 'report_message_complete';
@@ -3686,8 +3831,9 @@  discard block
 block discarded – undo
3686 3831
 	while ($row = $smcFunc['db_fetch_assoc']($request))
3687 3832
 	{
3688 3833
 		// Hide hidden groups!
3689
-		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups'))
3690
-			continue;
3834
+		if ($row['hidden'] && !$row['can_moderate'] && !allowedTo('manage_membergroups')) {
3835
+					continue;
3836
+		}
3691 3837
 
3692 3838
 		$context['groups'][$row['id_group']] = $row['group_name'];
3693 3839
 	}
@@ -3713,9 +3859,10 @@  discard block
 block discarded – undo
3713 3859
 			$context['rule'] = $context['rules'][$context['rid']];
3714 3860
 			$members = array();
3715 3861
 			// Need to get member names!
3716
-			foreach ($context['rule']['criteria'] as $k => $criteria)
3717
-				if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3718
-					$members[(int) $criteria['v']] = $k;
3862
+			foreach ($context['rule']['criteria'] as $k => $criteria) {
3863
+							if ($criteria['t'] == 'mid' && !empty($criteria['v']))
3864
+					$members[(int) $criteria['v']] = $k;
3865
+			}
3719 3866
 
3720 3867
 			if (!empty($members))
3721 3868
 			{
@@ -3727,19 +3874,20 @@  discard block
 block discarded – undo
3727 3874
 						'member_list' => array_keys($members),
3728 3875
 					)
3729 3876
 				);
3730
-				while ($row = $smcFunc['db_fetch_assoc']($request))
3731
-					$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3877
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
3878
+									$context['rule']['criteria'][$members[$row['id_member']]]['v'] = $row['member_name'];
3879
+				}
3732 3880
 				$smcFunc['db_free_result']($request);
3733 3881
 			}
3734
-		}
3735
-		else
3736
-			$context['rule'] = array(
3882
+		} else {
3883
+					$context['rule'] = array(
3737 3884
 				'id' => '',
3738 3885
 				'name' => '',
3739 3886
 				'criteria' => array(),
3740 3887
 				'actions' => array(),
3741 3888
 				'logic' => 'and',
3742
-			);
3889
+			);
3890
+		}
3743 3891
 	}
3744 3892
 	// Saving?
3745 3893
 	elseif (isset($_GET['save']))
@@ -3749,22 +3897,25 @@  discard block
 block discarded – undo
3749 3897
 
3750 3898
 		// Name is easy!
3751 3899
 		$ruleName = $smcFunc['htmlspecialchars'](trim($_POST['rule_name']));
3752
-		if (empty($ruleName))
3753
-			fatal_lang_error('pm_rule_no_name', false);
3900
+		if (empty($ruleName)) {
3901
+					fatal_lang_error('pm_rule_no_name', false);
3902
+		}
3754 3903
 
3755 3904
 		// Sanity check...
3756
-		if (empty($_POST['ruletype']) || empty($_POST['acttype']))
3757
-			fatal_lang_error('pm_rule_no_criteria', false);
3905
+		if (empty($_POST['ruletype']) || empty($_POST['acttype'])) {
3906
+					fatal_lang_error('pm_rule_no_criteria', false);
3907
+		}
3758 3908
 
3759 3909
 		// Let's do the criteria first - it's also hardest!
3760 3910
 		$criteria = array();
3761 3911
 		foreach ($_POST['ruletype'] as $ind => $type)
3762 3912
 		{
3763 3913
 			// Check everything is here...
3764
-			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]])))
3765
-				continue;
3766
-			elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind]))
3767
-				continue;
3914
+			if ($type == 'gid' && (!isset($_POST['ruledefgroup'][$ind]) || !isset($context['groups'][$_POST['ruledefgroup'][$ind]]))) {
3915
+							continue;
3916
+			} elseif ($type != 'bud' && !isset($_POST['ruledef'][$ind])) {
3917
+							continue;
3918
+			}
3768 3919
 
3769 3920
 			// Members need to be found.
3770 3921
 			if ($type == 'mid')
@@ -3788,13 +3939,13 @@  discard block
 block discarded – undo
3788 3939
 				$smcFunc['db_free_result']($request);
3789 3940
 
3790 3941
 				$criteria[] = array('t' => 'mid', 'v' => $memID);
3791
-			}
3792
-			elseif ($type == 'bud')
3793
-				$criteria[] = array('t' => 'bud', 'v' => 1);
3794
-			elseif ($type == 'gid')
3795
-				$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3796
-			elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '')
3797
-				$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3942
+			} elseif ($type == 'bud') {
3943
+							$criteria[] = array('t' => 'bud', 'v' => 1);
3944
+			} elseif ($type == 'gid') {
3945
+							$criteria[] = array('t' => 'gid', 'v' => (int) $_POST['ruledefgroup'][$ind]);
3946
+			} elseif (in_array($type, array('sub', 'msg')) && trim($_POST['ruledef'][$ind]) != '') {
3947
+							$criteria[] = array('t' => $type, 'v' => $smcFunc['htmlspecialchars'](trim($_POST['ruledef'][$ind])));
3948
+			}
3798 3949
 		}
3799 3950
 
3800 3951
 		// Also do the actions!
@@ -3804,26 +3955,29 @@  discard block
 block discarded – undo
3804 3955
 		foreach ($_POST['acttype'] as $ind => $type)
3805 3956
 		{
3806 3957
 			// Picking a valid label?
3807
-			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]])))
3808
-				continue;
3958
+			if ($type == 'lab' && (!isset($_POST['labdef'][$ind]) || !isset($context['labels'][$_POST['labdef'][$ind]]))) {
3959
+							continue;
3960
+			}
3809 3961
 
3810 3962
 			// Record what we're doing.
3811
-			if ($type == 'del')
3812
-				$doDelete = 1;
3813
-			elseif ($type == 'lab')
3814
-				$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3963
+			if ($type == 'del') {
3964
+							$doDelete = 1;
3965
+			} elseif ($type == 'lab') {
3966
+							$actions[] = array('t' => 'lab', 'v' => (int) $_POST['labdef'][$ind]);
3967
+			}
3815 3968
 		}
3816 3969
 
3817
-		if (empty($criteria) || (empty($actions) && !$doDelete))
3818
-			fatal_lang_error('pm_rule_no_criteria', false);
3970
+		if (empty($criteria) || (empty($actions) && !$doDelete)) {
3971
+					fatal_lang_error('pm_rule_no_criteria', false);
3972
+		}
3819 3973
 
3820 3974
 		// What are we storing?
3821 3975
 		$criteria = $smcFunc['json_encode']($criteria);
3822 3976
 		$actions = $smcFunc['json_encode']($actions);
3823 3977
 
3824 3978
 		// Create the rule?
3825
-		if (empty($context['rid']))
3826
-			$smcFunc['db_insert']('',
3979
+		if (empty($context['rid'])) {
3980
+					$smcFunc['db_insert']('',
3827 3981
 				'{db_prefix}pm_rules',
3828 3982
 				array(
3829 3983
 					'id_member' => 'int', 'rule_name' => 'string', 'criteria' => 'string', 'actions' => 'string',
@@ -3833,9 +3987,9 @@  discard block
 block discarded – undo
3833 3987
 					$user_info['id'], $ruleName, $criteria, $actions, $doDelete, $isOr,
3834 3988
 				),
3835 3989
 				array('id_rule')
3836
-			);
3837
-		else
3838
-			$smcFunc['db_query']('', '
3990
+			);
3991
+		} else {
3992
+					$smcFunc['db_query']('', '
3839 3993
 				UPDATE {db_prefix}pm_rules
3840 3994
 				SET rule_name = {string:rule_name}, criteria = {string:criteria}, actions = {string:actions},
3841 3995
 					delete_pm = {int:delete_pm}, is_or = {int:is_or}
@@ -3850,7 +4004,8 @@  discard block
 block discarded – undo
3850 4004
 					'criteria' => $criteria,
3851 4005
 					'actions' => $actions,
3852 4006
 				)
3853
-			);
4007
+			);
4008
+		}
3854 4009
 
3855 4010
 		redirectexit('action=pm;sa=manrules');
3856 4011
 	}
@@ -3859,11 +4014,12 @@  discard block
 block discarded – undo
3859 4014
 	{
3860 4015
 		checkSession();
3861 4016
 		$toDelete = array();
3862
-		foreach ($_POST['delrule'] as $k => $v)
3863
-			$toDelete[] = (int) $k;
4017
+		foreach ($_POST['delrule'] as $k => $v) {
4018
+					$toDelete[] = (int) $k;
4019
+		}
3864 4020
 
3865
-		if (!empty($toDelete))
3866
-			$smcFunc['db_query']('', '
4021
+		if (!empty($toDelete)) {
4022
+					$smcFunc['db_query']('', '
3867 4023
 				DELETE FROM {db_prefix}pm_rules
3868 4024
 				WHERE id_rule IN ({array_int:delete_list})
3869 4025
 					AND id_member = {int:current_member}',
@@ -3871,7 +4027,8 @@  discard block
 block discarded – undo
3871 4027
 					'current_member' => $user_info['id'],
3872 4028
 					'delete_list' => $toDelete,
3873 4029
 				)
3874
-			);
4030
+			);
4031
+		}
3875 4032
 
3876 4033
 		redirectexit('action=pm;sa=manrules');
3877 4034
 	}
@@ -3890,8 +4047,9 @@  discard block
 block discarded – undo
3890 4047
 	loadRules();
3891 4048
 
3892 4049
 	// No rules?
3893
-	if (empty($context['rules']))
3894
-		return;
4050
+	if (empty($context['rules'])) {
4051
+			return;
4052
+	}
3895 4053
 
3896 4054
 	// Just unread ones?
3897 4055
 	$ruleQuery = $all_messages ? '' : ' AND pmr.is_new = 1';
@@ -3921,8 +4079,9 @@  discard block
 block discarded – undo
3921 4079
 			// Loop through all the criteria hoping to make a match.
3922 4080
 			foreach ($rule['criteria'] as $criterium)
3923 4081
 			{
3924
-				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false))
3925
-					$match = true;
4082
+				if (($criterium['t'] == 'mid' && $criterium['v'] == $row['id_member_from']) || ($criterium['t'] == 'gid' && $criterium['v'] == $row['id_group']) || ($criterium['t'] == 'sub' && strpos($row['subject'], $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($row['body'], $criterium['v']) !== false)) {
4083
+									$match = true;
4084
+				}
3926 4085
 				// If we're adding and one criteria don't match then we stop!
3927 4086
 				elseif ($rule['logic'] == 'and')
3928 4087
 				{
@@ -3934,17 +4093,18 @@  discard block
 block discarded – undo
3934 4093
 			// If we have a match the rule must be true - act!
3935 4094
 			if ($match)
3936 4095
 			{
3937
-				if ($rule['delete'])
3938
-					$actions['deletes'][] = $row['id_pm'];
3939
-				else
4096
+				if ($rule['delete']) {
4097
+									$actions['deletes'][] = $row['id_pm'];
4098
+				} else
3940 4099
 				{
3941 4100
 					foreach ($rule['actions'] as $ruleAction)
3942 4101
 					{
3943 4102
 						if ($ruleAction['t'] == 'lab')
3944 4103
 						{
3945 4104
 							// Get a basic pot started!
3946
-							if (!isset($actions['labels'][$row['id_pm']]))
3947
-								$actions['labels'][$row['id_pm']] = array();
4105
+							if (!isset($actions['labels'][$row['id_pm']])) {
4106
+															$actions['labels'][$row['id_pm']] = array();
4107
+							}
3948 4108
 							$actions['labels'][$row['id_pm']][] = $ruleAction['v'];
3949 4109
 						}
3950 4110
 					}
@@ -3955,8 +4115,9 @@  discard block
 block discarded – undo
3955 4115
 	$smcFunc['db_free_result']($request);
3956 4116
 
3957 4117
 	// Deletes are easy!
3958
-	if (!empty($actions['deletes']))
3959
-		deleteMessages($actions['deletes']);
4118
+	if (!empty($actions['deletes'])) {
4119
+			deleteMessages($actions['deletes']);
4120
+	}
3960 4121
 
3961 4122
 	// Relabel?
3962 4123
 	if (!empty($actions['labels']))
@@ -3983,8 +4144,7 @@  discard block
 block discarded – undo
3983 4144
 								'current_member' => $user_info['id'],
3984 4145
 							)
3985 4146
 						);
3986
-					}
3987
-					else
4147
+					} else
3988 4148
 					{
3989 4149
 						$realLabels[] = $label['id'];
3990 4150
 					}
@@ -3993,8 +4153,9 @@  discard block
 block discarded – undo
3993 4153
 
3994 4154
 			$inserts = array();
3995 4155
 			// Now we insert the label info
3996
-			foreach ($realLabels as $a_label)
3997
-				$inserts[] = array($pm, $a_label);
4156
+			foreach ($realLabels as $a_label) {
4157
+							$inserts[] = array($pm, $a_label);
4158
+			}
3998 4159
 
3999 4160
 			$smcFunc['db_insert']('ignore',
4000 4161
 				'{db_prefix}pm_labeled_messages',
@@ -4015,8 +4176,9 @@  discard block
 block discarded – undo
4015 4176
 {
4016 4177
 	global $user_info, $context, $smcFunc;
4017 4178
 
4018
-	if (isset($context['rules']) && !$reload)
4019
-		return;
4179
+	if (isset($context['rules']) && !$reload) {
4180
+			return;
4181
+	}
4020 4182
 
4021 4183
 	$request = $smcFunc['db_query']('', '
4022 4184
 		SELECT
@@ -4040,8 +4202,9 @@  discard block
 block discarded – undo
4040 4202
 			'logic' => $row['is_or'] ? 'or' : 'and',
4041 4203
 		);
4042 4204
 
4043
-		if ($row['delete_pm'])
4044
-			$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4205
+		if ($row['delete_pm']) {
4206
+					$context['rules'][$row['id_rule']]['actions'][] = array('t' => 'del', 'v' => 1);
4207
+		}
4045 4208
 	}
4046 4209
 	$smcFunc['db_free_result']($request);
4047 4210
 }
Please login to merge, or discard this patch.
Sources/Notify.php 1 patch
Braces   +20 added lines, -18 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Turn off/on notification for a particular board.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	is_not_guest();
35 36
 
36 37
 	// You have to specify a board to turn notifications on!
37
-	if (empty($board))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($board)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// No subaction: find out what to do.
41 43
 	if (isset($_GET['mode']))
@@ -48,16 +50,16 @@  discard block
 block discarded – undo
48 50
 		require_once($sourcedir . '/Subs-Notify.php');
49 51
 		setNotifyPrefs($user_info['id'], array('board_notify_' . $board => $alertPref));
50 52
 
51
-		if ($mode > 1)
52
-			// Turn notification on.  (note this just blows smoke if it's already on.)
53
+		if ($mode > 1) {
54
+					// Turn notification on.  (note this just blows smoke if it's already on.)
53 55
 			$smcFunc['db_insert']('ignore',
54 56
 				'{db_prefix}log_notify',
55 57
 				array('id_member' => 'int', 'id_board' => 'int'),
56 58
 				array($user_info['id'], $board),
57 59
 				array('id_member', 'id_board')
58 60
 			);
59
-		else
60
-			$smcFunc['db_query']('', '
61
+		} else {
62
+					$smcFunc['db_query']('', '
61 63
 				DELETE FROM {db_prefix}log_notify
62 64
 				WHERE id_member = {int:current_member}
63 65
 				AND id_board = {int:current_board}',
@@ -66,6 +68,7 @@  discard block
 block discarded – undo
66 68
 					'current_member' => $user_info['id'],
67 69
 				)
68 70
 			);
71
+		}
69 72
 	}
70 73
 
71 74
 	// Back to the board!
@@ -80,10 +83,10 @@  discard block
 block discarded – undo
80 83
 			),
81 84
 		);
82 85
 		$context['sub_template'] = 'generic_xml';
86
+	} else {
87
+			redirectexit('board=' . $board . '.' . $_REQUEST['start']);
88
+	}
83 89
 	}
84
-	else
85
-		redirectexit('board=' . $board . '.' . $_REQUEST['start']);
86
-}
87 90
 
88 91
 /**
89 92
  * Turn off/on unread replies subscription for a topic as well as sets individual topic's alert preferences
@@ -128,8 +131,7 @@  discard block
 block discarded – undo
128 131
 					'id_msg' => 0,
129 132
 					'unwatched' => empty($mode) ? 1 : 0,
130 133
 				);
131
-			}
132
-			else
134
+			} else
133 135
 			{
134 136
 				$insert = false;
135 137
 				$log['unwatched'] = empty($mode) ? 1 : 0;
@@ -156,9 +158,8 @@  discard block
 block discarded – undo
156 158
 					array($user_info['id'], $log['id_topic']),
157 159
 					array('id_member', 'id_board')
158 160
 				);
159
-			}
160
-			else
161
-				$smcFunc['db_query']('', '
161
+			} else {
162
+							$smcFunc['db_query']('', '
162 163
 					DELETE FROM {db_prefix}log_notify
163 164
 					WHERE id_topic = {int:topic}
164 165
 						AND id_member = {int:member}',
@@ -166,6 +167,7 @@  discard block
 block discarded – undo
166 167
 						'topic' => $log['id_topic'],
167 168
 						'member' => $user_info['id'],
168 169
 					));
170
+			}
169 171
 		}
170 172
 	}
171 173
 
@@ -181,9 +183,9 @@  discard block
 block discarded – undo
181 183
 			),
182 184
 		);
183 185
 		$context['sub_template'] = 'generic_xml';
186
+	} else {
187
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
188
+	}
184 189
 	}
185
-	else
186
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
187
-}
188 190
 
189 191
 ?>
190 192
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1471 added lines, -1100 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,24 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-
195
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
196 199
 			{
197 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
198 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -213,8 +216,9 @@  discard block
 block discarded – undo
213 216
 
214 217
 		case 'postgroups':
215 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
216
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
217
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
218 222
 
219 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
220 224
 			if ($postgroups == null || $parameter1 == null)
@@ -229,8 +233,9 @@  discard block
 block discarded – undo
229 233
 					)
230 234
 				);
231 235
 				$postgroups = array();
232
-				while ($row = $smcFunc['db_fetch_assoc']($request))
233
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
234 239
 
235 240
 				$smcFunc['db_free_result']($request);
236 241
 
@@ -241,8 +246,9 @@  discard block
 block discarded – undo
241 246
 			}
242 247
 
243 248
 			// Oh great, they've screwed their post groups.
244
-			if (empty($postgroups))
245
-				return;
249
+			if (empty($postgroups)) {
250
+							return;
251
+			}
246 252
 
247 253
 			// Set all membergroups from most posts to least posts.
248 254
 			$conditions = '';
@@ -301,12 +307,9 @@  discard block
 block discarded – undo
301 307
 	{
302 308
 		$condition = 'id_member IN ({array_int:members})';
303 309
 		$parameters['members'] = $members;
304
-	}
305
-
306
-	elseif ($members === null)
307
-		$condition = '1=1';
308
-
309
-	else
310
+	} elseif ($members === null) {
311
+			$condition = '1=1';
312
+	} else
310 313
 	{
311 314
 		$condition = 'id_member = {int:member}';
312 315
 		$parameters['member'] = $members;
@@ -346,9 +349,9 @@  discard block
 block discarded – undo
346 349
 		if (count($vars_to_integrate) != 0)
347 350
 		{
348 351
 			// Fetch a list of member_names if necessary
349
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
350
-				$member_names = array($user_info['username']);
351
-			else
352
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
353
+							$member_names = array($user_info['username']);
354
+			} else
352 355
 			{
353 356
 				$member_names = array();
354 357
 				$request = $smcFunc['db_query']('', '
@@ -357,14 +360,16 @@  discard block
 block discarded – undo
357 360
 					WHERE ' . $condition,
358 361
 					$parameters
359 362
 				);
360
-				while ($row = $smcFunc['db_fetch_assoc']($request))
361
-					$member_names[] = $row['member_name'];
363
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
364
+									$member_names[] = $row['member_name'];
365
+				}
362 366
 				$smcFunc['db_free_result']($request);
363 367
 			}
364 368
 
365
-			if (!empty($member_names))
366
-				foreach ($vars_to_integrate as $var)
369
+			if (!empty($member_names)) {
370
+							foreach ($vars_to_integrate as $var)
367 371
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
372
+			}
368 373
 		}
369 374
 	}
370 375
 
@@ -372,16 +377,17 @@  discard block
 block discarded – undo
372 377
 	foreach ($data as $var => $val)
373 378
 	{
374 379
 		$type = 'string';
375
-		if (in_array($var, $knownInts))
376
-			$type = 'int';
377
-		elseif (in_array($var, $knownFloats))
378
-			$type = 'float';
379
-		elseif ($var == 'birthdate')
380
-			$type = 'date';
381
-		elseif ($var == 'member_ip')
382
-			$type = 'inet';
383
-		elseif ($var == 'member_ip2')
384
-			$type = 'inet';
380
+		if (in_array($var, $knownInts)) {
381
+					$type = 'int';
382
+		} elseif (in_array($var, $knownFloats)) {
383
+					$type = 'float';
384
+		} elseif ($var == 'birthdate') {
385
+					$type = 'date';
386
+		} elseif ($var == 'member_ip') {
387
+					$type = 'inet';
388
+		} elseif ($var == 'member_ip2') {
389
+					$type = 'inet';
390
+		}
385 391
 
386 392
 		// Doing an increment?
387 393
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -390,18 +396,17 @@  discard block
 block discarded – undo
390 396
 			if (is_array($members))
391 397
 			{
392 398
 				$val = 'CASE ';
393
-				foreach ($members as $k => $v)
394
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				foreach ($members as $k => $v) {
400
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
401
+				}
395 402
 				$val = $val . ' END';
396 403
 				$type = 'raw';
397
-			}
398
-			else
404
+			} else
399 405
 			{
400 406
 				$blub = fetch_alerts($members, false, 0, array(), false);
401 407
 				$val = count($blub);
402 408
 			}
403
-		}
404
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
409
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
405 410
 		{
406 411
 			$val = $var . ' ' . $val . ' 1';
407 412
 			$type = 'raw';
@@ -412,8 +417,9 @@  discard block
 block discarded – undo
412 417
 		{
413 418
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
414 419
 			{
415
-				if ($match[1] != '+ ')
416
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				if ($match[1] != '+ ') {
421
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
422
+				}
417 423
 				$type = 'raw';
418 424
 			}
419 425
 		}
@@ -434,8 +440,9 @@  discard block
 block discarded – undo
434 440
 	// Clear any caching?
435 441
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
436 442
 	{
437
-		if (!is_array($members))
438
-			$members = array($members);
443
+		if (!is_array($members)) {
444
+					$members = array($members);
445
+		}
439 446
 
440 447
 		foreach ($members as $member)
441 448
 		{
@@ -468,29 +475,32 @@  discard block
 block discarded – undo
468 475
 {
469 476
 	global $modSettings, $smcFunc;
470 477
 
471
-	if (empty($changeArray) || !is_array($changeArray))
472
-		return;
478
+	if (empty($changeArray) || !is_array($changeArray)) {
479
+			return;
480
+	}
473 481
 
474 482
 	$toRemove = array();
475 483
 
476 484
 	// Go check if there is any setting to be removed.
477
-	foreach ($changeArray as $k => $v)
478
-		if ($v === null)
485
+	foreach ($changeArray as $k => $v) {
486
+			if ($v === null)
479 487
 		{
480 488
 			// Found some, remove them from the original array and add them to ours.
481 489
 			unset($changeArray[$k]);
490
+	}
482 491
 			$toRemove[] = $k;
483 492
 		}
484 493
 
485 494
 	// Proceed with the deletion.
486
-	if (!empty($toRemove))
487
-		$smcFunc['db_query']('', '
495
+	if (!empty($toRemove)) {
496
+			$smcFunc['db_query']('', '
488 497
 			DELETE FROM {db_prefix}settings
489 498
 			WHERE variable IN ({array_string:remove})',
490 499
 			array(
491 500
 				'remove' => $toRemove,
492 501
 			)
493 502
 		);
503
+	}
494 504
 
495 505
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
496 506
 	if ($update)
@@ -519,19 +529,22 @@  discard block
 block discarded – undo
519 529
 	foreach ($changeArray as $variable => $value)
520 530
 	{
521 531
 		// Don't bother if it's already like that ;).
522
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
523
-			continue;
532
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
533
+					continue;
534
+		}
524 535
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
525
-		elseif (!isset($modSettings[$variable]) && empty($value))
526
-			continue;
536
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
537
+					continue;
538
+		}
527 539
 
528 540
 		$replaceArray[] = array($variable, $value);
529 541
 
530 542
 		$modSettings[$variable] = $value;
531 543
 	}
532 544
 
533
-	if (empty($replaceArray))
534
-		return;
545
+	if (empty($replaceArray)) {
546
+			return;
547
+	}
535 548
 
536 549
 	$smcFunc['db_insert']('replace',
537 550
 		'{db_prefix}settings',
@@ -577,14 +590,17 @@  discard block
 block discarded – undo
577 590
 	$start_invalid = $start < 0;
578 591
 
579 592
 	// Make sure $start is a proper variable - not less than 0.
580
-	if ($start_invalid)
581
-		$start = 0;
593
+	if ($start_invalid) {
594
+			$start = 0;
595
+	}
582 596
 	// Not greater than the upper bound.
583
-	elseif ($start >= $max_value)
584
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
597
+	elseif ($start >= $max_value) {
598
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
599
+	}
585 600
 	// And it has to be a multiple of $num_per_page!
586
-	else
587
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	else {
602
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
603
+	}
588 604
 
589 605
 	$context['current_page'] = $start / $num_per_page;
590 606
 
@@ -614,77 +630,87 @@  discard block
 block discarded – undo
614 630
 
615 631
 		// Show all the pages.
616 632
 		$display_page = 1;
617
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
618
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
634
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
635
+		}
619 636
 
620 637
 		// Show the right arrow.
621 638
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
622
-		if ($start != $counter - $max_value && !$start_invalid)
623
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
624
-	}
625
-	else
639
+		if ($start != $counter - $max_value && !$start_invalid) {
640
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
641
+		}
642
+	} else
626 643
 	{
627 644
 		// If they didn't enter an odd value, pretend they did.
628 645
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
629 646
 
630 647
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
631
-		if (!empty($start) && $show_prevnext)
632
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
633
-		else
634
-			$pageindex .= '';
648
+		if (!empty($start) && $show_prevnext) {
649
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
650
+		} else {
651
+					$pageindex .= '';
652
+		}
635 653
 
636 654
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
637
-		if ($start > $num_per_page * $PageContiguous)
638
-			$pageindex .= sprintf($base_link, 0, '1');
655
+		if ($start > $num_per_page * $PageContiguous) {
656
+					$pageindex .= sprintf($base_link, 0, '1');
657
+		}
639 658
 
640 659
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
641
-		if ($start > $num_per_page * ($PageContiguous + 1))
642
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
660
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
661
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
643 662
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
644 663
 				'{FIRST_PAGE}' => $num_per_page,
645 664
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
646 665
 				'{PER_PAGE}' => $num_per_page,
647 666
 			));
667
+		}
648 668
 
649 669
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
650
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
651
-			if ($start >= $num_per_page * $nCont)
670
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
671
+					if ($start >= $num_per_page * $nCont)
652 672
 			{
653 673
 				$tmpStart = $start - $num_per_page * $nCont;
674
+		}
654 675
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
655 676
 			}
656 677
 
657 678
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
658
-		if (!$start_invalid)
659
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
660
-		else
661
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
679
+		if (!$start_invalid) {
680
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
681
+		} else {
682
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
683
+		}
662 684
 
663 685
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
664 686
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
665
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
666
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
687
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
688
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
667 689
 			{
668 690
 				$tmpStart = $start + $num_per_page * $nCont;
691
+		}
669 692
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
670 693
 			}
671 694
 
672 695
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
673
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
674
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
696
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
697
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
675 698
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
676 699
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
677 700
 				'{LAST_PAGE}' => $tmpMaxPages,
678 701
 				'{PER_PAGE}' => $num_per_page,
679 702
 			));
703
+		}
680 704
 
681 705
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
682
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
683
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
707
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
708
+		}
684 709
 
685 710
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
686
-		if ($start != $tmpMaxPages && $show_prevnext)
687
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		if ($start != $tmpMaxPages && $show_prevnext) {
712
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
713
+		}
688 714
 	}
689 715
 	$pageindex .= $settings['page_index']['extra_after'];
690 716
 
@@ -710,8 +736,9 @@  discard block
 block discarded – undo
710 736
 	if ($decimal_separator === null)
711 737
 	{
712 738
 		// Not set for whatever reason?
713
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
714
-			return $number;
739
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
740
+					return $number;
741
+		}
715 742
 
716 743
 		// Cache these each load...
717 744
 		$thousands_separator = $matches[1];
@@ -752,17 +779,20 @@  discard block
 block discarded – undo
752 779
 	$user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M');
753 780
 
754 781
 	// Offset the time.
755
-	if (!$offset_type)
756
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
782
+	if (!$offset_type) {
783
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
784
+	}
757 785
 	// Just the forum offset?
758
-	elseif ($offset_type == 'forum')
759
-		$time = $log_time + $modSettings['time_offset'] * 3600;
760
-	else
761
-		$time = $log_time;
786
+	elseif ($offset_type == 'forum') {
787
+			$time = $log_time + $modSettings['time_offset'] * 3600;
788
+	} else {
789
+			$time = $log_time;
790
+	}
762 791
 
763 792
 	// We can't have a negative date (on Windows, at least.)
764
-	if ($log_time < 0)
765
-		$log_time = 0;
793
+	if ($log_time < 0) {
794
+			$log_time = 0;
795
+	}
766 796
 
767 797
 	// Today and Yesterday?
768 798
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -779,24 +809,27 @@  discard block
 block discarded – undo
779 809
 		{
780 810
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
781 811
 			$today_fmt = $h . ':%M' . $s . ' %p';
812
+		} else {
813
+					$today_fmt = '%H:%M' . $s;
782 814
 		}
783
-		else
784
-			$today_fmt = '%H:%M' . $s;
785 815
 
786 816
 		// Same day of the year, same year.... Today!
787
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
788
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
817
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
818
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
819
+		}
789 820
 
790 821
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
791
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
792
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
822
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
823
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
824
+		}
793 825
 	}
794 826
 
795 827
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
796 828
 
797 829
 	// Use the cached formats if available
798
-	if (is_null($finalizedFormats))
799
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
830
+	if (is_null($finalizedFormats)) {
831
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
832
+	}
800 833
 
801 834
 	// Make a supported version for this format if we don't already have one
802 835
 	if (empty($finalizedFormats[$str]))
@@ -825,8 +858,9 @@  discard block
 block discarded – undo
825 858
 		);
826 859
 
827 860
 		// No need to do this part again if we already did it once
828
-		if (is_null($unsupportedFormats))
829
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
861
+		if (is_null($unsupportedFormats)) {
862
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
863
+		}
830 864
 		if (empty($unsupportedFormats))
831 865
 		{
832 866
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -842,20 +876,23 @@  discard block
 block discarded – undo
842 876
 
843 877
 				// Windows will return false for unsupported formats
844 878
 				// Other operating systems return the format string as a literal
845
-				if ($value === false || $value === $format)
846
-					$unsupportedFormats[] = $format;
879
+				if ($value === false || $value === $format) {
880
+									$unsupportedFormats[] = $format;
881
+				}
847 882
 			}
848 883
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
849 884
 		}
850 885
 
851 886
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
852
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
853
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
887
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
888
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
889
+		}
854 890
 
855 891
 		// Substitute unsupported formats with supported ones
856
-		if (!empty($unsupportedFormats))
857
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
892
+		if (!empty($unsupportedFormats)) {
893
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
858 894
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
895
+		}
859 896
 
860 897
 		// Remember this so we don't need to do it again
861 898
 		$finalizedFormats[$str] = $timeformat;
@@ -864,33 +901,39 @@  discard block
 block discarded – undo
864 901
 
865 902
 	$str = $finalizedFormats[$str];
866 903
 
867
-	if (!isset($locale_cache))
868
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
904
+	if (!isset($locale_cache)) {
905
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
906
+	}
869 907
 
870 908
 	if ($locale_cache !== false)
871 909
 	{
872 910
 		// Check if another process changed the locale
873
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
874
-			setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
911
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
912
+					setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
913
+		}
875 914
 
876
-		if (!isset($non_twelve_hour))
877
-			$non_twelve_hour = trim(strftime('%p')) === '';
878
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
879
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
915
+		if (!isset($non_twelve_hour)) {
916
+					$non_twelve_hour = trim(strftime('%p')) === '';
917
+		}
918
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
919
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
920
+		}
880 921
 
881
-		foreach (array('%a', '%A', '%b', '%B') as $token)
882
-			if (strpos($str, $token) !== false)
922
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
923
+					if (strpos($str, $token) !== false)
883 924
 				$str = str_replace($token, strftime($token, $time), $str);
884
-	}
885
-	else
925
+		}
926
+	} else
886 927
 	{
887 928
 		// Do-it-yourself time localization.  Fun.
888
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
889
-			if (strpos($str, $token) !== false)
929
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
930
+					if (strpos($str, $token) !== false)
890 931
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
932
+		}
891 933
 
892
-		if (strpos($str, '%p') !== false)
893
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
934
+		if (strpos($str, '%p') !== false) {
935
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
936
+		}
894 937
 	}
895 938
 
896 939
 	// Format the time and then restore any literal percent characters
@@ -913,16 +956,19 @@  discard block
 block discarded – undo
913 956
 	static $translation = array();
914 957
 
915 958
 	// Determine the character set... Default to UTF-8
916
-	if (empty($context['character_set']))
917
-		$charset = 'UTF-8';
959
+	if (empty($context['character_set'])) {
960
+			$charset = 'UTF-8';
961
+	}
918 962
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
919
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
920
-		$charset = 'ISO-8859-1';
921
-	else
922
-		$charset = $context['character_set'];
963
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
964
+			$charset = 'ISO-8859-1';
965
+	} else {
966
+			$charset = $context['character_set'];
967
+	}
923 968
 
924
-	if (empty($translation))
925
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
969
+	if (empty($translation)) {
970
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
971
+	}
926 972
 
927 973
 	return strtr($string, $translation);
928 974
 }
@@ -944,8 +990,9 @@  discard block
 block discarded – undo
944 990
 	global $smcFunc;
945 991
 
946 992
 	// It was already short enough!
947
-	if ($smcFunc['strlen']($subject) <= $len)
948
-		return $subject;
993
+	if ($smcFunc['strlen']($subject) <= $len) {
994
+			return $subject;
995
+	}
949 996
 
950 997
 	// Shorten it by the length it was too long, and strip off junk from the end.
951 998
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -964,10 +1011,11 @@  discard block
 block discarded – undo
964 1011
 {
965 1012
 	global $user_info, $modSettings;
966 1013
 
967
-	if ($timestamp === null)
968
-		$timestamp = time();
969
-	elseif ($timestamp == 0)
970
-		return 0;
1014
+	if ($timestamp === null) {
1015
+			$timestamp = time();
1016
+	} elseif ($timestamp == 0) {
1017
+			return 0;
1018
+	}
971 1019
 
972 1020
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
973 1021
 }
@@ -996,8 +1044,9 @@  discard block
 block discarded – undo
996 1044
 		$array[$i] = $array[$j];
997 1045
 		$array[$j] = $temp;
998 1046
 
999
-		for ($i = 1; $p[$i] == 0; $i++)
1000
-			$p[$i] = 1;
1047
+		for ($i = 1; $p[$i] == 0; $i++) {
1048
+					$p[$i] = 1;
1049
+		}
1001 1050
 
1002 1051
 		$orders[] = $array;
1003 1052
 	}
@@ -1029,12 +1078,14 @@  discard block
 block discarded – undo
1029 1078
 	static $disabled;
1030 1079
 
1031 1080
 	// Don't waste cycles
1032
-	if ($message === '')
1033
-		return '';
1081
+	if ($message === '') {
1082
+			return '';
1083
+	}
1034 1084
 
1035 1085
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1036
-	if (!isset($context['utf8']))
1037
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1086
+	if (!isset($context['utf8'])) {
1087
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1088
+	}
1038 1089
 
1039 1090
 	// Clean up any cut/paste issues we may have
1040 1091
 	$message = sanitizeMSCutPaste($message);
@@ -1046,13 +1097,15 @@  discard block
 block discarded – undo
1046 1097
 		return $message;
1047 1098
 	}
1048 1099
 
1049
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1050
-		$smileys = (bool) $smileys;
1100
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1101
+			$smileys = (bool) $smileys;
1102
+	}
1051 1103
 
1052 1104
 	if (empty($modSettings['enableBBC']) && $message !== false)
1053 1105
 	{
1054
-		if ($smileys === true)
1055
-			parsesmileys($message);
1106
+		if ($smileys === true) {
1107
+					parsesmileys($message);
1108
+		}
1056 1109
 
1057 1110
 		return $message;
1058 1111
 	}
@@ -1065,8 +1118,9 @@  discard block
 block discarded – undo
1065 1118
 	}
1066 1119
 
1067 1120
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1068
-	if (!empty($modSettings['autoLinkUrls']))
1069
-		set_tld_regex();
1121
+	if (!empty($modSettings['autoLinkUrls'])) {
1122
+			set_tld_regex();
1123
+	}
1070 1124
 
1071 1125
 	// Allow mods access before entering the main parse_bbc loop
1072 1126
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1080,8 +1134,9 @@  discard block
 block discarded – undo
1080 1134
 
1081 1135
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1082 1136
 
1083
-			foreach ($temp as $tag)
1084
-				$disabled[trim($tag)] = true;
1137
+			foreach ($temp as $tag) {
1138
+							$disabled[trim($tag)] = true;
1139
+			}
1085 1140
 		}
1086 1141
 
1087 1142
 		/* The following bbc are formatted as an array, with keys as follows:
@@ -1211,8 +1266,9 @@  discard block
 block discarded – undo
1211 1266
 					$returnContext = '';
1212 1267
 
1213 1268
 					// BBC or the entire attachments feature is disabled
1214
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1215
-						return $data;
1269
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1270
+											return $data;
1271
+					}
1216 1272
 
1217 1273
 					// Save the attach ID.
1218 1274
 					$attachID = $data;
@@ -1223,8 +1279,9 @@  discard block
 block discarded – undo
1223 1279
 					$currentAttachment = parseAttachBBC($attachID);
1224 1280
 
1225 1281
 					// parseAttachBBC will return a string ($txt key) rather than dying with a fatal_error. Up to you to decide what to do.
1226
-					if (is_string($currentAttachment))
1227
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1282
+					if (is_string($currentAttachment)) {
1283
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1284
+					}
1228 1285
 
1229 1286
 					if (!empty($currentAttachment['is_image']))
1230 1287
 					{
@@ -1240,15 +1297,17 @@  discard block
 block discarded – undo
1240 1297
 							$height = ' height="' . $currentAttachment['height'] . '"';
1241 1298
 						}
1242 1299
 
1243
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1244
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1245
-						else
1246
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1300
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1301
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1302
+						} else {
1303
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1304
+						}
1247 1305
 					}
1248 1306
 
1249 1307
 					// No image. Show a link.
1250
-					else
1251
-						$returnContext .= $currentAttachment['link'];
1308
+					else {
1309
+											$returnContext .= $currentAttachment['link'];
1310
+					}
1252 1311
 
1253 1312
 					// Gotta append what we just did.
1254 1313
 					$data = $returnContext;
@@ -1302,8 +1361,9 @@  discard block
 block discarded – undo
1302 1361
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1303 1362
 						{
1304 1363
 							// Do PHP code coloring?
1305
-							if ($php_parts[$php_i] != '&lt;?php')
1306
-								continue;
1364
+							if ($php_parts[$php_i] != '&lt;?php') {
1365
+															continue;
1366
+							}
1307 1367
 
1308 1368
 							$php_string = '';
1309 1369
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1319,8 +1379,9 @@  discard block
 block discarded – undo
1319 1379
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1320 1380
 
1321 1381
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1322
-						if ($context['browser']['is_opera'])
1323
-							$data .= '&nbsp;';
1382
+						if ($context['browser']['is_opera']) {
1383
+													$data .= '&nbsp;';
1384
+						}
1324 1385
 					}
1325 1386
 				},
1326 1387
 				'block_level' => true,
@@ -1339,8 +1400,9 @@  discard block
 block discarded – undo
1339 1400
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1340 1401
 						{
1341 1402
 							// Do PHP code coloring?
1342
-							if ($php_parts[$php_i] != '&lt;?php')
1343
-								continue;
1403
+							if ($php_parts[$php_i] != '&lt;?php') {
1404
+															continue;
1405
+							}
1344 1406
 
1345 1407
 							$php_string = '';
1346 1408
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1356,8 +1418,9 @@  discard block
 block discarded – undo
1356 1418
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1357 1419
 
1358 1420
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1359
-						if ($context['browser']['is_opera'])
1360
-							$data[0] .= '&nbsp;';
1421
+						if ($context['browser']['is_opera']) {
1422
+													$data[0] .= '&nbsp;';
1423
+						}
1361 1424
 					}
1362 1425
 				},
1363 1426
 				'block_level' => true,
@@ -1398,10 +1461,11 @@  discard block
 block discarded – undo
1398 1461
 				{
1399 1462
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1400 1463
 
1401
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1402
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1403
-					else
1404
-						$css = '';
1464
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1465
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1466
+					} else {
1467
+											$css = '';
1468
+					}
1405 1469
 
1406 1470
 					$data = $class . $css;
1407 1471
 				},
@@ -1416,8 +1480,9 @@  discard block
 block discarded – undo
1416 1480
 				{
1417 1481
 					$data = strtr($data, array('<br />' => ''));
1418 1482
 
1419
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1420
-						$data = 'ftp://' . $data;
1483
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1484
+											$data = 'ftp://' . $data;
1485
+					}
1421 1486
 				},
1422 1487
 			),
1423 1488
 			array(
@@ -1427,8 +1492,9 @@  discard block
 block discarded – undo
1427 1492
 				'after' => '</a>',
1428 1493
 				'validate' => function(&$tag, &$data, $disabled)
1429 1494
 				{
1430
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1431
-						$data = 'ftp://' . $data;
1495
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1496
+											$data = 'ftp://' . $data;
1497
+					}
1432 1498
 				},
1433 1499
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1434 1500
 				'disabled_after' => ' ($1)',
@@ -1488,17 +1554,20 @@  discard block
 block discarded – undo
1488 1554
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1489 1555
 					if ($image_proxy_enabled)
1490 1556
 					{
1491
-						if (!empty($user_info['possibly_robot']))
1492
-							return;
1557
+						if (!empty($user_info['possibly_robot'])) {
1558
+													return;
1559
+						}
1493 1560
 
1494
-						if (empty($scheme))
1495
-							$data = 'http://' . ltrim($data, ':/');
1561
+						if (empty($scheme)) {
1562
+													$data = 'http://' . ltrim($data, ':/');
1563
+						}
1496 1564
 
1497
-						if ($scheme != 'https')
1498
-							$data = get_proxied_url($data);
1565
+						if ($scheme != 'https') {
1566
+													$data = get_proxied_url($data);
1567
+						}
1568
+					} elseif (empty($scheme)) {
1569
+											$data = '//' . ltrim($data, ':/');
1499 1570
 					}
1500
-					elseif (empty($scheme))
1501
-						$data = '//' . ltrim($data, ':/');
1502 1571
 				},
1503 1572
 				'disabled_content' => '($1)',
1504 1573
 			),
@@ -1514,17 +1583,20 @@  discard block
 block discarded – undo
1514 1583
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1515 1584
 					if ($image_proxy_enabled)
1516 1585
 					{
1517
-						if (!empty($user_info['possibly_robot']))
1518
-							return;
1586
+						if (!empty($user_info['possibly_robot'])) {
1587
+													return;
1588
+						}
1519 1589
 
1520
-						if (empty($scheme))
1521
-							$data = 'http://' . ltrim($data, ':/');
1590
+						if (empty($scheme)) {
1591
+													$data = 'http://' . ltrim($data, ':/');
1592
+						}
1522 1593
 
1523
-						if ($scheme != 'https')
1524
-							$data = get_proxied_url($data);
1594
+						if ($scheme != 'https') {
1595
+													$data = get_proxied_url($data);
1596
+						}
1597
+					} elseif (empty($scheme)) {
1598
+											$data = '//' . ltrim($data, ':/');
1525 1599
 					}
1526
-					elseif (empty($scheme))
1527
-						$data = '//' . ltrim($data, ':/');
1528 1600
 				},
1529 1601
 				'disabled_content' => '($1)',
1530 1602
 			),
@@ -1536,8 +1608,9 @@  discard block
 block discarded – undo
1536 1608
 				{
1537 1609
 					$data = strtr($data, array('<br>' => ''));
1538 1610
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1539
-					if (empty($scheme))
1540
-						$data = '//' . ltrim($data, ':/');
1611
+					if (empty($scheme)) {
1612
+											$data = '//' . ltrim($data, ':/');
1613
+					}
1541 1614
 				},
1542 1615
 			),
1543 1616
 			array(
@@ -1548,13 +1621,14 @@  discard block
 block discarded – undo
1548 1621
 				'after' => '</a>',
1549 1622
 				'validate' => function (&$tag, &$data, $disabled)
1550 1623
 				{
1551
-					if (substr($data, 0, 1) == '#')
1552
-						$data = '#post_' . substr($data, 1);
1553
-					else
1624
+					if (substr($data, 0, 1) == '#') {
1625
+											$data = '#post_' . substr($data, 1);
1626
+					} else
1554 1627
 					{
1555 1628
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1556
-						if (empty($scheme))
1557
-							$data = '//' . ltrim($data, ':/');
1629
+						if (empty($scheme)) {
1630
+													$data = '//' . ltrim($data, ':/');
1631
+						}
1558 1632
 					}
1559 1633
 				},
1560 1634
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1645,8 +1719,9 @@  discard block
 block discarded – undo
1645 1719
 					{
1646 1720
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1647 1721
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1648
-						if ($add_begin)
1649
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1722
+						if ($add_begin) {
1723
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1724
+						}
1650 1725
 					}
1651 1726
 				},
1652 1727
 				'block_level' => false,
@@ -1759,20 +1834,17 @@  discard block
 block discarded – undo
1759 1834
 					: function(&$tag, &$data, $disabled)
1760 1835
 					{
1761 1836
 
1762
-						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50))
1763
-							$data[1] = '0 -2px 1px';
1764
-
1765
-						elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100))
1766
-							$data[1] = '2px 0 1px';
1767
-
1768
-						elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190))
1769
-							$data[1] = '0 2px 1px';
1770
-
1771
-						elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280))
1772
-							$data[1] = '-2px 0 1px';
1773
-
1774
-						else
1775
-							$data[1] = '1px 1px 1px';
1837
+						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) {
1838
+													$data[1] = '0 -2px 1px';
1839
+						} elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) {
1840
+													$data[1] = '2px 0 1px';
1841
+						} elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) {
1842
+													$data[1] = '0 2px 1px';
1843
+						} elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) {
1844
+													$data[1] = '-2px 0 1px';
1845
+						} else {
1846
+													$data[1] = '1px 1px 1px';
1847
+						}
1776 1848
 					},
1777 1849
 			),
1778 1850
 			array(
@@ -1828,10 +1900,11 @@  discard block
 block discarded – undo
1828 1900
 				'content' => '$1',
1829 1901
 				'validate' => function (&$tag, &$data, $disabled)
1830 1902
 				{
1831
-					if (is_numeric($data))
1832
-						$data = timeformat($data);
1833
-					else
1834
-						$tag['content'] = '[time]$1[/time]';
1903
+					if (is_numeric($data)) {
1904
+											$data = timeformat($data);
1905
+					} else {
1906
+											$tag['content'] = '[time]$1[/time]';
1907
+					}
1835 1908
 				},
1836 1909
 			),
1837 1910
 			array(
@@ -1863,8 +1936,9 @@  discard block
 block discarded – undo
1863 1936
 				{
1864 1937
 					$data = strtr($data, array('<br>' => ''));
1865 1938
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1866
-					if (empty($scheme))
1867
-						$data = '//' . ltrim($data, ':/');
1939
+					if (empty($scheme)) {
1940
+											$data = '//' . ltrim($data, ':/');
1941
+					}
1868 1942
 				},
1869 1943
 			),
1870 1944
 			array(
@@ -1876,8 +1950,9 @@  discard block
 block discarded – undo
1876 1950
 				'validate' => function (&$tag, &$data, $disabled)
1877 1951
 				{
1878 1952
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1879
-					if (empty($scheme))
1880
-						$data = '//' . ltrim($data, ':/');
1953
+					if (empty($scheme)) {
1954
+											$data = '//' . ltrim($data, ':/');
1955
+					}
1881 1956
 				},
1882 1957
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1883 1958
 				'disabled_after' => ' ($1)',
@@ -1897,12 +1972,13 @@  discard block
 block discarded – undo
1897 1972
 		);
1898 1973
 
1899 1974
 		// Handle legacy bbc codes.
1900
-		foreach ($context['legacy_bbc'] as $bbc)
1901
-			$codes[] = array(
1975
+		foreach ($context['legacy_bbc'] as $bbc) {
1976
+					$codes[] = array(
1902 1977
 				'tag' => $bbc,
1903 1978
 				'before' => '',
1904 1979
 				'after' => '',
1905 1980
 			);
1981
+		}
1906 1982
 
1907 1983
 		// Let mods add new BBC without hassle.
1908 1984
 		call_integration_hook('integrate_bbc_codes', array(&$codes, &$no_autolink_tags));
@@ -1910,8 +1986,9 @@  discard block
 block discarded – undo
1910 1986
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1911 1987
 		if ($message === false)
1912 1988
 		{
1913
-			if (isset($temp_bbc))
1914
-				$bbc_codes = $temp_bbc;
1989
+			if (isset($temp_bbc)) {
1990
+							$bbc_codes = $temp_bbc;
1991
+			}
1915 1992
 			usort($codes, function ($a, $b) {
1916 1993
 				return strcmp($a['tag'], $b['tag']);
1917 1994
 			});
@@ -1931,8 +2008,9 @@  discard block
 block discarded – undo
1931 2008
 		);
1932 2009
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1933 2010
 		{
1934
-			foreach ($itemcodes as $c => $dummy)
1935
-				$bbc_codes[$c] = array();
2011
+			foreach ($itemcodes as $c => $dummy) {
2012
+							$bbc_codes[$c] = array();
2013
+			}
1936 2014
 		}
1937 2015
 
1938 2016
 		// Shhhh!
@@ -1953,12 +2031,14 @@  discard block
 block discarded – undo
1953 2031
 		foreach ($codes as $code)
1954 2032
 		{
1955 2033
 			// Make it easier to process parameters later
1956
-			if (!empty($code['parameters']))
1957
-				ksort($code['parameters'], SORT_STRING);
2034
+			if (!empty($code['parameters'])) {
2035
+							ksort($code['parameters'], SORT_STRING);
2036
+			}
1958 2037
 
1959 2038
 			// If we are not doing every tag only do ones we are interested in.
1960
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1961
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2039
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
2040
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2041
+			}
1962 2042
 		}
1963 2043
 		$codes = null;
1964 2044
 	}
@@ -1969,8 +2049,9 @@  discard block
 block discarded – undo
1969 2049
 		// It's likely this will change if the message is modified.
1970 2050
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1971 2051
 
1972
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1973
-			return $temp;
2052
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
2053
+					return $temp;
2054
+		}
1974 2055
 
1975 2056
 		$cache_t = microtime();
1976 2057
 	}
@@ -2002,8 +2083,9 @@  discard block
 block discarded – undo
2002 2083
 		$disabled['flash'] = true;
2003 2084
 
2004 2085
 		// @todo Change maybe?
2005
-		if (!isset($_GET['images']))
2006
-			$disabled['img'] = true;
2086
+		if (!isset($_GET['images'])) {
2087
+					$disabled['img'] = true;
2088
+		}
2007 2089
 
2008 2090
 		// @todo Interface/setting to add more?
2009 2091
 	}
@@ -2014,8 +2096,9 @@  discard block
 block discarded – undo
2014 2096
 	$alltags = array();
2015 2097
 	foreach ($bbc_codes as $section)
2016 2098
 	{
2017
-		foreach ($section as $code)
2018
-			$alltags[] = $code['tag'];
2099
+		foreach ($section as $code) {
2100
+					$alltags[] = $code['tag'];
2101
+		}
2019 2102
 	}
2020 2103
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
2021 2104
 
@@ -2027,8 +2110,9 @@  discard block
 block discarded – undo
2027 2110
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
2028 2111
 
2029 2112
 		// Failsafe.
2030
-		if ($pos === false || $last_pos > $pos)
2031
-			$pos = strlen($message) + 1;
2113
+		if ($pos === false || $last_pos > $pos) {
2114
+					$pos = strlen($message) + 1;
2115
+		}
2032 2116
 
2033 2117
 		// Can't have a one letter smiley, URL, or email! (sorry.)
2034 2118
 		if ($last_pos < $pos - 1)
@@ -2046,8 +2130,9 @@  discard block
 block discarded – undo
2046 2130
 
2047 2131
 				// <br> should be empty.
2048 2132
 				$empty_tags = array('br', 'hr');
2049
-				foreach ($empty_tags as $tag)
2050
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2133
+				foreach ($empty_tags as $tag) {
2134
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2135
+				}
2051 2136
 
2052 2137
 				// b, u, i, s, pre... basic tags.
2053 2138
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -2056,8 +2141,9 @@  discard block
 block discarded – undo
2056 2141
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
2057 2142
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
2058 2143
 
2059
-					if ($diff > 0)
2060
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2144
+					if ($diff > 0) {
2145
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2146
+					}
2061 2147
 				}
2062 2148
 
2063 2149
 				// Do <img ...> - with security... action= -> action-.
@@ -2070,8 +2156,9 @@  discard block
 block discarded – undo
2070 2156
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
2071 2157
 
2072 2158
 						// Remove action= from the URL - no funny business, now.
2073
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
2074
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2159
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2160
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2161
+						}
2075 2162
 
2076 2163
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
2077 2164
 					}
@@ -2086,16 +2173,18 @@  discard block
 block discarded – undo
2086 2173
 				$no_autolink_area = false;
2087 2174
 				if (!empty($open_tags))
2088 2175
 				{
2089
-					foreach ($open_tags as $open_tag)
2090
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2176
+					foreach ($open_tags as $open_tag) {
2177
+											if (in_array($open_tag['tag'], $no_autolink_tags))
2091 2178
 							$no_autolink_area = true;
2179
+					}
2092 2180
 				}
2093 2181
 
2094 2182
 				// Don't go backwards.
2095 2183
 				// @todo Don't think is the real solution....
2096 2184
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
2097
-				if ($pos < $lastAutoPos)
2098
-					$no_autolink_area = true;
2185
+				if ($pos < $lastAutoPos) {
2186
+									$no_autolink_area = true;
2187
+				}
2099 2188
 				$lastAutoPos = $pos;
2100 2189
 
2101 2190
 				if (!$no_autolink_area)
@@ -2200,29 +2289,33 @@  discard block
 block discarded – undo
2200 2289
 							$url = array_shift($matches);
2201 2290
 
2202 2291
 							// If this isn't a clean URL, bail out
2203
-							if ($url != sanitize_iri($url))
2204
-								return $url;
2292
+							if ($url != sanitize_iri($url)) {
2293
+															return $url;
2294
+							}
2205 2295
 
2206 2296
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2207 2297
 
2208 2298
 							if ($scheme == 'mailto')
2209 2299
 							{
2210 2300
 								$email_address = str_replace('mailto:', '', $url);
2211
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2212
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2213
-								else
2214
-									return $url;
2301
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2302
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2303
+								} else {
2304
+																	return $url;
2305
+								}
2215 2306
 							}
2216 2307
 
2217 2308
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2218
-							if (empty($scheme))
2219
-								$fullUrl = '//' . ltrim($url, ':/');
2220
-							else
2221
-								$fullUrl = $url;
2309
+							if (empty($scheme)) {
2310
+															$fullUrl = '//' . ltrim($url, ':/');
2311
+							} else {
2312
+															$fullUrl = $url;
2313
+							}
2222 2314
 
2223 2315
 							// Make sure that $fullUrl really is valid
2224
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2225
-								return $url;
2316
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2317
+															return $url;
2318
+							}
2226 2319
 
2227 2320
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2228 2321
 						}, $data);
@@ -2271,22 +2364,25 @@  discard block
 block discarded – undo
2271 2364
 		}
2272 2365
 
2273 2366
 		// Are we there yet?  Are we there yet?
2274
-		if ($pos >= strlen($message) - 1)
2275
-			break;
2367
+		if ($pos >= strlen($message) - 1) {
2368
+					break;
2369
+		}
2276 2370
 
2277 2371
 		$tags = strtolower($message[$pos + 1]);
2278 2372
 
2279 2373
 		if ($tags == '/' && !empty($open_tags))
2280 2374
 		{
2281 2375
 			$pos2 = strpos($message, ']', $pos + 1);
2282
-			if ($pos2 == $pos + 2)
2283
-				continue;
2376
+			if ($pos2 == $pos + 2) {
2377
+							continue;
2378
+			}
2284 2379
 
2285 2380
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2286 2381
 
2287 2382
 			// A closing tag that doesn't match any open tags? Skip it.
2288
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2289
-				continue;
2383
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2384
+							continue;
2385
+			}
2290 2386
 
2291 2387
 			$to_close = array();
2292 2388
 			$block_level = null;
@@ -2294,8 +2390,9 @@  discard block
 block discarded – undo
2294 2390
 			do
2295 2391
 			{
2296 2392
 				$tag = array_pop($open_tags);
2297
-				if (!$tag)
2298
-					break;
2393
+				if (!$tag) {
2394
+									break;
2395
+				}
2299 2396
 
2300 2397
 				if (!empty($tag['block_level']))
2301 2398
 				{
@@ -2309,10 +2406,11 @@  discard block
 block discarded – undo
2309 2406
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2310 2407
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2311 2408
 					{
2312
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2313
-							if ($temp['tag'] == $look_for)
2409
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2410
+													if ($temp['tag'] == $look_for)
2314 2411
 							{
2315 2412
 								$block_level = !empty($temp['block_level']);
2413
+						}
2316 2414
 								break;
2317 2415
 							}
2318 2416
 					}
@@ -2334,15 +2432,15 @@  discard block
 block discarded – undo
2334 2432
 			{
2335 2433
 				$open_tags = $to_close;
2336 2434
 				continue;
2337
-			}
2338
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2435
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2339 2436
 			{
2340 2437
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2341 2438
 				{
2342
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2343
-						if ($temp['tag'] == $look_for)
2439
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2440
+											if ($temp['tag'] == $look_for)
2344 2441
 						{
2345 2442
 							$block_level = !empty($temp['block_level']);
2443
+					}
2346 2444
 							break;
2347 2445
 						}
2348 2446
 				}
@@ -2350,8 +2448,9 @@  discard block
 block discarded – undo
2350 2448
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2351 2449
 				if (!$block_level)
2352 2450
 				{
2353
-					foreach ($to_close as $tag)
2354
-						array_push($open_tags, $tag);
2451
+					foreach ($to_close as $tag) {
2452
+											array_push($open_tags, $tag);
2453
+					}
2355 2454
 					continue;
2356 2455
 				}
2357 2456
 			}
@@ -2364,14 +2463,17 @@  discard block
 block discarded – undo
2364 2463
 
2365 2464
 				// See the comment at the end of the big loop - just eating whitespace ;).
2366 2465
 				$whitespace_regex = '';
2367
-				if (!empty($tag['block_level']))
2368
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2466
+				if (!empty($tag['block_level'])) {
2467
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2468
+				}
2369 2469
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2370
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2371
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2470
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2471
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2472
+				}
2372 2473
 
2373
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2374
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2474
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2475
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2476
+				}
2375 2477
 			}
2376 2478
 
2377 2479
 			if (!empty($to_close))
@@ -2384,8 +2486,9 @@  discard block
 block discarded – undo
2384 2486
 		}
2385 2487
 
2386 2488
 		// No tags for this character, so just keep going (fastest possible course.)
2387
-		if (!isset($bbc_codes[$tags]))
2388
-			continue;
2489
+		if (!isset($bbc_codes[$tags])) {
2490
+					continue;
2491
+		}
2389 2492
 
2390 2493
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2391 2494
 		$tag = null;
@@ -2394,48 +2497,57 @@  discard block
 block discarded – undo
2394 2497
 			$pt_strlen = strlen($possible['tag']);
2395 2498
 
2396 2499
 			// Not a match?
2397
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2398
-				continue;
2500
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2501
+							continue;
2502
+			}
2399 2503
 
2400 2504
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2401 2505
 
2402 2506
 			// A tag is the last char maybe
2403
-			if ($next_c == '')
2404
-				break;
2507
+			if ($next_c == '') {
2508
+							break;
2509
+			}
2405 2510
 
2406 2511
 			// A test validation?
2407
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2408
-				continue;
2512
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2513
+							continue;
2514
+			}
2409 2515
 			// Do we want parameters?
2410 2516
 			elseif (!empty($possible['parameters']))
2411 2517
 			{
2412
-				if ($next_c != ' ')
2413
-					continue;
2414
-			}
2415
-			elseif (isset($possible['type']))
2518
+				if ($next_c != ' ') {
2519
+									continue;
2520
+				}
2521
+			} elseif (isset($possible['type']))
2416 2522
 			{
2417 2523
 				// Do we need an equal sign?
2418
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2419
-					continue;
2524
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2525
+									continue;
2526
+				}
2420 2527
 				// Maybe we just want a /...
2421
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2422
-					continue;
2528
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2529
+									continue;
2530
+				}
2423 2531
 				// An immediate ]?
2424
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2425
-					continue;
2532
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2533
+									continue;
2534
+				}
2426 2535
 			}
2427 2536
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2428
-			elseif ($next_c != ']')
2429
-				continue;
2537
+			elseif ($next_c != ']') {
2538
+							continue;
2539
+			}
2430 2540
 
2431 2541
 			// Check allowed tree?
2432
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2433
-				continue;
2434
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2435
-				continue;
2542
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2543
+							continue;
2544
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2545
+							continue;
2546
+			}
2436 2547
 			// If this is in the list of disallowed child tags, don't parse it.
2437
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2438
-				continue;
2548
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2549
+							continue;
2550
+			}
2439 2551
 
2440 2552
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2441 2553
 
@@ -2447,8 +2559,9 @@  discard block
 block discarded – undo
2447 2559
 				foreach ($open_tags as $open_quote)
2448 2560
 				{
2449 2561
 					// Every parent quote this quote has flips the styling
2450
-					if ($open_quote['tag'] == 'quote')
2451
-						$quote_alt = !$quote_alt;
2562
+					if ($open_quote['tag'] == 'quote') {
2563
+											$quote_alt = !$quote_alt;
2564
+					}
2452 2565
 				}
2453 2566
 				// Add a class to the quote to style alternating blockquotes
2454 2567
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2459,8 +2572,9 @@  discard block
 block discarded – undo
2459 2572
 			{
2460 2573
 				// Build a regular expression for each parameter for the current tag.
2461 2574
 				$preg = array();
2462
-				foreach ($possible['parameters'] as $p => $info)
2463
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2575
+				foreach ($possible['parameters'] as $p => $info) {
2576
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2577
+				}
2464 2578
 
2465 2579
 				// Extract the string that potentially holds our parameters.
2466 2580
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2479,24 +2593,27 @@  discard block
 block discarded – undo
2479 2593
 
2480 2594
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2481 2595
 
2482
-					if ($match)
2483
-						$blob_counter = count($blobs) + 1;
2596
+					if ($match) {
2597
+											$blob_counter = count($blobs) + 1;
2598
+					}
2484 2599
 				}
2485 2600
 
2486 2601
 				// Didn't match our parameter list, try the next possible.
2487
-				if (!$match)
2488
-					continue;
2602
+				if (!$match) {
2603
+									continue;
2604
+				}
2489 2605
 
2490 2606
 				$params = array();
2491 2607
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2492 2608
 				{
2493 2609
 					$key = strtok(ltrim($matches[$i]), '=');
2494
-					if (isset($possible['parameters'][$key]['value']))
2495
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2496
-					elseif (isset($possible['parameters'][$key]['validate']))
2497
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2498
-					else
2499
-						$params['{' . $key . '}'] = $matches[$i + 1];
2610
+					if (isset($possible['parameters'][$key]['value'])) {
2611
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2612
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2613
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2614
+					} else {
2615
+											$params['{' . $key . '}'] = $matches[$i + 1];
2616
+					}
2500 2617
 
2501 2618
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2502 2619
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2504,23 +2621,26 @@  discard block
 block discarded – undo
2504 2621
 
2505 2622
 				foreach ($possible['parameters'] as $p => $info)
2506 2623
 				{
2507
-					if (!isset($params['{' . $p . '}']))
2508
-						$params['{' . $p . '}'] = '';
2624
+					if (!isset($params['{' . $p . '}'])) {
2625
+											$params['{' . $p . '}'] = '';
2626
+					}
2509 2627
 				}
2510 2628
 
2511 2629
 				$tag = $possible;
2512 2630
 
2513 2631
 				// Put the parameters into the string.
2514
-				if (isset($tag['before']))
2515
-					$tag['before'] = strtr($tag['before'], $params);
2516
-				if (isset($tag['after']))
2517
-					$tag['after'] = strtr($tag['after'], $params);
2518
-				if (isset($tag['content']))
2519
-					$tag['content'] = strtr($tag['content'], $params);
2632
+				if (isset($tag['before'])) {
2633
+									$tag['before'] = strtr($tag['before'], $params);
2634
+				}
2635
+				if (isset($tag['after'])) {
2636
+									$tag['after'] = strtr($tag['after'], $params);
2637
+				}
2638
+				if (isset($tag['content'])) {
2639
+									$tag['content'] = strtr($tag['content'], $params);
2640
+				}
2520 2641
 
2521 2642
 				$pos1 += strlen($given_param_string);
2522
-			}
2523
-			else
2643
+			} else
2524 2644
 			{
2525 2645
 				$tag = $possible;
2526 2646
 				$params = array();
@@ -2531,8 +2651,9 @@  discard block
 block discarded – undo
2531 2651
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2532 2652
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2533 2653
 		{
2534
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2535
-				continue;
2654
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2655
+							continue;
2656
+			}
2536 2657
 
2537 2658
 			$tag = $itemcodes[$message[$pos + 1]];
2538 2659
 
@@ -2553,9 +2674,9 @@  discard block
 block discarded – undo
2553 2674
 			{
2554 2675
 				array_pop($open_tags);
2555 2676
 				$code = '</li>';
2677
+			} else {
2678
+							$code = '';
2556 2679
 			}
2557
-			else
2558
-				$code = '';
2559 2680
 
2560 2681
 			// Now we open a new tag.
2561 2682
 			$open_tags[] = array(
@@ -2602,12 +2723,14 @@  discard block
 block discarded – undo
2602 2723
 		}
2603 2724
 
2604 2725
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2605
-		if ($tag === null)
2606
-			continue;
2726
+		if ($tag === null) {
2727
+					continue;
2728
+		}
2607 2729
 
2608 2730
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2609
-		if (isset($inside['disallow_children']))
2610
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2731
+		if (isset($inside['disallow_children'])) {
2732
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2733
+		}
2611 2734
 
2612 2735
 		// Is this tag disabled?
2613 2736
 		if (isset($disabled[$tag['tag']]))
@@ -2617,14 +2740,13 @@  discard block
 block discarded – undo
2617 2740
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2618 2741
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2619 2742
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2620
-			}
2621
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2743
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2622 2744
 			{
2623 2745
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2624 2746
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2747
+			} else {
2748
+							$tag['content'] = $tag['disabled_content'];
2625 2749
 			}
2626
-			else
2627
-				$tag['content'] = $tag['disabled_content'];
2628 2750
 		}
2629 2751
 
2630 2752
 		// we use this a lot
@@ -2634,8 +2756,9 @@  discard block
 block discarded – undo
2634 2756
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2635 2757
 		{
2636 2758
 			$n = count($open_tags) - 1;
2637
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2638
-				$n--;
2759
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2760
+							$n--;
2761
+			}
2639 2762
 
2640 2763
 			// Close all the non block level tags so this tag isn't surrounded by them.
2641 2764
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2647,12 +2770,15 @@  discard block
 block discarded – undo
2647 2770
 
2648 2771
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2649 2772
 				$whitespace_regex = '';
2650
-				if (!empty($tag['block_level']))
2651
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2652
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2653
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2654
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2655
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2773
+				if (!empty($tag['block_level'])) {
2774
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2775
+				}
2776
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2777
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2778
+				}
2779
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2780
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2781
+				}
2656 2782
 
2657 2783
 				array_pop($open_tags);
2658 2784
 			}
@@ -2673,16 +2799,19 @@  discard block
 block discarded – undo
2673 2799
 		elseif ($tag['type'] == 'unparsed_content')
2674 2800
 		{
2675 2801
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2676
-			if ($pos2 === false)
2677
-				continue;
2802
+			if ($pos2 === false) {
2803
+							continue;
2804
+			}
2678 2805
 
2679 2806
 			$data = substr($message, $pos1, $pos2 - $pos1);
2680 2807
 
2681
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2682
-				$data = substr($data, 4);
2808
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2809
+							$data = substr($data, 4);
2810
+			}
2683 2811
 
2684
-			if (isset($tag['validate']))
2685
-				$tag['validate']($tag, $data, $disabled, $params);
2812
+			if (isset($tag['validate'])) {
2813
+							$tag['validate']($tag, $data, $disabled, $params);
2814
+			}
2686 2815
 
2687 2816
 			$code = strtr($tag['content'], array('$1' => $data));
2688 2817
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2697,34 +2826,40 @@  discard block
 block discarded – undo
2697 2826
 			if (isset($tag['quoted']))
2698 2827
 			{
2699 2828
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2700
-				if ($tag['quoted'] != 'optional' && !$quoted)
2701
-					continue;
2829
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2830
+									continue;
2831
+				}
2702 2832
 
2703
-				if ($quoted)
2704
-					$pos1 += 6;
2833
+				if ($quoted) {
2834
+									$pos1 += 6;
2835
+				}
2836
+			} else {
2837
+							$quoted = false;
2705 2838
 			}
2706
-			else
2707
-				$quoted = false;
2708 2839
 
2709 2840
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2710
-			if ($pos2 === false)
2711
-				continue;
2841
+			if ($pos2 === false) {
2842
+							continue;
2843
+			}
2712 2844
 
2713 2845
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2714
-			if ($pos3 === false)
2715
-				continue;
2846
+			if ($pos3 === false) {
2847
+							continue;
2848
+			}
2716 2849
 
2717 2850
 			$data = array(
2718 2851
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2719 2852
 				substr($message, $pos1, $pos2 - $pos1)
2720 2853
 			);
2721 2854
 
2722
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2723
-				$data[0] = substr($data[0], 4);
2855
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2856
+							$data[0] = substr($data[0], 4);
2857
+			}
2724 2858
 
2725 2859
 			// Validation for my parking, please!
2726
-			if (isset($tag['validate']))
2727
-				$tag['validate']($tag, $data, $disabled, $params);
2860
+			if (isset($tag['validate'])) {
2861
+							$tag['validate']($tag, $data, $disabled, $params);
2862
+			}
2728 2863
 
2729 2864
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2730 2865
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2741,23 +2876,27 @@  discard block
 block discarded – undo
2741 2876
 		elseif ($tag['type'] == 'unparsed_commas_content')
2742 2877
 		{
2743 2878
 			$pos2 = strpos($message, ']', $pos1);
2744
-			if ($pos2 === false)
2745
-				continue;
2879
+			if ($pos2 === false) {
2880
+							continue;
2881
+			}
2746 2882
 
2747 2883
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2748
-			if ($pos3 === false)
2749
-				continue;
2884
+			if ($pos3 === false) {
2885
+							continue;
2886
+			}
2750 2887
 
2751 2888
 			// We want $1 to be the content, and the rest to be csv.
2752 2889
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2753 2890
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2754 2891
 
2755
-			if (isset($tag['validate']))
2756
-				$tag['validate']($tag, $data, $disabled, $params);
2892
+			if (isset($tag['validate'])) {
2893
+							$tag['validate']($tag, $data, $disabled, $params);
2894
+			}
2757 2895
 
2758 2896
 			$code = $tag['content'];
2759
-			foreach ($data as $k => $d)
2760
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2897
+			foreach ($data as $k => $d) {
2898
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2899
+			}
2761 2900
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2762 2901
 			$pos += strlen($code) - 1 + 2;
2763 2902
 		}
@@ -2765,24 +2904,28 @@  discard block
 block discarded – undo
2765 2904
 		elseif ($tag['type'] == 'unparsed_commas')
2766 2905
 		{
2767 2906
 			$pos2 = strpos($message, ']', $pos1);
2768
-			if ($pos2 === false)
2769
-				continue;
2907
+			if ($pos2 === false) {
2908
+							continue;
2909
+			}
2770 2910
 
2771 2911
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2772 2912
 
2773
-			if (isset($tag['validate']))
2774
-				$tag['validate']($tag, $data, $disabled, $params);
2913
+			if (isset($tag['validate'])) {
2914
+							$tag['validate']($tag, $data, $disabled, $params);
2915
+			}
2775 2916
 
2776 2917
 			// Fix after, for disabled code mainly.
2777
-			foreach ($data as $k => $d)
2778
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2918
+			foreach ($data as $k => $d) {
2919
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2920
+			}
2779 2921
 
2780 2922
 			$open_tags[] = $tag;
2781 2923
 
2782 2924
 			// Replace them out, $1, $2, $3, $4, etc.
2783 2925
 			$code = $tag['before'];
2784
-			foreach ($data as $k => $d)
2785
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2926
+			foreach ($data as $k => $d) {
2927
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2928
+			}
2786 2929
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2787 2930
 			$pos += strlen($code) - 1 + 2;
2788 2931
 		}
@@ -2793,28 +2936,33 @@  discard block
 block discarded – undo
2793 2936
 			if (isset($tag['quoted']))
2794 2937
 			{
2795 2938
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2796
-				if ($tag['quoted'] != 'optional' && !$quoted)
2797
-					continue;
2939
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2940
+									continue;
2941
+				}
2798 2942
 
2799
-				if ($quoted)
2800
-					$pos1 += 6;
2943
+				if ($quoted) {
2944
+									$pos1 += 6;
2945
+				}
2946
+			} else {
2947
+							$quoted = false;
2801 2948
 			}
2802
-			else
2803
-				$quoted = false;
2804 2949
 
2805 2950
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2806
-			if ($pos2 === false)
2807
-				continue;
2951
+			if ($pos2 === false) {
2952
+							continue;
2953
+			}
2808 2954
 
2809 2955
 			$data = substr($message, $pos1, $pos2 - $pos1);
2810 2956
 
2811 2957
 			// Validation for my parking, please!
2812
-			if (isset($tag['validate']))
2813
-				$tag['validate']($tag, $data, $disabled, $params);
2958
+			if (isset($tag['validate'])) {
2959
+							$tag['validate']($tag, $data, $disabled, $params);
2960
+			}
2814 2961
 
2815 2962
 			// For parsed content, we must recurse to avoid security problems.
2816
-			if ($tag['type'] != 'unparsed_equals')
2817
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2963
+			if ($tag['type'] != 'unparsed_equals') {
2964
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2965
+			}
2818 2966
 
2819 2967
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2820 2968
 
@@ -2826,34 +2974,40 @@  discard block
 block discarded – undo
2826 2974
 		}
2827 2975
 
2828 2976
 		// If this is block level, eat any breaks after it.
2829
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2830
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2977
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2978
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2979
+		}
2831 2980
 
2832 2981
 		// Are we trimming outside this tag?
2833
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2834
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2982
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2983
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2984
+		}
2835 2985
 	}
2836 2986
 
2837 2987
 	// Close any remaining tags.
2838
-	while ($tag = array_pop($open_tags))
2839
-		$message .= "\n" . $tag['after'] . "\n";
2988
+	while ($tag = array_pop($open_tags)) {
2989
+			$message .= "\n" . $tag['after'] . "\n";
2990
+	}
2840 2991
 
2841 2992
 	// Parse the smileys within the parts where it can be done safely.
2842 2993
 	if ($smileys === true)
2843 2994
 	{
2844 2995
 		$message_parts = explode("\n", $message);
2845
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2846
-			parsesmileys($message_parts[$i]);
2996
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2997
+					parsesmileys($message_parts[$i]);
2998
+		}
2847 2999
 
2848 3000
 		$message = implode('', $message_parts);
2849 3001
 	}
2850 3002
 
2851 3003
 	// No smileys, just get rid of the markers.
2852
-	else
2853
-		$message = strtr($message, array("\n" => ''));
3004
+	else {
3005
+			$message = strtr($message, array("\n" => ''));
3006
+	}
2854 3007
 
2855
-	if ($message !== '' && $message[0] === ' ')
2856
-		$message = '&nbsp;' . substr($message, 1);
3008
+	if ($message !== '' && $message[0] === ' ') {
3009
+			$message = '&nbsp;' . substr($message, 1);
3010
+	}
2857 3011
 
2858 3012
 	// Cleanup whitespace.
2859 3013
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2862,15 +3016,16 @@  discard block
 block discarded – undo
2862 3016
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2863 3017
 
2864 3018
 	// Cache the output if it took some time...
2865
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2866
-		cache_put_data($cache_key, $message, 240);
3019
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
3020
+			cache_put_data($cache_key, $message, 240);
3021
+	}
2867 3022
 
2868 3023
 	// If this was a force parse revert if needed.
2869 3024
 	if (!empty($parse_tags))
2870 3025
 	{
2871
-		if (empty($temp_bbc))
2872
-			$bbc_codes = array();
2873
-		else
3026
+		if (empty($temp_bbc)) {
3027
+					$bbc_codes = array();
3028
+		} else
2874 3029
 		{
2875 3030
 			$bbc_codes = $temp_bbc;
2876 3031
 			unset($temp_bbc);
@@ -2897,8 +3052,9 @@  discard block
 block discarded – undo
2897 3052
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2898 3053
 
2899 3054
 	// No smiley set at all?!
2900
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2901
-		return;
3055
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
3056
+			return;
3057
+	}
2902 3058
 
2903 3059
 	// Maybe a mod wants to implement an alternative method (e.g. emojis instead of images)
2904 3060
 	call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements));
@@ -2912,8 +3068,7 @@  discard block
 block discarded – undo
2912 3068
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', 'O:-)');
2913 3069
 			$smileysto = array('evil.png', 'cheesy.png', 'rolleyes.png', 'angry.png', 'laugh.png', 'smiley.png', 'wink.png', 'grin.png', 'sad.png', 'shocked.png', 'cool.png', 'tongue.png', 'huh.png', 'embarrassed.png', 'lipsrsealed.png', 'kiss.png', 'cry.png', 'undecided.png', 'azn.png', 'afro.png', 'police.png', 'angel.png');
2914 3070
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2915
-		}
2916
-		else
3071
+		} else
2917 3072
 		{
2918 3073
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2919 3074
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2937,9 +3092,9 @@  discard block
 block discarded – undo
2937 3092
 				$smcFunc['db_free_result']($result);
2938 3093
 
2939 3094
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
3095
+			} else {
3096
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2940 3097
 			}
2941
-			else
2942
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2943 3098
 		}
2944 3099
 
2945 3100
 		// The non-breaking-space is a complex thing...
@@ -2961,16 +3116,18 @@  discard block
 block discarded – undo
2961 3116
 				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2962 3117
 				if (!empty($alt_images))
2963 3118
 				{
2964
-					foreach ($exts as $ext)
2965
-						if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
3119
+					foreach ($exts as $ext) {
3120
+											if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
2966 3121
 						{
2967 3122
 							$smileysto[$i] = $fname . '.' . $ext;
3123
+					}
2968 3124
 							break;
2969 3125
 						}
2970 3126
 				}
2971 3127
 				// If we have no image, just leave the text version in place
2972
-				else
2973
-					continue;
3128
+				else {
3129
+									continue;
3130
+				}
2974 3131
 			}
2975 3132
 
2976 3133
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
@@ -3046,12 +3203,14 @@  discard block
 block discarded – undo
3046 3203
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
3047 3204
 
3048 3205
 	// Only use the proxy if enabled and necessary
3049
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
3050
-		return $url;
3206
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3207
+			return $url;
3208
+	}
3051 3209
 
3052 3210
 	// We don't need to proxy our own resources
3053
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
3054
-		return strtr($url, array('http://' => 'https://'));
3211
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3212
+			return strtr($url, array('http://' => 'https://'));
3213
+	}
3055 3214
 
3056 3215
 	// By default, use SMF's own image proxy script
3057 3216
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -3076,35 +3235,41 @@  discard block
 block discarded – undo
3076 3235
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
3077 3236
 
3078 3237
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
3079
-	if (!empty($context['flush_mail']))
3080
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3238
+	if (!empty($context['flush_mail'])) {
3239
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3081 3240
 		AddMailQueue(true);
3241
+	}
3082 3242
 
3083 3243
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
3084 3244
 
3085
-	if ($add)
3086
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3245
+	if ($add) {
3246
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3247
+	}
3087 3248
 
3088 3249
 	// Put the session ID in.
3089
-	if (defined('SID') && SID != '')
3090
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3250
+	if (defined('SID') && SID != '') {
3251
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3252
+	}
3091 3253
 	// Keep that debug in their for template debugging!
3092
-	elseif (isset($_GET['debug']))
3093
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3254
+	elseif (isset($_GET['debug'])) {
3255
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3256
+	}
3094 3257
 
3095 3258
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
3096 3259
 	{
3097
-		if (defined('SID') && SID != '')
3098
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3260
+		if (defined('SID') && SID != '') {
3261
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3099 3262
 				function ($m) use ($scripturl)
3100 3263
 				{
3101 3264
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3265
+		}
3102 3266
 				}, $setLocation);
3103
-		else
3104
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3267
+		else {
3268
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3105 3269
 				function ($m) use ($scripturl)
3106 3270
 				{
3107 3271
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3272
+		}
3108 3273
 				}, $setLocation);
3109 3274
 	}
3110 3275
 
@@ -3115,8 +3280,9 @@  discard block
 block discarded – undo
3115 3280
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
3116 3281
 
3117 3282
 	// Debugging.
3118
-	if (isset($db_show_debug) && $db_show_debug === true)
3119
-		$_SESSION['debug_redirect'] = $db_cache;
3283
+	if (isset($db_show_debug) && $db_show_debug === true) {
3284
+			$_SESSION['debug_redirect'] = $db_cache;
3285
+	}
3120 3286
 
3121 3287
 	obExit(false);
3122 3288
 }
@@ -3135,51 +3301,60 @@  discard block
 block discarded – undo
3135 3301
 
3136 3302
 	// Attempt to prevent a recursive loop.
3137 3303
 	++$level;
3138
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
3139
-		exit;
3140
-	if ($from_fatal_error)
3141
-		$has_fatal_error = true;
3304
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3305
+			exit;
3306
+	}
3307
+	if ($from_fatal_error) {
3308
+			$has_fatal_error = true;
3309
+	}
3142 3310
 
3143 3311
 	// Clear out the stat cache.
3144 3312
 	trackStats();
3145 3313
 
3146 3314
 	// If we have mail to send, send it.
3147
-	if (!empty($context['flush_mail']))
3148
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3315
+	if (!empty($context['flush_mail'])) {
3316
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3149 3317
 		AddMailQueue(true);
3318
+	}
3150 3319
 
3151 3320
 	$do_header = $header === null ? !$header_done : $header;
3152
-	if ($do_footer === null)
3153
-		$do_footer = $do_header;
3321
+	if ($do_footer === null) {
3322
+			$do_footer = $do_header;
3323
+	}
3154 3324
 
3155 3325
 	// Has the template/header been done yet?
3156 3326
 	if ($do_header)
3157 3327
 	{
3158 3328
 		// Was the page title set last minute? Also update the HTML safe one.
3159
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
3160
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3329
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3330
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3331
+		}
3161 3332
 
3162 3333
 		// Start up the session URL fixer.
3163 3334
 		ob_start('ob_sessrewrite');
3164 3335
 
3165
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3166
-			$buffers = explode(',', $settings['output_buffers']);
3167
-		elseif (!empty($settings['output_buffers']))
3168
-			$buffers = $settings['output_buffers'];
3169
-		else
3170
-			$buffers = array();
3336
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3337
+					$buffers = explode(',', $settings['output_buffers']);
3338
+		} elseif (!empty($settings['output_buffers'])) {
3339
+					$buffers = $settings['output_buffers'];
3340
+		} else {
3341
+					$buffers = array();
3342
+		}
3171 3343
 
3172
-		if (isset($modSettings['integrate_buffer']))
3173
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3344
+		if (isset($modSettings['integrate_buffer'])) {
3345
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3346
+		}
3174 3347
 
3175
-		if (!empty($buffers))
3176
-			foreach ($buffers as $function)
3348
+		if (!empty($buffers)) {
3349
+					foreach ($buffers as $function)
3177 3350
 			{
3178 3351
 				$call = call_helper($function, true);
3352
+		}
3179 3353
 
3180 3354
 				// Is it valid?
3181
-				if (!empty($call))
3182
-					ob_start($call);
3355
+				if (!empty($call)) {
3356
+									ob_start($call);
3357
+				}
3183 3358
 			}
3184 3359
 
3185 3360
 		// Display the screen in the logical order.
@@ -3191,8 +3366,9 @@  discard block
 block discarded – undo
3191 3366
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3192 3367
 
3193 3368
 		// Anything special to put out?
3194
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3195
-			echo $context['insert_after_template'];
3369
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3370
+					echo $context['insert_after_template'];
3371
+		}
3196 3372
 
3197 3373
 		// Just so we don't get caught in an endless loop of errors from the footer...
3198 3374
 		if (!$footer_done)
@@ -3201,14 +3377,16 @@  discard block
 block discarded – undo
3201 3377
 			template_footer();
3202 3378
 
3203 3379
 			// (since this is just debugging... it's okay that it's after </html>.)
3204
-			if (!isset($_REQUEST['xml']))
3205
-				displayDebug();
3380
+			if (!isset($_REQUEST['xml'])) {
3381
+							displayDebug();
3382
+			}
3206 3383
 		}
3207 3384
 	}
3208 3385
 
3209 3386
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3210
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3211
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3387
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3388
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3389
+	}
3212 3390
 
3213 3391
 	// For session check verification.... don't switch browsers...
3214 3392
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3217,9 +3395,10 @@  discard block
 block discarded – undo
3217 3395
 	call_integration_hook('integrate_exit', array($do_footer));
3218 3396
 
3219 3397
 	// Don't exit if we're coming from index.php; that will pass through normally.
3220
-	if (!$from_index)
3221
-		exit;
3222
-}
3398
+	if (!$from_index) {
3399
+			exit;
3400
+	}
3401
+	}
3223 3402
 
3224 3403
 /**
3225 3404
  * Get the size of a specified image with better error handling.
@@ -3238,8 +3417,9 @@  discard block
 block discarded – undo
3238 3417
 	$url = str_replace(' ', '%20', $url);
3239 3418
 
3240 3419
 	// Can we pull this from the cache... please please?
3241
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3242
-		return $temp;
3420
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3421
+			return $temp;
3422
+	}
3243 3423
 	$t = microtime();
3244 3424
 
3245 3425
 	// Get the host to pester...
@@ -3249,12 +3429,10 @@  discard block
 block discarded – undo
3249 3429
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3250 3430
 	{
3251 3431
 		return false;
3252
-	}
3253
-	elseif (!isset($match[1]))
3432
+	} elseif (!isset($match[1]))
3254 3433
 	{
3255 3434
 		$size = @getimagesize($url);
3256
-	}
3257
-	else
3435
+	} else
3258 3436
 	{
3259 3437
 		// Try to connect to the server... give it half a second.
3260 3438
 		$temp = 0;
@@ -3291,12 +3469,14 @@  discard block
 block discarded – undo
3291 3469
 	}
3292 3470
 
3293 3471
 	// If we didn't get it, we failed.
3294
-	if (!isset($size))
3295
-		$size = false;
3472
+	if (!isset($size)) {
3473
+			$size = false;
3474
+	}
3296 3475
 
3297 3476
 	// If this took a long time, we may never have to do it again, but then again we might...
3298
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3299
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3477
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3478
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3479
+	}
3300 3480
 
3301 3481
 	// Didn't work.
3302 3482
 	return $size;
@@ -3314,8 +3494,9 @@  discard block
 block discarded – undo
3314 3494
 
3315 3495
 	// Under SSI this function can be called more then once.  That can cause some problems.
3316 3496
 	//   So only run the function once unless we are forced to run it again.
3317
-	if ($loaded && !$forceload)
3318
-		return;
3497
+	if ($loaded && !$forceload) {
3498
+			return;
3499
+	}
3319 3500
 
3320 3501
 	$loaded = true;
3321 3502
 
@@ -3327,14 +3508,16 @@  discard block
 block discarded – undo
3327 3508
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3328 3509
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3329 3510
 	{
3330
-		if (trim($context['news_lines'][$i]) == '')
3331
-			continue;
3511
+		if (trim($context['news_lines'][$i]) == '') {
3512
+					continue;
3513
+		}
3332 3514
 
3333 3515
 		// Clean it up for presentation ;).
3334 3516
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3335 3517
 	}
3336
-	if (!empty($context['news_lines']))
3337
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3518
+	if (!empty($context['news_lines'])) {
3519
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3520
+	}
3338 3521
 
3339 3522
 	if (!$user_info['is_guest'])
3340 3523
 	{
@@ -3343,40 +3526,48 @@  discard block
 block discarded – undo
3343 3526
 		$context['user']['alerts'] = &$user_info['alerts'];
3344 3527
 
3345 3528
 		// Personal message popup...
3346
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3347
-			$context['user']['popup_messages'] = true;
3348
-		else
3349
-			$context['user']['popup_messages'] = false;
3529
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3530
+					$context['user']['popup_messages'] = true;
3531
+		} else {
3532
+					$context['user']['popup_messages'] = false;
3533
+		}
3350 3534
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3351 3535
 
3352
-		if (allowedTo('moderate_forum'))
3353
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3536
+		if (allowedTo('moderate_forum')) {
3537
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3538
+		}
3354 3539
 
3355 3540
 		$context['user']['avatar'] = array();
3356 3541
 
3357 3542
 		// Check for gravatar first since we might be forcing them...
3358 3543
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3359 3544
 		{
3360
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3361
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3362
-			else
3363
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3545
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3546
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3547
+			} else {
3548
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3549
+			}
3364 3550
 		}
3365 3551
 		// Uploaded?
3366
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3367
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3552
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3553
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3554
+		}
3368 3555
 		// Full URL?
3369
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3370
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3556
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3557
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3558
+		}
3371 3559
 		// Otherwise we assume it's server stored.
3372
-		elseif ($user_info['avatar']['url'] != '')
3373
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3560
+		elseif ($user_info['avatar']['url'] != '') {
3561
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3562
+		}
3374 3563
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3375
-		else
3376
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3564
+		else {
3565
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3566
+		}
3377 3567
 
3378
-		if (!empty($context['user']['avatar']))
3379
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3568
+		if (!empty($context['user']['avatar'])) {
3569
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3570
+		}
3380 3571
 
3381 3572
 		// Figure out how long they've been logged in.
3382 3573
 		$context['user']['total_time_logged_in'] = array(
@@ -3384,8 +3575,7 @@  discard block
 block discarded – undo
3384 3575
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3385 3576
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3386 3577
 		);
3387
-	}
3388
-	else
3578
+	} else
3389 3579
 	{
3390 3580
 		$context['user']['messages'] = 0;
3391 3581
 		$context['user']['unread_messages'] = 0;
@@ -3393,12 +3583,14 @@  discard block
 block discarded – undo
3393 3583
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3394 3584
 		$context['user']['popup_messages'] = false;
3395 3585
 
3396
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3397
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3586
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3587
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3588
+		}
3398 3589
 
3399 3590
 		// If we've upgraded recently, go easy on the passwords.
3400
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3401
-			$context['disable_login_hashing'] = true;
3591
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3592
+					$context['disable_login_hashing'] = true;
3593
+		}
3402 3594
 	}
3403 3595
 
3404 3596
 	// Setup the main menu items.
@@ -3411,8 +3603,8 @@  discard block
 block discarded – undo
3411 3603
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3412 3604
 
3413 3605
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3414
-	if ($context['show_pm_popup'])
3415
-		addInlineJavaScript('
3606
+	if ($context['show_pm_popup']) {
3607
+			addInlineJavaScript('
3416 3608
 		jQuery(document).ready(function($) {
3417 3609
 			new smc_Popup({
3418 3610
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3420,24 +3612,28 @@  discard block
 block discarded – undo
3420 3612
 				icon_class: \'generic_icons mail_new\'
3421 3613
 			});
3422 3614
 		});');
3615
+	}
3423 3616
 
3424 3617
 	// Add a generic "Are you sure?" confirmation message.
3425 3618
 	addInlineJavaScript('
3426 3619
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3427 3620
 
3428 3621
 	// Now add the capping code for avatars.
3429
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3430
-		addInlineCss('
3622
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3623
+			addInlineCss('
3431 3624
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3625
+	}
3432 3626
 
3433 3627
 	// Add max image limits
3434
-	if (!empty($modSettings['max_image_width']))
3435
-		addInlineCss('
3628
+	if (!empty($modSettings['max_image_width'])) {
3629
+			addInlineCss('
3436 3630
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3631
+	}
3437 3632
 
3438
-	if (!empty($modSettings['max_image_height']))
3439
-		addInlineCss('
3633
+	if (!empty($modSettings['max_image_height'])) {
3634
+			addInlineCss('
3440 3635
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3636
+	}
3441 3637
 
3442 3638
 	// This looks weird, but it's because BoardIndex.php references the variable.
3443 3639
 	$context['common_stats']['latest_member'] = array(
@@ -3454,11 +3650,13 @@  discard block
 block discarded – undo
3454 3650
 	);
3455 3651
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3456 3652
 
3457
-	if (empty($settings['theme_version']))
3458
-		addJavaScriptVar('smf_scripturl', $scripturl);
3653
+	if (empty($settings['theme_version'])) {
3654
+			addJavaScriptVar('smf_scripturl', $scripturl);
3655
+	}
3459 3656
 
3460
-	if (!isset($context['page_title']))
3461
-		$context['page_title'] = '';
3657
+	if (!isset($context['page_title'])) {
3658
+			$context['page_title'] = '';
3659
+	}
3462 3660
 
3463 3661
 	// Set some specific vars.
3464 3662
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3468,21 +3666,23 @@  discard block
 block discarded – undo
3468 3666
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3469 3667
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3470 3668
 
3471
-	if (!empty($context['meta_keywords']))
3472
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3669
+	if (!empty($context['meta_keywords'])) {
3670
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3671
+	}
3473 3672
 
3474
-	if (!empty($context['canonical_url']))
3475
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3673
+	if (!empty($context['canonical_url'])) {
3674
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3675
+	}
3476 3676
 
3477
-	if (!empty($settings['og_image']))
3478
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3677
+	if (!empty($settings['og_image'])) {
3678
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3679
+	}
3479 3680
 
3480 3681
 	if (!empty($context['meta_description']))
3481 3682
 	{
3482 3683
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3483 3684
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3484
-	}
3485
-	else
3685
+	} else
3486 3686
 	{
3487 3687
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3488 3688
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3507,8 +3707,9 @@  discard block
 block discarded – undo
3507 3707
 	$memory_needed = memoryReturnBytes($needed);
3508 3708
 
3509 3709
 	// should we account for how much is currently being used?
3510
-	if ($in_use)
3511
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3710
+	if ($in_use) {
3711
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3712
+	}
3512 3713
 
3513 3714
 	// if more is needed, request it
3514 3715
 	if ($memory_current < $memory_needed)
@@ -3531,8 +3732,9 @@  discard block
 block discarded – undo
3531 3732
  */
3532 3733
 function memoryReturnBytes($val)
3533 3734
 {
3534
-	if (is_integer($val))
3535
-		return $val;
3735
+	if (is_integer($val)) {
3736
+			return $val;
3737
+	}
3536 3738
 
3537 3739
 	// Separate the number from the designator
3538 3740
 	$val = trim($val);
@@ -3568,10 +3770,11 @@  discard block
 block discarded – undo
3568 3770
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3569 3771
 
3570 3772
 		// Are we debugging the template/html content?
3571
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3572
-			header('content-type: application/xhtml+xml');
3573
-		elseif (!isset($_REQUEST['xml']))
3574
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3773
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3774
+					header('content-type: application/xhtml+xml');
3775
+		} elseif (!isset($_REQUEST['xml'])) {
3776
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3777
+		}
3575 3778
 	}
3576 3779
 
3577 3780
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3580,8 +3783,9 @@  discard block
 block discarded – undo
3580 3783
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3581 3784
 	{
3582 3785
 		$position = array_search('body', $context['template_layers']);
3583
-		if ($position === false)
3584
-			$position = array_search('main', $context['template_layers']);
3786
+		if ($position === false) {
3787
+					$position = array_search('main', $context['template_layers']);
3788
+		}
3585 3789
 
3586 3790
 		if ($position !== false)
3587 3791
 		{
@@ -3609,23 +3813,25 @@  discard block
 block discarded – undo
3609 3813
 
3610 3814
 			foreach ($securityFiles as $i => $securityFile)
3611 3815
 			{
3612
-				if (!file_exists($boarddir . '/' . $securityFile))
3613
-					unset($securityFiles[$i]);
3816
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3817
+									unset($securityFiles[$i]);
3818
+				}
3614 3819
 			}
3615 3820
 
3616 3821
 			// We are already checking so many files...just few more doesn't make any difference! :P
3617
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3618
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3619
-
3620
-			else
3621
-				$path = $modSettings['attachmentUploadDir'];
3822
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3823
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3824
+			} else {
3825
+							$path = $modSettings['attachmentUploadDir'];
3826
+			}
3622 3827
 
3623 3828
 			secureDirectory($path, true);
3624 3829
 			secureDirectory($cachedir);
3625 3830
 
3626 3831
 			// If agreement is enabled, at least the english version shall exists
3627
-			if ($modSettings['requireAgreement'])
3628
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3832
+			if ($modSettings['requireAgreement']) {
3833
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3834
+			}
3629 3835
 
3630 3836
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3631 3837
 			{
@@ -3640,18 +3846,21 @@  discard block
 block discarded – undo
3640 3846
 					echo '
3641 3847
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3642 3848
 
3643
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3644
-						echo '
3849
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3850
+											echo '
3645 3851
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3852
+					}
3646 3853
 				}
3647 3854
 
3648
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3649
-					echo '
3855
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3856
+									echo '
3650 3857
 				<strong>', $txt['cache_writable'], '</strong><br>';
3858
+				}
3651 3859
 
3652
-				if (!empty($agreement))
3653
-					echo '
3860
+				if (!empty($agreement)) {
3861
+									echo '
3654 3862
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3863
+				}
3655 3864
 
3656 3865
 				echo '
3657 3866
 			</p>
@@ -3666,16 +3875,18 @@  discard block
 block discarded – undo
3666 3875
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3667 3876
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3668 3877
 
3669
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3670
-				echo '
3878
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3879
+							echo '
3671 3880
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3881
+			}
3672 3882
 
3673
-			if (!empty($_SESSION['ban']['expire_time']))
3674
-				echo '
3883
+			if (!empty($_SESSION['ban']['expire_time'])) {
3884
+							echo '
3675 3885
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3676
-			else
3677
-				echo '
3886
+			} else {
3887
+							echo '
3678 3888
 					<div>', $txt['your_ban_expires_never'], '</div>';
3889
+			}
3679 3890
 
3680 3891
 			echo '
3681 3892
 				</div>';
@@ -3691,8 +3902,9 @@  discard block
 block discarded – undo
3691 3902
 	global $forum_copyright, $software_year, $forum_version;
3692 3903
 
3693 3904
 	// Don't display copyright for things like SSI.
3694
-	if (!isset($forum_version) || !isset($software_year))
3695
-		return;
3905
+	if (!isset($forum_version) || !isset($software_year)) {
3906
+			return;
3907
+	}
3696 3908
 
3697 3909
 	// Put in the version...
3698 3910
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3710,9 +3922,10 @@  discard block
 block discarded – undo
3710 3922
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3711 3923
 	$context['load_queries'] = $db_count;
3712 3924
 
3713
-	foreach (array_reverse($context['template_layers']) as $layer)
3714
-		loadSubTemplate($layer . '_below', true);
3715
-}
3925
+	foreach (array_reverse($context['template_layers']) as $layer) {
3926
+			loadSubTemplate($layer . '_below', true);
3927
+	}
3928
+	}
3716 3929
 
3717 3930
 /**
3718 3931
  * Output the Javascript files
@@ -3746,8 +3959,7 @@  discard block
 block discarded – undo
3746 3959
 			{
3747 3960
 				echo '
3748 3961
 		var ', $key, ';';
3749
-			}
3750
-			else
3962
+			} else
3751 3963
 			{
3752 3964
 				echo '
3753 3965
 		var ', $key, ' = ', $value, ';';
@@ -3766,27 +3978,29 @@  discard block
 block discarded – undo
3766 3978
 		foreach ($context['javascript_files'] as $id => $js_file)
3767 3979
 		{
3768 3980
 			// Last minute call! allow theme authors to disable single files.
3769
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3770
-				continue;
3981
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3982
+							continue;
3983
+			}
3771 3984
 
3772 3985
 			// By default files don't get minimized unless the file explicitly says so!
3773 3986
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3774 3987
 			{
3775
-				if (!empty($js_file['options']['async']))
3776
-					$toMinify['async'][] = $js_file;
3777
-				elseif (!empty($js_file['options']['defer']))
3778
-					$toMinify['defer'][] = $js_file;
3779
-				else
3780
-					$toMinify['standard'][] = $js_file;
3988
+				if (!empty($js_file['options']['async'])) {
3989
+									$toMinify['async'][] = $js_file;
3990
+				} elseif (!empty($js_file['options']['defer'])) {
3991
+									$toMinify['defer'][] = $js_file;
3992
+				} else {
3993
+									$toMinify['standard'][] = $js_file;
3994
+				}
3781 3995
 
3782 3996
 				// Grab a random seed.
3783
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3784
-					$minSeed = $js_file['options']['seed'];
3785
-			}
3786
-
3787
-			else
3788
-				echo '
3997
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3998
+									$minSeed = $js_file['options']['seed'];
3999
+				}
4000
+			} else {
4001
+							echo '
3789 4002
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
4003
+			}
3790 4004
 		}
3791 4005
 
3792 4006
 		foreach ($toMinify as $js_files)
@@ -3797,9 +4011,10 @@  discard block
 block discarded – undo
3797 4011
 
3798 4012
 				$minSuccessful = array_keys($result) === array('smf_minified');
3799 4013
 
3800
-				foreach ($result as $minFile)
3801
-					echo '
4014
+				foreach ($result as $minFile) {
4015
+									echo '
3802 4016
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
4017
+				}
3803 4018
 			}
3804 4019
 		}
3805 4020
 	}
@@ -3813,8 +4028,9 @@  discard block
 block discarded – undo
3813 4028
 <script>
3814 4029
 window.addEventListener("DOMContentLoaded", function() {';
3815 4030
 
3816
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3817
-				echo $js_code;
4031
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
4032
+							echo $js_code;
4033
+			}
3818 4034
 
3819 4035
 			echo '
3820 4036
 });
@@ -3826,8 +4042,9 @@  discard block
 block discarded – undo
3826 4042
 			echo '
3827 4043
 	<script>';
3828 4044
 
3829
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3830
-				echo $js_code;
4045
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
4046
+							echo $js_code;
4047
+			}
3831 4048
 
3832 4049
 			echo '
3833 4050
 	</script>';
@@ -3855,23 +4072,26 @@  discard block
 block discarded – undo
3855 4072
 	foreach ($context['css_files'] as $id => $file)
3856 4073
 	{
3857 4074
 		// Last minute call! allow theme authors to disable single files.
3858
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3859
-			continue;
4075
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
4076
+					continue;
4077
+		}
3860 4078
 
3861 4079
 		// Files are minimized unless they explicitly opt out.
3862
-		if (!isset($file['options']['minimize']))
3863
-			$file['options']['minimize'] = true;
4080
+		if (!isset($file['options']['minimize'])) {
4081
+					$file['options']['minimize'] = true;
4082
+		}
3864 4083
 
3865 4084
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3866 4085
 		{
3867 4086
 			$toMinify[] = $file;
3868 4087
 
3869 4088
 			// Grab a random seed.
3870
-			if (!isset($minSeed) && isset($file['options']['seed']))
3871
-				$minSeed = $file['options']['seed'];
4089
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
4090
+							$minSeed = $file['options']['seed'];
4091
+			}
4092
+		} else {
4093
+					$normal[] = $file['fileUrl'];
3872 4094
 		}
3873
-		else
3874
-			$normal[] = $file['fileUrl'];
3875 4095
 	}
3876 4096
 
3877 4097
 	if (!empty($toMinify))
@@ -3880,23 +4100,26 @@  discard block
 block discarded – undo
3880 4100
 
3881 4101
 		$minSuccessful = array_keys($result) === array('smf_minified');
3882 4102
 
3883
-		foreach ($result as $minFile)
3884
-			echo '
4103
+		foreach ($result as $minFile) {
4104
+					echo '
3885 4105
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
4106
+		}
3886 4107
 	}
3887 4108
 
3888 4109
 	// Print the rest after the minified files.
3889
-	if (!empty($normal))
3890
-		foreach ($normal as $nf)
4110
+	if (!empty($normal)) {
4111
+			foreach ($normal as $nf)
3891 4112
 			echo '
3892 4113
 	<link rel="stylesheet" href="', $nf ,'">';
4114
+	}
3893 4115
 
3894 4116
 	if ($db_show_debug === true)
3895 4117
 	{
3896 4118
 		// Try to keep only what's useful.
3897 4119
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3898
-		foreach ($context['css_files'] as $file)
3899
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4120
+		foreach ($context['css_files'] as $file) {
4121
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4122
+		}
3900 4123
 	}
3901 4124
 
3902 4125
 	if (!empty($context['css_header']))
@@ -3904,9 +4127,10 @@  discard block
 block discarded – undo
3904 4127
 		echo '
3905 4128
 	<style>';
3906 4129
 
3907
-		foreach ($context['css_header'] as $css)
3908
-			echo $css .'
4130
+		foreach ($context['css_header'] as $css) {
4131
+					echo $css .'
3909 4132
 	';
4133
+		}
3910 4134
 
3911 4135
 		echo'
3912 4136
 	</style>';
@@ -3929,8 +4153,9 @@  discard block
 block discarded – undo
3929 4153
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3930 4154
 	$data = is_array($data) ? $data : array();
3931 4155
 
3932
-	if (empty($type) || empty($data))
3933
-		return $data;
4156
+	if (empty($type) || empty($data)) {
4157
+			return $data;
4158
+	}
3934 4159
 
3935 4160
 	// Different pages include different files, so we use a hash to label the different combinations
3936 4161
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3939,13 +4164,14 @@  discard block
 block discarded – undo
3939 4164
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3940 4165
 
3941 4166
 	// Already done?
3942
-	if (!empty($toCache))
3943
-		return array('smf_minified' => array(
4167
+	if (!empty($toCache)) {
4168
+			return array('smf_minified' => array(
3944 4169
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3945 4170
 			'filePath' => $toCache,
3946 4171
 			'fileName' => basename($toCache),
3947 4172
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3948 4173
 		));
4174
+	}
3949 4175
 
3950 4176
 
3951 4177
 	// No namespaces, sorry!
@@ -3975,9 +4201,9 @@  discard block
 block discarded – undo
3975 4201
 
3976 4202
 	foreach ($data as $id => $file)
3977 4203
 	{
3978
-		if (empty($file['filePath']))
3979
-			$toAdd = false;
3980
-		else
4204
+		if (empty($file['filePath'])) {
4205
+					$toAdd = false;
4206
+		} else
3981 4207
 		{
3982 4208
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3983 4209
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3985,12 +4211,14 @@  discard block
 block discarded – undo
3985 4211
 		}
3986 4212
 
3987 4213
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3988
-		if (empty($file['options']['async']))
3989
-			$async = false;
4214
+		if (empty($file['options']['async'])) {
4215
+					$async = false;
4216
+		}
3990 4217
 
3991 4218
 		// A minified script should only be deferred if all its components wanted to be.
3992
-		if (empty($file['options']['defer']))
3993
-			$defer = false;
4219
+		if (empty($file['options']['defer'])) {
4220
+					$defer = false;
4221
+		}
3994 4222
 
3995 4223
 		// The file couldn't be located so it won't be added. Log this error.
3996 4224
 		if (empty($toAdd))
@@ -4056,12 +4284,14 @@  discard block
 block discarded – undo
4056 4284
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
4057 4285
 			{
4058 4286
 				// Remove the cache entry
4059
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
4060
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4287
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4288
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4289
+				}
4061 4290
 
4062 4291
 				// Try to delete the file. Add it to our error list if it fails.
4063
-				if (!@unlink($filename))
4064
-					$not_deleted[] = $filename;
4292
+				if (!@unlink($filename)) {
4293
+									$not_deleted[] = $filename;
4294
+				}
4065 4295
 			}
4066 4296
 		}
4067 4297
 	}
@@ -4093,8 +4323,9 @@  discard block
 block discarded – undo
4093 4323
 	global $modSettings, $smcFunc;
4094 4324
 
4095 4325
 	// Just make up a nice hash...
4096
-	if ($new)
4097
-		return sha1(md5($filename . time()) . mt_rand());
4326
+	if ($new) {
4327
+			return sha1(md5($filename . time()) . mt_rand());
4328
+	}
4098 4329
 
4099 4330
 	// Just make sure that attachment id is only a int
4100 4331
 	$attachment_id = (int) $attachment_id;
@@ -4111,23 +4342,25 @@  discard block
 block discarded – undo
4111 4342
 				'id_attach' => $attachment_id,
4112 4343
 			));
4113 4344
 
4114
-		if ($smcFunc['db_num_rows']($request) === 0)
4115
-			return false;
4345
+		if ($smcFunc['db_num_rows']($request) === 0) {
4346
+					return false;
4347
+		}
4116 4348
 
4117 4349
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
4118 4350
 		$smcFunc['db_free_result']($request);
4119 4351
 	}
4120 4352
 
4121 4353
 	// Still no hash? mmm...
4122
-	if (empty($file_hash))
4123
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4354
+	if (empty($file_hash)) {
4355
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4356
+	}
4124 4357
 
4125 4358
 	// Are we using multiple directories?
4126
-	if (is_array($modSettings['attachmentUploadDir']))
4127
-		$path = $modSettings['attachmentUploadDir'][$dir];
4128
-
4129
-	else
4130
-		$path = $modSettings['attachmentUploadDir'];
4359
+	if (is_array($modSettings['attachmentUploadDir'])) {
4360
+			$path = $modSettings['attachmentUploadDir'][$dir];
4361
+	} else {
4362
+			$path = $modSettings['attachmentUploadDir'];
4363
+	}
4131 4364
 
4132 4365
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4133 4366
 }
@@ -4142,8 +4375,9 @@  discard block
 block discarded – undo
4142 4375
 function ip2range($fullip)
4143 4376
 {
4144 4377
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
4145
-	if ($fullip == 'unknown')
4146
-		$fullip = '255.255.255.255';
4378
+	if ($fullip == 'unknown') {
4379
+			$fullip = '255.255.255.255';
4380
+	}
4147 4381
 
4148 4382
 	$ip_parts = explode('-', $fullip);
4149 4383
 	$ip_array = array();
@@ -4167,10 +4401,11 @@  discard block
 block discarded – undo
4167 4401
 		$ip_array['low'] = $ip_parts[0];
4168 4402
 		$ip_array['high'] = $ip_parts[1];
4169 4403
 		return $ip_array;
4170
-	}
4171
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4404
+	} elseif (count($ip_parts) == 2) {
4405
+		// if ip 22.22.*-22.22.*
4172 4406
 	{
4173 4407
 		$valid_low = isValidIP($ip_parts[0]);
4408
+	}
4174 4409
 		$valid_high = isValidIP($ip_parts[1]);
4175 4410
 		$count = 0;
4176 4411
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4185,7 +4420,9 @@  discard block
 block discarded – undo
4185 4420
 				$ip_parts[0] .= $mode . $min;
4186 4421
 				$valid_low = isValidIP($ip_parts[0]);
4187 4422
 				$count++;
4188
-				if ($count > 9) break;
4423
+				if ($count > 9) {
4424
+					break;
4425
+				}
4189 4426
 			}
4190 4427
 		}
4191 4428
 
@@ -4199,7 +4436,9 @@  discard block
 block discarded – undo
4199 4436
 				$ip_parts[1] .= $mode . $max;
4200 4437
 				$valid_high = isValidIP($ip_parts[1]);
4201 4438
 				$count++;
4202
-				if ($count > 9) break;
4439
+				if ($count > 9) {
4440
+					break;
4441
+				}
4203 4442
 			}
4204 4443
 		}
4205 4444
 
@@ -4223,46 +4462,54 @@  discard block
 block discarded – undo
4223 4462
 {
4224 4463
 	global $modSettings;
4225 4464
 
4226
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4227
-		return $host;
4465
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4466
+			return $host;
4467
+	}
4228 4468
 	$t = microtime();
4229 4469
 
4230 4470
 	// Try the Linux host command, perhaps?
4231 4471
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4232 4472
 	{
4233
-		if (!isset($modSettings['host_to_dis']))
4234
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4235
-		else
4236
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4473
+		if (!isset($modSettings['host_to_dis'])) {
4474
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4475
+		} else {
4476
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4477
+		}
4237 4478
 
4238 4479
 		// Did host say it didn't find anything?
4239
-		if (strpos($test, 'not found') !== false)
4240
-			$host = '';
4480
+		if (strpos($test, 'not found') !== false) {
4481
+					$host = '';
4482
+		}
4241 4483
 		// Invalid server option?
4242
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4243
-			updateSettings(array('host_to_dis' => 1));
4484
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4485
+					updateSettings(array('host_to_dis' => 1));
4486
+		}
4244 4487
 		// Maybe it found something, after all?
4245
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4246
-			$host = $match[1];
4488
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4489
+					$host = $match[1];
4490
+		}
4247 4491
 	}
4248 4492
 
4249 4493
 	// This is nslookup; usually only Windows, but possibly some Unix?
4250 4494
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4251 4495
 	{
4252 4496
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4253
-		if (strpos($test, 'Non-existent domain') !== false)
4254
-			$host = '';
4255
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4256
-			$host = $match[1];
4497
+		if (strpos($test, 'Non-existent domain') !== false) {
4498
+					$host = '';
4499
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4500
+					$host = $match[1];
4501
+		}
4257 4502
 	}
4258 4503
 
4259 4504
 	// This is the last try :/.
4260
-	if (!isset($host) || $host === false)
4261
-		$host = @gethostbyaddr($ip);
4505
+	if (!isset($host) || $host === false) {
4506
+			$host = @gethostbyaddr($ip);
4507
+	}
4262 4508
 
4263 4509
 	// It took a long time, so let's cache it!
4264
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4265
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4510
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4511
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4512
+	}
4266 4513
 
4267 4514
 	return $host;
4268 4515
 }
@@ -4298,20 +4545,21 @@  discard block
 block discarded – undo
4298 4545
 			{
4299 4546
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4300 4547
 				$total = 0;
4301
-				for ($i = 0; $i < $max_chars; $i++)
4302
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4548
+				for ($i = 0; $i < $max_chars; $i++) {
4549
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4550
+				}
4303 4551
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4304 4552
 			}
4305 4553
 		}
4306 4554
 		return array_unique($returned_ints);
4307
-	}
4308
-	else
4555
+	} else
4309 4556
 	{
4310 4557
 		// Trim characters before and after and add slashes for database insertion.
4311 4558
 		$returned_words = array();
4312
-		foreach ($words as $word)
4313
-			if (($word = trim($word, '-_\'')) !== '')
4559
+		foreach ($words as $word) {
4560
+					if (($word = trim($word, '-_\'')) !== '')
4314 4561
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4562
+		}
4315 4563
 
4316 4564
 		// Filter out all words that occur more than once.
4317 4565
 		return array_unique($returned_words);
@@ -4333,16 +4581,18 @@  discard block
 block discarded – undo
4333 4581
 	global $settings, $txt;
4334 4582
 
4335 4583
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4336
-	if (function_exists('template_create_button') && !$force_use)
4337
-		return template_create_button($name, $alt, $label = '', $custom = '');
4584
+	if (function_exists('template_create_button') && !$force_use) {
4585
+			return template_create_button($name, $alt, $label = '', $custom = '');
4586
+	}
4338 4587
 
4339
-	if (!$settings['use_image_buttons'])
4340
-		return $txt[$alt];
4341
-	elseif (!empty($settings['use_buttons']))
4342
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4343
-	else
4344
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4345
-}
4588
+	if (!$settings['use_image_buttons']) {
4589
+			return $txt[$alt];
4590
+	} elseif (!empty($settings['use_buttons'])) {
4591
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4592
+	} else {
4593
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4594
+	}
4595
+	}
4346 4596
 
4347 4597
 /**
4348 4598
  * Sets up all of the top menu buttons
@@ -4385,9 +4635,10 @@  discard block
 block discarded – undo
4385 4635
 	var user_menus = new smc_PopupMenu();
4386 4636
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4387 4637
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4388
-		if ($context['allow_pm'])
4389
-			addInlineJavaScript('
4638
+		if ($context['allow_pm']) {
4639
+					addInlineJavaScript('
4390 4640
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4641
+		}
4391 4642
 
4392 4643
 		if (!empty($modSettings['enable_ajax_alerts']))
4393 4644
 		{
@@ -4547,88 +4798,96 @@  discard block
 block discarded – undo
4547 4798
 
4548 4799
 		// Now we put the buttons in the context so the theme can use them.
4549 4800
 		$menu_buttons = array();
4550
-		foreach ($buttons as $act => $button)
4551
-			if (!empty($button['show']))
4801
+		foreach ($buttons as $act => $button) {
4802
+					if (!empty($button['show']))
4552 4803
 			{
4553 4804
 				$button['active_button'] = false;
4805
+		}
4554 4806
 
4555 4807
 				// This button needs some action.
4556
-				if (isset($button['action_hook']))
4557
-					$needs_action_hook = true;
4808
+				if (isset($button['action_hook'])) {
4809
+									$needs_action_hook = true;
4810
+				}
4558 4811
 
4559 4812
 				// Make sure the last button truly is the last button.
4560 4813
 				if (!empty($button['is_last']))
4561 4814
 				{
4562
-					if (isset($last_button))
4563
-						unset($menu_buttons[$last_button]['is_last']);
4815
+					if (isset($last_button)) {
4816
+											unset($menu_buttons[$last_button]['is_last']);
4817
+					}
4564 4818
 					$last_button = $act;
4565 4819
 				}
4566 4820
 
4567 4821
 				// Go through the sub buttons if there are any.
4568
-				if (!empty($button['sub_buttons']))
4569
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4822
+				if (!empty($button['sub_buttons'])) {
4823
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4570 4824
 					{
4571 4825
 						if (empty($subbutton['show']))
4572 4826
 							unset($button['sub_buttons'][$key]);
4827
+				}
4573 4828
 
4574 4829
 						// 2nd level sub buttons next...
4575 4830
 						if (!empty($subbutton['sub_buttons']))
4576 4831
 						{
4577 4832
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4578 4833
 							{
4579
-								if (empty($sub_button2['show']))
4580
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4834
+								if (empty($sub_button2['show'])) {
4835
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4836
+								}
4581 4837
 							}
4582 4838
 						}
4583 4839
 					}
4584 4840
 
4585 4841
 				// Does this button have its own icon?
4586
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4587
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4588
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4589
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4590
-				elseif (isset($button['icon']))
4591
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4592
-				else
4593
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4842
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4843
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4844
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4845
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4846
+				} elseif (isset($button['icon'])) {
4847
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4848
+				} else {
4849
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4850
+				}
4594 4851
 
4595 4852
 				$menu_buttons[$act] = $button;
4596 4853
 			}
4597 4854
 
4598
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4599
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4855
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4856
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4857
+		}
4600 4858
 	}
4601 4859
 
4602 4860
 	$context['menu_buttons'] = $menu_buttons;
4603 4861
 
4604 4862
 	// Logging out requires the session id in the url.
4605
-	if (isset($context['menu_buttons']['logout']))
4606
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4863
+	if (isset($context['menu_buttons']['logout'])) {
4864
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4865
+	}
4607 4866
 
4608 4867
 	// Figure out which action we are doing so we can set the active tab.
4609 4868
 	// Default to home.
4610 4869
 	$current_action = 'home';
4611 4870
 
4612
-	if (isset($context['menu_buttons'][$context['current_action']]))
4613
-		$current_action = $context['current_action'];
4614
-	elseif ($context['current_action'] == 'search2')
4615
-		$current_action = 'search';
4616
-	elseif ($context['current_action'] == 'theme')
4617
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4618
-	elseif ($context['current_action'] == 'register2')
4619
-		$current_action = 'register';
4620
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4621
-		$current_action = 'login';
4622
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4623
-		$current_action = 'moderate';
4871
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4872
+			$current_action = $context['current_action'];
4873
+	} elseif ($context['current_action'] == 'search2') {
4874
+			$current_action = 'search';
4875
+	} elseif ($context['current_action'] == 'theme') {
4876
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4877
+	} elseif ($context['current_action'] == 'register2') {
4878
+			$current_action = 'register';
4879
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4880
+			$current_action = 'login';
4881
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4882
+			$current_action = 'moderate';
4883
+	}
4624 4884
 
4625 4885
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4626 4886
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4627 4887
 	{
4628 4888
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4629 4889
 		$context[$current_action] = true;
4630
-	}
4631
-	elseif ($context['current_action'] == 'pm')
4890
+	} elseif ($context['current_action'] == 'pm')
4632 4891
 	{
4633 4892
 		$current_action = 'self_pm';
4634 4893
 		$context['self_pm'] = true;
@@ -4685,12 +4944,14 @@  discard block
 block discarded – undo
4685 4944
 	}
4686 4945
 
4687 4946
 	// Not all actions are simple.
4688
-	if (!empty($needs_action_hook))
4689
-		call_integration_hook('integrate_current_action', array(&$current_action));
4947
+	if (!empty($needs_action_hook)) {
4948
+			call_integration_hook('integrate_current_action', array(&$current_action));
4949
+	}
4690 4950
 
4691
-	if (isset($context['menu_buttons'][$current_action]))
4692
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4693
-}
4951
+	if (isset($context['menu_buttons'][$current_action])) {
4952
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4953
+	}
4954
+	}
4694 4955
 
4695 4956
 /**
4696 4957
  * Generate a random seed and ensure it's stored in settings.
@@ -4714,30 +4975,35 @@  discard block
 block discarded – undo
4714 4975
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4715 4976
 	global $context, $txt;
4716 4977
 
4717
-	if ($db_show_debug === true)
4718
-		$context['debug']['hooks'][] = $hook;
4978
+	if ($db_show_debug === true) {
4979
+			$context['debug']['hooks'][] = $hook;
4980
+	}
4719 4981
 
4720 4982
 	// Need to have some control.
4721
-	if (!isset($context['instances']))
4722
-		$context['instances'] = array();
4983
+	if (!isset($context['instances'])) {
4984
+			$context['instances'] = array();
4985
+	}
4723 4986
 
4724 4987
 	$results = array();
4725
-	if (empty($modSettings[$hook]))
4726
-		return $results;
4988
+	if (empty($modSettings[$hook])) {
4989
+			return $results;
4990
+	}
4727 4991
 
4728 4992
 	$functions = explode(',', $modSettings[$hook]);
4729 4993
 	// Loop through each function.
4730 4994
 	foreach ($functions as $function)
4731 4995
 	{
4732 4996
 		// Hook has been marked as "disabled". Skip it!
4733
-		if (strpos($function, '!') !== false)
4734
-			continue;
4997
+		if (strpos($function, '!') !== false) {
4998
+					continue;
4999
+		}
4735 5000
 
4736 5001
 		$call = call_helper($function, true);
4737 5002
 
4738 5003
 		// Is it valid?
4739
-		if (!empty($call))
4740
-			$results[$function] = call_user_func_array($call, $parameters);
5004
+		if (!empty($call)) {
5005
+					$results[$function] = call_user_func_array($call, $parameters);
5006
+		}
4741 5007
 
4742 5008
 		// Whatever it was suppose to call, it failed :(
4743 5009
 		elseif (!empty($function))
@@ -4753,8 +5019,9 @@  discard block
 block discarded – undo
4753 5019
 			}
4754 5020
 
4755 5021
 			// "Assume" the file resides on $boarddir somewhere...
4756
-			else
4757
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5022
+			else {
5023
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5024
+			}
4758 5025
 		}
4759 5026
 	}
4760 5027
 
@@ -4776,12 +5043,14 @@  discard block
 block discarded – undo
4776 5043
 	global $smcFunc, $modSettings;
4777 5044
 
4778 5045
 	// Any objects?
4779
-	if ($object)
4780
-		$function = $function . '#';
5046
+	if ($object) {
5047
+			$function = $function . '#';
5048
+	}
4781 5049
 
4782 5050
 	// Any files  to load?
4783
-	if (!empty($file) && is_string($file))
4784
-		$function = $file . (!empty($function) ? '|' . $function : '');
5051
+	if (!empty($file) && is_string($file)) {
5052
+			$function = $file . (!empty($function) ? '|' . $function : '');
5053
+	}
4785 5054
 
4786 5055
 	// Get the correct string.
4787 5056
 	$integration_call = $function;
@@ -4803,13 +5072,14 @@  discard block
 block discarded – undo
4803 5072
 		if (!empty($current_functions))
4804 5073
 		{
4805 5074
 			$current_functions = explode(',', $current_functions);
4806
-			if (in_array($integration_call, $current_functions))
4807
-				return;
5075
+			if (in_array($integration_call, $current_functions)) {
5076
+							return;
5077
+			}
4808 5078
 
4809 5079
 			$permanent_functions = array_merge($current_functions, array($integration_call));
5080
+		} else {
5081
+					$permanent_functions = array($integration_call);
4810 5082
 		}
4811
-		else
4812
-			$permanent_functions = array($integration_call);
4813 5083
 
4814 5084
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4815 5085
 	}
@@ -4818,8 +5088,9 @@  discard block
 block discarded – undo
4818 5088
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4819 5089
 
4820 5090
 	// Do nothing, if it's already there.
4821
-	if (in_array($integration_call, $functions))
4822
-		return;
5091
+	if (in_array($integration_call, $functions)) {
5092
+			return;
5093
+	}
4823 5094
 
4824 5095
 	$functions[] = $integration_call;
4825 5096
 	$modSettings[$hook] = implode(',', $functions);
@@ -4842,12 +5113,14 @@  discard block
 block discarded – undo
4842 5113
 	global $smcFunc, $modSettings;
4843 5114
 
4844 5115
 	// Any objects?
4845
-	if ($object)
4846
-		$function = $function . '#';
5116
+	if ($object) {
5117
+			$function = $function . '#';
5118
+	}
4847 5119
 
4848 5120
 	// Any files  to load?
4849
-	if (!empty($file) && is_string($file))
4850
-		$function = $file . '|' . $function;
5121
+	if (!empty($file) && is_string($file)) {
5122
+			$function = $file . '|' . $function;
5123
+	}
4851 5124
 
4852 5125
 	// Get the correct string.
4853 5126
 	$integration_call = $function;
@@ -4868,16 +5141,18 @@  discard block
 block discarded – undo
4868 5141
 	{
4869 5142
 		$current_functions = explode(',', $current_functions);
4870 5143
 
4871
-		if (in_array($integration_call, $current_functions))
4872
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5144
+		if (in_array($integration_call, $current_functions)) {
5145
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5146
+		}
4873 5147
 	}
4874 5148
 
4875 5149
 	// Turn the function list into something usable.
4876 5150
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4877 5151
 
4878 5152
 	// You can only remove it if it's available.
4879
-	if (!in_array($integration_call, $functions))
4880
-		return;
5153
+	if (!in_array($integration_call, $functions)) {
5154
+			return;
5155
+	}
4881 5156
 
4882 5157
 	$functions = array_diff($functions, array($integration_call));
4883 5158
 	$modSettings[$hook] = implode(',', $functions);
@@ -4898,17 +5173,20 @@  discard block
 block discarded – undo
4898 5173
 	global $context, $smcFunc, $txt, $db_show_debug;
4899 5174
 
4900 5175
 	// Really?
4901
-	if (empty($string))
4902
-		return false;
5176
+	if (empty($string)) {
5177
+			return false;
5178
+	}
4903 5179
 
4904 5180
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4905 5181
 	// A closure? should be a callable one.
4906
-	if (is_array($string) || $string instanceof Closure)
4907
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5182
+	if (is_array($string) || $string instanceof Closure) {
5183
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5184
+	}
4908 5185
 
4909 5186
 	// No full objects, sorry! pass a method or a property instead!
4910
-	if (is_object($string))
4911
-		return false;
5187
+	if (is_object($string)) {
5188
+			return false;
5189
+	}
4912 5190
 
4913 5191
 	// Stay vitaminized my friends...
4914 5192
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4917,8 +5195,9 @@  discard block
 block discarded – undo
4917 5195
 	$string = load_file($string);
4918 5196
 
4919 5197
 	// Loaded file failed
4920
-	if (empty($string))
4921
-		return false;
5198
+	if (empty($string)) {
5199
+			return false;
5200
+	}
4922 5201
 
4923 5202
 	// Found a method.
4924 5203
 	if (strpos($string, '::') !== false)
@@ -4939,8 +5218,9 @@  discard block
 block discarded – undo
4939 5218
 				// Add another one to the list.
4940 5219
 				if ($db_show_debug === true)
4941 5220
 				{
4942
-					if (!isset($context['debug']['instances']))
4943
-						$context['debug']['instances'] = array();
5221
+					if (!isset($context['debug']['instances'])) {
5222
+											$context['debug']['instances'] = array();
5223
+					}
4944 5224
 
4945 5225
 					$context['debug']['instances'][$class] = $class;
4946 5226
 				}
@@ -4950,13 +5230,15 @@  discard block
 block discarded – undo
4950 5230
 		}
4951 5231
 
4952 5232
 		// Right then. This is a call to a static method.
4953
-		else
4954
-			$func = array($class, $method);
5233
+		else {
5234
+					$func = array($class, $method);
5235
+		}
4955 5236
 	}
4956 5237
 
4957 5238
 	// Nope! just a plain regular function.
4958
-	else
4959
-		$func = $string;
5239
+	else {
5240
+			$func = $string;
5241
+	}
4960 5242
 
4961 5243
 	// Right, we got what we need, time to do some checks.
4962 5244
 	if (!is_callable($func, false, $callable_name))
@@ -4972,17 +5254,18 @@  discard block
 block discarded – undo
4972 5254
 	else
4973 5255
 	{
4974 5256
 		// What are we gonna do about it?
4975
-		if ($return)
4976
-			return $func;
5257
+		if ($return) {
5258
+					return $func;
5259
+		}
4977 5260
 
4978 5261
 		// If this is a plain function, avoid the heat of calling call_user_func().
4979 5262
 		else
4980 5263
 		{
4981
-			if (is_array($func))
4982
-				call_user_func($func);
4983
-
4984
-			else
4985
-				$func();
5264
+			if (is_array($func)) {
5265
+							call_user_func($func);
5266
+			} else {
5267
+							$func();
5268
+			}
4986 5269
 		}
4987 5270
 	}
4988 5271
 }
@@ -4999,31 +5282,34 @@  discard block
 block discarded – undo
4999 5282
 {
5000 5283
 	global $sourcedir, $txt, $boarddir, $settings;
5001 5284
 
5002
-	if (empty($string))
5003
-		return false;
5285
+	if (empty($string)) {
5286
+			return false;
5287
+	}
5004 5288
 
5005 5289
 	if (strpos($string, '|') !== false)
5006 5290
 	{
5007 5291
 		list ($file, $string) = explode('|', $string);
5008 5292
 
5009 5293
 		// Match the wildcards to their regular vars.
5010
-		if (empty($settings['theme_dir']))
5011
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5012
-
5013
-		else
5014
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5294
+		if (empty($settings['theme_dir'])) {
5295
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5296
+		} else {
5297
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5298
+		}
5015 5299
 
5016 5300
 		// Load the file if it can be loaded.
5017
-		if (file_exists($absPath))
5018
-			require_once($absPath);
5301
+		if (file_exists($absPath)) {
5302
+					require_once($absPath);
5303
+		}
5019 5304
 
5020 5305
 		// No? try a fallback to $sourcedir
5021 5306
 		else
5022 5307
 		{
5023 5308
 			$absPath = $sourcedir .'/'. $file;
5024 5309
 
5025
-			if (file_exists($absPath))
5026
-				require_once($absPath);
5310
+			if (file_exists($absPath)) {
5311
+							require_once($absPath);
5312
+			}
5027 5313
 
5028 5314
 			// Sorry, can't do much for you at this point.
5029 5315
 			else
@@ -5062,8 +5348,9 @@  discard block
 block discarded – undo
5062 5348
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
5063 5349
 
5064 5350
 	// No scheme? No data for you!
5065
-	if (empty($match[1]))
5066
-		return false;
5351
+	if (empty($match[1])) {
5352
+			return false;
5353
+	}
5067 5354
 
5068 5355
 	// An FTP url. We should try connecting and RETRieving it...
5069 5356
 	elseif ($match[1] == 'ftp')
@@ -5073,23 +5360,26 @@  discard block
 block discarded – undo
5073 5360
 
5074 5361
 		// Establish a connection and attempt to enable passive mode.
5075 5362
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
5076
-		if ($ftp->error !== false || !$ftp->passive())
5077
-			return false;
5363
+		if ($ftp->error !== false || !$ftp->passive()) {
5364
+					return false;
5365
+		}
5078 5366
 
5079 5367
 		// I want that one *points*!
5080 5368
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
5081 5369
 
5082 5370
 		// Since passive mode worked (or we would have returned already!) open the connection.
5083 5371
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
5084
-		if (!$fp)
5085
-			return false;
5372
+		if (!$fp) {
5373
+					return false;
5374
+		}
5086 5375
 
5087 5376
 		// The server should now say something in acknowledgement.
5088 5377
 		$ftp->check_response(150);
5089 5378
 
5090 5379
 		$data = '';
5091
-		while (!feof($fp))
5092
-			$data .= fread($fp, 4096);
5380
+		while (!feof($fp)) {
5381
+					$data .= fread($fp, 4096);
5382
+		}
5093 5383
 		fclose($fp);
5094 5384
 
5095 5385
 		// All done, right?  Good.
@@ -5101,8 +5391,9 @@  discard block
 block discarded – undo
5101 5391
 	elseif (isset($match[1]) && $match[1] == 'http')
5102 5392
 	{
5103 5393
 		// First try to use fsockopen, because it is fastest.
5104
-		if ($keep_alive && $match[3] == $keep_alive_dom)
5105
-			$fp = $keep_alive_fp;
5394
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5395
+					$fp = $keep_alive_fp;
5396
+		}
5106 5397
 		if (empty($fp))
5107 5398
 		{
5108 5399
 			// Open the socket on the port we want...
@@ -5122,20 +5413,21 @@  discard block
 block discarded – undo
5122 5413
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
5123 5414
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5124 5415
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5125
-				if ($keep_alive)
5126
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5127
-				else
5128
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
5129
-			}
5130
-			else
5416
+				if ($keep_alive) {
5417
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5418
+				} else {
5419
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5420
+				}
5421
+			} else
5131 5422
 			{
5132 5423
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
5133 5424
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5134 5425
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5135
-				if ($keep_alive)
5136
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5137
-				else
5138
-					fwrite($fp, 'connection: close' . "\r\n");
5426
+				if ($keep_alive) {
5427
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5428
+				} else {
5429
+									fwrite($fp, 'connection: close' . "\r\n");
5430
+				}
5139 5431
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
5140 5432
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
5141 5433
 				fwrite($fp, $post_data);
@@ -5148,30 +5440,33 @@  discard block
 block discarded – undo
5148 5440
 			{
5149 5441
 				$header = '';
5150 5442
 				$location = '';
5151
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5152
-					if (strpos($header, 'location:') !== false)
5443
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5444
+									if (strpos($header, 'location:') !== false)
5153 5445
 						$location = trim(substr($header, strpos($header, ':') + 1));
5446
+				}
5154 5447
 
5155
-				if (empty($location))
5156
-					return false;
5157
-				else
5448
+				if (empty($location)) {
5449
+									return false;
5450
+				} else
5158 5451
 				{
5159
-					if (!$keep_alive)
5160
-						fclose($fp);
5452
+					if (!$keep_alive) {
5453
+											fclose($fp);
5454
+					}
5161 5455
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
5162 5456
 				}
5163 5457
 			}
5164 5458
 
5165 5459
 			// Make sure we get a 200 OK.
5166
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5167
-				return false;
5460
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5461
+							return false;
5462
+			}
5168 5463
 
5169 5464
 			// Skip the headers...
5170 5465
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5171 5466
 			{
5172
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5173
-					$content_length = $match[1];
5174
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5467
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5468
+									$content_length = $match[1];
5469
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5175 5470
 				{
5176 5471
 					$keep_alive_dom = null;
5177 5472
 					$keep_alive = false;
@@ -5183,17 +5478,19 @@  discard block
 block discarded – undo
5183 5478
 			$data = '';
5184 5479
 			if (isset($content_length))
5185 5480
 			{
5186
-				while (!feof($fp) && strlen($data) < $content_length)
5187
-					$data .= fread($fp, $content_length - strlen($data));
5188
-			}
5189
-			else
5481
+				while (!feof($fp) && strlen($data) < $content_length) {
5482
+									$data .= fread($fp, $content_length - strlen($data));
5483
+				}
5484
+			} else
5190 5485
 			{
5191
-				while (!feof($fp))
5192
-					$data .= fread($fp, 4096);
5486
+				while (!feof($fp)) {
5487
+									$data .= fread($fp, 4096);
5488
+				}
5193 5489
 			}
5194 5490
 
5195
-			if (!$keep_alive)
5196
-				fclose($fp);
5491
+			if (!$keep_alive) {
5492
+							fclose($fp);
5493
+			}
5197 5494
 		}
5198 5495
 
5199 5496
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5206,17 +5503,18 @@  discard block
 block discarded – undo
5206 5503
 			$fetch_data->get_url_data($url, $post_data);
5207 5504
 
5208 5505
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5209
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5210
-				$data = $fetch_data->result('body');
5211
-			else
5212
-				return false;
5506
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5507
+							$data = $fetch_data->result('body');
5508
+			} else {
5509
+							return false;
5510
+			}
5213 5511
 		}
5214 5512
 
5215 5513
 		// Neither fsockopen nor curl are available. Well, phooey.
5216
-		else
5217
-			return false;
5218
-	}
5219
-	else
5514
+		else {
5515
+					return false;
5516
+		}
5517
+	} else
5220 5518
 	{
5221 5519
 		// Umm, this shouldn't happen?
5222 5520
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5236,8 +5534,9 @@  discard block
 block discarded – undo
5236 5534
 	global $user_info, $smcFunc;
5237 5535
 
5238 5536
 	// Make sure we have something to work with.
5239
-	if (empty($topic))
5240
-		return array();
5537
+	if (empty($topic)) {
5538
+			return array();
5539
+	}
5241 5540
 
5242 5541
 
5243 5542
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5260,8 +5559,9 @@  discard block
 block discarded – undo
5260 5559
 				'topic' => $topic,
5261 5560
 			)
5262 5561
 		);
5263
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5264
-			$temp[] = (int) $row['content_id'];
5562
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5563
+					$temp[] = (int) $row['content_id'];
5564
+		}
5265 5565
 
5266 5566
 		cache_put_data($cache_key, $temp, $ttl);
5267 5567
 	}
@@ -5282,8 +5582,9 @@  discard block
 block discarded – undo
5282 5582
 {
5283 5583
 	global $context;
5284 5584
 
5285
-	if (empty($string))
5286
-		return $string;
5585
+	if (empty($string)) {
5586
+			return $string;
5587
+	}
5287 5588
 
5288 5589
 	// UTF-8 occurences of MS special characters
5289 5590
 	$findchars_utf8 = array(
@@ -5324,10 +5625,11 @@  discard block
 block discarded – undo
5324 5625
 		'--',	// &mdash;
5325 5626
 	);
5326 5627
 
5327
-	if ($context['utf8'])
5328
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5329
-	else
5330
-		$string = str_replace($findchars_iso, $replacechars, $string);
5628
+	if ($context['utf8']) {
5629
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5630
+	} else {
5631
+			$string = str_replace($findchars_iso, $replacechars, $string);
5632
+	}
5331 5633
 
5332 5634
 	return $string;
5333 5635
 }
@@ -5346,49 +5648,59 @@  discard block
 block discarded – undo
5346 5648
 {
5347 5649
 	global $context;
5348 5650
 
5349
-	if (!isset($matches[2]))
5350
-		return '';
5651
+	if (!isset($matches[2])) {
5652
+			return '';
5653
+	}
5351 5654
 
5352 5655
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5353 5656
 
5354 5657
 	// remove left to right / right to left overrides
5355
-	if ($num === 0x202D || $num === 0x202E)
5356
-		return '';
5658
+	if ($num === 0x202D || $num === 0x202E) {
5659
+			return '';
5660
+	}
5357 5661
 
5358 5662
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5359
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5360
-		return '&#' . $num . ';';
5663
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5664
+			return '&#' . $num . ';';
5665
+	}
5361 5666
 
5362 5667
 	if (empty($context['utf8']))
5363 5668
 	{
5364 5669
 		// no control characters
5365
-		if ($num < 0x20)
5366
-			return '';
5670
+		if ($num < 0x20) {
5671
+					return '';
5672
+		}
5367 5673
 		// text is text
5368
-		elseif ($num < 0x80)
5369
-			return chr($num);
5674
+		elseif ($num < 0x80) {
5675
+					return chr($num);
5676
+		}
5370 5677
 		// all others get html-ised
5371
-		else
5372
-			return '&#' . $matches[2] . ';';
5373
-	}
5374
-	else
5678
+		else {
5679
+					return '&#' . $matches[2] . ';';
5680
+		}
5681
+	} else
5375 5682
 	{
5376 5683
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5377 5684
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5378
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5379
-			return '';
5685
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5686
+					return '';
5687
+		}
5380 5688
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5381
-		elseif ($num < 0x80)
5382
-			return chr($num);
5689
+		elseif ($num < 0x80) {
5690
+					return chr($num);
5691
+		}
5383 5692
 		// <0x800 (2048)
5384
-		elseif ($num < 0x800)
5385
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5693
+		elseif ($num < 0x800) {
5694
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5695
+		}
5386 5696
 		// < 0x10000 (65536)
5387
-		elseif ($num < 0x10000)
5388
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5697
+		elseif ($num < 0x10000) {
5698
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5699
+		}
5389 5700
 		// <= 0x10FFFF (1114111)
5390
-		else
5391
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5701
+		else {
5702
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5703
+		}
5392 5704
 	}
5393 5705
 }
5394 5706
 
@@ -5404,28 +5716,34 @@  discard block
 block discarded – undo
5404 5716
  */
5405 5717
 function fixchar__callback($matches)
5406 5718
 {
5407
-	if (!isset($matches[1]))
5408
-		return '';
5719
+	if (!isset($matches[1])) {
5720
+			return '';
5721
+	}
5409 5722
 
5410 5723
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5411 5724
 
5412 5725
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5413 5726
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5414
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5415
-		return '';
5727
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5728
+			return '';
5729
+	}
5416 5730
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5417
-	elseif ($num < 0x80)
5418
-		return chr($num);
5731
+	elseif ($num < 0x80) {
5732
+			return chr($num);
5733
+	}
5419 5734
 	// <0x800 (2048)
5420
-	elseif ($num < 0x800)
5421
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5735
+	elseif ($num < 0x800) {
5736
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5737
+	}
5422 5738
 	// < 0x10000 (65536)
5423
-	elseif ($num < 0x10000)
5424
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5739
+	elseif ($num < 0x10000) {
5740
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5741
+	}
5425 5742
 	// <= 0x10FFFF (1114111)
5426
-	else
5427
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5428
-}
5743
+	else {
5744
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5745
+	}
5746
+	}
5429 5747
 
5430 5748
 /**
5431 5749
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5438,17 +5756,19 @@  discard block
 block discarded – undo
5438 5756
  */
5439 5757
 function entity_fix__callback($matches)
5440 5758
 {
5441
-	if (!isset($matches[2]))
5442
-		return '';
5759
+	if (!isset($matches[2])) {
5760
+			return '';
5761
+	}
5443 5762
 
5444 5763
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5445 5764
 
5446 5765
 	// we don't allow control characters, characters out of range, byte markers, etc
5447
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5448
-		return '';
5449
-	else
5450
-		return '&#' . $num . ';';
5451
-}
5766
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5767
+			return '';
5768
+	} else {
5769
+			return '&#' . $num . ';';
5770
+	}
5771
+	}
5452 5772
 
5453 5773
 /**
5454 5774
  * Return a Gravatar URL based on
@@ -5472,18 +5792,23 @@  discard block
 block discarded – undo
5472 5792
 		$ratings = array('G', 'PG', 'R', 'X');
5473 5793
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5474 5794
 		$url_params = array();
5475
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5476
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5477
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5478
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5479
-		if (!empty($modSettings['avatar_max_width_external']))
5480
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5481
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5482
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5795
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5796
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5797
+		}
5798
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5799
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5800
+		}
5801
+		if (!empty($modSettings['avatar_max_width_external'])) {
5802
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5803
+		}
5804
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5805
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5483 5806
 				$size_string = $modSettings['avatar_max_height_external'];
5807
+		}
5484 5808
 
5485
-		if (!empty($size_string))
5486
-			$url_params[] = 's=' . $size_string;
5809
+		if (!empty($size_string)) {
5810
+					$url_params[] = 's=' . $size_string;
5811
+		}
5487 5812
 	}
5488 5813
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5489 5814
 
@@ -5502,22 +5827,26 @@  discard block
 block discarded – undo
5502 5827
 	static $timezones = null, $lastwhen = null;
5503 5828
 
5504 5829
 	// No point doing this over if we already did it once
5505
-	if (!empty($timezones) && $when == $lastwhen)
5506
-		return $timezones;
5507
-	else
5508
-		$lastwhen = $when;
5830
+	if (!empty($timezones) && $when == $lastwhen) {
5831
+			return $timezones;
5832
+	} else {
5833
+			$lastwhen = $when;
5834
+	}
5509 5835
 
5510 5836
 	// Parseable datetime string?
5511
-	if (is_int($timestamp = strtotime($when)))
5512
-		$when = $timestamp;
5837
+	if (is_int($timestamp = strtotime($when))) {
5838
+			$when = $timestamp;
5839
+	}
5513 5840
 
5514 5841
 	// A Unix timestamp?
5515
-	elseif (is_numeric($when))
5516
-		$when = intval($when);
5842
+	elseif (is_numeric($when)) {
5843
+			$when = intval($when);
5844
+	}
5517 5845
 
5518 5846
 	// Invalid value? Just get current Unix timestamp.
5519
-	else
5520
-		$when = time();
5847
+	else {
5848
+			$when = time();
5849
+	}
5521 5850
 
5522 5851
 	// We'll need these too
5523 5852
 	$date_when = date_create('@' . $when);
@@ -5532,8 +5861,9 @@  discard block
 block discarded – undo
5532 5861
 	foreach ($priority_countries as $country)
5533 5862
 	{
5534 5863
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5535
-		if (!empty($country_tzids))
5536
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5864
+		if (!empty($country_tzids)) {
5865
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5866
+		}
5537 5867
 	}
5538 5868
 
5539 5869
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5547,8 +5877,9 @@  discard block
 block discarded – undo
5547 5877
 	foreach ($tzids as $tzid)
5548 5878
 	{
5549 5879
 		// We don't want UTC right now
5550
-		if ($tzid == 'UTC')
5551
-			continue;
5880
+		if ($tzid == 'UTC') {
5881
+					continue;
5882
+		}
5552 5883
 
5553 5884
 		$tz = timezone_open($tzid);
5554 5885
 
@@ -5569,13 +5900,14 @@  discard block
 block discarded – undo
5569 5900
 		}
5570 5901
 
5571 5902
 		// A time zone from a prioritized country?
5572
-		if (in_array($tzid, $priority_tzids))
5573
-			$priority_zones[$tzkey] = true;
5903
+		if (in_array($tzid, $priority_tzids)) {
5904
+					$priority_zones[$tzkey] = true;
5905
+		}
5574 5906
 
5575 5907
 		// Keep track of the location and offset for this tzid
5576
-		if (!empty($txt[$tzid]))
5577
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5578
-		else
5908
+		if (!empty($txt[$tzid])) {
5909
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5910
+		} else
5579 5911
 		{
5580 5912
 			$tzid_parts = explode('/', $tzid);
5581 5913
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5595,23 +5927,27 @@  discard block
 block discarded – undo
5595 5927
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5596 5928
 
5597 5929
 		// Use the custom description, if there is one
5598
-		if (!empty($tztxt[$tzvalue['tzid']]))
5599
-			$desc = $tztxt[$tzvalue['tzid']];
5930
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5931
+					$desc = $tztxt[$tzvalue['tzid']];
5932
+		}
5600 5933
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5601
-		else
5602
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5934
+		else {
5935
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5936
+		}
5603 5937
 
5604 5938
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5605 5939
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5606 5940
 
5607
-		if (isset($priority_zones[$tzkey]))
5608
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5609
-		else
5610
-			$timezones[$tzvalue['tzid']] = $desc;
5941
+		if (isset($priority_zones[$tzkey])) {
5942
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5943
+		} else {
5944
+					$timezones[$tzvalue['tzid']] = $desc;
5945
+		}
5611 5946
 	}
5612 5947
 
5613
-	if (!empty($priority_timezones))
5614
-		$priority_timezones[] = '-----';
5948
+	if (!empty($priority_timezones)) {
5949
+			$priority_timezones[] = '-----';
5950
+	}
5615 5951
 
5616 5952
 	$timezones = array_merge(
5617 5953
 		$priority_timezones,
@@ -5628,8 +5964,9 @@  discard block
 block discarded – undo
5628 5964
  */
5629 5965
 function inet_ptod($ip_address)
5630 5966
 {
5631
-	if (!isValidIP($ip_address))
5632
-		return $ip_address;
5967
+	if (!isValidIP($ip_address)) {
5968
+			return $ip_address;
5969
+	}
5633 5970
 
5634 5971
 	$bin = inet_pton($ip_address);
5635 5972
 	return $bin;
@@ -5641,13 +5978,15 @@  discard block
 block discarded – undo
5641 5978
  */
5642 5979
 function inet_dtop($bin)
5643 5980
 {
5644
-	if(empty($bin))
5645
-		return '';
5981
+	if(empty($bin)) {
5982
+			return '';
5983
+	}
5646 5984
 
5647 5985
 	global $db_type;
5648 5986
 
5649
-	if ($db_type == 'postgresql')
5650
-		return $bin;
5987
+	if ($db_type == 'postgresql') {
5988
+			return $bin;
5989
+	}
5651 5990
 
5652 5991
 	$ip_address = inet_ntop($bin);
5653 5992
 
@@ -5672,26 +6011,32 @@  discard block
 block discarded – undo
5672 6011
  */
5673 6012
 function _safe_serialize($value)
5674 6013
 {
5675
-	if(is_null($value))
5676
-		return 'N;';
6014
+	if(is_null($value)) {
6015
+			return 'N;';
6016
+	}
5677 6017
 
5678
-	if(is_bool($value))
5679
-		return 'b:'. (int) $value .';';
6018
+	if(is_bool($value)) {
6019
+			return 'b:'. (int) $value .';';
6020
+	}
5680 6021
 
5681
-	if(is_int($value))
5682
-		return 'i:'. $value .';';
6022
+	if(is_int($value)) {
6023
+			return 'i:'. $value .';';
6024
+	}
5683 6025
 
5684
-	if(is_float($value))
5685
-		return 'd:'. str_replace(',', '.', $value) .';';
6026
+	if(is_float($value)) {
6027
+			return 'd:'. str_replace(',', '.', $value) .';';
6028
+	}
5686 6029
 
5687
-	if(is_string($value))
5688
-		return 's:'. strlen($value) .':"'. $value .'";';
6030
+	if(is_string($value)) {
6031
+			return 's:'. strlen($value) .':"'. $value .'";';
6032
+	}
5689 6033
 
5690 6034
 	if(is_array($value))
5691 6035
 	{
5692 6036
 		$out = '';
5693
-		foreach($value as $k => $v)
5694
-			$out .= _safe_serialize($k) . _safe_serialize($v);
6037
+		foreach($value as $k => $v) {
6038
+					$out .= _safe_serialize($k) . _safe_serialize($v);
6039
+		}
5695 6040
 
5696 6041
 		return 'a:'. count($value) .':{'. $out .'}';
5697 6042
 	}
@@ -5717,8 +6062,9 @@  discard block
 block discarded – undo
5717 6062
 
5718 6063
 	$out = _safe_serialize($value);
5719 6064
 
5720
-	if (isset($mbIntEnc))
5721
-		mb_internal_encoding($mbIntEnc);
6065
+	if (isset($mbIntEnc)) {
6066
+			mb_internal_encoding($mbIntEnc);
6067
+	}
5722 6068
 
5723 6069
 	return $out;
5724 6070
 }
@@ -5735,8 +6081,9 @@  discard block
 block discarded – undo
5735 6081
 function _safe_unserialize($str)
5736 6082
 {
5737 6083
 	// Input  is not a string.
5738
-	if(empty($str) || !is_string($str))
5739
-		return false;
6084
+	if(empty($str) || !is_string($str)) {
6085
+			return false;
6086
+	}
5740 6087
 
5741 6088
 	$stack = array();
5742 6089
 	$expected = array();
@@ -5752,43 +6099,38 @@  discard block
 block discarded – undo
5752 6099
 	while($state != 1)
5753 6100
 	{
5754 6101
 		$type = isset($str[0]) ? $str[0] : '';
5755
-		if($type == '}')
5756
-			$str = substr($str, 1);
5757
-
5758
-		else if($type == 'N' && $str[1] == ';')
6102
+		if($type == '}') {
6103
+					$str = substr($str, 1);
6104
+		} else if($type == 'N' && $str[1] == ';')
5759 6105
 		{
5760 6106
 			$value = null;
5761 6107
 			$str = substr($str, 2);
5762
-		}
5763
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
6108
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5764 6109
 		{
5765 6110
 			$value = $matches[1] == '1' ? true : false;
5766 6111
 			$str = substr($str, 4);
5767
-		}
5768
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
6112
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5769 6113
 		{
5770 6114
 			$value = (int)$matches[1];
5771 6115
 			$str = $matches[2];
5772
-		}
5773
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
6116
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5774 6117
 		{
5775 6118
 			$value = (float)$matches[1];
5776 6119
 			$str = $matches[3];
5777
-		}
5778
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
6120
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5779 6121
 		{
5780 6122
 			$value = substr($matches[2], 0, (int)$matches[1]);
5781 6123
 			$str = substr($matches[2], (int)$matches[1] + 2);
5782
-		}
5783
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
6124
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5784 6125
 		{
5785 6126
 			$expectedLength = (int)$matches[1];
5786 6127
 			$str = $matches[2];
5787 6128
 		}
5788 6129
 
5789 6130
 		// Object or unknown/malformed type.
5790
-		else
5791
-			return false;
6131
+		else {
6132
+					return false;
6133
+		}
5792 6134
 
5793 6135
 		switch($state)
5794 6136
 		{
@@ -5816,8 +6158,9 @@  discard block
 block discarded – undo
5816 6158
 				if($type == '}')
5817 6159
 				{
5818 6160
 					// Array size is less than expected.
5819
-					if(count($list) < end($expected))
5820
-						return false;
6161
+					if(count($list) < end($expected)) {
6162
+											return false;
6163
+					}
5821 6164
 
5822 6165
 					unset($list);
5823 6166
 					$list = &$stack[count($stack)-1];
@@ -5826,8 +6169,9 @@  discard block
 block discarded – undo
5826 6169
 					// Go to terminal state if we're at the end of the root array.
5827 6170
 					array_pop($expected);
5828 6171
 
5829
-					if(count($expected) == 0)
5830
-						$state = 1;
6172
+					if(count($expected) == 0) {
6173
+											$state = 1;
6174
+					}
5831 6175
 
5832 6176
 					break;
5833 6177
 				}
@@ -5835,8 +6179,9 @@  discard block
 block discarded – undo
5835 6179
 				if($type == 'i' || $type == 's')
5836 6180
 				{
5837 6181
 					// Array size exceeds expected length.
5838
-					if(count($list) >= end($expected))
5839
-						return false;
6182
+					if(count($list) >= end($expected)) {
6183
+											return false;
6184
+					}
5840 6185
 
5841 6186
 					$key = $value;
5842 6187
 					$state = 3;
@@ -5870,8 +6215,9 @@  discard block
 block discarded – undo
5870 6215
 	}
5871 6216
 
5872 6217
 	// Trailing data in input.
5873
-	if(!empty($str))
5874
-		return false;
6218
+	if(!empty($str)) {
6219
+			return false;
6220
+	}
5875 6221
 
5876 6222
 	return $data;
5877 6223
 }
@@ -5894,8 +6240,9 @@  discard block
 block discarded – undo
5894 6240
 
5895 6241
 	$out = _safe_unserialize($str);
5896 6242
 
5897
-	if (isset($mbIntEnc))
5898
-		mb_internal_encoding($mbIntEnc);
6243
+	if (isset($mbIntEnc)) {
6244
+			mb_internal_encoding($mbIntEnc);
6245
+	}
5899 6246
 
5900 6247
 	return $out;
5901 6248
 }
@@ -5910,12 +6257,14 @@  discard block
 block discarded – undo
5910 6257
 function smf_chmod($file, $value = 0)
5911 6258
 {
5912 6259
 	// No file? no checks!
5913
-	if (empty($file))
5914
-		return false;
6260
+	if (empty($file)) {
6261
+			return false;
6262
+	}
5915 6263
 
5916 6264
 	// Already writable?
5917
-	if (is_writable($file))
5918
-		return true;
6265
+	if (is_writable($file)) {
6266
+			return true;
6267
+	}
5919 6268
 
5920 6269
 	// Do we have a file or a dir?
5921 6270
 	$isDir = is_dir($file);
@@ -5931,10 +6280,9 @@  discard block
 block discarded – undo
5931 6280
 		{
5932 6281
 			$isWritable = true;
5933 6282
 			break;
6283
+		} else {
6284
+					@chmod($file, $val);
5934 6285
 		}
5935
-
5936
-		else
5937
-			@chmod($file, $val);
5938 6286
 	}
5939 6287
 
5940 6288
 	return $isWritable;
@@ -5953,8 +6301,9 @@  discard block
 block discarded – undo
5953 6301
 	global $txt;
5954 6302
 
5955 6303
 	// Come on...
5956
-	if (empty($json) || !is_string($json))
5957
-		return array();
6304
+	if (empty($json) || !is_string($json)) {
6305
+			return array();
6306
+	}
5958 6307
 
5959 6308
 	$returnArray = @json_decode($json, $returnAsArray);
5960 6309
 
@@ -5992,11 +6341,11 @@  discard block
 block discarded – undo
5992 6341
 		$jsonDebug = $jsonDebug[0];
5993 6342
 		loadLanguage('Errors');
5994 6343
 
5995
-		if (!empty($jsonDebug))
5996
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5997
-
5998
-		else
5999
-			log_error($txt['json_'. $jsonError], 'critical');
6344
+		if (!empty($jsonDebug)) {
6345
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6346
+		} else {
6347
+					log_error($txt['json_'. $jsonError], 'critical');
6348
+		}
6000 6349
 
6001 6350
 		// Everyone expects an array.
6002 6351
 		return array();
@@ -6030,8 +6379,9 @@  discard block
 block discarded – undo
6030 6379
 	global $db_show_debug, $modSettings;
6031 6380
 
6032 6381
 	// Defensive programming anyone?
6033
-	if (empty($data))
6034
-		return false;
6382
+	if (empty($data)) {
6383
+			return false;
6384
+	}
6035 6385
 
6036 6386
 	// Don't need extra stuff...
6037 6387
 	$db_show_debug = false;
@@ -6039,11 +6389,11 @@  discard block
 block discarded – undo
6039 6389
 	// Kill anything else.
6040 6390
 	ob_end_clean();
6041 6391
 
6042
-	if (!empty($modSettings['CompressedOutput']))
6043
-		@ob_start('ob_gzhandler');
6044
-
6045
-	else
6046
-		ob_start();
6392
+	if (!empty($modSettings['CompressedOutput'])) {
6393
+			@ob_start('ob_gzhandler');
6394
+	} else {
6395
+			ob_start();
6396
+	}
6047 6397
 
6048 6398
 	// Set the header.
6049 6399
 	header($type);
@@ -6075,8 +6425,9 @@  discard block
 block discarded – undo
6075 6425
 	static $done = false;
6076 6426
 
6077 6427
 	// If we don't need to do anything, don't
6078
-	if (!$update && $done)
6079
-		return;
6428
+	if (!$update && $done) {
6429
+			return;
6430
+	}
6080 6431
 
6081 6432
 	// Should we get a new copy of the official list of TLDs?
6082 6433
 	if ($update)
@@ -6088,8 +6439,9 @@  discard block
 block discarded – undo
6088 6439
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
6089 6440
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
6090 6441
 		// update to see if civilization has been restored.
6091
-		if ($tlds === false)
6092
-			$postapocalypticNightmare = true;
6442
+		if ($tlds === false) {
6443
+					$postapocalypticNightmare = true;
6444
+		}
6093 6445
 	}
6094 6446
 	// If we aren't updating and the regex is valid, we're done
6095 6447
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -6104,10 +6456,11 @@  discard block
 block discarded – undo
6104 6456
 		// Clean $tlds and convert it to an array
6105 6457
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
6106 6458
 			$line = trim($line);
6107
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
6108
-				return false;
6109
-			else
6110
-				return true;
6459
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6460
+							return false;
6461
+			} else {
6462
+							return true;
6463
+			}
6111 6464
 		});
6112 6465
 
6113 6466
 		// Convert Punycode to Unicode
@@ -6199,8 +6552,7 @@  discard block
 block discarded – undo
6199 6552
 
6200 6553
 		$strlen = 'mb_strlen';
6201 6554
 		$substr = 'mb_substr';
6202
-	}
6203
-	else
6555
+	} else
6204 6556
 	{
6205 6557
 		$strlen = $smcFunc['strlen'];
6206 6558
 		$substr = $smcFunc['substr'];
@@ -6214,20 +6566,21 @@  discard block
 block discarded – undo
6214 6566
 
6215 6567
 		$first = $substr($string, 0, 1);
6216 6568
 
6217
-		if (empty($index[$first]))
6218
-			$index[$first] = array();
6569
+		if (empty($index[$first])) {
6570
+					$index[$first] = array();
6571
+		}
6219 6572
 
6220 6573
 		if ($strlen($string) > 1)
6221 6574
 		{
6222 6575
 			// Sanity check on recursion
6223
-			if ($depth > 99)
6224
-				$index[$first][$substr($string, 1)] = '';
6225
-
6226
-			else
6227
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6576
+			if ($depth > 99) {
6577
+							$index[$first][$substr($string, 1)] = '';
6578
+			} else {
6579
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6580
+			}
6581
+		} else {
6582
+					$index[$first][''] = '';
6228 6583
 		}
6229
-		else
6230
-			$index[$first][''] = '';
6231 6584
 
6232 6585
 		$depth--;
6233 6586
 		return $index;
@@ -6250,9 +6603,9 @@  discard block
 block discarded – undo
6250 6603
 			$key_regex = preg_quote($key, $delim);
6251 6604
 			$new_key = $key;
6252 6605
 
6253
-			if (empty($value))
6254
-				$sub_regex = '';
6255
-			else
6606
+			if (empty($value)) {
6607
+							$sub_regex = '';
6608
+			} else
6256 6609
 			{
6257 6610
 				$sub_regex = $index_to_regex($value, $delim);
6258 6611
 
@@ -6260,22 +6613,22 @@  discard block
 block discarded – undo
6260 6613
 				{
6261 6614
 					$new_key_array = explode('(?'.'>', $sub_regex);
6262 6615
 					$new_key .= $new_key_array[0];
6616
+				} else {
6617
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6263 6618
 				}
6264
-				else
6265
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6266 6619
 			}
6267 6620
 
6268
-			if ($depth > 1)
6269
-				$regex[$new_key] = $key_regex . $sub_regex;
6270
-			else
6621
+			if ($depth > 1) {
6622
+							$regex[$new_key] = $key_regex . $sub_regex;
6623
+			} else
6271 6624
 			{
6272 6625
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6273 6626
 				{
6274 6627
 					$regex[$new_key] = $key_regex . $sub_regex;
6275 6628
 					unset($index[$key]);
6629
+				} else {
6630
+									break;
6276 6631
 				}
6277
-				else
6278
-					break;
6279 6632
 			}
6280 6633
 		}
6281 6634
 
@@ -6284,10 +6637,11 @@  discard block
 block discarded – undo
6284 6637
 			$l1 = $strlen($k1);
6285 6638
 			$l2 = $strlen($k2);
6286 6639
 
6287
-			if ($l1 == $l2)
6288
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6289
-			else
6290
-				return $l1 > $l2 ? -1 : 1;
6640
+			if ($l1 == $l2) {
6641
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6642
+			} else {
6643
+							return $l1 > $l2 ? -1 : 1;
6644
+			}
6291 6645
 		});
6292 6646
 
6293 6647
 		$depth--;
@@ -6298,21 +6652,24 @@  discard block
 block discarded – undo
6298 6652
 	$index = array();
6299 6653
 	$regex = '';
6300 6654
 
6301
-	foreach ($strings as $string)
6302
-		$index = $add_string_to_index($string, $index);
6655
+	foreach ($strings as $string) {
6656
+			$index = $add_string_to_index($string, $index);
6657
+	}
6303 6658
 
6304 6659
 	if ($returnArray === true)
6305 6660
 	{
6306 6661
 		$regex = array();
6307
-		while (!empty($index))
6308
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6662
+		while (!empty($index)) {
6663
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6664
+		}
6665
+	} else {
6666
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6309 6667
 	}
6310
-	else
6311
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6312 6668
 
6313 6669
 	// Restore PHP's internal character encoding to whatever it was originally
6314
-	if (!empty($current_encoding))
6315
-		mb_internal_encoding($current_encoding);
6670
+	if (!empty($current_encoding)) {
6671
+			mb_internal_encoding($current_encoding);
6672
+	}
6316 6673
 
6317 6674
 	return $regex;
6318 6675
 }
@@ -6355,13 +6712,15 @@  discard block
 block discarded – undo
6355 6712
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6356 6713
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6357 6714
 	$headers = @get_headers($url);
6358
-	if ($headers === false)
6359
-		return false;
6715
+	if ($headers === false) {
6716
+			return false;
6717
+	}
6360 6718
 
6361 6719
 	// Now to see if it came back https...
6362 6720
 	// First check for a redirect status code in first row (301, 302, 307)
6363
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6364
-		return false;
6721
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6722
+			return false;
6723
+	}
6365 6724
 
6366 6725
 	// Search for the location entry to confirm https
6367 6726
 	$result = false;
@@ -6399,8 +6758,7 @@  discard block
 block discarded – undo
6399 6758
 		$is_admin = $user_info['is_admin'];
6400 6759
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6401 6760
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6402
-	}
6403
-	else
6761
+	} else
6404 6762
 	{
6405 6763
 		$request = $smcFunc['db_query']('', '
6406 6764
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6414,17 +6772,19 @@  discard block
 block discarded – undo
6414 6772
 
6415 6773
 		$row = $smcFunc['db_fetch_assoc']($request);
6416 6774
 
6417
-		if (empty($row['additional_groups']))
6418
-			$groups = array($row['id_group'], $row['id_post_group']);
6419
-		else
6420
-			$groups = array_merge(
6775
+		if (empty($row['additional_groups'])) {
6776
+					$groups = array($row['id_group'], $row['id_post_group']);
6777
+		} else {
6778
+					$groups = array_merge(
6421 6779
 					array($row['id_group'], $row['id_post_group']),
6422 6780
 					explode(',', $row['additional_groups'])
6423 6781
 			);
6782
+		}
6424 6783
 
6425 6784
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6426
-		foreach ($groups as $k => $v)
6427
-			$groups[$k] = (int) $v;
6785
+		foreach ($groups as $k => $v) {
6786
+					$groups[$k] = (int) $v;
6787
+		}
6428 6788
 
6429 6789
 		$is_admin = in_array(1, $groups);
6430 6790
 
@@ -6441,8 +6801,9 @@  discard block
 block discarded – undo
6441 6801
 				'current_member' => $userid,
6442 6802
 			)
6443 6803
 		);
6444
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6445
-			$boards_mod[] = $row['id_board'];
6804
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6805
+					$boards_mod[] = $row['id_board'];
6806
+		}
6446 6807
 		$smcFunc['db_free_result']($request);
6447 6808
 
6448 6809
 		// Can any of the groups they're in moderate any of the boards?
@@ -6454,8 +6815,9 @@  discard block
 block discarded – undo
6454 6815
 				'groups' => $groups,
6455 6816
 			)
6456 6817
 		);
6457
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6458
-			$boards_mod[] = $row['id_board'];
6818
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6819
+					$boards_mod[] = $row['id_board'];
6820
+		}
6459 6821
 		$smcFunc['db_free_result']($request);
6460 6822
 
6461 6823
 		// Just in case we've got duplicates here...
@@ -6465,21 +6827,25 @@  discard block
 block discarded – undo
6465 6827
 	}
6466 6828
 
6467 6829
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6468
-	if ($is_admin)
6469
-		$query_part['query_see_board'] = '1=1';
6830
+	if ($is_admin) {
6831
+			$query_part['query_see_board'] = '1=1';
6832
+	}
6470 6833
 	// Otherwise just the groups in $user_info['groups'].
6471
-	else
6472
-		$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6834
+	else {
6835
+			$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6836
+	}
6473 6837
 
6474 6838
 	// Build the list of boards they WANT to see.
6475 6839
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6476 6840
 
6477 6841
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6478
-	if (empty($ignoreboards))
6479
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6842
+	if (empty($ignoreboards)) {
6843
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6844
+	}
6480 6845
 	// Ok I guess they don't want to see all the boards
6481
-	else
6482
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6846
+	else {
6847
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6848
+	}
6483 6849
 
6484 6850
 	return $query_part;
6485 6851
 }
@@ -6493,10 +6859,11 @@  discard block
 block discarded – undo
6493 6859
 {
6494 6860
 	$secure = false;
6495 6861
 
6496
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6497
-		$secure = true;
6498
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
6499
-		$secure = true;
6862
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6863
+			$secure = true;
6864
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
6865
+			$secure = true;
6866
+	}
6500 6867
 
6501 6868
 	return $secure;
6502 6869
 }
@@ -6513,11 +6880,12 @@  discard block
 block discarded – undo
6513 6880
 {
6514 6881
 	$url = iri_to_url($iri);
6515 6882
 
6516
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6517
-		return $iri;
6518
-	else
6519
-		return false;
6520
-}
6883
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6884
+			return $iri;
6885
+	} else {
6886
+			return false;
6887
+	}
6888
+	}
6521 6889
 
6522 6890
 /**
6523 6891
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6560,8 +6928,9 @@  discard block
 block discarded – undo
6560 6928
 
6561 6929
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6562 6930
 
6563
-	if (empty($host))
6564
-		return $iri;
6931
+	if (empty($host)) {
6932
+			return $iri;
6933
+	}
6565 6934
 
6566 6935
 	// Convert the domain using the Punycode algorithm
6567 6936
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6597,8 +6966,9 @@  discard block
 block discarded – undo
6597 6966
 
6598 6967
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6599 6968
 
6600
-	if (empty($host))
6601
-		return $url;
6969
+	if (empty($host)) {
6970
+			return $url;
6971
+	}
6602 6972
 
6603 6973
 	// Decode the domain from Punycode
6604 6974
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6624,8 +6994,9 @@  discard block
 block discarded – undo
6624 6994
 {
6625 6995
 	global $user_info, $modSettings, $smcFunc, $txt;
6626 6996
 
6627
-	if (empty($modSettings['cron_last_checked']))
6628
-		$modSettings['cron_last_checked'] = 0;
6997
+	if (empty($modSettings['cron_last_checked'])) {
6998
+			$modSettings['cron_last_checked'] = 0;
6999
+	}
6629 7000
 
6630 7001
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6631 7002
 	{
@@ -6645,9 +7016,9 @@  discard block
 block discarded – undo
6645 7016
 			loadLanguage('ManageScheduledTasks');
6646 7017
 			log_error($txt['cron_not_working']);
6647 7018
 			updateSettings(array('cron_is_real_cron' => 0));
7019
+		} else {
7020
+					updateSettings(array('cron_last_checked' => time()));
6648 7021
 		}
6649
-		else
6650
-			updateSettings(array('cron_last_checked' => time()));
6651 7022
 	}
6652 7023
 }
6653 7024
 
Please login to merge, or discard this patch.
Sources/Subs-Editor.php 1 patch
Braces   +403 added lines, -303 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * !!!Compatibility!!!
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 {
32 33
 	global $modSettings;
33 34
 
34
-	if (!$compat_mode)
35
-		return $text;
35
+	if (!$compat_mode) {
36
+			return $text;
37
+	}
36 38
 
37 39
 	// Turn line breaks back into br's.
38 40
 	$text = strtr($text, array("\r" => '', "\n" => '<br>'));
@@ -49,8 +51,9 @@  discard block
 block discarded – undo
49 51
 			for ($i = 0, $n = count($parts); $i < $n; $i++)
50 52
 			{
51 53
 				// Value of 2 means we're inside the tag.
52
-				if ($i % 4 == 2)
53
-					$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
54
+				if ($i % 4 == 2) {
55
+									$parts[$i] = strtr($parts[$i], array('[' => '&#91;', ']' => '&#93;', "'" => "'"));
56
+				}
54 57
 			}
55 58
 			// Put our humpty dumpty message back together again.
56 59
 			$text = implode('', $parts);
@@ -109,8 +112,9 @@  discard block
 block discarded – undo
109 112
 	$text = preg_replace('~</p>\s*(?!<)~i', '</p><br>', $text);
110 113
 
111 114
 	// Safari/webkit wraps lines in Wysiwyg in <div>'s.
112
-	if (isBrowser('webkit'))
113
-		$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
115
+	if (isBrowser('webkit')) {
116
+			$text = preg_replace(array('~<div(?:\s(?:[^<>]*?))?' . '>~i', '</div>'), array('<br>', ''), $text);
117
+	}
114 118
 
115 119
 	// If there's a trailing break get rid of it - Firefox tends to add one.
116 120
 	$text = preg_replace('~<br\s?/?' . '>$~i', '', $text);
@@ -125,8 +129,9 @@  discard block
 block discarded – undo
125 129
 		for ($i = 0, $n = count($parts); $i < $n; $i++)
126 130
 		{
127 131
 			// Value of 2 means we're inside the tag.
128
-			if ($i % 4 == 2)
129
-				$parts[$i] = strip_tags($parts[$i]);
132
+			if ($i % 4 == 2) {
133
+							$parts[$i] = strip_tags($parts[$i]);
134
+			}
130 135
 		}
131 136
 
132 137
 		$text = strtr(implode('', $parts), array('#smf_br_spec_grudge_cool!#' => '<br>'));
@@ -152,18 +157,19 @@  discard block
 block discarded – undo
152 157
 			{
153 158
 				$found = array_search($file, $smileysto);
154 159
 				// Note the weirdness here is to stop double spaces between smileys.
155
-				if ($found)
156
-					$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
157
-				else
158
-					$matches[1][$k] = '';
160
+				if ($found) {
161
+									$matches[1][$k] = '-[]-smf_smily_start#|#' . $smcFunc['htmlspecialchars']($smileysfrom[$found]) . '-[]-smf_smily_end#|#';
162
+				} else {
163
+									$matches[1][$k] = '';
164
+				}
159 165
 			}
160
-		}
161
-		else
166
+		} else
162 167
 		{
163 168
 			// Load all the smileys.
164 169
 			$names = array();
165
-			foreach ($matches[1] as $file)
166
-				$names[] = $file;
170
+			foreach ($matches[1] as $file) {
171
+							$names[] = $file;
172
+			}
167 173
 			$names = array_unique($names);
168 174
 
169 175
 			if (!empty($names))
@@ -177,13 +183,15 @@  discard block
 block discarded – undo
177 183
 					)
178 184
 				);
179 185
 				$mappings = array();
180
-				while ($row = $smcFunc['db_fetch_assoc']($request))
181
-					$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
186
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
187
+									$mappings[$row['filename']] = $smcFunc['htmlspecialchars']($row['code']);
188
+				}
182 189
 				$smcFunc['db_free_result']($request);
183 190
 
184
-				foreach ($matches[1] as $k => $file)
185
-					if (isset($mappings[$file]))
191
+				foreach ($matches[1] as $k => $file) {
192
+									if (isset($mappings[$file]))
186 193
 						$matches[1][$k] = '-[]-smf_smily_start#|#' . $mappings[$file] . '-[]-smf_smily_end#|#';
194
+				}
187 195
 			}
188 196
 		}
189 197
 
@@ -195,8 +203,9 @@  discard block
 block discarded – undo
195 203
 	}
196 204
 
197 205
 	// Only try to buy more time if the client didn't quit.
198
-	if (connection_aborted() && $context['server']['is_apache'])
199
-		@apache_reset_timeout();
206
+	if (connection_aborted() && $context['server']['is_apache']) {
207
+			@apache_reset_timeout();
208
+	}
200 209
 
201 210
 	$parts = preg_split('~(<[A-Za-z]+\s*[^<>]*?style="?[^<>"]+"?[^<>]*?(?:/?)>|</[A-Za-z]+>)~', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
202 211
 	$replacement = '';
@@ -207,9 +216,9 @@  discard block
 block discarded – undo
207 216
 		if (preg_match('~(<([A-Za-z]+)\s*[^<>]*?)style="?([^<>"]+)"?([^<>]*?(/?)>)~', $part, $matches) === 1)
208 217
 		{
209 218
 			// If it's being closed instantly, we can't deal with it...yet.
210
-			if ($matches[5] === '/')
211
-				continue;
212
-			else
219
+			if ($matches[5] === '/') {
220
+							continue;
221
+			} else
213 222
 			{
214 223
 				// Get an array of styles that apply to this element. (The strtr is there to combat HTML generated by Word.)
215 224
 				$styles = explode(';', strtr($matches[3], array('&quot;' => '')));
@@ -225,8 +234,9 @@  discard block
 block discarded – undo
225 234
 					$clean_type_value_pair = strtolower(strtr(trim($type_value_pair), '=', ':'));
226 235
 
227 236
 					// Something like 'font-weight: bold' is expected here.
228
-					if (strpos($clean_type_value_pair, ':') === false)
229
-						continue;
237
+					if (strpos($clean_type_value_pair, ':') === false) {
238
+											continue;
239
+					}
230 240
 
231 241
 					// Capture the elements of a single style item (e.g. 'font-weight' and 'bold').
232 242
 					list ($style_type, $style_value) = explode(':', $type_value_pair);
@@ -248,8 +258,7 @@  discard block
 block discarded – undo
248 258
 							{
249 259
 								$curCloseTags .= '[/u]';
250 260
 								$replacement .= '[u]';
251
-							}
252
-							elseif ($style_value == 'line-through')
261
+							} elseif ($style_value == 'line-through')
253 262
 							{
254 263
 								$curCloseTags .= '[/s]';
255 264
 								$replacement .= '[s]';
@@ -261,13 +270,11 @@  discard block
 block discarded – undo
261 270
 							{
262 271
 								$curCloseTags .= '[/left]';
263 272
 								$replacement .= '[left]';
264
-							}
265
-							elseif ($style_value == 'center')
273
+							} elseif ($style_value == 'center')
266 274
 							{
267 275
 								$curCloseTags .= '[/center]';
268 276
 								$replacement .= '[center]';
269
-							}
270
-							elseif ($style_value == 'right')
277
+							} elseif ($style_value == 'right')
271 278
 							{
272 279
 								$curCloseTags .= '[/right]';
273 280
 								$replacement .= '[right]';
@@ -289,8 +296,9 @@  discard block
 block discarded – undo
289 296
 
290 297
 						case 'font-size':
291 298
 							// Sometimes people put decimals where decimals should not be.
292
-							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1)
293
-								$style_value = $dec_matches[1] . $dec_matches[2];
299
+							if (preg_match('~(\d)+\.\d+(p[xt])~i', $style_value, $dec_matches) === 1) {
300
+															$style_value = $dec_matches[1] . $dec_matches[2];
301
+							}
294 302
 
295 303
 							$curCloseTags .= '[/size]';
296 304
 							$replacement .= '[size=' . $style_value . ']';
@@ -298,8 +306,9 @@  discard block
 block discarded – undo
298 306
 
299 307
 						case 'font-family':
300 308
 							// Only get the first freaking font if there's a list!
301
-							if (strpos($style_value, ',') !== false)
302
-								$style_value = substr($style_value, 0, strpos($style_value, ','));
309
+							if (strpos($style_value, ',') !== false) {
310
+															$style_value = substr($style_value, 0, strpos($style_value, ','));
311
+							}
303 312
 
304 313
 							$curCloseTags .= '[/font]';
305 314
 							$replacement .= '[font=' . strtr($style_value, array("'" => '')) . ']';
@@ -308,13 +317,15 @@  discard block
 block discarded – undo
308 317
 						// This is a hack for images with dimensions embedded.
309 318
 						case 'width':
310 319
 						case 'height':
311
-							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1)
312
-								$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
320
+							if (preg_match('~[1-9]\d*~i', $style_value, $dimension) === 1) {
321
+															$extra_attr .= ' ' . $style_type . '="' . $dimension[0] . '"';
322
+							}
313 323
 						break;
314 324
 
315 325
 						case 'list-style-type':
316
-							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1)
317
-								$extra_attr .= ' listtype="' . $listType[0] . '"';
326
+							if (preg_match('~none|disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman|lower-alpha|upper-alpha|lower-greek|lower-latin|upper-latin|hebrew|armenian|georgian|cjk-ideographic|hiragana|katakana|hiragana-iroha|katakana-iroha~i', $style_value, $listType) === 1) {
327
+															$extra_attr .= ' listtype="' . $listType[0] . '"';
328
+							}
318 329
 						break;
319 330
 					}
320 331
 				}
@@ -327,18 +338,17 @@  discard block
 block discarded – undo
327 338
 				}
328 339
 
329 340
 				// If there's something that still needs closing, push it to the stack.
330
-				if (!empty($curCloseTags))
331
-					array_push($stack, array(
341
+				if (!empty($curCloseTags)) {
342
+									array_push($stack, array(
332 343
 							'element' => strtolower($curElement),
333 344
 							'closeTags' => $curCloseTags
334 345
 						)
335 346
 					);
336
-				elseif (!empty($extra_attr))
337
-					$replacement .= $precedingStyle . $extra_attr . $afterStyle;
347
+				} elseif (!empty($extra_attr)) {
348
+									$replacement .= $precedingStyle . $extra_attr . $afterStyle;
349
+				}
338 350
 			}
339
-		}
340
-
341
-		elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
351
+		} elseif (preg_match('~</([A-Za-z]+)>~', $part, $matches) === 1)
342 352
 		{
343 353
 			// Is this the element that we've been waiting for to be closed?
344 354
 			if (!empty($stack) && strtolower($matches[1]) === $stack[count($stack) - 1]['element'])
@@ -348,28 +358,32 @@  discard block
 block discarded – undo
348 358
 			}
349 359
 
350 360
 			// Must've been something else.
351
-			else
352
-				$replacement .= $part;
361
+			else {
362
+							$replacement .= $part;
363
+			}
353 364
 		}
354 365
 		// In all other cases, just add the part to the replacement.
355
-		else
356
-			$replacement .= $part;
366
+		else {
367
+					$replacement .= $part;
368
+		}
357 369
 	}
358 370
 
359 371
 	// Now put back the replacement in the text.
360 372
 	$text = $replacement;
361 373
 
362 374
 	// We are not finished yet, request more time.
363
-	if (connection_aborted() && $context['server']['is_apache'])
364
-		@apache_reset_timeout();
375
+	if (connection_aborted() && $context['server']['is_apache']) {
376
+			@apache_reset_timeout();
377
+	}
365 378
 
366 379
 	// Let's pull out any legacy alignments.
367 380
 	while (preg_match('~<([A-Za-z]+)\s+[^<>]*?(align="*(left|center|right)"*)[^<>]*?(/?)>~i', $text, $matches) === 1)
368 381
 	{
369 382
 		// Find the position in the text of this tag over again.
370 383
 		$start_pos = strpos($text, $matches[0]);
371
-		if ($start_pos === false)
372
-			break;
384
+		if ($start_pos === false) {
385
+					break;
386
+		}
373 387
 
374 388
 		// End tag?
375 389
 		if ($matches[4] != '/' && strpos($text, '</' . $matches[1] . '>', $start_pos) !== false)
@@ -383,8 +397,7 @@  discard block
 block discarded – undo
383 397
 
384 398
 			// Put the tags back into the body.
385 399
 			$text = substr($text, 0, $start_pos) . $tag . '[' . $matches[3] . ']' . $content . '[/' . $matches[3] . ']' . substr($text, $end_pos);
386
-		}
387
-		else
400
+		} else
388 401
 		{
389 402
 			// Just get rid of this evil tag.
390 403
 			$text = substr($text, 0, $start_pos) . substr($text, $start_pos + strlen($matches[0]));
@@ -397,8 +410,9 @@  discard block
 block discarded – undo
397 410
 		// Find the position of this again.
398 411
 		$start_pos = strpos($text, $matches[0]);
399 412
 		$end_pos = false;
400
-		if ($start_pos === false)
401
-			break;
413
+		if ($start_pos === false) {
414
+					break;
415
+		}
402 416
 
403 417
 		// This must have an end tag - and we must find the right one.
404 418
 		$lower_text = strtolower($text);
@@ -431,8 +445,9 @@  discard block
 block discarded – undo
431 445
 				break;
432 446
 			}
433 447
 		}
434
-		if ($end_pos === false)
435
-			break;
448
+		if ($end_pos === false) {
449
+					break;
450
+		}
436 451
 
437 452
 		// Now work out what the attributes are.
438 453
 		$attribs = fetchTagAttributes($matches[1]);
@@ -446,11 +461,11 @@  discard block
 block discarded – undo
446 461
 				$v = (int) trim($v);
447 462
 				$v = empty($v) ? 1 : $v;
448 463
 				$tags[] = array('[size=' . $sizes_equivalence[$v] . ']', '[/size]');
464
+			} elseif ($s == 'face') {
465
+							$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
466
+			} elseif ($s == 'color') {
467
+							$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
449 468
 			}
450
-			elseif ($s == 'face')
451
-				$tags[] = array('[font=' . trim(strtolower($v)) . ']', '[/font]');
452
-			elseif ($s == 'color')
453
-				$tags[] = array('[color=' . trim(strtolower($v)) . ']', '[/color]');
454 469
 		}
455 470
 
456 471
 		// As before add in our tags.
@@ -458,8 +473,9 @@  discard block
 block discarded – undo
458 473
 		foreach ($tags as $tag)
459 474
 		{
460 475
 			$before .= $tag[0];
461
-			if (isset($tag[1]))
462
-				$after = $tag[1] . $after;
476
+			if (isset($tag[1])) {
477
+							$after = $tag[1] . $after;
478
+			}
463 479
 		}
464 480
 
465 481
 		// Remove the tag so it's never checked again.
@@ -470,8 +486,9 @@  discard block
 block discarded – undo
470 486
 	}
471 487
 
472 488
 	// Almost there, just a little more time.
473
-	if (connection_aborted() && $context['server']['is_apache'])
474
-		@apache_reset_timeout();
489
+	if (connection_aborted() && $context['server']['is_apache']) {
490
+			@apache_reset_timeout();
491
+	}
475 492
 
476 493
 	if (count($parts = preg_split('~<(/?)(li|ol|ul)([^>]*)>~i', $text, null, PREG_SPLIT_DELIM_CAPTURE)) > 1)
477 494
 	{
@@ -527,12 +544,13 @@  discard block
 block discarded – undo
527 544
 						{
528 545
 							$inList = true;
529 546
 
530
-							if ($tag === 'ol')
531
-								$listType = 'decimal';
532
-							elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1)
533
-								$listType = $listTypeMapping[$match[1]];
534
-							else
535
-								$listType = null;
547
+							if ($tag === 'ol') {
548
+															$listType = 'decimal';
549
+							} elseif (preg_match('~type="?(' . implode('|', array_keys($listTypeMapping)) . ')"?~', $parts[$i + 3], $match) === 1) {
550
+															$listType = $listTypeMapping[$match[1]];
551
+							} else {
552
+															$listType = null;
553
+							}
536 554
 
537 555
 							$listDepth++;
538 556
 
@@ -596,9 +614,7 @@  discard block
 block discarded – undo
596 614
 							$parts[$i + 1] = '';
597 615
 							$parts[$i + 2] = str_repeat("\t", $listDepth) . '[/list]';
598 616
 							$parts[$i + 3] = '';
599
-						}
600
-
601
-						else
617
+						} else
602 618
 						{
603 619
 							// We're in a list item.
604 620
 							if ($listDepth > 0)
@@ -635,9 +651,7 @@  discard block
 block discarded – undo
635 651
 							$parts[$i + 1] = '';
636 652
 							$parts[$i + 2] = '';
637 653
 							$parts[$i + 3] = '';
638
-						}
639
-
640
-						else
654
+						} else
641 655
 						{
642 656
 							// Remove the trailing breaks from the list item.
643 657
 							$parts[$i] = preg_replace('~\s*<br\s*' . '/?' . '>\s*$~', '', $parts[$i]);
@@ -675,8 +689,9 @@  discard block
 block discarded – undo
675 689
 			$text .= str_repeat("\t", $listDepth) . '[/list]';
676 690
 		}
677 691
 
678
-		for ($i = $listDepth; $i > 0; $i--)
679
-			$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
692
+		for ($i = $listDepth; $i > 0; $i--) {
693
+					$text .= '[/li]' . "\n" . str_repeat("\t", $i - 1) . '[/list]';
694
+		}
680 695
 	}
681 696
 
682 697
 	// I love my own image...
@@ -684,8 +699,9 @@  discard block
 block discarded – undo
684 699
 	{
685 700
 		// Find the position of the image.
686 701
 		$start_pos = strpos($text, $matches[0]);
687
-		if ($start_pos === false)
688
-			break;
702
+		if ($start_pos === false) {
703
+					break;
704
+		}
689 705
 		$end_pos = $start_pos + strlen($matches[0]);
690 706
 
691 707
 		$params = '';
@@ -694,12 +710,13 @@  discard block
 block discarded – undo
694 710
 		$attrs = fetchTagAttributes($matches[1]);
695 711
 		foreach ($attrs as $attrib => $value)
696 712
 		{
697
-			if (in_array($attrib, array('width', 'height')))
698
-				$params .= ' ' . $attrib . '=' . (int) $value;
699
-			elseif ($attrib == 'alt' && trim($value) != '')
700
-				$params .= ' alt=' . trim($value);
701
-			elseif ($attrib == 'src')
702
-				$src = trim($value);
713
+			if (in_array($attrib, array('width', 'height'))) {
714
+							$params .= ' ' . $attrib . '=' . (int) $value;
715
+			} elseif ($attrib == 'alt' && trim($value) != '') {
716
+							$params .= ' alt=' . trim($value);
717
+			} elseif ($attrib == 'src') {
718
+							$src = trim($value);
719
+			}
703 720
 		}
704 721
 
705 722
 		$tag = '';
@@ -710,10 +727,11 @@  discard block
 block discarded – undo
710 727
 			{
711 728
 				$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
712 729
 
713
-				if (substr($src, 0, 1) === '/')
714
-					$src = $baseURL . $src;
715
-				else
716
-					$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
730
+				if (substr($src, 0, 1) === '/') {
731
+									$src = $baseURL . $src;
732
+				} else {
733
+									$src = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $src;
734
+				}
717 735
 			}
718 736
 
719 737
 			$tag = '[img' . $params . ']' . $src . '[/img]';
@@ -891,20 +909,23 @@  discard block
 block discarded – undo
891 909
 		},
892 910
 	);
893 911
 
894
-	foreach ($tags as $tag => $replace)
895
-		$text = preg_replace_callback($tag, $replace, $text);
912
+	foreach ($tags as $tag => $replace) {
913
+			$text = preg_replace_callback($tag, $replace, $text);
914
+	}
896 915
 
897 916
 	// Please give us just a little more time.
898
-	if (connection_aborted() && $context['server']['is_apache'])
899
-		@apache_reset_timeout();
917
+	if (connection_aborted() && $context['server']['is_apache']) {
918
+			@apache_reset_timeout();
919
+	}
900 920
 
901 921
 	// What about URL's - the pain in the ass of the tag world.
902 922
 	while (preg_match('~<a\s+([^<>]*)>([^<>]*)</a>~i', $text, $matches) === 1)
903 923
 	{
904 924
 		// Find the position of the URL.
905 925
 		$start_pos = strpos($text, $matches[0]);
906
-		if ($start_pos === false)
907
-			break;
926
+		if ($start_pos === false) {
927
+					break;
928
+		}
908 929
 		$end_pos = $start_pos + strlen($matches[0]);
909 930
 
910 931
 		$tag_type = 'url';
@@ -918,8 +939,9 @@  discard block
 block discarded – undo
918 939
 				$href = trim($value);
919 940
 
920 941
 				// Are we dealing with an FTP link?
921
-				if (preg_match('~^ftps?://~', $href) === 1)
922
-					$tag_type = 'ftp';
942
+				if (preg_match('~^ftps?://~', $href) === 1) {
943
+									$tag_type = 'ftp';
944
+				}
923 945
 
924 946
 				// Or is this a link to an email address?
925 947
 				elseif (substr($href, 0, 7) == 'mailto:')
@@ -933,28 +955,31 @@  discard block
 block discarded – undo
933 955
 				{
934 956
 					$baseURL = (isset($parsedURL['scheme']) ? $parsedURL['scheme'] : 'http') . '://' . $parsedURL['host'] . (empty($parsedURL['port']) ? '' : ':' . $parsedURL['port']);
935 957
 
936
-					if (substr($href, 0, 1) === '/')
937
-						$href = $baseURL . $href;
938
-					else
939
-						$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
958
+					if (substr($href, 0, 1) === '/') {
959
+											$href = $baseURL . $href;
960
+					} else {
961
+											$href = $baseURL . (empty($parsedURL['path']) ? '/' : preg_replace('~/(?:index\\.php)?$~', '', $parsedURL['path'])) . '/' . $href;
962
+					}
940 963
 				}
941 964
 			}
942 965
 
943 966
 			// External URL?
944 967
 			if ($attrib == 'target' && $tag_type == 'url')
945 968
 			{
946
-				if (trim($value) == '_blank')
947
-					$tag_type == 'iurl';
969
+				if (trim($value) == '_blank') {
970
+									$tag_type == 'iurl';
971
+				}
948 972
 			}
949 973
 		}
950 974
 
951 975
 		$tag = '';
952 976
 		if ($href != '')
953 977
 		{
954
-			if ($matches[2] == $href)
955
-				$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
956
-			else
957
-				$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
978
+			if ($matches[2] == $href) {
979
+							$tag = '[' . $tag_type . ']' . $href . '[/' . $tag_type . ']';
980
+			} else {
981
+							$tag = '[' . $tag_type . '=' . $href . ']' . $matches[2] . '[/' . $tag_type . ']';
982
+			}
958 983
 		}
959 984
 
960 985
 		// Replace the tag
@@ -994,17 +1019,18 @@  discard block
 block discarded – undo
994 1019
 		// We're either moving from the key to the attribute or we're in a string and this is fine.
995 1020
 		if ($text[$i] == '=')
996 1021
 		{
997
-			if ($tag_state == 0)
998
-				$tag_state = 1;
999
-			elseif ($tag_state == 2)
1000
-				$value .= '=';
1022
+			if ($tag_state == 0) {
1023
+							$tag_state = 1;
1024
+			} elseif ($tag_state == 2) {
1025
+							$value .= '=';
1026
+			}
1001 1027
 		}
1002 1028
 		// A space is either moving from an attribute back to a potential key or in a string is fine.
1003 1029
 		elseif ($text[$i] == ' ')
1004 1030
 		{
1005
-			if ($tag_state == 2)
1006
-				$value .= ' ';
1007
-			elseif ($tag_state == 1)
1031
+			if ($tag_state == 2) {
1032
+							$value .= ' ';
1033
+			} elseif ($tag_state == 1)
1008 1034
 			{
1009 1035
 				$attribs[$key] = $value;
1010 1036
 				$key = $value = '';
@@ -1015,24 +1041,27 @@  discard block
 block discarded – undo
1015 1041
 		elseif ($text[$i] == '"')
1016 1042
 		{
1017 1043
 			// Must be either going into or out of a string.
1018
-			if ($tag_state == 1)
1019
-				$tag_state = 2;
1020
-			else
1021
-				$tag_state = 1;
1044
+			if ($tag_state == 1) {
1045
+							$tag_state = 2;
1046
+			} else {
1047
+							$tag_state = 1;
1048
+			}
1022 1049
 		}
1023 1050
 		// Otherwise it's fine.
1024 1051
 		else
1025 1052
 		{
1026
-			if ($tag_state == 0)
1027
-				$key .= $text[$i];
1028
-			else
1029
-				$value .= $text[$i];
1053
+			if ($tag_state == 0) {
1054
+							$key .= $text[$i];
1055
+			} else {
1056
+							$value .= $text[$i];
1057
+			}
1030 1058
 		}
1031 1059
 	}
1032 1060
 
1033 1061
 	// Anything left?
1034
-	if ($key != '' && $value != '')
1035
-		$attribs[$key] = $value;
1062
+	if ($key != '' && $value != '') {
1063
+			$attribs[$key] = $value;
1064
+	}
1036 1065
 
1037 1066
 	return $attribs;
1038 1067
 }
@@ -1050,8 +1079,9 @@  discard block
 block discarded – undo
1050 1079
 	global $modSettings;
1051 1080
 
1052 1081
 	// Don't care about the texts that are too short.
1053
-	if (strlen($text) < 3)
1054
-		return $text;
1082
+	if (strlen($text) < 3) {
1083
+			return $text;
1084
+	}
1055 1085
 
1056 1086
 	// A list of tags that's disabled by the admin.
1057 1087
 	$disabled = empty($modSettings['disabledBBC']) ? array() : array_flip(explode(',', strtolower($modSettings['disabledBBC'])));
@@ -1062,10 +1092,12 @@  discard block
 block discarded – undo
1062 1092
 	$self_closing_tags = array();
1063 1093
 	foreach ($all_tags as $tag)
1064 1094
 	{
1065
-		if (!isset($disabled[$tag['tag']]))
1066
-			$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1067
-		if (isset($tag['type']) && $tag['type'] == 'closed')
1068
-			$self_closing_tags[] = $tag['tag'];
1095
+		if (!isset($disabled[$tag['tag']])) {
1096
+					$valid_tags[$tag['tag']] = !empty($tag['block_level']);
1097
+		}
1098
+		if (isset($tag['type']) && $tag['type'] == 'closed') {
1099
+					$self_closing_tags[] = $tag['tag'];
1100
+		}
1069 1101
 	}
1070 1102
 
1071 1103
 	// Right - we're going to start by going through the whole lot to make sure we don't have align stuff crossed as this happens load and is stupid!
@@ -1092,16 +1124,19 @@  discard block
 block discarded – undo
1092 1124
 				$tagName = substr($match, $isClosingTag ? 2 : 1, -1);
1093 1125
 
1094 1126
 				// We're closing the exact same tag that we opened.
1095
-				if ($isClosingTag && $insideTag === $tagName)
1096
-					$insideTag = null;
1127
+				if ($isClosingTag && $insideTag === $tagName) {
1128
+									$insideTag = null;
1129
+				}
1097 1130
 
1098 1131
 				// We're opening a tag and we're not yet inside one either
1099
-				elseif (!$isClosingTag && $insideTag === null)
1100
-					$insideTag = $tagName;
1132
+				elseif (!$isClosingTag && $insideTag === null) {
1133
+									$insideTag = $tagName;
1134
+				}
1101 1135
 
1102 1136
 				// In all other cases, this tag must be invalid
1103
-				else
1104
-					unset($matches[$i]);
1137
+				else {
1138
+									unset($matches[$i]);
1139
+				}
1105 1140
 			}
1106 1141
 
1107 1142
 			// The next one is gonna be the other one.
@@ -1109,8 +1144,9 @@  discard block
 block discarded – undo
1109 1144
 		}
1110 1145
 
1111 1146
 		// We're still inside a tag and had no chance for closure?
1112
-		if ($insideTag !== null)
1113
-			$matches[] = '[/' . $insideTag . ']';
1147
+		if ($insideTag !== null) {
1148
+					$matches[] = '[/' . $insideTag . ']';
1149
+		}
1114 1150
 
1115 1151
 		// And a complete text string again.
1116 1152
 		$text = implode('', $matches);
@@ -1119,8 +1155,9 @@  discard block
 block discarded – undo
1119 1155
 	// Quickly remove any tags which are back to back.
1120 1156
 	$backToBackPattern = '~\\[(' . implode('|', array_diff(array_keys($valid_tags), array('td', 'anchor'))) . ')[^<>\\[\\]]*\\]\s*\\[/\\1\\]~';
1121 1157
 	$lastlen = 0;
1122
-	while (strlen($text) !== $lastlen)
1123
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1158
+	while (strlen($text) !== $lastlen) {
1159
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1160
+	}
1124 1161
 
1125 1162
 	// Need to sort the tags my name length.
1126 1163
 	uksort($valid_tags, 'sort_array_length');
@@ -1157,8 +1194,9 @@  discard block
 block discarded – undo
1157 1194
 			$isCompetingTag = in_array($tag, $competing_tags);
1158 1195
 
1159 1196
 			// Check if this might be one of those cleaned out tags.
1160
-			if ($tag === '')
1161
-				continue;
1197
+			if ($tag === '') {
1198
+							continue;
1199
+			}
1162 1200
 
1163 1201
 			// Special case: inside [code] blocks any code is left untouched.
1164 1202
 			elseif ($tag === 'code')
@@ -1169,8 +1207,9 @@  discard block
 block discarded – undo
1169 1207
 					$inCode = false;
1170 1208
 
1171 1209
 					// Reopen tags that were closed before the code block.
1172
-					if (!empty($inlineElements))
1173
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1210
+					if (!empty($inlineElements)) {
1211
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1212
+					}
1174 1213
 				}
1175 1214
 
1176 1215
 				// We're outside a coding and nobbc block and opening it.
@@ -1199,8 +1238,9 @@  discard block
 block discarded – undo
1199 1238
 					$inNoBbc = false;
1200 1239
 
1201 1240
 					// Some inline elements might've been closed that need reopening.
1202
-					if (!empty($inlineElements))
1203
-						$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1241
+					if (!empty($inlineElements)) {
1242
+											$parts[$i + 4] .= '[' . implode('][', array_keys($inlineElements)) . ']';
1243
+					}
1204 1244
 				}
1205 1245
 
1206 1246
 				// We're outside a nobbc and coding block and opening it.
@@ -1220,8 +1260,9 @@  discard block
 block discarded – undo
1220 1260
 			}
1221 1261
 
1222 1262
 			// So, we're inside one of the special blocks: ignore any tag.
1223
-			elseif ($inCode || $inNoBbc)
1224
-				continue;
1263
+			elseif ($inCode || $inNoBbc) {
1264
+							continue;
1265
+			}
1225 1266
 
1226 1267
 			// We're dealing with an opening tag.
1227 1268
 			if ($isOpeningTag)
@@ -1262,8 +1303,9 @@  discard block
 block discarded – undo
1262 1303
 							if ($parts[$j + 3] === $tag)
1263 1304
 							{
1264 1305
 								// If it's an opening tag, increase the level.
1265
-								if ($parts[$j + 2] === '')
1266
-									$curLevel++;
1306
+								if ($parts[$j + 2] === '') {
1307
+																	$curLevel++;
1308
+								}
1267 1309
 
1268 1310
 								// A closing tag, decrease the level.
1269 1311
 								else
@@ -1286,13 +1328,15 @@  discard block
 block discarded – undo
1286 1328
 					{
1287 1329
 						if ($isCompetingTag)
1288 1330
 						{
1289
-							if (!isset($competingElements[$tag]))
1290
-								$competingElements[$tag] = array();
1331
+							if (!isset($competingElements[$tag])) {
1332
+															$competingElements[$tag] = array();
1333
+							}
1291 1334
 
1292 1335
 							$competingElements[$tag][] = $parts[$i + 4];
1293 1336
 
1294
-							if (count($competingElements[$tag]) > 1)
1295
-								$parts[$i] .= '[/' . $tag . ']';
1337
+							if (count($competingElements[$tag]) > 1) {
1338
+															$parts[$i] .= '[/' . $tag . ']';
1339
+							}
1296 1340
 						}
1297 1341
 
1298 1342
 						$inlineElements[$elementContent] = $tag;
@@ -1312,15 +1356,17 @@  discard block
 block discarded – undo
1312 1356
 						$addClosingTags = array();
1313 1357
 						while ($element = array_pop($blockElements))
1314 1358
 						{
1315
-							if ($element === $tag)
1316
-								break;
1359
+							if ($element === $tag) {
1360
+															break;
1361
+							}
1317 1362
 
1318 1363
 							// Still a block tag was open not equal to this tag.
1319 1364
 							$addClosingTags[] = $element['type'];
1320 1365
 						}
1321 1366
 
1322
-						if (!empty($addClosingTags))
1323
-							$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1367
+						if (!empty($addClosingTags)) {
1368
+													$parts[$i + 1] = '[/' . implode('][/', array_reverse($addClosingTags)) . ']' . $parts[$i + 1];
1369
+						}
1324 1370
 
1325 1371
 						// Apparently the closing tag was not found on the stack.
1326 1372
 						if (!is_string($element) || $element !== $tag)
@@ -1330,8 +1376,7 @@  discard block
 block discarded – undo
1330 1376
 							$parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1331 1377
 							continue;
1332 1378
 						}
1333
-					}
1334
-					else
1379
+					} else
1335 1380
 					{
1336 1381
 						// Get rid of this closing tag!
1337 1382
 						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
@@ -1360,53 +1405,62 @@  discard block
 block discarded – undo
1360 1405
 							unset($inlineElements[$tagContentToBeClosed]);
1361 1406
 
1362 1407
 							// Was this the tag we were looking for?
1363
-							if ($tagToBeClosed === $tag)
1364
-								break;
1408
+							if ($tagToBeClosed === $tag) {
1409
+															break;
1410
+							}
1365 1411
 
1366 1412
 							// Nope, close it and look further!
1367
-							else
1368
-								$parts[$i] .= '[/' . $tagToBeClosed . ']';
1413
+							else {
1414
+															$parts[$i] .= '[/' . $tagToBeClosed . ']';
1415
+							}
1369 1416
 						}
1370 1417
 
1371 1418
 						if ($isCompetingTag && !empty($competingElements[$tag]))
1372 1419
 						{
1373 1420
 							array_pop($competingElements[$tag]);
1374 1421
 
1375
-							if (count($competingElements[$tag]) > 0)
1376
-								$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1422
+							if (count($competingElements[$tag]) > 0) {
1423
+															$parts[$i + 5] = '[' . $tag . $competingElements[$tag][count($competingElements[$tag]) - 1] . $parts[$i + 5];
1424
+							}
1377 1425
 						}
1378 1426
 					}
1379 1427
 
1380 1428
 					// Unexpected closing tag, ex-ter-mi-nate.
1381
-					else
1382
-						$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1429
+					else {
1430
+											$parts[$i + 1] = $parts[$i + 2] = $parts[$i + 3] = $parts[$i + 4] = '';
1431
+					}
1383 1432
 				}
1384 1433
 			}
1385 1434
 		}
1386 1435
 
1387 1436
 		// Close the code tags.
1388
-		if ($inCode)
1389
-			$parts[$i] .= '[/code]';
1437
+		if ($inCode) {
1438
+					$parts[$i] .= '[/code]';
1439
+		}
1390 1440
 
1391 1441
 		// The same for nobbc tags.
1392
-		elseif ($inNoBbc)
1393
-			$parts[$i] .= '[/nobbc]';
1442
+		elseif ($inNoBbc) {
1443
+					$parts[$i] .= '[/nobbc]';
1444
+		}
1394 1445
 
1395 1446
 		// Still inline tags left unclosed? Close them now, better late than never.
1396
-		elseif (!empty($inlineElements))
1397
-			$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1447
+		elseif (!empty($inlineElements)) {
1448
+					$parts[$i] .= '[/' . implode('][/', array_reverse($inlineElements)) . ']';
1449
+		}
1398 1450
 
1399 1451
 		// Now close the block elements.
1400
-		if (!empty($blockElements))
1401
-			$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1452
+		if (!empty($blockElements)) {
1453
+					$parts[$i] .= '[/' . implode('][/', array_reverse($blockElements)) . ']';
1454
+		}
1402 1455
 
1403 1456
 		$text = implode('', $parts);
1404 1457
 	}
1405 1458
 
1406 1459
 	// Final clean up of back to back tags.
1407 1460
 	$lastlen = 0;
1408
-	while (strlen($text) !== $lastlen)
1409
-		$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1461
+	while (strlen($text) !== $lastlen) {
1462
+			$lastlen = strlen($text = preg_replace($backToBackPattern, '', $text));
1463
+	}
1410 1464
 
1411 1465
 	return $text;
1412 1466
 }
@@ -1437,22 +1491,25 @@  discard block
 block discarded – undo
1437 1491
 	$context['template_layers'] = array();
1438 1492
 	// Lets make sure we aren't going to output anything nasty.
1439 1493
 	@ob_end_clean();
1440
-	if (!empty($modSettings['enableCompressedOutput']))
1441
-		@ob_start('ob_gzhandler');
1442
-	else
1443
-		@ob_start();
1494
+	if (!empty($modSettings['enableCompressedOutput'])) {
1495
+			@ob_start('ob_gzhandler');
1496
+	} else {
1497
+			@ob_start();
1498
+	}
1444 1499
 
1445 1500
 	// If we don't have any locale better avoid broken js
1446
-	if (empty($txt['lang_locale']))
1447
-		die();
1501
+	if (empty($txt['lang_locale'])) {
1502
+			die();
1503
+	}
1448 1504
 
1449 1505
 	$file_data = '(function ($) {
1450 1506
 	\'use strict\';
1451 1507
 
1452 1508
 	$.sceditor.locale[' . JavaScriptEscape($txt['lang_locale']) . '] = {';
1453
-	foreach ($editortxt as $key => $val)
1454
-		$file_data .= '
1509
+	foreach ($editortxt as $key => $val) {
1510
+			$file_data .= '
1455 1511
 		' . JavaScriptEscape($key) . ': ' . JavaScriptEscape($val) . ',';
1512
+	}
1456 1513
 
1457 1514
 	$file_data .= '
1458 1515
 		dateFormat: "day.month.year"
@@ -1520,8 +1577,9 @@  discard block
 block discarded – undo
1520 1577
 				)
1521 1578
 			);
1522 1579
 			$icon_data = array();
1523
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1524
-				$icon_data[] = $row;
1580
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
1581
+							$icon_data[] = $row;
1582
+			}
1525 1583
 			$smcFunc['db_free_result']($request);
1526 1584
 
1527 1585
 			$icons = array();
@@ -1536,9 +1594,9 @@  discard block
 block discarded – undo
1536 1594
 			}
1537 1595
 
1538 1596
 			cache_put_data('posting_icons-' . $board_id, $icons, 480);
1597
+		} else {
1598
+					$icons = $temp;
1539 1599
 		}
1540
-		else
1541
-			$icons = $temp;
1542 1600
 	}
1543 1601
 	call_integration_hook('integrate_load_message_icons', array(&$icons));
1544 1602
 
@@ -1581,8 +1639,9 @@  discard block
 block discarded – undo
1581 1639
 	{
1582 1640
 		// Some general stuff.
1583 1641
 		$settings['smileys_url'] = $modSettings['smileys_url'] . '/' . $user_info['smiley_set'];
1584
-		if (!empty($context['drafts_autosave']))
1585
-			$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1642
+		if (!empty($context['drafts_autosave'])) {
1643
+					$context['drafts_autosave_frequency'] = empty($modSettings['drafts_autosave_frequency']) ? 60000 : $modSettings['drafts_autosave_frequency'] * 1000;
1644
+		}
1586 1645
 
1587 1646
 		// This really has some WYSIWYG stuff.
1588 1647
 		loadCSSFile('jquery.sceditor.css', array('force_current' => false, 'validate' => true), 'smf_jquery_sceditor');
@@ -1599,8 +1658,9 @@  discard block
 block discarded – undo
1599 1658
 		var bbc_quote = \'' . addcslashes($txt['quote'], "'") . '\';
1600 1659
 		var bbc_search_on = \'' . addcslashes($txt['search_on'], "'") . '\';');
1601 1660
 		// editor language file
1602
-		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US')
1603
-			loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1661
+		if (!empty($txt['lang_locale']) && $txt['lang_locale'] != 'en_US') {
1662
+					loadJavaScriptFile($scripturl . '?action=loadeditorlocale', array('external' => true), 'sceditor_language');
1663
+		}
1604 1664
 
1605 1665
 		$context['shortcuts_text'] = $txt['shortcuts' . (!empty($context['drafts_save']) ? '_drafts' : '') . (stripos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== false ? '_mac' : (isBrowser('is_firefox') ? '_firefox' : ''))];
1606 1666
 		$context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_character_set'] == 'UTF-8' || function_exists('iconv'))));
@@ -1609,11 +1669,12 @@  discard block
 block discarded – undo
1609 1669
 			loadJavaScriptFile('spellcheck.js', array('minimize' => true), 'smf_spellcheck');
1610 1670
 
1611 1671
 			// Some hidden information is needed in order to make the spell checking work.
1612
-			if (!isset($_REQUEST['xml']))
1613
-				$context['insert_after_template'] .= '
1672
+			if (!isset($_REQUEST['xml'])) {
1673
+							$context['insert_after_template'] .= '
1614 1674
 		<form name="spell_form" id="spell_form" method="post" accept-charset="' . $context['character_set'] . '" target="spellWindow" action="' . $scripturl . '?action=spellcheck">
1615 1675
 			<input type="hidden" name="spellstring" value="">
1616 1676
 		</form>';
1677
+			}
1617 1678
 		}
1618 1679
 	}
1619 1680
 
@@ -1805,8 +1866,9 @@  discard block
 block discarded – undo
1805 1866
 
1806 1867
 		// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
1807 1868
 		$disabled_tags = array();
1808
-		if (!empty($modSettings['disabledBBC']))
1809
-			$disabled_tags = explode(',', $modSettings['disabledBBC']);
1869
+		if (!empty($modSettings['disabledBBC'])) {
1870
+					$disabled_tags = explode(',', $modSettings['disabledBBC']);
1871
+		}
1810 1872
 
1811 1873
 		foreach ($disabled_tags as $tag)
1812 1874
 		{
@@ -1818,9 +1880,10 @@  discard block
 block discarded – undo
1818 1880
 				$context['disabled_tags']['orderedlist'] = true;
1819 1881
 			}
1820 1882
 
1821
-			foreach ($editor_tag_map as $thisTag => $tagNameBBC)
1822
-				if ($tag === $thisTag)
1883
+			foreach ($editor_tag_map as $thisTag => $tagNameBBC) {
1884
+							if ($tag === $thisTag)
1823 1885
 					$context['disabled_tags'][$tagNameBBC] = true;
1886
+			}
1824 1887
 
1825 1888
 			$context['disabled_tags'][$tag] = true;
1826 1889
 		}
@@ -1831,8 +1894,9 @@  discard block
 block discarded – undo
1831 1894
 
1832 1895
 		foreach ($context['bbc_tags'] as $row => $tagRow)
1833 1896
 		{
1834
-			if (!isset($context['bbc_toolbar'][$row]))
1835
-				$context['bbc_toolbar'][$row] = array();
1897
+			if (!isset($context['bbc_toolbar'][$row])) {
1898
+							$context['bbc_toolbar'][$row] = array();
1899
+			}
1836 1900
 
1837 1901
 			$tagsRow = array();
1838 1902
 
@@ -1868,20 +1932,21 @@  discard block
 block discarded – undo
1868 1932
 
1869 1933
 					$context['bbcodes_handlers'] .= '
1870 1934
 						});';
1871
-				}
1872
-				else
1935
+				} else
1873 1936
 				{
1874 1937
 					$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1875 1938
 					$tagsRow = array();
1876 1939
 				}
1877 1940
 			}
1878 1941
 
1879
-			if (!empty($tagsRow))
1880
-				$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1942
+			if (!empty($tagsRow)) {
1943
+							$context['bbc_toolbar'][$row][] = implode(',', $tagsRow);
1944
+			}
1881 1945
 		}
1882 1946
 
1883
-		if (!empty($bbcodes_styles))
1884
-			addInlineCss($bbcodes_styles);
1947
+		if (!empty($bbcodes_styles)) {
1948
+					addInlineCss($bbcodes_styles);
1949
+		}
1885 1950
 	}
1886 1951
 
1887 1952
 	// Initialize smiley array... if not loaded before.
@@ -1893,8 +1958,8 @@  discard block
 block discarded – undo
1893 1958
 		);
1894 1959
 
1895 1960
 		// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
1896
-		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none')
1897
-			$context['smileys']['postform'][] = array(
1961
+		if (empty($modSettings['smiley_enable']) && $user_info['smiley_set'] != 'none') {
1962
+					$context['smileys']['postform'][] = array(
1898 1963
 				'smileys' => array(
1899 1964
 					array(
1900 1965
 						'code' => ':)',
@@ -1980,7 +2045,7 @@  discard block
 block discarded – undo
1980 2045
 				),
1981 2046
 				'isLast' => true,
1982 2047
 			);
1983
-		elseif ($user_info['smiley_set'] != 'none')
2048
+		} elseif ($user_info['smiley_set'] != 'none')
1984 2049
 		{
1985 2050
 			if (($temp = cache_get_data('posting_smileys', 480)) == null)
1986 2051
 			{
@@ -2003,17 +2068,19 @@  discard block
 block discarded – undo
2003 2068
 
2004 2069
 				foreach ($context['smileys'] as $section => $smileyRows)
2005 2070
 				{
2006
-					foreach ($smileyRows as $rowIndex => $smileys)
2007
-						$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2071
+					foreach ($smileyRows as $rowIndex => $smileys) {
2072
+											$context['smileys'][$section][$rowIndex]['smileys'][count($smileys['smileys']) - 1]['isLast'] = true;
2073
+					}
2008 2074
 
2009
-					if (!empty($smileyRows))
2010
-						$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2075
+					if (!empty($smileyRows)) {
2076
+											$context['smileys'][$section][count($smileyRows) - 1]['isLast'] = true;
2077
+					}
2011 2078
 				}
2012 2079
 
2013 2080
 				cache_put_data('posting_smileys', $context['smileys'], 480);
2081
+			} else {
2082
+							$context['smileys'] = $temp;
2014 2083
 			}
2015
-			else
2016
-				$context['smileys'] = $temp;
2017 2084
 		}
2018 2085
 	}
2019 2086
 
@@ -2029,12 +2096,15 @@  discard block
 block discarded – undo
2029 2096
 		'plugins' => 'undo',
2030 2097
 		'bbcodeTrim' => true,
2031 2098
 	);
2032
-	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale']))
2033
-		$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2034
-	if (!empty($context['right_to_left']))
2035
-		$sce_options['rtl'] = true;
2036
-	if ($editorOptions['id'] != 'quickReply')
2037
-		$sce_options['autofocus'] = true;
2099
+	if (!empty($context['controls']['richedit'][$editorOptions['id']]['locale'])) {
2100
+			$sce_options['locale'] = $context['controls']['richedit'][$editorOptions['id']]['locale'];
2101
+	}
2102
+	if (!empty($context['right_to_left'])) {
2103
+			$sce_options['rtl'] = true;
2104
+	}
2105
+	if ($editorOptions['id'] != 'quickReply') {
2106
+			$sce_options['autofocus'] = true;
2107
+	}
2038 2108
 
2039 2109
 	$sce_options['emoticons'] = array();
2040 2110
 	$sce_options['emoticonsDescriptions'] = array();
@@ -2051,10 +2121,11 @@  discard block
 block discarded – undo
2051 2121
 			$countLocations--;
2052 2122
 
2053 2123
 			unset($smiley_location);
2054
-			if ($location == 'postform')
2055
-				$smiley_location = &$sce_options['emoticons']['dropdown'];
2056
-			elseif ($location == 'popup')
2057
-				$smiley_location = &$sce_options['emoticons']['popup'];
2124
+			if ($location == 'postform') {
2125
+							$smiley_location = &$sce_options['emoticons']['dropdown'];
2126
+			} elseif ($location == 'popup') {
2127
+							$smiley_location = &$sce_options['emoticons']['popup'];
2128
+			}
2058 2129
 
2059 2130
 			$numRows = count($smileyRows);
2060 2131
 
@@ -2068,8 +2139,9 @@  discard block
 block discarded – undo
2068 2139
 					$sce_options['emoticonsDescriptions'][$smiley['code']] = $smiley['description'];
2069 2140
 				}
2070 2141
 
2071
-				if (empty($smileyRow['isLast']) && $numRows != 1)
2072
-					$smiley_location['-' . $emptyPlaceholder++] = '';
2142
+				if (empty($smileyRow['isLast']) && $numRows != 1) {
2143
+									$smiley_location['-' . $emptyPlaceholder++] = '';
2144
+				}
2073 2145
 			}
2074 2146
 		}
2075 2147
 	}
@@ -2084,8 +2156,9 @@  discard block
 block discarded – undo
2084 2156
 
2085 2157
 			$count_tags--;
2086 2158
 
2087
-			if (!empty($count_tags))
2088
-				$sce_options['toolbar'] .= '||';
2159
+			if (!empty($count_tags)) {
2160
+							$sce_options['toolbar'] .= '||';
2161
+			}
2089 2162
 		}
2090 2163
 	}
2091 2164
 
@@ -2113,8 +2186,9 @@  discard block
 block discarded – undo
2113 2186
 		loadTemplate('GenericControls');
2114 2187
 
2115 2188
 		// Some javascript ma'am?
2116
-		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])))
2117
-			loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha');
2189
+		if (!empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual']))) {
2190
+					loadJavaScriptFile('captcha.js', array('minimize' => true), 'smf_captcha');
2191
+		}
2118 2192
 
2119 2193
 		$context['use_graphic_library'] = in_array('gd', get_loaded_extensions());
2120 2194
 
@@ -2127,8 +2201,8 @@  discard block
 block discarded – undo
2127 2201
 	$isNew = !isset($context['controls']['verification'][$verificationOptions['id']]);
2128 2202
 
2129 2203
 	// Log this into our collection.
2130
-	if ($isNew)
2131
-		$context['controls']['verification'][$verificationOptions['id']] = array(
2204
+	if ($isNew) {
2205
+			$context['controls']['verification'][$verificationOptions['id']] = array(
2132 2206
 			'id' => $verificationOptions['id'],
2133 2207
 			'empty_field' => empty($verificationOptions['no_empty_field']),
2134 2208
 			'show_visual' => !empty($verificationOptions['override_visual']) || (!empty($modSettings['visual_verification_type']) && !isset($verificationOptions['override_visual'])),
@@ -2139,13 +2213,15 @@  discard block
 block discarded – undo
2139 2213
 			'questions' => array(),
2140 2214
 			'can_recaptcha' => !empty($modSettings['recaptcha_enabled']) && !empty($modSettings['recaptcha_site_key']) && !empty($modSettings['recaptcha_secret_key']),
2141 2215
 		);
2216
+	}
2142 2217
 	$thisVerification = &$context['controls']['verification'][$verificationOptions['id']];
2143 2218
 
2144 2219
 	// Is there actually going to be anything?
2145
-	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha']))
2146
-		return false;
2147
-	elseif (!$isNew && !$do_test)
2148
-		return true;
2220
+	if (empty($thisVerification['show_visual']) && empty($thisVerification['number_questions']) && empty($thisVerification['can_recaptcha'])) {
2221
+			return false;
2222
+	} elseif (!$isNew && !$do_test) {
2223
+			return true;
2224
+	}
2149 2225
 
2150 2226
 	// Sanitize reCAPTCHA fields?
2151 2227
 	if ($thisVerification['can_recaptcha'])
@@ -2158,11 +2234,12 @@  discard block
 block discarded – undo
2158 2234
 	}
2159 2235
 
2160 2236
 	// Add javascript for the object.
2161
-	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual'])
2162
-		$context['insert_after_template'] .= '
2237
+	if ($context['controls']['verification'][$verificationOptions['id']]['show_visual']) {
2238
+			$context['insert_after_template'] .= '
2163 2239
 			<script>
2164 2240
 				var verification' . $verificationOptions['id'] . 'Handle = new smfCaptcha("' . $thisVerification['image_href'] . '", "' . $verificationOptions['id'] . '", ' . ($context['use_graphic_library'] ? 1 : 0) . ');
2165 2241
 			</script>';
2242
+	}
2166 2243
 
2167 2244
 	// If we want questions do we have a cache of all the IDs?
2168 2245
 	if (!empty($thisVerification['number_questions']) && empty($modSettings['question_id_cache']))
@@ -2185,8 +2262,9 @@  discard block
 block discarded – undo
2185 2262
 				unset ($row['id_question']);
2186 2263
 				// Make them all lowercase. We can't directly use $smcFunc['strtolower'] with array_walk, so do it manually, eh?
2187 2264
 				$row['answers'] = $smcFunc['json_decode']($row['answers'], true);
2188
-				foreach ($row['answers'] as $k => $v)
2189
-					$row['answers'][$k] = $smcFunc['strtolower']($v);
2265
+				foreach ($row['answers'] as $k => $v) {
2266
+									$row['answers'][$k] = $smcFunc['strtolower']($v);
2267
+				}
2190 2268
 
2191 2269
 				$modSettings['question_id_cache']['questions'][$id_question] = $row;
2192 2270
 				$modSettings['question_id_cache']['langs'][$row['lngfile']][] = $id_question;
@@ -2197,35 +2275,42 @@  discard block
 block discarded – undo
2197 2275
 		}
2198 2276
 	}
2199 2277
 
2200
-	if (!isset($_SESSION[$verificationOptions['id'] . '_vv']))
2201
-		$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2278
+	if (!isset($_SESSION[$verificationOptions['id'] . '_vv'])) {
2279
+			$_SESSION[$verificationOptions['id'] . '_vv'] = array();
2280
+	}
2202 2281
 
2203 2282
 	// Do we need to refresh the verification?
2204
-	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh']))
2205
-		$force_refresh = true;
2206
-	else
2207
-		$force_refresh = false;
2283
+	if (!$do_test && (!empty($_SESSION[$verificationOptions['id'] . '_vv']['did_pass']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) || $_SESSION[$verificationOptions['id'] . '_vv']['count'] > 3) && empty($verificationOptions['dont_refresh'])) {
2284
+			$force_refresh = true;
2285
+	} else {
2286
+			$force_refresh = false;
2287
+	}
2208 2288
 
2209 2289
 	// This can also force a fresh, although unlikely.
2210
-	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q'])))
2211
-		$force_refresh = true;
2290
+	if (($thisVerification['show_visual'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['code'])) || ($thisVerification['number_questions'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['q']))) {
2291
+			$force_refresh = true;
2292
+	}
2212 2293
 
2213 2294
 	$verification_errors = array();
2214 2295
 	// Start with any testing.
2215 2296
 	if ($do_test)
2216 2297
 	{
2217 2298
 		// This cannot happen!
2218
-		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count']))
2219
-			fatal_lang_error('no_access', false);
2299
+		if (!isset($_SESSION[$verificationOptions['id'] . '_vv']['count'])) {
2300
+					fatal_lang_error('no_access', false);
2301
+		}
2220 2302
 		// ... nor this!
2221
-		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'])))
2222
-			fatal_lang_error('no_access', false);
2303
+		if ($thisVerification['number_questions'] && (!isset($_SESSION[$verificationOptions['id'] . '_vv']['q']) || !isset($_REQUEST[$verificationOptions['id'] . '_vv']['q']))) {
2304
+					fatal_lang_error('no_access', false);
2305
+		}
2223 2306
 		// Hmm, it's requested but not actually declared. This shouldn't happen.
2224
-		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2225
-			fatal_lang_error('no_access', false);
2307
+		if ($thisVerification['empty_field'] && empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field'])) {
2308
+					fatal_lang_error('no_access', false);
2309
+		}
2226 2310
 		// While we're here, did the user do something bad?
2227
-		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']]))
2228
-			$verification_errors[] = 'wrong_verification_answer';
2311
+		if ($thisVerification['empty_field'] && !empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']) && !empty($_REQUEST[$_SESSION[$verificationOptions['id'] . '_vv']['empty_field']])) {
2312
+					$verification_errors[] = 'wrong_verification_answer';
2313
+		}
2229 2314
 
2230 2315
 		if ($thisVerification['can_recaptcha'])
2231 2316
 		{
@@ -2236,22 +2321,25 @@  discard block
 block discarded – undo
2236 2321
 			{
2237 2322
 				$resp = $reCaptcha->verify($_POST['g-recaptcha-response'], $user_info['ip']);
2238 2323
 
2239
-				if (!$resp->isSuccess())
2240
-					$verification_errors[] = 'wrong_verification_code';
2324
+				if (!$resp->isSuccess()) {
2325
+									$verification_errors[] = 'wrong_verification_code';
2326
+				}
2327
+			} else {
2328
+							$verification_errors[] = 'wrong_verification_code';
2241 2329
 			}
2242
-			else
2243
-				$verification_errors[] = 'wrong_verification_code';
2244 2330
 		}
2245
-		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code']))
2246
-			$verification_errors[] = 'wrong_verification_code';
2331
+		if ($thisVerification['show_visual'] && (empty($_REQUEST[$verificationOptions['id'] . '_vv']['code']) || empty($_SESSION[$verificationOptions['id'] . '_vv']['code']) || strtoupper($_REQUEST[$verificationOptions['id'] . '_vv']['code']) !== $_SESSION[$verificationOptions['id'] . '_vv']['code'])) {
2332
+					$verification_errors[] = 'wrong_verification_code';
2333
+		}
2247 2334
 		if ($thisVerification['number_questions'])
2248 2335
 		{
2249 2336
 			$incorrectQuestions = array();
2250 2337
 			foreach ($_SESSION[$verificationOptions['id'] . '_vv']['q'] as $q)
2251 2338
 			{
2252 2339
 				// We don't have this question any more, thus no answers.
2253
-				if (!isset($modSettings['question_id_cache']['questions'][$q]))
2254
-					continue;
2340
+				if (!isset($modSettings['question_id_cache']['questions'][$q])) {
2341
+									continue;
2342
+				}
2255 2343
 				// This is quite complex. We have our question but it might have multiple answers.
2256 2344
 				// First, did they actually answer this question?
2257 2345
 				if (!isset($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) || trim($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q]) == '')
@@ -2263,24 +2351,28 @@  discard block
 block discarded – undo
2263 2351
 				else
2264 2352
 				{
2265 2353
 					$given_answer = trim($smcFunc['htmlspecialchars'](strtolower($_REQUEST[$verificationOptions['id'] . '_vv']['q'][$q])));
2266
-					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers']))
2267
-						$incorrectQuestions[] = $q;
2354
+					if (!in_array($given_answer, $modSettings['question_id_cache']['questions'][$q]['answers'])) {
2355
+											$incorrectQuestions[] = $q;
2356
+					}
2268 2357
 				}
2269 2358
 			}
2270 2359
 
2271
-			if (!empty($incorrectQuestions))
2272
-				$verification_errors[] = 'wrong_verification_answer';
2360
+			if (!empty($incorrectQuestions)) {
2361
+							$verification_errors[] = 'wrong_verification_answer';
2362
+			}
2273 2363
 		}
2274 2364
 	}
2275 2365
 
2276 2366
 	// Any errors means we refresh potentially.
2277 2367
 	if (!empty($verification_errors))
2278 2368
 	{
2279
-		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors']))
2280
-			$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2369
+		if (empty($_SESSION[$verificationOptions['id'] . '_vv']['errors'])) {
2370
+					$_SESSION[$verificationOptions['id'] . '_vv']['errors'] = 0;
2371
+		}
2281 2372
 		// Too many errors?
2282
-		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors'])
2283
-			$force_refresh = true;
2373
+		elseif ($_SESSION[$verificationOptions['id'] . '_vv']['errors'] > $thisVerification['max_errors']) {
2374
+					$force_refresh = true;
2375
+		}
2284 2376
 
2285 2377
 		// Keep a track of these.
2286 2378
 		$_SESSION[$verificationOptions['id'] . '_vv']['errors']++;
@@ -2313,8 +2405,9 @@  discard block
 block discarded – undo
2313 2405
 			// Are we overriding the range?
2314 2406
 			$character_range = !empty($verificationOptions['override_range']) ? $verificationOptions['override_range'] : $context['standard_captcha_range'];
2315 2407
 
2316
-			for ($i = 0; $i < 6; $i++)
2317
-				$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2408
+			for ($i = 0; $i < 6; $i++) {
2409
+							$_SESSION[$verificationOptions['id'] . '_vv']['code'] .= $character_range[array_rand($character_range)];
2410
+			}
2318 2411
 		}
2319 2412
 
2320 2413
 		// Getting some new questions?
@@ -2322,8 +2415,9 @@  discard block
 block discarded – undo
2322 2415
 		{
2323 2416
 			// Attempt to try the current page's language, followed by the user's preference, followed by the site default.
2324 2417
 			$possible_langs = array();
2325
-			if (isset($_SESSION['language']))
2326
-				$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2418
+			if (isset($_SESSION['language'])) {
2419
+							$possible_langs[] = strtr($_SESSION['language'], array('-utf8' => ''));
2420
+			}
2327 2421
 			if (!empty($user_info['language']));
2328 2422
 			$possible_langs[] = $user_info['language'];
2329 2423
 			$possible_langs[] = $language;
@@ -2342,8 +2436,7 @@  discard block
 block discarded – undo
2342 2436
 				}
2343 2437
 			}
2344 2438
 		}
2345
-	}
2346
-	else
2439
+	} else
2347 2440
 	{
2348 2441
 		// Same questions as before.
2349 2442
 		$questionIDs = !empty($_SESSION[$verificationOptions['id'] . '_vv']['q']) ? $_SESSION[$verificationOptions['id'] . '_vv']['q'] : array();
@@ -2353,8 +2446,9 @@  discard block
 block discarded – undo
2353 2446
 	// If we do have an empty field, it would be nice to hide it from legitimate users who shouldn't be populating it anyway.
2354 2447
 	if (!empty($_SESSION[$verificationOptions['id'] . '_vv']['empty_field']))
2355 2448
 	{
2356
-		if (!isset($context['html_headers']))
2357
-			$context['html_headers'] = '';
2449
+		if (!isset($context['html_headers'])) {
2450
+					$context['html_headers'] = '';
2451
+		}
2358 2452
 		$context['html_headers'] .= '<style>.vv_special { display:none; }</style>';
2359 2453
 	}
2360 2454
 
@@ -2380,11 +2474,13 @@  discard block
 block discarded – undo
2380 2474
 	$_SESSION[$verificationOptions['id'] . '_vv']['count'] = empty($_SESSION[$verificationOptions['id'] . '_vv']['count']) ? 1 : $_SESSION[$verificationOptions['id'] . '_vv']['count'] + 1;
2381 2475
 
2382 2476
 	// Return errors if we have them.
2383
-	if (!empty($verification_errors))
2384
-		return $verification_errors;
2477
+	if (!empty($verification_errors)) {
2478
+			return $verification_errors;
2479
+	}
2385 2480
 	// If we had a test that one, make a note.
2386
-	elseif ($do_test)
2387
-		$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2481
+	elseif ($do_test) {
2482
+			$_SESSION[$verificationOptions['id'] . '_vv']['did_pass'] = true;
2483
+	}
2388 2484
 
2389 2485
 	// Say that everything went well chaps.
2390 2486
 	return true;
@@ -2409,8 +2505,9 @@  discard block
 block discarded – undo
2409 2505
 	call_integration_hook('integrate_autosuggest', array(&$searchTypes));
2410 2506
 
2411 2507
 	// If we're just checking the callback function is registered return true or false.
2412
-	if ($checkRegistered != null)
2413
-		return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2508
+	if ($checkRegistered != null) {
2509
+			return isset($searchTypes[$checkRegistered]) && function_exists('AutoSuggest_Search_' . $checkRegistered);
2510
+	}
2414 2511
 
2415 2512
 	checkSession('get');
2416 2513
 	loadTemplate('Xml');
@@ -2561,24 +2658,27 @@  discard block
 block discarded – undo
2561 2658
 		foreach ($possible_versions as $ver)
2562 2659
 		{
2563 2660
 			$ver = trim($ver);
2564
-			if (strpos($ver, 'SMF') === 0)
2565
-				$versions[] = $ver;
2661
+			if (strpos($ver, 'SMF') === 0) {
2662
+							$versions[] = $ver;
2663
+			}
2566 2664
 		}
2567 2665
 	}
2568 2666
 	$smcFunc['db_free_result']($request);
2569 2667
 
2570 2668
 	// Just in case we don't have ANYthing.
2571
-	if (empty($versions))
2572
-		$versions = array('SMF 2.0');
2669
+	if (empty($versions)) {
2670
+			$versions = array('SMF 2.0');
2671
+	}
2573 2672
 
2574
-	foreach ($versions as $id => $version)
2575
-		if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2673
+	foreach ($versions as $id => $version) {
2674
+			if (strpos($version, strtoupper($_REQUEST['search'])) !== false)
2576 2675
 			$xml_data['items']['children'][] = array(
2577 2676
 				'attributes' => array(
2578 2677
 					'id' => $id,
2579 2678
 				),
2580 2679
 				'value' => $version,
2581 2680
 			);
2681
+	}
2582 2682
 
2583 2683
 	return $xml_data;
2584 2684
 }
Please login to merge, or discard this patch.