Completed
Pull Request — release-2.1 (#5005)
by Martyn
09:25 queued 03:14
created
Sources/Security.php 1 patch
Braces   +255 added lines, -197 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
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type . '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason, COALESCE(bg.expire_time, 0) AS expire_time
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -298,14 +315,15 @@  discard block
 block discarded – undo
298 315
 	if (isset($_SESSION['ban']['cannot_access']))
299 316
 	{
300 317
 		// We don't wanna see you!
301
-		if (!$user_info['is_guest'])
302
-			$smcFunc['db_query']('', '
318
+		if (!$user_info['is_guest']) {
319
+					$smcFunc['db_query']('', '
303 320
 				DELETE FROM {db_prefix}log_online
304 321
 				WHERE id_member = {int:current_member}',
305 322
 				array(
306 323
 					'current_member' => $user_info['id'],
307 324
 				)
308 325
 			);
326
+		}
309 327
 
310 328
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
311 329
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -391,9 +409,10 @@  discard block
 block discarded – undo
391 409
 	}
392 410
 
393 411
 	// Fix up the banning permissions.
394
-	if (isset($user_info['permissions']))
395
-		banPermissions();
396
-}
412
+	if (isset($user_info['permissions'])) {
413
+			banPermissions();
414
+	}
415
+	}
397 416
 
398 417
 /**
399 418
  * Fix permissions according to ban status.
@@ -404,8 +423,9 @@  discard block
 block discarded – undo
404 423
 	global $user_info, $sourcedir, $modSettings, $context;
405 424
 
406 425
 	// Somehow they got here, at least take away all permissions...
407
-	if (isset($_SESSION['ban']['cannot_access']))
408
-		$user_info['permissions'] = array();
426
+	if (isset($_SESSION['ban']['cannot_access'])) {
427
+			$user_info['permissions'] = array();
428
+	}
409 429
 	// Okay, well, you can watch, but don't touch a thing.
410 430
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
411 431
 	{
@@ -447,19 +467,20 @@  discard block
 block discarded – undo
447 467
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
448 468
 		foreach ($permission_change as $old => $new)
449 469
 		{
450
-			if (!in_array($old, $user_info['permissions']))
451
-				unset($permission_change[$old]);
452
-			else
453
-				$user_info['permissions'][] = $new;
470
+			if (!in_array($old, $user_info['permissions'])) {
471
+							unset($permission_change[$old]);
472
+			} else {
473
+							$user_info['permissions'][] = $new;
474
+			}
454 475
 		}
455 476
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
456 477
 	}
457 478
 
458 479
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
459 480
 	// Finally, some bits we cache in the session because it saves queries.
460
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
461
-		$user_info['mod_cache'] = $_SESSION['mc'];
462
-	else
481
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
482
+			$user_info['mod_cache'] = $_SESSION['mc'];
483
+	} else
463 484
 	{
464 485
 		require_once($sourcedir . '/Subs-Auth.php');
465 486
 		rebuildModCache();
@@ -470,14 +491,12 @@  discard block
 block discarded – undo
470 491
 	{
471 492
 		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
472 493
 		$context['open_member_reports'] = $_SESSION['rc']['member_reports'];
473
-	}
474
-	elseif ($_SESSION['mc']['bq'] != '0=1')
494
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
475 495
 	{
476 496
 		require_once($sourcedir . '/Subs-ReportedContent.php');
477 497
 		$context['open_mod_reports'] = recountOpenReports('posts');
478 498
 		$context['open_member_reports'] = recountOpenReports('members');
479
-	}
480
-	else
499
+	} else
481 500
 	{
482 501
 		$context['open_mod_reports'] = 0;
483 502
 		$context['open_member_reports'] = 0;
@@ -497,8 +516,9 @@  discard block
 block discarded – undo
497 516
 	global $user_info, $smcFunc;
498 517
 
499 518
 	// Don't log web accelerators, it's very confusing...
500
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
501
-		return;
519
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
520
+			return;
521
+	}
502 522
 
503 523
 	$smcFunc['db_insert']('',
504 524
 		'{db_prefix}log_banned',
@@ -508,8 +528,8 @@  discard block
 block discarded – undo
508 528
 	);
509 529
 
510 530
 	// One extra point for these bans.
511
-	if (!empty($ban_ids))
512
-		$smcFunc['db_query']('', '
531
+	if (!empty($ban_ids)) {
532
+			$smcFunc['db_query']('', '
513 533
 			UPDATE {db_prefix}ban_items
514 534
 			SET hits = hits + 1
515 535
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -517,7 +537,8 @@  discard block
 block discarded – undo
517 537
 				'ban_ids' => $ban_ids,
518 538
 			)
519 539
 		);
520
-}
540
+	}
541
+	}
521 542
 
522 543
 /**
523 544
  * Checks if a given email address might be banned.
@@ -533,8 +554,9 @@  discard block
 block discarded – undo
533 554
 	global $txt, $smcFunc;
534 555
 
535 556
 	// Can't ban an empty email
536
-	if (empty($email) || trim($email) == '')
537
-		return;
557
+	if (empty($email) || trim($email) == '') {
558
+			return;
559
+	}
538 560
 
539 561
 	// Let's start with the bans based on your IP/hostname/memberID...
540 562
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -607,16 +629,18 @@  discard block
 block discarded – undo
607 629
 	if ($type == 'post')
608 630
 	{
609 631
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
610
-		if ($check !== $sc)
611
-			$error = 'session_timeout';
632
+		if ($check !== $sc) {
633
+					$error = 'session_timeout';
634
+		}
612 635
 	}
613 636
 
614 637
 	// How about $_GET['sesc']?
615 638
 	elseif ($type == 'get')
616 639
 	{
617 640
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
618
-		if ($check !== $sc)
619
-			$error = 'session_verify_fail';
641
+		if ($check !== $sc) {
642
+					$error = 'session_verify_fail';
643
+		}
620 644
 	}
621 645
 
622 646
 	// Or can it be in either?
@@ -624,13 +648,15 @@  discard block
 block discarded – undo
624 648
 	{
625 649
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
626 650
 
627
-		if ($check !== $sc)
628
-			$error = 'session_verify_fail';
651
+		if ($check !== $sc) {
652
+					$error = 'session_verify_fail';
653
+		}
629 654
 	}
630 655
 
631 656
 	// Verify that they aren't changing user agents on us - that could be bad.
632
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
633
-		$error = 'session_verify_fail';
657
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
658
+			$error = 'session_verify_fail';
659
+	}
634 660
 
635 661
 	// Make sure a page with session check requirement is not being prefetched.
636 662
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -641,30 +667,35 @@  discard block
 block discarded – undo
641 667
 	}
642 668
 
643 669
 	// Check the referring site - it should be the same server at least!
644
-	if (isset($_SESSION['request_referer']))
645
-		$referrer = $_SESSION['request_referer'];
646
-	else
647
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
670
+	if (isset($_SESSION['request_referer'])) {
671
+			$referrer = $_SESSION['request_referer'];
672
+	} else {
673
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
674
+	}
648 675
 	if (!empty($referrer['host']))
649 676
 	{
650
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
651
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
652
-		else
653
-			$real_host = $_SERVER['HTTP_HOST'];
677
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
678
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
679
+		} else {
680
+					$real_host = $_SERVER['HTTP_HOST'];
681
+		}
654 682
 
655 683
 		$parsed_url = parse_url($boardurl);
656 684
 
657 685
 		// Are global cookies on?  If so, let's check them ;).
658 686
 		if (!empty($modSettings['globalCookies']))
659 687
 		{
660
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
661
-				$parsed_url['host'] = $parts[1];
688
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
689
+							$parsed_url['host'] = $parts[1];
690
+			}
662 691
 
663
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
664
-				$referrer['host'] = $parts[1];
692
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
693
+							$referrer['host'] = $parts[1];
694
+			}
665 695
 
666
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
667
-				$real_host = $parts[1];
696
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
697
+							$real_host = $parts[1];
698
+			}
668 699
 		}
669 700
 
670 701
 		// Okay: referrer must either match parsed_url or real_host.
@@ -682,12 +713,14 @@  discard block
 block discarded – undo
682 713
 		$log_error = true;
683 714
 	}
684 715
 
685
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
686
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
716
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
717
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
718
+	}
687 719
 
688 720
 	// Everything is ok, return an empty string.
689
-	if (!isset($error))
690
-		return '';
721
+	if (!isset($error)) {
722
+			return '';
723
+	}
691 724
 	// A session error occurred, show the error.
692 725
 	elseif ($is_fatal)
693 726
 	{
@@ -696,13 +729,14 @@  discard block
 block discarded – undo
696 729
 			ob_end_clean();
697 730
 			send_http_status(403, 'Forbidden - Session timeout');
698 731
 			die;
732
+		} else {
733
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
699 734
 		}
700
-		else
701
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
702 735
 	}
703 736
 	// A session error occurred, return the error to the calling function.
704
-	else
705
-		return $error;
737
+	else {
738
+			return $error;
739
+	}
706 740
 
707 741
 	// We really should never fall through here, for very important reasons.  Let's make sure.
708 742
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -718,10 +752,9 @@  discard block
 block discarded – undo
718 752
 {
719 753
 	global $modSettings;
720 754
 
721
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
722
-		return true;
723
-
724
-	else
755
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
756
+			return true;
757
+	} else
725 758
 	{
726 759
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
727 760
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -772,9 +805,9 @@  discard block
 block discarded – undo
772 805
 			$return = $_SESSION['token'][$type . '-' . $action][3];
773 806
 			unset($_SESSION['token'][$type . '-' . $action]);
774 807
 			return $return;
808
+		} else {
809
+					return '';
775 810
 		}
776
-		else
777
-			return '';
778 811
 	}
779 812
 
780 813
 	// This nasty piece of code validates a token.
@@ -805,12 +838,14 @@  discard block
 block discarded – undo
805 838
 		fatal_lang_error('token_verify_fail', false);
806 839
 	}
807 840
 	// Remove this token as its useless
808
-	else
809
-		unset($_SESSION['token'][$type . '-' . $action]);
841
+	else {
842
+			unset($_SESSION['token'][$type . '-' . $action]);
843
+	}
810 844
 
811 845
 	// Randomly check if we should remove some older tokens.
812
-	if (mt_rand(0, 138) == 23)
813
-		cleanTokens();
846
+	if (mt_rand(0, 138) == 23) {
847
+			cleanTokens();
848
+	}
814 849
 
815 850
 	return false;
816 851
 }
@@ -825,14 +860,16 @@  discard block
 block discarded – undo
825 860
 function cleanTokens($complete = false)
826 861
 {
827 862
 	// We appreciate cleaning up after yourselves.
828
-	if (!isset($_SESSION['token']))
829
-		return;
863
+	if (!isset($_SESSION['token'])) {
864
+			return;
865
+	}
830 866
 
831 867
 	// Clean up tokens, trying to give enough time still.
832
-	foreach ($_SESSION['token'] as $key => $data)
833
-		if ($data[2] + 10800 < time() || $complete)
868
+	foreach ($_SESSION['token'] as $key => $data) {
869
+			if ($data[2] + 10800 < time() || $complete)
834 870
 			unset($_SESSION['token'][$key]);
835
-}
871
+	}
872
+	}
836 873
 
837 874
 /**
838 875
  * Check whether a form has been submitted twice.
@@ -850,37 +887,40 @@  discard block
 block discarded – undo
850 887
 {
851 888
 	global $context;
852 889
 
853
-	if (!isset($_SESSION['forms']))
854
-		$_SESSION['forms'] = array();
890
+	if (!isset($_SESSION['forms'])) {
891
+			$_SESSION['forms'] = array();
892
+	}
855 893
 
856 894
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
857 895
 	if ($action == 'register')
858 896
 	{
859 897
 		$context['form_sequence_number'] = 0;
860
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
861
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
898
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
899
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
900
+		}
862 901
 	}
863 902
 	// Check whether the submitted number can be found in the session.
864 903
 	elseif ($action == 'check')
865 904
 	{
866
-		if (!isset($_REQUEST['seqnum']))
867
-			return true;
868
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
905
+		if (!isset($_REQUEST['seqnum'])) {
906
+					return true;
907
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
869 908
 		{
870 909
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
871 910
 			return true;
911
+		} elseif ($is_fatal) {
912
+					fatal_lang_error('error_form_already_submitted', false);
913
+		} else {
914
+					return false;
872 915
 		}
873
-		elseif ($is_fatal)
874
-			fatal_lang_error('error_form_already_submitted', false);
875
-		else
876
-			return false;
877 916
 	}
878 917
 	// Don't check, just free the stack number.
879
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
880
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
881
-	elseif ($action != 'free')
882
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
883
-}
918
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
919
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
920
+	} elseif ($action != 'free') {
921
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
922
+	}
923
+	}
884 924
 
885 925
 /**
886 926
  * Check the user's permissions.
@@ -899,16 +939,19 @@  discard block
 block discarded – undo
899 939
 	global $user_info, $smcFunc;
900 940
 
901 941
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
902
-	if (empty($permission))
903
-		return true;
942
+	if (empty($permission)) {
943
+			return true;
944
+	}
904 945
 
905 946
 	// You're never allowed to do something if your data hasn't been loaded yet!
906
-	if (empty($user_info))
907
-		return false;
947
+	if (empty($user_info)) {
948
+			return false;
949
+	}
908 950
 
909 951
 	// Administrators are supermen :P.
910
-	if ($user_info['is_admin'])
911
-		return true;
952
+	if ($user_info['is_admin']) {
953
+			return true;
954
+	}
912 955
 
913 956
 	// Let's ensure this is an array.
914 957
 	$permission = (array) $permission;
@@ -916,14 +959,16 @@  discard block
 block discarded – undo
916 959
 	// Are we checking the _current_ board, or some other boards?
917 960
 	if ($boards === null)
918 961
 	{
919
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
920
-			return true;
962
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
963
+					return true;
964
+		}
921 965
 		// You aren't allowed, by default.
922
-		else
923
-			return false;
966
+		else {
967
+					return false;
968
+		}
969
+	} elseif (!is_array($boards)) {
970
+			$boards = array($boards);
924 971
 	}
925
-	elseif (!is_array($boards))
926
-		$boards = array($boards);
927 972
 
928 973
 	$request = $smcFunc['db_query']('', '
929 974
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -951,20 +996,23 @@  discard block
 block discarded – undo
951 996
 		while ($row = $smcFunc['db_fetch_assoc']($request))
952 997
 		{
953 998
 			$result = !empty($row['add_deny']);
954
-			if ($result == true)
955
-				break;
999
+			if ($result == true) {
1000
+							break;
1001
+			}
956 1002
 		}
957 1003
 		$smcFunc['db_free_result']($request);
958 1004
 		return $result;
959 1005
 	}
960 1006
 
961 1007
 	// Make sure they can do it on all of the boards.
962
-	if ($smcFunc['db_num_rows']($request) != count($boards))
963
-		return false;
1008
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
1009
+			return false;
1010
+	}
964 1011
 
965 1012
 	$result = true;
966
-	while ($row = $smcFunc['db_fetch_assoc']($request))
967
-		$result &= !empty($row['add_deny']);
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$result &= !empty($row['add_deny']);
1015
+	}
968 1016
 	$smcFunc['db_free_result']($request);
969 1017
 
970 1018
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1031,9 +1079,10 @@  discard block
 block discarded – undo
1031 1079
 
1032 1080
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1033 1081
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1034
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1035
-		validateSession();
1036
-}
1082
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1083
+			validateSession();
1084
+	}
1085
+	}
1037 1086
 
1038 1087
 /**
1039 1088
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1064,13 +1113,14 @@  discard block
 block discarded – undo
1064 1113
 	// Administrators are all powerful, sorry.
1065 1114
 	if ($user_info['is_admin'])
1066 1115
 	{
1067
-		if ($simple)
1068
-			return array(0);
1069
-		else
1116
+		if ($simple) {
1117
+					return array(0);
1118
+		} else
1070 1119
 		{
1071 1120
 			$boards = array();
1072
-			foreach ($permissions as $permission)
1073
-				$boards[$permission] = array(0);
1121
+			foreach ($permissions as $permission) {
1122
+							$boards[$permission] = array(0);
1123
+			}
1074 1124
 
1075 1125
 			return $boards;
1076 1126
 		}
@@ -1102,31 +1152,32 @@  discard block
 block discarded – undo
1102 1152
 	{
1103 1153
 		if ($simple)
1104 1154
 		{
1105
-			if (empty($row['add_deny']))
1106
-				$deny_boards[] = $row['id_board'];
1107
-			else
1108
-				$boards[] = $row['id_board'];
1109
-		}
1110
-		else
1155
+			if (empty($row['add_deny'])) {
1156
+							$deny_boards[] = $row['id_board'];
1157
+			} else {
1158
+							$boards[] = $row['id_board'];
1159
+			}
1160
+		} else
1111 1161
 		{
1112
-			if (empty($row['add_deny']))
1113
-				$deny_boards[$row['permission']][] = $row['id_board'];
1114
-			else
1115
-				$boards[$row['permission']][] = $row['id_board'];
1162
+			if (empty($row['add_deny'])) {
1163
+							$deny_boards[$row['permission']][] = $row['id_board'];
1164
+			} else {
1165
+							$boards[$row['permission']][] = $row['id_board'];
1166
+			}
1116 1167
 		}
1117 1168
 	}
1118 1169
 	$smcFunc['db_free_result']($request);
1119 1170
 
1120
-	if ($simple)
1121
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1122
-	else
1171
+	if ($simple) {
1172
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1173
+	} else
1123 1174
 	{
1124 1175
 		foreach ($permissions as $permission)
1125 1176
 		{
1126 1177
 			// never had it to start with
1127
-			if (empty($boards[$permission]))
1128
-				$boards[$permission] = array();
1129
-			else
1178
+			if (empty($boards[$permission])) {
1179
+							$boards[$permission] = array();
1180
+			} else
1130 1181
 			{
1131 1182
 				// Or it may have been removed
1132 1183
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1162,10 +1213,11 @@  discard block
 block discarded – undo
1162 1213
 
1163 1214
 
1164 1215
 	// Moderators are free...
1165
-	if (!allowedTo('moderate_board'))
1166
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1167
-	else
1168
-		$timeLimit = 2;
1216
+	if (!allowedTo('moderate_board')) {
1217
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1218
+	} else {
1219
+			$timeLimit = 2;
1220
+	}
1169 1221
 
1170 1222
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1171 1223
 
@@ -1192,8 +1244,9 @@  discard block
 block discarded – undo
1192 1244
 	if ($smcFunc['db_affected_rows']() != 1)
1193 1245
 	{
1194 1246
 		// Spammer!  You only have to wait a *few* seconds!
1195
-		if (!$only_return_result)
1196
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1247
+		if (!$only_return_result) {
1248
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1249
+		}
1197 1250
 
1198 1251
 		return true;
1199 1252
 	}
@@ -1211,11 +1264,13 @@  discard block
 block discarded – undo
1211 1264
  */
1212 1265
 function secureDirectory($path, $attachments = false)
1213 1266
 {
1214
-	if (empty($path))
1215
-		return 'empty_path';
1267
+	if (empty($path)) {
1268
+			return 'empty_path';
1269
+	}
1216 1270
 
1217
-	if (!is_writable($path))
1218
-		return 'path_not_writable';
1271
+	if (!is_writable($path)) {
1272
+			return 'path_not_writable';
1273
+	}
1219 1274
 
1220 1275
 	$directoryname = basename($path);
1221 1276
 
@@ -1227,9 +1282,9 @@  discard block
 block discarded – undo
1227 1282
 
1228 1283
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1229 1284
 
1230
-	if (file_exists($path . '/.htaccess'))
1231
-		$errors[] = 'htaccess_exists';
1232
-	else
1285
+	if (file_exists($path . '/.htaccess')) {
1286
+			$errors[] = 'htaccess_exists';
1287
+	} else
1233 1288
 	{
1234 1289
 		$fh = @fopen($path . '/.htaccess', 'w');
1235 1290
 		if ($fh)
@@ -1242,9 +1297,9 @@  discard block
 block discarded – undo
1242 1297
 		$errors[] = 'htaccess_cannot_create_file';
1243 1298
 	}
1244 1299
 
1245
-	if (file_exists($path . '/index.php'))
1246
-		$errors[] = 'index-php_exists';
1247
-	else
1300
+	if (file_exists($path . '/index.php')) {
1301
+			$errors[] = 'index-php_exists';
1302
+	} else
1248 1303
 	{
1249 1304
 		$fh = @fopen($path . '/index.php', 'w');
1250 1305
 		if ($fh)
@@ -1272,11 +1327,12 @@  discard block
 block discarded – undo
1272 1327
 		$errors[] = 'index-php_cannot_create_file';
1273 1328
 	}
1274 1329
 
1275
-	if (!empty($errors))
1276
-		return $errors;
1277
-	else
1278
-		return true;
1279
-}
1330
+	if (!empty($errors)) {
1331
+			return $errors;
1332
+	} else {
1333
+			return true;
1334
+	}
1335
+	}
1280 1336
 
1281 1337
 /**
1282 1338
 * This sets the X-Frame-Options header.
@@ -1289,14 +1345,16 @@  discard block
 block discarded – undo
1289 1345
 	global $modSettings;
1290 1346
 
1291 1347
 	$option = 'SAMEORIGIN';
1292
-	if (is_null($override) && !empty($modSettings['frame_security']))
1293
-		$option = $modSettings['frame_security'];
1294
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1295
-		$option = $override;
1348
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1349
+			$option = $modSettings['frame_security'];
1350
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1351
+			$option = $override;
1352
+	}
1296 1353
 
1297 1354
 	// Don't bother setting the header if we have disabled it.
1298
-	if ($option == 'DISABLE')
1299
-		return;
1355
+	if ($option == 'DISABLE') {
1356
+			return;
1357
+	}
1300 1358
 
1301 1359
 	// Finally set it.
1302 1360
 	header('x-frame-options: ' . $option);
Please login to merge, or discard this patch.
Sources/Display.php 1 patch
Braces   +298 added lines, -219 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
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -365,9 +370,10 @@  discard block
 block discarded – undo
365 370
 		list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
366 371
 		$sig_limits = explode(',', $sig_limits);
367 372
 
368
-		if (!empty($sig_limits[5]) || !empty($sig_limits[6]))
369
-			addInlineCss('
373
+		if (!empty($sig_limits[5]) || !empty($sig_limits[6])) {
374
+					addInlineCss('
370 375
 	.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}');
376
+		}
371 377
 	}
372 378
 
373 379
 	// Censor the title...
@@ -405,21 +411,25 @@  discard block
 block discarded – undo
405 411
 		);
406 412
 		while ($row = $smcFunc['db_fetch_assoc']($request))
407 413
 		{
408
-			if (empty($row['id_member']))
409
-				continue;
414
+			if (empty($row['id_member'])) {
415
+							continue;
416
+			}
410 417
 
411
-			if (!empty($row['online_color']))
412
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
413
-			else
414
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
418
+			if (!empty($row['online_color'])) {
419
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
420
+			} else {
421
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
422
+			}
415 423
 
416 424
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
417
-			if ($is_buddy)
418
-				$link = '<strong>' . $link . '</strong>';
425
+			if ($is_buddy) {
426
+							$link = '<strong>' . $link . '</strong>';
427
+			}
419 428
 
420 429
 			// Add them both to the list and to the more detailed list.
421
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
422
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
430
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
431
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
432
+			}
423 433
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
424 434
 				'id' => $row['id_member'],
425 435
 				'username' => $row['member_name'],
@@ -431,8 +441,9 @@  discard block
 block discarded – undo
431 441
 				'hidden' => empty($row['show_online']),
432 442
 			);
433 443
 
434
-			if (empty($row['show_online']))
435
-				$context['view_num_hidden']++;
444
+			if (empty($row['show_online'])) {
445
+							$context['view_num_hidden']++;
446
+			}
436 447
 		}
437 448
 
438 449
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -446,11 +457,13 @@  discard block
 block discarded – undo
446 457
 
447 458
 	// If all is set, but not allowed... just unset it.
448 459
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
449
-	if (isset($_REQUEST['all']) && !$can_show_all)
450
-		unset($_REQUEST['all']);
460
+	if (isset($_REQUEST['all']) && !$can_show_all) {
461
+			unset($_REQUEST['all']);
462
+	}
451 463
 	// Otherwise, it must be allowed... so pretend start was -1.
452
-	elseif (isset($_REQUEST['all']))
453
-		$_REQUEST['start'] = -1;
464
+	elseif (isset($_REQUEST['all'])) {
465
+			$_REQUEST['start'] = -1;
466
+	}
454 467
 
455 468
 	// Construct the page index, allowing for the .START method...
456 469
 	$context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
@@ -487,8 +500,9 @@  discard block
 block discarded – undo
487 500
 			$_REQUEST['start'] = 0;
488 501
 		}
489 502
 		// They aren't using it, but the *option* is there, at least.
490
-		else
491
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
503
+		else {
504
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
505
+		}
492 506
 	}
493 507
 
494 508
 	// Build the link tree.
@@ -504,14 +518,16 @@  discard block
 block discarded – undo
504 518
 	if (!empty($board_info['moderators']))
505 519
 	{
506 520
 		// Add a link for each moderator...
507
-		foreach ($board_info['moderators'] as $mod)
508
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
521
+		foreach ($board_info['moderators'] as $mod) {
522
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
523
+		}
509 524
 	}
510 525
 	if (!empty($board_info['moderator_groups']))
511 526
 	{
512 527
 		// Add a link for each moderator group as well...
513
-		foreach ($board_info['moderator_groups'] as $mod_group)
514
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
528
+		foreach ($board_info['moderator_groups'] as $mod_group) {
529
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
530
+		}
515 531
 	}
516 532
 
517 533
 	if (!empty($context['link_moderators']))
@@ -542,9 +558,9 @@  discard block
 block discarded – undo
542 558
 	// For quick reply we need a response prefix in the default forum language.
543 559
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
544 560
 	{
545
-		if ($language === $user_info['language'])
546
-			$context['response_prefix'] = $txt['response_prefix'];
547
-		else
561
+		if ($language === $user_info['language']) {
562
+					$context['response_prefix'] = $txt['response_prefix'];
563
+		} else
548 564
 		{
549 565
 			loadLanguage('index', $language, false);
550 566
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -576,8 +592,9 @@  discard block
 block discarded – undo
576 592
 			list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
577 593
 
578 594
 			// Sanity check
579
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
580
-				continue;
595
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
596
+							continue;
597
+			}
581 598
 
582 599
 			$linked_calendar_event = array(
583 600
 				'id' => $row['id_event'],
@@ -626,8 +643,9 @@  discard block
 block discarded – undo
626 643
 		}
627 644
 		$smcFunc['db_free_result']($request);
628 645
 
629
-		if (!empty($context['linked_calendar_events']))
630
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
646
+		if (!empty($context['linked_calendar_events'])) {
647
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
648
+		}
631 649
 	}
632 650
 
633 651
 	// Create the poll info if it exists.
@@ -651,9 +669,9 @@  discard block
 block discarded – undo
651 669
 	}
652 670
 
653 671
 	// Create the poll info if it exists and is valid.
654
-	if ($context['is_poll'] && empty($pollinfo))
655
-		$context['is_poll'] = false;
656
-	elseif ($context['is_poll'])
672
+	if ($context['is_poll'] && empty($pollinfo)) {
673
+			$context['is_poll'] = false;
674
+	} elseif ($context['is_poll'])
657 675
 	{
658 676
 		$request = $smcFunc['db_query']('', '
659 677
 			SELECT COUNT(DISTINCT id_member) AS total
@@ -696,8 +714,9 @@  discard block
 block discarded – undo
696 714
 		$smcFunc['db_free_result']($request);
697 715
 
698 716
 		// Got we multi choice?
699
-		if ($pollinfo['max_votes'] > 1)
700
-			$realtotal = $pollinfo['total'];
717
+		if ($pollinfo['max_votes'] > 1) {
718
+					$realtotal = $pollinfo['total'];
719
+		}
701 720
 
702 721
 		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
703 722
 		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
@@ -710,20 +729,21 @@  discard block
 block discarded – undo
710 729
 				foreach ($guestinfo as $i => $guestvoted)
711 730
 				{
712 731
 					$guestvoted = explode(',', $guestvoted);
713
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
714
-						break;
732
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
733
+											break;
734
+					}
715 735
 				}
716 736
 				// Has the poll been reset since guest voted?
717 737
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
718 738
 				{
719 739
 					// Remove the poll info from the cookie to allow guest to vote again
720 740
 					unset($guestinfo[$i]);
721
-					if (!empty($guestinfo))
722
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
723
-					else
724
-						unset($_COOKIE['guest_poll_vote']);
725
-				}
726
-				else
741
+					if (!empty($guestinfo)) {
742
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
743
+					} else {
744
+											unset($_COOKIE['guest_poll_vote']);
745
+					}
746
+				} else
727 747
 				{
728 748
 					// What did they vote for?
729 749
 					unset($guestvoted[0], $guestvoted[1]);
@@ -837,23 +857,29 @@  discard block
 block discarded – undo
837 857
 		// Build the poll moderation button array.
838 858
 		$context['poll_buttons'] = array();
839 859
 
840
-		if ($context['allow_return_vote'])
841
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
860
+		if ($context['allow_return_vote']) {
861
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
862
+		}
842 863
 
843
-		if ($context['show_view_results_button'])
844
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
864
+		if ($context['show_view_results_button']) {
865
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
866
+		}
845 867
 
846
-		if ($context['allow_change_vote'])
847
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
868
+		if ($context['allow_change_vote']) {
869
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
870
+		}
848 871
 
849
-		if ($context['allow_lock_poll'])
850
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
872
+		if ($context['allow_lock_poll']) {
873
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
874
+		}
851 875
 
852
-		if ($context['allow_edit_poll'])
853
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
876
+		if ($context['allow_edit_poll']) {
877
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
878
+		}
854 879
 
855
-		if ($context['can_remove_poll'])
856
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
880
+		if ($context['can_remove_poll']) {
881
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
882
+		}
857 883
 
858 884
 		// Allow mods to add additional buttons here
859 885
 		call_integration_hook('integrate_poll_buttons');
@@ -889,9 +915,9 @@  discard block
 block discarded – undo
889 915
 	{
890 916
 		$start_char = 'C';
891 917
 		$page_id = $ascending ? $context['topicinfo']['id_first_msg'] : $context['topicinfo']['id_last_msg'];
918
+	} else {
919
+			$start_char = null;
892 920
 	}
893
-	else
894
-		$start_char = null;
895 921
 
896 922
 	$limit = $context['messages_per_page'];
897 923
 
@@ -905,17 +931,17 @@  discard block
 block discarded – undo
905 931
 		{
906 932
 			$ascending_seek = true;
907 933
 			$page_operator = $ascending ? '>=' : '<=';
908
-		}
909
-		else
934
+		} else
910 935
 		{
911 936
 			$ascending_seek = false;
912 937
 			$page_operator = $ascending ? '<=' : '>=';
913 938
 		}
914 939
 
915
-		if ($start_char === 'C')
916
-			$limit_seek = $limit;
917
-		else
918
-			$limit_seek  = $limit + 1;
940
+		if ($start_char === 'C') {
941
+					$limit_seek = $limit;
942
+		} else {
943
+					$limit_seek  = $limit + 1;
944
+		}
919 945
 
920 946
 		$request = $smcFunc['db_query']('', '
921 947
 			SELECT id_msg, id_member, approved
@@ -938,21 +964,23 @@  discard block
 block discarded – undo
938 964
 		$found_msg = false;
939 965
 
940 966
 		// Fallback
941
-		if ($smcFunc['db_num_rows']($request) < 1)
942
-			unset($start_char);
943
-		else
967
+		if ($smcFunc['db_num_rows']($request) < 1) {
968
+					unset($start_char);
969
+		} else
944 970
 		{
945 971
 			while ($row = $smcFunc['db_fetch_assoc']($request))
946 972
 			{
947 973
 				// Check if the start msg is in our result
948
-				if ($row['id_msg'] == $page_id)
949
-					$found_msg = true;
974
+				if ($row['id_msg'] == $page_id) {
975
+									$found_msg = true;
976
+				}
950 977
 
951 978
 				// Skip the the start msg if we not in mode C
952 979
 				if ($start_char === 'C' || $row['id_msg'] != $page_id)
953 980
 				{
954
-					if (!empty($row['id_member']))
955
-						$all_posters[$row['id_msg']] = $row['id_member'];
981
+					if (!empty($row['id_member'])) {
982
+											$all_posters[$row['id_msg']] = $row['id_member'];
983
+					}
956 984
 
957 985
 					$messages[] = $row['id_msg'];
958 986
 				}
@@ -968,8 +996,9 @@  discard block
 block discarded – undo
968 996
 		}
969 997
 
970 998
 		// Before Page bring in the right order
971
-		if (!empty($start_char) && $start_char === 'L')
972
-			krsort($messages);
999
+		if (!empty($start_char) && $start_char === 'L') {
1000
+					krsort($messages);
1001
+		}
973 1002
 	}
974 1003
 
975 1004
 	// Jump to page
@@ -1004,14 +1033,16 @@  discard block
 block discarded – undo
1004 1033
 
1005 1034
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1006 1035
 		{
1007
-			if (!empty($row['id_member']))
1008
-				$all_posters[$row['id_msg']] = $row['id_member'];
1036
+			if (!empty($row['id_member'])) {
1037
+							$all_posters[$row['id_msg']] = $row['id_member'];
1038
+			}
1009 1039
 			$messages[] = $row['id_msg'];
1010 1040
 		}
1011 1041
 
1012 1042
 		// Sort the messages into the correct display order
1013
-		if (!$ascending)
1014
-			sort($messages);
1043
+		if (!$ascending) {
1044
+					sort($messages);
1045
+		}
1015 1046
 	}
1016 1047
 
1017 1048
 	// Remember the paging data for next time
@@ -1031,8 +1062,9 @@  discard block
 block discarded – undo
1031 1062
 	if (!$user_info['is_guest'] && !empty($messages))
1032 1063
 	{
1033 1064
 		$mark_at_msg = max($messages);
1034
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
1035
-			$mark_at_msg = $modSettings['maxMsgID'];
1065
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
1066
+					$mark_at_msg = $modSettings['maxMsgID'];
1067
+		}
1036 1068
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
1037 1069
 		{
1038 1070
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -1064,8 +1096,9 @@  discard block
 block discarded – undo
1064 1096
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1065 1097
 		{
1066 1098
 			// Find if this topic is marked for notification...
1067
-			if (!empty($row['id_topic']))
1068
-				$context['is_marked_notify'] = true;
1099
+			if (!empty($row['id_topic'])) {
1100
+							$context['is_marked_notify'] = true;
1101
+			}
1069 1102
 
1070 1103
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
1071 1104
 			if (!empty($row['sent']) && $do_once)
@@ -1087,8 +1120,9 @@  discard block
 block discarded – undo
1087 1120
 		}
1088 1121
 
1089 1122
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
1090
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
1091
-			$_SESSION['topicseen_cache'][$board]--;
1123
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
1124
+					$_SESSION['topicseen_cache'][$board]--;
1125
+		}
1092 1126
 		// Mark board as seen if this is the only new topic.
1093 1127
 		elseif (isset($_REQUEST['topicseen']))
1094 1128
 		{
@@ -1112,14 +1146,16 @@  discard block
 block discarded – undo
1112 1146
 			$smcFunc['db_free_result']($request);
1113 1147
 
1114 1148
 			// If there're no real new topics in this board, mark the board as seen.
1115
-			if (empty($numNewTopics))
1116
-				$_REQUEST['boardseen'] = true;
1117
-			else
1118
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1149
+			if (empty($numNewTopics)) {
1150
+							$_REQUEST['boardseen'] = true;
1151
+			} else {
1152
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1153
+			}
1119 1154
 		}
1120 1155
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
1121
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
1122
-			$_SESSION['topicseen_cache'][$board]--;
1156
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1157
+					$_SESSION['topicseen_cache'][$board]--;
1158
+		}
1123 1159
 
1124 1160
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
1125 1161
 		if (isset($_REQUEST['boardseen']))
@@ -1176,23 +1212,26 @@  discard block
 block discarded – undo
1176 1212
 			$temp = array();
1177 1213
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1178 1214
 			{
1179
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1180
-					continue;
1215
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1216
+									continue;
1217
+				}
1181 1218
 
1182 1219
 				$temp[$row['id_attach']] = $row;
1183 1220
 				$temp[$row['id_attach']]['topic'] = $topic;
1184 1221
 				$temp[$row['id_attach']]['board'] = $board;
1185 1222
 
1186
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1187
-					$context['loaded_attachments'][$row['id_msg']] = array();
1223
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1224
+									$context['loaded_attachments'][$row['id_msg']] = array();
1225
+				}
1188 1226
 			}
1189 1227
 			$smcFunc['db_free_result']($request);
1190 1228
 
1191 1229
 			// This is better than sorting it with the query...
1192 1230
 			ksort($temp);
1193 1231
 
1194
-			foreach ($temp as $row)
1195
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1232
+			foreach ($temp as $row) {
1233
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1234
+			}
1196 1235
 		}
1197 1236
 
1198 1237
 		$msg_parameters = array(
@@ -1219,21 +1258,23 @@  discard block
 block discarded – undo
1219 1258
 		);
1220 1259
 
1221 1260
 		// And the likes
1222
-		if (!empty($modSettings['enable_likes']))
1223
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1261
+		if (!empty($modSettings['enable_likes'])) {
1262
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1263
+		}
1224 1264
 
1225 1265
 		// Go to the last message if the given time is beyond the time of the last message.
1226
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1227
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1266
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1267
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1268
+		}
1228 1269
 
1229 1270
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1230 1271
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1231
-		if (empty($options['view_newest_first']))
1232
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1233
-		else
1234
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1235
-	}
1236
-	else
1272
+		if (empty($options['view_newest_first'])) {
1273
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1274
+		} else {
1275
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1276
+		}
1277
+	} else
1237 1278
 	{
1238 1279
 		$messages_request = false;
1239 1280
 		$context['first_message'] = 0;
@@ -1268,8 +1309,9 @@  discard block
 block discarded – undo
1268 1309
 		'can_restore_msg' => 'move_any',
1269 1310
 		'can_like' => 'likes_like',
1270 1311
 	);
1271
-	foreach ($common_permissions as $contextual => $perm)
1272
-		$context[$contextual] = allowedTo($perm);
1312
+	foreach ($common_permissions as $contextual => $perm) {
1313
+			$context[$contextual] = allowedTo($perm);
1314
+	}
1273 1315
 
1274 1316
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1275 1317
 	$anyown_permissions = array(
@@ -1282,8 +1324,9 @@  discard block
 block discarded – undo
1282 1324
 		'can_reply_unapproved' => 'post_unapproved_replies',
1283 1325
 		'can_view_warning' => 'profile_warning',
1284 1326
 	);
1285
-	foreach ($anyown_permissions as $contextual => $perm)
1286
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1327
+	foreach ($anyown_permissions as $contextual => $perm) {
1328
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1329
+	}
1287 1330
 
1288 1331
 	if (!$user_info['is_admin'] && $context['can_move'] && !$modSettings['topic_move_any'])
1289 1332
 	{
@@ -1329,8 +1372,9 @@  discard block
 block discarded – undo
1329 1372
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1330 1373
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1331 1374
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1332
-	if (!empty($context['drafts_save']))
1333
-		loadLanguage('Drafts');
1375
+	if (!empty($context['drafts_save'])) {
1376
+			loadLanguage('Drafts');
1377
+	}
1334 1378
 
1335 1379
 	// When was the last time this topic was replied to?  Should we warn them about it?
1336 1380
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1391,26 +1435,31 @@  discard block
 block discarded – undo
1391 1435
 	// Message icons - customized icons are off?
1392 1436
 	$context['icons'] = getMessageIcons($board);
1393 1437
 
1394
-	if (!empty($context['icons']))
1395
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1438
+	if (!empty($context['icons'])) {
1439
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1440
+	}
1396 1441
 
1397 1442
 	// Build the normal button array.
1398 1443
 	$context['normal_buttons'] = array();
1399 1444
 
1400
-	if ($context['can_reply'])
1401
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1445
+	if ($context['can_reply']) {
1446
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1447
+	}
1402 1448
 
1403
-	if ($context['can_add_poll'])
1404
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1449
+	if ($context['can_add_poll']) {
1450
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1451
+	}
1405 1452
 
1406
-	if ($context['can_mark_unread'])
1407
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1453
+	if ($context['can_mark_unread']) {
1454
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1455
+	}
1408 1456
 
1409
-	if ($context['can_print'])
1410
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1457
+	if ($context['can_print']) {
1458
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1459
+	}
1411 1460
 
1412
-	if ($context['can_set_notify'])
1413
-		$context['normal_buttons']['notify'] = array(
1461
+	if ($context['can_set_notify']) {
1462
+			$context['normal_buttons']['notify'] = array(
1414 1463
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1415 1464
 			'sub_buttons' => array(
1416 1465
 				array(
@@ -1432,38 +1481,47 @@  discard block
 block discarded – undo
1432 1481
 				),
1433 1482
 			),
1434 1483
 		);
1484
+	}
1435 1485
 
1436 1486
 	// Build the mod button array
1437 1487
 	$context['mod_buttons'] = array();
1438 1488
 
1439
-	if ($context['can_move'])
1440
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1489
+	if ($context['can_move']) {
1490
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1491
+	}
1441 1492
 
1442
-	if ($context['can_delete'])
1443
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1493
+	if ($context['can_delete']) {
1494
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1495
+	}
1444 1496
 
1445
-	if ($context['can_lock'])
1446
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_locked'] ? 'unlock' : 'lock') . ';' . $context['session_var'] . '=' . $context['session_id']);
1497
+	if ($context['can_lock']) {
1498
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_locked'] ? 'unlock' : 'lock') . ';' . $context['session_var'] . '=' . $context['session_id']);
1499
+	}
1447 1500
 
1448
-	if ($context['can_sticky'])
1449
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_sticky'] ? 'nonsticky' : 'sticky') . ';' . $context['session_var'] . '=' . $context['session_id']);
1501
+	if ($context['can_sticky']) {
1502
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_sticky'] ? 'nonsticky' : 'sticky') . ';' . $context['session_var'] . '=' . $context['session_id']);
1503
+	}
1450 1504
 
1451
-	if ($context['can_merge'])
1452
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1505
+	if ($context['can_merge']) {
1506
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1507
+	}
1453 1508
 
1454
-	if ($context['calendar_post'])
1455
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1509
+	if ($context['calendar_post']) {
1510
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1511
+	}
1456 1512
 
1457 1513
 	// Restore topic. eh?  No monkey business.
1458
-	if ($context['can_restore_topic'])
1459
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1514
+	if ($context['can_restore_topic']) {
1515
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1516
+	}
1460 1517
 
1461 1518
 	// Show a message in case a recently posted message became unapproved.
1462 1519
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1463 1520
 
1464 1521
 	// Don't want to show this forever...
1465
-	if ($context['becomesUnapproved'])
1466
-		unset($_SESSION['becomesUnapproved']);
1522
+	if ($context['becomesUnapproved']) {
1523
+			unset($_SESSION['becomesUnapproved']);
1524
+	}
1467 1525
 
1468 1526
 	// Allow adding new mod buttons easily.
1469 1527
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1472,12 +1530,14 @@  discard block
 block discarded – undo
1472 1530
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1473 1531
 
1474 1532
 	// Load the drafts js file
1475
-	if ($context['drafts_autosave'])
1476
-		loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts');
1533
+	if ($context['drafts_autosave']) {
1534
+			loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts');
1535
+	}
1477 1536
 
1478 1537
 	// Spellcheck
1479
-	if ($context['show_spellchecking'])
1480
-		loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
1538
+	if ($context['show_spellchecking']) {
1539
+			loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
1540
+	}
1481 1541
 
1482 1542
 	// topic.js
1483 1543
 	loadJavaScriptFile('topic.js', array('defer' => false, 'minimize' => true), 'smf_topic');
@@ -1511,16 +1571,19 @@  discard block
 block discarded – undo
1511 1571
 	static $counter = null;
1512 1572
 
1513 1573
 	// If the query returned false, bail.
1514
-	if ($messages_request == false)
1515
-		return false;
1574
+	if ($messages_request == false) {
1575
+			return false;
1576
+	}
1516 1577
 
1517 1578
 	// Remember which message this is.  (ie. reply #83)
1518
-	if ($counter === null || $reset)
1519
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1579
+	if ($counter === null || $reset) {
1580
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1581
+	}
1520 1582
 
1521 1583
 	// Start from the beginning...
1522
-	if ($reset)
1523
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1584
+	if ($reset) {
1585
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1586
+	}
1524 1587
 
1525 1588
 	// Attempt to get the next message.
1526 1589
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1534,19 +1597,21 @@  discard block
 block discarded – undo
1534 1597
 	if (empty($context['icon_sources']))
1535 1598
 	{
1536 1599
 		$context['icon_sources'] = array();
1537
-		foreach ($context['stable_icons'] as $icon)
1538
-			$context['icon_sources'][$icon] = 'images_url';
1600
+		foreach ($context['stable_icons'] as $icon) {
1601
+					$context['icon_sources'][$icon] = 'images_url';
1602
+		}
1539 1603
 	}
1540 1604
 
1541 1605
 	// Message Icon Management... check the images exist.
1542 1606
 	if (empty($modSettings['messageIconChecks_disable']))
1543 1607
 	{
1544 1608
 		// If the current icon isn't known, then we need to do something...
1545
-		if (!isset($context['icon_sources'][$message['icon']]))
1546
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1609
+		if (!isset($context['icon_sources'][$message['icon']])) {
1610
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1611
+		}
1612
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1613
+			$context['icon_sources'][$message['icon']] = 'images_url';
1547 1614
 	}
1548
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1549
-		$context['icon_sources'][$message['icon']] = 'images_url';
1550 1615
 
1551 1616
 	// If you're a lazy bum, you probably didn't give a subject...
1552 1617
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1571,8 +1636,7 @@  discard block
 block discarded – undo
1571 1636
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1572 1637
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1573 1638
 		$memberContext[$message['id_member']]['is_guest'] = true;
1574
-	}
1575
-	else
1639
+	} else
1576 1640
 	{
1577 1641
 		// Define this here to make things a bit more readable
1578 1642
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1595,8 +1659,9 @@  discard block
 block discarded – undo
1595 1659
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1596 1660
 
1597 1661
 	// If it's in the recycle bin we need to override whatever icon we did have.
1598
-	if (!empty($board_info['recycle']))
1599
-		$message['icon'] = 'recycled';
1662
+	if (!empty($board_info['recycle'])) {
1663
+			$message['icon'] = 'recycled';
1664
+	}
1600 1665
 
1601 1666
 	require_once($sourcedir . '/Subs-Attachments.php');
1602 1667
 
@@ -1640,32 +1705,36 @@  discard block
 block discarded – undo
1640 1705
 	}
1641 1706
 
1642 1707
 	// Are likes enable?
1643
-	if (!empty($modSettings['enable_likes']))
1644
-		$output['likes'] = array(
1708
+	if (!empty($modSettings['enable_likes'])) {
1709
+			$output['likes'] = array(
1645 1710
 			'count' => $message['likes'],
1646 1711
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1647 1712
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1648 1713
 		);
1714
+	}
1649 1715
 
1650 1716
 	// Is this user the message author?
1651 1717
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1652
-	if (!empty($output['modified']['name']))
1653
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1718
+	if (!empty($output['modified']['name'])) {
1719
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1720
+	}
1654 1721
 
1655 1722
 	// Did they give a reason for editing?
1656
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1657
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1723
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1724
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1725
+	}
1658 1726
 
1659 1727
 	// Any custom profile fields?
1660
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1661
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1728
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1729
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1662 1730
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1731
+	}
1663 1732
 
1664
-	if (empty($options['view_newest_first']))
1665
-		$counter++;
1666
-
1667
-	else
1668
-		$counter--;
1733
+	if (empty($options['view_newest_first'])) {
1734
+			$counter++;
1735
+	} else {
1736
+			$counter--;
1737
+	}
1669 1738
 
1670 1739
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1671 1740
 
@@ -1691,8 +1760,9 @@  discard block
 block discarded – undo
1691 1760
  */
1692 1761
 function approved_attach_sort($a, $b)
1693 1762
 {
1694
-	if ($a['is_approved'] == $b['is_approved'])
1695
-		return 0;
1763
+	if ($a['is_approved'] == $b['is_approved']) {
1764
+			return 0;
1765
+	}
1696 1766
 
1697 1767
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1698 1768
 }
@@ -1709,16 +1779,19 @@  discard block
 block discarded – undo
1709 1779
 
1710 1780
 	require_once($sourcedir . '/RemoveTopic.php');
1711 1781
 
1712
-	if (empty($_REQUEST['msgs']))
1713
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1782
+	if (empty($_REQUEST['msgs'])) {
1783
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1784
+	}
1714 1785
 
1715 1786
 	$messages = array();
1716
-	foreach ($_REQUEST['msgs'] as $dummy)
1717
-		$messages[] = (int) $dummy;
1787
+	foreach ($_REQUEST['msgs'] as $dummy) {
1788
+			$messages[] = (int) $dummy;
1789
+	}
1718 1790
 
1719 1791
 	// We are restoring messages. We handle this in another place.
1720
-	if (isset($_REQUEST['restore_selected']))
1721
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1792
+	if (isset($_REQUEST['restore_selected'])) {
1793
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1794
+	}
1722 1795
 	if (isset($_REQUEST['split_selection']))
1723 1796
 	{
1724 1797
 		$request = $smcFunc['db_query']('', '
@@ -1737,8 +1810,9 @@  discard block
 block discarded – undo
1737 1810
 	}
1738 1811
 
1739 1812
 	// Allowed to delete any message?
1740
-	if (allowedTo('delete_any'))
1741
-		$allowed_all = true;
1813
+	if (allowedTo('delete_any')) {
1814
+			$allowed_all = true;
1815
+	}
1742 1816
 	// Allowed to delete replies to their messages?
1743 1817
 	elseif (allowedTo('delete_replies'))
1744 1818
 	{
@@ -1755,13 +1829,14 @@  discard block
 block discarded – undo
1755 1829
 		$smcFunc['db_free_result']($request);
1756 1830
 
1757 1831
 		$allowed_all = $starter == $user_info['id'];
1832
+	} else {
1833
+			$allowed_all = false;
1758 1834
 	}
1759
-	else
1760
-		$allowed_all = false;
1761 1835
 
1762 1836
 	// Make sure they're allowed to delete their own messages, if not any.
1763
-	if (!$allowed_all)
1764
-		isAllowedTo('delete_own');
1837
+	if (!$allowed_all) {
1838
+			isAllowedTo('delete_own');
1839
+	}
1765 1840
 
1766 1841
 	// Allowed to remove which messages?
1767 1842
 	$request = $smcFunc['db_query']('', '
@@ -1781,8 +1856,9 @@  discard block
 block discarded – undo
1781 1856
 	$messages = array();
1782 1857
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1783 1858
 	{
1784
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1785
-			continue;
1859
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1860
+					continue;
1861
+		}
1786 1862
 
1787 1863
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1788 1864
 	}
@@ -1805,17 +1881,20 @@  discard block
 block discarded – undo
1805 1881
 	foreach ($messages as $message => $info)
1806 1882
 	{
1807 1883
 		// Just skip the first message - if it's not the last.
1808
-		if ($message == $first_message && $message != $last_message)
1809
-			continue;
1884
+		if ($message == $first_message && $message != $last_message) {
1885
+					continue;
1886
+		}
1810 1887
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1811
-		elseif ($message == $first_message)
1812
-			$topicGone = true;
1888
+		elseif ($message == $first_message) {
1889
+					$topicGone = true;
1890
+		}
1813 1891
 
1814 1892
 		removeMessage($message);
1815 1893
 
1816 1894
 		// Log this moderation action ;).
1817
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1818
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1895
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1896
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1897
+		}
1819 1898
 	}
1820 1899
 
1821 1900
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Themes/default/Memberlist.template.php 1 patch
Braces   +30 added lines, -20 removed lines patch added patch discarded remove patch
@@ -27,9 +27,10 @@  discard block
 block discarded – undo
27 27
 			<h3 class="catbg">
28 28
 				<span class="floatleft">', $txt['members_list'], '</span>';
29 29
 
30
-	if (!isset($context['old_search']))
31
-		echo '
30
+	if (!isset($context['old_search'])) {
31
+			echo '
32 32
 				<span class="floatright">', $context['letter_links'], '</span>';
33
+	}
33 34
 	echo '
34 35
 			</h3>
35 36
 		</div>';
@@ -44,20 +45,23 @@  discard block
 block discarded – undo
44 45
 	foreach ($context['columns'] as $key => $column)
45 46
 	{
46 47
 		// @TODO maybe find something nicer?
47
-		if ($key == 'email_address' && !$context['can_send_email'])
48
-			continue;
48
+		if ($key == 'email_address' && !$context['can_send_email']) {
49
+					continue;
50
+		}
49 51
 
50 52
 		// This is a selected column, so underline it or some such.
51
-		if ($column['selected'])
52
-			echo '
53
+		if ($column['selected']) {
54
+					echo '
53 55
 						<th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', ' selected" style="width: auto;"' . (isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '') . '>
54 56
 							<a href="' . $column['href'] . '" rel="nofollow">' . $column['label'] . '</a><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></th>';
57
+		}
55 58
 
56 59
 		// This is just some column... show the link and be done with it.
57
-		else
58
-			echo '
60
+		else {
61
+					echo '
59 62
 						<th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', '"', isset($column['width']) ? ' style="width: ' . $column['width'] . '"' : '', isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '', '>
60 63
 						', $column['link'], '</th>';
64
+		}
61 65
 	}
62 66
 
63 67
 	echo '
@@ -77,9 +81,10 @@  discard block
 block discarded – undo
77 81
 						</td>
78 82
 						<td class="real_name lefttext">', $member['link'], '</td>';
79 83
 
80
-			if (!isset($context['disabled_fields']['website']))
81
-				echo '
84
+			if (!isset($context['disabled_fields']['website'])) {
85
+							echo '
82 86
 						<td class="website_url centertext">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" rel="noopener"><span class="generic_icons www" title="' . $member['website']['title'] . '"></span></a>' : '', '</td>';
87
+			}
83 88
 
84 89
 			// Group and date.
85 90
 			echo '
@@ -91,33 +96,36 @@  discard block
 block discarded – undo
91 96
 				echo '
92 97
 						<td class="post_count centertext">';
93 98
 
94
-				if (!empty($member['post_percent']))
95
-					echo '
99
+				if (!empty($member['post_percent'])) {
100
+									echo '
96 101
 							<div class="generic_bar">
97 102
 								<div class="bar" style="width: ', $member['post_percent'], '%;"></div>
98 103
 								<span>', $member['posts'], '</span>
99 104
 							</div>';
105
+				}
100 106
 
101 107
 				echo '
102 108
 						</td>';
103 109
 			}
104 110
 
105 111
 			// Show custom fields marked to be shown here
106
-			if (!empty($context['custom_profile_fields']['columns']))
107
-				foreach ($context['custom_profile_fields']['columns'] as $key => $column)
112
+			if (!empty($context['custom_profile_fields']['columns'])) {
113
+							foreach ($context['custom_profile_fields']['columns'] as $key => $column)
108 114
 					echo '
109 115
 						<td class="' , $key , ' centertext">', $member['options'][$key], '</td>';
116
+			}
110 117
 
111 118
 			echo '
112 119
 					</tr>';
113 120
 		}
114 121
 	}
115 122
 	// No members?
116
-	else
117
-		echo '
123
+	else {
124
+			echo '
118 125
 					<tr>
119 126
 						<td colspan="', $context['colspan'], '" class="windowbg">', $txt['search_no_results'], '</td>
120 127
 					</tr>';
128
+	}
121 129
 
122 130
 	echo '
123 131
 				</tbody>
@@ -130,11 +138,12 @@  discard block
 block discarded – undo
130 138
 			<div class="pagelinks floatleft">', $context['page_index'], '</div>';
131 139
 
132 140
 	// If it is displaying the result of a search show a "search again" link to edit their criteria.
133
-	if (isset($context['old_search']))
134
-		echo '
141
+	if (isset($context['old_search'])) {
142
+			echo '
135 143
 			<div class="buttonlist floatright">
136 144
 				<a class="button" href="', $scripturl, '?action=mlist;sa=search;search=', $context['old_search_value'], '">', $txt['mlist_search_again'], '</a>
137 145
 			</div>';
146
+	}
138 147
 	echo '
139 148
 		</div>
140 149
 	</div><!-- #memberlist -->';
@@ -174,12 +183,13 @@  discard block
 block discarded – undo
174 183
 					<dd>
175 184
 						<ul>';
176 185
 
177
-	foreach ($context['search_fields'] as $id => $title)
178
-		echo '
186
+	foreach ($context['search_fields'] as $id => $title) {
187
+			echo '
179 188
 							<li>
180 189
 								<input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '"', in_array($id, $context['search_defaults']) ? ' checked' : '', '>
181 190
 								<label for="fields-', $id, '">', $title, '</label>
182 191
 							</li>';
192
+	}
183 193
 
184 194
 	echo '
185 195
 						</ul>
Please login to merge, or discard this patch.
Sources/tasks/CreatePost-Notify.php 1 patch
Braces   +74 added lines, -54 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,26 +135,31 @@  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
 			// Don't send a notification if they don't want any...
147
-			if (in_array($frequency, array(self::FREQUENCY_NOTHING, self::FREQUENCY_DAILY_DIGEST, self::FREQUENCY_WEEKLY_DIGEST)))
148
-				continue;
152
+			if (in_array($frequency, array(self::FREQUENCY_NOTHING, self::FREQUENCY_DAILY_DIGEST, self::FREQUENCY_WEEKLY_DIGEST))) {
153
+							continue;
154
+			}
149 155
 			// ... or if we already sent one and they don't want more...
150
-			elseif ($frequency === self::FREQUENCY_FIRST_UNREAD_MSG && $data['sent'])
151
-				continue;
156
+			elseif ($frequency === self::FREQUENCY_FIRST_UNREAD_MSG && $data['sent']) {
157
+							continue;
158
+			}
152 159
 			// ... or if they aren't on the bouncer's list.
153
-			elseif (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only']))
154
-				continue;
160
+			elseif (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only'])) {
161
+							continue;
162
+			}
155 163
 
156 164
 			// Watched topic?
157 165
 			if (!empty($data['id_topic']) && $type != 'topic' && !empty($prefs[$member]))
@@ -161,10 +169,12 @@  discard block
 block discarded – undo
161 169
 
162 170
 				if ($type == 'reply')
163 171
 				{
164
-					if (!empty($prefs[$member]['msg_receive_body']))
165
-						$message_type .= '_body';
166
-					if (!empty($frequency))
167
-						$message_type .= '_once';
172
+					if (!empty($prefs[$member]['msg_receive_body'])) {
173
+											$message_type .= '_body';
174
+					}
175
+					if (!empty($frequency)) {
176
+											$message_type .= '_once';
177
+					}
168 178
 				}
169 179
 
170 180
 				$content_type = 'topic';
@@ -177,12 +187,14 @@  discard block
 block discarded – undo
177 187
 				$content_type = 'board';
178 188
 
179 189
 				$message_type = !empty($frequency) ? 'notify_boards_once' : 'notify_boards';
180
-				if (!empty($prefs[$member]['msg_receive_body']))
181
-					$message_type .= '_body';
190
+				if (!empty($prefs[$member]['msg_receive_body'])) {
191
+									$message_type .= '_body';
192
+				}
182 193
 			}
183 194
 			// If neither of the above, this might be a redundent row due to the OR clause in our SQL query, skip
184
-			else
185
-				continue;
195
+			else {
196
+							continue;
197
+			}
186 198
 
187 199
 			// Bitwise check: Receiving a email notification?
188 200
 			if ($pref & self::RECEIVE_NOTIFY_EMAIL)
@@ -199,8 +211,9 @@  discard block
 block discarded – undo
199 211
 				$mail_result = sendmail($data['email_address'], $emaildata['subject'], $emaildata['body'], null, 'm' . $topicOptions['id'], $emaildata['is_html']);
200 212
 
201 213
 				// We failed, don't trigger a alert as we don't have a way to attempt to resend just the email currently.
202
-				if ($mail_result === false)
203
-					continue;
214
+				if ($mail_result === false) {
215
+									continue;
216
+				}
204 217
 			}
205 218
 
206 219
 			// Bitwise check: Receiving a alert?
@@ -251,14 +264,15 @@  discard block
 block discarded – undo
251 264
 		);
252 265
 
253 266
 		// Insert the alerts if any
254
-		if (!empty($alert_rows))
255
-			$smcFunc['db_insert']('',
267
+		if (!empty($alert_rows)) {
268
+					$smcFunc['db_insert']('',
256 269
 				'{db_prefix}user_alerts',
257 270
 				array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
258 271
 					'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
259 272
 				$alert_rows,
260 273
 				array()
261 274
 			);
275
+		}
262 276
 
263 277
 		return true;
264 278
 	}
@@ -269,8 +283,9 @@  discard block
 block discarded – undo
269 283
 
270 284
 		foreach ($quotedMembers as $id => $member)
271 285
 		{
272
-			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote']))
273
-				continue;
286
+			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote'])) {
287
+							continue;
288
+			}
274 289
 
275 290
 			$done_members[] = $id;
276 291
 
@@ -324,32 +339,35 @@  discard block
 block discarded – undo
324 339
 		{
325 340
 			if (preg_match('/\[quote(.*)?\]/i', $block, $matches))
326 341
 			{
327
-				if ($quote_level == 0)
328
-					$message .= '[quote' . $matches[1] . ']';
342
+				if ($quote_level == 0) {
343
+									$message .= '[quote' . $matches[1] . ']';
344
+				}
329 345
 				$quote_level++;
330
-			}
331
-			elseif (preg_match('/\[\/quote\]/i', $block))
346
+			} elseif (preg_match('/\[\/quote\]/i', $block))
332 347
 			{
333
-				if ($quote_level <= 1)
334
-					$message .= '[/quote]';
348
+				if ($quote_level <= 1) {
349
+									$message .= '[/quote]';
350
+				}
335 351
 				if ($quote_level >= 1)
336 352
 				{
337 353
 					$quote_level--;
338 354
 					$message .= "\n";
339 355
 				}
356
+			} elseif ($quote_level <= 1) {
357
+							$message .= $block;
340 358
 			}
341
-			elseif ($quote_level <= 1)
342
-				$message .= $block;
343 359
 		}
344 360
 
345 361
 		preg_match_all('/\[quote.*?link=msg=([0-9]+).*?\]/i', $message, $matches);
346 362
 
347 363
 		$id_msgs = $matches[1];
348
-		foreach ($id_msgs as $k => $id_msg)
349
-			$id_msgs[$k] = (int) $id_msg;
364
+		foreach ($id_msgs as $k => $id_msg) {
365
+					$id_msgs[$k] = (int) $id_msg;
366
+		}
350 367
 
351
-		if (empty($id_msgs))
352
-			return array();
368
+		if (empty($id_msgs)) {
369
+					return array();
370
+		}
353 371
 
354 372
 		// Get the messages
355 373
 		$request = $smcFunc['db_query']('', '
@@ -367,8 +385,9 @@  discard block
 block discarded – undo
367 385
 		$members = array();
368 386
 		while ($row = $smcFunc['db_fetch_assoc']($request))
369 387
 		{
370
-			if ($posterOptions['id'] == $row['id_member'])
371
-				continue;
388
+			if ($posterOptions['id'] == $row['id_member']) {
389
+							continue;
390
+			}
372 391
 
373 392
 			$members[$row['id_member']] = $row;
374 393
 		}
@@ -382,10 +401,11 @@  discard block
 block discarded – undo
382 401
 
383 402
 		foreach ($members as $id => $member)
384 403
 		{
385
-			if (!empty($prefs[$id]['msg_mention']))
386
-				$done_members[] = $id;
387
-			else
388
-				continue;
404
+			if (!empty($prefs[$id]['msg_mention'])) {
405
+							$done_members[] = $id;
406
+			} else {
407
+							continue;
408
+			}
389 409
 
390 410
 			// Alerts' emails are always instant
391 411
 			if ($prefs[$id]['msg_mention'] & self::RECEIVE_NOTIFY_EMAIL)
Please login to merge, or discard this patch.
Themes/default/ManageSmileys.template.php 1 patch
Braces   +58 added lines, -44 removed lines patch added patch discarded remove patch
@@ -34,11 +34,12 @@  discard block
 block discarded – undo
34 34
 		</div>';
35 35
 
36 36
 	// If this is an existing set, and there are still un-added smileys - offer an import opportunity.
37
-	if (!empty($context['current_set']['can_import']))
38
-		echo '
37
+	if (!empty($context['current_set']['can_import'])) {
38
+			echo '
39 39
 		<div class="information noup">
40 40
 			', $context['current_set']['can_import'] == 1 ? sprintf($txt['smiley_set_import_single'], $context['current_set']['import_url']) : sprintf($txt['smiley_set_import_multiple'], $context['current_set']['can_import'], $context['current_set']['import_url']), '
41 41
 		</div>';
42
+	}
42 43
 
43 44
 	echo '
44 45
 		<div class="windowbg noup">
@@ -54,20 +55,20 @@  discard block
 block discarded – undo
54 55
 				</dt>
55 56
 				<dd>
56 57
 					', $modSettings['smileys_url'], '/';
57
-	if ($context['current_set']['id'] == 'default')
58
-		echo '<strong>default</strong><input type="hidden" name="smiley_sets_path" id="smiley_sets_path" value="default">';
59
-
60
-	elseif (empty($context['smiley_set_dirs']))
61
-		echo '
58
+	if ($context['current_set']['id'] == 'default') {
59
+			echo '<strong>default</strong><input type="hidden" name="smiley_sets_path" id="smiley_sets_path" value="default">';
60
+	} elseif (empty($context['smiley_set_dirs'])) {
61
+			echo '
62 62
 					<input type="text" name="smiley_sets_path" id="smiley_sets_path" value="', $context['current_set']['path'], '"> ';
63
-	else
63
+	} else
64 64
 	{
65 65
 		echo '
66 66
 					<select name="smiley_sets_path" id="smiley_sets_path">';
67 67
 
68
-		foreach ($context['smiley_set_dirs'] as $smiley_set_dir)
69
-			echo '
68
+		foreach ($context['smiley_set_dirs'] as $smiley_set_dir) {
69
+					echo '
70 70
 						<option value="', $smiley_set_dir['id'], '"', $smiley_set_dir['current'] ? ' selected' : '', $smiley_set_dir['selectable'] ? '' : ' disabled', '>', $smiley_set_dir['id'], '</option>';
71
+		}
71 72
 		echo '
72 73
 					</select> ';
73 74
 	}
@@ -82,14 +83,15 @@  discard block
 block discarded – undo
82 83
 				</dd>';
83 84
 
84 85
 	// If this is a new smiley set they have the option to import smileys already in the directory.
85
-	if ($context['current_set']['is_new'] && !empty($modSettings['smiley_enable']))
86
-		echo '
86
+	if ($context['current_set']['is_new'] && !empty($modSettings['smiley_enable'])) {
87
+			echo '
87 88
 				<dt>
88 89
 					<strong><label for="smiley_sets_import">', $txt['smiley_set_import_directory'], '</label>: </strong>
89 90
 				</dt>
90 91
 				<dd>
91 92
 					<input type="checkbox" name="smiley_sets_import" id="smiley_sets_import" value="1">
92 93
 				</dd>';
94
+	}
93 95
 
94 96
 	echo '
95 97
 			</dl>
@@ -121,9 +123,10 @@  discard block
 block discarded – undo
121 123
 				<dd>
122 124
 					<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $context['current_smiley']['filename'], '" id="preview" alt=""> ', $txt['smiley_preview_using'], ': <select name="set" onchange="updatePreview();">';
123 125
 
124
-	foreach ($context['smiley_sets'] as $smiley_set)
125
-		echo '
126
+	foreach ($context['smiley_sets'] as $smiley_set) {
127
+			echo '
126 128
 					<option value="', $smiley_set['path'], '"', $context['selected_set'] == $smiley_set['path'] ? ' selected' : '', '>', $smiley_set['name'], '</option>';
129
+	}
127 130
 
128 131
 	echo '
129 132
 					</select>
@@ -139,17 +142,18 @@  discard block
 block discarded – undo
139 142
 				</dt>
140 143
 				<dd>';
141 144
 
142
-	if (empty($context['filenames']))
143
-		echo '
145
+	if (empty($context['filenames'])) {
146
+			echo '
144 147
 					<input type="text" name="smiley_filename" id="smiley_filename" value="', $context['current_smiley']['filename'], '">';
145
-	else
148
+	} else
146 149
 	{
147 150
 		echo '
148 151
 					<select name="smiley_filename" id="smiley_filename" onchange="updatePreview();">';
149 152
 
150
-		foreach ($context['filenames'] as $filename)
151
-			echo '
153
+		foreach ($context['filenames'] as $filename) {
154
+					echo '
152 155
 						<option value="', $filename['id'], '"', $filename['selected'] ? ' selected' : '', '>', $filename['id'], '</option>';
156
+		}
153 157
 		echo '
154 158
 					</select>';
155 159
 	}
@@ -216,9 +220,10 @@  discard block
 block discarded – undo
216 220
 					<dd>
217 221
 						', $txt['smiley_preview_using'], ': <select name="set" onchange="updatePreview();selectMethod(\'existing\');">';
218 222
 
219
-	foreach ($context['smiley_sets'] as $smiley_set)
220
-		echo '
223
+	foreach ($context['smiley_sets'] as $smiley_set) {
224
+			echo '
221 225
 							<option value="', $smiley_set['path'], '"', $context['selected_set'] == $smiley_set['path'] ? ' selected' : '', '>', $smiley_set['name'], '</option>';
226
+	}
222 227
 
223 228
 	echo '
224 229
 						</select>
@@ -228,17 +233,18 @@  discard block
 block discarded – undo
228 233
 					</dt>
229 234
 					<dd>';
230 235
 
231
-	if (empty($context['filenames']))
232
-		echo '
236
+	if (empty($context['filenames'])) {
237
+			echo '
233 238
 						<input type="text" name="smiley_filename" id="smiley_filename" value="', $context['current_smiley']['filename'], '" onchange="selectMethod(\'existing\');">';
234
-	else
239
+	} else
235 240
 	{
236 241
 		echo '
237 242
 						<select name="smiley_filename" id="smiley_filename" onchange="updatePreview();selectMethod(\'existing\');">';
238 243
 
239
-		foreach ($context['filenames'] as $filename)
240
-			echo '
244
+		foreach ($context['filenames'] as $filename) {
245
+					echo '
241 246
 							<option value="', $filename['id'], '"', $filename['selected'] ? ' selected' : '', '>', $filename['id'], '</option>';
247
+		}
242 248
 		echo '
243 249
 						</select>';
244 250
 	}
@@ -267,14 +273,15 @@  discard block
 block discarded – undo
267 273
 
268 274
 			<dl id="uploadMore" style="display: none;" class="settings">';
269 275
 
270
-	foreach ($context['smiley_sets'] as $smiley_set)
271
-		echo '
276
+	foreach ($context['smiley_sets'] as $smiley_set) {
277
+			echo '
272 278
 				<dt>
273 279
 					', sprintf($txt['smileys_add_upload_for'], '<strong>' . $smiley_set['name'] . '</strong>'), ':
274 280
 				</dt>
275 281
 				<dd>
276 282
 					<input type="file" name="individual_', $smiley_set['name'], '" onchange="selectMethod(\'upload\');">
277 283
 				</dd>';
284
+	}
278 285
 
279 286
 	echo '
280 287
 			</dl>
@@ -341,27 +348,30 @@  discard block
 block discarded – undo
341 348
 
342 349
 		foreach ($location['rows'] as $row)
343 350
 		{
344
-			if (!empty($context['move_smiley']))
345
-				echo '
351
+			if (!empty($context['move_smiley'])) {
352
+							echo '
346 353
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';row=', $row[0]['row'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons select_below" title="', $txt['smileys_move_here'], '"></span></a>';
354
+			}
347 355
 
348 356
 			foreach ($row as $smiley)
349 357
 			{
350
-				if (empty($context['move_smiley']))
351
-					echo '
358
+				if (empty($context['move_smiley'])) {
359
+									echo '
352 360
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;move=', $smiley['id'], '"><img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $smiley['filename'], '" alt="', $smiley['description'], '"></a>';
353
-				else
354
-					echo '
361
+				} else {
362
+									echo '
355 363
 			<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $smiley['filename'], '" alt="', $smiley['description'], '" ', $smiley['selected'] ? 'class="selected_item"' : '', '>
356 364
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';after=', $smiley['id'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '" title="', $txt['smileys_move_here'], '"><span class="generic_icons select_below" title="', $txt['smileys_move_here'], '"></span></a>';
365
+				}
357 366
 			}
358 367
 
359 368
 			echo '
360 369
 			<br>';
361 370
 		}
362
-		if (!empty($context['move_smiley']))
363
-			echo '
371
+		if (!empty($context['move_smiley'])) {
372
+					echo '
364 373
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';row=', $location['last_row'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons select_below" title="', $txt['smileys_move_here'], '"></span></a>';
374
+		}
365 375
 		echo '
366 376
 		</div><!-- .windowbg -->
367 377
 		<input type="hidden" name="reorder" value="1">
@@ -394,14 +404,15 @@  discard block
 block discarded – undo
394 404
 		<div class="windowbg">
395 405
 			<dl class="settings">';
396 406
 
397
-	if (!$context['new_icon'])
398
-		echo '
407
+	if (!$context['new_icon']) {
408
+			echo '
399 409
 				<dt>
400 410
 					<strong>', $txt['smiley_preview'], ': </strong>
401 411
 				</dt>
402 412
 				<dd>
403 413
 					<img src="', $context['icon']['image_url'], '" alt="', $context['icon']['title'], '">
404 414
 				</dd>';
415
+	}
405 416
 
406 417
 	echo '
407 418
 				<dt>
@@ -428,9 +439,10 @@  discard block
 block discarded – undo
428 439
 		echo '
429 440
 						<optgroup label="', $category['name'], '">';
430 441
 
431
-		foreach ($category['boards'] as $board)
432
-			echo '
442
+		foreach ($category['boards'] as $board) {
443
+					echo '
433 444
 							<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
445
+		}
434 446
 
435 447
 		echo '
436 448
 						</optgroup>';
@@ -447,19 +459,21 @@  discard block
 block discarded – undo
447 459
 						<option value="0"', empty($context['icon']['after']) ? ' selected' : '', '>', $txt['icons_location_first_icon'], '</option>';
448 460
 
449 461
 	// Print the list of all the icons it can be put after...
450
-	foreach ($context['icons'] as $id => $data)
451
-		if (empty($context['icon']['id']) || $id != $context['icon']['id'])
462
+	foreach ($context['icons'] as $id => $data) {
463
+			if (empty($context['icon']['id']) || $id != $context['icon']['id'])
452 464
 			echo '
453 465
 						<option value="', $id, '"', !empty($context['icon']['after']) && $id == $context['icon']['after'] ? ' selected' : '', '>', $txt['icons_location_after'], ': ', $data['title'], '</option>';
466
+	}
454 467
 
455 468
 	echo '
456 469
 					</select>
457 470
 				</dd>
458 471
 			</dl>';
459 472
 
460
-	if (!$context['new_icon'])
461
-		echo '
473
+	if (!$context['new_icon']) {
474
+			echo '
462 475
 			<input type="hidden" name="icon" value="', $context['icon']['id'], '">';
476
+	}
463 477
 
464 478
 	echo '
465 479
 			<input type="submit" name="icons_save" value="', $txt['smileys_save'], '" class="button">
Please login to merge, or discard this patch.
Sources/Post.php 1 patch
Braces   +677 added lines, -523 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
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -60,12 +63,14 @@  discard block
 block discarded – undo
60 63
 	{
61 64
 		// Get ids of all the boards they can post in.
62 65
 		$post_permissions = array('post_new');
63
-		if ($modSettings['postmod_active'])
64
-			$post_permissions[] = 'post_unapproved_topics';
66
+		if ($modSettings['postmod_active']) {
67
+					$post_permissions[] = 'post_unapproved_topics';
68
+		}
65 69
 
66 70
 		$boards = boardsAllowedTo($post_permissions);
67
-		if (empty($boards))
68
-			fatal_lang_error('cannot_post_new', false);
71
+		if (empty($boards)) {
72
+					fatal_lang_error('cannot_post_new', false);
73
+		}
69 74
 
70 75
 		// Get a list of boards for the select menu
71 76
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -78,8 +83,9 @@  discard block
 block discarded – undo
78 83
 		$board_list = getBoardList($boardListOptions);
79 84
 	}
80 85
 	// Let's keep things simple for ourselves below
81
-	else
82
-		$boards = array($board);
86
+	else {
87
+			$boards = array($board);
88
+	}
83 89
 
84 90
 	require_once($sourcedir . '/Subs-Post.php');
85 91
 
@@ -102,10 +108,11 @@  discard block
 block discarded – undo
102 108
 			array(
103 109
 				'msg' => (int) $_REQUEST['msg'],
104 110
 		));
105
-		if ($smcFunc['db_num_rows']($request) != 1)
106
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
107
-		else
108
-			list ($topic) = $smcFunc['db_fetch_row']($request);
111
+		if ($smcFunc['db_num_rows']($request) != 1) {
112
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
113
+		} else {
114
+					list ($topic) = $smcFunc['db_fetch_row']($request);
115
+		}
109 116
 		$smcFunc['db_free_result']($request);
110 117
 	}
111 118
 
@@ -132,33 +139,36 @@  discard block
 block discarded – undo
132 139
 		$smcFunc['db_free_result']($request);
133 140
 
134 141
 		// If this topic already has a poll, they sure can't add another.
135
-		if (isset($_REQUEST['poll']) && $pollID > 0)
136
-			unset($_REQUEST['poll']);
142
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
143
+					unset($_REQUEST['poll']);
144
+		}
137 145
 
138 146
 		if (empty($_REQUEST['msg']))
139 147
 		{
140
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
141
-				is_not_guest();
148
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
149
+							is_not_guest();
150
+			}
142 151
 
143 152
 			// By default the reply will be approved...
144 153
 			$context['becomes_approved'] = true;
145 154
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
146 155
 			{
147
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
148
-					$context['becomes_approved'] = false;
149
-				else
150
-					isAllowedTo('post_reply_any');
151
-			}
152
-			elseif (!allowedTo('post_reply_any'))
156
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
157
+									$context['becomes_approved'] = false;
158
+				} else {
159
+									isAllowedTo('post_reply_any');
160
+				}
161
+			} elseif (!allowedTo('post_reply_any'))
153 162
 			{
154
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
155
-					$context['becomes_approved'] = false;
156
-				else
157
-					isAllowedTo('post_reply_own');
163
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
164
+									$context['becomes_approved'] = false;
165
+				} else {
166
+									isAllowedTo('post_reply_own');
167
+				}
158 168
 			}
169
+		} else {
170
+					$context['becomes_approved'] = true;
159 171
 		}
160
-		else
161
-			$context['becomes_approved'] = true;
162 172
 
163 173
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
164 174
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -173,17 +183,18 @@  discard block
 block discarded – undo
173 183
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
174 184
 
175 185
 		// Check whether this is a really old post being bumped...
176
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
177
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
178
-	}
179
-	else
186
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
187
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
188
+		}
189
+	} else
180 190
 	{
181 191
 		// @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu
182 192
 		$context['becomes_approved'] = true;
183
-		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true))
184
-			$context['becomes_approved'] = false;
185
-		else
186
-			isAllowedTo('post_new', $boards, true);
193
+		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) {
194
+					$context['becomes_approved'] = false;
195
+		} else {
196
+					isAllowedTo('post_new', $boards, true);
197
+		}
187 198
 
188 199
 		$locked = 0;
189 200
 		$context['already_locked'] = 0;
@@ -213,27 +224,32 @@  discard block
 block discarded – undo
213 224
 	if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached']))
214 225
 	{
215 226
 		require_once($sourcedir . '/ManageAttachments.php');
216
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
217
-			removeAttachments(array('id_attach' => $attachID));
227
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
228
+					removeAttachments(array('id_attach' => $attachID));
229
+		}
218 230
 
219 231
 		unset($_SESSION['already_attached']);
220 232
 	}
221 233
 
222 234
 	// Don't allow a post if it's locked and you aren't all powerful.
223
-	if ($locked && !allowedTo('moderate_board'))
224
-		fatal_lang_error('topic_locked', false);
235
+	if ($locked && !allowedTo('moderate_board')) {
236
+			fatal_lang_error('topic_locked', false);
237
+	}
225 238
 	// Check the users permissions - is the user allowed to add or post a poll?
226 239
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
227 240
 	{
228 241
 		// New topic, new poll.
229
-		if (empty($topic))
230
-			isAllowedTo('poll_post');
242
+		if (empty($topic)) {
243
+					isAllowedTo('poll_post');
244
+		}
231 245
 		// This is an old topic - but it is yours!  Can you add to it?
232
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
233
-			isAllowedTo('poll_add_own');
246
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
247
+					isAllowedTo('poll_add_own');
248
+		}
234 249
 		// If you're not the owner, can you add to any poll?
235
-		else
236
-			isAllowedTo('poll_add_any');
250
+		else {
251
+					isAllowedTo('poll_add_any');
252
+		}
237 253
 
238 254
 		if (!empty($board))
239 255
 		{
@@ -242,8 +258,9 @@  discard block
 block discarded – undo
242 258
 			$guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']);
243 259
 		}
244 260
 		// No board, so we'll have to check this again in Post2
245
-		else
246
-			$guest_vote_enabled = true;
261
+		else {
262
+					$guest_vote_enabled = true;
263
+		}
247 264
 
248 265
 		// Set up the poll options.
249 266
 		$context['poll_options'] = array(
@@ -269,8 +286,9 @@  discard block
 block discarded – undo
269 286
 	if ($context['make_event'])
270 287
 	{
271 288
 		// They might want to pick a board.
272
-		if (!isset($context['current_board']))
273
-			$context['current_board'] = 0;
289
+		if (!isset($context['current_board'])) {
290
+					$context['current_board'] = 0;
291
+		}
274 292
 
275 293
 		// Start loading up the event info.
276 294
 		$context['event'] = array();
@@ -284,10 +302,11 @@  discard block
 block discarded – undo
284 302
 		isAllowedTo('calendar_post');
285 303
 
286 304
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
287
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
288
-			$time_string = '%k:%M';
289
-		else
290
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
305
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
306
+					$time_string = '%k:%M';
307
+		} else {
308
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
309
+		}
291 310
 
292 311
 		$js_time_string = str_replace(
293 312
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -309,8 +328,7 @@  discard block
 block discarded – undo
309 328
 			require_once($sourcedir . '/Subs-Calendar.php');
310 329
 			$eventProperties = getEventProperties($context['event']['id']);
311 330
 			$context['event'] = array_merge($context['event'], $eventProperties);
312
-		}
313
-		else
331
+		} else
314 332
 		{
315 333
 			// Get the current event information.
316 334
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -318,10 +336,12 @@  discard block
 block discarded – undo
318 336
 			$context['event'] = array_merge($context['event'], $eventProperties);
319 337
 
320 338
 			// Make sure the year and month are in the valid range.
321
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
322
-				fatal_lang_error('invalid_month', false);
323
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
324
-				fatal_lang_error('invalid_year', false);
339
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
340
+							fatal_lang_error('invalid_month', false);
341
+			}
342
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
343
+							fatal_lang_error('invalid_year', false);
344
+			}
325 345
 
326 346
 			$context['event']['categories'] = $board_list;
327 347
 		}
@@ -432,10 +452,11 @@  discard block
 block discarded – undo
432 452
 
433 453
 			if (!empty($context['new_replies']))
434 454
 			{
435
-				if ($context['new_replies'] == 1)
436
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
437
-				else
438
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
455
+				if ($context['new_replies'] == 1) {
456
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
457
+				} else {
458
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
459
+				}
439 460
 
440 461
 				$post_errors[] = 'new_replies';
441 462
 
@@ -447,9 +468,9 @@  discard block
 block discarded – undo
447 468
 	// Get a response prefix (like 'Re:') in the default forum language.
448 469
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
449 470
 	{
450
-		if ($language === $user_info['language'])
451
-			$context['response_prefix'] = $txt['response_prefix'];
452
-		else
471
+		if ($language === $user_info['language']) {
472
+					$context['response_prefix'] = $txt['response_prefix'];
473
+		} else
453 474
 		{
454 475
 			loadLanguage('index', $language, false);
455 476
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -462,23 +483,26 @@  discard block
 block discarded – undo
462 483
 	// Do we have a body, but an error happened.
463 484
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
464 485
 	{
465
-		if (isset($_REQUEST['quickReply']))
466
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
486
+		if (isset($_REQUEST['quickReply'])) {
487
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
488
+		}
467 489
 
468 490
 		// Validate inputs.
469 491
 		if (empty($context['post_error']))
470 492
 		{
471 493
 			// This means they didn't click Post and get an error.
472 494
 			$really_previewing = true;
473
-		}
474
-		else
495
+		} else
475 496
 		{
476
-			if (!isset($_REQUEST['subject']))
477
-				$_REQUEST['subject'] = '';
478
-			if (!isset($_REQUEST['message']))
479
-				$_REQUEST['message'] = '';
480
-			if (!isset($_REQUEST['icon']))
481
-				$_REQUEST['icon'] = 'xx';
497
+			if (!isset($_REQUEST['subject'])) {
498
+							$_REQUEST['subject'] = '';
499
+			}
500
+			if (!isset($_REQUEST['message'])) {
501
+							$_REQUEST['message'] = '';
502
+			}
503
+			if (!isset($_REQUEST['icon'])) {
504
+							$_REQUEST['icon'] = 'xx';
505
+			}
482 506
 
483 507
 			// They are previewing if they asked to preview (i.e. came from quick reply).
484 508
 			$really_previewing = !empty($_POST['preview']);
@@ -494,8 +518,9 @@  discard block
 block discarded – undo
494 518
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
495 519
 
496 520
 		// Make sure the subject isn't too long - taking into account special characters.
497
-		if ($smcFunc['strlen']($form_subject) > 100)
498
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
521
+		if ($smcFunc['strlen']($form_subject) > 100) {
522
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
523
+		}
499 524
 
500 525
 		if (isset($_REQUEST['poll']))
501 526
 		{
@@ -507,8 +532,9 @@  discard block
 block discarded – undo
507 532
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
508 533
 			foreach ($_POST['options'] as $option)
509 534
 			{
510
-				if (trim($option) == '')
511
-					continue;
535
+				if (trim($option) == '') {
536
+									continue;
537
+				}
512 538
 
513 539
 				$context['choices'][] = array(
514 540
 					'id' => $choice_id++,
@@ -570,13 +596,14 @@  discard block
 block discarded – undo
570 596
 				$context['preview_subject'] = $form_subject;
571 597
 
572 598
 				censorText($context['preview_subject']);
599
+			} else {
600
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
573 601
 			}
574
-			else
575
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
576 602
 
577 603
 			// Protect any CDATA blocks.
578
-			if (isset($_REQUEST['xml']))
579
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
604
+			if (isset($_REQUEST['xml'])) {
605
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
606
+			}
580 607
 		}
581 608
 
582 609
 		// Set up the checkboxes.
@@ -615,29 +642,32 @@  discard block
 block discarded – undo
615 642
 			);
616 643
 			// The message they were trying to edit was most likely deleted.
617 644
 			// @todo Change this error message?
618
-			if ($smcFunc['db_num_rows']($request) == 0)
619
-				fatal_lang_error('no_board', false);
645
+			if ($smcFunc['db_num_rows']($request) == 0) {
646
+							fatal_lang_error('no_board', false);
647
+			}
620 648
 			$row = $smcFunc['db_fetch_assoc']($request);
621 649
 
622 650
 			$attachment_stuff = array($row);
623
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
624
-				$attachment_stuff[] = $row2;
651
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
652
+							$attachment_stuff[] = $row2;
653
+			}
625 654
 			$smcFunc['db_free_result']($request);
626 655
 
627 656
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
628 657
 			{
629 658
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
630
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
631
-					fatal_lang_error('modify_post_time_passed', false);
632
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
633
-					isAllowedTo('modify_replies');
634
-				else
635
-					isAllowedTo('modify_own');
659
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
660
+									fatal_lang_error('modify_post_time_passed', false);
661
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
662
+									isAllowedTo('modify_replies');
663
+				} else {
664
+									isAllowedTo('modify_own');
665
+				}
666
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
667
+							isAllowedTo('modify_replies');
668
+			} else {
669
+							isAllowedTo('modify_any');
636 670
 			}
637
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
638
-				isAllowedTo('modify_replies');
639
-			else
640
-				isAllowedTo('modify_any');
641 671
 
642 672
 			if ($context['can_announce'] && !empty($row['id_action']))
643 673
 			{
@@ -661,8 +691,9 @@  discard block
 block discarded – undo
661 691
 
662 692
 				while ($row = $smcFunc['db_fetch_assoc']($request))
663 693
 				{
664
-					if ($row['filesize'] <= 0)
665
-						continue;
694
+					if ($row['filesize'] <= 0) {
695
+											continue;
696
+					}
666 697
 					$context['current_attachments'][$row['id_attach']] = array(
667 698
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
668 699
 						'size' => $row['filesize'],
@@ -732,29 +763,32 @@  discard block
 block discarded – undo
732 763
 			)
733 764
 		);
734 765
 		// The message they were trying to edit was most likely deleted.
735
-		if ($smcFunc['db_num_rows']($request) == 0)
736
-			fatal_lang_error('no_message', false);
766
+		if ($smcFunc['db_num_rows']($request) == 0) {
767
+					fatal_lang_error('no_message', false);
768
+		}
737 769
 		$row = $smcFunc['db_fetch_assoc']($request);
738 770
 
739 771
 		$attachment_stuff = array($row);
740
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
741
-			$attachment_stuff[] = $row2;
772
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
773
+					$attachment_stuff[] = $row2;
774
+		}
742 775
 		$smcFunc['db_free_result']($request);
743 776
 
744 777
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
745 778
 		{
746 779
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
747
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
748
-				fatal_lang_error('modify_post_time_passed', false);
749
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
750
-				isAllowedTo('modify_replies');
751
-			else
752
-				isAllowedTo('modify_own');
780
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
781
+							fatal_lang_error('modify_post_time_passed', false);
782
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
783
+							isAllowedTo('modify_replies');
784
+			} else {
785
+							isAllowedTo('modify_own');
786
+			}
787
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
788
+					isAllowedTo('modify_replies');
789
+		} else {
790
+					isAllowedTo('modify_any');
753 791
 		}
754
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
755
-			isAllowedTo('modify_replies');
756
-		else
757
-			isAllowedTo('modify_any');
758 792
 
759 793
 		if ($context['can_announce'] && !empty($row['id_action']))
760 794
 		{
@@ -781,15 +815,17 @@  discard block
 block discarded – undo
781 815
 		$context['icon'] = $row['icon'];
782 816
 
783 817
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
784
-		if (!$row['approved'] && !$context['show_approval'])
785
-			$context['show_approval'] = allowedTo('approve_posts');
818
+		if (!$row['approved'] && !$context['show_approval']) {
819
+					$context['show_approval'] = allowedTo('approve_posts');
820
+		}
786 821
 
787 822
 		// Sort the attachments so they are in the order saved
788 823
 		$temp = array();
789 824
 		foreach ($attachment_stuff as $attachment)
790 825
 		{
791
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
792
-				$temp[$attachment['id_attach']] = $attachment;
826
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
827
+							$temp[$attachment['id_attach']] = $attachment;
828
+			}
793 829
 		}
794 830
 		ksort($temp);
795 831
 
@@ -850,14 +886,16 @@  discard block
 block discarded – undo
850 886
 					'is_approved' => 1,
851 887
 				)
852 888
 			);
853
-			if ($smcFunc['db_num_rows']($request) == 0)
854
-				fatal_lang_error('quoted_post_deleted', false);
889
+			if ($smcFunc['db_num_rows']($request) == 0) {
890
+							fatal_lang_error('quoted_post_deleted', false);
891
+			}
855 892
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
856 893
 			$smcFunc['db_free_result']($request);
857 894
 
858 895
 			// Add 'Re: ' to the front of the quoted subject.
859
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
860
-				$form_subject = $context['response_prefix'] . $form_subject;
896
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
897
+							$form_subject = $context['response_prefix'] . $form_subject;
898
+			}
861 899
 
862 900
 			// Censor the message and subject.
863 901
 			censorText($form_message);
@@ -870,10 +908,11 @@  discard block
 block discarded – undo
870 908
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
871 909
 				{
872 910
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
873
-					if ($i % 4 == 0)
874
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
911
+					if ($i % 4 == 0) {
912
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
875 913
 						{
876 914
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
915
+					}
877 916
 						}, $parts[$i]);
878 917
 				}
879 918
 				$form_message = implode('', $parts);
@@ -882,8 +921,9 @@  discard block
 block discarded – undo
882 921
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
883 922
 
884 923
 			// Remove any nested quotes, if necessary.
885
-			if (!empty($modSettings['removeNestedQuotes']))
886
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
924
+			if (!empty($modSettings['removeNestedQuotes'])) {
925
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
926
+			}
887 927
 
888 928
 			// Add a quote string on the front and end.
889 929
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -895,15 +935,15 @@  discard block
 block discarded – undo
895 935
 			$form_subject = $first_subject;
896 936
 
897 937
 			// Add 'Re: ' to the front of the subject.
898
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
899
-				$form_subject = $context['response_prefix'] . $form_subject;
938
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
939
+							$form_subject = $context['response_prefix'] . $form_subject;
940
+			}
900 941
 
901 942
 			// Censor the subject.
902 943
 			censorText($form_subject);
903 944
 
904 945
 			$form_message = '';
905
-		}
906
-		else
946
+		} else
907 947
 		{
908 948
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
909 949
 			$form_message = '';
@@ -922,13 +962,15 @@  discard block
 block discarded – undo
922 962
 		if (isset($_REQUEST['msg']))
923 963
 		{
924 964
 			$context['attachments']['quantity'] = count($context['current_attachments']);
925
-			foreach ($context['current_attachments'] as $attachment)
926
-				$context['attachments']['total_size'] += $attachment['size'];
965
+			foreach ($context['current_attachments'] as $attachment) {
966
+							$context['attachments']['total_size'] += $attachment['size'];
967
+			}
927 968
 		}
928 969
 
929 970
 		// A bit of house keeping first.
930
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
931
-			unset($_SESSION['temp_attachments']);
971
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
972
+					unset($_SESSION['temp_attachments']);
973
+		}
932 974
 
933 975
 		if (!empty($_SESSION['temp_attachments']))
934 976
 		{
@@ -937,9 +979,10 @@  discard block
 block discarded – undo
937 979
 			{
938 980
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
939 981
 				{
940
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
941
-						if (file_exists($attachment['tmp_name']))
982
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
983
+											if (file_exists($attachment['tmp_name']))
942 984
 							unlink($attachment['tmp_name']);
985
+					}
943 986
 				}
944 987
 				$post_errors[] = 'temp_attachments_gone';
945 988
 				$_SESSION['temp_attachments'] = array();
@@ -953,8 +996,9 @@  discard block
 block discarded – undo
953 996
 					// See if any files still exist before showing the warning message and the files attached.
954 997
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
955 998
 					{
956
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
957
-							continue;
999
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1000
+													continue;
1001
+						}
958 1002
 
959 1003
 						if (file_exists($attachment['tmp_name']))
960 1004
 						{
@@ -964,20 +1008,21 @@  discard block
 block discarded – undo
964 1008
 							break;
965 1009
 						}
966 1010
 					}
967
-				}
968
-				else
1011
+				} else
969 1012
 				{
970 1013
 					// Since, they don't belong here. Let's inform the user that they exist..
971
-					if (!empty($topic))
972
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
973
-					else
974
-						$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1014
+					if (!empty($topic)) {
1015
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
1016
+					} else {
1017
+											$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1018
+					}
975 1019
 
976 1020
 					// Compile a list of the files to show the user.
977 1021
 					$file_list = array();
978
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
979
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1022
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1023
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
980 1024
 							$file_list[] = $attachment['name'];
1025
+					}
981 1026
 
982 1027
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
983 1028
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -989,8 +1034,7 @@  discard block
 block discarded – undo
989 1034
 
990 1035
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
991 1036
 						$context['ignore_temp_attachments'] = true;
992
-					}
993
-					else
1037
+					} else
994 1038
 					{
995 1039
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
996 1040
 						$context['ignore_temp_attachments'] = true;
@@ -998,16 +1042,19 @@  discard block
 block discarded – undo
998 1042
 				}
999 1043
 			}
1000 1044
 
1001
-			if (!empty($context['we_are_history']))
1002
-				$post_errors[] = $context['we_are_history'];
1045
+			if (!empty($context['we_are_history'])) {
1046
+							$post_errors[] = $context['we_are_history'];
1047
+			}
1003 1048
 
1004 1049
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1005 1050
 			{
1006
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
1007
-					break;
1051
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1052
+									break;
1053
+				}
1008 1054
 
1009
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1010
-					continue;
1055
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1056
+									continue;
1057
+				}
1011 1058
 
1012 1059
 				if ($attachID == 'initial_error')
1013 1060
 				{
@@ -1022,15 +1069,17 @@  discard block
 block discarded – undo
1022 1069
 				{
1023 1070
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1024 1071
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1025
-					foreach ($attachment['errors'] as $error)
1026
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1072
+					foreach ($attachment['errors'] as $error) {
1073
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1074
+					}
1027 1075
 					$txt['error_attach_errors'] .= '</div>';
1028 1076
 					$post_errors[] = 'attach_errors';
1029 1077
 
1030 1078
 					// Take out the trash.
1031 1079
 					unset($_SESSION['temp_attachments'][$attachID]);
1032
-					if (file_exists($attachment['tmp_name']))
1033
-						unlink($attachment['tmp_name']);
1080
+					if (file_exists($attachment['tmp_name'])) {
1081
+											unlink($attachment['tmp_name']);
1082
+					}
1034 1083
 					continue;
1035 1084
 				}
1036 1085
 
@@ -1043,8 +1092,9 @@  discard block
 block discarded – undo
1043 1092
 
1044 1093
 				$context['attachments']['quantity']++;
1045 1094
 				$context['attachments']['total_size'] += $attachment['size'];
1046
-				if (!isset($context['files_in_session_warning']))
1047
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1095
+				if (!isset($context['files_in_session_warning'])) {
1096
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1097
+				}
1048 1098
 
1049 1099
 				$context['current_attachments'][$attachID] = array(
1050 1100
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1072,8 +1122,9 @@  discard block
 block discarded – undo
1072 1122
 	}
1073 1123
 
1074 1124
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1075
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1076
-		$post_errors[] = 'need_qr_verification';
1125
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1126
+			$post_errors[] = 'need_qr_verification';
1127
+	}
1077 1128
 
1078 1129
 	/*
1079 1130
 	 * There are two error types: serious and minor. Serious errors
@@ -1090,52 +1141,56 @@  discard block
 block discarded – undo
1090 1141
 	{
1091 1142
 		loadLanguage('Errors');
1092 1143
 		$context['error_type'] = 'minor';
1093
-		foreach ($post_errors as $post_error)
1094
-			if (is_array($post_error))
1144
+		foreach ($post_errors as $post_error) {
1145
+					if (is_array($post_error))
1095 1146
 			{
1096 1147
 				$post_error_id = $post_error[0];
1148
+		}
1097 1149
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1098 1150
 
1099 1151
 				// If it's not a minor error flag it as such.
1100
-				if (!in_array($post_error_id, $minor_errors))
1101
-					$context['error_type'] = 'serious';
1102
-			}
1103
-			else
1152
+				if (!in_array($post_error_id, $minor_errors)) {
1153
+									$context['error_type'] = 'serious';
1154
+				}
1155
+			} else
1104 1156
 			{
1105 1157
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1106 1158
 
1107 1159
 				// If it's not a minor error flag it as such.
1108
-				if (!in_array($post_error, $minor_errors))
1109
-					$context['error_type'] = 'serious';
1160
+				if (!in_array($post_error, $minor_errors)) {
1161
+									$context['error_type'] = 'serious';
1162
+				}
1110 1163
 			}
1111 1164
 	}
1112 1165
 
1113 1166
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1114
-	if (isset($_REQUEST['poll']))
1115
-		$context['page_title'] = $txt['new_poll'];
1116
-	elseif ($context['make_event'])
1117
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1118
-	elseif (isset($_REQUEST['msg']))
1119
-		$context['page_title'] = $txt['modify_msg'];
1120
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1121
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1122
-	elseif (empty($topic))
1123
-		$context['page_title'] = $txt['start_new_topic'];
1124
-	else
1125
-		$context['page_title'] = $txt['post_reply'];
1167
+	if (isset($_REQUEST['poll'])) {
1168
+			$context['page_title'] = $txt['new_poll'];
1169
+	} elseif ($context['make_event']) {
1170
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1171
+	} elseif (isset($_REQUEST['msg'])) {
1172
+			$context['page_title'] = $txt['modify_msg'];
1173
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1174
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1175
+	} elseif (empty($topic)) {
1176
+			$context['page_title'] = $txt['start_new_topic'];
1177
+	} else {
1178
+			$context['page_title'] = $txt['post_reply'];
1179
+	}
1126 1180
 
1127 1181
 	// Build the link tree.
1128
-	if (empty($topic))
1129
-		$context['linktree'][] = array(
1182
+	if (empty($topic)) {
1183
+			$context['linktree'][] = array(
1130 1184
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1131 1185
 		);
1132
-	else
1133
-		$context['linktree'][] = array(
1186
+	} else {
1187
+			$context['linktree'][] = array(
1134 1188
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1135 1189
 			'name' => $form_subject,
1136 1190
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1137 1191
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1138 1192
 		);
1193
+	}
1139 1194
 
1140 1195
 	$context['subject'] = addcslashes($form_subject, '"');
1141 1196
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1179,8 +1234,9 @@  discard block
 block discarded – undo
1179 1234
 	// Message icons - customized icons are off?
1180 1235
 	$context['icons'] = getMessageIcons(!empty($board) ? $board : 0);
1181 1236
 
1182
-	if (!empty($context['icons']))
1183
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1237
+	if (!empty($context['icons'])) {
1238
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1239
+	}
1184 1240
 
1185 1241
 	// Are we starting a poll? if set the poll icon as selected if its available
1186 1242
 	if (isset($_REQUEST['poll']))
@@ -1200,8 +1256,9 @@  discard block
 block discarded – undo
1200 1256
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1201 1257
 	{
1202 1258
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1203
-		if ($context['icons'][$i]['selected'])
1204
-			$context['icon_url'] = $context['icons'][$i]['url'];
1259
+		if ($context['icons'][$i]['selected']) {
1260
+					$context['icon_url'] = $context['icons'][$i]['url'];
1261
+		}
1205 1262
 	}
1206 1263
 	if (empty($context['icon_url']))
1207 1264
 	{
@@ -1215,8 +1272,9 @@  discard block
 block discarded – undo
1215 1272
 		));
1216 1273
 	}
1217 1274
 
1218
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1219
-		getTopic();
1275
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1276
+			getTopic();
1277
+	}
1220 1278
 
1221 1279
 	// If the user can post attachments prepare the warning labels.
1222 1280
 	if ($context['can_post_attachment'])
@@ -1227,12 +1285,13 @@  discard block
 block discarded – undo
1227 1285
 		$context['attachment_restrictions'] = array();
1228 1286
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1229 1287
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1230
-		foreach ($attachmentRestrictionTypes as $type)
1231
-			if (!empty($modSettings[$type]))
1288
+		foreach ($attachmentRestrictionTypes as $type) {
1289
+					if (!empty($modSettings[$type]))
1232 1290
 			{
1233 1291
 				// Show the max number of attachments if not 0.
1234 1292
 				if ($type == 'attachmentNumPerPostLimit')
1235 1293
 					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1294
+		}
1236 1295
 			}
1237 1296
 	}
1238 1297
 
@@ -1266,8 +1325,8 @@  discard block
 block discarded – undo
1266 1325
 
1267 1326
 	if (!empty($context['current_attachments']))
1268 1327
 	{
1269
-		foreach ($context['current_attachments'] as $key => $mock)
1270
-			addInlineJavaScript('
1328
+		foreach ($context['current_attachments'] as $key => $mock) {
1329
+					addInlineJavaScript('
1271 1330
 	current_attachments.push({
1272 1331
 		name: '. JavaScriptEscape($mock['name']) . ',
1273 1332
 		size: '. $mock['size'] . ',
@@ -1276,6 +1335,7 @@  discard block
 block discarded – undo
1276 1335
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1277 1336
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1278 1337
 	});');
1338
+		}
1279 1339
 	}
1280 1340
 
1281 1341
 	// File Upload.
@@ -1374,12 +1434,13 @@  discard block
 block discarded – undo
1374 1434
 		{
1375 1435
 			$context['posting_fields']['board']['input']['options'][$category['name']] = array('options' => array());
1376 1436
 
1377
-			foreach ($category['boards'] as $brd)
1378
-				$context['posting_fields']['board']['input']['options'][$category['name']]['options'][$brd['name']]['attributes'] = array(
1437
+			foreach ($category['boards'] as $brd) {
1438
+							$context['posting_fields']['board']['input']['options'][$category['name']]['options'][$brd['name']]['attributes'] = array(
1379 1439
 					'value' => $brd['id'],
1380 1440
 					'selected' => (bool) $brd['selected'],
1381 1441
 					'label' => ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=&gt;' : '') . ' ' . $brd['name'],
1382 1442
 				);
1443
+			}
1383 1444
 		}
1384 1445
 	}
1385 1446
 
@@ -1425,8 +1486,9 @@  discard block
 block discarded – undo
1425 1486
 
1426 1487
 
1427 1488
 	// Finally, load the template.
1428
-	if (!isset($_REQUEST['xml']))
1429
-		loadTemplate('Post');
1489
+	if (!isset($_REQUEST['xml'])) {
1490
+			loadTemplate('Post');
1491
+	}
1430 1492
 
1431 1493
 	call_integration_hook('integrate_post_end');
1432 1494
 }
@@ -1447,13 +1509,14 @@  discard block
 block discarded – undo
1447 1509
 	// Sneaking off, are we?
1448 1510
 	if (empty($_POST) && empty($topic))
1449 1511
 	{
1450
-		if (empty($_SERVER['CONTENT_LENGTH']))
1451
-			redirectexit('action=post;board=' . $board . '.0');
1452
-		else
1453
-			fatal_lang_error('post_upload_error', false);
1512
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1513
+					redirectexit('action=post;board=' . $board . '.0');
1514
+		} else {
1515
+					fatal_lang_error('post_upload_error', false);
1516
+		}
1517
+	} elseif (empty($_POST) && !empty($topic)) {
1518
+			redirectexit('action=post;topic=' . $topic . '.0');
1454 1519
 	}
1455
-	elseif (empty($_POST) && !empty($topic))
1456
-		redirectexit('action=post;topic=' . $topic . '.0');
1457 1520
 
1458 1521
 	// No need!
1459 1522
 	$context['robot_no_index'] = true;
@@ -1465,8 +1528,9 @@  discard block
 block discarded – undo
1465 1528
 	$post_errors = array();
1466 1529
 
1467 1530
 	// If the session has timed out, let the user re-submit their form.
1468
-	if (checkSession('post', '', false) != '')
1469
-		$post_errors[] = 'session_timeout';
1531
+	if (checkSession('post', '', false) != '') {
1532
+			$post_errors[] = 'session_timeout';
1533
+	}
1470 1534
 
1471 1535
 	// Wrong verification code?
1472 1536
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1476,8 +1540,9 @@  discard block
 block discarded – undo
1476 1540
 			'id' => 'post',
1477 1541
 		);
1478 1542
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1479
-		if (is_array($context['require_verification']))
1480
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1543
+		if (is_array($context['require_verification'])) {
1544
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1545
+		}
1481 1546
 	}
1482 1547
 
1483 1548
 	require_once($sourcedir . '/Subs-Post.php');
@@ -1486,25 +1551,29 @@  discard block
 block discarded – undo
1486 1551
 	call_integration_hook('integrate_post2_start');
1487 1552
 
1488 1553
 	// Drafts enabled and needed?
1489
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1490
-		require_once($sourcedir . '/Drafts.php');
1554
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1555
+			require_once($sourcedir . '/Drafts.php');
1556
+	}
1491 1557
 
1492 1558
 	// First check to see if they are trying to delete any current attachments.
1493 1559
 	if (isset($_POST['attach_del']))
1494 1560
 	{
1495 1561
 		$keep_temp = array();
1496 1562
 		$keep_ids = array();
1497
-		foreach ($_POST['attach_del'] as $dummy)
1498
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1563
+		foreach ($_POST['attach_del'] as $dummy) {
1564
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1499 1565
 				$keep_temp[] = $dummy;
1500
-			else
1501
-				$keep_ids[] = (int) $dummy;
1566
+		}
1567
+			else {
1568
+							$keep_ids[] = (int) $dummy;
1569
+			}
1502 1570
 
1503
-		if (isset($_SESSION['temp_attachments']))
1504
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1571
+		if (isset($_SESSION['temp_attachments'])) {
1572
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1505 1573
 			{
1506 1574
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1507 1575
 					continue;
1576
+		}
1508 1577
 
1509 1578
 				unset($_SESSION['temp_attachments'][$attachID]);
1510 1579
 				unlink($attachment['tmp_name']);
@@ -1536,8 +1605,9 @@  discard block
 block discarded – undo
1536 1605
 	{
1537 1606
 		require_once($sourcedir . '/ManageAttachments.php');
1538 1607
 
1539
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
1540
-			removeAttachments(array('id_attach' => $attachID));
1608
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
1609
+					removeAttachments(array('id_attach' => $attachID));
1610
+		}
1541 1611
 
1542 1612
 		unset($_SESSION['already_attached']);
1543 1613
 
@@ -1560,12 +1630,14 @@  discard block
 block discarded – undo
1560 1630
 		$smcFunc['db_free_result']($request);
1561 1631
 
1562 1632
 		// Though the topic should be there, it might have vanished.
1563
-		if (!is_array($topic_info))
1564
-			fatal_lang_error('topic_doesnt_exist', 404);
1633
+		if (!is_array($topic_info)) {
1634
+					fatal_lang_error('topic_doesnt_exist', 404);
1635
+		}
1565 1636
 
1566 1637
 		// Did this topic suddenly move? Just checking...
1567
-		if ($topic_info['id_board'] != $board)
1568
-			fatal_lang_error('not_a_topic');
1638
+		if ($topic_info['id_board'] != $board) {
1639
+					fatal_lang_error('not_a_topic');
1640
+		}
1569 1641
 
1570 1642
 		// Do the permissions and approval stuff...
1571 1643
 		$becomesApproved = true;
@@ -1588,49 +1660,50 @@  discard block
 block discarded – undo
1588 1660
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1589 1661
 	{
1590 1662
 		// Don't allow a post if it's locked.
1591
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1592
-			fatal_lang_error('topic_locked', false);
1663
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1664
+					fatal_lang_error('topic_locked', false);
1665
+		}
1593 1666
 
1594 1667
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1595
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1596
-			unset($_REQUEST['poll']);
1597
-
1598
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1599
-		{
1600
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1601
-				$becomesApproved = false;
1602
-
1603
-			else
1604
-				isAllowedTo('post_reply_any');
1605
-		}
1606
-		elseif (!allowedTo('post_reply_any'))
1668
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1669
+					unset($_REQUEST['poll']);
1670
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1671
+		{
1672
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1673
+							$becomesApproved = false;
1674
+			} else {
1675
+							isAllowedTo('post_reply_any');
1676
+			}
1677
+		} elseif (!allowedTo('post_reply_any'))
1607 1678
 		{
1608
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1609
-				$becomesApproved = false;
1610
-
1611
-			else
1612
-				isAllowedTo('post_reply_own');
1679
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1680
+							$becomesApproved = false;
1681
+			} else {
1682
+							isAllowedTo('post_reply_own');
1683
+			}
1613 1684
 		}
1614 1685
 
1615 1686
 		if (isset($_POST['lock']))
1616 1687
 		{
1617 1688
 			// Nothing is changed to the lock.
1618
-			if (empty($topic_info['locked']) == empty($_POST['lock']))
1619
-				unset($_POST['lock']);
1689
+			if (empty($topic_info['locked']) == empty($_POST['lock'])) {
1690
+							unset($_POST['lock']);
1691
+			}
1620 1692
 
1621 1693
 			// You're have no permission to lock this topic.
1622
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1623
-				unset($_POST['lock']);
1694
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1695
+							unset($_POST['lock']);
1696
+			}
1624 1697
 
1625 1698
 			// You are allowed to (un)lock your own topic only.
1626 1699
 			elseif (!allowedTo('lock_any'))
1627 1700
 			{
1628 1701
 				// You cannot override a moderator lock.
1629
-				if ($topic_info['locked'] == 1)
1630
-					unset($_POST['lock']);
1631
-
1632
-				else
1633
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1702
+				if ($topic_info['locked'] == 1) {
1703
+									unset($_POST['lock']);
1704
+				} else {
1705
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1706
+				}
1634 1707
 			}
1635 1708
 			// Hail mighty moderator, (un)lock this topic immediately.
1636 1709
 			else
@@ -1638,19 +1711,21 @@  discard block
 block discarded – undo
1638 1711
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1639 1712
 
1640 1713
 				// Did someone (un)lock this while you were posting?
1641
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1642
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1714
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1715
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1716
+				}
1643 1717
 			}
1644 1718
 		}
1645 1719
 
1646 1720
 		// So you wanna (un)sticky this...let's see.
1647
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1648
-			unset($_POST['sticky']);
1649
-		elseif (isset($_POST['sticky']))
1721
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1722
+					unset($_POST['sticky']);
1723
+		} elseif (isset($_POST['sticky']))
1650 1724
 		{
1651 1725
 			// Did someone (un)sticky this while you were posting?
1652
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1653
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1726
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1727
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1728
+			}
1654 1729
 		}
1655 1730
 
1656 1731
 		// If drafts are enabled, then pass this off
@@ -1677,26 +1752,31 @@  discard block
 block discarded – undo
1677 1752
 
1678 1753
 		// Do like, the permissions, for safety and stuff...
1679 1754
 		$becomesApproved = true;
1680
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1681
-			$becomesApproved = false;
1682
-		else
1683
-			isAllowedTo('post_new');
1755
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1756
+					$becomesApproved = false;
1757
+		} else {
1758
+					isAllowedTo('post_new');
1759
+		}
1684 1760
 
1685 1761
 		if (isset($_POST['lock']))
1686 1762
 		{
1687 1763
 			// New topics are by default not locked.
1688
-			if (empty($_POST['lock']))
1689
-				unset($_POST['lock']);
1764
+			if (empty($_POST['lock'])) {
1765
+							unset($_POST['lock']);
1766
+			}
1690 1767
 			// Besides, you need permission.
1691
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1692
-				unset($_POST['lock']);
1768
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1769
+							unset($_POST['lock']);
1770
+			}
1693 1771
 			// A moderator-lock (1) can override a user-lock (2).
1694
-			else
1695
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1772
+			else {
1773
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1774
+			}
1696 1775
 		}
1697 1776
 
1698
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1699
-			unset($_POST['sticky']);
1777
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1778
+					unset($_POST['sticky']);
1779
+		}
1700 1780
 
1701 1781
 		// Saving your new topic as a draft first?
1702 1782
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1721,31 +1801,37 @@  discard block
 block discarded – undo
1721 1801
 				'id_msg' => $_REQUEST['msg'],
1722 1802
 			)
1723 1803
 		);
1724
-		if ($smcFunc['db_num_rows']($request) == 0)
1725
-			fatal_lang_error('cant_find_messages', false);
1804
+		if ($smcFunc['db_num_rows']($request) == 0) {
1805
+					fatal_lang_error('cant_find_messages', false);
1806
+		}
1726 1807
 		$row = $smcFunc['db_fetch_assoc']($request);
1727 1808
 		$smcFunc['db_free_result']($request);
1728 1809
 
1729
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1730
-			fatal_lang_error('topic_locked', false);
1810
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1811
+					fatal_lang_error('topic_locked', false);
1812
+		}
1731 1813
 
1732 1814
 		if (isset($_POST['lock']))
1733 1815
 		{
1734 1816
 			// Nothing changes to the lock status.
1735
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1736
-				unset($_POST['lock']);
1817
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1818
+							unset($_POST['lock']);
1819
+			}
1737 1820
 			// You're simply not allowed to (un)lock this.
1738
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1739
-				unset($_POST['lock']);
1821
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1822
+							unset($_POST['lock']);
1823
+			}
1740 1824
 			// You're only allowed to lock your own topics.
1741 1825
 			elseif (!allowedTo('lock_any'))
1742 1826
 			{
1743 1827
 				// You're not allowed to break a moderator's lock.
1744
-				if ($topic_info['locked'] == 1)
1745
-					unset($_POST['lock']);
1828
+				if ($topic_info['locked'] == 1) {
1829
+									unset($_POST['lock']);
1830
+				}
1746 1831
 				// Lock it with a soft lock or unlock it.
1747
-				else
1748
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1832
+				else {
1833
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1834
+				}
1749 1835
 			}
1750 1836
 			// You must be the moderator.
1751 1837
 			else
@@ -1753,44 +1839,46 @@  discard block
 block discarded – undo
1753 1839
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1754 1840
 
1755 1841
 				// Did someone (un)lock this while you were posting?
1756
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1757
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1842
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1843
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1844
+				}
1758 1845
 			}
1759 1846
 		}
1760 1847
 
1761 1848
 		// Change the sticky status of this topic?
1762
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1763
-			unset($_POST['sticky']);
1764
-		elseif (isset($_POST['sticky']))
1849
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1850
+					unset($_POST['sticky']);
1851
+		} elseif (isset($_POST['sticky']))
1765 1852
 		{
1766 1853
 			// Did someone (un)sticky this while you were posting?
1767
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1768
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1854
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1855
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1856
+			}
1769 1857
 		}
1770 1858
 
1771 1859
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1772 1860
 		{
1773
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1774
-				fatal_lang_error('modify_post_time_passed', false);
1775
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1776
-				isAllowedTo('modify_replies');
1777
-			else
1778
-				isAllowedTo('modify_own');
1779
-		}
1780
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1861
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1862
+							fatal_lang_error('modify_post_time_passed', false);
1863
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1864
+							isAllowedTo('modify_replies');
1865
+			} else {
1866
+							isAllowedTo('modify_own');
1867
+			}
1868
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1781 1869
 		{
1782 1870
 			isAllowedTo('modify_replies');
1783 1871
 
1784 1872
 			// If you're modifying a reply, I say it better be logged...
1785 1873
 			$moderationAction = true;
1786
-		}
1787
-		else
1874
+		} else
1788 1875
 		{
1789 1876
 			isAllowedTo('modify_any');
1790 1877
 
1791 1878
 			// Log it, assuming you're not modifying your own post.
1792
-			if ($row['id_member'] != $user_info['id'])
1793
-				$moderationAction = true;
1879
+			if ($row['id_member'] != $user_info['id']) {
1880
+							$moderationAction = true;
1881
+			}
1794 1882
 		}
1795 1883
 
1796 1884
 		// If drafts are enabled, then lets send this off to save
@@ -1817,8 +1905,9 @@  discard block
 block discarded – undo
1817 1905
 		// Update search api
1818 1906
 		require_once($sourcedir . '/Search.php');
1819 1907
 		$searchAPI = findSearchAPI();
1820
-		if ($searchAPI->supportsMethod('postRemoved'))
1821
-			$searchAPI->postRemoved($_REQUEST['msg']);
1908
+		if ($searchAPI->supportsMethod('postRemoved')) {
1909
+					$searchAPI->postRemoved($_REQUEST['msg']);
1910
+		}
1822 1911
 
1823 1912
 	}
1824 1913
 
@@ -1836,20 +1925,24 @@  discard block
 block discarded – undo
1836 1925
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1837 1926
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1838 1927
 
1839
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1840
-			$post_errors[] = 'no_name';
1841
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1842
-			$post_errors[] = 'long_name';
1928
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1929
+					$post_errors[] = 'no_name';
1930
+		}
1931
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1932
+					$post_errors[] = 'long_name';
1933
+		}
1843 1934
 
1844 1935
 		if (empty($modSettings['guest_post_no_email']))
1845 1936
 		{
1846 1937
 			// Only check if they changed it!
1847 1938
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1848 1939
 			{
1849
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1850
-					$post_errors[] = 'no_email';
1851
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1852
-					$post_errors[] = 'bad_email';
1940
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1941
+									$post_errors[] = 'no_email';
1942
+				}
1943
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1944
+									$post_errors[] = 'bad_email';
1945
+				}
1853 1946
 			}
1854 1947
 
1855 1948
 			// Now make sure this email address is not banned from posting.
@@ -1865,76 +1958,90 @@  discard block
 block discarded – undo
1865 1958
 	}
1866 1959
 
1867 1960
 	// Coming from the quickReply?
1868
-	if (isset($_POST['quickReply']))
1869
-		$_POST['message'] = $_POST['quickReply'];
1961
+	if (isset($_POST['quickReply'])) {
1962
+			$_POST['message'] = $_POST['quickReply'];
1963
+	}
1870 1964
 
1871 1965
 	// Check the subject and message.
1872
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1873
-		$post_errors[] = 'no_subject';
1874
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1875
-		$post_errors[] = 'no_message';
1876
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1877
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1878
-	else
1966
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1967
+			$post_errors[] = 'no_subject';
1968
+	}
1969
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1970
+			$post_errors[] = 'no_message';
1971
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1972
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1973
+	} else
1879 1974
 	{
1880 1975
 		// Prepare the message a bit for some additional testing.
1881 1976
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1882 1977
 
1883 1978
 		// Preparse code. (Zef)
1884
-		if ($user_info['is_guest'])
1885
-			$user_info['name'] = $_POST['guestname'];
1979
+		if ($user_info['is_guest']) {
1980
+					$user_info['name'] = $_POST['guestname'];
1981
+		}
1886 1982
 		preparsecode($_POST['message']);
1887 1983
 
1888 1984
 		// Let's see if there's still some content left without the tags.
1889
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1890
-			$post_errors[] = 'no_message';
1985
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1986
+					$post_errors[] = 'no_message';
1987
+		}
1891 1988
 
1892 1989
 	}
1893
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1894
-		$post_errors[] = 'no_event';
1990
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1991
+			$post_errors[] = 'no_event';
1992
+	}
1895 1993
 	// You are not!
1896
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1897
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1994
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1995
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1996
+	}
1898 1997
 
1899 1998
 	// Validate the poll...
1900 1999
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1901 2000
 	{
1902
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1903
-			fatal_lang_error('no_access', false);
2001
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
2002
+					fatal_lang_error('no_access', false);
2003
+		}
1904 2004
 
1905 2005
 		// This is a new topic... so it's a new poll.
1906
-		if (empty($topic))
1907
-			isAllowedTo('poll_post');
2006
+		if (empty($topic)) {
2007
+					isAllowedTo('poll_post');
2008
+		}
1908 2009
 		// Can you add to your own topics?
1909
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1910
-			isAllowedTo('poll_add_own');
2010
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
2011
+					isAllowedTo('poll_add_own');
2012
+		}
1911 2013
 		// Can you add polls to any topic, then?
1912
-		else
1913
-			isAllowedTo('poll_add_any');
2014
+		else {
2015
+					isAllowedTo('poll_add_any');
2016
+		}
1914 2017
 
1915
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1916
-			$post_errors[] = 'no_question';
2018
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
2019
+					$post_errors[] = 'no_question';
2020
+		}
1917 2021
 
1918 2022
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1919 2023
 
1920 2024
 		// Get rid of empty ones.
1921
-		foreach ($_POST['options'] as $k => $option)
1922
-			if ($option == '')
2025
+		foreach ($_POST['options'] as $k => $option) {
2026
+					if ($option == '')
1923 2027
 				unset($_POST['options'][$k], $_POST['options'][$k]);
2028
+		}
1924 2029
 
1925 2030
 		// What are you going to vote between with one choice?!?
1926
-		if (count($_POST['options']) < 2)
1927
-			$post_errors[] = 'poll_few';
1928
-		elseif (count($_POST['options']) > 256)
1929
-			$post_errors[] = 'poll_many';
2031
+		if (count($_POST['options']) < 2) {
2032
+					$post_errors[] = 'poll_few';
2033
+		} elseif (count($_POST['options']) > 256) {
2034
+					$post_errors[] = 'poll_many';
2035
+		}
1930 2036
 	}
1931 2037
 
1932 2038
 	if ($posterIsGuest)
1933 2039
 	{
1934 2040
 		// If user is a guest, make sure the chosen name isn't taken.
1935 2041
 		require_once($sourcedir . '/Subs-Members.php');
1936
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1937
-			$post_errors[] = 'bad_name';
2042
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
2043
+					$post_errors[] = 'bad_name';
2044
+		}
1938 2045
 	}
1939 2046
 	// If the user isn't a guest, get his or her name and email.
1940 2047
 	elseif (!isset($_REQUEST['msg']))
@@ -1965,8 +2072,9 @@  discard block
 block discarded – undo
1965 2072
 	}
1966 2073
 
1967 2074
 	// Make sure the user isn't spamming the board.
1968
-	if (!isset($_REQUEST['msg']))
1969
-		spamProtection('post');
2075
+	if (!isset($_REQUEST['msg'])) {
2076
+			spamProtection('post');
2077
+	}
1970 2078
 
1971 2079
 	// At about this point, we're posting and that's that.
1972 2080
 	ignore_user_abort(true);
@@ -1979,32 +2087,36 @@  discard block
 block discarded – undo
1979 2087
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1980 2088
 
1981 2089
 	// At this point, we want to make sure the subject isn't too long.
1982
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1983
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2090
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
2091
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2092
+	}
1984 2093
 
1985 2094
 	// Same with the "why did you edit this" text.
1986
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1987
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2095
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2096
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2097
+	}
1988 2098
 
1989 2099
 	// Make the poll...
1990 2100
 	if (isset($_REQUEST['poll']))
1991 2101
 	{
1992 2102
 		// Make sure that the user has not entered a ridiculous number of options..
1993
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1994
-			$_POST['poll_max_votes'] = 1;
1995
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1996
-			$_POST['poll_max_votes'] = count($_POST['options']);
1997
-		else
1998
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2103
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
2104
+					$_POST['poll_max_votes'] = 1;
2105
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
2106
+					$_POST['poll_max_votes'] = count($_POST['options']);
2107
+		} else {
2108
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2109
+		}
1999 2110
 
2000 2111
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
2001 2112
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
2002 2113
 
2003 2114
 		// Just set it to zero if it's not there..
2004
-		if (!isset($_POST['poll_hide']))
2005
-			$_POST['poll_hide'] = 0;
2006
-		else
2007
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2115
+		if (!isset($_POST['poll_hide'])) {
2116
+					$_POST['poll_hide'] = 0;
2117
+		} else {
2118
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2119
+		}
2008 2120
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
2009 2121
 
2010 2122
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -2013,16 +2125,19 @@  discard block
 block discarded – undo
2013 2125
 		{
2014 2126
 			require_once($sourcedir . '/Subs-Members.php');
2015 2127
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
2016
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
2017
-				$_POST['poll_guest_vote'] = 0;
2128
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2129
+							$_POST['poll_guest_vote'] = 0;
2130
+			}
2018 2131
 		}
2019 2132
 
2020 2133
 		// If the user tries to set the poll too far in advance, don't let them.
2021
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
2022
-			fatal_lang_error('poll_range_error', false);
2134
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2135
+					fatal_lang_error('poll_range_error', false);
2136
+		}
2023 2137
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
2024
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
2025
-			$_POST['poll_hide'] = 1;
2138
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2139
+					$_POST['poll_hide'] = 1;
2140
+		}
2026 2141
 
2027 2142
 		// Clean up the question and answers.
2028 2143
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -2036,13 +2151,15 @@  discard block
 block discarded – undo
2036 2151
 	{
2037 2152
 		$attachIDs = array();
2038 2153
 		$attach_errors = array();
2039
-		if (!empty($context['we_are_history']))
2040
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2154
+		if (!empty($context['we_are_history'])) {
2155
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2156
+		}
2041 2157
 
2042 2158
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
2043 2159
 		{
2044
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
2045
-				continue;
2160
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2161
+							continue;
2162
+			}
2046 2163
 
2047 2164
 			// If there was an initial error just show that message.
2048 2165
 			if ($attachID == 'initial_error')
@@ -2071,12 +2188,13 @@  discard block
 block discarded – undo
2071 2188
 				if (createAttachment($attachmentOptions))
2072 2189
 				{
2073 2190
 					$attachIDs[] = $attachmentOptions['id'];
2074
-					if (!empty($attachmentOptions['thumb']))
2075
-						$attachIDs[] = $attachmentOptions['thumb'];
2191
+					if (!empty($attachmentOptions['thumb'])) {
2192
+											$attachIDs[] = $attachmentOptions['thumb'];
2193
+					}
2076 2194
 				}
2195
+			} else {
2196
+							$attach_errors[] = '<dt>&nbsp;</dt>';
2077 2197
 			}
2078
-			else
2079
-				$attach_errors[] = '<dt>&nbsp;</dt>';
2080 2198
 
2081 2199
 			if (!empty($attachmentOptions['errors']))
2082 2200
 			{
@@ -2088,14 +2206,16 @@  discard block
 block discarded – undo
2088 2206
 					if (!is_array($error))
2089 2207
 					{
2090 2208
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
2091
-						if (in_array($error, $log_these))
2092
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2209
+						if (in_array($error, $log_these)) {
2210
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2211
+						}
2212
+					} else {
2213
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2093 2214
 					}
2094
-					else
2095
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2096 2215
 				}
2097
-				if (file_exists($attachment['tmp_name']))
2098
-					unlink($attachment['tmp_name']);
2216
+				if (file_exists($attachment['tmp_name'])) {
2217
+									unlink($attachment['tmp_name']);
2218
+				}
2099 2219
 			}
2100 2220
 		}
2101 2221
 		unset($_SESSION['temp_attachments']);
@@ -2136,24 +2256,24 @@  discard block
 block discarded – undo
2136 2256
 		);
2137 2257
 
2138 2258
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2259
+	} else {
2260
+			$id_poll = 0;
2139 2261
 	}
2140
-	else
2141
-		$id_poll = 0;
2142 2262
 
2143 2263
 	// Creating a new topic?
2144 2264
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2145 2265
 
2146 2266
 	// Check the icon.
2147
-	if (!isset($_POST['icon']))
2148
-		$_POST['icon'] = 'xx';
2149
-
2150
-	else
2267
+	if (!isset($_POST['icon'])) {
2268
+			$_POST['icon'] = 'xx';
2269
+	} else
2151 2270
 	{
2152 2271
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2153 2272
 
2154 2273
 		// Need to figure it out if this is a valid icon name.
2155
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2156
-			$_POST['icon'] = 'xx';
2274
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2275
+					$_POST['icon'] = 'xx';
2276
+		}
2157 2277
 	}
2158 2278
 
2159 2279
 	// Collect all parameters for the creation or modification of a post.
@@ -2194,8 +2314,9 @@  discard block
 block discarded – undo
2194 2314
 		}
2195 2315
 
2196 2316
 		// This will save some time...
2197
-		if (empty($approve_has_changed))
2198
-			unset($msgOptions['approved']);
2317
+		if (empty($approve_has_changed)) {
2318
+					unset($msgOptions['approved']);
2319
+		}
2199 2320
 
2200 2321
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2201 2322
 	}
@@ -2204,8 +2325,9 @@  discard block
 block discarded – undo
2204 2325
 	{
2205 2326
 		createPost($msgOptions, $topicOptions, $posterOptions);
2206 2327
 
2207
-		if (isset($topicOptions['id']))
2208
-			$topic = $topicOptions['id'];
2328
+		if (isset($topicOptions['id'])) {
2329
+					$topic = $topicOptions['id'];
2330
+		}
2209 2331
 	}
2210 2332
 
2211 2333
 	// Are there attachments already uploaded and waiting to be assigned?
@@ -2217,8 +2339,9 @@  discard block
 block discarded – undo
2217 2339
 	}
2218 2340
 
2219 2341
 	// If we had a draft for this, its time to remove it since it was just posted
2220
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2221
-		DeleteDraft($_POST['id_draft']);
2342
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2343
+			DeleteDraft($_POST['id_draft']);
2344
+	}
2222 2345
 
2223 2346
 	// Editing or posting an event?
2224 2347
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2237,8 +2360,7 @@  discard block
 block discarded – undo
2237 2360
 			'member' => $user_info['id'],
2238 2361
 		);
2239 2362
 		insertEvent($eventOptions);
2240
-	}
2241
-	elseif (isset($_POST['calendar']))
2363
+	} elseif (isset($_POST['calendar']))
2242 2364
 	{
2243 2365
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2244 2366
 
@@ -2266,14 +2388,15 @@  discard block
 block discarded – undo
2266 2388
 		}
2267 2389
 
2268 2390
 		// Delete it?
2269
-		if (isset($_REQUEST['deleteevent']))
2270
-			$smcFunc['db_query']('', '
2391
+		if (isset($_REQUEST['deleteevent'])) {
2392
+					$smcFunc['db_query']('', '
2271 2393
 				DELETE FROM {db_prefix}calendar
2272 2394
 				WHERE id_event = {int:id_event}',
2273 2395
 				array(
2274 2396
 					'id_event' => $_REQUEST['eventid'],
2275 2397
 				)
2276 2398
 			);
2399
+		}
2277 2400
 		// ... or just update it?
2278 2401
 		else
2279 2402
 		{
@@ -2315,9 +2438,8 @@  discard block
 block discarded – undo
2315 2438
 			array($user_info['id'], $topic, 0),
2316 2439
 			array('id_member', 'id_topic', 'id_board')
2317 2440
 		);
2318
-	}
2319
-	elseif (!$newTopic)
2320
-		$smcFunc['db_query']('', '
2441
+	} elseif (!$newTopic) {
2442
+			$smcFunc['db_query']('', '
2321 2443
 			DELETE FROM {db_prefix}log_notify
2322 2444
 			WHERE id_member = {int:current_member}
2323 2445
 				AND id_topic = {int:current_topic}',
@@ -2326,16 +2448,20 @@  discard block
 block discarded – undo
2326 2448
 				'current_topic' => $topic,
2327 2449
 			)
2328 2450
 		);
2451
+	}
2329 2452
 
2330 2453
 	// Log an act of moderation - modifying.
2331
-	if (!empty($moderationAction))
2332
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2454
+	if (!empty($moderationAction)) {
2455
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2456
+	}
2333 2457
 
2334
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2335
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2458
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2459
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2460
+	}
2336 2461
 
2337
-	if (isset($_POST['sticky']))
2338
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2462
+	if (isset($_POST['sticky'])) {
2463
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2464
+	}
2339 2465
 
2340 2466
 	// Returning to the topic?
2341 2467
 	if (!empty($_REQUEST['goback']))
@@ -2354,26 +2480,31 @@  discard block
 block discarded – undo
2354 2480
 		);
2355 2481
 	}
2356 2482
 
2357
-	if ($board_info['num_topics'] == 0)
2358
-		cache_put_data('board-' . $board, null, 120);
2483
+	if ($board_info['num_topics'] == 0) {
2484
+			cache_put_data('board-' . $board, null, 120);
2485
+	}
2359 2486
 
2360 2487
 	call_integration_hook('integrate_post2_end');
2361 2488
 
2362
-	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic'))
2363
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2489
+	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) {
2490
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2491
+	}
2364 2492
 
2365
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2366
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2493
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2494
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2495
+	}
2367 2496
 
2368 2497
 	// Return to post if the mod is on.
2369
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2370
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2371
-	elseif (!empty($_REQUEST['goback']))
2372
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2498
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2499
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2500
+	} elseif (!empty($_REQUEST['goback'])) {
2501
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2502
+	}
2373 2503
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2374
-	else
2375
-		redirectexit('board=' . $board . '.0');
2376
-}
2504
+	else {
2505
+			redirectexit('board=' . $board . '.0');
2506
+	}
2507
+	}
2377 2508
 
2378 2509
 /**
2379 2510
  * Handle the announce topic function (action=announce).
@@ -2391,8 +2522,9 @@  discard block
 block discarded – undo
2391 2522
 
2392 2523
 	validateSession();
2393 2524
 
2394
-	if (empty($topic))
2395
-		fatal_lang_error('topic_gone', false);
2525
+	if (empty($topic)) {
2526
+			fatal_lang_error('topic_gone', false);
2527
+	}
2396 2528
 
2397 2529
 	loadLanguage('Post');
2398 2530
 	loadTemplate('Post');
@@ -2419,8 +2551,9 @@  discard block
 block discarded – undo
2419 2551
 	global $txt, $context, $topic, $board_info, $smcFunc;
2420 2552
 
2421 2553
 	$groups = array_merge($board_info['groups'], array(1));
2422
-	foreach ($groups as $id => $group)
2423
-		$groups[$id] = (int) $group;
2554
+	foreach ($groups as $id => $group) {
2555
+			$groups[$id] = (int) $group;
2556
+	}
2424 2557
 
2425 2558
 	$context['groups'] = array();
2426 2559
 	if (in_array(0, $groups))
@@ -2463,8 +2596,9 @@  discard block
 block discarded – undo
2463 2596
 			'group_list' => $groups,
2464 2597
 		)
2465 2598
 	);
2466
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2467
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2599
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2600
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2601
+	}
2468 2602
 	$smcFunc['db_free_result']($request);
2469 2603
 
2470 2604
 	// Get the subject of the topic we're about to announce.
@@ -2506,16 +2640,19 @@  discard block
 block discarded – undo
2506 2640
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2507 2641
 	$groups = array_merge($board_info['groups'], array(1));
2508 2642
 
2509
-	if (isset($_POST['membergroups']))
2510
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2643
+	if (isset($_POST['membergroups'])) {
2644
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2645
+	}
2511 2646
 
2512 2647
 	// Check whether at least one membergroup was selected.
2513
-	if (empty($_POST['who']))
2514
-		fatal_lang_error('no_membergroup_selected');
2648
+	if (empty($_POST['who'])) {
2649
+			fatal_lang_error('no_membergroup_selected');
2650
+	}
2515 2651
 
2516 2652
 	// Make sure all membergroups are integers and can access the board of the announcement.
2517
-	foreach ($_POST['who'] as $id => $mg)
2518
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2653
+	foreach ($_POST['who'] as $id => $mg) {
2654
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2655
+	}
2519 2656
 
2520 2657
 	// Get the topic subject and censor it.
2521 2658
 	$request = $smcFunc['db_query']('', '
@@ -2561,12 +2698,13 @@  discard block
 block discarded – undo
2561 2698
 	if ($smcFunc['db_num_rows']($request) == 0)
2562 2699
 	{
2563 2700
 		logAction('announce_topic', array('topic' => $topic), 'user');
2564
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2565
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2566
-		elseif (!empty($_REQUEST['goback']))
2567
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2568
-		else
2569
-			redirectexit('board=' . $board . '.0');
2701
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2702
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2703
+		} elseif (!empty($_REQUEST['goback'])) {
2704
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2705
+		} else {
2706
+					redirectexit('board=' . $board . '.0');
2707
+		}
2570 2708
 	}
2571 2709
 
2572 2710
 	$announcements = array();
@@ -2585,8 +2723,9 @@  discard block
 block discarded – undo
2585 2723
 	foreach ($rows as $row)
2586 2724
 	{
2587 2725
 		// Force them to have it?
2588
-		if (empty($prefs[$row['id_member']]['announcements']))
2589
-			continue;
2726
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2727
+					continue;
2728
+		}
2590 2729
 
2591 2730
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2592 2731
 
@@ -2614,8 +2753,9 @@  discard block
 block discarded – undo
2614 2753
 	}
2615 2754
 
2616 2755
 	// For each language send a different mail - low priority...
2617
-	foreach ($announcements as $lang => $mail)
2618
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2756
+	foreach ($announcements as $lang => $mail) {
2757
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2758
+	}
2619 2759
 
2620 2760
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2621 2761
 
@@ -2625,9 +2765,10 @@  discard block
 block discarded – undo
2625 2765
 	$context['sub_template'] = 'announcement_send';
2626 2766
 
2627 2767
 	// Go back to the correct language for the user ;).
2628
-	if (!empty($modSettings['userLanguage']))
2629
-		loadLanguage('Post');
2630
-}
2768
+	if (!empty($modSettings['userLanguage'])) {
2769
+			loadLanguage('Post');
2770
+	}
2771
+	}
2631 2772
 
2632 2773
 /**
2633 2774
  * Get the topic for display purposes.
@@ -2640,12 +2781,13 @@  discard block
 block discarded – undo
2640 2781
 {
2641 2782
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2642 2783
 
2643
-	if (isset($_REQUEST['xml']))
2644
-		$limit = '
2784
+	if (isset($_REQUEST['xml'])) {
2785
+			$limit = '
2645 2786
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2646
-	else
2647
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2787
+	} else {
2788
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2648 2789
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2790
+	}
2649 2791
 
2650 2792
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2651 2793
 	$request = $smcFunc['db_query']('', '
@@ -2683,8 +2825,9 @@  discard block
 block discarded – undo
2683 2825
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2684 2826
 		);
2685 2827
 
2686
-		if (!empty($context['new_replies']))
2687
-			$context['new_replies']--;
2828
+		if (!empty($context['new_replies'])) {
2829
+					$context['new_replies']--;
2830
+		}
2688 2831
 	}
2689 2832
 	$smcFunc['db_free_result']($request);
2690 2833
 }
@@ -2701,8 +2844,9 @@  discard block
 block discarded – undo
2701 2844
 	global $sourcedir, $smcFunc;
2702 2845
 
2703 2846
 	loadLanguage('Post');
2704
-	if (!isset($_REQUEST['xml']))
2705
-		loadTemplate('Post');
2847
+	if (!isset($_REQUEST['xml'])) {
2848
+			loadTemplate('Post');
2849
+	}
2706 2850
 
2707 2851
 	include_once($sourcedir . '/Subs-Post.php');
2708 2852
 
@@ -2733,8 +2877,9 @@  discard block
 block discarded – undo
2733 2877
 	$smcFunc['db_free_result']($request);
2734 2878
 
2735 2879
 	$context['sub_template'] = 'quotefast';
2736
-	if (!empty($row))
2737
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2880
+	if (!empty($row)) {
2881
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2882
+	}
2738 2883
 
2739 2884
 	if (!empty($can_view_post))
2740 2885
 	{
@@ -2767,8 +2912,9 @@  discard block
 block discarded – undo
2767 2912
 		}
2768 2913
 
2769 2914
 		// Remove any nested quotes.
2770
-		if (!empty($modSettings['removeNestedQuotes']))
2771
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2915
+		if (!empty($modSettings['removeNestedQuotes'])) {
2916
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2917
+		}
2772 2918
 
2773 2919
 		$lb = "\n";
2774 2920
 
@@ -2794,14 +2940,14 @@  discard block
 block discarded – undo
2794 2940
 				'time' => '',
2795 2941
 			),
2796 2942
 		);
2797
-	}
2798
-	else
2799
-		$context['quote'] = array(
2943
+	} else {
2944
+			$context['quote'] = array(
2800 2945
 			'xml' => '',
2801 2946
 			'mozilla' => '',
2802 2947
 			'text' => '',
2803 2948
 		);
2804
-}
2949
+	}
2950
+	}
2805 2951
 
2806 2952
 /**
2807 2953
  * Used to edit the body or subject of a message inline
@@ -2813,8 +2959,9 @@  discard block
 block discarded – undo
2813 2959
 	global $user_info, $context, $smcFunc, $language, $board_info;
2814 2960
 
2815 2961
 	// We have to have a topic!
2816
-	if (empty($topic))
2817
-		obExit(false);
2962
+	if (empty($topic)) {
2963
+			obExit(false);
2964
+	}
2818 2965
 
2819 2966
 	checkSession('get');
2820 2967
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2840,31 +2987,35 @@  discard block
 block discarded – undo
2840 2987
 			'guest_id' => 0,
2841 2988
 		)
2842 2989
 	);
2843
-	if ($smcFunc['db_num_rows']($request) == 0)
2844
-		fatal_lang_error('no_board', false);
2990
+	if ($smcFunc['db_num_rows']($request) == 0) {
2991
+			fatal_lang_error('no_board', false);
2992
+	}
2845 2993
 	$row = $smcFunc['db_fetch_assoc']($request);
2846 2994
 	$smcFunc['db_free_result']($request);
2847 2995
 
2848 2996
 	// Change either body or subject requires permissions to modify messages.
2849 2997
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2850 2998
 	{
2851
-		if (!empty($row['locked']))
2852
-			isAllowedTo('moderate_board');
2999
+		if (!empty($row['locked'])) {
3000
+					isAllowedTo('moderate_board');
3001
+		}
2853 3002
 
2854 3003
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2855 3004
 		{
2856
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2857
-				fatal_lang_error('modify_post_time_passed', false);
2858
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2859
-				isAllowedTo('modify_replies');
2860
-			else
2861
-				isAllowedTo('modify_own');
3005
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
3006
+							fatal_lang_error('modify_post_time_passed', false);
3007
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
3008
+							isAllowedTo('modify_replies');
3009
+			} else {
3010
+							isAllowedTo('modify_own');
3011
+			}
2862 3012
 		}
2863 3013
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2864
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2865
-			isAllowedTo('modify_replies');
2866
-		else
2867
-			isAllowedTo('modify_any');
3014
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
3015
+					isAllowedTo('modify_replies');
3016
+		} else {
3017
+					isAllowedTo('modify_any');
3018
+		}
2868 3019
 
2869 3020
 		// Only log this action if it wasn't your message.
2870 3021
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2876,10 +3027,10 @@  discard block
 block discarded – undo
2876 3027
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2877 3028
 
2878 3029
 		// Maximum number of characters.
2879
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2880
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2881
-	}
2882
-	elseif (isset($_POST['subject']))
3030
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
3031
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
3032
+		}
3033
+	} elseif (isset($_POST['subject']))
2883 3034
 	{
2884 3035
 		$post_errors[] = 'no_subject';
2885 3036
 		unset($_POST['subject']);
@@ -2891,13 +3042,11 @@  discard block
 block discarded – undo
2891 3042
 		{
2892 3043
 			$post_errors[] = 'no_message';
2893 3044
 			unset($_POST['message']);
2894
-		}
2895
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
3045
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2896 3046
 		{
2897 3047
 			$post_errors[] = 'long_message';
2898 3048
 			unset($_POST['message']);
2899
-		}
2900
-		else
3049
+		} else
2901 3050
 		{
2902 3051
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2903 3052
 
@@ -2913,31 +3062,34 @@  discard block
 block discarded – undo
2913 3062
 
2914 3063
 	if (isset($_POST['lock']))
2915 3064
 	{
2916
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2917
-			unset($_POST['lock']);
2918
-		elseif (!allowedTo('lock_any'))
3065
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
3066
+					unset($_POST['lock']);
3067
+		} elseif (!allowedTo('lock_any'))
2919 3068
 		{
2920
-			if ($row['locked'] == 1)
2921
-				unset($_POST['lock']);
2922
-			else
2923
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3069
+			if ($row['locked'] == 1) {
3070
+							unset($_POST['lock']);
3071
+			} else {
3072
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3073
+			}
3074
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
3075
+					unset($_POST['lock']);
3076
+		} else {
3077
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2924 3078
 		}
2925
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2926
-			unset($_POST['lock']);
2927
-		else
2928
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2929 3079
 	}
2930 3080
 
2931
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2932
-		unset($_POST['sticky']);
3081
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
3082
+			unset($_POST['sticky']);
3083
+	}
2933 3084
 
2934 3085
 	if (isset($_POST['modify_reason']))
2935 3086
 	{
2936 3087
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2937 3088
 
2938 3089
 		// Maximum number of characters.
2939
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2940
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3090
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
3091
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3092
+		}
2941 3093
 	}
2942 3094
 
2943 3095
 	if (empty($post_errors))
@@ -2974,8 +3126,9 @@  discard block
 block discarded – undo
2974 3126
 			}
2975 3127
 		}
2976 3128
 		// If nothing was changed there's no need to add an entry to the moderation log.
2977
-		else
2978
-			$moderationAction = false;
3129
+		else {
3130
+					$moderationAction = false;
3131
+		}
2979 3132
 
2980 3133
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2981 3134
 
@@ -2993,9 +3146,9 @@  discard block
 block discarded – undo
2993 3146
 			// Get the proper (default language) response prefix first.
2994 3147
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2995 3148
 			{
2996
-				if ($language === $user_info['language'])
2997
-					$context['response_prefix'] = $txt['response_prefix'];
2998
-				else
3149
+				if ($language === $user_info['language']) {
3150
+									$context['response_prefix'] = $txt['response_prefix'];
3151
+				} else
2999 3152
 				{
3000 3153
 					loadLanguage('index', $language, false);
3001 3154
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -3017,8 +3170,9 @@  discard block
 block discarded – undo
3017 3170
 			);
3018 3171
 		}
3019 3172
 
3020
-		if (!empty($moderationAction))
3021
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3173
+		if (!empty($moderationAction)) {
3174
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3175
+		}
3022 3176
 	}
3023 3177
 
3024 3178
 	if (isset($_REQUEST['xml']))
@@ -3059,8 +3213,7 @@  discard block
 block discarded – undo
3059 3213
 			);
3060 3214
 
3061 3215
 			censorText($context['message']['subject']);
3062
-		}
3063
-		else
3216
+		} else
3064 3217
 		{
3065 3218
 			$context['message'] = array(
3066 3219
 				'id' => $row['id_msg'],
@@ -3072,15 +3225,16 @@  discard block
 block discarded – undo
3072 3225
 			loadLanguage('Errors');
3073 3226
 			foreach ($post_errors as $post_error)
3074 3227
 			{
3075
-				if ($post_error == 'long_message')
3076
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3077
-				else
3078
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3228
+				if ($post_error == 'long_message') {
3229
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3230
+				} else {
3231
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3232
+				}
3079 3233
 			}
3080 3234
 		}
3235
+	} else {
3236
+			obExit(false);
3237
+	}
3081 3238
 	}
3082
-	else
3083
-		obExit(false);
3084
-}
3085 3239
 
3086 3240
 ?>
3087 3241
\ No newline at end of file
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +935 added lines, -690 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
 	die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -107,11 +108,14 @@  discard block
 block discarded – undo
107 108
 	ini_set('default_socket_timeout', 900);
108 109
 }
109 110
 // Clean the upgrade path if this is from the client.
110
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
111
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
111
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
112
+	for ($i = 1;
113
+}
114
+$i < $_SERVER['argc']; $i++)
112 115
 	{
113
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
114
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
116
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
117
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
118
+		}
115 119
 	}
116 120
 
117 121
 // Are we from the client?
@@ -119,16 +123,17 @@  discard block
 block discarded – undo
119 123
 {
120 124
 	$command_line = true;
121 125
 	$disable_security = true;
122
-}
123
-else
126
+} else {
124 127
 	$command_line = false;
128
+}
125 129
 
126 130
 // Load this now just because we can.
127 131
 require_once($upgrade_path . '/Settings.php');
128 132
 
129 133
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
130
-if (isset($language))
134
+if (isset($language)) {
131 135
 	$language = str_ireplace('-utf8', '', $language);
136
+}
132 137
 
133 138
 // Are we logged in?
134 139
 if (isset($upgradeData))
@@ -136,10 +141,12 @@  discard block
 block discarded – undo
136 141
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
137 142
 
138 143
 	// Check for sensible values.
139
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
140
-		$upcontext['user']['started'] = time();
141
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
142
-		$upcontext['user']['updated'] = 0;
144
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
145
+			$upcontext['user']['started'] = time();
146
+	}
147
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
148
+			$upcontext['user']['updated'] = 0;
149
+	}
143 150
 
144 151
 	$upcontext['started'] = $upcontext['user']['started'];
145 152
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 			'db_error_skip' => true,
205 212
 		)
206 213
 	);
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$modSettings[$row['variable']] = $row['value'];
214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
215
+			$modSettings[$row['variable']] = $row['value'];
216
+	}
209 217
 	$smcFunc['db_free_result']($request);
210 218
 }
211 219
 
@@ -215,14 +223,17 @@  discard block
 block discarded – undo
215 223
 	$modSettings['theme_url'] = 'Themes/default';
216 224
 	$modSettings['images_url'] = 'Themes/default/images';
217 225
 }
218
-if (!isset($settings['default_theme_url']))
226
+if (!isset($settings['default_theme_url'])) {
219 227
 	$settings['default_theme_url'] = $modSettings['theme_url'];
220
-if (!isset($settings['default_theme_dir']))
228
+}
229
+if (!isset($settings['default_theme_dir'])) {
221 230
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
231
+}
222 232
 
223 233
 // This is needed in case someone invokes the upgrader using https when upgrading an http forum
224
-if (httpsOn())
234
+if (httpsOn()) {
225 235
 	$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
236
+}
226 237
 
227 238
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
228 239
 // Default title...
@@ -240,13 +251,15 @@  discard block
 block discarded – undo
240 251
 	$support_js = $upcontext['upgrade_status']['js'];
241 252
 
242 253
 	// Only set this if the upgrader status says so.
243
-	if (empty($is_debug))
244
-		$is_debug = $upcontext['upgrade_status']['debug'];
254
+	if (empty($is_debug)) {
255
+			$is_debug = $upcontext['upgrade_status']['debug'];
256
+	}
245 257
 
246 258
 	// Load the language.
247
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
248
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
249
-}
259
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
260
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
261
+	}
262
+	}
250 263
 // Set the defaults.
251 264
 else
252 265
 {
@@ -264,15 +277,18 @@  discard block
 block discarded – undo
264 277
 }
265 278
 
266 279
 // If this isn't the first stage see whether they are logging in and resuming.
267
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
280
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
268 281
 	checkLogin();
282
+}
269 283
 
270
-if ($command_line)
284
+if ($command_line) {
271 285
 	cmdStep0();
286
+}
272 287
 
273 288
 // Don't error if we're using xml.
274
-if (isset($_GET['xml']))
289
+if (isset($_GET['xml'])) {
275 290
 	$upcontext['return_error'] = true;
291
+}
276 292
 
277 293
 // Loop through all the steps doing each one as required.
278 294
 $upcontext['overall_percent'] = 0;
@@ -293,9 +309,9 @@  discard block
 block discarded – undo
293 309
 		}
294 310
 
295 311
 		// Call the step and if it returns false that means pause!
296
-		if (function_exists($step[2]) && $step[2]() === false)
297
-			break;
298
-		elseif (function_exists($step[2])) {
312
+		if (function_exists($step[2]) && $step[2]() === false) {
313
+					break;
314
+		} elseif (function_exists($step[2])) {
299 315
 			//Start each new step with this unset, so the 'normal' template is called first
300 316
 			unset($_GET['xml']);
301 317
 			//Clear out warnings at the start of each step
@@ -341,17 +357,18 @@  discard block
 block discarded – undo
341 357
 		// This should not happen my dear... HELP ME DEVELOPERS!!
342 358
 		if (!empty($command_line))
343 359
 		{
344
-			if (function_exists('debug_print_backtrace'))
345
-				debug_print_backtrace();
360
+			if (function_exists('debug_print_backtrace')) {
361
+							debug_print_backtrace();
362
+			}
346 363
 
347 364
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
348 365
 			flush();
349 366
 			die();
350 367
 		}
351 368
 
352
-		if (!isset($_GET['xml']))
353
-			template_upgrade_above();
354
-		else
369
+		if (!isset($_GET['xml'])) {
370
+					template_upgrade_above();
371
+		} else
355 372
 		{
356 373
 			header('content-type: text/xml; charset=UTF-8');
357 374
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -373,25 +390,29 @@  discard block
 block discarded – undo
373 390
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
374 391
 
375 392
 			// Custom stuff to pass back?
376
-			if (!empty($upcontext['query_string']))
377
-				$upcontext['form_url'] .= $upcontext['query_string'];
393
+			if (!empty($upcontext['query_string'])) {
394
+							$upcontext['form_url'] .= $upcontext['query_string'];
395
+			}
378 396
 
379 397
 			// Call the appropriate subtemplate
380
-			if (is_callable('template_' . $upcontext['sub_template']))
381
-				call_user_func('template_' . $upcontext['sub_template']);
382
-			else
383
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
398
+			if (is_callable('template_' . $upcontext['sub_template'])) {
399
+							call_user_func('template_' . $upcontext['sub_template']);
400
+			} else {
401
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
402
+			}
384 403
 		}
385 404
 
386 405
 		// Was there an error?
387
-		if (!empty($upcontext['forced_error_message']))
388
-			echo $upcontext['forced_error_message'];
406
+		if (!empty($upcontext['forced_error_message'])) {
407
+					echo $upcontext['forced_error_message'];
408
+		}
389 409
 
390 410
 		// Show the footer.
391
-		if (!isset($_GET['xml']))
392
-			template_upgrade_below();
393
-		else
394
-			template_xml_below();
411
+		if (!isset($_GET['xml'])) {
412
+					template_upgrade_below();
413
+		} else {
414
+					template_xml_below();
415
+		}
395 416
 	}
396 417
 
397 418
 	// Show the upgrade time for CLI when we are completely done, if in debug mode.
@@ -403,12 +424,13 @@  discard block
 block discarded – undo
403 424
 		$seconds = intval($active % 60);
404 425
 
405 426
 		$totalTime = '';
406
-		if ($hours > 0)
407
-			echo "\n" . '', sprintf($txt['upgrade_completed_time_hms'], $hours, $minutes, $seconds), '' . "\n";
408
-		elseif ($minutes > 0)
409
-			echo "\n" . '', sprintf($txt['upgrade_completed_time_ms'], $minutes, $seconds), '' . "\n";
410
-		elseif ($seconds > 0)
411
-			echo "\n" . '', sprintf($txt['upgrade_completed_time_s'], $seconds), '' . "\n";
427
+		if ($hours > 0) {
428
+					echo "\n" . '', sprintf($txt['upgrade_completed_time_hms'], $hours, $minutes, $seconds), '' . "\n";
429
+		} elseif ($minutes > 0) {
430
+					echo "\n" . '', sprintf($txt['upgrade_completed_time_ms'], $minutes, $seconds), '' . "\n";
431
+		} elseif ($seconds > 0) {
432
+					echo "\n" . '', sprintf($txt['upgrade_completed_time_s'], $seconds), '' . "\n";
433
+		}
412 434
 	}
413 435
 
414 436
 	// Bang - gone!
@@ -429,8 +451,9 @@  discard block
 block discarded – undo
429 451
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
430 452
 		while ($entry = $dir->read())
431 453
 		{
432
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
433
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
454
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
455
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
456
+			}
434 457
 		}
435 458
 		$dir->close();
436 459
 	}
@@ -474,10 +497,11 @@  discard block
 block discarded – undo
474 497
 	}
475 498
 
476 499
 	// Override the language file?
477
-	if (isset($_GET['lang_file']))
478
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
479
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
480
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
500
+	if (isset($_GET['lang_file'])) {
501
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
502
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
503
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
504
+	}
481 505
 
482 506
 	// Make sure it exists, if it doesn't reset it.
483 507
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -486,12 +510,14 @@  discard block
 block discarded – undo
486 510
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
487 511
 
488 512
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
489
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
490
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
513
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
514
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
515
+		}
491 516
 
492 517
 		// For backup we load the english at first -> second language overwrite the english one
493
-		if (count($incontext['detected_languages']) > 1)
494
-			require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
518
+		if (count($incontext['detected_languages']) > 1) {
519
+					require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
520
+		}
495 521
 	}
496 522
 
497 523
 	// And now include the actual language file itself.
@@ -499,11 +525,12 @@  discard block
 block discarded – undo
499 525
 
500 526
 	// Which language did we load? Assume that he likes his language.
501 527
 	preg_match('~^Install\.(.+[^-utf8])\.php$~', $_SESSION['installer_temp_lang'], $matches);
502
-	if (empty($matches[1]))
503
-		$matches = [
528
+	if (empty($matches[1])) {
529
+			$matches = [
504 530
 			0 => 'nothing',
505 531
 			1 => 'english',
506 532
 		];
533
+	}
507 534
 	$user_info['language'] = $matches[1];
508 535
 }
509 536
 
@@ -513,8 +540,9 @@  discard block
 block discarded – undo
513 540
 	global $upgradeurl, $upcontext, $command_line;
514 541
 
515 542
 	// Command line users can't be redirected.
516
-	if ($command_line)
517
-		upgradeExit(true);
543
+	if ($command_line) {
544
+			upgradeExit(true);
545
+	}
518 546
 
519 547
 	// Are we providing the core info?
520 548
 	if ($addForm)
@@ -540,12 +568,14 @@  discard block
 block discarded – undo
540 568
 	define('SMF', 1);
541 569
 
542 570
 	// Start the session.
543
-	if (@ini_get('session.save_handler') == 'user')
544
-		@ini_set('session.save_handler', 'files');
571
+	if (@ini_get('session.save_handler') == 'user') {
572
+			@ini_set('session.save_handler', 'files');
573
+	}
545 574
 	@session_start();
546 575
 
547
-	if (empty($smcFunc))
548
-		$smcFunc = array();
576
+	if (empty($smcFunc)) {
577
+			$smcFunc = array();
578
+	}
549 579
 
550 580
 	// We need this for authentication and some upgrade code
551 581
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -576,30 +606,34 @@  discard block
 block discarded – undo
576 606
 		{
577 607
 			$options = array('non_fatal' => true);
578 608
 			// Add in the port if needed
579
-			if (!empty($db_port))
580
-				$options['port'] = $db_port;
609
+			if (!empty($db_port)) {
610
+							$options['port'] = $db_port;
611
+			}
581 612
 			
582
-			if (!empty($db_mb4))
583
-				$options['db_mb4'] = $db_mb4;
613
+			if (!empty($db_mb4)) {
614
+							$options['db_mb4'] = $db_mb4;
615
+			}
584 616
 			
585 617
 			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
586
-		}
587
-		else
588
-			// If we've returned here, ping/reconnect to be safe
618
+		} else {
619
+					// If we've returned here, ping/reconnect to be safe
589 620
 			$smcFunc['db_ping']($db_connection);
621
+		}
590 622
 
591 623
 		// Oh dear god!!
592
-		if ($db_connection === null)
593
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
624
+		if ($db_connection === null) {
625
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
626
+		}
594 627
 
595
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
596
-			$smcFunc['db_query']('', '
628
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
629
+					$smcFunc['db_query']('', '
597 630
 			SET NAMES {string:db_character_set}',
598 631
 			array(
599 632
 				'db_error_skip' => true,
600 633
 				'db_character_set' => $db_character_set,
601 634
 			)
602 635
 		);
636
+		}
603 637
 
604 638
 		// Load the modSettings data...
605 639
 		$request = $smcFunc['db_query']('', '
@@ -610,11 +644,11 @@  discard block
 block discarded – undo
610 644
 			)
611 645
 		);
612 646
 		$modSettings = array();
613
-		while ($row = $smcFunc['db_fetch_assoc']($request))
614
-			$modSettings[$row['variable']] = $row['value'];
647
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
648
+					$modSettings[$row['variable']] = $row['value'];
649
+		}
615 650
 		$smcFunc['db_free_result']($request);
616
-	}
617
-	else
651
+	} else
618 652
 	{
619 653
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
620 654
 	}
@@ -628,9 +662,10 @@  discard block
 block discarded – undo
628 662
 		cleanRequest();
629 663
 	}
630 664
 
631
-	if (!isset($_GET['substep']))
632
-		$_GET['substep'] = 0;
633
-}
665
+	if (!isset($_GET['substep'])) {
666
+			$_GET['substep'] = 0;
667
+	}
668
+	}
634 669
 
635 670
 function initialize_inputs()
636 671
 {
@@ -660,8 +695,9 @@  discard block
 block discarded – undo
660 695
 		$dh = opendir(dirname(__FILE__));
661 696
 		while ($file = readdir($dh))
662 697
 		{
663
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
664
-				@unlink(dirname(__FILE__) . '/' . $file);
698
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
699
+							@unlink(dirname(__FILE__) . '/' . $file);
700
+			}
665 701
 		}
666 702
 		closedir($dh);
667 703
 
@@ -690,8 +726,9 @@  discard block
 block discarded – undo
690 726
 	$temp = 'upgrade_php?step';
691 727
 	while (strlen($temp) > 4)
692 728
 	{
693
-		if (isset($_GET[$temp]))
694
-			unset($_GET[$temp]);
729
+		if (isset($_GET[$temp])) {
730
+					unset($_GET[$temp]);
731
+		}
695 732
 		$temp = substr($temp, 1);
696 733
 	}
697 734
 
@@ -718,32 +755,39 @@  discard block
 block discarded – undo
718 755
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
719 756
 
720 757
 	// Need legacy scripts?
721
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
722
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
723
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
724
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
725
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
726
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
758
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
759
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
760
+	}
761
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
762
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
763
+	}
764
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
765
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
766
+	}
727 767
 
728 768
 	// We don't need "-utf8" files anymore...
729 769
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
730 770
 
731 771
 	// This needs to exist!
732
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
733
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
734
-	else
735
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
772
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
773
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
774
+	} else {
775
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
776
+	}
736 777
 
737
-	if (!$check)
738
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
778
+	if (!$check) {
779
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
739 780
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
781
+	}
740 782
 
741 783
 	// Do they meet the install requirements?
742
-	if (!php_version_check())
743
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
784
+	if (!php_version_check()) {
785
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
786
+	}
744 787
 
745
-	if (!db_version_check())
746
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
788
+	if (!db_version_check()) {
789
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
790
+	}
747 791
 
748 792
 	// Do some checks to make sure they have proper privileges
749 793
 	db_extend('packages');
@@ -758,14 +802,16 @@  discard block
 block discarded – undo
758 802
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
759 803
 
760 804
 	// Sorry... we need CREATE, ALTER and DROP
761
-	if (!$create || !$alter || !$drop)
762
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
805
+	if (!$create || !$alter || !$drop) {
806
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
807
+	}
763 808
 
764 809
 	// Do a quick version spot check.
765 810
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
766 811
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
767
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
768
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
812
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
813
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
814
+	}
769 815
 
770 816
 	// What absolutely needs to be writable?
771 817
 	$writable_files = array(
@@ -774,12 +820,13 @@  discard block
 block discarded – undo
774 820
 	);
775 821
 
776 822
 	// Only check for minified writable files if we have it enabled or not set.
777
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
778
-		$writable_files += array(
823
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
824
+			$writable_files += array(
779 825
 			$modSettings['theme_dir'] . '/css/minified.css',
780 826
 			$modSettings['theme_dir'] . '/scripts/minified.js',
781 827
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
782 828
 		);
829
+	}
783 830
 
784 831
 	// Do we need to add this setting?
785 832
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -791,12 +838,13 @@  discard block
 block discarded – undo
791 838
 	quickFileWritable($custom_av_dir);
792 839
 
793 840
 	// Are we good now?
794
-	if (!is_writable($custom_av_dir))
795
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
796
-	elseif ($need_settings_update)
841
+	if (!is_writable($custom_av_dir)) {
842
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
843
+	} elseif ($need_settings_update)
797 844
 	{
798
-		if (!function_exists('cache_put_data'))
799
-			require_once($sourcedir . '/Load.php');
845
+		if (!function_exists('cache_put_data')) {
846
+					require_once($sourcedir . '/Load.php');
847
+		}
800 848
 
801 849
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
802 850
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
@@ -806,29 +854,34 @@  discard block
 block discarded – undo
806 854
 
807 855
 	// Check the cache directory.
808 856
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
809
-	if (!file_exists($cachedir_temp))
810
-		@mkdir($cachedir_temp);
857
+	if (!file_exists($cachedir_temp)) {
858
+			@mkdir($cachedir_temp);
859
+	}
811 860
 
812
-	if (!file_exists($cachedir_temp))
813
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
861
+	if (!file_exists($cachedir_temp)) {
862
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
863
+	}
814 864
 
815
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
816
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
817
-	elseif (!isset($_GET['skiplang']))
865
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
866
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
867
+	} elseif (!isset($_GET['skiplang']))
818 868
 	{
819 869
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
820 870
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
821 871
 
822
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
823
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
872
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
873
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
874
+		}
824 875
 	}
825 876
 
826
-	if (!makeFilesWritable($writable_files))
827
-		return false;
877
+	if (!makeFilesWritable($writable_files)) {
878
+			return false;
879
+	}
828 880
 
829 881
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
830
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
831
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
882
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
883
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
884
+	}
832 885
 
833 886
 	// Upgrade the agreement.
834 887
 	elseif (isset($modSettings['agreement']))
@@ -839,8 +892,8 @@  discard block
 block discarded – undo
839 892
 	}
840 893
 
841 894
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
842
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
843
-		$upcontext['warning'] = '
895
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
896
+			$upcontext['warning'] = '
844 897
 			'. sprintf($txt['upgrade_boarddir_settings'], $boarddir, dirname(__FILE__)) .'<br>
845 898
 			<ul>
846 899
 				<li>'. $txt['upgrade_boarddir'] .'  ' . $boarddir . '</li>
@@ -848,19 +901,23 @@  discard block
 block discarded – undo
848 901
 				<li>'. $txt['upgrade_cachedir'] .'  ' . $cachedir_temp . '</li>
849 902
 			</ul>
850 903
 			'. $txt['upgrade_incorrect_settings'] .'';
904
+	}
851 905
 
852 906
 	// Confirm mbstring is loaded...
853
-	if (!extension_loaded('mbstring'))
854
-		return throw_error($txt['install_no_mbstring']);
907
+	if (!extension_loaded('mbstring')) {
908
+			return throw_error($txt['install_no_mbstring']);
909
+	}
855 910
 
856 911
 	// Check for https stream support.
857 912
 	$supported_streams = stream_get_wrappers();
858
-	if (!in_array('https', $supported_streams))
859
-		$upcontext['custom_warning'] = $txt['install_no_https'];
913
+	if (!in_array('https', $supported_streams)) {
914
+			$upcontext['custom_warning'] = $txt['install_no_https'];
915
+	}
860 916
 
861 917
 	// Either we're logged in or we're going to present the login.
862
-	if (checkLogin())
863
-		return true;
918
+	if (checkLogin()) {
919
+			return true;
920
+	}
864 921
 
865 922
 	$upcontext += createToken('login');
866 923
 
@@ -874,15 +931,17 @@  discard block
 block discarded – undo
874 931
 	global $smcFunc, $db_type, $support_js;
875 932
 
876 933
 	// Don't bother if the security is disabled.
877
-	if ($disable_security)
878
-		return true;
934
+	if ($disable_security) {
935
+			return true;
936
+	}
879 937
 
880 938
 	// Are we trying to login?
881 939
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
882 940
 	{
883 941
 		// If we've disabled security pick a suitable name!
884
-		if (empty($_POST['user']))
885
-			$_POST['user'] = 'Administrator';
942
+		if (empty($_POST['user'])) {
943
+					$_POST['user'] = 'Administrator';
944
+		}
886 945
 
887 946
 		// Before 2.0 these column names were different!
888 947
 		$oldDB = false;
@@ -897,16 +956,17 @@  discard block
 block discarded – undo
897 956
 					'db_error_skip' => true,
898 957
 				)
899 958
 			);
900
-			if ($smcFunc['db_num_rows']($request) != 0)
901
-				$oldDB = true;
959
+			if ($smcFunc['db_num_rows']($request) != 0) {
960
+							$oldDB = true;
961
+			}
902 962
 			$smcFunc['db_free_result']($request);
903 963
 		}
904 964
 
905 965
 		// Get what we believe to be their details.
906 966
 		if (!$disable_security)
907 967
 		{
908
-			if ($oldDB)
909
-				$request = $smcFunc['db_query']('', '
968
+			if ($oldDB) {
969
+							$request = $smcFunc['db_query']('', '
910 970
 					SELECT id_member, memberName AS member_name, passwd, id_group,
911 971
 					additionalGroups AS additional_groups, lngfile
912 972
 					FROM {db_prefix}members
@@ -916,8 +976,8 @@  discard block
 block discarded – undo
916 976
 						'db_error_skip' => true,
917 977
 					)
918 978
 				);
919
-			else
920
-				$request = $smcFunc['db_query']('', '
979
+			} else {
980
+							$request = $smcFunc['db_query']('', '
921 981
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
922 982
 					FROM {db_prefix}members
923 983
 					WHERE member_name = {string:member_name}',
@@ -926,6 +986,7 @@  discard block
 block discarded – undo
926 986
 						'db_error_skip' => true,
927 987
 					)
928 988
 				);
989
+			}
929 990
 			if ($smcFunc['db_num_rows']($request) != 0)
930 991
 			{
931 992
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -933,16 +994,17 @@  discard block
 block discarded – undo
933 994
 				$groups = explode(',', $addGroups);
934 995
 				$groups[] = $id_group;
935 996
 
936
-				foreach ($groups as $k => $v)
937
-					$groups[$k] = (int) $v;
997
+				foreach ($groups as $k => $v) {
998
+									$groups[$k] = (int) $v;
999
+				}
938 1000
 
939 1001
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
940 1002
 
941 1003
 				// We don't use "-utf8" anymore...
942 1004
 				$user_language = str_ireplace('-utf8', '', $user_language);
1005
+			} else {
1006
+							$upcontext['username_incorrect'] = true;
943 1007
 			}
944
-			else
945
-				$upcontext['username_incorrect'] = true;
946 1008
 
947 1009
 			$smcFunc['db_free_result']($request);
948 1010
 		}
@@ -953,13 +1015,14 @@  discard block
 block discarded – undo
953 1015
 		{
954 1016
 			$upcontext['upgrade_status']['js'] = 1;
955 1017
 			$support_js = 1;
1018
+		} else {
1019
+					$support_js = 0;
956 1020
 		}
957
-		else
958
-			$support_js = 0;
959 1021
 
960 1022
 		// Note down the version we are coming from.
961
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
962
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
1023
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
1024
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
1025
+		}
963 1026
 
964 1027
 		// Didn't get anywhere?
965 1028
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -993,15 +1056,15 @@  discard block
 block discarded – undo
993 1056
 							'db_error_skip' => true,
994 1057
 						)
995 1058
 					);
996
-					if ($smcFunc['db_num_rows']($request) == 0)
997
-						return throw_error('You need to be an admin to perform an upgrade!');
1059
+					if ($smcFunc['db_num_rows']($request) == 0) {
1060
+											return throw_error('You need to be an admin to perform an upgrade!');
1061
+					}
998 1062
 					$smcFunc['db_free_result']($request);
999 1063
 				}
1000 1064
 
1001 1065
 				$upcontext['user']['id'] = $id_member;
1002 1066
 				$upcontext['user']['name'] = $name;
1003
-			}
1004
-			else
1067
+			} else
1005 1068
 			{
1006 1069
 				$upcontext['user']['id'] = 1;
1007 1070
 				$upcontext['user']['name'] = 'Administrator';
@@ -1017,11 +1080,11 @@  discard block
 block discarded – undo
1017 1080
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
1018 1081
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
1019 1082
 
1020
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
1021
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1022
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
1023
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1024
-				else
1083
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1084
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1085
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1086
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1087
+				} else
1025 1088
 				{
1026 1089
 					// Set this as the new language.
1027 1090
 					$upcontext['language'] = $user_language;
@@ -1068,8 +1131,9 @@  discard block
 block discarded – undo
1068 1131
 	$upcontext['migrateSettingsNeeded'] = detectSettingsFileMigrationNeeded() ? 1 : 0;
1069 1132
 
1070 1133
 	// If we've not submitted then we're done.
1071
-	if (empty($_POST['upcont']))
1072
-		return false;
1134
+	if (empty($_POST['upcont'])) {
1135
+			return false;
1136
+	}
1073 1137
 
1074 1138
 	// Firstly, if they're enabling SM stat collection just do it.
1075 1139
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1089,16 +1153,17 @@  discard block
 block discarded – undo
1089 1153
 				fwrite($fp, $out);
1090 1154
 
1091 1155
 				$return_data = '';
1092
-				while (!feof($fp))
1093
-					$return_data .= fgets($fp, 128);
1156
+				while (!feof($fp)) {
1157
+									$return_data .= fgets($fp, 128);
1158
+				}
1094 1159
 
1095 1160
 				fclose($fp);
1096 1161
 
1097 1162
 				// Get the unique site ID.
1098 1163
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1099 1164
 
1100
-				if (!empty($ID[1]))
1101
-					$smcFunc['db_insert']('replace',
1165
+				if (!empty($ID[1])) {
1166
+									$smcFunc['db_insert']('replace',
1102 1167
 						$db_prefix . 'settings',
1103 1168
 						array('variable' => 'string', 'value' => 'string'),
1104 1169
 						array(
@@ -1107,9 +1172,9 @@  discard block
 block discarded – undo
1107 1172
 						),
1108 1173
 						array('variable')
1109 1174
 					);
1175
+				}
1110 1176
 			}
1111
-		}
1112
-		else
1177
+		} else
1113 1178
 		{
1114 1179
 			$smcFunc['db_insert']('replace',
1115 1180
 				$db_prefix . 'settings',
@@ -1120,8 +1185,8 @@  discard block
 block discarded – undo
1120 1185
 		}
1121 1186
 	}
1122 1187
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1123
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1124
-		$smcFunc['db_query']('', '
1188
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1189
+			$smcFunc['db_query']('', '
1125 1190
 			DELETE FROM {db_prefix}settings
1126 1191
 			WHERE variable = {string:enable_sm_stats}',
1127 1192
 			array(
@@ -1129,6 +1194,7 @@  discard block
 block discarded – undo
1129 1194
 				'db_error_skip' => true,
1130 1195
 			)
1131 1196
 		);
1197
+	}
1132 1198
 
1133 1199
 	// Deleting old karma stuff?
1134 1200
 	if (!empty($_POST['delete_karma']))
@@ -1143,20 +1209,22 @@  discard block
 block discarded – undo
1143 1209
 		);
1144 1210
 
1145 1211
 		// Cleaning up old karma member settings.
1146
-		if ($upcontext['karma_installed']['good'])
1147
-			$smcFunc['db_query']('', '
1212
+		if ($upcontext['karma_installed']['good']) {
1213
+					$smcFunc['db_query']('', '
1148 1214
 				ALTER TABLE {db_prefix}members
1149 1215
 				DROP karma_good',
1150 1216
 				array()
1151 1217
 			);
1218
+		}
1152 1219
 
1153 1220
 		// Does karma bad was enable?
1154
-		if ($upcontext['karma_installed']['bad'])
1155
-			$smcFunc['db_query']('', '
1221
+		if ($upcontext['karma_installed']['bad']) {
1222
+					$smcFunc['db_query']('', '
1156 1223
 				ALTER TABLE {db_prefix}members
1157 1224
 				DROP karma_bad',
1158 1225
 				array()
1159 1226
 			);
1227
+		}
1160 1228
 
1161 1229
 		// Cleaning up old karma permissions.
1162 1230
 		$smcFunc['db_query']('', '
@@ -1174,32 +1242,37 @@  discard block
 block discarded – undo
1174 1242
 	}
1175 1243
 
1176 1244
 	// Emptying the error log?
1177
-	if (!empty($_POST['empty_error']))
1178
-		$smcFunc['db_query']('truncate_table', '
1245
+	if (!empty($_POST['empty_error'])) {
1246
+			$smcFunc['db_query']('truncate_table', '
1179 1247
 			TRUNCATE {db_prefix}log_errors',
1180 1248
 			array(
1181 1249
 			)
1182 1250
 		);
1251
+	}
1183 1252
 
1184 1253
 	$changes = array();
1185 1254
 
1186 1255
 	// Add proxy settings.
1187
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1188
-		$changes += array(
1256
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1257
+			$changes += array(
1189 1258
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1190 1259
 			'image_proxy_maxsize' => 5190,
1191 1260
 			'image_proxy_enabled' => 0,
1192 1261
 		);
1262
+	}
1193 1263
 
1194 1264
 	// If $boardurl reflects https, set force_ssl
1195
-	if (!function_exists('cache_put_data'))
1196
-		require_once($sourcedir . '/Load.php');
1197
-	if (stripos($boardurl, 'https://') !== false)
1198
-		updateSettings(array('force_ssl' => '1'));
1265
+	if (!function_exists('cache_put_data')) {
1266
+			require_once($sourcedir . '/Load.php');
1267
+	}
1268
+	if (stripos($boardurl, 'https://') !== false) {
1269
+			updateSettings(array('force_ssl' => '1'));
1270
+	}
1199 1271
 
1200 1272
 	// If we're overriding the language follow it through.
1201
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1202
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1273
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1274
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1275
+	}
1203 1276
 
1204 1277
 	if (!empty($_POST['maint']))
1205 1278
 	{
@@ -1211,26 +1284,29 @@  discard block
 block discarded – undo
1211 1284
 		{
1212 1285
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1213 1286
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1214
-		}
1215
-		else
1287
+		} else
1216 1288
 		{
1217 1289
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1218 1290
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1219 1291
 		}
1220 1292
 	}
1221 1293
 
1222
-	if ($command_line)
1223
-		echo ' * Updating Settings.php...';
1294
+	if ($command_line) {
1295
+			echo ' * Updating Settings.php...';
1296
+	}
1224 1297
 
1225 1298
 	// Fix some old paths.
1226
-	if (substr($boarddir, 0, 1) == '.')
1227
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1299
+	if (substr($boarddir, 0, 1) == '.') {
1300
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1301
+	}
1228 1302
 
1229
-	if (substr($sourcedir, 0, 1) == '.')
1230
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1303
+	if (substr($sourcedir, 0, 1) == '.') {
1304
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1305
+	}
1231 1306
 
1232
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1233
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1307
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1308
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1309
+	}
1234 1310
 
1235 1311
 	// If they have a "host:port" setup for the host, split that into separate values
1236 1312
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1241,32 +1317,36 @@  discard block
 block discarded – undo
1241 1317
 		$changes['db_server'] = '\'' . $db_server . '\'';
1242 1318
 
1243 1319
 		// Only set this if we're not using the default port
1244
-		if ($db_port != ini_get('mysqli.default_port'))
1245
-			$changes['db_port'] = (int) $db_port;
1246
-	}
1247
-	elseif (!empty($db_port))
1320
+		if ($db_port != ini_get('mysqli.default_port')) {
1321
+					$changes['db_port'] = (int) $db_port;
1322
+		}
1323
+	} elseif (!empty($db_port))
1248 1324
 	{
1249 1325
 		// If db_port is set and is the same as the default, set it to ''
1250 1326
 		if ($db_type == 'mysql')
1251 1327
 		{
1252
-			if ($db_port == ini_get('mysqli.default_port'))
1253
-				$changes['db_port'] = '\'\'';
1254
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1255
-				$changes['db_port'] = '\'\'';
1328
+			if ($db_port == ini_get('mysqli.default_port')) {
1329
+							$changes['db_port'] = '\'\'';
1330
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1331
+							$changes['db_port'] = '\'\'';
1332
+			}
1256 1333
 		}
1257 1334
 	}
1258 1335
 
1259 1336
 	// Maybe we haven't had this option yet?
1260
-	if (empty($packagesdir))
1261
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1337
+	if (empty($packagesdir)) {
1338
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1339
+	}
1262 1340
 
1263 1341
 	// Add support for $tasksdir var.
1264
-	if (empty($tasksdir))
1265
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1342
+	if (empty($tasksdir)) {
1343
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1344
+	}
1266 1345
 
1267 1346
 	// Make sure we fix the language as well.
1268
-	if (stristr($language, '-utf8'))
1269
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1347
+	if (stristr($language, '-utf8')) {
1348
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1349
+	}
1270 1350
 
1271 1351
 	// @todo Maybe change the cookie name if going to 1.1, too?
1272 1352
 
@@ -1277,8 +1357,7 @@  discard block
 block discarded – undo
1277 1357
 		$changes['upgradeData'] = '"' . base64_encode(json_encode($upcontext['user'])) . '"';
1278 1358
 
1279 1359
 		migrateSettingsFile($changes);
1280
-	}
1281
-	else
1360
+	} else
1282 1361
 	{
1283 1362
 		// Update Settings.php with the new settings.
1284 1363
 		require_once($sourcedir . '/Subs-Admin.php');
@@ -1288,8 +1367,9 @@  discard block
 block discarded – undo
1288 1367
 		move_db_last_error_to_cachedir();
1289 1368
 	}
1290 1369
 
1291
-	if ($command_line)
1292
-		echo ' Successful.' . "\n";
1370
+	if ($command_line) {
1371
+			echo ' Successful.' . "\n";
1372
+	}
1293 1373
 
1294 1374
 	// Are we doing debug?
1295 1375
 	if (isset($_POST['debug']))
@@ -1299,8 +1379,9 @@  discard block
 block discarded – undo
1299 1379
 	}
1300 1380
 
1301 1381
 	// If we're not backing up then jump one.
1302
-	if (empty($_POST['backup']))
1303
-		$upcontext['current_step']++;
1382
+	if (empty($_POST['backup'])) {
1383
+			$upcontext['current_step']++;
1384
+	}
1304 1385
 
1305 1386
 	// If we've got here then let's proceed to the next step!
1306 1387
 	return true;
@@ -1315,8 +1396,9 @@  discard block
 block discarded – undo
1315 1396
 	$upcontext['page_title'] = $txt['backup_database'];
1316 1397
 
1317 1398
 	// Done it already - js wise?
1318
-	if (!empty($_POST['backup_done']))
1319
-		return true;
1399
+	if (!empty($_POST['backup_done'])) {
1400
+			return true;
1401
+	}
1320 1402
 
1321 1403
 	// Some useful stuff here.
1322 1404
 	db_extend();
@@ -1330,9 +1412,10 @@  discard block
 block discarded – undo
1330 1412
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1331 1413
 
1332 1414
 	$table_names = array();
1333
-	foreach ($tables as $table)
1334
-		if (substr($table, 0, 7) !== 'backup_')
1415
+	foreach ($tables as $table) {
1416
+			if (substr($table, 0, 7) !== 'backup_')
1335 1417
 			$table_names[] = $table;
1418
+	}
1336 1419
 
1337 1420
 	$upcontext['table_count'] = count($table_names);
1338 1421
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1342,12 +1425,14 @@  discard block
 block discarded – undo
1342 1425
 	$file_steps = $upcontext['table_count'];
1343 1426
 
1344 1427
 	// What ones have we already done?
1345
-	foreach ($table_names as $id => $table)
1346
-		if ($id < $_GET['substep'])
1428
+	foreach ($table_names as $id => $table) {
1429
+			if ($id < $_GET['substep'])
1347 1430
 			$upcontext['previous_tables'][] = $table;
1431
+	}
1348 1432
 
1349
-	if ($command_line)
1350
-		echo 'Backing Up Tables.';
1433
+	if ($command_line) {
1434
+			echo 'Backing Up Tables.';
1435
+	}
1351 1436
 
1352 1437
 	// If we don't support javascript we backup here.
1353 1438
 	if (!$support_js || isset($_GET['xml']))
@@ -1366,8 +1451,9 @@  discard block
 block discarded – undo
1366 1451
 			backupTable($table_names[$substep]);
1367 1452
 
1368 1453
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1369
-			if (isset($_GET['xml']))
1370
-				return upgradeExit();
1454
+			if (isset($_GET['xml'])) {
1455
+							return upgradeExit();
1456
+			}
1371 1457
 		}
1372 1458
 
1373 1459
 		if ($command_line)
@@ -1400,9 +1486,10 @@  discard block
 block discarded – undo
1400 1486
 
1401 1487
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1402 1488
 
1403
-	if ($command_line)
1404
-		echo ' done.';
1405
-}
1489
+	if ($command_line) {
1490
+			echo ' done.';
1491
+	}
1492
+	}
1406 1493
 
1407 1494
 // Step 2: Everything.
1408 1495
 function DatabaseChanges()
@@ -1411,8 +1498,9 @@  discard block
 block discarded – undo
1411 1498
 	global $upcontext, $support_js, $db_type;
1412 1499
 
1413 1500
 	// Have we just completed this?
1414
-	if (!empty($_POST['database_done']))
1415
-		return true;
1501
+	if (!empty($_POST['database_done'])) {
1502
+			return true;
1503
+	}
1416 1504
 
1417 1505
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1418 1506
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1427,15 +1515,16 @@  discard block
 block discarded – undo
1427 1515
 	);
1428 1516
 
1429 1517
 	// How many files are there in total?
1430
-	if (isset($_GET['filecount']))
1431
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1432
-	else
1518
+	if (isset($_GET['filecount'])) {
1519
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1520
+	} else
1433 1521
 	{
1434 1522
 		$upcontext['file_count'] = 0;
1435 1523
 		foreach ($files as $file)
1436 1524
 		{
1437
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1438
-				$upcontext['file_count']++;
1525
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1526
+							$upcontext['file_count']++;
1527
+			}
1439 1528
 		}
1440 1529
 	}
1441 1530
 
@@ -1445,9 +1534,9 @@  discard block
 block discarded – undo
1445 1534
 	$upcontext['cur_file_num'] = 0;
1446 1535
 	foreach ($files as $file)
1447 1536
 	{
1448
-		if ($did_not_do)
1449
-			$did_not_do--;
1450
-		else
1537
+		if ($did_not_do) {
1538
+					$did_not_do--;
1539
+		} else
1451 1540
 		{
1452 1541
 			$upcontext['cur_file_num']++;
1453 1542
 			$upcontext['cur_file_name'] = $file[0];
@@ -1474,12 +1563,13 @@  discard block
 block discarded – undo
1474 1563
 					// Flag to move on to the next.
1475 1564
 					$upcontext['completed_step'] = true;
1476 1565
 					// Did we complete the whole file?
1477
-					if ($nextFile)
1478
-						$upcontext['current_debug_item_num'] = -1;
1566
+					if ($nextFile) {
1567
+											$upcontext['current_debug_item_num'] = -1;
1568
+					}
1479 1569
 					return upgradeExit();
1570
+				} elseif ($support_js) {
1571
+									break;
1480 1572
 				}
1481
-				elseif ($support_js)
1482
-					break;
1483 1573
 			}
1484 1574
 			// Set the progress bar to be right as if we had - even if we hadn't...
1485 1575
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1505,8 +1595,9 @@  discard block
 block discarded – undo
1505 1595
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt, $settings;
1506 1596
 
1507 1597
 	// Now it's nice to have some of the basic SMF source files.
1508
-	if (!isset($_GET['ssi']) && !$command_line)
1509
-		redirectLocation('&ssi=1');
1598
+	if (!isset($_GET['ssi']) && !$command_line) {
1599
+			redirectLocation('&ssi=1');
1600
+	}
1510 1601
 
1511 1602
 	$upcontext['sub_template'] = 'upgrade_complete';
1512 1603
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1522,14 +1613,16 @@  discard block
 block discarded – undo
1522 1613
 	// Are we in maintenance mode?
1523 1614
 	if (isset($upcontext['user']['main']))
1524 1615
 	{
1525
-		if ($command_line)
1526
-			echo ' * ';
1616
+		if ($command_line) {
1617
+					echo ' * ';
1618
+		}
1527 1619
 		$upcontext['removed_maintenance'] = true;
1528 1620
 		$changes['maintenance'] = $upcontext['user']['main'];
1529 1621
 	}
1530 1622
 	// Otherwise if somehow we are in 2 let's go to 1.
1531
-	elseif (!empty($maintenance) && $maintenance == 2)
1532
-		$changes['maintenance'] = 1;
1623
+	elseif (!empty($maintenance) && $maintenance == 2) {
1624
+			$changes['maintenance'] = 1;
1625
+	}
1533 1626
 
1534 1627
 	// Wipe this out...
1535 1628
 	$upcontext['user'] = array();
@@ -1544,21 +1637,23 @@  discard block
 block discarded – undo
1544 1637
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1545 1638
 
1546 1639
 	// Now is the perfect time to fetch the SM files.
1547
-	if ($command_line)
1548
-		cli_scheduled_fetchSMfiles();
1549
-	else
1640
+	if ($command_line) {
1641
+			cli_scheduled_fetchSMfiles();
1642
+	} else
1550 1643
 	{
1551 1644
 		require_once($sourcedir . '/ScheduledTasks.php');
1552 1645
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
1553 1646
 		scheduled_fetchSMfiles(); // Now go get those files!
1554 1647
 		// This is needed in case someone invokes the upgrader using https when upgrading an http forum
1555
-		if (httpsOn())
1556
-			$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
1648
+		if (httpsOn()) {
1649
+					$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
1650
+		}
1557 1651
 	}
1558 1652
 
1559 1653
 	// Log what we've done.
1560
-	if (empty($user_info['id']))
1561
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1654
+	if (empty($user_info['id'])) {
1655
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1656
+	}
1562 1657
 
1563 1658
 	// Log the action manually, so CLI still works.
1564 1659
 	$smcFunc['db_insert']('',
@@ -1577,8 +1672,9 @@  discard block
 block discarded – undo
1577 1672
 
1578 1673
 	// Save the current database version.
1579 1674
 	$server_version = $smcFunc['db_server_info']();
1580
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1581
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1675
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1676
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1677
+	}
1582 1678
 
1583 1679
 	if ($command_line)
1584 1680
 	{
@@ -1590,8 +1686,9 @@  discard block
 block discarded – undo
1590 1686
 
1591 1687
 	// Make sure it says we're done.
1592 1688
 	$upcontext['overall_percent'] = 100;
1593
-	if (isset($upcontext['step_progress']))
1594
-		unset($upcontext['step_progress']);
1689
+	if (isset($upcontext['step_progress'])) {
1690
+			unset($upcontext['step_progress']);
1691
+	}
1595 1692
 
1596 1693
 	$_GET['substep'] = 0;
1597 1694
 	return false;
@@ -1602,8 +1699,9 @@  discard block
 block discarded – undo
1602 1699
 {
1603 1700
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1604 1701
 
1605
-	if (empty($modSettings['time_format']))
1606
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1702
+	if (empty($modSettings['time_format'])) {
1703
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1704
+	}
1607 1705
 
1608 1706
 	// What files do we want to get
1609 1707
 	$request = $smcFunc['db_query']('', '
@@ -1637,8 +1735,9 @@  discard block
 block discarded – undo
1637 1735
 		$file_data = fetch_web_data($url);
1638 1736
 
1639 1737
 		// If we got an error - give up - the site might be down.
1640
-		if ($file_data === false)
1641
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1738
+		if ($file_data === false) {
1739
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1740
+		}
1642 1741
 
1643 1742
 		// Save the file to the database.
1644 1743
 		$smcFunc['db_query']('substring', '
@@ -1680,8 +1779,9 @@  discard block
 block discarded – undo
1680 1779
 	$themeData = array();
1681 1780
 	foreach ($values as $variable => $value)
1682 1781
 	{
1683
-		if (!isset($value) || $value === null)
1684
-			$value = 0;
1782
+		if (!isset($value) || $value === null) {
1783
+					$value = 0;
1784
+		}
1685 1785
 
1686 1786
 		$themeData[] = array(0, 1, $variable, $value);
1687 1787
 	}
@@ -1710,8 +1810,9 @@  discard block
 block discarded – undo
1710 1810
 
1711 1811
 	foreach ($values as $variable => $value)
1712 1812
 	{
1713
-		if (empty($modSettings[$value[0]]))
1714
-			continue;
1813
+		if (empty($modSettings[$value[0]])) {
1814
+					continue;
1815
+		}
1715 1816
 
1716 1817
 		$smcFunc['db_query']('', '
1717 1818
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1797,19 +1898,21 @@  discard block
 block discarded – undo
1797 1898
 	set_error_handler(
1798 1899
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1799 1900
 		{
1800
-			if ($support_js)
1801
-				return true;
1802
-			else
1803
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1901
+			if ($support_js) {
1902
+							return true;
1903
+			} else {
1904
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1905
+			}
1804 1906
 		}
1805 1907
 	);
1806 1908
 
1807 1909
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1808 1910
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1809
-	if ($db_type == 'mysql')
1810
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1811
-	else
1812
-		$db_collation = '';
1911
+	if ($db_type == 'mysql') {
1912
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1913
+	} else {
1914
+			$db_collation = '';
1915
+	}
1813 1916
 
1814 1917
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1815 1918
 
@@ -1821,8 +1924,9 @@  discard block
 block discarded – undo
1821 1924
 	$last_step = '';
1822 1925
 
1823 1926
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1824
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1825
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1927
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1928
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1929
+	}
1826 1930
 
1827 1931
 	// Count the total number of steps within this file - for progress.
1828 1932
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1842,15 +1946,18 @@  discard block
 block discarded – undo
1842 1946
 		$do_current = $substep >= $_GET['substep'];
1843 1947
 
1844 1948
 		// Get rid of any comments in the beginning of the line...
1845
-		if (substr(trim($line), 0, 2) === '/*')
1846
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1949
+		if (substr(trim($line), 0, 2) === '/*') {
1950
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1951
+		}
1847 1952
 
1848 1953
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1849
-		if ($is_debug && !$support_js && $command_line)
1850
-			flush();
1954
+		if ($is_debug && !$support_js && $command_line) {
1955
+					flush();
1956
+		}
1851 1957
 
1852
-		if (trim($line) === '')
1853
-			continue;
1958
+		if (trim($line) === '') {
1959
+					continue;
1960
+		}
1854 1961
 
1855 1962
 		if (trim(substr($line, 0, 3)) === '---')
1856 1963
 		{
@@ -1860,8 +1967,9 @@  discard block
 block discarded – undo
1860 1967
 			if (trim($current_data) != '' && $type !== '}')
1861 1968
 			{
1862 1969
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1863
-				if ($command_line)
1864
-					echo $upcontext['error_message'];
1970
+				if ($command_line) {
1971
+									echo $upcontext['error_message'];
1972
+				}
1865 1973
 			}
1866 1974
 
1867 1975
 			if ($type == ' ')
@@ -1879,17 +1987,18 @@  discard block
 block discarded – undo
1879 1987
 				if ($do_current)
1880 1988
 				{
1881 1989
 					$upcontext['actioned_items'][] = $last_step;
1882
-					if ($command_line)
1883
-						echo ' * ';
1990
+					if ($command_line) {
1991
+											echo ' * ';
1992
+					}
1884 1993
 				}
1885
-			}
1886
-			elseif ($type == '#')
1994
+			} elseif ($type == '#')
1887 1995
 			{
1888 1996
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1889 1997
 
1890 1998
 				$upcontext['current_debug_item_num']++;
1891
-				if (trim($line) != '---#')
1892
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1999
+				if (trim($line) != '---#') {
2000
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
2001
+				}
1893 2002
 
1894 2003
 				// Have we already done something?
1895 2004
 				if (isset($_GET['xml']) && $done_something)
@@ -1900,34 +2009,36 @@  discard block
 block discarded – undo
1900 2009
 
1901 2010
 				if ($do_current)
1902 2011
 				{
1903
-					if (trim($line) == '---#' && $command_line)
1904
-						echo ' done.', $endl;
1905
-					elseif ($command_line)
1906
-						echo ' +++ ', rtrim(substr($line, 4));
1907
-					elseif (trim($line) != '---#')
2012
+					if (trim($line) == '---#' && $command_line) {
2013
+											echo ' done.', $endl;
2014
+					} elseif ($command_line) {
2015
+											echo ' +++ ', rtrim(substr($line, 4));
2016
+					} elseif (trim($line) != '---#')
1908 2017
 					{
1909
-						if ($is_debug)
1910
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2018
+						if ($is_debug) {
2019
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2020
+						}
1911 2021
 					}
1912 2022
 				}
1913 2023
 
1914 2024
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1915 2025
 				{
1916
-					if ($command_line)
1917
-						echo ' * ';
1918
-					else
1919
-						$upcontext['actioned_items'][] = $last_step;
2026
+					if ($command_line) {
2027
+											echo ' * ';
2028
+					} else {
2029
+											$upcontext['actioned_items'][] = $last_step;
2030
+					}
1920 2031
 				}
1921 2032
 
1922 2033
 				// Small step - only if we're actually doing stuff.
1923
-				if ($do_current)
1924
-					nextSubstep(++$substep);
1925
-				else
1926
-					$substep++;
1927
-			}
1928
-			elseif ($type == '{')
1929
-				$current_type = 'code';
1930
-			elseif ($type == '}')
2034
+				if ($do_current) {
2035
+									nextSubstep(++$substep);
2036
+				} else {
2037
+									$substep++;
2038
+				}
2039
+			} elseif ($type == '{') {
2040
+							$current_type = 'code';
2041
+			} elseif ($type == '}')
1931 2042
 			{
1932 2043
 				$current_type = 'sql';
1933 2044
 
@@ -1940,8 +2051,9 @@  discard block
 block discarded – undo
1940 2051
 				if (eval('global $db_prefix, $modSettings, $smcFunc, $txt; ' . $current_data) === false)
1941 2052
 				{
1942 2053
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1943
-					if ($command_line)
1944
-						echo $upcontext['error_message'];
2054
+					if ($command_line) {
2055
+											echo $upcontext['error_message'];
2056
+					}
1945 2057
 				}
1946 2058
 
1947 2059
 				// Done with code!
@@ -2029,8 +2141,9 @@  discard block
 block discarded – undo
2029 2141
 	$db_unbuffered = false;
2030 2142
 
2031 2143
 	// Failure?!
2032
-	if ($result !== false)
2033
-		return $result;
2144
+	if ($result !== false) {
2145
+			return $result;
2146
+	}
2034 2147
 
2035 2148
 	$db_error_message = $smcFunc['db_error']($db_connection);
2036 2149
 	// If MySQL we do something more clever.
@@ -2058,54 +2171,61 @@  discard block
 block discarded – undo
2058 2171
 			{
2059 2172
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2060 2173
 				$result = mysqli_query($db_connection, $string);
2061
-				if ($result !== false)
2062
-					return $result;
2174
+				if ($result !== false) {
2175
+									return $result;
2176
+				}
2063 2177
 			}
2064
-		}
2065
-		elseif ($mysqli_errno == 2013)
2178
+		} elseif ($mysqli_errno == 2013)
2066 2179
 		{
2067 2180
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2068 2181
 			mysqli_select_db($db_connection, $db_name);
2069 2182
 			if ($db_connection)
2070 2183
 			{
2071 2184
 				$result = mysqli_query($db_connection, $string);
2072
-				if ($result !== false)
2073
-					return $result;
2185
+				if ($result !== false) {
2186
+									return $result;
2187
+				}
2074 2188
 			}
2075 2189
 		}
2076 2190
 		// Duplicate column name... should be okay ;).
2077
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2078
-			return false;
2191
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2192
+					return false;
2193
+		}
2079 2194
 		// Duplicate insert... make sure it's the proper type of query ;).
2080
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2081
-			return false;
2195
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2196
+					return false;
2197
+		}
2082 2198
 		// Creating an index on a non-existent column.
2083
-		elseif ($mysqli_errno == 1072)
2084
-			return false;
2085
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2086
-			return false;
2199
+		elseif ($mysqli_errno == 1072) {
2200
+					return false;
2201
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2202
+					return false;
2203
+		}
2087 2204
 	}
2088 2205
 	// If a table already exists don't go potty.
2089 2206
 	else
2090 2207
 	{
2091 2208
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2092 2209
 		{
2093
-			if (strpos($db_error_message, 'exist') !== false)
2094
-				return true;
2095
-		}
2096
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2210
+			if (strpos($db_error_message, 'exist') !== false) {
2211
+							return true;
2212
+			}
2213
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2097 2214
 		{
2098
-			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error)
2099
-				return true;
2215
+			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) {
2216
+							return true;
2217
+			}
2100 2218
 		}
2101 2219
 	}
2102 2220
 
2103 2221
 	// Get the query string so we pass everything.
2104 2222
 	$query_string = '';
2105
-	foreach ($_GET as $k => $v)
2106
-		$query_string .= ';' . $k . '=' . $v;
2107
-	if (strlen($query_string) != 0)
2108
-		$query_string = '?' . substr($query_string, 1);
2223
+	foreach ($_GET as $k => $v) {
2224
+			$query_string .= ';' . $k . '=' . $v;
2225
+	}
2226
+	if (strlen($query_string) != 0) {
2227
+			$query_string = '?' . substr($query_string, 1);
2228
+	}
2109 2229
 
2110 2230
 	if ($command_line)
2111 2231
 	{
@@ -2160,16 +2280,18 @@  discard block
 block discarded – undo
2160 2280
 			{
2161 2281
 				$found |= 1;
2162 2282
 				// Do some checks on the data if we have it set.
2163
-				if (isset($change['col_type']))
2164
-					$found &= $change['col_type'] === $column['type'];
2165
-				if (isset($change['null_allowed']))
2166
-					$found &= $column['null'] == $change['null_allowed'];
2167
-				if (isset($change['default']))
2168
-					$found &= $change['default'] === $column['default'];
2283
+				if (isset($change['col_type'])) {
2284
+									$found &= $change['col_type'] === $column['type'];
2285
+				}
2286
+				if (isset($change['null_allowed'])) {
2287
+									$found &= $column['null'] == $change['null_allowed'];
2288
+				}
2289
+				if (isset($change['default'])) {
2290
+									$found &= $change['default'] === $column['default'];
2291
+				}
2169 2292
 			}
2170 2293
 		}
2171
-	}
2172
-	elseif ($change['type'] === 'index')
2294
+	} elseif ($change['type'] === 'index')
2173 2295
 	{
2174 2296
 		$request = upgrade_query('
2175 2297
 			SHOW INDEX
@@ -2178,9 +2300,10 @@  discard block
 block discarded – undo
2178 2300
 		{
2179 2301
 			$cur_index = array();
2180 2302
 
2181
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2182
-				if ($row['Key_name'] === $change['name'])
2303
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2304
+							if ($row['Key_name'] === $change['name'])
2183 2305
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2306
+			}
2184 2307
 
2185 2308
 			ksort($cur_index, SORT_NUMERIC);
2186 2309
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2190,14 +2313,17 @@  discard block
 block discarded – undo
2190 2313
 	}
2191 2314
 
2192 2315
 	// If we're trying to add and it's added, we're done.
2193
-	if ($found && in_array($change['method'], array('add', 'change')))
2194
-		return true;
2316
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2317
+			return true;
2318
+	}
2195 2319
 	// Otherwise if we're removing and it wasn't found we're also done.
2196
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2197
-		return true;
2320
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2321
+			return true;
2322
+	}
2198 2323
 	// Otherwise is it just a test?
2199
-	elseif ($is_test)
2200
-		return false;
2324
+	elseif ($is_test) {
2325
+			return false;
2326
+	}
2201 2327
 
2202 2328
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2203 2329
 	$running = false;
@@ -2208,8 +2334,9 @@  discard block
 block discarded – undo
2208 2334
 			SHOW FULL PROCESSLIST');
2209 2335
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2210 2336
 		{
2211
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2212
-				$found = true;
2337
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2338
+							$found = true;
2339
+			}
2213 2340
 		}
2214 2341
 
2215 2342
 		// Can't find it? Then we need to run it fools!
@@ -2221,8 +2348,9 @@  discard block
 block discarded – undo
2221 2348
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2222 2349
 				' . $change['text'], true) !== false;
2223 2350
 
2224
-			if (!$success)
2225
-				return false;
2351
+			if (!$success) {
2352
+							return false;
2353
+			}
2226 2354
 
2227 2355
 			// Return
2228 2356
 			$running = true;
@@ -2264,8 +2392,9 @@  discard block
 block discarded – undo
2264 2392
 			'db_error_skip' => true,
2265 2393
 		)
2266 2394
 	);
2267
-	if ($smcFunc['db_num_rows']($request) === 0)
2268
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2395
+	if ($smcFunc['db_num_rows']($request) === 0) {
2396
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2397
+	}
2269 2398
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2270 2399
 	$smcFunc['db_free_result']($request);
2271 2400
 
@@ -2287,18 +2416,19 @@  discard block
 block discarded – undo
2287 2416
 			)
2288 2417
 		);
2289 2418
 		// No results? Just forget it all together.
2290
-		if ($smcFunc['db_num_rows']($request) === 0)
2291
-			unset($table_row['Collation']);
2292
-		else
2293
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2419
+		if ($smcFunc['db_num_rows']($request) === 0) {
2420
+					unset($table_row['Collation']);
2421
+		} else {
2422
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2423
+		}
2294 2424
 		$smcFunc['db_free_result']($request);
2295 2425
 	}
2296 2426
 
2297 2427
 	if ($column_fix)
2298 2428
 	{
2299 2429
 		// Make sure there are no NULL's left.
2300
-		if ($null_fix)
2301
-			$smcFunc['db_query']('', '
2430
+		if ($null_fix) {
2431
+					$smcFunc['db_query']('', '
2302 2432
 				UPDATE {db_prefix}' . $change['table'] . '
2303 2433
 				SET ' . $change['column'] . ' = {string:default}
2304 2434
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2307,6 +2437,7 @@  discard block
 block discarded – undo
2307 2437
 					'db_error_skip' => true,
2308 2438
 				)
2309 2439
 			);
2440
+		}
2310 2441
 
2311 2442
 		// Do the actual alteration.
2312 2443
 		$smcFunc['db_query']('', '
@@ -2335,8 +2466,9 @@  discard block
 block discarded – undo
2335 2466
 	}
2336 2467
 
2337 2468
 	// Not a column we need to check on?
2338
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2339
-		return;
2469
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2470
+			return;
2471
+	}
2340 2472
 
2341 2473
 	// Break it up you (six|seven).
2342 2474
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2355,13 +2487,13 @@  discard block
 block discarded – undo
2355 2487
 				'new_name' => $temp[2],
2356 2488
 		));
2357 2489
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2358
-		if ($smcFunc['db_num_rows'] != 1)
2359
-			return;
2490
+		if ($smcFunc['db_num_rows'] != 1) {
2491
+					return;
2492
+		}
2360 2493
 
2361 2494
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2362 2495
 		$smcFunc['db_free_result']($request);
2363
-	}
2364
-	else
2496
+	} else
2365 2497
 	{
2366 2498
 		// Do this the old fashion, sure method way.
2367 2499
 		$request = $smcFunc['db_query']('', '
@@ -2372,21 +2504,24 @@  discard block
 block discarded – undo
2372 2504
 		));
2373 2505
 		// Mayday!
2374 2506
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2375
-		if ($smcFunc['db_num_rows'] == 0)
2376
-			return;
2507
+		if ($smcFunc['db_num_rows'] == 0) {
2508
+					return;
2509
+		}
2377 2510
 
2378 2511
 		// Oh where, oh where has my little field gone. Oh where can it be...
2379
-		while ($row = $smcFunc['db_query']($request))
2380
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2512
+		while ($row = $smcFunc['db_query']($request)) {
2513
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2381 2514
 			{
2382 2515
 				$current_type = $row['Type'];
2516
+		}
2383 2517
 				break;
2384 2518
 			}
2385 2519
 	}
2386 2520
 
2387 2521
 	// If this doesn't match, the column may of been altered for a reason.
2388
-	if (trim($current_type) != trim($temp[3]))
2389
-		$temp[3] = $current_type;
2522
+	if (trim($current_type) != trim($temp[3])) {
2523
+			$temp[3] = $current_type;
2524
+	}
2390 2525
 
2391 2526
 	// Piece this back together.
2392 2527
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2398,8 +2533,9 @@  discard block
 block discarded – undo
2398 2533
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2399 2534
 	global $step_progress, $is_debug, $upcontext;
2400 2535
 
2401
-	if ($_GET['substep'] < $substep)
2402
-		$_GET['substep'] = $substep;
2536
+	if ($_GET['substep'] < $substep) {
2537
+			$_GET['substep'] = $substep;
2538
+	}
2403 2539
 
2404 2540
 	if ($command_line)
2405 2541
 	{
@@ -2412,29 +2548,33 @@  discard block
 block discarded – undo
2412 2548
 	}
2413 2549
 
2414 2550
 	@set_time_limit(300);
2415
-	if (function_exists('apache_reset_timeout'))
2416
-		@apache_reset_timeout();
2551
+	if (function_exists('apache_reset_timeout')) {
2552
+			@apache_reset_timeout();
2553
+	}
2417 2554
 
2418
-	if (time() - $start_time <= $timeLimitThreshold)
2419
-		return;
2555
+	if (time() - $start_time <= $timeLimitThreshold) {
2556
+			return;
2557
+	}
2420 2558
 
2421 2559
 	// Do we have some custom step progress stuff?
2422 2560
 	if (!empty($step_progress))
2423 2561
 	{
2424 2562
 		$upcontext['substep_progress'] = 0;
2425 2563
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2426
-		if ($step_progress['current'] > $step_progress['total'])
2427
-			$upcontext['substep_progress'] = 99.9;
2428
-		else
2429
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2564
+		if ($step_progress['current'] > $step_progress['total']) {
2565
+					$upcontext['substep_progress'] = 99.9;
2566
+		} else {
2567
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2568
+		}
2430 2569
 
2431 2570
 		// Make it nicely rounded.
2432 2571
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2433 2572
 	}
2434 2573
 
2435 2574
 	// If this is XML we just exit right away!
2436
-	if (isset($_GET['xml']))
2437
-		return upgradeExit();
2575
+	if (isset($_GET['xml'])) {
2576
+			return upgradeExit();
2577
+	}
2438 2578
 
2439 2579
 	// We're going to pause after this!
2440 2580
 	$upcontext['pause'] = true;
@@ -2442,13 +2582,15 @@  discard block
 block discarded – undo
2442 2582
 	$upcontext['query_string'] = '';
2443 2583
 	foreach ($_GET as $k => $v)
2444 2584
 	{
2445
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2446
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2585
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2586
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2587
+		}
2447 2588
 	}
2448 2589
 
2449 2590
 	// Custom warning?
2450
-	if (!empty($custom_warning))
2451
-		$upcontext['custom_warning'] = $custom_warning;
2591
+	if (!empty($custom_warning)) {
2592
+			$upcontext['custom_warning'] = $custom_warning;
2593
+	}
2452 2594
 
2453 2595
 	upgradeExit();
2454 2596
 }
@@ -2463,25 +2605,26 @@  discard block
 block discarded – undo
2463 2605
 	ob_implicit_flush(true);
2464 2606
 	@set_time_limit(600);
2465 2607
 
2466
-	if (!isset($_SERVER['argv']))
2467
-		$_SERVER['argv'] = array();
2608
+	if (!isset($_SERVER['argv'])) {
2609
+			$_SERVER['argv'] = array();
2610
+	}
2468 2611
 	$_GET['maint'] = 1;
2469 2612
 
2470 2613
 	foreach ($_SERVER['argv'] as $i => $arg)
2471 2614
 	{
2472
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2473
-			$_GET['lang'] = $match[1];
2474
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2475
-			continue;
2476
-		elseif ($arg == '--no-maintenance')
2477
-			$_GET['maint'] = 0;
2478
-		elseif ($arg == '--debug')
2479
-			$is_debug = true;
2480
-		elseif ($arg == '--backup')
2481
-			$_POST['backup'] = 1;
2482
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2483
-			$_GET['conv'] = 1;
2484
-		elseif ($i != 0)
2615
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2616
+					$_GET['lang'] = $match[1];
2617
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2618
+					continue;
2619
+		} elseif ($arg == '--no-maintenance') {
2620
+					$_GET['maint'] = 0;
2621
+		} elseif ($arg == '--debug') {
2622
+					$is_debug = true;
2623
+		} elseif ($arg == '--backup') {
2624
+					$_POST['backup'] = 1;
2625
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2626
+					$_GET['conv'] = 1;
2627
+		} elseif ($i != 0)
2485 2628
 		{
2486 2629
 			echo 'SMF Command-line Upgrader
2487 2630
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2495,10 +2638,12 @@  discard block
 block discarded – undo
2495 2638
 		}
2496 2639
 	}
2497 2640
 
2498
-	if (!php_version_check())
2499
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2500
-	if (!db_version_check())
2501
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2641
+	if (!php_version_check()) {
2642
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2643
+	}
2644
+	if (!db_version_check()) {
2645
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2646
+	}
2502 2647
 
2503 2648
 	// Do some checks to make sure they have proper privileges
2504 2649
 	db_extend('packages');
@@ -2513,34 +2658,39 @@  discard block
 block discarded – undo
2513 2658
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2514 2659
 
2515 2660
 	// Sorry... we need CREATE, ALTER and DROP
2516
-	if (!$create || !$alter || !$drop)
2517
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2661
+	if (!$create || !$alter || !$drop) {
2662
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2663
+	}
2518 2664
 
2519 2665
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2520 2666
 		&& @file_exists($sourcedir . '/QueryString.php')
2521 2667
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2522
-	if (!$check && !isset($modSettings['smfVersion']))
2523
-		print_error('Error: Some files are missing or out-of-date.', true);
2668
+	if (!$check && !isset($modSettings['smfVersion'])) {
2669
+			print_error('Error: Some files are missing or out-of-date.', true);
2670
+	}
2524 2671
 
2525 2672
 	// Do a quick version spot check.
2526 2673
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2527 2674
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2528
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2529
-		print_error('Error: Some files have not yet been updated properly.');
2675
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2676
+			print_error('Error: Some files have not yet been updated properly.');
2677
+	}
2530 2678
 
2531 2679
 	// Make sure Settings.php is writable.
2532 2680
 	quickFileWritable($boarddir . '/Settings.php');
2533
-	if (!is_writable($boarddir . '/Settings.php'))
2534
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2681
+	if (!is_writable($boarddir . '/Settings.php')) {
2682
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2683
+	}
2535 2684
 
2536 2685
 	// Make sure Settings_bak.php is writable.
2537 2686
 	quickFileWritable($boarddir . '/Settings_bak.php');
2538
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2539
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2687
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2688
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2689
+	}
2540 2690
 
2541
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2542
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2543
-	elseif (isset($modSettings['agreement']))
2691
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2692
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2693
+	} elseif (isset($modSettings['agreement']))
2544 2694
 	{
2545 2695
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2546 2696
 		fwrite($fp, $modSettings['agreement']);
@@ -2550,36 +2700,42 @@  discard block
 block discarded – undo
2550 2700
 	// Make sure Themes is writable.
2551 2701
 	quickFileWritable($modSettings['theme_dir']);
2552 2702
 
2553
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2554
-		print_error('Error: Unable to obtain write access to "Themes".');
2703
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2704
+			print_error('Error: Unable to obtain write access to "Themes".');
2705
+	}
2555 2706
 
2556 2707
 	// Make sure cache directory exists and is writable!
2557 2708
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2558
-	if (!file_exists($cachedir_temp))
2559
-		@mkdir($cachedir_temp);
2709
+	if (!file_exists($cachedir_temp)) {
2710
+			@mkdir($cachedir_temp);
2711
+	}
2560 2712
 
2561 2713
 	// Make sure the cache temp dir is writable.
2562 2714
 	quickFileWritable($cachedir_temp);
2563 2715
 
2564
-	if (!is_writable($cachedir_temp))
2565
-		print_error('Error: Unable to obtain write access to "cache".', true);
2716
+	if (!is_writable($cachedir_temp)) {
2717
+			print_error('Error: Unable to obtain write access to "cache".', true);
2718
+	}
2566 2719
 
2567 2720
 	// Make sure db_last_error.php is writable.
2568 2721
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2569
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2570
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2722
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2723
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2724
+	}
2571 2725
 
2572
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2573
-		print_error('Error: Unable to find language files!', true);
2574
-	else
2726
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2727
+			print_error('Error: Unable to find language files!', true);
2728
+	} else
2575 2729
 	{
2576 2730
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2577 2731
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2578 2732
 
2579
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2580
-			print_error('Error: Language files out of date.', true);
2581
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2582
-			print_error('Error: Install language is missing for selected language.', true);
2733
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2734
+					print_error('Error: Language files out of date.', true);
2735
+		}
2736
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2737
+					print_error('Error: Install language is missing for selected language.', true);
2738
+		}
2583 2739
 
2584 2740
 		// Otherwise include it!
2585 2741
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2599,8 +2755,9 @@  discard block
 block discarded – undo
2599 2755
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2600 2756
 
2601 2757
 	// Done it already?
2602
-	if (!empty($_POST['utf8_done']))
2603
-		return true;
2758
+	if (!empty($_POST['utf8_done'])) {
2759
+			return true;
2760
+	}
2604 2761
 
2605 2762
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2606 2763
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2613,8 +2770,7 @@  discard block
 block discarded – undo
2613 2770
 		);
2614 2771
 
2615 2772
 		return true;
2616
-	}
2617
-	else
2773
+	} else
2618 2774
 	{
2619 2775
 		$upcontext['page_title'] = $txt['converting_utf8'];
2620 2776
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2658,8 +2814,9 @@  discard block
 block discarded – undo
2658 2814
 			)
2659 2815
 		);
2660 2816
 		$db_charsets = array();
2661
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2662
-			$db_charsets[] = $row['Charset'];
2817
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2818
+					$db_charsets[] = $row['Charset'];
2819
+		}
2663 2820
 
2664 2821
 		$smcFunc['db_free_result']($request);
2665 2822
 
@@ -2695,13 +2852,15 @@  discard block
 block discarded – undo
2695 2852
 		// If there's a fulltext index, we need to drop it first...
2696 2853
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2697 2854
 		{
2698
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2699
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2855
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2856
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2700 2857
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2858
+			}
2701 2859
 			$smcFunc['db_free_result']($request);
2702 2860
 
2703
-			if (isset($upcontext['fulltext_index']))
2704
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2861
+			if (isset($upcontext['fulltext_index'])) {
2862
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2863
+			}
2705 2864
 		}
2706 2865
 
2707 2866
 		// Drop it and make a note...
@@ -2891,8 +3050,9 @@  discard block
 block discarded – undo
2891 3050
 			$replace = '%field%';
2892 3051
 
2893 3052
 			// Build a huge REPLACE statement...
2894
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2895
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3053
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3054
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3055
+			}
2896 3056
 		}
2897 3057
 
2898 3058
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2902,9 +3062,10 @@  discard block
 block discarded – undo
2902 3062
 		$upcontext['table_count'] = count($queryTables);
2903 3063
 
2904 3064
 		// What ones have we already done?
2905
-		foreach ($queryTables as $id => $table)
2906
-			if ($id < $_GET['substep'])
3065
+		foreach ($queryTables as $id => $table) {
3066
+					if ($id < $_GET['substep'])
2907 3067
 				$upcontext['previous_tables'][] = $table;
3068
+		}
2908 3069
 
2909 3070
 		$upcontext['cur_table_num'] = $_GET['substep'];
2910 3071
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2941,8 +3102,9 @@  discard block
 block discarded – undo
2941 3102
 			nextSubstep($substep);
2942 3103
 
2943 3104
 			// Just to make sure it doesn't time out.
2944
-			if (function_exists('apache_reset_timeout'))
2945
-				@apache_reset_timeout();
3105
+			if (function_exists('apache_reset_timeout')) {
3106
+							@apache_reset_timeout();
3107
+			}
2946 3108
 
2947 3109
 			$table_charsets = array();
2948 3110
 
@@ -2965,8 +3127,9 @@  discard block
 block discarded – undo
2965 3127
 
2966 3128
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2967 3129
 						if ($charset != 'utf8') {
2968
-							if (!isset($table_charsets[$charset]))
2969
-								$table_charsets[$charset] = array();
3130
+							if (!isset($table_charsets[$charset])) {
3131
+															$table_charsets[$charset] = array();
3132
+							}
2970 3133
 
2971 3134
 							$table_charsets[$charset][] = $column_info;
2972 3135
 						}
@@ -3007,10 +3170,11 @@  discard block
 block discarded – undo
3007 3170
 				if (isset($translation_tables[$upcontext['charset_detected']]))
3008 3171
 				{
3009 3172
 					$update = '';
3010
-					foreach ($table_charsets as $charset => $columns)
3011
-						foreach ($columns as $column)
3173
+					foreach ($table_charsets as $charset => $columns) {
3174
+											foreach ($columns as $column)
3012 3175
 							$update .= '
3013 3176
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3177
+					}
3014 3178
 
3015 3179
 					$smcFunc['db_query']('', '
3016 3180
 						UPDATE {raw:table_name}
@@ -3035,8 +3199,9 @@  discard block
 block discarded – undo
3035 3199
 			// Now do the actual conversion (if still needed).
3036 3200
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
3037 3201
 			{
3038
-				if ($command_line)
3039
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3202
+				if ($command_line) {
3203
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3204
+				}
3040 3205
 
3041 3206
 				$smcFunc['db_query']('', '
3042 3207
 					ALTER TABLE {raw:table_name}
@@ -3046,12 +3211,14 @@  discard block
 block discarded – undo
3046 3211
 					)
3047 3212
 				);
3048 3213
 
3049
-				if ($command_line)
3050
-					echo " done.\n";
3214
+				if ($command_line) {
3215
+									echo " done.\n";
3216
+				}
3051 3217
 			}
3052 3218
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3053
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
3054
-				return upgradeExit();
3219
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3220
+							return upgradeExit();
3221
+			}
3055 3222
 		}
3056 3223
 
3057 3224
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3080,8 +3247,8 @@  discard block
 block discarded – undo
3080 3247
 		);
3081 3248
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3082 3249
 		{
3083
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
3084
-				$smcFunc['db_query']('', '
3250
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3251
+							$smcFunc['db_query']('', '
3085 3252
 					UPDATE {db_prefix}log_actions
3086 3253
 					SET extra = {string:extra}
3087 3254
 					WHERE id_action = {int:current_action}',
@@ -3090,6 +3257,7 @@  discard block
 block discarded – undo
3090 3257
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3091 3258
 					)
3092 3259
 				);
3260
+			}
3093 3261
 		}
3094 3262
 		$smcFunc['db_free_result']($request);
3095 3263
 
@@ -3111,15 +3279,17 @@  discard block
 block discarded – undo
3111 3279
 	// First thing's first - did we already do this?
3112 3280
 	if (!empty($modSettings['json_done']))
3113 3281
 	{
3114
-		if ($command_line)
3115
-			return DeleteUpgrade();
3116
-		else
3117
-			return true;
3282
+		if ($command_line) {
3283
+					return DeleteUpgrade();
3284
+		} else {
3285
+					return true;
3286
+		}
3118 3287
 	}
3119 3288
 
3120 3289
 	// Done it already - js wise?
3121
-	if (!empty($_POST['json_done']))
3122
-		return true;
3290
+	if (!empty($_POST['json_done'])) {
3291
+			return true;
3292
+	}
3123 3293
 
3124 3294
 	// List of tables affected by this function
3125 3295
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3151,12 +3321,14 @@  discard block
 block discarded – undo
3151 3321
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3152 3322
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3153 3323
 
3154
-	foreach ($keys as $id => $table)
3155
-		if ($id < $_GET['substep'])
3324
+	foreach ($keys as $id => $table) {
3325
+			if ($id < $_GET['substep'])
3156 3326
 			$upcontext['previous_tables'][] = $table;
3327
+	}
3157 3328
 
3158
-	if ($command_line)
3159
-		echo 'Converting data from serialize() to json_encode().';
3329
+	if ($command_line) {
3330
+			echo 'Converting data from serialize() to json_encode().';
3331
+	}
3160 3332
 
3161 3333
 	if (!$support_js || isset($_GET['xml']))
3162 3334
 	{
@@ -3196,8 +3368,9 @@  discard block
 block discarded – undo
3196 3368
 
3197 3369
 				// Loop through and fix these...
3198 3370
 				$new_settings = array();
3199
-				if ($command_line)
3200
-					echo "\n" . 'Fixing some settings...';
3371
+				if ($command_line) {
3372
+									echo "\n" . 'Fixing some settings...';
3373
+				}
3201 3374
 
3202 3375
 				foreach ($serialized_settings as $var)
3203 3376
 				{
@@ -3205,22 +3378,24 @@  discard block
 block discarded – undo
3205 3378
 					{
3206 3379
 						// Attempt to unserialize the setting
3207 3380
 						$temp = @safe_unserialize($modSettings[$var]);
3208
-						if (!$temp && $command_line)
3209
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3210
-						elseif ($temp !== false)
3211
-							$new_settings[$var] = json_encode($temp);
3381
+						if (!$temp && $command_line) {
3382
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3383
+						} elseif ($temp !== false) {
3384
+													$new_settings[$var] = json_encode($temp);
3385
+						}
3212 3386
 					}
3213 3387
 				}
3214 3388
 
3215 3389
 				// Update everything at once
3216
-				if (!function_exists('cache_put_data'))
3217
-					require_once($sourcedir . '/Load.php');
3390
+				if (!function_exists('cache_put_data')) {
3391
+									require_once($sourcedir . '/Load.php');
3392
+				}
3218 3393
 				updateSettings($new_settings, true);
3219 3394
 
3220
-				if ($command_line)
3221
-					echo ' done.';
3222
-			}
3223
-			elseif ($table == 'themes')
3395
+				if ($command_line) {
3396
+									echo ' done.';
3397
+				}
3398
+			} elseif ($table == 'themes')
3224 3399
 			{
3225 3400
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3226 3401
 				$query = $smcFunc['db_query']('', '
@@ -3239,10 +3414,11 @@  discard block
 block discarded – undo
3239 3414
 
3240 3415
 						if ($command_line)
3241 3416
 						{
3242
-							if ($temp === false)
3243
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3244
-							else
3245
-								echo "\n" . 'Fixing admin preferences...';
3417
+							if ($temp === false) {
3418
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3419
+							} else {
3420
+															echo "\n" . 'Fixing admin preferences...';
3421
+							}
3246 3422
 						}
3247 3423
 
3248 3424
 						if ($temp !== false)
@@ -3264,15 +3440,15 @@  discard block
 block discarded – undo
3264 3440
 								)
3265 3441
 							);
3266 3442
 
3267
-							if ($command_line)
3268
-								echo ' done.';
3443
+							if ($command_line) {
3444
+															echo ' done.';
3445
+							}
3269 3446
 						}
3270 3447
 					}
3271 3448
 
3272 3449
 					$smcFunc['db_free_result']($query);
3273 3450
 				}
3274
-			}
3275
-			else
3451
+			} else
3276 3452
 			{
3277 3453
 				// First item is always the key...
3278 3454
 				$key = $info[0];
@@ -3283,8 +3459,7 @@  discard block
 block discarded – undo
3283 3459
 				{
3284 3460
 					$col_select = $info[1];
3285 3461
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3286
-				}
3287
-				else
3462
+				} else
3288 3463
 				{
3289 3464
 					$col_select = implode(', ', $info);
3290 3465
 				}
@@ -3317,8 +3492,7 @@  discard block
 block discarded – undo
3317 3492
 								if ($temp === false && $command_line)
3318 3493
 								{
3319 3494
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3320
-								}
3321
-								else
3495
+								} else
3322 3496
 								{
3323 3497
 									$row[$col] = json_encode($temp);
3324 3498
 
@@ -3343,16 +3517,18 @@  discard block
 block discarded – undo
3343 3517
 						}
3344 3518
 					}
3345 3519
 
3346
-					if ($command_line)
3347
-						echo ' done.';
3520
+					if ($command_line) {
3521
+											echo ' done.';
3522
+					}
3348 3523
 
3349 3524
 					// Free up some memory...
3350 3525
 					$smcFunc['db_free_result']($query);
3351 3526
 				}
3352 3527
 			}
3353 3528
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3354
-			if (isset($_GET['xml']))
3355
-				return upgradeExit();
3529
+			if (isset($_GET['xml'])) {
3530
+							return upgradeExit();
3531
+			}
3356 3532
 		}
3357 3533
 
3358 3534
 		if ($command_line)
@@ -3367,8 +3543,9 @@  discard block
 block discarded – undo
3367 3543
 
3368 3544
 		$_GET['substep'] = 0;
3369 3545
 		// Make sure we move on!
3370
-		if ($command_line)
3371
-			return DeleteUpgrade();
3546
+		if ($command_line) {
3547
+					return DeleteUpgrade();
3548
+		}
3372 3549
 
3373 3550
 		return true;
3374 3551
 	}
@@ -3425,14 +3602,16 @@  discard block
 block discarded – undo
3425 3602
 	global $upcontext, $txt, $settings;
3426 3603
 
3427 3604
 	// Don't call me twice!
3428
-	if (!empty($upcontext['chmod_called']))
3429
-		return;
3605
+	if (!empty($upcontext['chmod_called'])) {
3606
+			return;
3607
+	}
3430 3608
 
3431 3609
 	$upcontext['chmod_called'] = true;
3432 3610
 
3433 3611
 	// Nothing?
3434
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3435
-		return;
3612
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3613
+			return;
3614
+	}
3436 3615
 
3437 3616
 	// Was it a problem with Windows?
3438 3617
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3464,11 +3643,12 @@  discard block
 block discarded – undo
3464 3643
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3465 3644
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3466 3645
 
3467
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3468
-		echo '
3646
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3647
+			echo '
3469 3648
 					content.write(\'<hr>\n\t\t\t\');
3470 3649
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3471 3650
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3651
+	}
3472 3652
 
3473 3653
 	echo '
3474 3654
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3476,16 +3656,18 @@  discard block
 block discarded – undo
3476 3656
 				}
3477 3657
 			</script>';
3478 3658
 
3479
-	if (!empty($upcontext['chmod']['ftp_error']))
3480
-		echo '
3659
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3660
+			echo '
3481 3661
 			<div class="error_message red">
3482 3662
 				<p>', $txt['upgrade_ftp_error'], '<p>
3483 3663
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3484 3664
 			</div>';
3665
+	}
3485 3666
 
3486
-	if (empty($upcontext['chmod_in_form']))
3487
-		echo '
3667
+	if (empty($upcontext['chmod_in_form'])) {
3668
+			echo '
3488 3669
 			<form action="', $upcontext['form_url'], '" method="post">';
3670
+	}
3489 3671
 
3490 3672
 	echo '
3491 3673
 				<dl class="settings">
@@ -3527,9 +3709,10 @@  discard block
 block discarded – undo
3527 3709
 					<input type="submit" value="', $txt['ftp_connect'], '" class="button">
3528 3710
 				</div>';
3529 3711
 
3530
-	if (empty($upcontext['chmod_in_form']))
3531
-		echo '
3712
+	if (empty($upcontext['chmod_in_form'])) {
3713
+			echo '
3532 3714
 			</form>';
3715
+	}
3533 3716
 
3534 3717
 	echo '
3535 3718
 		</div><!-- .panel -->';
@@ -3593,9 +3776,10 @@  discard block
 block discarded – undo
3593 3776
 					<h2>', $txt['upgrade_progress'], '</h2>
3594 3777
 					<ul>';
3595 3778
 
3596
-	foreach ($upcontext['steps'] as $num => $step)
3597
-		echo '
3779
+	foreach ($upcontext['steps'] as $num => $step) {
3780
+			echo '
3598 3781
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3782
+	}
3599 3783
 
3600 3784
 	echo '
3601 3785
 					</ul>
@@ -3608,13 +3792,14 @@  discard block
 block discarded – undo
3608 3792
 						<span id="overall_text">', $upcontext['overall_percent'], '%</span>
3609 3793
 					</div>';
3610 3794
 
3611
-	if (isset($upcontext['step_progress']))
3612
-		echo '
3795
+	if (isset($upcontext['step_progress'])) {
3796
+			echo '
3613 3797
 					<div id="progress_bar_step" class="progress_bar progress_yellow">
3614 3798
 						<h3>', $txt['upgrade_step_progress'], '</h3>
3615 3799
 						<div id="step_progress" class="bar" style="width: ', $upcontext['step_progress'], '%;"></div>
3616 3800
 						<span id="step_text">', $upcontext['step_progress'], '%</span>
3617 3801
 					</div>';
3802
+	}
3618 3803
 
3619 3804
 	echo '
3620 3805
 					<div id="substep_bar_div" class="progress_bar" style="display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">
@@ -3645,31 +3830,35 @@  discard block
 block discarded – undo
3645 3830
 {
3646 3831
 	global $upcontext, $txt;
3647 3832
 
3648
-	if (!empty($upcontext['pause']))
3649
-		echo '
3833
+	if (!empty($upcontext['pause'])) {
3834
+			echo '
3650 3835
 					<em>', $txt['upgrade_incomplete'], '.</em><br>
3651 3836
 
3652 3837
 					<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3653 3838
 					<h3>
3654 3839
 						', $txt['upgrade_paused_overload'], '
3655 3840
 					</h3>';
3841
+	}
3656 3842
 
3657
-	if (!empty($upcontext['custom_warning']))
3658
-		echo '
3843
+	if (!empty($upcontext['custom_warning'])) {
3844
+			echo '
3659 3845
 					<div class="errorbox">
3660 3846
 						<h3>', $txt['upgrade_note'], '</h3>
3661 3847
 						', $upcontext['custom_warning'], '
3662 3848
 					</div>';
3849
+	}
3663 3850
 
3664 3851
 	echo '
3665 3852
 					<div class="righttext" style="margin: 1ex;">';
3666 3853
 
3667
-	if (!empty($upcontext['continue']))
3668
-		echo '
3854
+	if (!empty($upcontext['continue'])) {
3855
+			echo '
3669 3856
 						<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3670
-	if (!empty($upcontext['skip']))
3671
-		echo '
3857
+	}
3858
+	if (!empty($upcontext['skip'])) {
3859
+			echo '
3672 3860
 						<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3861
+	}
3673 3862
 
3674 3863
 	echo '
3675 3864
 					</div>
@@ -3720,11 +3909,12 @@  discard block
 block discarded – undo
3720 3909
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3721 3910
 	<smf>';
3722 3911
 
3723
-	if (!empty($upcontext['get_data']))
3724
-		foreach ($upcontext['get_data'] as $k => $v)
3912
+	if (!empty($upcontext['get_data'])) {
3913
+			foreach ($upcontext['get_data'] as $k => $v)
3725 3914
 			echo '
3726 3915
 		<get key="', $k, '">', $v, '</get>';
3727
-}
3916
+	}
3917
+	}
3728 3918
 
3729 3919
 function template_xml_below()
3730 3920
 {
@@ -3764,20 +3954,22 @@  discard block
 block discarded – undo
3764 3954
 	template_chmod();
3765 3955
 
3766 3956
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3767
-	if ($upcontext['is_large_forum'])
3768
-		echo '
3957
+	if ($upcontext['is_large_forum']) {
3958
+			echo '
3769 3959
 					<div class="errorbox">
3770 3960
 						<h3>', $txt['upgrade_warning'], '</h3>
3771 3961
 						', $txt['upgrade_warning_lots_data'], '
3772 3962
 					</div>';
3963
+	}
3773 3964
 
3774 3965
 	// A warning message?
3775
-	if (!empty($upcontext['warning']))
3776
-		echo '
3966
+	if (!empty($upcontext['warning'])) {
3967
+			echo '
3777 3968
 					<div class="errorbox">
3778 3969
 						<h3>', $txt['upgrade_warning'], '</h3>
3779 3970
 						', $upcontext['warning'], '
3780 3971
 					</div>';
3972
+	}
3781 3973
 
3782 3974
 	// Paths are incorrect?
3783 3975
 	echo '
@@ -3808,16 +4000,18 @@  discard block
 block discarded – undo
3808 4000
 						<p>', sprintf($txt[$agoTxt],  $ago_seconds, $ago_minutes, $ago_hours), '</p>
3809 4001
 						<p>', sprintf($txt[$updatedTxt], $updated_seconds, $updated_minutes, $updated_hours), '</p>';
3810 4002
 
3811
-		if ($updated < 600)
3812
-			echo '
4003
+		if ($updated < 600) {
4004
+					echo '
3813 4005
 						<p>', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '</p>';
4006
+		}
3814 4007
 
3815
-		if ($updated > $upcontext['inactive_timeout'])
3816
-			echo '
4008
+		if ($updated > $upcontext['inactive_timeout']) {
4009
+					echo '
3817 4010
 						<p>',$txt['upgrade_run'], '</p>';
3818
-		else
3819
-			echo '
4011
+		} else {
4012
+					echo '
3820 4013
 						<p>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!'), '</p>';
4014
+		}
3821 4015
 
3822 4016
 		echo '
3823 4017
 					</div>';
@@ -3833,9 +4027,10 @@  discard block
 block discarded – undo
3833 4027
 						<dd>
3834 4028
 							<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3835 4029
 
3836
-	if (!empty($upcontext['username_incorrect']))
3837
-		echo '
4030
+	if (!empty($upcontext['username_incorrect'])) {
4031
+			echo '
3838 4032
 							<div class="smalltext red">', $txt['upgrade_wrong_username'], '</div>';
4033
+	}
3839 4034
 
3840 4035
 	echo '
3841 4036
 						</dd>
@@ -3846,9 +4041,10 @@  discard block
 block discarded – undo
3846 4041
 							<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3847 4042
 							<input type="hidden" name="hash_passwrd" value="">';
3848 4043
 
3849
-	if (!empty($upcontext['password_failed']))
3850
-		echo '
4044
+	if (!empty($upcontext['password_failed'])) {
4045
+			echo '
3851 4046
 							<div class="smalltext red">', $txt['upgrade_wrong_password'], '</div>';
4047
+	}
3852 4048
 
3853 4049
 	echo '
3854 4050
 						</dd>';
@@ -3916,12 +4112,13 @@  discard block
 block discarded – undo
3916 4112
 				<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3917 4113
 
3918 4114
 	// Warning message?
3919
-	if (!empty($upcontext['upgrade_options_warning']))
3920
-		echo '
4115
+	if (!empty($upcontext['upgrade_options_warning'])) {
4116
+			echo '
3921 4117
 				<div class="errorbox">
3922 4118
 					<h3>', $txt['upgrade_warning'] ,'</h3>
3923 4119
 					', $upcontext['upgrade_options_warning'], '
3924 4120
 				</div>';
4121
+	}
3925 4122
 
3926 4123
 	echo '
3927 4124
 				<ul class="upgrade_settings">
@@ -3950,12 +4147,13 @@  discard block
 block discarded – undo
3950 4147
 						<label for="empty_error">', $txt['upgrade_empty_errlog'], '</label>
3951 4148
 					</li>';
3952 4149
 
3953
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3954
-		echo '
4150
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4151
+			echo '
3955 4152
 					<li>
3956 4153
 						<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
3957 4154
 						<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3958 4155
 					</li>';
4156
+	}
3959 4157
 
3960 4158
 	echo '
3961 4159
 					<li>
@@ -3995,10 +4193,11 @@  discard block
 block discarded – undo
3995 4193
 					</div>';
3996 4194
 
3997 4195
 	// Dont any tables so far?
3998
-	if (!empty($upcontext['previous_tables']))
3999
-		foreach ($upcontext['previous_tables'] as $table)
4196
+	if (!empty($upcontext['previous_tables'])) {
4197
+			foreach ($upcontext['previous_tables'] as $table)
4000 4198
 			echo '
4001 4199
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4200
+	}
4002 4201
 
4003 4202
 	echo '
4004 4203
 					<h3 id="current_tab">
@@ -4037,12 +4236,13 @@  discard block
 block discarded – undo
4037 4236
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4038 4237
 
4039 4238
 		// If debug flood the screen.
4040
-		if ($is_debug)
4041
-			echo '
4239
+		if ($is_debug) {
4240
+					echo '
4042 4241
 							setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4043 4242
 
4044 4243
 							if (document.getElementById(\'debug_section\').scrollHeight)
4045 4244
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4245
+		}
4046 4246
 
4047 4247
 		echo '
4048 4248
 							// Get the next update...
@@ -4075,8 +4275,9 @@  discard block
 block discarded – undo
4075 4275
 {
4076 4276
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4077 4277
 
4078
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4079
-		$is_debug = true;
4278
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4279
+			$is_debug = true;
4280
+	}
4080 4281
 
4081 4282
 	echo '
4082 4283
 				<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4091,8 +4292,9 @@  discard block
 block discarded – undo
4091 4292
 	{
4092 4293
 		foreach ($upcontext['actioned_items'] as $num => $item)
4093 4294
 		{
4094
-			if ($num != 0)
4095
-				echo ' Successful!';
4295
+			if ($num != 0) {
4296
+							echo ' Successful!';
4297
+			}
4096 4298
 			echo '<br>' . $item;
4097 4299
 		}
4098 4300
 
@@ -4107,20 +4309,20 @@  discard block
 block discarded – undo
4107 4309
 				$seconds = intval($active % 60);
4108 4310
 
4109 4311
 				echo '', sprintf($txt['upgrade_success_time_db'], $seconds, $minutes, $hours), '<br>';
4312
+			} else {
4313
+							echo '', $txt['upgrade_success'], '<br>';
4110 4314
 			}
4111
-			else
4112
-				echo '', $txt['upgrade_success'], '<br>';
4113 4315
 
4114 4316
 			echo '
4115 4317
 					<p id="commess">', $txt['upgrade_db_complete'], '</p>';
4116 4318
 		}
4117
-	}
4118
-	else
4319
+	} else
4119 4320
 	{
4120 4321
 		// Tell them how many files we have in total.
4121
-		if ($upcontext['file_count'] > 1)
4122
-			echo '
4322
+		if ($upcontext['file_count'] > 1) {
4323
+					echo '
4123 4324
 					<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4325
+		}
4124 4326
 
4125 4327
 		echo '
4126 4328
 					<h3 id="info2">
@@ -4140,10 +4342,10 @@  discard block
 block discarded – undo
4140 4342
 
4141 4343
 				echo '
4142 4344
 					<p id="upgradeCompleted">', sprintf($txt['upgrade_success_time_db'], $seconds, $minutes, $hours), '</p>';
4143
-			}
4144
-			else
4145
-				echo '
4345
+			} else {
4346
+							echo '
4146 4347
 					<p id="upgradeCompleted"></p>';
4348
+			}
4147 4349
 
4148 4350
 			echo '
4149 4351
 					<div id="debug_section">
@@ -4179,9 +4381,10 @@  discard block
 block discarded – undo
4179 4381
 						var getData = "";
4180 4382
 						var debugItems = ', $upcontext['debug_items'], ';';
4181 4383
 
4182
-		if ($is_debug)
4183
-			echo '
4384
+		if ($is_debug) {
4385
+					echo '
4184 4386
 						var upgradeStartTime = ' . $upcontext['started'] . ';';
4387
+		}
4185 4388
 
4186 4389
 		echo '
4187 4390
 						function getNextItem()
@@ -4221,9 +4424,10 @@  discard block
 block discarded – undo
4221 4424
 									document.getElementById("error_block").style.display = "";
4222 4425
 									setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4223 4426
 
4224
-	if ($is_debug)
4225
-		echo '
4427
+	if ($is_debug) {
4428
+			echo '
4226 4429
 									setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4430
+	}
4227 4431
 
4228 4432
 	echo '
4229 4433
 								}
@@ -4244,9 +4448,10 @@  discard block
 block discarded – undo
4244 4448
 									document.getElementById("error_block").style.display = "";
4245 4449
 									setInnerHTML(document.getElementById("error_message"), "', $txt['upgrade_loop'], '" + sDebugName);';
4246 4450
 
4247
-	if ($is_debug)
4248
-		echo '
4451
+	if ($is_debug) {
4452
+			echo '
4249 4453
 									setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4454
+	}
4250 4455
 
4251 4456
 	echo '
4252 4457
 								}
@@ -4304,8 +4509,8 @@  discard block
 block discarded – undo
4304 4509
 							{';
4305 4510
 
4306 4511
 		// Database Changes, tell us how much time we spen to do this.  If this gets updated via JS.
4307
-		if ($is_debug)
4308
-			echo '
4512
+		if ($is_debug) {
4513
+					echo '
4309 4514
 								document.getElementById(\'debug_section\').style.display = "none";
4310 4515
 
4311 4516
 								var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4320,6 +4525,7 @@  discard block
 block discarded – undo
4320 4525
 								completedTxt = completedTxt.replace("%1$d", diffSeconds).replace("%2$d", diffMinutes).replace("%3$d", diffHours);
4321 4526
 console.log(completedTxt, upgradeFinishedTime, diffTime, diffHours, diffMinutes, diffSeconds);
4322 4527
 								setInnerHTML(document.getElementById("upgradeCompleted"), completedTxt);';
4528
+		}
4323 4529
 
4324 4530
 		echo '
4325 4531
 
@@ -4327,9 +4533,10 @@  discard block
 block discarded – undo
4327 4533
 								document.getElementById(\'contbutt\').disabled = 0;
4328 4534
 								document.getElementById(\'database_done\').value = 1;';
4329 4535
 
4330
-		if ($upcontext['file_count'] > 1)
4331
-			echo '
4536
+		if ($upcontext['file_count'] > 1) {
4537
+					echo '
4332 4538
 								document.getElementById(\'info1\').style.display = "none";';
4539
+		}
4333 4540
 
4334 4541
 		echo '
4335 4542
 								document.getElementById(\'info2\').style.display = "none";
@@ -4342,9 +4549,10 @@  discard block
 block discarded – undo
4342 4549
 								lastItem = 0;
4343 4550
 								prevFile = curFile;';
4344 4551
 
4345
-		if ($is_debug)
4346
-			echo '
4552
+		if ($is_debug) {
4553
+					echo '
4347 4554
 								setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4555
+		}
4348 4556
 
4349 4557
 		echo '
4350 4558
 								getNextItem();
@@ -4352,8 +4560,8 @@  discard block
 block discarded – undo
4352 4560
 							}';
4353 4561
 
4354 4562
 		// If debug scroll the screen.
4355
-		if ($is_debug)
4356
-			echo '
4563
+		if ($is_debug) {
4564
+					echo '
4357 4565
 							if (iLastSubStepProgress == -1)
4358 4566
 							{
4359 4567
 								// Give it consistent dots.
@@ -4372,6 +4580,7 @@  discard block
 block discarded – undo
4372 4580
 
4373 4581
 							if (document.getElementById(\'debug_section\').scrollHeight)
4374 4582
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4583
+		}
4375 4584
 
4376 4585
 		echo '
4377 4586
 							// Update the page.
@@ -4432,9 +4641,10 @@  discard block
 block discarded – undo
4432 4641
 						}';
4433 4642
 
4434 4643
 		// Start things off assuming we've not errored.
4435
-		if (empty($upcontext['error_message']))
4436
-			echo '
4644
+		if (empty($upcontext['error_message'])) {
4645
+					echo '
4437 4646
 						getNextItem();';
4647
+		}
4438 4648
 
4439 4649
 		echo '
4440 4650
 					//# sourceURL=dynamicScript-dbch.js
@@ -4452,18 +4662,21 @@  discard block
 block discarded – undo
4452 4662
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4453 4663
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4454 4664
 
4455
-	if (!empty($upcontext['error_message']))
4456
-		echo '
4665
+	if (!empty($upcontext['error_message'])) {
4666
+			echo '
4457 4667
 	<error>', $upcontext['error_message'], '</error>';
4668
+	}
4458 4669
 
4459
-	if (!empty($upcontext['error_string']))
4460
-		echo '
4670
+	if (!empty($upcontext['error_string'])) {
4671
+			echo '
4461 4672
 	<sql>', $upcontext['error_string'], '</sql>';
4673
+	}
4462 4674
 
4463
-	if ($is_debug)
4464
-		echo '
4675
+	if ($is_debug) {
4676
+			echo '
4465 4677
 	<curtime>', time(), '</curtime>';
4466
-}
4678
+	}
4679
+	}
4467 4680
 
4468 4681
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4469 4682
 function template_convert_utf8()
@@ -4480,10 +4693,11 @@  discard block
 block discarded – undo
4480 4693
 					</div>';
4481 4694
 
4482 4695
 	// Done any tables so far?
4483
-	if (!empty($upcontext['previous_tables']))
4484
-		foreach ($upcontext['previous_tables'] as $table)
4696
+	if (!empty($upcontext['previous_tables'])) {
4697
+			foreach ($upcontext['previous_tables'] as $table)
4485 4698
 			echo '
4486 4699
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4700
+	}
4487 4701
 
4488 4702
 	echo '
4489 4703
 					<h3 id="current_tab">
@@ -4491,9 +4705,10 @@  discard block
 block discarded – undo
4491 4705
 					</h3>';
4492 4706
 
4493 4707
 	// If we dropped their index, let's let them know
4494
-	if ($upcontext['dropping_index'])
4495
-		echo '
4708
+	if ($upcontext['dropping_index']) {
4709
+			echo '
4496 4710
 					<p id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</p>';
4711
+	}
4497 4712
 
4498 4713
 	// Completion notification
4499 4714
 	echo '
@@ -4530,12 +4745,13 @@  discard block
 block discarded – undo
4530 4745
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4531 4746
 
4532 4747
 		// If debug flood the screen.
4533
-		if ($is_debug)
4534
-			echo '
4748
+		if ($is_debug) {
4749
+					echo '
4535 4750
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4536 4751
 
4537 4752
 						if (document.getElementById(\'debug_section\').scrollHeight)
4538 4753
 							document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4754
+		}
4539 4755
 
4540 4756
 		echo '
4541 4757
 						// Get the next update...
@@ -4581,10 +4797,11 @@  discard block
 block discarded – undo
4581 4797
 					</div>';
4582 4798
 
4583 4799
 	// Dont any tables so far?
4584
-	if (!empty($upcontext['previous_tables']))
4585
-		foreach ($upcontext['previous_tables'] as $table)
4800
+	if (!empty($upcontext['previous_tables'])) {
4801
+			foreach ($upcontext['previous_tables'] as $table)
4586 4802
 			echo '
4587 4803
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4804
+	}
4588 4805
 
4589 4806
 	echo '
4590 4807
 					<h3 id="current_tab">
@@ -4593,9 +4810,10 @@  discard block
 block discarded – undo
4593 4810
 					<p id="commess" style="display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</p>';
4594 4811
 
4595 4812
 	// Try to make sure substep was reset.
4596
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4597
-		echo '
4813
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4814
+			echo '
4598 4815
 					<input type="hidden" name="substep" id="substep" value="0">';
4816
+	}
4599 4817
 
4600 4818
 	// Continue please!
4601 4819
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4628,12 +4846,13 @@  discard block
 block discarded – undo
4628 4846
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4629 4847
 
4630 4848
 		// If debug flood the screen.
4631
-		if ($is_debug)
4632
-			echo '
4849
+		if ($is_debug) {
4850
+					echo '
4633 4851
 							setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4634 4852
 
4635 4853
 							if (document.getElementById(\'debug_section\').scrollHeight)
4636 4854
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4855
+		}
4637 4856
 
4638 4857
 		echo '
4639 4858
 							// Get the next update...
@@ -4669,8 +4888,8 @@  discard block
 block discarded – undo
4669 4888
 				<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4670 4889
 				<form action="', $boardurl, '/index.php">';
4671 4890
 
4672
-	if (!empty($upcontext['can_delete_script']))
4673
-		echo '
4891
+	if (!empty($upcontext['can_delete_script'])) {
4892
+			echo '
4674 4893
 					<label>
4675 4894
 						<input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '
4676 4895
 					</label>
@@ -4684,6 +4903,7 @@  discard block
 block discarded – undo
4684 4903
 						}
4685 4904
 					</script>
4686 4905
 					<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4906
+	}
4687 4907
 
4688 4908
 	// Show Upgrade time in debug mode when we completed the upgrade process totatly
4689 4909
 	if ($is_debug)
@@ -4693,12 +4913,13 @@  discard block
 block discarded – undo
4693 4913
 		$minutes = intval(($active / 60) % 60);
4694 4914
 		$seconds = intval($active % 60);
4695 4915
 
4696
-		if ($hours > 0)
4697
-			echo '', sprintf($txt['upgrade_completed_time_hms'], $seconds, $minutes, $hours), '';
4698
-		elseif ($minutes > 0)
4699
-			echo '', sprintf($txt['upgrade_completed_time_ms'], $seconds, $minutes), '';
4700
-		elseif ($seconds > 0)
4701
-			echo '', sprintf($txt['upgrade_completed_time_s'], $seconds), '';
4916
+		if ($hours > 0) {
4917
+					echo '', sprintf($txt['upgrade_completed_time_hms'], $seconds, $minutes, $hours), '';
4918
+		} elseif ($minutes > 0) {
4919
+					echo '', sprintf($txt['upgrade_completed_time_ms'], $seconds, $minutes), '';
4920
+		} elseif ($seconds > 0) {
4921
+					echo '', sprintf($txt['upgrade_completed_time_s'], $seconds), '';
4922
+		}
4702 4923
 	}
4703 4924
 
4704 4925
 	echo '
@@ -4728,8 +4949,9 @@  discard block
 block discarded – undo
4728 4949
 
4729 4950
 	$current_substep = $_GET['substep'];
4730 4951
 
4731
-	if (empty($_GET['a']))
4732
-		$_GET['a'] = 0;
4952
+	if (empty($_GET['a'])) {
4953
+			$_GET['a'] = 0;
4954
+	}
4733 4955
 	$step_progress['name'] = 'Converting ips';
4734 4956
 	$step_progress['current'] = $_GET['a'];
4735 4957
 
@@ -4772,16 +4994,19 @@  discard block
 block discarded – undo
4772 4994
 				'empty' => '',
4773 4995
 				'limit' => $limit,
4774 4996
 		));
4775
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4776
-			$arIp[] = $row[$oldCol];
4997
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4998
+					$arIp[] = $row[$oldCol];
4999
+		}
4777 5000
 		$smcFunc['db_free_result']($request);
4778 5001
 
4779 5002
 		// Special case, null ip could keep us in a loop.
4780
-		if (is_null($arIp[0]))
4781
-			unset($arIp[0]);
5003
+		if (is_null($arIp[0])) {
5004
+					unset($arIp[0]);
5005
+		}
4782 5006
 
4783
-		if (empty($arIp))
4784
-			$is_done = true;
5007
+		if (empty($arIp)) {
5008
+					$is_done = true;
5009
+		}
4785 5010
 
4786 5011
 		$updates = array();
4787 5012
 		$cases = array();
@@ -4790,16 +5015,18 @@  discard block
 block discarded – undo
4790 5015
 		{
4791 5016
 			$arIp[$i] = trim($arIp[$i]);
4792 5017
 
4793
-			if (empty($arIp[$i]))
4794
-				continue;
5018
+			if (empty($arIp[$i])) {
5019
+							continue;
5020
+			}
4795 5021
 
4796 5022
 			$updates['ip' . $i] = $arIp[$i];
4797 5023
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4798 5024
 
4799 5025
 			if ($setSize > 0 && $i % $setSize === 0)
4800 5026
 			{
4801
-				if (count($updates) == 1)
4802
-					continue;
5027
+				if (count($updates) == 1) {
5028
+									continue;
5029
+				}
4803 5030
 
4804 5031
 				$updates['whereSet'] = array_values($updates);
4805 5032
 				$smcFunc['db_query']('', '
@@ -4833,8 +5060,7 @@  discard block
 block discarded – undo
4833 5060
 							'ip' => $ip
4834 5061
 					));
4835 5062
 				}
4836
-			}
4837
-			else
5063
+			} else
4838 5064
 			{
4839 5065
 				$updates['whereSet'] = array_values($updates);
4840 5066
 				$smcFunc['db_query']('', '
@@ -4848,9 +5074,9 @@  discard block
 block discarded – undo
4848 5074
 					$updates
4849 5075
 				);
4850 5076
 			}
5077
+		} else {
5078
+					$is_done = true;
4851 5079
 		}
4852
-		else
4853
-			$is_done = true;
4854 5080
 
4855 5081
 		$_GET['a'] += $limit;
4856 5082
 		$step_progress['current'] = $_GET['a'];
@@ -4876,11 +5102,12 @@  discard block
 block discarded – undo
4876 5102
 
4877 5103
 	$columns = $smcFunc['db_list_columns']($targetTable, true);
4878 5104
 
4879
-	if (isset($columns[$column]))
4880
-		return $columns[$column];
4881
-	else
4882
-		return null;
4883
-}
5105
+	if (isset($columns[$column])) {
5106
+			return $columns[$column];
5107
+	} else {
5108
+			return null;
5109
+	}
5110
+	}
4884 5111
 
4885 5112
 /**
4886 5113
  * Takes the changes to be made during the upgradeOptions step, grabs all known Settings data from Settings.php, then runs
@@ -5154,18 +5381,20 @@  discard block
 block discarded – undo
5154 5381
 		global $$setVar;
5155 5382
 
5156 5383
 		// Find the setting.
5157
-		if ($setType == 'string' || $setType == 'string_fatal')
5158
-			$original[$setVar] = isset($$setVar) ? '\'' . addslashes($$setVar) . '\'' : (strpos('fatal', $setType) ? null : '\'\'');
5159
-		elseif ($setType == 'int' || $setType == 'int_fatal')
5160
-			$original[$setVar] = isset($$setVar) ? (int) $$setVar : (strpos('fatal', $setType) ? null : 0);
5161
-		elseif ($setType == 'bool' || $setType == 'bool_fatal')
5162
-			$original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'false');
5163
-		elseif ($setType == 'null' || $setType == 'null_fatal')
5164
-			$original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'null');
5384
+		if ($setType == 'string' || $setType == 'string_fatal') {
5385
+					$original[$setVar] = isset($$setVar) ? '\'' . addslashes($$setVar) . '\'' : (strpos('fatal', $setType) ? null : '\'\'');
5386
+		} elseif ($setType == 'int' || $setType == 'int_fatal') {
5387
+					$original[$setVar] = isset($$setVar) ? (int) $$setVar : (strpos('fatal', $setType) ? null : 0);
5388
+		} elseif ($setType == 'bool' || $setType == 'bool_fatal') {
5389
+					$original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'false');
5390
+		} elseif ($setType == 'null' || $setType == 'null_fatal') {
5391
+					$original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'null');
5392
+		}
5165 5393
 
5166 5394
 		// Well this isn't good.  Do we fix it or bail?
5167
-		if (is_null($original) && $setType != 'null' && strpos('fatal', $setType) > -1)
5168
-			return throw_error('The upgrader could not copy a setting (' . $setVar . ') from your Settings file.  Unable to migrate your Settings file to a new version.');
5395
+		if (is_null($original) && $setType != 'null' && strpos('fatal', $setType) > -1) {
5396
+					return throw_error('The upgrader could not copy a setting (' . $setVar . ') from your Settings file.  Unable to migrate your Settings file to a new version.');
5397
+		}
5169 5398
 	}
5170 5399
 
5171 5400
 	// Finally, merge the changes with the new ones.
@@ -5173,8 +5402,9 @@  discard block
 block discarded – undo
5173 5402
 	foreach ($changes as $setVar => $value)
5174 5403
 	{
5175 5404
 		// Nothing needed here.
5176
-		if ($setVar != 'upgradeData' && $config_vars[$setVar] == $changes[$setVar])
5177
-			continue;
5405
+		if ($setVar != 'upgradeData' && $config_vars[$setVar] == $changes[$setVar]) {
5406
+					continue;
5407
+		}
5178 5408
 
5179 5409
 		$config_vars[$setVar] = $value;
5180 5410
 	}
@@ -5187,15 +5417,17 @@  discard block
 block discarded – undo
5187 5417
 	$last_settings_change = filemtime($boarddir . '/Settings.php');
5188 5418
 
5189 5419
 	// remove any /r's that made there way in here
5190
-	foreach ($settingsArray as $k => $dummy)
5191
-		$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
5420
+	foreach ($settingsArray as $k => $dummy) {
5421
+			$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
5422
+	}
5192 5423
 
5193 5424
 	// go line by line and see whats changing
5194 5425
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
5195 5426
 	{
5196 5427
 		// Don't trim or bother with it if it's not a variable.
5197
-		if (substr($settingsArray[$i], 0, 1) != '$')
5198
-			continue;
5428
+		if (substr($settingsArray[$i], 0, 1) != '$') {
5429
+					continue;
5430
+		}
5199 5431
 
5200 5432
 		$settingsArray[$i] = trim($settingsArray[$i]) . "\n";
5201 5433
 
@@ -5203,9 +5435,9 @@  discard block
 block discarded – undo
5203 5435
 		foreach ($config_vars as $var => $val)
5204 5436
 		{
5205 5437
 			// be sure someone is not updating db_last_error this with a group
5206
-			if ($var === 'db_last_error')
5207
-				unset($config_vars[$var]);
5208
-			elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
5438
+			if ($var === 'db_last_error') {
5439
+							unset($config_vars[$var]);
5440
+			} elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
5209 5441
 			{
5210 5442
 				$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
5211 5443
 				$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n";
@@ -5216,34 +5448,39 @@  discard block
 block discarded – undo
5216 5448
 		}
5217 5449
 
5218 5450
 		// End of the file ... maybe
5219
-		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>')
5220
-			$end = $i;
5451
+		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') {
5452
+					$end = $i;
5453
+		}
5221 5454
 	}
5222 5455
 
5223 5456
 	// This should never happen, but apparently it is happening.
5224
-	if (empty($end) || $end < 10)
5225
-		$end = count($settingsArray) - 1;
5457
+	if (empty($end) || $end < 10) {
5458
+			$end = count($settingsArray) - 1;
5459
+	}
5226 5460
 
5227 5461
 	// Still more variables to go?  Then lets add them at the end.
5228 5462
 	if (!empty($config_vars))
5229 5463
 	{
5230
-		if (trim($settingsArray[$end]) == '?' . '>')
5231
-			$settingsArray[$end++] = '';
5232
-		else
5233
-			$end++;
5464
+		if (trim($settingsArray[$end]) == '?' . '>') {
5465
+					$settingsArray[$end++] = '';
5466
+		} else {
5467
+					$end++;
5468
+		}
5234 5469
 
5235 5470
 		// Add in any newly defined vars that were passed
5236
-		foreach ($config_vars as $var => $val)
5237
-			$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
5471
+		foreach ($config_vars as $var => $val) {
5472
+					$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
5473
+		}
5238 5474
 
5239 5475
 		$settingsArray[$end] = '?' . '>';
5476
+	} else {
5477
+			$settingsArray[$end] = trim($settingsArray[$end]);
5240 5478
 	}
5241
-	else
5242
-		$settingsArray[$end] = trim($settingsArray[$end]);
5243 5479
 
5244 5480
 	// Sanity error checking: the file needs to be at least 12 lines.
5245
-	if (count($settingsArray) < 12)
5246
-		return throw_error('The upgrader could not process your Settings file for updates.  Unable to migrate your Settings file to a new version.');
5481
+	if (count($settingsArray) < 12) {
5482
+			return throw_error('The upgrader could not process your Settings file for updates.  Unable to migrate your Settings file to a new version.');
5483
+	}
5247 5484
 
5248 5485
 	// Try to avoid a few pitfalls:
5249 5486
 	//  - like a possible race condition,
@@ -5251,8 +5488,9 @@  discard block
 block discarded – undo
5251 5488
 	//
5252 5489
 	// Check before you act: if cache is enabled, we can do a simple write test
5253 5490
 	// to validate that we even write things on this filesystem.
5254
-	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
5255
-		$cachedir = $boarddir . '/cache';
5491
+	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
5492
+			$cachedir = $boarddir . '/cache';
5493
+	}
5256 5494
 
5257 5495
 	$test_fp = @fopen($cachedir . '/settings_update.tmp', "w+");
5258 5496
 	if ($test_fp)
@@ -5263,8 +5501,9 @@  discard block
 block discarded – undo
5263 5501
 
5264 5502
 		// Oops. Low disk space, perhaps. Don't mess with Settings.php then.
5265 5503
 		// No means no. :P
5266
-		if ($written_bytes !== 4)
5267
-			return throw_error('The upgrader could not write a test file, perhaps not enough storage?  Unable to migrate your Settings file to a new version.');
5504
+		if ($written_bytes !== 4) {
5505
+					return throw_error('The upgrader could not write a test file, perhaps not enough storage?  Unable to migrate your Settings file to a new version.');
5506
+		}
5268 5507
 	}
5269 5508
 
5270 5509
 	// Protect me from what I want! :P
@@ -5282,8 +5521,9 @@  discard block
 block discarded – undo
5282 5521
 		// survey says ...
5283 5522
 		if ($written_bytes !== strlen($write_settings) && !$settings_backup_fail)
5284 5523
 		{
5285
-			if (file_exists($boarddir . '/Settings_bak.php'))
5286
-				@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
5524
+			if (file_exists($boarddir . '/Settings_bak.php')) {
5525
+							@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
5526
+			}
5287 5527
 
5288 5528
 			return throw_error('The upgrader detected a bad Settings file and reverted the changes.  Unable to migrate your Settings file to a new version.');
5289 5529
 		}
@@ -5291,9 +5531,10 @@  discard block
 block discarded – undo
5291 5531
 
5292 5532
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
5293 5533
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
5294
-	if (function_exists('opcache_invalidate'))
5295
-		opcache_invalidate($boarddir . '/Settings.php', true);
5296
-}
5534
+	if (function_exists('opcache_invalidate')) {
5535
+			opcache_invalidate($boarddir . '/Settings.php', true);
5536
+	}
5537
+	}
5297 5538
 
5298 5539
 /**
5299 5540
  * Determine if we should auto select the migrate Settings file.  This is determined by a variety of missing settings.
@@ -5310,23 +5551,27 @@  discard block
 block discarded – undo
5310 5551
 	global $boarddir, $packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled, $db_show_debug;
5311 5552
 
5312 5553
 	// We should not migrate if db_show_debug is in there, some dev stuff going on here.
5313
-	if (isset($db_show_debug))
5314
-		return false;
5554
+	if (isset($db_show_debug)) {
5555
+			return false;
5556
+	}
5315 5557
 
5316 5558
 	$file_contents = file_get_contents($boarddir . '/Settings.php');
5317 5559
 
5318 5560
 	// Is there a include statement somewhere in there? Some advanced handling of the variables elsewhere?
5319 5561
 	// Try our best to stay away from the cachedir match.
5320
-	if (preg_match('~\sinclude\((?:(?!\(isset\(\$cachedir))~im', $file_contents))
5321
-		return false;
5562
+	if (preg_match('~\sinclude\((?:(?!\(isset\(\$cachedir))~im', $file_contents)) {
5563
+			return false;
5564
+	}
5322 5565
 
5323 5566
 	// If we find a mention of $GLOBALS, there may be a integration going on.
5324
-	if (preg_match('~\$GLOBALS\[~im', $file_contents))
5325
-		return false;
5567
+	if (preg_match('~\$GLOBALS\[~im', $file_contents)) {
5568
+			return false;
5569
+	}
5326 5570
 
5327 5571
 	// If these are not set, it makes us a canidate to migrate.
5328
-	if (!isset($packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled))
5329
-		return true;
5572
+	if (!isset($packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled)) {
5573
+			return true;
5574
+	}
5330 5575
 
5331 5576
 	return false;
5332 5577
 }
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +154 added lines, -121 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
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -98,23 +102,26 @@  discard block
 block discarded – undo
98 102
 	if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest'])
99 103
 	{
100 104
 		// First check for 2.1 json-format cookie in $_COOKIE
101
-		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1)
102
-			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
105
+		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) {
106
+					list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
107
+		}
103 108
 
104 109
 		// Try checking for 2.1 json-format cookie in $_SESSION
105
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1)
106
-			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
110
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) {
111
+					list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
112
+		}
107 113
 
108 114
 		// Next, try checking for 2.0 serialized string cookie in $_COOKIE
109
-		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1)
110
-			list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
115
+		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) {
116
+					list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
117
+		}
111 118
 
112 119
 		// Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION
113
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1)
114
-			list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
115
-
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
120
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) {
121
+					list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
122
+		} else {
123
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
124
+		}
118 125
 
119 126
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 127
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -134,24 +141,23 @@  discard block
 block discarded – undo
134 141
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
135 142
 	{
136 143
 		// Strike!  You're outta there!
137
-		if ($_GET['member'] != $user_info['id'])
138
-			fatal_lang_error('login_cookie_error', false);
144
+		if ($_GET['member'] != $user_info['id']) {
145
+					fatal_lang_error('login_cookie_error', false);
146
+		}
139 147
 
140 148
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
141 149
 
142 150
 		// Some whitelisting for login_url...
143
-		if (empty($_SESSION['login_url']))
144
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
145
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
151
+		if (empty($_SESSION['login_url'])) {
152
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
153
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
146 154
 		{
147 155
 			unset ($_SESSION['login_url']);
148 156
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
149
-		}
150
-		elseif (!empty($user_settings['tfa_secret']))
157
+		} elseif (!empty($user_settings['tfa_secret']))
151 158
 		{
152 159
 			redirectexit('action=logintfa');
153
-		}
154
-		else
160
+		} else
155 161
 		{
156 162
 			// Best not to clutter the session data too much...
157 163
 			$temp = $_SESSION['login_url'];
@@ -162,8 +168,9 @@  discard block
 block discarded – undo
162 168
 	}
163 169
 
164 170
 	// Beyond this point you are assumed to be a guest trying to login.
165
-	if (!$user_info['is_guest'])
166
-		redirectexit();
171
+	if (!$user_info['is_guest']) {
172
+			redirectexit();
173
+	}
167 174
 
168 175
 	// Are you guessing with a script?
169 176
 	checkSession();
@@ -171,18 +178,21 @@  discard block
 block discarded – undo
171 178
 	spamProtection('login');
172 179
 
173 180
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
174
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
175
-		$_SESSION['login_url'] = $_SESSION['old_url'];
181
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
182
+			$_SESSION['login_url'] = $_SESSION['old_url'];
183
+	}
176 184
 
177 185
 	// Been guessing a lot, haven't we?
178
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
179
-		fatal_lang_error('login_threshold_fail', 'login');
186
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
187
+			fatal_lang_error('login_threshold_fail', 'login');
188
+	}
180 189
 
181 190
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
182
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
183
-		$modSettings['cookieTime'] = 3153600;
184
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600))
185
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
191
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
192
+			$modSettings['cookieTime'] = 3153600;
193
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600)) {
194
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
195
+	}
186 196
 
187 197
 	loadLanguage('Login');
188 198
 	// Load the template stuff.
@@ -302,8 +312,9 @@  discard block
 block discarded – undo
302 312
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
303 313
 
304 314
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
305
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
306
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
315
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
316
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
317
+			}
307 318
 
308 319
 			// phpBB3 users new hashing.  We now support it as well ;).
309 320
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -323,27 +334,29 @@  discard block
 block discarded – undo
323 334
 			// Some common md5 ones.
324 335
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
325 336
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
326
-		}
327
-		elseif (strlen($user_settings['passwd']) == 40)
337
+		} elseif (strlen($user_settings['passwd']) == 40)
328 338
 		{
329 339
 			// Maybe they are using a hash from before the password fix.
330 340
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
331 341
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
332 342
 
333 343
 			// BurningBoard3 style of hashing.
334
-			if (!empty($modSettings['enable_password_conversion']))
335
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
344
+			if (!empty($modSettings['enable_password_conversion'])) {
345
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
346
+			}
336 347
 
337 348
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
338 349
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
339 350
 			{
340 351
 				// Try iconv first, for no particular reason.
341
-				if (function_exists('iconv'))
342
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
352
+				if (function_exists('iconv')) {
353
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
354
+				}
343 355
 
344 356
 				// Say it aint so, iconv failed!
345
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
346
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
357
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
358
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
359
+				}
347 360
 			}
348 361
 		}
349 362
 
@@ -373,8 +386,9 @@  discard block
 block discarded – undo
373 386
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
374 387
 
375 388
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
376
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
377
-				redirectexit('action=reminder');
389
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
390
+							redirectexit('action=reminder');
391
+			}
378 392
 			// We'll give you another chance...
379 393
 			else
380 394
 			{
@@ -385,8 +399,7 @@  discard block
 block discarded – undo
385 399
 				return;
386 400
 			}
387 401
 		}
388
-	}
389
-	elseif (!empty($user_settings['passwd_flood']))
402
+	} elseif (!empty($user_settings['passwd_flood']))
390 403
 	{
391 404
 		// Let's be sure they weren't a little hacker.
392 405
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -403,8 +416,9 @@  discard block
 block discarded – undo
403 416
 	}
404 417
 
405 418
 	// Check their activation status.
406
-	if (!checkActivation())
407
-		return;
419
+	if (!checkActivation()) {
420
+			return;
421
+	}
408 422
 
409 423
 	DoLogin();
410 424
 }
@@ -416,8 +430,9 @@  discard block
 block discarded – undo
416 430
 {
417 431
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
418 432
 
419
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
420
-		fatal_lang_error('no_access', false);
433
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
434
+			fatal_lang_error('no_access', false);
435
+	}
421 436
 
422 437
 	loadLanguage('Profile');
423 438
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -425,8 +440,9 @@  discard block
 block discarded – undo
425 440
 	$member = $context['tfa_member'];
426 441
 
427 442
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
428
-	if (time() - $member['last_login'] < 120)
429
-		fatal_lang_error('tfa_wait', false);
443
+	if (time() - $member['last_login'] < 120) {
444
+			fatal_lang_error('tfa_wait', false);
445
+	}
430 446
 
431 447
 	$totp = new \TOTP\Auth($member['tfa_secret']);
432 448
 	$totp->setRange(1);
@@ -440,8 +456,9 @@  discard block
 block discarded – undo
440 456
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
441 457
 	{
442 458
 		// Check to ensure we're forcing SSL for authentication
443
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
444
-			fatal_lang_error('login_ssl_required');
459
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
460
+					fatal_lang_error('login_ssl_required');
461
+		}
445 462
 
446 463
 		$code = $_POST['tfa_code'];
447 464
 
@@ -451,20 +468,19 @@  discard block
 block discarded – undo
451 468
 
452 469
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
453 470
 			redirectexit();
454
-		}
455
-		else
471
+		} else
456 472
 		{
457 473
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
458 474
 
459 475
 			$context['tfa_error'] = true;
460 476
 			$context['tfa_value'] = $_POST['tfa_code'];
461 477
 		}
462
-	}
463
-	elseif (!empty($_POST['tfa_backup']))
478
+	} elseif (!empty($_POST['tfa_backup']))
464 479
 	{
465 480
 		// Check to ensure we're forcing SSL for authentication
466
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
467
-			fatal_lang_error('login_ssl_required');
481
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
482
+					fatal_lang_error('login_ssl_required');
483
+		}
468 484
 
469 485
 		$backup = $_POST['tfa_backup'];
470 486
 
@@ -478,8 +494,7 @@  discard block
 block discarded – undo
478 494
 			));
479 495
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
480 496
 			redirectexit('action=profile;area=tfasetup;backup');
481
-		}
482
-		else
497
+		} else
483 498
 		{
484 499
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
485 500
 
@@ -502,8 +517,9 @@  discard block
 block discarded – undo
502 517
 {
503 518
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
504 519
 
505
-	if (!isset($context['login_errors']))
506
-		$context['login_errors'] = array();
520
+	if (!isset($context['login_errors'])) {
521
+			$context['login_errors'] = array();
522
+	}
507 523
 
508 524
 	// What is the true activation status of this account?
509 525
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -515,8 +531,9 @@  discard block
 block discarded – undo
515 531
 		return false;
516 532
 	}
517 533
 	// Awaiting approval still?
518
-	elseif ($activation_status == 3)
519
-		fatal_lang_error('still_awaiting_approval', 'user');
534
+	elseif ($activation_status == 3) {
535
+			fatal_lang_error('still_awaiting_approval', 'user');
536
+	}
520 537
 	// Awaiting deletion, changed their mind?
521 538
 	elseif ($activation_status == 4)
522 539
 	{
@@ -524,8 +541,7 @@  discard block
 block discarded – undo
524 541
 		{
525 542
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
526 543
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
527
-		}
528
-		else
544
+		} else
529 545
 		{
530 546
 			$context['disable_login_hashing'] = true;
531 547
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -565,8 +581,9 @@  discard block
 block discarded – undo
565 581
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
566 582
 
567 583
 	// Reset the login threshold.
568
-	if (isset($_SESSION['failed_login']))
569
-		unset($_SESSION['failed_login']);
584
+	if (isset($_SESSION['failed_login'])) {
585
+			unset($_SESSION['failed_login']);
586
+	}
570 587
 
571 588
 	$user_info['is_guest'] = false;
572 589
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -588,16 +605,18 @@  discard block
 block discarded – undo
588 605
 			'id_member' => $user_info['id'],
589 606
 		)
590 607
 	);
591
-	if ($smcFunc['db_num_rows']($request) == 1)
592
-		$_SESSION['first_login'] = true;
593
-	else
594
-		unset($_SESSION['first_login']);
608
+	if ($smcFunc['db_num_rows']($request) == 1) {
609
+			$_SESSION['first_login'] = true;
610
+	} else {
611
+			unset($_SESSION['first_login']);
612
+	}
595 613
 	$smcFunc['db_free_result']($request);
596 614
 
597 615
 	// You've logged in, haven't you?
598 616
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
599
-	if (empty($user_settings['tfa_secret']))
600
-		$update['last_login'] = time();
617
+	if (empty($user_settings['tfa_secret'])) {
618
+			$update['last_login'] = time();
619
+	}
601 620
 	updateMemberData($user_info['id'], $update);
602 621
 
603 622
 	// Get rid of the online entry for that old guest....
@@ -611,8 +630,8 @@  discard block
 block discarded – undo
611 630
 	$_SESSION['log_time'] = 0;
612 631
 
613 632
 	// Log this entry, only if we have it enabled.
614
-	if (!empty($modSettings['loginHistoryDays']))
615
-		$smcFunc['db_insert']('insert',
633
+	if (!empty($modSettings['loginHistoryDays'])) {
634
+			$smcFunc['db_insert']('insert',
616 635
 			'{db_prefix}member_logins',
617 636
 			array(
618 637
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -624,13 +643,15 @@  discard block
 block discarded – undo
624 643
 				'id_member', 'time'
625 644
 			)
626 645
 		);
646
+	}
627 647
 
628 648
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
629
-	if (empty($maintenance) || allowedTo('admin_forum'))
630
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
631
-	else
632
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
633
-}
649
+	if (empty($maintenance) || allowedTo('admin_forum')) {
650
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
651
+	} else {
652
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
653
+	}
654
+	}
634 655
 
635 656
 /**
636 657
  * Logs the current user out of their account.
@@ -646,13 +667,15 @@  discard block
 block discarded – undo
646 667
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
647 668
 
648 669
 	// Make sure they aren't being auto-logged out.
649
-	if (!$internal)
650
-		checkSession('get');
670
+	if (!$internal) {
671
+			checkSession('get');
672
+	}
651 673
 
652 674
 	require_once($sourcedir . '/Subs-Auth.php');
653 675
 
654
-	if (isset($_SESSION['pack_ftp']))
655
-		$_SESSION['pack_ftp'] = null;
676
+	if (isset($_SESSION['pack_ftp'])) {
677
+			$_SESSION['pack_ftp'] = null;
678
+	}
656 679
 
657 680
 	// It won't be first login anymore.
658 681
 	unset($_SESSION['first_login']);
@@ -680,8 +703,9 @@  discard block
 block discarded – undo
680 703
 
681 704
 	// And some other housekeeping while we're at it.
682 705
 	$salt = substr(md5(mt_rand()), 0, 4);
683
-	if (!empty($user_info['id']))
684
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
706
+	if (!empty($user_info['id'])) {
707
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
708
+	}
685 709
 
686 710
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
687 711
 	{
@@ -694,14 +718,13 @@  discard block
 block discarded – undo
694 718
 	// Off to the merry board index we go!
695 719
 	if ($redirect)
696 720
 	{
697
-		if (empty($_SESSION['logout_url']))
698
-			redirectexit('', $context['server']['needs_login_fix']);
699
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
721
+		if (empty($_SESSION['logout_url'])) {
722
+					redirectexit('', $context['server']['needs_login_fix']);
723
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
700 724
 		{
701 725
 			unset ($_SESSION['logout_url']);
702 726
 			redirectexit();
703
-		}
704
-		else
727
+		} else
705 728
 		{
706 729
 			$temp = $_SESSION['logout_url'];
707 730
 			unset($_SESSION['logout_url']);
@@ -734,8 +757,9 @@  discard block
 block discarded – undo
734 757
 function phpBB3_password_check($passwd, $passwd_hash)
735 758
 {
736 759
 	// Too long or too short?
737
-	if (strlen($passwd_hash) != 34)
738
-		return;
760
+	if (strlen($passwd_hash) != 34) {
761
+			return;
762
+	}
739 763
 
740 764
 	// Range of characters allowed.
741 765
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -746,8 +770,9 @@  discard block
 block discarded – undo
746 770
 	$salt = substr($passwd_hash, 4, 8);
747 771
 
748 772
 	$hash = md5($salt . $passwd, true);
749
-	for (; $count != 0; --$count)
750
-		$hash = md5($hash . $passwd, true);
773
+	for (; $count != 0; --$count) {
774
+			$hash = md5($hash . $passwd, true);
775
+	}
751 776
 
752 777
 	$output = substr($passwd_hash, 0, 12);
753 778
 	$i = 0;
@@ -756,21 +781,25 @@  discard block
 block discarded – undo
756 781
 		$value = ord($hash[$i++]);
757 782
 		$output .= $range[$value & 0x3f];
758 783
 
759
-		if ($i < 16)
760
-			$value |= ord($hash[$i]) << 8;
784
+		if ($i < 16) {
785
+					$value |= ord($hash[$i]) << 8;
786
+		}
761 787
 
762 788
 		$output .= $range[($value >> 6) & 0x3f];
763 789
 
764
-		if ($i++ >= 16)
765
-			break;
790
+		if ($i++ >= 16) {
791
+					break;
792
+		}
766 793
 
767
-		if ($i < 16)
768
-			$value |= ord($hash[$i]) << 16;
794
+		if ($i < 16) {
795
+					$value |= ord($hash[$i]) << 16;
796
+		}
769 797
 
770 798
 		$output .= $range[($value >> 12) & 0x3f];
771 799
 
772
-		if ($i++ >= 16)
773
-			break;
800
+		if ($i++ >= 16) {
801
+					break;
802
+		}
774 803
 
775 804
 		$output .= $range[($value >> 18) & 0x3f];
776 805
 	}
@@ -802,8 +831,9 @@  discard block
 block discarded – undo
802 831
 		require_once($sourcedir . '/Subs-Auth.php');
803 832
 		setLoginCookie(-3600, 0);
804 833
 
805
-		if (isset($_SESSION['login_' . $cookiename]))
806
-			unset($_SESSION['login_' . $cookiename]);
834
+		if (isset($_SESSION['login_' . $cookiename])) {
835
+					unset($_SESSION['login_' . $cookiename]);
836
+		}
807 837
 	}
808 838
 
809 839
 	// We need a member!
@@ -817,8 +847,9 @@  discard block
 block discarded – undo
817 847
 	}
818 848
 
819 849
 	// Right, have we got a flood value?
820
-	if ($password_flood_value !== false)
821
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
850
+	if ($password_flood_value !== false) {
851
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
852
+	}
822 853
 
823 854
 	// Timestamp or number of tries invalid?
824 855
 	if (empty($number_tries) || empty($time_stamp))
@@ -834,15 +865,17 @@  discard block
 block discarded – undo
834 865
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
835 866
 
836 867
 		// They are trying too fast, make them wait longer
837
-		if ($time_stamp < time() - 10)
838
-			$time_stamp = time();
868
+		if ($time_stamp < time() - 10) {
869
+					$time_stamp = time();
870
+		}
839 871
 	}
840 872
 
841 873
 	$number_tries++;
842 874
 
843 875
 	// Broken the law?
844
-	if ($number_tries > 5)
845
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
876
+	if ($number_tries > 5) {
877
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
878
+	}
846 879
 
847 880
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
848 881
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1477 added lines, -1105 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)',
@@ -1904,12 +1979,13 @@  discard block
 block discarded – undo
1904 1979
 		);
1905 1980
 
1906 1981
 		// Handle legacy bbc codes.
1907
-		foreach ($context['legacy_bbc'] as $bbc)
1908
-			$codes[] = array(
1982
+		foreach ($context['legacy_bbc'] as $bbc) {
1983
+					$codes[] = array(
1909 1984
 				'tag' => $bbc,
1910 1985
 				'before' => '',
1911 1986
 				'after' => '',
1912 1987
 			);
1988
+		}
1913 1989
 
1914 1990
 		// Let mods add new BBC without hassle.
1915 1991
 		call_integration_hook('integrate_bbc_codes', array(&$codes, &$no_autolink_tags));
@@ -1917,8 +1993,9 @@  discard block
 block discarded – undo
1917 1993
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1918 1994
 		if ($message === false)
1919 1995
 		{
1920
-			if (isset($temp_bbc))
1921
-				$bbc_codes = $temp_bbc;
1996
+			if (isset($temp_bbc)) {
1997
+							$bbc_codes = $temp_bbc;
1998
+			}
1922 1999
 			usort($codes, function ($a, $b) {
1923 2000
 				return strcmp($a['tag'], $b['tag']);
1924 2001
 			});
@@ -1938,8 +2015,9 @@  discard block
 block discarded – undo
1938 2015
 		);
1939 2016
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1940 2017
 		{
1941
-			foreach ($itemcodes as $c => $dummy)
1942
-				$bbc_codes[$c] = array();
2018
+			foreach ($itemcodes as $c => $dummy) {
2019
+							$bbc_codes[$c] = array();
2020
+			}
1943 2021
 		}
1944 2022
 
1945 2023
 		// Shhhh!
@@ -1960,12 +2038,14 @@  discard block
 block discarded – undo
1960 2038
 		foreach ($codes as $code)
1961 2039
 		{
1962 2040
 			// Make it easier to process parameters later
1963
-			if (!empty($code['parameters']))
1964
-				ksort($code['parameters'], SORT_STRING);
2041
+			if (!empty($code['parameters'])) {
2042
+							ksort($code['parameters'], SORT_STRING);
2043
+			}
1965 2044
 
1966 2045
 			// If we are not doing every tag only do ones we are interested in.
1967
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1968
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2046
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
2047
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2048
+			}
1969 2049
 		}
1970 2050
 		$codes = null;
1971 2051
 	}
@@ -1976,8 +2056,9 @@  discard block
 block discarded – undo
1976 2056
 		// It's likely this will change if the message is modified.
1977 2057
 		$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']);
1978 2058
 
1979
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1980
-			return $temp;
2059
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
2060
+					return $temp;
2061
+		}
1981 2062
 
1982 2063
 		$cache_t = microtime();
1983 2064
 	}
@@ -2009,8 +2090,9 @@  discard block
 block discarded – undo
2009 2090
 		$disabled['flash'] = true;
2010 2091
 
2011 2092
 		// @todo Change maybe?
2012
-		if (!isset($_GET['images']))
2013
-			$disabled['img'] = true;
2093
+		if (!isset($_GET['images'])) {
2094
+					$disabled['img'] = true;
2095
+		}
2014 2096
 
2015 2097
 		// @todo Interface/setting to add more?
2016 2098
 	}
@@ -2021,8 +2103,9 @@  discard block
 block discarded – undo
2021 2103
 	$alltags = array();
2022 2104
 	foreach ($bbc_codes as $section)
2023 2105
 	{
2024
-		foreach ($section as $code)
2025
-			$alltags[] = $code['tag'];
2106
+		foreach ($section as $code) {
2107
+					$alltags[] = $code['tag'];
2108
+		}
2026 2109
 	}
2027 2110
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
2028 2111
 
@@ -2034,8 +2117,9 @@  discard block
 block discarded – undo
2034 2117
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
2035 2118
 
2036 2119
 		// Failsafe.
2037
-		if ($pos === false || $last_pos > $pos)
2038
-			$pos = strlen($message) + 1;
2120
+		if ($pos === false || $last_pos > $pos) {
2121
+					$pos = strlen($message) + 1;
2122
+		}
2039 2123
 
2040 2124
 		// Can't have a one letter smiley, URL, or email! (sorry.)
2041 2125
 		if ($last_pos < $pos - 1)
@@ -2053,8 +2137,9 @@  discard block
 block discarded – undo
2053 2137
 
2054 2138
 				// <br> should be empty.
2055 2139
 				$empty_tags = array('br', 'hr');
2056
-				foreach ($empty_tags as $tag)
2057
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2140
+				foreach ($empty_tags as $tag) {
2141
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2142
+				}
2058 2143
 
2059 2144
 				// b, u, i, s, pre... basic tags.
2060 2145
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -2063,8 +2148,9 @@  discard block
 block discarded – undo
2063 2148
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
2064 2149
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
2065 2150
 
2066
-					if ($diff > 0)
2067
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2151
+					if ($diff > 0) {
2152
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2153
+					}
2068 2154
 				}
2069 2155
 
2070 2156
 				// Do <img ...> - with security... action= -> action-.
@@ -2077,8 +2163,9 @@  discard block
 block discarded – undo
2077 2163
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
2078 2164
 
2079 2165
 						// Remove action= from the URL - no funny business, now.
2080
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
2081
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2166
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2167
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2168
+						}
2082 2169
 
2083 2170
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
2084 2171
 					}
@@ -2093,16 +2180,18 @@  discard block
 block discarded – undo
2093 2180
 				$no_autolink_area = false;
2094 2181
 				if (!empty($open_tags))
2095 2182
 				{
2096
-					foreach ($open_tags as $open_tag)
2097
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2183
+					foreach ($open_tags as $open_tag) {
2184
+											if (in_array($open_tag['tag'], $no_autolink_tags))
2098 2185
 							$no_autolink_area = true;
2186
+					}
2099 2187
 				}
2100 2188
 
2101 2189
 				// Don't go backwards.
2102 2190
 				// @todo Don't think is the real solution....
2103 2191
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
2104
-				if ($pos < $lastAutoPos)
2105
-					$no_autolink_area = true;
2192
+				if ($pos < $lastAutoPos) {
2193
+									$no_autolink_area = true;
2194
+				}
2106 2195
 				$lastAutoPos = $pos;
2107 2196
 
2108 2197
 				if (!$no_autolink_area)
@@ -2207,29 +2296,33 @@  discard block
 block discarded – undo
2207 2296
 							$url = array_shift($matches);
2208 2297
 
2209 2298
 							// If this isn't a clean URL, bail out
2210
-							if ($url != sanitize_iri($url))
2211
-								return $url;
2299
+							if ($url != sanitize_iri($url)) {
2300
+															return $url;
2301
+							}
2212 2302
 
2213 2303
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2214 2304
 
2215 2305
 							if ($scheme == 'mailto')
2216 2306
 							{
2217 2307
 								$email_address = str_replace('mailto:', '', $url);
2218
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2219
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2220
-								else
2221
-									return $url;
2308
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2309
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2310
+								} else {
2311
+																	return $url;
2312
+								}
2222 2313
 							}
2223 2314
 
2224 2315
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2225
-							if (empty($scheme))
2226
-								$fullUrl = '//' . ltrim($url, ':/');
2227
-							else
2228
-								$fullUrl = $url;
2316
+							if (empty($scheme)) {
2317
+															$fullUrl = '//' . ltrim($url, ':/');
2318
+							} else {
2319
+															$fullUrl = $url;
2320
+							}
2229 2321
 
2230 2322
 							// Make sure that $fullUrl really is valid
2231
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2232
-								return $url;
2323
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2324
+															return $url;
2325
+							}
2233 2326
 
2234 2327
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2235 2328
 						}, $data);
@@ -2278,22 +2371,25 @@  discard block
 block discarded – undo
2278 2371
 		}
2279 2372
 
2280 2373
 		// Are we there yet?  Are we there yet?
2281
-		if ($pos >= strlen($message) - 1)
2282
-			break;
2374
+		if ($pos >= strlen($message) - 1) {
2375
+					break;
2376
+		}
2283 2377
 
2284 2378
 		$tags = strtolower($message[$pos + 1]);
2285 2379
 
2286 2380
 		if ($tags == '/' && !empty($open_tags))
2287 2381
 		{
2288 2382
 			$pos2 = strpos($message, ']', $pos + 1);
2289
-			if ($pos2 == $pos + 2)
2290
-				continue;
2383
+			if ($pos2 == $pos + 2) {
2384
+							continue;
2385
+			}
2291 2386
 
2292 2387
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2293 2388
 
2294 2389
 			// A closing tag that doesn't match any open tags? Skip it.
2295
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2296
-				continue;
2390
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2391
+							continue;
2392
+			}
2297 2393
 
2298 2394
 			$to_close = array();
2299 2395
 			$block_level = null;
@@ -2301,8 +2397,9 @@  discard block
 block discarded – undo
2301 2397
 			do
2302 2398
 			{
2303 2399
 				$tag = array_pop($open_tags);
2304
-				if (!$tag)
2305
-					break;
2400
+				if (!$tag) {
2401
+									break;
2402
+				}
2306 2403
 
2307 2404
 				if (!empty($tag['block_level']))
2308 2405
 				{
@@ -2316,10 +2413,11 @@  discard block
 block discarded – undo
2316 2413
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2317 2414
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2318 2415
 					{
2319
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2320
-							if ($temp['tag'] == $look_for)
2416
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2417
+													if ($temp['tag'] == $look_for)
2321 2418
 							{
2322 2419
 								$block_level = !empty($temp['block_level']);
2420
+						}
2323 2421
 								break;
2324 2422
 							}
2325 2423
 					}
@@ -2341,15 +2439,15 @@  discard block
 block discarded – undo
2341 2439
 			{
2342 2440
 				$open_tags = $to_close;
2343 2441
 				continue;
2344
-			}
2345
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2442
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2346 2443
 			{
2347 2444
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2348 2445
 				{
2349
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2350
-						if ($temp['tag'] == $look_for)
2446
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2447
+											if ($temp['tag'] == $look_for)
2351 2448
 						{
2352 2449
 							$block_level = !empty($temp['block_level']);
2450
+					}
2353 2451
 							break;
2354 2452
 						}
2355 2453
 				}
@@ -2357,8 +2455,9 @@  discard block
 block discarded – undo
2357 2455
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2358 2456
 				if (!$block_level)
2359 2457
 				{
2360
-					foreach ($to_close as $tag)
2361
-						array_push($open_tags, $tag);
2458
+					foreach ($to_close as $tag) {
2459
+											array_push($open_tags, $tag);
2460
+					}
2362 2461
 					continue;
2363 2462
 				}
2364 2463
 			}
@@ -2371,14 +2470,17 @@  discard block
 block discarded – undo
2371 2470
 
2372 2471
 				// See the comment at the end of the big loop - just eating whitespace ;).
2373 2472
 				$whitespace_regex = '';
2374
-				if (!empty($tag['block_level']))
2375
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2473
+				if (!empty($tag['block_level'])) {
2474
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2475
+				}
2376 2476
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2377
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2378
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2477
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2478
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2479
+				}
2379 2480
 
2380
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2381
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2481
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2482
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2483
+				}
2382 2484
 			}
2383 2485
 
2384 2486
 			if (!empty($to_close))
@@ -2391,8 +2493,9 @@  discard block
 block discarded – undo
2391 2493
 		}
2392 2494
 
2393 2495
 		// No tags for this character, so just keep going (fastest possible course.)
2394
-		if (!isset($bbc_codes[$tags]))
2395
-			continue;
2496
+		if (!isset($bbc_codes[$tags])) {
2497
+					continue;
2498
+		}
2396 2499
 
2397 2500
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2398 2501
 		$tag = null;
@@ -2401,48 +2504,57 @@  discard block
 block discarded – undo
2401 2504
 			$pt_strlen = strlen($possible['tag']);
2402 2505
 
2403 2506
 			// Not a match?
2404
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2405
-				continue;
2507
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2508
+							continue;
2509
+			}
2406 2510
 
2407 2511
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2408 2512
 
2409 2513
 			// A tag is the last char maybe
2410
-			if ($next_c == '')
2411
-				break;
2514
+			if ($next_c == '') {
2515
+							break;
2516
+			}
2412 2517
 
2413 2518
 			// A test validation?
2414
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2415
-				continue;
2519
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2520
+							continue;
2521
+			}
2416 2522
 			// Do we want parameters?
2417 2523
 			elseif (!empty($possible['parameters']))
2418 2524
 			{
2419
-				if ($next_c != ' ')
2420
-					continue;
2421
-			}
2422
-			elseif (isset($possible['type']))
2525
+				if ($next_c != ' ') {
2526
+									continue;
2527
+				}
2528
+			} elseif (isset($possible['type']))
2423 2529
 			{
2424 2530
 				// Do we need an equal sign?
2425
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2426
-					continue;
2531
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2532
+									continue;
2533
+				}
2427 2534
 				// Maybe we just want a /...
2428
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2429
-					continue;
2535
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2536
+									continue;
2537
+				}
2430 2538
 				// An immediate ]?
2431
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2432
-					continue;
2539
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2540
+									continue;
2541
+				}
2433 2542
 			}
2434 2543
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2435
-			elseif ($next_c != ']')
2436
-				continue;
2544
+			elseif ($next_c != ']') {
2545
+							continue;
2546
+			}
2437 2547
 
2438 2548
 			// Check allowed tree?
2439
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2440
-				continue;
2441
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2442
-				continue;
2549
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2550
+							continue;
2551
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2552
+							continue;
2553
+			}
2443 2554
 			// If this is in the list of disallowed child tags, don't parse it.
2444
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2445
-				continue;
2555
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2556
+							continue;
2557
+			}
2446 2558
 
2447 2559
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2448 2560
 
@@ -2454,8 +2566,9 @@  discard block
 block discarded – undo
2454 2566
 				foreach ($open_tags as $open_quote)
2455 2567
 				{
2456 2568
 					// Every parent quote this quote has flips the styling
2457
-					if ($open_quote['tag'] == 'quote')
2458
-						$quote_alt = !$quote_alt;
2569
+					if ($open_quote['tag'] == 'quote') {
2570
+											$quote_alt = !$quote_alt;
2571
+					}
2459 2572
 				}
2460 2573
 				// Add a class to the quote to style alternating blockquotes
2461 2574
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2466,8 +2579,9 @@  discard block
 block discarded – undo
2466 2579
 			{
2467 2580
 				// Build a regular expression for each parameter for the current tag.
2468 2581
 				$preg = array();
2469
-				foreach ($possible['parameters'] as $p => $info)
2470
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2582
+				foreach ($possible['parameters'] as $p => $info) {
2583
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2584
+				}
2471 2585
 
2472 2586
 				// Extract the string that potentially holds our parameters.
2473 2587
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2486,24 +2600,27 @@  discard block
 block discarded – undo
2486 2600
 
2487 2601
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2488 2602
 
2489
-					if ($match)
2490
-						$blob_counter = count($blobs) + 1;
2603
+					if ($match) {
2604
+											$blob_counter = count($blobs) + 1;
2605
+					}
2491 2606
 				}
2492 2607
 
2493 2608
 				// Didn't match our parameter list, try the next possible.
2494
-				if (!$match)
2495
-					continue;
2609
+				if (!$match) {
2610
+									continue;
2611
+				}
2496 2612
 
2497 2613
 				$params = array();
2498 2614
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2499 2615
 				{
2500 2616
 					$key = strtok(ltrim($matches[$i]), '=');
2501
-					if (isset($possible['parameters'][$key]['value']))
2502
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2503
-					elseif (isset($possible['parameters'][$key]['validate']))
2504
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2505
-					else
2506
-						$params['{' . $key . '}'] = $matches[$i + 1];
2617
+					if (isset($possible['parameters'][$key]['value'])) {
2618
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2619
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2620
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2621
+					} else {
2622
+											$params['{' . $key . '}'] = $matches[$i + 1];
2623
+					}
2507 2624
 
2508 2625
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2509 2626
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2511,23 +2628,26 @@  discard block
 block discarded – undo
2511 2628
 
2512 2629
 				foreach ($possible['parameters'] as $p => $info)
2513 2630
 				{
2514
-					if (!isset($params['{' . $p . '}']))
2515
-						$params['{' . $p . '}'] = '';
2631
+					if (!isset($params['{' . $p . '}'])) {
2632
+											$params['{' . $p . '}'] = '';
2633
+					}
2516 2634
 				}
2517 2635
 
2518 2636
 				$tag = $possible;
2519 2637
 
2520 2638
 				// Put the parameters into the string.
2521
-				if (isset($tag['before']))
2522
-					$tag['before'] = strtr($tag['before'], $params);
2523
-				if (isset($tag['after']))
2524
-					$tag['after'] = strtr($tag['after'], $params);
2525
-				if (isset($tag['content']))
2526
-					$tag['content'] = strtr($tag['content'], $params);
2639
+				if (isset($tag['before'])) {
2640
+									$tag['before'] = strtr($tag['before'], $params);
2641
+				}
2642
+				if (isset($tag['after'])) {
2643
+									$tag['after'] = strtr($tag['after'], $params);
2644
+				}
2645
+				if (isset($tag['content'])) {
2646
+									$tag['content'] = strtr($tag['content'], $params);
2647
+				}
2527 2648
 
2528 2649
 				$pos1 += strlen($given_param_string);
2529
-			}
2530
-			else
2650
+			} else
2531 2651
 			{
2532 2652
 				$tag = $possible;
2533 2653
 				$params = array();
@@ -2538,8 +2658,9 @@  discard block
 block discarded – undo
2538 2658
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2539 2659
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2540 2660
 		{
2541
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2542
-				continue;
2661
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2662
+							continue;
2663
+			}
2543 2664
 
2544 2665
 			$tag = $itemcodes[$message[$pos + 1]];
2545 2666
 
@@ -2560,9 +2681,9 @@  discard block
 block discarded – undo
2560 2681
 			{
2561 2682
 				array_pop($open_tags);
2562 2683
 				$code = '</li>';
2684
+			} else {
2685
+							$code = '';
2563 2686
 			}
2564
-			else
2565
-				$code = '';
2566 2687
 
2567 2688
 			// Now we open a new tag.
2568 2689
 			$open_tags[] = array(
@@ -2609,12 +2730,14 @@  discard block
 block discarded – undo
2609 2730
 		}
2610 2731
 
2611 2732
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2612
-		if ($tag === null)
2613
-			continue;
2733
+		if ($tag === null) {
2734
+					continue;
2735
+		}
2614 2736
 
2615 2737
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2616
-		if (isset($inside['disallow_children']))
2617
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2738
+		if (isset($inside['disallow_children'])) {
2739
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2740
+		}
2618 2741
 
2619 2742
 		// Is this tag disabled?
2620 2743
 		if (isset($disabled[$tag['tag']]))
@@ -2624,14 +2747,13 @@  discard block
 block discarded – undo
2624 2747
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2625 2748
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2626 2749
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2627
-			}
2628
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2750
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2629 2751
 			{
2630 2752
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2631 2753
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2754
+			} else {
2755
+							$tag['content'] = $tag['disabled_content'];
2632 2756
 			}
2633
-			else
2634
-				$tag['content'] = $tag['disabled_content'];
2635 2757
 		}
2636 2758
 
2637 2759
 		// we use this a lot
@@ -2641,8 +2763,9 @@  discard block
 block discarded – undo
2641 2763
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2642 2764
 		{
2643 2765
 			$n = count($open_tags) - 1;
2644
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2645
-				$n--;
2766
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2767
+							$n--;
2768
+			}
2646 2769
 
2647 2770
 			// Close all the non block level tags so this tag isn't surrounded by them.
2648 2771
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2654,12 +2777,15 @@  discard block
 block discarded – undo
2654 2777
 
2655 2778
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2656 2779
 				$whitespace_regex = '';
2657
-				if (!empty($tag['block_level']))
2658
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2659
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2660
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2661
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2662
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2780
+				if (!empty($tag['block_level'])) {
2781
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2782
+				}
2783
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2784
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2785
+				}
2786
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2787
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2788
+				}
2663 2789
 
2664 2790
 				array_pop($open_tags);
2665 2791
 			}
@@ -2680,16 +2806,19 @@  discard block
 block discarded – undo
2680 2806
 		elseif ($tag['type'] == 'unparsed_content')
2681 2807
 		{
2682 2808
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2683
-			if ($pos2 === false)
2684
-				continue;
2809
+			if ($pos2 === false) {
2810
+							continue;
2811
+			}
2685 2812
 
2686 2813
 			$data = substr($message, $pos1, $pos2 - $pos1);
2687 2814
 
2688
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2689
-				$data = substr($data, 4);
2815
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2816
+							$data = substr($data, 4);
2817
+			}
2690 2818
 
2691
-			if (isset($tag['validate']))
2692
-				$tag['validate']($tag, $data, $disabled, $params);
2819
+			if (isset($tag['validate'])) {
2820
+							$tag['validate']($tag, $data, $disabled, $params);
2821
+			}
2693 2822
 
2694 2823
 			$code = strtr($tag['content'], array('$1' => $data));
2695 2824
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2704,34 +2833,40 @@  discard block
 block discarded – undo
2704 2833
 			if (isset($tag['quoted']))
2705 2834
 			{
2706 2835
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2707
-				if ($tag['quoted'] != 'optional' && !$quoted)
2708
-					continue;
2836
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2837
+									continue;
2838
+				}
2709 2839
 
2710
-				if ($quoted)
2711
-					$pos1 += 6;
2840
+				if ($quoted) {
2841
+									$pos1 += 6;
2842
+				}
2843
+			} else {
2844
+							$quoted = false;
2712 2845
 			}
2713
-			else
2714
-				$quoted = false;
2715 2846
 
2716 2847
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2717
-			if ($pos2 === false)
2718
-				continue;
2848
+			if ($pos2 === false) {
2849
+							continue;
2850
+			}
2719 2851
 
2720 2852
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2721
-			if ($pos3 === false)
2722
-				continue;
2853
+			if ($pos3 === false) {
2854
+							continue;
2855
+			}
2723 2856
 
2724 2857
 			$data = array(
2725 2858
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2726 2859
 				substr($message, $pos1, $pos2 - $pos1)
2727 2860
 			);
2728 2861
 
2729
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2730
-				$data[0] = substr($data[0], 4);
2862
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2863
+							$data[0] = substr($data[0], 4);
2864
+			}
2731 2865
 
2732 2866
 			// Validation for my parking, please!
2733
-			if (isset($tag['validate']))
2734
-				$tag['validate']($tag, $data, $disabled, $params);
2867
+			if (isset($tag['validate'])) {
2868
+							$tag['validate']($tag, $data, $disabled, $params);
2869
+			}
2735 2870
 
2736 2871
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2737 2872
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2748,23 +2883,27 @@  discard block
 block discarded – undo
2748 2883
 		elseif ($tag['type'] == 'unparsed_commas_content')
2749 2884
 		{
2750 2885
 			$pos2 = strpos($message, ']', $pos1);
2751
-			if ($pos2 === false)
2752
-				continue;
2886
+			if ($pos2 === false) {
2887
+							continue;
2888
+			}
2753 2889
 
2754 2890
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2755
-			if ($pos3 === false)
2756
-				continue;
2891
+			if ($pos3 === false) {
2892
+							continue;
2893
+			}
2757 2894
 
2758 2895
 			// We want $1 to be the content, and the rest to be csv.
2759 2896
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2760 2897
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2761 2898
 
2762
-			if (isset($tag['validate']))
2763
-				$tag['validate']($tag, $data, $disabled, $params);
2899
+			if (isset($tag['validate'])) {
2900
+							$tag['validate']($tag, $data, $disabled, $params);
2901
+			}
2764 2902
 
2765 2903
 			$code = $tag['content'];
2766
-			foreach ($data as $k => $d)
2767
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2904
+			foreach ($data as $k => $d) {
2905
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2906
+			}
2768 2907
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2769 2908
 			$pos += strlen($code) - 1 + 2;
2770 2909
 		}
@@ -2772,24 +2911,28 @@  discard block
 block discarded – undo
2772 2911
 		elseif ($tag['type'] == 'unparsed_commas')
2773 2912
 		{
2774 2913
 			$pos2 = strpos($message, ']', $pos1);
2775
-			if ($pos2 === false)
2776
-				continue;
2914
+			if ($pos2 === false) {
2915
+							continue;
2916
+			}
2777 2917
 
2778 2918
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2779 2919
 
2780
-			if (isset($tag['validate']))
2781
-				$tag['validate']($tag, $data, $disabled, $params);
2920
+			if (isset($tag['validate'])) {
2921
+							$tag['validate']($tag, $data, $disabled, $params);
2922
+			}
2782 2923
 
2783 2924
 			// Fix after, for disabled code mainly.
2784
-			foreach ($data as $k => $d)
2785
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2925
+			foreach ($data as $k => $d) {
2926
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2927
+			}
2786 2928
 
2787 2929
 			$open_tags[] = $tag;
2788 2930
 
2789 2931
 			// Replace them out, $1, $2, $3, $4, etc.
2790 2932
 			$code = $tag['before'];
2791
-			foreach ($data as $k => $d)
2792
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2933
+			foreach ($data as $k => $d) {
2934
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2935
+			}
2793 2936
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2794 2937
 			$pos += strlen($code) - 1 + 2;
2795 2938
 		}
@@ -2800,28 +2943,33 @@  discard block
 block discarded – undo
2800 2943
 			if (isset($tag['quoted']))
2801 2944
 			{
2802 2945
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2803
-				if ($tag['quoted'] != 'optional' && !$quoted)
2804
-					continue;
2946
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2947
+									continue;
2948
+				}
2805 2949
 
2806
-				if ($quoted)
2807
-					$pos1 += 6;
2950
+				if ($quoted) {
2951
+									$pos1 += 6;
2952
+				}
2953
+			} else {
2954
+							$quoted = false;
2808 2955
 			}
2809
-			else
2810
-				$quoted = false;
2811 2956
 
2812 2957
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2813
-			if ($pos2 === false)
2814
-				continue;
2958
+			if ($pos2 === false) {
2959
+							continue;
2960
+			}
2815 2961
 
2816 2962
 			$data = substr($message, $pos1, $pos2 - $pos1);
2817 2963
 
2818 2964
 			// Validation for my parking, please!
2819
-			if (isset($tag['validate']))
2820
-				$tag['validate']($tag, $data, $disabled, $params);
2965
+			if (isset($tag['validate'])) {
2966
+							$tag['validate']($tag, $data, $disabled, $params);
2967
+			}
2821 2968
 
2822 2969
 			// For parsed content, we must recurse to avoid security problems.
2823
-			if ($tag['type'] != 'unparsed_equals')
2824
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2970
+			if ($tag['type'] != 'unparsed_equals') {
2971
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2972
+			}
2825 2973
 
2826 2974
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2827 2975
 
@@ -2833,34 +2981,40 @@  discard block
 block discarded – undo
2833 2981
 		}
2834 2982
 
2835 2983
 		// If this is block level, eat any breaks after it.
2836
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2837
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2984
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2985
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2986
+		}
2838 2987
 
2839 2988
 		// Are we trimming outside this tag?
2840
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2841
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2989
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2990
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2991
+		}
2842 2992
 	}
2843 2993
 
2844 2994
 	// Close any remaining tags.
2845
-	while ($tag = array_pop($open_tags))
2846
-		$message .= "\n" . $tag['after'] . "\n";
2995
+	while ($tag = array_pop($open_tags)) {
2996
+			$message .= "\n" . $tag['after'] . "\n";
2997
+	}
2847 2998
 
2848 2999
 	// Parse the smileys within the parts where it can be done safely.
2849 3000
 	if ($smileys === true)
2850 3001
 	{
2851 3002
 		$message_parts = explode("\n", $message);
2852
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2853
-			parsesmileys($message_parts[$i]);
3003
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
3004
+					parsesmileys($message_parts[$i]);
3005
+		}
2854 3006
 
2855 3007
 		$message = implode('', $message_parts);
2856 3008
 	}
2857 3009
 
2858 3010
 	// No smileys, just get rid of the markers.
2859
-	else
2860
-		$message = strtr($message, array("\n" => ''));
3011
+	else {
3012
+			$message = strtr($message, array("\n" => ''));
3013
+	}
2861 3014
 
2862
-	if ($message !== '' && $message[0] === ' ')
2863
-		$message = '&nbsp;' . substr($message, 1);
3015
+	if ($message !== '' && $message[0] === ' ') {
3016
+			$message = '&nbsp;' . substr($message, 1);
3017
+	}
2864 3018
 
2865 3019
 	// Cleanup whitespace.
2866 3020
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2869,15 +3023,16 @@  discard block
 block discarded – undo
2869 3023
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2870 3024
 
2871 3025
 	// Cache the output if it took some time...
2872
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2873
-		cache_put_data($cache_key, $message, 240);
3026
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
3027
+			cache_put_data($cache_key, $message, 240);
3028
+	}
2874 3029
 
2875 3030
 	// If this was a force parse revert if needed.
2876 3031
 	if (!empty($parse_tags))
2877 3032
 	{
2878
-		if (empty($temp_bbc))
2879
-			$bbc_codes = array();
2880
-		else
3033
+		if (empty($temp_bbc)) {
3034
+					$bbc_codes = array();
3035
+		} else
2881 3036
 		{
2882 3037
 			$bbc_codes = $temp_bbc;
2883 3038
 			unset($temp_bbc);
@@ -2904,8 +3059,9 @@  discard block
 block discarded – undo
2904 3059
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2905 3060
 
2906 3061
 	// No smiley set at all?!
2907
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2908
-		return;
3062
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
3063
+			return;
3064
+	}
2909 3065
 
2910 3066
 	// Maybe a mod wants to implement an alternative method (e.g. emojis instead of images)
2911 3067
 	call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements));
@@ -2919,8 +3075,7 @@  discard block
 block discarded – undo
2919 3075
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', 'O:-)');
2920 3076
 			$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');
2921 3077
 			$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'], '', '', '', '');
2922
-		}
2923
-		else
3078
+		} else
2924 3079
 		{
2925 3080
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2926 3081
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2944,9 +3099,9 @@  discard block
 block discarded – undo
2944 3099
 				$smcFunc['db_free_result']($result);
2945 3100
 
2946 3101
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
3102
+			} else {
3103
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2947 3104
 			}
2948
-			else
2949
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2950 3105
 		}
2951 3106
 
2952 3107
 		// The non-breaking-space is a complex thing...
@@ -2968,16 +3123,18 @@  discard block
 block discarded – undo
2968 3123
 				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2969 3124
 				if (!empty($alt_images))
2970 3125
 				{
2971
-					foreach ($exts as $ext)
2972
-						if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
3126
+					foreach ($exts as $ext) {
3127
+											if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
2973 3128
 						{
2974 3129
 							$smileysto[$i] = $fname . '.' . $ext;
3130
+					}
2975 3131
 							break;
2976 3132
 						}
2977 3133
 				}
2978 3134
 				// If we have no image, just leave the text version in place
2979
-				else
2980
-					continue;
3135
+				else {
3136
+									continue;
3137
+				}
2981 3138
 			}
2982 3139
 
2983 3140
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
@@ -3053,12 +3210,14 @@  discard block
 block discarded – undo
3053 3210
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
3054 3211
 
3055 3212
 	// Only use the proxy if enabled and necessary
3056
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
3057
-		return $url;
3213
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3214
+			return $url;
3215
+	}
3058 3216
 
3059 3217
 	// We don't need to proxy our own resources
3060
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
3061
-		return strtr($url, array('http://' => 'https://'));
3218
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3219
+			return strtr($url, array('http://' => 'https://'));
3220
+	}
3062 3221
 
3063 3222
 	// By default, use SMF's own image proxy script
3064 3223
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -3083,35 +3242,41 @@  discard block
 block discarded – undo
3083 3242
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
3084 3243
 
3085 3244
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
3086
-	if (!empty($context['flush_mail']))
3087
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3245
+	if (!empty($context['flush_mail'])) {
3246
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3088 3247
 		AddMailQueue(true);
3248
+	}
3089 3249
 
3090 3250
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
3091 3251
 
3092
-	if ($add)
3093
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3252
+	if ($add) {
3253
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3254
+	}
3094 3255
 
3095 3256
 	// Put the session ID in.
3096
-	if (defined('SID') && SID != '')
3097
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3257
+	if (defined('SID') && SID != '') {
3258
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3259
+	}
3098 3260
 	// Keep that debug in their for template debugging!
3099
-	elseif (isset($_GET['debug']))
3100
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3261
+	elseif (isset($_GET['debug'])) {
3262
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3263
+	}
3101 3264
 
3102 3265
 	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'])))
3103 3266
 	{
3104
-		if (defined('SID') && SID != '')
3105
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3267
+		if (defined('SID') && SID != '') {
3268
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3106 3269
 				function ($m) use ($scripturl)
3107 3270
 				{
3108 3271
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3272
+		}
3109 3273
 				}, $setLocation);
3110
-		else
3111
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3274
+		else {
3275
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3112 3276
 				function ($m) use ($scripturl)
3113 3277
 				{
3114 3278
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3279
+		}
3115 3280
 				}, $setLocation);
3116 3281
 	}
3117 3282
 
@@ -3122,8 +3287,9 @@  discard block
 block discarded – undo
3122 3287
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
3123 3288
 
3124 3289
 	// Debugging.
3125
-	if (isset($db_show_debug) && $db_show_debug === true)
3126
-		$_SESSION['debug_redirect'] = $db_cache;
3290
+	if (isset($db_show_debug) && $db_show_debug === true) {
3291
+			$_SESSION['debug_redirect'] = $db_cache;
3292
+	}
3127 3293
 
3128 3294
 	obExit(false);
3129 3295
 }
@@ -3142,51 +3308,60 @@  discard block
 block discarded – undo
3142 3308
 
3143 3309
 	// Attempt to prevent a recursive loop.
3144 3310
 	++$level;
3145
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
3146
-		exit;
3147
-	if ($from_fatal_error)
3148
-		$has_fatal_error = true;
3311
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3312
+			exit;
3313
+	}
3314
+	if ($from_fatal_error) {
3315
+			$has_fatal_error = true;
3316
+	}
3149 3317
 
3150 3318
 	// Clear out the stat cache.
3151 3319
 	trackStats();
3152 3320
 
3153 3321
 	// If we have mail to send, send it.
3154
-	if (!empty($context['flush_mail']))
3155
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3322
+	if (!empty($context['flush_mail'])) {
3323
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3156 3324
 		AddMailQueue(true);
3325
+	}
3157 3326
 
3158 3327
 	$do_header = $header === null ? !$header_done : $header;
3159
-	if ($do_footer === null)
3160
-		$do_footer = $do_header;
3328
+	if ($do_footer === null) {
3329
+			$do_footer = $do_header;
3330
+	}
3161 3331
 
3162 3332
 	// Has the template/header been done yet?
3163 3333
 	if ($do_header)
3164 3334
 	{
3165 3335
 		// Was the page title set last minute? Also update the HTML safe one.
3166
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
3167
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3336
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3337
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3338
+		}
3168 3339
 
3169 3340
 		// Start up the session URL fixer.
3170 3341
 		ob_start('ob_sessrewrite');
3171 3342
 
3172
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3173
-			$buffers = explode(',', $settings['output_buffers']);
3174
-		elseif (!empty($settings['output_buffers']))
3175
-			$buffers = $settings['output_buffers'];
3176
-		else
3177
-			$buffers = array();
3343
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3344
+					$buffers = explode(',', $settings['output_buffers']);
3345
+		} elseif (!empty($settings['output_buffers'])) {
3346
+					$buffers = $settings['output_buffers'];
3347
+		} else {
3348
+					$buffers = array();
3349
+		}
3178 3350
 
3179
-		if (isset($modSettings['integrate_buffer']))
3180
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3351
+		if (isset($modSettings['integrate_buffer'])) {
3352
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3353
+		}
3181 3354
 
3182
-		if (!empty($buffers))
3183
-			foreach ($buffers as $function)
3355
+		if (!empty($buffers)) {
3356
+					foreach ($buffers as $function)
3184 3357
 			{
3185 3358
 				$call = call_helper($function, true);
3359
+		}
3186 3360
 
3187 3361
 				// Is it valid?
3188
-				if (!empty($call))
3189
-					ob_start($call);
3362
+				if (!empty($call)) {
3363
+									ob_start($call);
3364
+				}
3190 3365
 			}
3191 3366
 
3192 3367
 		// Display the screen in the logical order.
@@ -3198,8 +3373,9 @@  discard block
 block discarded – undo
3198 3373
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3199 3374
 
3200 3375
 		// Anything special to put out?
3201
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3202
-			echo $context['insert_after_template'];
3376
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3377
+					echo $context['insert_after_template'];
3378
+		}
3203 3379
 
3204 3380
 		// Just so we don't get caught in an endless loop of errors from the footer...
3205 3381
 		if (!$footer_done)
@@ -3208,14 +3384,16 @@  discard block
 block discarded – undo
3208 3384
 			template_footer();
3209 3385
 
3210 3386
 			// (since this is just debugging... it's okay that it's after </html>.)
3211
-			if (!isset($_REQUEST['xml']))
3212
-				displayDebug();
3387
+			if (!isset($_REQUEST['xml'])) {
3388
+							displayDebug();
3389
+			}
3213 3390
 		}
3214 3391
 	}
3215 3392
 
3216 3393
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3217
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3218
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3394
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3395
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3396
+	}
3219 3397
 
3220 3398
 	// For session check verification.... don't switch browsers...
3221 3399
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3224,9 +3402,10 @@  discard block
 block discarded – undo
3224 3402
 	call_integration_hook('integrate_exit', array($do_footer));
3225 3403
 
3226 3404
 	// Don't exit if we're coming from index.php; that will pass through normally.
3227
-	if (!$from_index)
3228
-		exit;
3229
-}
3405
+	if (!$from_index) {
3406
+			exit;
3407
+	}
3408
+	}
3230 3409
 
3231 3410
 /**
3232 3411
  * Get the size of a specified image with better error handling.
@@ -3245,8 +3424,9 @@  discard block
 block discarded – undo
3245 3424
 	$url = str_replace(' ', '%20', $url);
3246 3425
 
3247 3426
 	// Can we pull this from the cache... please please?
3248
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3249
-		return $temp;
3427
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3428
+			return $temp;
3429
+	}
3250 3430
 	$t = microtime();
3251 3431
 
3252 3432
 	// Get the host to pester...
@@ -3256,12 +3436,10 @@  discard block
 block discarded – undo
3256 3436
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3257 3437
 	{
3258 3438
 		return false;
3259
-	}
3260
-	elseif (!isset($match[1]))
3439
+	} elseif (!isset($match[1]))
3261 3440
 	{
3262 3441
 		$size = @getimagesize($url);
3263
-	}
3264
-	else
3442
+	} else
3265 3443
 	{
3266 3444
 		// Try to connect to the server... give it half a second.
3267 3445
 		$temp = 0;
@@ -3298,12 +3476,14 @@  discard block
 block discarded – undo
3298 3476
 	}
3299 3477
 
3300 3478
 	// If we didn't get it, we failed.
3301
-	if (!isset($size))
3302
-		$size = false;
3479
+	if (!isset($size)) {
3480
+			$size = false;
3481
+	}
3303 3482
 
3304 3483
 	// If this took a long time, we may never have to do it again, but then again we might...
3305
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3306
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3484
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3485
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3486
+	}
3307 3487
 
3308 3488
 	// Didn't work.
3309 3489
 	return $size;
@@ -3321,8 +3501,9 @@  discard block
 block discarded – undo
3321 3501
 
3322 3502
 	// Under SSI this function can be called more then once.  That can cause some problems.
3323 3503
 	//   So only run the function once unless we are forced to run it again.
3324
-	if ($loaded && !$forceload)
3325
-		return;
3504
+	if ($loaded && !$forceload) {
3505
+			return;
3506
+	}
3326 3507
 
3327 3508
 	$loaded = true;
3328 3509
 
@@ -3334,14 +3515,16 @@  discard block
 block discarded – undo
3334 3515
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3335 3516
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3336 3517
 	{
3337
-		if (trim($context['news_lines'][$i]) == '')
3338
-			continue;
3518
+		if (trim($context['news_lines'][$i]) == '') {
3519
+					continue;
3520
+		}
3339 3521
 
3340 3522
 		// Clean it up for presentation ;).
3341 3523
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3342 3524
 	}
3343
-	if (!empty($context['news_lines']))
3344
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3525
+	if (!empty($context['news_lines'])) {
3526
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3527
+	}
3345 3528
 
3346 3529
 	if (!$user_info['is_guest'])
3347 3530
 	{
@@ -3350,40 +3533,48 @@  discard block
 block discarded – undo
3350 3533
 		$context['user']['alerts'] = &$user_info['alerts'];
3351 3534
 
3352 3535
 		// Personal message popup...
3353
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3354
-			$context['user']['popup_messages'] = true;
3355
-		else
3356
-			$context['user']['popup_messages'] = false;
3536
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3537
+					$context['user']['popup_messages'] = true;
3538
+		} else {
3539
+					$context['user']['popup_messages'] = false;
3540
+		}
3357 3541
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3358 3542
 
3359
-		if (allowedTo('moderate_forum'))
3360
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3543
+		if (allowedTo('moderate_forum')) {
3544
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3545
+		}
3361 3546
 
3362 3547
 		$context['user']['avatar'] = array();
3363 3548
 
3364 3549
 		// Check for gravatar first since we might be forcing them...
3365 3550
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3366 3551
 		{
3367
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3368
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3369
-			else
3370
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3552
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3553
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3554
+			} else {
3555
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3556
+			}
3371 3557
 		}
3372 3558
 		// Uploaded?
3373
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3374
-			$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';
3559
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3560
+					$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';
3561
+		}
3375 3562
 		// Full URL?
3376
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3377
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3563
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3564
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3565
+		}
3378 3566
 		// Otherwise we assume it's server stored.
3379
-		elseif ($user_info['avatar']['url'] != '')
3380
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3567
+		elseif ($user_info['avatar']['url'] != '') {
3568
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3569
+		}
3381 3570
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3382
-		else
3383
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3571
+		else {
3572
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3573
+		}
3384 3574
 
3385
-		if (!empty($context['user']['avatar']))
3386
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3575
+		if (!empty($context['user']['avatar'])) {
3576
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3577
+		}
3387 3578
 
3388 3579
 		// Figure out how long they've been logged in.
3389 3580
 		$context['user']['total_time_logged_in'] = array(
@@ -3391,8 +3582,7 @@  discard block
 block discarded – undo
3391 3582
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3392 3583
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3393 3584
 		);
3394
-	}
3395
-	else
3585
+	} else
3396 3586
 	{
3397 3587
 		$context['user']['messages'] = 0;
3398 3588
 		$context['user']['unread_messages'] = 0;
@@ -3400,12 +3590,14 @@  discard block
 block discarded – undo
3400 3590
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3401 3591
 		$context['user']['popup_messages'] = false;
3402 3592
 
3403
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3404
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3593
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3594
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3595
+		}
3405 3596
 
3406 3597
 		// If we've upgraded recently, go easy on the passwords.
3407
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3408
-			$context['disable_login_hashing'] = true;
3598
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3599
+					$context['disable_login_hashing'] = true;
3600
+		}
3409 3601
 	}
3410 3602
 
3411 3603
 	// Setup the main menu items.
@@ -3418,8 +3610,8 @@  discard block
 block discarded – undo
3418 3610
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3419 3611
 
3420 3612
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3421
-	if ($context['show_pm_popup'])
3422
-		addInlineJavaScript('
3613
+	if ($context['show_pm_popup']) {
3614
+			addInlineJavaScript('
3423 3615
 		jQuery(document).ready(function($) {
3424 3616
 			new smc_Popup({
3425 3617
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3427,24 +3619,28 @@  discard block
 block discarded – undo
3427 3619
 				icon_class: \'generic_icons mail_new\'
3428 3620
 			});
3429 3621
 		});');
3622
+	}
3430 3623
 
3431 3624
 	// Add a generic "Are you sure?" confirmation message.
3432 3625
 	addInlineJavaScript('
3433 3626
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3434 3627
 
3435 3628
 	// Now add the capping code for avatars.
3436
-	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')
3437
-		addInlineCss('
3629
+	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') {
3630
+			addInlineCss('
3438 3631
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3632
+	}
3439 3633
 
3440 3634
 	// Add max image limits
3441
-	if (!empty($modSettings['max_image_width']))
3442
-		addInlineCss('
3635
+	if (!empty($modSettings['max_image_width'])) {
3636
+			addInlineCss('
3443 3637
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3638
+	}
3444 3639
 
3445
-	if (!empty($modSettings['max_image_height']))
3446
-		addInlineCss('
3640
+	if (!empty($modSettings['max_image_height'])) {
3641
+			addInlineCss('
3447 3642
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3643
+	}
3448 3644
 
3449 3645
 	// This looks weird, but it's because BoardIndex.php references the variable.
3450 3646
 	$context['common_stats']['latest_member'] = array(
@@ -3461,11 +3657,13 @@  discard block
 block discarded – undo
3461 3657
 	);
3462 3658
 	$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']);
3463 3659
 
3464
-	if (empty($settings['theme_version']))
3465
-		addJavaScriptVar('smf_scripturl', $scripturl);
3660
+	if (empty($settings['theme_version'])) {
3661
+			addJavaScriptVar('smf_scripturl', $scripturl);
3662
+	}
3466 3663
 
3467
-	if (!isset($context['page_title']))
3468
-		$context['page_title'] = '';
3664
+	if (!isset($context['page_title'])) {
3665
+			$context['page_title'] = '';
3666
+	}
3469 3667
 
3470 3668
 	// Set some specific vars.
3471 3669
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3475,21 +3673,23 @@  discard block
 block discarded – undo
3475 3673
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3476 3674
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3477 3675
 
3478
-	if (!empty($context['meta_keywords']))
3479
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3676
+	if (!empty($context['meta_keywords'])) {
3677
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3678
+	}
3480 3679
 
3481
-	if (!empty($context['canonical_url']))
3482
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3680
+	if (!empty($context['canonical_url'])) {
3681
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3682
+	}
3483 3683
 
3484
-	if (!empty($settings['og_image']))
3485
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3684
+	if (!empty($settings['og_image'])) {
3685
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3686
+	}
3486 3687
 
3487 3688
 	if (!empty($context['meta_description']))
3488 3689
 	{
3489 3690
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3490 3691
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3491
-	}
3492
-	else
3692
+	} else
3493 3693
 	{
3494 3694
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3495 3695
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3514,8 +3714,9 @@  discard block
 block discarded – undo
3514 3714
 	$memory_needed = memoryReturnBytes($needed);
3515 3715
 
3516 3716
 	// should we account for how much is currently being used?
3517
-	if ($in_use)
3518
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3717
+	if ($in_use) {
3718
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3719
+	}
3519 3720
 
3520 3721
 	// if more is needed, request it
3521 3722
 	if ($memory_current < $memory_needed)
@@ -3538,8 +3739,9 @@  discard block
 block discarded – undo
3538 3739
  */
3539 3740
 function memoryReturnBytes($val)
3540 3741
 {
3541
-	if (is_integer($val))
3542
-		return $val;
3742
+	if (is_integer($val)) {
3743
+			return $val;
3744
+	}
3543 3745
 
3544 3746
 	// Separate the number from the designator
3545 3747
 	$val = trim($val);
@@ -3575,10 +3777,11 @@  discard block
 block discarded – undo
3575 3777
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3576 3778
 
3577 3779
 		// Are we debugging the template/html content?
3578
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3579
-			header('content-type: application/xhtml+xml');
3580
-		elseif (!isset($_REQUEST['xml']))
3581
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3780
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3781
+					header('content-type: application/xhtml+xml');
3782
+		} elseif (!isset($_REQUEST['xml'])) {
3783
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3784
+		}
3582 3785
 	}
3583 3786
 
3584 3787
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3587,8 +3790,9 @@  discard block
 block discarded – undo
3587 3790
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3588 3791
 	{
3589 3792
 		$position = array_search('body', $context['template_layers']);
3590
-		if ($position === false)
3591
-			$position = array_search('main', $context['template_layers']);
3793
+		if ($position === false) {
3794
+					$position = array_search('main', $context['template_layers']);
3795
+		}
3592 3796
 
3593 3797
 		if ($position !== false)
3594 3798
 		{
@@ -3616,23 +3820,25 @@  discard block
 block discarded – undo
3616 3820
 
3617 3821
 			foreach ($securityFiles as $i => $securityFile)
3618 3822
 			{
3619
-				if (!file_exists($boarddir . '/' . $securityFile))
3620
-					unset($securityFiles[$i]);
3823
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3824
+									unset($securityFiles[$i]);
3825
+				}
3621 3826
 			}
3622 3827
 
3623 3828
 			// We are already checking so many files...just few more doesn't make any difference! :P
3624
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3625
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3626
-
3627
-			else
3628
-				$path = $modSettings['attachmentUploadDir'];
3829
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3830
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3831
+			} else {
3832
+							$path = $modSettings['attachmentUploadDir'];
3833
+			}
3629 3834
 
3630 3835
 			secureDirectory($path, true);
3631 3836
 			secureDirectory($cachedir);
3632 3837
 
3633 3838
 			// If agreement is enabled, at least the english version shall exists
3634
-			if ($modSettings['requireAgreement'])
3635
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3839
+			if ($modSettings['requireAgreement']) {
3840
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3841
+			}
3636 3842
 
3637 3843
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3638 3844
 			{
@@ -3647,18 +3853,21 @@  discard block
 block discarded – undo
3647 3853
 					echo '
3648 3854
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3649 3855
 
3650
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3651
-						echo '
3856
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3857
+											echo '
3652 3858
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3859
+					}
3653 3860
 				}
3654 3861
 
3655
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3656
-					echo '
3862
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3863
+									echo '
3657 3864
 				<strong>', $txt['cache_writable'], '</strong><br>';
3865
+				}
3658 3866
 
3659
-				if (!empty($agreement))
3660
-					echo '
3867
+				if (!empty($agreement)) {
3868
+									echo '
3661 3869
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3870
+				}
3662 3871
 
3663 3872
 				echo '
3664 3873
 			</p>
@@ -3673,16 +3882,18 @@  discard block
 block discarded – undo
3673 3882
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3674 3883
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3675 3884
 
3676
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3677
-				echo '
3885
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3886
+							echo '
3678 3887
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3888
+			}
3679 3889
 
3680
-			if (!empty($_SESSION['ban']['expire_time']))
3681
-				echo '
3890
+			if (!empty($_SESSION['ban']['expire_time'])) {
3891
+							echo '
3682 3892
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3683
-			else
3684
-				echo '
3893
+			} else {
3894
+							echo '
3685 3895
 					<div>', $txt['your_ban_expires_never'], '</div>';
3896
+			}
3686 3897
 
3687 3898
 			echo '
3688 3899
 				</div>';
@@ -3698,8 +3909,9 @@  discard block
 block discarded – undo
3698 3909
 	global $forum_copyright, $software_year, $forum_version;
3699 3910
 
3700 3911
 	// Don't display copyright for things like SSI.
3701
-	if (!isset($forum_version) || !isset($software_year))
3702
-		return;
3912
+	if (!isset($forum_version) || !isset($software_year)) {
3913
+			return;
3914
+	}
3703 3915
 
3704 3916
 	// Put in the version...
3705 3917
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3717,9 +3929,10 @@  discard block
 block discarded – undo
3717 3929
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3718 3930
 	$context['load_queries'] = $db_count;
3719 3931
 
3720
-	foreach (array_reverse($context['template_layers']) as $layer)
3721
-		loadSubTemplate($layer . '_below', true);
3722
-}
3932
+	foreach (array_reverse($context['template_layers']) as $layer) {
3933
+			loadSubTemplate($layer . '_below', true);
3934
+	}
3935
+	}
3723 3936
 
3724 3937
 /**
3725 3938
  * Output the Javascript files
@@ -3753,8 +3966,7 @@  discard block
 block discarded – undo
3753 3966
 			{
3754 3967
 				echo '
3755 3968
 		var ', $key, ';';
3756
-			}
3757
-			else
3969
+			} else
3758 3970
 			{
3759 3971
 				echo '
3760 3972
 		var ', $key, ' = ', $value, ';';
@@ -3773,27 +3985,29 @@  discard block
 block discarded – undo
3773 3985
 		foreach ($context['javascript_files'] as $id => $js_file)
3774 3986
 		{
3775 3987
 			// Last minute call! allow theme authors to disable single files.
3776
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3777
-				continue;
3988
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3989
+							continue;
3990
+			}
3778 3991
 
3779 3992
 			// By default files don't get minimized unless the file explicitly says so!
3780 3993
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3781 3994
 			{
3782
-				if (!empty($js_file['options']['async']))
3783
-					$toMinify['async'][] = $js_file;
3784
-				elseif (!empty($js_file['options']['defer']))
3785
-					$toMinify['defer'][] = $js_file;
3786
-				else
3787
-					$toMinify['standard'][] = $js_file;
3995
+				if (!empty($js_file['options']['async'])) {
3996
+									$toMinify['async'][] = $js_file;
3997
+				} elseif (!empty($js_file['options']['defer'])) {
3998
+									$toMinify['defer'][] = $js_file;
3999
+				} else {
4000
+									$toMinify['standard'][] = $js_file;
4001
+				}
3788 4002
 
3789 4003
 				// Grab a random seed.
3790
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3791
-					$minSeed = $js_file['options']['seed'];
3792
-			}
3793
-
3794
-			else
3795
-				echo '
4004
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
4005
+									$minSeed = $js_file['options']['seed'];
4006
+				}
4007
+			} else {
4008
+							echo '
3796 4009
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
4010
+			}
3797 4011
 		}
3798 4012
 
3799 4013
 		foreach ($toMinify as $js_files)
@@ -3804,9 +4018,10 @@  discard block
 block discarded – undo
3804 4018
 
3805 4019
 				$minSuccessful = array_keys($result) === array('smf_minified');
3806 4020
 
3807
-				foreach ($result as $minFile)
3808
-					echo '
4021
+				foreach ($result as $minFile) {
4022
+									echo '
3809 4023
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
4024
+				}
3810 4025
 			}
3811 4026
 		}
3812 4027
 	}
@@ -3820,8 +4035,9 @@  discard block
 block discarded – undo
3820 4035
 <script>
3821 4036
 window.addEventListener("DOMContentLoaded", function() {';
3822 4037
 
3823
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3824
-				echo $js_code;
4038
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
4039
+							echo $js_code;
4040
+			}
3825 4041
 
3826 4042
 			echo '
3827 4043
 });
@@ -3833,8 +4049,9 @@  discard block
 block discarded – undo
3833 4049
 			echo '
3834 4050
 	<script>';
3835 4051
 
3836
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3837
-				echo $js_code;
4052
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
4053
+							echo $js_code;
4054
+			}
3838 4055
 
3839 4056
 			echo '
3840 4057
 	</script>';
@@ -3862,23 +4079,26 @@  discard block
 block discarded – undo
3862 4079
 	foreach ($context['css_files'] as $id => $file)
3863 4080
 	{
3864 4081
 		// Last minute call! allow theme authors to disable single files.
3865
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3866
-			continue;
4082
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
4083
+					continue;
4084
+		}
3867 4085
 
3868 4086
 		// Files are minimized unless they explicitly opt out.
3869
-		if (!isset($file['options']['minimize']))
3870
-			$file['options']['minimize'] = true;
4087
+		if (!isset($file['options']['minimize'])) {
4088
+					$file['options']['minimize'] = true;
4089
+		}
3871 4090
 
3872 4091
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3873 4092
 		{
3874 4093
 			$toMinify[] = $file;
3875 4094
 
3876 4095
 			// Grab a random seed.
3877
-			if (!isset($minSeed) && isset($file['options']['seed']))
3878
-				$minSeed = $file['options']['seed'];
4096
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
4097
+							$minSeed = $file['options']['seed'];
4098
+			}
4099
+		} else {
4100
+					$normal[] = $file['fileUrl'];
3879 4101
 		}
3880
-		else
3881
-			$normal[] = $file['fileUrl'];
3882 4102
 	}
3883 4103
 
3884 4104
 	if (!empty($toMinify))
@@ -3887,23 +4107,26 @@  discard block
 block discarded – undo
3887 4107
 
3888 4108
 		$minSuccessful = array_keys($result) === array('smf_minified');
3889 4109
 
3890
-		foreach ($result as $minFile)
3891
-			echo '
4110
+		foreach ($result as $minFile) {
4111
+					echo '
3892 4112
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
4113
+		}
3893 4114
 	}
3894 4115
 
3895 4116
 	// Print the rest after the minified files.
3896
-	if (!empty($normal))
3897
-		foreach ($normal as $nf)
4117
+	if (!empty($normal)) {
4118
+			foreach ($normal as $nf)
3898 4119
 			echo '
3899 4120
 	<link rel="stylesheet" href="', $nf ,'">';
4121
+	}
3900 4122
 
3901 4123
 	if ($db_show_debug === true)
3902 4124
 	{
3903 4125
 		// Try to keep only what's useful.
3904 4126
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3905
-		foreach ($context['css_files'] as $file)
3906
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4127
+		foreach ($context['css_files'] as $file) {
4128
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4129
+		}
3907 4130
 	}
3908 4131
 
3909 4132
 	if (!empty($context['css_header']))
@@ -3911,9 +4134,10 @@  discard block
 block discarded – undo
3911 4134
 		echo '
3912 4135
 	<style>';
3913 4136
 
3914
-		foreach ($context['css_header'] as $css)
3915
-			echo $css .'
4137
+		foreach ($context['css_header'] as $css) {
4138
+					echo $css .'
3916 4139
 	';
4140
+		}
3917 4141
 
3918 4142
 		echo'
3919 4143
 	</style>';
@@ -3936,8 +4160,9 @@  discard block
 block discarded – undo
3936 4160
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3937 4161
 	$data = is_array($data) ? $data : array();
3938 4162
 
3939
-	if (empty($type) || empty($data))
3940
-		return $data;
4163
+	if (empty($type) || empty($data)) {
4164
+			return $data;
4165
+	}
3941 4166
 
3942 4167
 	// Different pages include different files, so we use a hash to label the different combinations
3943 4168
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3946,13 +4171,14 @@  discard block
 block discarded – undo
3946 4171
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3947 4172
 
3948 4173
 	// Already done?
3949
-	if (!empty($toCache))
3950
-		return array('smf_minified' => array(
4174
+	if (!empty($toCache)) {
4175
+			return array('smf_minified' => array(
3951 4176
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3952 4177
 			'filePath' => $toCache,
3953 4178
 			'fileName' => basename($toCache),
3954 4179
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3955 4180
 		));
4181
+	}
3956 4182
 
3957 4183
 
3958 4184
 	// No namespaces, sorry!
@@ -3982,9 +4208,9 @@  discard block
 block discarded – undo
3982 4208
 
3983 4209
 	foreach ($data as $id => $file)
3984 4210
 	{
3985
-		if (empty($file['filePath']))
3986
-			$toAdd = false;
3987
-		else
4211
+		if (empty($file['filePath'])) {
4212
+					$toAdd = false;
4213
+		} else
3988 4214
 		{
3989 4215
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3990 4216
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3992,12 +4218,14 @@  discard block
 block discarded – undo
3992 4218
 		}
3993 4219
 
3994 4220
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3995
-		if (empty($file['options']['async']))
3996
-			$async = false;
4221
+		if (empty($file['options']['async'])) {
4222
+					$async = false;
4223
+		}
3997 4224
 
3998 4225
 		// A minified script should only be deferred if all its components wanted to be.
3999
-		if (empty($file['options']['defer']))
4000
-			$defer = false;
4226
+		if (empty($file['options']['defer'])) {
4227
+					$defer = false;
4228
+		}
4001 4229
 
4002 4230
 		// The file couldn't be located so it won't be added. Log this error.
4003 4231
 		if (empty($toAdd))
@@ -4063,12 +4291,14 @@  discard block
 block discarded – undo
4063 4291
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
4064 4292
 			{
4065 4293
 				// Remove the cache entry
4066
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
4067
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4294
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4295
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4296
+				}
4068 4297
 
4069 4298
 				// Try to delete the file. Add it to our error list if it fails.
4070
-				if (!@unlink($filename))
4071
-					$not_deleted[] = $filename;
4299
+				if (!@unlink($filename)) {
4300
+									$not_deleted[] = $filename;
4301
+				}
4072 4302
 			}
4073 4303
 		}
4074 4304
 	}
@@ -4100,8 +4330,9 @@  discard block
 block discarded – undo
4100 4330
 	global $modSettings, $smcFunc;
4101 4331
 
4102 4332
 	// Just make up a nice hash...
4103
-	if ($new)
4104
-		return sha1(md5($filename . time()) . mt_rand());
4333
+	if ($new) {
4334
+			return sha1(md5($filename . time()) . mt_rand());
4335
+	}
4105 4336
 
4106 4337
 	// Just make sure that attachment id is only a int
4107 4338
 	$attachment_id = (int) $attachment_id;
@@ -4118,23 +4349,25 @@  discard block
 block discarded – undo
4118 4349
 				'id_attach' => $attachment_id,
4119 4350
 			));
4120 4351
 
4121
-		if ($smcFunc['db_num_rows']($request) === 0)
4122
-			return false;
4352
+		if ($smcFunc['db_num_rows']($request) === 0) {
4353
+					return false;
4354
+		}
4123 4355
 
4124 4356
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
4125 4357
 		$smcFunc['db_free_result']($request);
4126 4358
 	}
4127 4359
 
4128 4360
 	// Still no hash? mmm...
4129
-	if (empty($file_hash))
4130
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4361
+	if (empty($file_hash)) {
4362
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4363
+	}
4131 4364
 
4132 4365
 	// Are we using multiple directories?
4133
-	if (is_array($modSettings['attachmentUploadDir']))
4134
-		$path = $modSettings['attachmentUploadDir'][$dir];
4135
-
4136
-	else
4137
-		$path = $modSettings['attachmentUploadDir'];
4366
+	if (is_array($modSettings['attachmentUploadDir'])) {
4367
+			$path = $modSettings['attachmentUploadDir'][$dir];
4368
+	} else {
4369
+			$path = $modSettings['attachmentUploadDir'];
4370
+	}
4138 4371
 
4139 4372
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4140 4373
 }
@@ -4149,8 +4382,9 @@  discard block
 block discarded – undo
4149 4382
 function ip2range($fullip)
4150 4383
 {
4151 4384
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
4152
-	if ($fullip == 'unknown')
4153
-		$fullip = '255.255.255.255';
4385
+	if ($fullip == 'unknown') {
4386
+			$fullip = '255.255.255.255';
4387
+	}
4154 4388
 
4155 4389
 	$ip_parts = explode('-', $fullip);
4156 4390
 	$ip_array = array();
@@ -4174,10 +4408,11 @@  discard block
 block discarded – undo
4174 4408
 		$ip_array['low'] = $ip_parts[0];
4175 4409
 		$ip_array['high'] = $ip_parts[1];
4176 4410
 		return $ip_array;
4177
-	}
4178
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4411
+	} elseif (count($ip_parts) == 2) {
4412
+		// if ip 22.22.*-22.22.*
4179 4413
 	{
4180 4414
 		$valid_low = isValidIP($ip_parts[0]);
4415
+	}
4181 4416
 		$valid_high = isValidIP($ip_parts[1]);
4182 4417
 		$count = 0;
4183 4418
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4192,7 +4427,9 @@  discard block
 block discarded – undo
4192 4427
 				$ip_parts[0] .= $mode . $min;
4193 4428
 				$valid_low = isValidIP($ip_parts[0]);
4194 4429
 				$count++;
4195
-				if ($count > 9) break;
4430
+				if ($count > 9) {
4431
+					break;
4432
+				}
4196 4433
 			}
4197 4434
 		}
4198 4435
 
@@ -4206,7 +4443,9 @@  discard block
 block discarded – undo
4206 4443
 				$ip_parts[1] .= $mode . $max;
4207 4444
 				$valid_high = isValidIP($ip_parts[1]);
4208 4445
 				$count++;
4209
-				if ($count > 9) break;
4446
+				if ($count > 9) {
4447
+					break;
4448
+				}
4210 4449
 			}
4211 4450
 		}
4212 4451
 
@@ -4230,46 +4469,54 @@  discard block
 block discarded – undo
4230 4469
 {
4231 4470
 	global $modSettings;
4232 4471
 
4233
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4234
-		return $host;
4472
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4473
+			return $host;
4474
+	}
4235 4475
 	$t = microtime();
4236 4476
 
4237 4477
 	// Try the Linux host command, perhaps?
4238 4478
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4239 4479
 	{
4240
-		if (!isset($modSettings['host_to_dis']))
4241
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4242
-		else
4243
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4480
+		if (!isset($modSettings['host_to_dis'])) {
4481
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4482
+		} else {
4483
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4484
+		}
4244 4485
 
4245 4486
 		// Did host say it didn't find anything?
4246
-		if (strpos($test, 'not found') !== false)
4247
-			$host = '';
4487
+		if (strpos($test, 'not found') !== false) {
4488
+					$host = '';
4489
+		}
4248 4490
 		// Invalid server option?
4249
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4250
-			updateSettings(array('host_to_dis' => 1));
4491
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4492
+					updateSettings(array('host_to_dis' => 1));
4493
+		}
4251 4494
 		// Maybe it found something, after all?
4252
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4253
-			$host = $match[1];
4495
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4496
+					$host = $match[1];
4497
+		}
4254 4498
 	}
4255 4499
 
4256 4500
 	// This is nslookup; usually only Windows, but possibly some Unix?
4257 4501
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4258 4502
 	{
4259 4503
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4260
-		if (strpos($test, 'Non-existent domain') !== false)
4261
-			$host = '';
4262
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4263
-			$host = $match[1];
4504
+		if (strpos($test, 'Non-existent domain') !== false) {
4505
+					$host = '';
4506
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4507
+					$host = $match[1];
4508
+		}
4264 4509
 	}
4265 4510
 
4266 4511
 	// This is the last try :/.
4267
-	if (!isset($host) || $host === false)
4268
-		$host = @gethostbyaddr($ip);
4512
+	if (!isset($host) || $host === false) {
4513
+			$host = @gethostbyaddr($ip);
4514
+	}
4269 4515
 
4270 4516
 	// It took a long time, so let's cache it!
4271
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4272
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4517
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4518
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4519
+	}
4273 4520
 
4274 4521
 	return $host;
4275 4522
 }
@@ -4305,20 +4552,21 @@  discard block
 block discarded – undo
4305 4552
 			{
4306 4553
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4307 4554
 				$total = 0;
4308
-				for ($i = 0; $i < $max_chars; $i++)
4309
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4555
+				for ($i = 0; $i < $max_chars; $i++) {
4556
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4557
+				}
4310 4558
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4311 4559
 			}
4312 4560
 		}
4313 4561
 		return array_unique($returned_ints);
4314
-	}
4315
-	else
4562
+	} else
4316 4563
 	{
4317 4564
 		// Trim characters before and after and add slashes for database insertion.
4318 4565
 		$returned_words = array();
4319
-		foreach ($words as $word)
4320
-			if (($word = trim($word, '-_\'')) !== '')
4566
+		foreach ($words as $word) {
4567
+					if (($word = trim($word, '-_\'')) !== '')
4321 4568
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4569
+		}
4322 4570
 
4323 4571
 		// Filter out all words that occur more than once.
4324 4572
 		return array_unique($returned_words);
@@ -4340,16 +4588,18 @@  discard block
 block discarded – undo
4340 4588
 	global $settings, $txt;
4341 4589
 
4342 4590
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4343
-	if (function_exists('template_create_button') && !$force_use)
4344
-		return template_create_button($name, $alt, $label = '', $custom = '');
4591
+	if (function_exists('template_create_button') && !$force_use) {
4592
+			return template_create_button($name, $alt, $label = '', $custom = '');
4593
+	}
4345 4594
 
4346
-	if (!$settings['use_image_buttons'])
4347
-		return $txt[$alt];
4348
-	elseif (!empty($settings['use_buttons']))
4349
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4350
-	else
4351
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4352
-}
4595
+	if (!$settings['use_image_buttons']) {
4596
+			return $txt[$alt];
4597
+	} elseif (!empty($settings['use_buttons'])) {
4598
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4599
+	} else {
4600
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4601
+	}
4602
+	}
4353 4603
 
4354 4604
 /**
4355 4605
  * Sets up all of the top menu buttons
@@ -4392,9 +4642,10 @@  discard block
 block discarded – undo
4392 4642
 	var user_menus = new smc_PopupMenu();
4393 4643
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4394 4644
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4395
-		if ($context['allow_pm'])
4396
-			addInlineJavaScript('
4645
+		if ($context['allow_pm']) {
4646
+					addInlineJavaScript('
4397 4647
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4648
+		}
4398 4649
 
4399 4650
 		if (!empty($modSettings['enable_ajax_alerts']))
4400 4651
 		{
@@ -4554,88 +4805,96 @@  discard block
 block discarded – undo
4554 4805
 
4555 4806
 		// Now we put the buttons in the context so the theme can use them.
4556 4807
 		$menu_buttons = array();
4557
-		foreach ($buttons as $act => $button)
4558
-			if (!empty($button['show']))
4808
+		foreach ($buttons as $act => $button) {
4809
+					if (!empty($button['show']))
4559 4810
 			{
4560 4811
 				$button['active_button'] = false;
4812
+		}
4561 4813
 
4562 4814
 				// This button needs some action.
4563
-				if (isset($button['action_hook']))
4564
-					$needs_action_hook = true;
4815
+				if (isset($button['action_hook'])) {
4816
+									$needs_action_hook = true;
4817
+				}
4565 4818
 
4566 4819
 				// Make sure the last button truly is the last button.
4567 4820
 				if (!empty($button['is_last']))
4568 4821
 				{
4569
-					if (isset($last_button))
4570
-						unset($menu_buttons[$last_button]['is_last']);
4822
+					if (isset($last_button)) {
4823
+											unset($menu_buttons[$last_button]['is_last']);
4824
+					}
4571 4825
 					$last_button = $act;
4572 4826
 				}
4573 4827
 
4574 4828
 				// Go through the sub buttons if there are any.
4575
-				if (!empty($button['sub_buttons']))
4576
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4829
+				if (!empty($button['sub_buttons'])) {
4830
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4577 4831
 					{
4578 4832
 						if (empty($subbutton['show']))
4579 4833
 							unset($button['sub_buttons'][$key]);
4834
+				}
4580 4835
 
4581 4836
 						// 2nd level sub buttons next...
4582 4837
 						if (!empty($subbutton['sub_buttons']))
4583 4838
 						{
4584 4839
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4585 4840
 							{
4586
-								if (empty($sub_button2['show']))
4587
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4841
+								if (empty($sub_button2['show'])) {
4842
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4843
+								}
4588 4844
 							}
4589 4845
 						}
4590 4846
 					}
4591 4847
 
4592 4848
 				// Does this button have its own icon?
4593
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4594
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4595
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4596
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4597
-				elseif (isset($button['icon']))
4598
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4599
-				else
4600
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4849
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4850
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4851
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4852
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4853
+				} elseif (isset($button['icon'])) {
4854
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4855
+				} else {
4856
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4857
+				}
4601 4858
 
4602 4859
 				$menu_buttons[$act] = $button;
4603 4860
 			}
4604 4861
 
4605
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4606
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4862
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4863
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4864
+		}
4607 4865
 	}
4608 4866
 
4609 4867
 	$context['menu_buttons'] = $menu_buttons;
4610 4868
 
4611 4869
 	// Logging out requires the session id in the url.
4612
-	if (isset($context['menu_buttons']['logout']))
4613
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4870
+	if (isset($context['menu_buttons']['logout'])) {
4871
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4872
+	}
4614 4873
 
4615 4874
 	// Figure out which action we are doing so we can set the active tab.
4616 4875
 	// Default to home.
4617 4876
 	$current_action = 'home';
4618 4877
 
4619
-	if (isset($context['menu_buttons'][$context['current_action']]))
4620
-		$current_action = $context['current_action'];
4621
-	elseif ($context['current_action'] == 'search2')
4622
-		$current_action = 'search';
4623
-	elseif ($context['current_action'] == 'theme')
4624
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4625
-	elseif ($context['current_action'] == 'register2')
4626
-		$current_action = 'register';
4627
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4628
-		$current_action = 'login';
4629
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4630
-		$current_action = 'moderate';
4878
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4879
+			$current_action = $context['current_action'];
4880
+	} elseif ($context['current_action'] == 'search2') {
4881
+			$current_action = 'search';
4882
+	} elseif ($context['current_action'] == 'theme') {
4883
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4884
+	} elseif ($context['current_action'] == 'register2') {
4885
+			$current_action = 'register';
4886
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4887
+			$current_action = 'login';
4888
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4889
+			$current_action = 'moderate';
4890
+	}
4631 4891
 
4632 4892
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4633 4893
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4634 4894
 	{
4635 4895
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4636 4896
 		$context[$current_action] = true;
4637
-	}
4638
-	elseif ($context['current_action'] == 'pm')
4897
+	} elseif ($context['current_action'] == 'pm')
4639 4898
 	{
4640 4899
 		$current_action = 'self_pm';
4641 4900
 		$context['self_pm'] = true;
@@ -4694,12 +4953,14 @@  discard block
 block discarded – undo
4694 4953
 	}
4695 4954
 
4696 4955
 	// Not all actions are simple.
4697
-	if (!empty($needs_action_hook))
4698
-		call_integration_hook('integrate_current_action', array(&$current_action));
4956
+	if (!empty($needs_action_hook)) {
4957
+			call_integration_hook('integrate_current_action', array(&$current_action));
4958
+	}
4699 4959
 
4700
-	if (isset($context['menu_buttons'][$current_action]))
4701
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4702
-}
4960
+	if (isset($context['menu_buttons'][$current_action])) {
4961
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4962
+	}
4963
+	}
4703 4964
 
4704 4965
 /**
4705 4966
  * Generate a random seed and ensure it's stored in settings.
@@ -4723,30 +4984,35 @@  discard block
 block discarded – undo
4723 4984
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4724 4985
 	global $context, $txt;
4725 4986
 
4726
-	if ($db_show_debug === true)
4727
-		$context['debug']['hooks'][] = $hook;
4987
+	if ($db_show_debug === true) {
4988
+			$context['debug']['hooks'][] = $hook;
4989
+	}
4728 4990
 
4729 4991
 	// Need to have some control.
4730
-	if (!isset($context['instances']))
4731
-		$context['instances'] = array();
4992
+	if (!isset($context['instances'])) {
4993
+			$context['instances'] = array();
4994
+	}
4732 4995
 
4733 4996
 	$results = array();
4734
-	if (empty($modSettings[$hook]))
4735
-		return $results;
4997
+	if (empty($modSettings[$hook])) {
4998
+			return $results;
4999
+	}
4736 5000
 
4737 5001
 	$functions = explode(',', $modSettings[$hook]);
4738 5002
 	// Loop through each function.
4739 5003
 	foreach ($functions as $function)
4740 5004
 	{
4741 5005
 		// Hook has been marked as "disabled". Skip it!
4742
-		if (strpos($function, '!') !== false)
4743
-			continue;
5006
+		if (strpos($function, '!') !== false) {
5007
+					continue;
5008
+		}
4744 5009
 
4745 5010
 		$call = call_helper($function, true);
4746 5011
 
4747 5012
 		// Is it valid?
4748
-		if (!empty($call))
4749
-			$results[$function] = call_user_func_array($call, $parameters);
5013
+		if (!empty($call)) {
5014
+					$results[$function] = call_user_func_array($call, $parameters);
5015
+		}
4750 5016
 
4751 5017
 		// Whatever it was suppose to call, it failed :(
4752 5018
 		elseif (!empty($function))
@@ -4762,8 +5028,9 @@  discard block
 block discarded – undo
4762 5028
 			}
4763 5029
 
4764 5030
 			// "Assume" the file resides on $boarddir somewhere...
4765
-			else
4766
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5031
+			else {
5032
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5033
+			}
4767 5034
 		}
4768 5035
 	}
4769 5036
 
@@ -4785,12 +5052,14 @@  discard block
 block discarded – undo
4785 5052
 	global $smcFunc, $modSettings;
4786 5053
 
4787 5054
 	// Any objects?
4788
-	if ($object)
4789
-		$function = $function . '#';
5055
+	if ($object) {
5056
+			$function = $function . '#';
5057
+	}
4790 5058
 
4791 5059
 	// Any files  to load?
4792
-	if (!empty($file) && is_string($file))
4793
-		$function = $file . (!empty($function) ? '|' . $function : '');
5060
+	if (!empty($file) && is_string($file)) {
5061
+			$function = $file . (!empty($function) ? '|' . $function : '');
5062
+	}
4794 5063
 
4795 5064
 	// Get the correct string.
4796 5065
 	$integration_call = $function;
@@ -4812,13 +5081,14 @@  discard block
 block discarded – undo
4812 5081
 		if (!empty($current_functions))
4813 5082
 		{
4814 5083
 			$current_functions = explode(',', $current_functions);
4815
-			if (in_array($integration_call, $current_functions))
4816
-				return;
5084
+			if (in_array($integration_call, $current_functions)) {
5085
+							return;
5086
+			}
4817 5087
 
4818 5088
 			$permanent_functions = array_merge($current_functions, array($integration_call));
5089
+		} else {
5090
+					$permanent_functions = array($integration_call);
4819 5091
 		}
4820
-		else
4821
-			$permanent_functions = array($integration_call);
4822 5092
 
4823 5093
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4824 5094
 	}
@@ -4827,8 +5097,9 @@  discard block
 block discarded – undo
4827 5097
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4828 5098
 
4829 5099
 	// Do nothing, if it's already there.
4830
-	if (in_array($integration_call, $functions))
4831
-		return;
5100
+	if (in_array($integration_call, $functions)) {
5101
+			return;
5102
+	}
4832 5103
 
4833 5104
 	$functions[] = $integration_call;
4834 5105
 	$modSettings[$hook] = implode(',', $functions);
@@ -4851,12 +5122,14 @@  discard block
 block discarded – undo
4851 5122
 	global $smcFunc, $modSettings;
4852 5123
 
4853 5124
 	// Any objects?
4854
-	if ($object)
4855
-		$function = $function . '#';
5125
+	if ($object) {
5126
+			$function = $function . '#';
5127
+	}
4856 5128
 
4857 5129
 	// Any files  to load?
4858
-	if (!empty($file) && is_string($file))
4859
-		$function = $file . '|' . $function;
5130
+	if (!empty($file) && is_string($file)) {
5131
+			$function = $file . '|' . $function;
5132
+	}
4860 5133
 
4861 5134
 	// Get the correct string.
4862 5135
 	$integration_call = $function;
@@ -4877,16 +5150,18 @@  discard block
 block discarded – undo
4877 5150
 	{
4878 5151
 		$current_functions = explode(',', $current_functions);
4879 5152
 
4880
-		if (in_array($integration_call, $current_functions))
4881
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5153
+		if (in_array($integration_call, $current_functions)) {
5154
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5155
+		}
4882 5156
 	}
4883 5157
 
4884 5158
 	// Turn the function list into something usable.
4885 5159
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4886 5160
 
4887 5161
 	// You can only remove it if it's available.
4888
-	if (!in_array($integration_call, $functions))
4889
-		return;
5162
+	if (!in_array($integration_call, $functions)) {
5163
+			return;
5164
+	}
4890 5165
 
4891 5166
 	$functions = array_diff($functions, array($integration_call));
4892 5167
 	$modSettings[$hook] = implode(',', $functions);
@@ -4907,17 +5182,20 @@  discard block
 block discarded – undo
4907 5182
 	global $context, $smcFunc, $txt, $db_show_debug;
4908 5183
 
4909 5184
 	// Really?
4910
-	if (empty($string))
4911
-		return false;
5185
+	if (empty($string)) {
5186
+			return false;
5187
+	}
4912 5188
 
4913 5189
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4914 5190
 	// A closure? should be a callable one.
4915
-	if (is_array($string) || $string instanceof Closure)
4916
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5191
+	if (is_array($string) || $string instanceof Closure) {
5192
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5193
+	}
4917 5194
 
4918 5195
 	// No full objects, sorry! pass a method or a property instead!
4919
-	if (is_object($string))
4920
-		return false;
5196
+	if (is_object($string)) {
5197
+			return false;
5198
+	}
4921 5199
 
4922 5200
 	// Stay vitaminized my friends...
4923 5201
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4926,8 +5204,9 @@  discard block
 block discarded – undo
4926 5204
 	$string = load_file($string);
4927 5205
 
4928 5206
 	// Loaded file failed
4929
-	if (empty($string))
4930
-		return false;
5207
+	if (empty($string)) {
5208
+			return false;
5209
+	}
4931 5210
 
4932 5211
 	// Found a method.
4933 5212
 	if (strpos($string, '::') !== false)
@@ -4948,8 +5227,9 @@  discard block
 block discarded – undo
4948 5227
 				// Add another one to the list.
4949 5228
 				if ($db_show_debug === true)
4950 5229
 				{
4951
-					if (!isset($context['debug']['instances']))
4952
-						$context['debug']['instances'] = array();
5230
+					if (!isset($context['debug']['instances'])) {
5231
+											$context['debug']['instances'] = array();
5232
+					}
4953 5233
 
4954 5234
 					$context['debug']['instances'][$class] = $class;
4955 5235
 				}
@@ -4959,13 +5239,15 @@  discard block
 block discarded – undo
4959 5239
 		}
4960 5240
 
4961 5241
 		// Right then. This is a call to a static method.
4962
-		else
4963
-			$func = array($class, $method);
5242
+		else {
5243
+					$func = array($class, $method);
5244
+		}
4964 5245
 	}
4965 5246
 
4966 5247
 	// Nope! just a plain regular function.
4967
-	else
4968
-		$func = $string;
5248
+	else {
5249
+			$func = $string;
5250
+	}
4969 5251
 
4970 5252
 	// Right, we got what we need, time to do some checks.
4971 5253
 	if (!is_callable($func, false, $callable_name))
@@ -4981,17 +5263,18 @@  discard block
 block discarded – undo
4981 5263
 	else
4982 5264
 	{
4983 5265
 		// What are we gonna do about it?
4984
-		if ($return)
4985
-			return $func;
5266
+		if ($return) {
5267
+					return $func;
5268
+		}
4986 5269
 
4987 5270
 		// If this is a plain function, avoid the heat of calling call_user_func().
4988 5271
 		else
4989 5272
 		{
4990
-			if (is_array($func))
4991
-				call_user_func($func);
4992
-
4993
-			else
4994
-				$func();
5273
+			if (is_array($func)) {
5274
+							call_user_func($func);
5275
+			} else {
5276
+							$func();
5277
+			}
4995 5278
 		}
4996 5279
 	}
4997 5280
 }
@@ -5008,31 +5291,34 @@  discard block
 block discarded – undo
5008 5291
 {
5009 5292
 	global $sourcedir, $txt, $boarddir, $settings;
5010 5293
 
5011
-	if (empty($string))
5012
-		return false;
5294
+	if (empty($string)) {
5295
+			return false;
5296
+	}
5013 5297
 
5014 5298
 	if (strpos($string, '|') !== false)
5015 5299
 	{
5016 5300
 		list ($file, $string) = explode('|', $string);
5017 5301
 
5018 5302
 		// Match the wildcards to their regular vars.
5019
-		if (empty($settings['theme_dir']))
5020
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5021
-
5022
-		else
5023
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5303
+		if (empty($settings['theme_dir'])) {
5304
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5305
+		} else {
5306
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5307
+		}
5024 5308
 
5025 5309
 		// Load the file if it can be loaded.
5026
-		if (file_exists($absPath))
5027
-			require_once($absPath);
5310
+		if (file_exists($absPath)) {
5311
+					require_once($absPath);
5312
+		}
5028 5313
 
5029 5314
 		// No? try a fallback to $sourcedir
5030 5315
 		else
5031 5316
 		{
5032 5317
 			$absPath = $sourcedir .'/'. $file;
5033 5318
 
5034
-			if (file_exists($absPath))
5035
-				require_once($absPath);
5319
+			if (file_exists($absPath)) {
5320
+							require_once($absPath);
5321
+			}
5036 5322
 
5037 5323
 			// Sorry, can't do much for you at this point.
5038 5324
 			else
@@ -5071,8 +5357,9 @@  discard block
 block discarded – undo
5071 5357
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
5072 5358
 
5073 5359
 	// No scheme? No data for you!
5074
-	if (empty($match[1]))
5075
-		return false;
5360
+	if (empty($match[1])) {
5361
+			return false;
5362
+	}
5076 5363
 
5077 5364
 	// An FTP url. We should try connecting and RETRieving it...
5078 5365
 	elseif ($match[1] == 'ftp')
@@ -5082,23 +5369,26 @@  discard block
 block discarded – undo
5082 5369
 
5083 5370
 		// Establish a connection and attempt to enable passive mode.
5084 5371
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
5085
-		if ($ftp->error !== false || !$ftp->passive())
5086
-			return false;
5372
+		if ($ftp->error !== false || !$ftp->passive()) {
5373
+					return false;
5374
+		}
5087 5375
 
5088 5376
 		// I want that one *points*!
5089 5377
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
5090 5378
 
5091 5379
 		// Since passive mode worked (or we would have returned already!) open the connection.
5092 5380
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
5093
-		if (!$fp)
5094
-			return false;
5381
+		if (!$fp) {
5382
+					return false;
5383
+		}
5095 5384
 
5096 5385
 		// The server should now say something in acknowledgement.
5097 5386
 		$ftp->check_response(150);
5098 5387
 
5099 5388
 		$data = '';
5100
-		while (!feof($fp))
5101
-			$data .= fread($fp, 4096);
5389
+		while (!feof($fp)) {
5390
+					$data .= fread($fp, 4096);
5391
+		}
5102 5392
 		fclose($fp);
5103 5393
 
5104 5394
 		// All done, right?  Good.
@@ -5110,8 +5400,9 @@  discard block
 block discarded – undo
5110 5400
 	elseif (isset($match[1]) && $match[1] == 'http')
5111 5401
 	{
5112 5402
 		// First try to use fsockopen, because it is fastest.
5113
-		if ($keep_alive && $match[3] == $keep_alive_dom)
5114
-			$fp = $keep_alive_fp;
5403
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5404
+					$fp = $keep_alive_fp;
5405
+		}
5115 5406
 		if (empty($fp))
5116 5407
 		{
5117 5408
 			// Open the socket on the port we want...
@@ -5131,20 +5422,21 @@  discard block
 block discarded – undo
5131 5422
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
5132 5423
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5133 5424
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5134
-				if ($keep_alive)
5135
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5136
-				else
5137
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
5138
-			}
5139
-			else
5425
+				if ($keep_alive) {
5426
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5427
+				} else {
5428
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5429
+				}
5430
+			} else
5140 5431
 			{
5141 5432
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
5142 5433
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5143 5434
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5144
-				if ($keep_alive)
5145
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5146
-				else
5147
-					fwrite($fp, 'connection: close' . "\r\n");
5435
+				if ($keep_alive) {
5436
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5437
+				} else {
5438
+									fwrite($fp, 'connection: close' . "\r\n");
5439
+				}
5148 5440
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
5149 5441
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
5150 5442
 				fwrite($fp, $post_data);
@@ -5157,30 +5449,33 @@  discard block
 block discarded – undo
5157 5449
 			{
5158 5450
 				$header = '';
5159 5451
 				$location = '';
5160
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5161
-					if (strpos($header, 'location:') !== false)
5452
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5453
+									if (strpos($header, 'location:') !== false)
5162 5454
 						$location = trim(substr($header, strpos($header, ':') + 1));
5455
+				}
5163 5456
 
5164
-				if (empty($location))
5165
-					return false;
5166
-				else
5457
+				if (empty($location)) {
5458
+									return false;
5459
+				} else
5167 5460
 				{
5168
-					if (!$keep_alive)
5169
-						fclose($fp);
5461
+					if (!$keep_alive) {
5462
+											fclose($fp);
5463
+					}
5170 5464
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
5171 5465
 				}
5172 5466
 			}
5173 5467
 
5174 5468
 			// Make sure we get a 200 OK.
5175
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5176
-				return false;
5469
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5470
+							return false;
5471
+			}
5177 5472
 
5178 5473
 			// Skip the headers...
5179 5474
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5180 5475
 			{
5181
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5182
-					$content_length = $match[1];
5183
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5476
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5477
+									$content_length = $match[1];
5478
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5184 5479
 				{
5185 5480
 					$keep_alive_dom = null;
5186 5481
 					$keep_alive = false;
@@ -5192,17 +5487,19 @@  discard block
 block discarded – undo
5192 5487
 			$data = '';
5193 5488
 			if (isset($content_length))
5194 5489
 			{
5195
-				while (!feof($fp) && strlen($data) < $content_length)
5196
-					$data .= fread($fp, $content_length - strlen($data));
5197
-			}
5198
-			else
5490
+				while (!feof($fp) && strlen($data) < $content_length) {
5491
+									$data .= fread($fp, $content_length - strlen($data));
5492
+				}
5493
+			} else
5199 5494
 			{
5200
-				while (!feof($fp))
5201
-					$data .= fread($fp, 4096);
5495
+				while (!feof($fp)) {
5496
+									$data .= fread($fp, 4096);
5497
+				}
5202 5498
 			}
5203 5499
 
5204
-			if (!$keep_alive)
5205
-				fclose($fp);
5500
+			if (!$keep_alive) {
5501
+							fclose($fp);
5502
+			}
5206 5503
 		}
5207 5504
 
5208 5505
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5215,17 +5512,18 @@  discard block
 block discarded – undo
5215 5512
 			$fetch_data->get_url_data($url, $post_data);
5216 5513
 
5217 5514
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5218
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5219
-				$data = $fetch_data->result('body');
5220
-			else
5221
-				return false;
5515
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5516
+							$data = $fetch_data->result('body');
5517
+			} else {
5518
+							return false;
5519
+			}
5222 5520
 		}
5223 5521
 
5224 5522
 		// Neither fsockopen nor curl are available. Well, phooey.
5225
-		else
5226
-			return false;
5227
-	}
5228
-	else
5523
+		else {
5524
+					return false;
5525
+		}
5526
+	} else
5229 5527
 	{
5230 5528
 		// Umm, this shouldn't happen?
5231 5529
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5245,8 +5543,9 @@  discard block
 block discarded – undo
5245 5543
 	global $user_info, $smcFunc;
5246 5544
 
5247 5545
 	// Make sure we have something to work with.
5248
-	if (empty($topic))
5249
-		return array();
5546
+	if (empty($topic)) {
5547
+			return array();
5548
+	}
5250 5549
 
5251 5550
 
5252 5551
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5269,8 +5568,9 @@  discard block
 block discarded – undo
5269 5568
 				'topic' => $topic,
5270 5569
 			)
5271 5570
 		);
5272
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5273
-			$temp[] = (int) $row['content_id'];
5571
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5572
+					$temp[] = (int) $row['content_id'];
5573
+		}
5274 5574
 
5275 5575
 		cache_put_data($cache_key, $temp, $ttl);
5276 5576
 	}
@@ -5291,8 +5591,9 @@  discard block
 block discarded – undo
5291 5591
 {
5292 5592
 	global $context;
5293 5593
 
5294
-	if (empty($string))
5295
-		return $string;
5594
+	if (empty($string)) {
5595
+			return $string;
5596
+	}
5296 5597
 
5297 5598
 	// UTF-8 occurences of MS special characters
5298 5599
 	$findchars_utf8 = array(
@@ -5333,10 +5634,11 @@  discard block
 block discarded – undo
5333 5634
 		'--',	// &mdash;
5334 5635
 	);
5335 5636
 
5336
-	if ($context['utf8'])
5337
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5338
-	else
5339
-		$string = str_replace($findchars_iso, $replacechars, $string);
5637
+	if ($context['utf8']) {
5638
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5639
+	} else {
5640
+			$string = str_replace($findchars_iso, $replacechars, $string);
5641
+	}
5340 5642
 
5341 5643
 	return $string;
5342 5644
 }
@@ -5355,49 +5657,59 @@  discard block
 block discarded – undo
5355 5657
 {
5356 5658
 	global $context;
5357 5659
 
5358
-	if (!isset($matches[2]))
5359
-		return '';
5660
+	if (!isset($matches[2])) {
5661
+			return '';
5662
+	}
5360 5663
 
5361 5664
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5362 5665
 
5363 5666
 	// remove left to right / right to left overrides
5364
-	if ($num === 0x202D || $num === 0x202E)
5365
-		return '';
5667
+	if ($num === 0x202D || $num === 0x202E) {
5668
+			return '';
5669
+	}
5366 5670
 
5367 5671
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5368
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5369
-		return '&#' . $num . ';';
5672
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5673
+			return '&#' . $num . ';';
5674
+	}
5370 5675
 
5371 5676
 	if (empty($context['utf8']))
5372 5677
 	{
5373 5678
 		// no control characters
5374
-		if ($num < 0x20)
5375
-			return '';
5679
+		if ($num < 0x20) {
5680
+					return '';
5681
+		}
5376 5682
 		// text is text
5377
-		elseif ($num < 0x80)
5378
-			return chr($num);
5683
+		elseif ($num < 0x80) {
5684
+					return chr($num);
5685
+		}
5379 5686
 		// all others get html-ised
5380
-		else
5381
-			return '&#' . $matches[2] . ';';
5382
-	}
5383
-	else
5687
+		else {
5688
+					return '&#' . $matches[2] . ';';
5689
+		}
5690
+	} else
5384 5691
 	{
5385 5692
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5386 5693
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5387
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5388
-			return '';
5694
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5695
+					return '';
5696
+		}
5389 5697
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5390
-		elseif ($num < 0x80)
5391
-			return chr($num);
5698
+		elseif ($num < 0x80) {
5699
+					return chr($num);
5700
+		}
5392 5701
 		// <0x800 (2048)
5393
-		elseif ($num < 0x800)
5394
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5702
+		elseif ($num < 0x800) {
5703
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5704
+		}
5395 5705
 		// < 0x10000 (65536)
5396
-		elseif ($num < 0x10000)
5397
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5706
+		elseif ($num < 0x10000) {
5707
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5708
+		}
5398 5709
 		// <= 0x10FFFF (1114111)
5399
-		else
5400
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5710
+		else {
5711
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5712
+		}
5401 5713
 	}
5402 5714
 }
5403 5715
 
@@ -5413,28 +5725,34 @@  discard block
 block discarded – undo
5413 5725
  */
5414 5726
 function fixchar__callback($matches)
5415 5727
 {
5416
-	if (!isset($matches[1]))
5417
-		return '';
5728
+	if (!isset($matches[1])) {
5729
+			return '';
5730
+	}
5418 5731
 
5419 5732
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5420 5733
 
5421 5734
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5422 5735
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5423
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5424
-		return '';
5736
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5737
+			return '';
5738
+	}
5425 5739
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5426
-	elseif ($num < 0x80)
5427
-		return chr($num);
5740
+	elseif ($num < 0x80) {
5741
+			return chr($num);
5742
+	}
5428 5743
 	// <0x800 (2048)
5429
-	elseif ($num < 0x800)
5430
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5744
+	elseif ($num < 0x800) {
5745
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5746
+	}
5431 5747
 	// < 0x10000 (65536)
5432
-	elseif ($num < 0x10000)
5433
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5748
+	elseif ($num < 0x10000) {
5749
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5750
+	}
5434 5751
 	// <= 0x10FFFF (1114111)
5435
-	else
5436
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5437
-}
5752
+	else {
5753
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5754
+	}
5755
+	}
5438 5756
 
5439 5757
 /**
5440 5758
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5447,17 +5765,19 @@  discard block
 block discarded – undo
5447 5765
  */
5448 5766
 function entity_fix__callback($matches)
5449 5767
 {
5450
-	if (!isset($matches[2]))
5451
-		return '';
5768
+	if (!isset($matches[2])) {
5769
+			return '';
5770
+	}
5452 5771
 
5453 5772
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5454 5773
 
5455 5774
 	// we don't allow control characters, characters out of range, byte markers, etc
5456
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5457
-		return '';
5458
-	else
5459
-		return '&#' . $num . ';';
5460
-}
5775
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5776
+			return '';
5777
+	} else {
5778
+			return '&#' . $num . ';';
5779
+	}
5780
+	}
5461 5781
 
5462 5782
 /**
5463 5783
  * Return a Gravatar URL based on
@@ -5481,18 +5801,23 @@  discard block
 block discarded – undo
5481 5801
 		$ratings = array('G', 'PG', 'R', 'X');
5482 5802
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5483 5803
 		$url_params = array();
5484
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5485
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5486
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5487
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5488
-		if (!empty($modSettings['avatar_max_width_external']))
5489
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5490
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5491
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5804
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5805
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5806
+		}
5807
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5808
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5809
+		}
5810
+		if (!empty($modSettings['avatar_max_width_external'])) {
5811
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5812
+		}
5813
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5814
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5492 5815
 				$size_string = $modSettings['avatar_max_height_external'];
5816
+		}
5493 5817
 
5494
-		if (!empty($size_string))
5495
-			$url_params[] = 's=' . $size_string;
5818
+		if (!empty($size_string)) {
5819
+					$url_params[] = 's=' . $size_string;
5820
+		}
5496 5821
 	}
5497 5822
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5498 5823
 
@@ -5511,22 +5836,26 @@  discard block
 block discarded – undo
5511 5836
 	static $timezones = null, $lastwhen = null;
5512 5837
 
5513 5838
 	// No point doing this over if we already did it once
5514
-	if (!empty($timezones) && $when == $lastwhen)
5515
-		return $timezones;
5516
-	else
5517
-		$lastwhen = $when;
5839
+	if (!empty($timezones) && $when == $lastwhen) {
5840
+			return $timezones;
5841
+	} else {
5842
+			$lastwhen = $when;
5843
+	}
5518 5844
 
5519 5845
 	// Parseable datetime string?
5520
-	if (is_int($timestamp = strtotime($when)))
5521
-		$when = $timestamp;
5846
+	if (is_int($timestamp = strtotime($when))) {
5847
+			$when = $timestamp;
5848
+	}
5522 5849
 
5523 5850
 	// A Unix timestamp?
5524
-	elseif (is_numeric($when))
5525
-		$when = intval($when);
5851
+	elseif (is_numeric($when)) {
5852
+			$when = intval($when);
5853
+	}
5526 5854
 
5527 5855
 	// Invalid value? Just get current Unix timestamp.
5528
-	else
5529
-		$when = time();
5856
+	else {
5857
+			$when = time();
5858
+	}
5530 5859
 
5531 5860
 	// We'll need these too
5532 5861
 	$date_when = date_create('@' . $when);
@@ -5541,8 +5870,9 @@  discard block
 block discarded – undo
5541 5870
 	foreach ($priority_countries as $country)
5542 5871
 	{
5543 5872
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5544
-		if (!empty($country_tzids))
5545
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5873
+		if (!empty($country_tzids)) {
5874
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5875
+		}
5546 5876
 	}
5547 5877
 
5548 5878
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5556,8 +5886,9 @@  discard block
 block discarded – undo
5556 5886
 	foreach ($tzids as $tzid)
5557 5887
 	{
5558 5888
 		// We don't want UTC right now
5559
-		if ($tzid == 'UTC')
5560
-			continue;
5889
+		if ($tzid == 'UTC') {
5890
+					continue;
5891
+		}
5561 5892
 
5562 5893
 		$tz = timezone_open($tzid);
5563 5894
 
@@ -5578,13 +5909,14 @@  discard block
 block discarded – undo
5578 5909
 		}
5579 5910
 
5580 5911
 		// A time zone from a prioritized country?
5581
-		if (in_array($tzid, $priority_tzids))
5582
-			$priority_zones[$tzkey] = true;
5912
+		if (in_array($tzid, $priority_tzids)) {
5913
+					$priority_zones[$tzkey] = true;
5914
+		}
5583 5915
 
5584 5916
 		// Keep track of the location and offset for this tzid
5585
-		if (!empty($txt[$tzid]))
5586
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5587
-		else
5917
+		if (!empty($txt[$tzid])) {
5918
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5919
+		} else
5588 5920
 		{
5589 5921
 			$tzid_parts = explode('/', $tzid);
5590 5922
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5604,23 +5936,27 @@  discard block
 block discarded – undo
5604 5936
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5605 5937
 
5606 5938
 		// Use the custom description, if there is one
5607
-		if (!empty($tztxt[$tzvalue['tzid']]))
5608
-			$desc = $tztxt[$tzvalue['tzid']];
5939
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5940
+					$desc = $tztxt[$tzvalue['tzid']];
5941
+		}
5609 5942
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5610
-		else
5611
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5943
+		else {
5944
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5945
+		}
5612 5946
 
5613 5947
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5614 5948
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5615 5949
 
5616
-		if (isset($priority_zones[$tzkey]))
5617
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5618
-		else
5619
-			$timezones[$tzvalue['tzid']] = $desc;
5950
+		if (isset($priority_zones[$tzkey])) {
5951
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5952
+		} else {
5953
+					$timezones[$tzvalue['tzid']] = $desc;
5954
+		}
5620 5955
 	}
5621 5956
 
5622
-	if (!empty($priority_timezones))
5623
-		$priority_timezones[] = '-----';
5957
+	if (!empty($priority_timezones)) {
5958
+			$priority_timezones[] = '-----';
5959
+	}
5624 5960
 
5625 5961
 	$timezones = array_merge(
5626 5962
 		$priority_timezones,
@@ -5637,8 +5973,9 @@  discard block
 block discarded – undo
5637 5973
  */
5638 5974
 function inet_ptod($ip_address)
5639 5975
 {
5640
-	if (!isValidIP($ip_address))
5641
-		return $ip_address;
5976
+	if (!isValidIP($ip_address)) {
5977
+			return $ip_address;
5978
+	}
5642 5979
 
5643 5980
 	$bin = inet_pton($ip_address);
5644 5981
 	return $bin;
@@ -5650,13 +5987,15 @@  discard block
 block discarded – undo
5650 5987
  */
5651 5988
 function inet_dtop($bin)
5652 5989
 {
5653
-	if(empty($bin))
5654
-		return '';
5990
+	if(empty($bin)) {
5991
+			return '';
5992
+	}
5655 5993
 
5656 5994
 	global $db_type;
5657 5995
 
5658
-	if ($db_type == 'postgresql')
5659
-		return $bin;
5996
+	if ($db_type == 'postgresql') {
5997
+			return $bin;
5998
+	}
5660 5999
 
5661 6000
 	$ip_address = inet_ntop($bin);
5662 6001
 
@@ -5681,26 +6020,32 @@  discard block
 block discarded – undo
5681 6020
  */
5682 6021
 function _safe_serialize($value)
5683 6022
 {
5684
-	if(is_null($value))
5685
-		return 'N;';
6023
+	if(is_null($value)) {
6024
+			return 'N;';
6025
+	}
5686 6026
 
5687
-	if(is_bool($value))
5688
-		return 'b:'. (int) $value .';';
6027
+	if(is_bool($value)) {
6028
+			return 'b:'. (int) $value .';';
6029
+	}
5689 6030
 
5690
-	if(is_int($value))
5691
-		return 'i:'. $value .';';
6031
+	if(is_int($value)) {
6032
+			return 'i:'. $value .';';
6033
+	}
5692 6034
 
5693
-	if(is_float($value))
5694
-		return 'd:'. str_replace(',', '.', $value) .';';
6035
+	if(is_float($value)) {
6036
+			return 'd:'. str_replace(',', '.', $value) .';';
6037
+	}
5695 6038
 
5696
-	if(is_string($value))
5697
-		return 's:'. strlen($value) .':"'. $value .'";';
6039
+	if(is_string($value)) {
6040
+			return 's:'. strlen($value) .':"'. $value .'";';
6041
+	}
5698 6042
 
5699 6043
 	if(is_array($value))
5700 6044
 	{
5701 6045
 		$out = '';
5702
-		foreach($value as $k => $v)
5703
-			$out .= _safe_serialize($k) . _safe_serialize($v);
6046
+		foreach($value as $k => $v) {
6047
+					$out .= _safe_serialize($k) . _safe_serialize($v);
6048
+		}
5704 6049
 
5705 6050
 		return 'a:'. count($value) .':{'. $out .'}';
5706 6051
 	}
@@ -5726,8 +6071,9 @@  discard block
 block discarded – undo
5726 6071
 
5727 6072
 	$out = _safe_serialize($value);
5728 6073
 
5729
-	if (isset($mbIntEnc))
5730
-		mb_internal_encoding($mbIntEnc);
6074
+	if (isset($mbIntEnc)) {
6075
+			mb_internal_encoding($mbIntEnc);
6076
+	}
5731 6077
 
5732 6078
 	return $out;
5733 6079
 }
@@ -5744,8 +6090,9 @@  discard block
 block discarded – undo
5744 6090
 function _safe_unserialize($str)
5745 6091
 {
5746 6092
 	// Input  is not a string.
5747
-	if(empty($str) || !is_string($str))
5748
-		return false;
6093
+	if(empty($str) || !is_string($str)) {
6094
+			return false;
6095
+	}
5749 6096
 
5750 6097
 	$stack = array();
5751 6098
 	$expected = array();
@@ -5761,43 +6108,38 @@  discard block
 block discarded – undo
5761 6108
 	while($state != 1)
5762 6109
 	{
5763 6110
 		$type = isset($str[0]) ? $str[0] : '';
5764
-		if($type == '}')
5765
-			$str = substr($str, 1);
5766
-
5767
-		else if($type == 'N' && $str[1] == ';')
6111
+		if($type == '}') {
6112
+					$str = substr($str, 1);
6113
+		} else if($type == 'N' && $str[1] == ';')
5768 6114
 		{
5769 6115
 			$value = null;
5770 6116
 			$str = substr($str, 2);
5771
-		}
5772
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
6117
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5773 6118
 		{
5774 6119
 			$value = $matches[1] == '1' ? true : false;
5775 6120
 			$str = substr($str, 4);
5776
-		}
5777
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
6121
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5778 6122
 		{
5779 6123
 			$value = (int)$matches[1];
5780 6124
 			$str = $matches[2];
5781
-		}
5782
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
6125
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5783 6126
 		{
5784 6127
 			$value = (float)$matches[1];
5785 6128
 			$str = $matches[3];
5786
-		}
5787
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
6129
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5788 6130
 		{
5789 6131
 			$value = substr($matches[2], 0, (int)$matches[1]);
5790 6132
 			$str = substr($matches[2], (int)$matches[1] + 2);
5791
-		}
5792
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
6133
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5793 6134
 		{
5794 6135
 			$expectedLength = (int)$matches[1];
5795 6136
 			$str = $matches[2];
5796 6137
 		}
5797 6138
 
5798 6139
 		// Object or unknown/malformed type.
5799
-		else
5800
-			return false;
6140
+		else {
6141
+					return false;
6142
+		}
5801 6143
 
5802 6144
 		switch($state)
5803 6145
 		{
@@ -5825,8 +6167,9 @@  discard block
 block discarded – undo
5825 6167
 				if($type == '}')
5826 6168
 				{
5827 6169
 					// Array size is less than expected.
5828
-					if(count($list) < end($expected))
5829
-						return false;
6170
+					if(count($list) < end($expected)) {
6171
+											return false;
6172
+					}
5830 6173
 
5831 6174
 					unset($list);
5832 6175
 					$list = &$stack[count($stack)-1];
@@ -5835,8 +6178,9 @@  discard block
 block discarded – undo
5835 6178
 					// Go to terminal state if we're at the end of the root array.
5836 6179
 					array_pop($expected);
5837 6180
 
5838
-					if(count($expected) == 0)
5839
-						$state = 1;
6181
+					if(count($expected) == 0) {
6182
+											$state = 1;
6183
+					}
5840 6184
 
5841 6185
 					break;
5842 6186
 				}
@@ -5844,8 +6188,9 @@  discard block
 block discarded – undo
5844 6188
 				if($type == 'i' || $type == 's')
5845 6189
 				{
5846 6190
 					// Array size exceeds expected length.
5847
-					if(count($list) >= end($expected))
5848
-						return false;
6191
+					if(count($list) >= end($expected)) {
6192
+											return false;
6193
+					}
5849 6194
 
5850 6195
 					$key = $value;
5851 6196
 					$state = 3;
@@ -5879,8 +6224,9 @@  discard block
 block discarded – undo
5879 6224
 	}
5880 6225
 
5881 6226
 	// Trailing data in input.
5882
-	if(!empty($str))
5883
-		return false;
6227
+	if(!empty($str)) {
6228
+			return false;
6229
+	}
5884 6230
 
5885 6231
 	return $data;
5886 6232
 }
@@ -5903,8 +6249,9 @@  discard block
 block discarded – undo
5903 6249
 
5904 6250
 	$out = _safe_unserialize($str);
5905 6251
 
5906
-	if (isset($mbIntEnc))
5907
-		mb_internal_encoding($mbIntEnc);
6252
+	if (isset($mbIntEnc)) {
6253
+			mb_internal_encoding($mbIntEnc);
6254
+	}
5908 6255
 
5909 6256
 	return $out;
5910 6257
 }
@@ -5919,12 +6266,14 @@  discard block
 block discarded – undo
5919 6266
 function smf_chmod($file, $value = 0)
5920 6267
 {
5921 6268
 	// No file? no checks!
5922
-	if (empty($file))
5923
-		return false;
6269
+	if (empty($file)) {
6270
+			return false;
6271
+	}
5924 6272
 
5925 6273
 	// Already writable?
5926
-	if (is_writable($file))
5927
-		return true;
6274
+	if (is_writable($file)) {
6275
+			return true;
6276
+	}
5928 6277
 
5929 6278
 	// Do we have a file or a dir?
5930 6279
 	$isDir = is_dir($file);
@@ -5940,10 +6289,9 @@  discard block
 block discarded – undo
5940 6289
 		{
5941 6290
 			$isWritable = true;
5942 6291
 			break;
6292
+		} else {
6293
+					@chmod($file, $val);
5943 6294
 		}
5944
-
5945
-		else
5946
-			@chmod($file, $val);
5947 6295
 	}
5948 6296
 
5949 6297
 	return $isWritable;
@@ -5962,8 +6310,9 @@  discard block
 block discarded – undo
5962 6310
 	global $txt;
5963 6311
 
5964 6312
 	// Come on...
5965
-	if (empty($json) || !is_string($json))
5966
-		return array();
6313
+	if (empty($json) || !is_string($json)) {
6314
+			return array();
6315
+	}
5967 6316
 
5968 6317
 	$returnArray = @json_decode($json, $returnAsArray);
5969 6318
 
@@ -6001,11 +6350,11 @@  discard block
 block discarded – undo
6001 6350
 		$jsonDebug = $jsonDebug[0];
6002 6351
 		loadLanguage('Errors');
6003 6352
 
6004
-		if (!empty($jsonDebug))
6005
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6006
-
6007
-		else
6008
-			log_error($txt['json_'. $jsonError], 'critical');
6353
+		if (!empty($jsonDebug)) {
6354
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6355
+		} else {
6356
+					log_error($txt['json_'. $jsonError], 'critical');
6357
+		}
6009 6358
 
6010 6359
 		// Everyone expects an array.
6011 6360
 		return array();
@@ -6039,8 +6388,9 @@  discard block
 block discarded – undo
6039 6388
 	global $db_show_debug, $modSettings;
6040 6389
 
6041 6390
 	// Defensive programming anyone?
6042
-	if (empty($data))
6043
-		return false;
6391
+	if (empty($data)) {
6392
+			return false;
6393
+	}
6044 6394
 
6045 6395
 	// Don't need extra stuff...
6046 6396
 	$db_show_debug = false;
@@ -6048,11 +6398,11 @@  discard block
 block discarded – undo
6048 6398
 	// Kill anything else.
6049 6399
 	ob_end_clean();
6050 6400
 
6051
-	if (!empty($modSettings['CompressedOutput']))
6052
-		@ob_start('ob_gzhandler');
6053
-
6054
-	else
6055
-		ob_start();
6401
+	if (!empty($modSettings['CompressedOutput'])) {
6402
+			@ob_start('ob_gzhandler');
6403
+	} else {
6404
+			ob_start();
6405
+	}
6056 6406
 
6057 6407
 	// Set the header.
6058 6408
 	header($type);
@@ -6084,8 +6434,9 @@  discard block
 block discarded – undo
6084 6434
 	static $done = false;
6085 6435
 
6086 6436
 	// If we don't need to do anything, don't
6087
-	if (!$update && $done)
6088
-		return;
6437
+	if (!$update && $done) {
6438
+			return;
6439
+	}
6089 6440
 
6090 6441
 	// Should we get a new copy of the official list of TLDs?
6091 6442
 	if ($update)
@@ -6097,8 +6448,9 @@  discard block
 block discarded – undo
6097 6448
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
6098 6449
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
6099 6450
 		// update to see if civilization has been restored.
6100
-		if ($tlds === false)
6101
-			$postapocalypticNightmare = true;
6451
+		if ($tlds === false) {
6452
+					$postapocalypticNightmare = true;
6453
+		}
6102 6454
 	}
6103 6455
 	// If we aren't updating and the regex is valid, we're done
6104 6456
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -6113,10 +6465,11 @@  discard block
 block discarded – undo
6113 6465
 		// Clean $tlds and convert it to an array
6114 6466
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
6115 6467
 			$line = trim($line);
6116
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
6117
-				return false;
6118
-			else
6119
-				return true;
6468
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6469
+							return false;
6470
+			} else {
6471
+							return true;
6472
+			}
6120 6473
 		});
6121 6474
 
6122 6475
 		// Convert Punycode to Unicode
@@ -6208,8 +6561,7 @@  discard block
 block discarded – undo
6208 6561
 
6209 6562
 		$strlen = 'mb_strlen';
6210 6563
 		$substr = 'mb_substr';
6211
-	}
6212
-	else
6564
+	} else
6213 6565
 	{
6214 6566
 		$strlen = $smcFunc['strlen'];
6215 6567
 		$substr = $smcFunc['substr'];
@@ -6223,20 +6575,21 @@  discard block
 block discarded – undo
6223 6575
 
6224 6576
 		$first = $substr($string, 0, 1);
6225 6577
 
6226
-		if (empty($index[$first]))
6227
-			$index[$first] = array();
6578
+		if (empty($index[$first])) {
6579
+					$index[$first] = array();
6580
+		}
6228 6581
 
6229 6582
 		if ($strlen($string) > 1)
6230 6583
 		{
6231 6584
 			// Sanity check on recursion
6232
-			if ($depth > 99)
6233
-				$index[$first][$substr($string, 1)] = '';
6234
-
6235
-			else
6236
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6585
+			if ($depth > 99) {
6586
+							$index[$first][$substr($string, 1)] = '';
6587
+			} else {
6588
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6589
+			}
6590
+		} else {
6591
+					$index[$first][''] = '';
6237 6592
 		}
6238
-		else
6239
-			$index[$first][''] = '';
6240 6593
 
6241 6594
 		$depth--;
6242 6595
 		return $index;
@@ -6259,9 +6612,9 @@  discard block
 block discarded – undo
6259 6612
 			$key_regex = preg_quote($key, $delim);
6260 6613
 			$new_key = $key;
6261 6614
 
6262
-			if (empty($value))
6263
-				$sub_regex = '';
6264
-			else
6615
+			if (empty($value)) {
6616
+							$sub_regex = '';
6617
+			} else
6265 6618
 			{
6266 6619
 				$sub_regex = $index_to_regex($value, $delim);
6267 6620
 
@@ -6269,22 +6622,22 @@  discard block
 block discarded – undo
6269 6622
 				{
6270 6623
 					$new_key_array = explode('(?'.'>', $sub_regex);
6271 6624
 					$new_key .= $new_key_array[0];
6625
+				} else {
6626
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6272 6627
 				}
6273
-				else
6274
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6275 6628
 			}
6276 6629
 
6277
-			if ($depth > 1)
6278
-				$regex[$new_key] = $key_regex . $sub_regex;
6279
-			else
6630
+			if ($depth > 1) {
6631
+							$regex[$new_key] = $key_regex . $sub_regex;
6632
+			} else
6280 6633
 			{
6281 6634
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6282 6635
 				{
6283 6636
 					$regex[$new_key] = $key_regex . $sub_regex;
6284 6637
 					unset($index[$key]);
6638
+				} else {
6639
+									break;
6285 6640
 				}
6286
-				else
6287
-					break;
6288 6641
 			}
6289 6642
 		}
6290 6643
 
@@ -6293,10 +6646,11 @@  discard block
 block discarded – undo
6293 6646
 			$l1 = $strlen($k1);
6294 6647
 			$l2 = $strlen($k2);
6295 6648
 
6296
-			if ($l1 == $l2)
6297
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6298
-			else
6299
-				return $l1 > $l2 ? -1 : 1;
6649
+			if ($l1 == $l2) {
6650
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6651
+			} else {
6652
+							return $l1 > $l2 ? -1 : 1;
6653
+			}
6300 6654
 		});
6301 6655
 
6302 6656
 		$depth--;
@@ -6307,21 +6661,24 @@  discard block
 block discarded – undo
6307 6661
 	$index = array();
6308 6662
 	$regex = '';
6309 6663
 
6310
-	foreach ($strings as $string)
6311
-		$index = $add_string_to_index($string, $index);
6664
+	foreach ($strings as $string) {
6665
+			$index = $add_string_to_index($string, $index);
6666
+	}
6312 6667
 
6313 6668
 	if ($returnArray === true)
6314 6669
 	{
6315 6670
 		$regex = array();
6316
-		while (!empty($index))
6317
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6671
+		while (!empty($index)) {
6672
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6673
+		}
6674
+	} else {
6675
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6318 6676
 	}
6319
-	else
6320
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6321 6677
 
6322 6678
 	// Restore PHP's internal character encoding to whatever it was originally
6323
-	if (!empty($current_encoding))
6324
-		mb_internal_encoding($current_encoding);
6679
+	if (!empty($current_encoding)) {
6680
+			mb_internal_encoding($current_encoding);
6681
+	}
6325 6682
 
6326 6683
 	return $regex;
6327 6684
 }
@@ -6364,13 +6721,15 @@  discard block
 block discarded – undo
6364 6721
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6365 6722
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6366 6723
 	$headers = @get_headers($url);
6367
-	if ($headers === false)
6368
-		return false;
6724
+	if ($headers === false) {
6725
+			return false;
6726
+	}
6369 6727
 
6370 6728
 	// Now to see if it came back https...
6371 6729
 	// First check for a redirect status code in first row (301, 302, 307)
6372
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6373
-		return false;
6730
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6731
+			return false;
6732
+	}
6374 6733
 
6375 6734
 	// Search for the location entry to confirm https
6376 6735
 	$result = false;
@@ -6408,8 +6767,7 @@  discard block
 block discarded – undo
6408 6767
 		$is_admin = $user_info['is_admin'];
6409 6768
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6410 6769
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6411
-	}
6412
-	else
6770
+	} else
6413 6771
 	{
6414 6772
 		$request = $smcFunc['db_query']('', '
6415 6773
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6423,17 +6781,19 @@  discard block
 block discarded – undo
6423 6781
 
6424 6782
 		$row = $smcFunc['db_fetch_assoc']($request);
6425 6783
 
6426
-		if (empty($row['additional_groups']))
6427
-			$groups = array($row['id_group'], $row['id_post_group']);
6428
-		else
6429
-			$groups = array_merge(
6784
+		if (empty($row['additional_groups'])) {
6785
+					$groups = array($row['id_group'], $row['id_post_group']);
6786
+		} else {
6787
+					$groups = array_merge(
6430 6788
 					array($row['id_group'], $row['id_post_group']),
6431 6789
 					explode(',', $row['additional_groups'])
6432 6790
 			);
6791
+		}
6433 6792
 
6434 6793
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6435
-		foreach ($groups as $k => $v)
6436
-			$groups[$k] = (int) $v;
6794
+		foreach ($groups as $k => $v) {
6795
+					$groups[$k] = (int) $v;
6796
+		}
6437 6797
 
6438 6798
 		$is_admin = in_array(1, $groups);
6439 6799
 
@@ -6450,8 +6810,9 @@  discard block
 block discarded – undo
6450 6810
 				'current_member' => $userid,
6451 6811
 			)
6452 6812
 		);
6453
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6454
-			$boards_mod[] = $row['id_board'];
6813
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6814
+					$boards_mod[] = $row['id_board'];
6815
+		}
6455 6816
 		$smcFunc['db_free_result']($request);
6456 6817
 
6457 6818
 		// Can any of the groups they're in moderate any of the boards?
@@ -6463,8 +6824,9 @@  discard block
 block discarded – undo
6463 6824
 				'groups' => $groups,
6464 6825
 			)
6465 6826
 		);
6466
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6467
-			$boards_mod[] = $row['id_board'];
6827
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6828
+					$boards_mod[] = $row['id_board'];
6829
+		}
6468 6830
 		$smcFunc['db_free_result']($request);
6469 6831
 
6470 6832
 		// Just in case we've got duplicates here...
@@ -6474,21 +6836,25 @@  discard block
 block discarded – undo
6474 6836
 	}
6475 6837
 
6476 6838
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6477
-	if ($is_admin)
6478
-		$query_part['query_see_board'] = '1=1';
6839
+	if ($is_admin) {
6840
+			$query_part['query_see_board'] = '1=1';
6841
+	}
6479 6842
 	// Otherwise just the groups in $user_info['groups'].
6480
-	else
6481
-		$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'] : '') . ')';
6843
+	else {
6844
+			$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'] : '') . ')';
6845
+	}
6482 6846
 
6483 6847
 	// Build the list of boards they WANT to see.
6484 6848
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6485 6849
 
6486 6850
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6487
-	if (empty($ignoreboards))
6488
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6851
+	if (empty($ignoreboards)) {
6852
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6853
+	}
6489 6854
 	// Ok I guess they don't want to see all the boards
6490
-	else
6491
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6855
+	else {
6856
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6857
+	}
6492 6858
 
6493 6859
 	return $query_part;
6494 6860
 }
@@ -6502,10 +6868,11 @@  discard block
 block discarded – undo
6502 6868
 {
6503 6869
 	$secure = false;
6504 6870
 
6505
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6506
-		$secure = true;
6507
-	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')
6508
-		$secure = true;
6871
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6872
+			$secure = true;
6873
+	} 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') {
6874
+			$secure = true;
6875
+	}
6509 6876
 
6510 6877
 	return $secure;
6511 6878
 }
@@ -6522,11 +6889,12 @@  discard block
 block discarded – undo
6522 6889
 {
6523 6890
 	$url = iri_to_url($iri);
6524 6891
 
6525
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6526
-		return $iri;
6527
-	else
6528
-		return false;
6529
-}
6892
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6893
+			return $iri;
6894
+	} else {
6895
+			return false;
6896
+	}
6897
+	}
6530 6898
 
6531 6899
 /**
6532 6900
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6569,8 +6937,9 @@  discard block
 block discarded – undo
6569 6937
 
6570 6938
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6571 6939
 
6572
-	if (empty($host))
6573
-		return $iri;
6940
+	if (empty($host)) {
6941
+			return $iri;
6942
+	}
6574 6943
 
6575 6944
 	// Convert the domain using the Punycode algorithm
6576 6945
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6606,8 +6975,9 @@  discard block
 block discarded – undo
6606 6975
 
6607 6976
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6608 6977
 
6609
-	if (empty($host))
6610
-		return $url;
6978
+	if (empty($host)) {
6979
+			return $url;
6980
+	}
6611 6981
 
6612 6982
 	// Decode the domain from Punycode
6613 6983
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6633,8 +7003,9 @@  discard block
 block discarded – undo
6633 7003
 {
6634 7004
 	global $user_info, $modSettings, $smcFunc, $txt;
6635 7005
 
6636
-	if (empty($modSettings['cron_last_checked']))
6637
-		$modSettings['cron_last_checked'] = 0;
7006
+	if (empty($modSettings['cron_last_checked'])) {
7007
+			$modSettings['cron_last_checked'] = 0;
7008
+	}
6638 7009
 
6639 7010
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6640 7011
 	{
@@ -6654,9 +7025,9 @@  discard block
 block discarded – undo
6654 7025
 			loadLanguage('ManageScheduledTasks');
6655 7026
 			log_error($txt['cron_not_working']);
6656 7027
 			updateSettings(array('cron_is_real_cron' => 0));
7028
+		} else {
7029
+					updateSettings(array('cron_last_checked' => time()));
6657 7030
 		}
6658
-		else
6659
-			updateSettings(array('cron_last_checked' => time()));
6660 7031
 	}
6661 7032
 }
6662 7033
 
@@ -6680,10 +7051,11 @@  discard block
 block discarded – undo
6680 7051
 
6681 7052
 	$protocol = preg_match('~^\s*(HTTP/[12]\.\d)\s*$~i', $_SERVER['SERVER_PROTOCOL'], $matches) ? $matches[1] : 'HTTP/1.0';
6682 7053
 
6683
-	if (!isset($statuses[$code]) && empty($status))
6684
-		header($protocol . ' 500 Internal Server Error');
6685
-	else
6686
-		header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code]));
6687
-}
7054
+	if (!isset($statuses[$code]) && empty($status)) {
7055
+			header($protocol . ' 500 Internal Server Error');
7056
+	} else {
7057
+			header($protocol . ' ' . $code . ' ' . (!empty($status) ? $status : $statuses[$code]));
7058
+	}
7059
+	}
6688 7060
 
6689 7061
 ?>
6690 7062
\ No newline at end of file
Please login to merge, or discard this patch.