Completed
Push — release-2.1 ( 9fa566...084464 )
by Colin
17:59 queued 10:04
created
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');
@@ -92,8 +95,9 @@  discard block
 block discarded – undo
92 95
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
93 96
 
94 97
 	// Check to ensure we're forcing SSL for authentication
95
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
96
-		fatal_lang_error('login_ssl_required');
98
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
99
+			fatal_lang_error('login_ssl_required');
100
+	}
97 101
 
98 102
 	// Load cookie authentication stuff.
99 103
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -107,23 +111,26 @@  discard block
 block discarded – undo
107 111
 	if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest'])
108 112
 	{
109 113
 		// First check for 2.1 json-format cookie in $_COOKIE
110
-		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1)
111
-			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
114
+		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) {
115
+					list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
116
+		}
112 117
 
113 118
 		// Try checking for 2.1 json-format cookie in $_SESSION
114
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1)
115
-			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
119
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) {
120
+					list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
121
+		}
116 122
 
117 123
 		// Next, try checking for 2.0 serialized string cookie in $_COOKIE
118
-		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)
119
-			list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
124
+		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) {
125
+					list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
126
+		}
120 127
 
121 128
 		// Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION
122
-		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)
123
-			list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
124
-
125
-		else
126
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
129
+		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) {
130
+					list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
131
+		} else {
132
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
133
+		}
127 134
 
128 135
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
129 136
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -143,24 +150,23 @@  discard block
 block discarded – undo
143 150
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
144 151
 	{
145 152
 		// Strike!  You're outta there!
146
-		if ($_GET['member'] != $user_info['id'])
147
-			fatal_lang_error('login_cookie_error', false);
153
+		if ($_GET['member'] != $user_info['id']) {
154
+					fatal_lang_error('login_cookie_error', false);
155
+		}
148 156
 
149 157
 		$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']))));
150 158
 
151 159
 		// Some whitelisting for login_url...
152
-		if (empty($_SESSION['login_url']))
153
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
154
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
160
+		if (empty($_SESSION['login_url'])) {
161
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
162
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
155 163
 		{
156 164
 			unset ($_SESSION['login_url']);
157 165
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
158
-		}
159
-		elseif (!empty($user_settings['tfa_secret']))
166
+		} elseif (!empty($user_settings['tfa_secret']))
160 167
 		{
161 168
 			redirectexit('action=logintfa');
162
-		}
163
-		else
169
+		} else
164 170
 		{
165 171
 			// Best not to clutter the session data too much...
166 172
 			$temp = $_SESSION['login_url'];
@@ -171,8 +177,9 @@  discard block
 block discarded – undo
171 177
 	}
172 178
 
173 179
 	// Beyond this point you are assumed to be a guest trying to login.
174
-	if (!$user_info['is_guest'])
175
-		redirectexit();
180
+	if (!$user_info['is_guest']) {
181
+			redirectexit();
182
+	}
176 183
 
177 184
 	// Are you guessing with a script?
178 185
 	checkSession();
@@ -180,18 +187,21 @@  discard block
 block discarded – undo
180 187
 	spamProtection('login');
181 188
 
182 189
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
183
-	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))
184
-		$_SESSION['login_url'] = $_SESSION['old_url'];
190
+	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)) {
191
+			$_SESSION['login_url'] = $_SESSION['old_url'];
192
+	}
185 193
 
186 194
 	// Been guessing a lot, haven't we?
187
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
188
-		fatal_lang_error('login_threshold_fail', 'login');
195
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
196
+			fatal_lang_error('login_threshold_fail', 'login');
197
+	}
189 198
 
190 199
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
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'];
200
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
201
+			$modSettings['cookieTime'] = 3153600;
202
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600)) {
203
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
204
+	}
195 205
 
196 206
 	// Login Cookie times. Format: time => txt
197 207
 	$context['login_cookie_times'] = array(
@@ -320,8 +330,9 @@  discard block
 block discarded – undo
320 330
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
321 331
 
322 332
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
323
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
324
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
333
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
334
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
335
+			}
325 336
 
326 337
 			// phpBB3 users new hashing.  We now support it as well ;).
327 338
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -341,27 +352,29 @@  discard block
 block discarded – undo
341 352
 			// Some common md5 ones.
342 353
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
343 354
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
344
-		}
345
-		elseif (strlen($user_settings['passwd']) == 40)
355
+		} elseif (strlen($user_settings['passwd']) == 40)
346 356
 		{
347 357
 			// Maybe they are using a hash from before the password fix.
348 358
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
349 359
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
350 360
 
351 361
 			// BurningBoard3 style of hashing.
352
-			if (!empty($modSettings['enable_password_conversion']))
353
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
362
+			if (!empty($modSettings['enable_password_conversion'])) {
363
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
364
+			}
354 365
 
355 366
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
356 367
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
357 368
 			{
358 369
 				// Try iconv first, for no particular reason.
359
-				if (function_exists('iconv'))
360
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
370
+				if (function_exists('iconv')) {
371
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
372
+				}
361 373
 
362 374
 				// Say it aint so, iconv failed!
363
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
364
-					$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'])));
375
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
376
+									$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'])));
377
+				}
365 378
 			}
366 379
 		}
367 380
 
@@ -391,8 +404,9 @@  discard block
 block discarded – undo
391 404
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
392 405
 
393 406
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
394
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
395
-				redirectexit('action=reminder');
407
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
408
+							redirectexit('action=reminder');
409
+			}
396 410
 			// We'll give you another chance...
397 411
 			else
398 412
 			{
@@ -403,8 +417,7 @@  discard block
 block discarded – undo
403 417
 				return;
404 418
 			}
405 419
 		}
406
-	}
407
-	elseif (!empty($user_settings['passwd_flood']))
420
+	} elseif (!empty($user_settings['passwd_flood']))
408 421
 	{
409 422
 		// Let's be sure they weren't a little hacker.
410 423
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -421,8 +434,9 @@  discard block
 block discarded – undo
421 434
 	}
422 435
 
423 436
 	// Check their activation status.
424
-	if (!checkActivation())
425
-		return;
437
+	if (!checkActivation()) {
438
+			return;
439
+	}
426 440
 
427 441
 	DoLogin();
428 442
 }
@@ -434,8 +448,9 @@  discard block
 block discarded – undo
434 448
 {
435 449
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
436 450
 
437
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
438
-		fatal_lang_error('no_access', false);
451
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
452
+			fatal_lang_error('no_access', false);
453
+	}
439 454
 
440 455
 	loadLanguage('Profile');
441 456
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -443,8 +458,9 @@  discard block
 block discarded – undo
443 458
 	$member = $context['tfa_member'];
444 459
 
445 460
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
446
-	if (time() - $member['last_login'] < 120)
447
-		fatal_lang_error('tfa_wait', false);
461
+	if (time() - $member['last_login'] < 120) {
462
+			fatal_lang_error('tfa_wait', false);
463
+	}
448 464
 
449 465
 	$totp = new \TOTP\Auth($member['tfa_secret']);
450 466
 	$totp->setRange(1);
@@ -458,8 +474,9 @@  discard block
 block discarded – undo
458 474
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
459 475
 	{
460 476
 		// Check to ensure we're forcing SSL for authentication
461
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
462
-			fatal_lang_error('login_ssl_required');
477
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
478
+					fatal_lang_error('login_ssl_required');
479
+		}
463 480
 
464 481
 		$code = $_POST['tfa_code'];
465 482
 
@@ -469,20 +486,19 @@  discard block
 block discarded – undo
469 486
 
470 487
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
471 488
 			redirectexit();
472
-		}
473
-		else
489
+		} else
474 490
 		{
475 491
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
476 492
 
477 493
 			$context['tfa_error'] = true;
478 494
 			$context['tfa_value'] = $_POST['tfa_code'];
479 495
 		}
480
-	}
481
-	elseif (!empty($_POST['tfa_backup']))
496
+	} elseif (!empty($_POST['tfa_backup']))
482 497
 	{
483 498
 		// Check to ensure we're forcing SSL for authentication
484
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
485
-			fatal_lang_error('login_ssl_required');
499
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
500
+					fatal_lang_error('login_ssl_required');
501
+		}
486 502
 
487 503
 		$backup = $_POST['tfa_backup'];
488 504
 
@@ -496,8 +512,7 @@  discard block
 block discarded – undo
496 512
 			));
497 513
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
498 514
 			redirectexit('action=profile;area=tfasetup;backup');
499
-		}
500
-		else
515
+		} else
501 516
 		{
502 517
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
503 518
 
@@ -520,8 +535,9 @@  discard block
 block discarded – undo
520 535
 {
521 536
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
522 537
 
523
-	if (!isset($context['login_errors']))
524
-		$context['login_errors'] = array();
538
+	if (!isset($context['login_errors'])) {
539
+			$context['login_errors'] = array();
540
+	}
525 541
 
526 542
 	// What is the true activation status of this account?
527 543
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -533,8 +549,9 @@  discard block
 block discarded – undo
533 549
 		return false;
534 550
 	}
535 551
 	// Awaiting approval still?
536
-	elseif ($activation_status == 3)
537
-		fatal_lang_error('still_awaiting_approval', 'user');
552
+	elseif ($activation_status == 3) {
553
+			fatal_lang_error('still_awaiting_approval', 'user');
554
+	}
538 555
 	// Awaiting deletion, changed their mind?
539 556
 	elseif ($activation_status == 4)
540 557
 	{
@@ -542,8 +559,7 @@  discard block
 block discarded – undo
542 559
 		{
543 560
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
544 561
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
545
-		}
546
-		else
562
+		} else
547 563
 		{
548 564
 			$context['disable_login_hashing'] = true;
549 565
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -583,8 +599,9 @@  discard block
 block discarded – undo
583 599
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
584 600
 
585 601
 	// Reset the login threshold.
586
-	if (isset($_SESSION['failed_login']))
587
-		unset($_SESSION['failed_login']);
602
+	if (isset($_SESSION['failed_login'])) {
603
+			unset($_SESSION['failed_login']);
604
+	}
588 605
 
589 606
 	$user_info['is_guest'] = false;
590 607
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -606,16 +623,18 @@  discard block
 block discarded – undo
606 623
 			'id_member' => $user_info['id'],
607 624
 		)
608 625
 	);
609
-	if ($smcFunc['db_num_rows']($request) == 1)
610
-		$_SESSION['first_login'] = true;
611
-	else
612
-		unset($_SESSION['first_login']);
626
+	if ($smcFunc['db_num_rows']($request) == 1) {
627
+			$_SESSION['first_login'] = true;
628
+	} else {
629
+			unset($_SESSION['first_login']);
630
+	}
613 631
 	$smcFunc['db_free_result']($request);
614 632
 
615 633
 	// You've logged in, haven't you?
616 634
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
617
-	if (empty($user_settings['tfa_secret']))
618
-		$update['last_login'] = time();
635
+	if (empty($user_settings['tfa_secret'])) {
636
+			$update['last_login'] = time();
637
+	}
619 638
 	updateMemberData($user_info['id'], $update);
620 639
 
621 640
 	// Get rid of the online entry for that old guest....
@@ -629,8 +648,8 @@  discard block
 block discarded – undo
629 648
 	$_SESSION['log_time'] = 0;
630 649
 
631 650
 	// Log this entry, only if we have it enabled.
632
-	if (!empty($modSettings['loginHistoryDays']))
633
-		$smcFunc['db_insert']('insert',
651
+	if (!empty($modSettings['loginHistoryDays'])) {
652
+			$smcFunc['db_insert']('insert',
634 653
 			'{db_prefix}member_logins',
635 654
 			array(
636 655
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -642,13 +661,15 @@  discard block
 block discarded – undo
642 661
 				'id_member', 'time'
643 662
 			)
644 663
 		);
664
+	}
645 665
 
646 666
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
647
-	if (empty($maintenance) || allowedTo('admin_forum'))
648
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
649
-	else
650
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
651
-}
667
+	if (empty($maintenance) || allowedTo('admin_forum')) {
668
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
669
+	} else {
670
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
671
+	}
672
+	}
652 673
 
653 674
 /**
654 675
  * Logs the current user out of their account.
@@ -664,13 +685,15 @@  discard block
 block discarded – undo
664 685
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
665 686
 
666 687
 	// Make sure they aren't being auto-logged out.
667
-	if (!$internal)
668
-		checkSession('get');
688
+	if (!$internal) {
689
+			checkSession('get');
690
+	}
669 691
 
670 692
 	require_once($sourcedir . '/Subs-Auth.php');
671 693
 
672
-	if (isset($_SESSION['pack_ftp']))
673
-		$_SESSION['pack_ftp'] = null;
694
+	if (isset($_SESSION['pack_ftp'])) {
695
+			$_SESSION['pack_ftp'] = null;
696
+	}
674 697
 
675 698
 	// It won't be first login anymore.
676 699
 	unset($_SESSION['first_login']);
@@ -698,8 +721,9 @@  discard block
 block discarded – undo
698 721
 
699 722
 	// And some other housekeeping while we're at it.
700 723
 	$salt = substr(md5(mt_rand()), 0, 4);
701
-	if (!empty($user_info['id']))
702
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
724
+	if (!empty($user_info['id'])) {
725
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
726
+	}
703 727
 
704 728
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
705 729
 	{
@@ -712,14 +736,13 @@  discard block
 block discarded – undo
712 736
 	// Off to the merry board index we go!
713 737
 	if ($redirect)
714 738
 	{
715
-		if (empty($_SESSION['logout_url']))
716
-			redirectexit('', $context['server']['needs_login_fix']);
717
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
739
+		if (empty($_SESSION['logout_url'])) {
740
+					redirectexit('', $context['server']['needs_login_fix']);
741
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
718 742
 		{
719 743
 			unset ($_SESSION['logout_url']);
720 744
 			redirectexit();
721
-		}
722
-		else
745
+		} else
723 746
 		{
724 747
 			$temp = $_SESSION['logout_url'];
725 748
 			unset($_SESSION['logout_url']);
@@ -752,8 +775,9 @@  discard block
 block discarded – undo
752 775
 function phpBB3_password_check($passwd, $passwd_hash)
753 776
 {
754 777
 	// Too long or too short?
755
-	if (strlen($passwd_hash) != 34)
756
-		return;
778
+	if (strlen($passwd_hash) != 34) {
779
+			return;
780
+	}
757 781
 
758 782
 	// Range of characters allowed.
759 783
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -764,8 +788,9 @@  discard block
 block discarded – undo
764 788
 	$salt = substr($passwd_hash, 4, 8);
765 789
 
766 790
 	$hash = md5($salt . $passwd, true);
767
-	for (; $count != 0; --$count)
768
-		$hash = md5($hash . $passwd, true);
791
+	for (; $count != 0; --$count) {
792
+			$hash = md5($hash . $passwd, true);
793
+	}
769 794
 
770 795
 	$output = substr($passwd_hash, 0, 12);
771 796
 	$i = 0;
@@ -774,21 +799,25 @@  discard block
 block discarded – undo
774 799
 		$value = ord($hash[$i++]);
775 800
 		$output .= $range[$value & 0x3f];
776 801
 
777
-		if ($i < 16)
778
-			$value |= ord($hash[$i]) << 8;
802
+		if ($i < 16) {
803
+					$value |= ord($hash[$i]) << 8;
804
+		}
779 805
 
780 806
 		$output .= $range[($value >> 6) & 0x3f];
781 807
 
782
-		if ($i++ >= 16)
783
-			break;
808
+		if ($i++ >= 16) {
809
+					break;
810
+		}
784 811
 
785
-		if ($i < 16)
786
-			$value |= ord($hash[$i]) << 16;
812
+		if ($i < 16) {
813
+					$value |= ord($hash[$i]) << 16;
814
+		}
787 815
 
788 816
 		$output .= $range[($value >> 12) & 0x3f];
789 817
 
790
-		if ($i++ >= 16)
791
-			break;
818
+		if ($i++ >= 16) {
819
+					break;
820
+		}
792 821
 
793 822
 		$output .= $range[($value >> 18) & 0x3f];
794 823
 	}
@@ -820,8 +849,9 @@  discard block
 block discarded – undo
820 849
 		require_once($sourcedir . '/Subs-Auth.php');
821 850
 		setLoginCookie(-3600, 0);
822 851
 
823
-		if (isset($_SESSION['login_' . $cookiename]))
824
-			unset($_SESSION['login_' . $cookiename]);
852
+		if (isset($_SESSION['login_' . $cookiename])) {
853
+					unset($_SESSION['login_' . $cookiename]);
854
+		}
825 855
 	}
826 856
 
827 857
 	// We need a member!
@@ -835,8 +865,9 @@  discard block
 block discarded – undo
835 865
 	}
836 866
 
837 867
 	// Right, have we got a flood value?
838
-	if ($password_flood_value !== false)
839
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
868
+	if ($password_flood_value !== false) {
869
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
870
+	}
840 871
 
841 872
 	// Timestamp or number of tries invalid?
842 873
 	if (empty($number_tries) || empty($time_stamp))
@@ -852,15 +883,17 @@  discard block
 block discarded – undo
852 883
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
853 884
 
854 885
 		// They are trying too fast, make them wait longer
855
-		if ($time_stamp < time() - 10)
856
-			$time_stamp = time();
886
+		if ($time_stamp < time() - 10) {
887
+					$time_stamp = time();
888
+		}
857 889
 	}
858 890
 
859 891
 	$number_tries++;
860 892
 
861 893
 	// Broken the law?
862
-	if ($number_tries > 5)
863
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
894
+	if ($number_tries > 5) {
895
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
896
+	}
864 897
 
865 898
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
866 899
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +470 added lines, -350 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 
66
-			if ($charcode == 'UTF8')
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting for fatal errors.
154 160
 	error_reporting(E_ERROR | E_PARSE);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -230,10 +239,11 @@  discard block
 block discarded – undo
230 239
 		// Now just redirect to a blank.png...
231 240
 		$secure = false;
232 241
 
233
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
234
-			$secure = true;
235
-		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')
236
-			$secure = true;
242
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
243
+					$secure = true;
244
+		} 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') {
245
+					$secure = true;
246
+		}
237 247
 
238 248
 		header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
239 249
 		exit;
@@ -244,10 +254,11 @@  discard block
 block discarded – undo
244 254
 	{
245 255
 		// Get PHP's default timezone, if set
246 256
 		$ini_tz = ini_get('date.timezone');
247
-		if (!empty($ini_tz))
248
-			$timezone_id = $ini_tz;
249
-		else
250
-			$timezone_id = '';
257
+		if (!empty($ini_tz)) {
258
+					$timezone_id = $ini_tz;
259
+		} else {
260
+					$timezone_id = '';
261
+		}
251 262
 
252 263
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
253 264
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -277,8 +288,9 @@  discard block
 block discarded – undo
277 288
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
278 289
 		while ($entry = $dir->read())
279 290
 		{
280
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
281
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
291
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
292
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
293
+			}
282 294
 		}
283 295
 		$dir->close();
284 296
 	}
@@ -325,10 +337,11 @@  discard block
 block discarded – undo
325 337
 	}
326 338
 
327 339
 	// Override the language file?
328
-	if (isset($_GET['lang_file']))
329
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
331
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
340
+	if (isset($_GET['lang_file'])) {
341
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
342
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
343
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
344
+	}
332 345
 
333 346
 	// Make sure it exists, if it doesn't reset it.
334 347
 	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']))
@@ -337,8 +350,9 @@  discard block
 block discarded – undo
337 350
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
338 351
 
339 352
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
340
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
341
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
353
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
354
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
355
+		}
342 356
 	}
343 357
 
344 358
 	// And now include the actual language file itself.
@@ -355,15 +369,18 @@  discard block
 block discarded – undo
355 369
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings;
356 370
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist;
357 371
 
358
-	if (empty($sourcedir))
359
-		$sourcedir = dirname(__FILE__) . '/Sources';
372
+	if (empty($sourcedir)) {
373
+			$sourcedir = dirname(__FILE__) . '/Sources';
374
+	}
360 375
 
361 376
 	// Need this to check whether we need the database password.
362 377
 	require(dirname(__FILE__) . '/Settings.php');
363
-	if (!defined('SMF'))
364
-		define('SMF', 1);
365
-	if (empty($smcFunc))
366
-		$smcFunc = array();
378
+	if (!defined('SMF')) {
379
+			define('SMF', 1);
380
+	}
381
+	if (empty($smcFunc)) {
382
+			$smcFunc = array();
383
+	}
367 384
 
368 385
 	$modSettings['disableQueryCheck'] = true;
369 386
 
@@ -371,8 +388,9 @@  discard block
 block discarded – undo
371 388
 	if (!$db_connection)
372 389
 	{
373 390
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
374
-		if (version_compare(PHP_VERSION, '5', '<'))
375
-			require_once($sourcedir . '/Subs-Compat.php');
391
+		if (version_compare(PHP_VERSION, '5', '<')) {
392
+					require_once($sourcedir . '/Subs-Compat.php');
393
+		}
376 394
 
377 395
 		$db_options = array('persist' => $db_persist);
378 396
 		$port = '';
@@ -383,19 +401,20 @@  discard block
 block discarded – undo
383 401
 			if ($db_type == 'mysql')
384 402
 			{
385 403
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
386
-			}
387
-			elseif ($db_type == 'postgresql')
404
+			} elseif ($db_type == 'postgresql')
388 405
 			{
389 406
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
390 407
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
391 408
 			}
392 409
 		}
393 410
 
394
-		if (!empty($port))
395
-			$db_options['port'] = $port;
411
+		if (!empty($port)) {
412
+					$db_options['port'] = $port;
413
+		}
396 414
 
397
-		if (!$db_connection)
398
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
415
+		if (!$db_connection) {
416
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
417
+		}
399 418
 	}
400 419
 }
401 420
 
@@ -423,8 +442,9 @@  discard block
 block discarded – undo
423 442
 		// @todo REMOVE THIS!!
424 443
 		else
425 444
 		{
426
-			if (function_exists('doStep' . $_GET['step']))
427
-				call_user_func('doStep' . $_GET['step']);
445
+			if (function_exists('doStep' . $_GET['step'])) {
446
+							call_user_func('doStep' . $_GET['step']);
447
+			}
428 448
 		}
429 449
 		// Show the footer.
430 450
 		template_install_below();
@@ -442,8 +462,9 @@  discard block
 block discarded – undo
442 462
 	$incontext['sub_template'] = 'welcome_message';
443 463
 
444 464
 	// Done the submission?
445
-	if (isset($_POST['contbutt']))
446
-		return true;
465
+	if (isset($_POST['contbutt'])) {
466
+			return true;
467
+	}
447 468
 
448 469
 	// See if we think they have already installed it?
449 470
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -451,14 +472,17 @@  discard block
 block discarded – undo
451 472
 		$probably_installed = 0;
452 473
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
453 474
 		{
454
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
455
-				$probably_installed++;
456
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
457
-				$probably_installed++;
475
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
476
+							$probably_installed++;
477
+			}
478
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
479
+							$probably_installed++;
480
+			}
458 481
 		}
459 482
 
460
-		if ($probably_installed == 2)
461
-			$incontext['warning'] = $txt['error_already_installed'];
483
+		if ($probably_installed == 2) {
484
+					$incontext['warning'] = $txt['error_already_installed'];
485
+		}
462 486
 	}
463 487
 
464 488
 	// Is some database support even compiled in?
@@ -473,45 +497,54 @@  discard block
 block discarded – undo
473 497
 				$databases[$key]['supported'] = false;
474 498
 				$notFoundSQLFile = true;
475 499
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
500
+			} else {
501
+							$incontext['supported_databases'][] = $db;
476 502
 			}
477
-			else
478
-				$incontext['supported_databases'][] = $db;
479 503
 		}
480 504
 	}
481 505
 
482 506
 	// Check the PHP version.
483
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
484
-		$error = 'error_php_too_low';
507
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
508
+			$error = 'error_php_too_low';
509
+	}
485 510
 	// Make sure we have a supported database
486
-	elseif (empty($incontext['supported_databases']))
487
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
511
+	elseif (empty($incontext['supported_databases'])) {
512
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
513
+	}
488 514
 	// How about session support?  Some crazy sysadmin remove it?
489
-	elseif (!function_exists('session_start'))
490
-		$error = 'error_session_missing';
515
+	elseif (!function_exists('session_start')) {
516
+			$error = 'error_session_missing';
517
+	}
491 518
 	// Make sure they uploaded all the files.
492
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
493
-		$error = 'error_missing_files';
519
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
520
+			$error = 'error_missing_files';
521
+	}
494 522
 	// Very simple check on the session.save_path for Windows.
495 523
 	// @todo Move this down later if they don't use database-driven sessions?
496
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
497
-		$error = 'error_session_save_path';
524
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
525
+			$error = 'error_session_save_path';
526
+	}
498 527
 
499 528
 	// Since each of the three messages would look the same, anyway...
500
-	if (isset($error))
501
-		$incontext['error'] = $txt[$error];
529
+	if (isset($error)) {
530
+			$incontext['error'] = $txt[$error];
531
+	}
502 532
 
503 533
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
504
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
505
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
534
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
535
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
536
+	}
506 537
 
507 538
 	// Confirm mbstring is loaded...
508
-	if (!extension_loaded('mbstring'))
509
-		$incontext['error'] = $txt['install_no_mbstring'];
539
+	if (!extension_loaded('mbstring')) {
540
+			$incontext['error'] = $txt['install_no_mbstring'];
541
+	}
510 542
 
511 543
 	// Check for https stream support.
512 544
 	$supported_streams = stream_get_wrappers();
513
-	if (!in_array('https', $supported_streams))
514
-		$incontext['warning'] = $txt['install_no_https'];
545
+	if (!in_array('https', $supported_streams)) {
546
+			$incontext['warning'] = $txt['install_no_https'];
547
+	}
515 548
 
516 549
 	return false;
517 550
 }
@@ -536,12 +569,14 @@  discard block
 block discarded – undo
536 569
 		'Settings_bak.php',
537 570
 	);
538 571
 
539
-	foreach ($incontext['detected_languages'] as $lang => $temp)
540
-		$extra_files[] = 'Themes/default/languages/' . $lang;
572
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
573
+			$extra_files[] = 'Themes/default/languages/' . $lang;
574
+	}
541 575
 
542 576
 	// With mod_security installed, we could attempt to fix it with .htaccess.
543
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
544
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
577
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
578
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
579
+	}
545 580
 
546 581
 	$failed_files = array();
547 582
 
@@ -553,20 +588,23 @@  discard block
 block discarded – undo
553 588
 		foreach ($writable_files as $file)
554 589
 		{
555 590
 			// Some files won't exist, try to address up front
556
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
557
-				@touch(dirname(__FILE__) . '/' . $file);
591
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
592
+							@touch(dirname(__FILE__) . '/' . $file);
593
+			}
558 594
 			// NOW do the writable check...
559 595
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
560 596
 			{
561 597
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
562 598
 
563 599
 				// Well, 755 hopefully worked... if not, try 777.
564
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
565
-					$failed_files[] = $file;
600
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
601
+									$failed_files[] = $file;
602
+				}
566 603
 			}
567 604
 		}
568
-		foreach ($extra_files as $file)
569
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
605
+		foreach ($extra_files as $file) {
606
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
607
+		}
570 608
 	}
571 609
 	// Windows is trickier.  Let's try opening for r+...
572 610
 	else
@@ -576,30 +614,35 @@  discard block
 block discarded – undo
576 614
 		foreach ($writable_files as $file)
577 615
 		{
578 616
 			// Folders can't be opened for write... but the index.php in them can ;)
579
-			if (is_dir(dirname(__FILE__) . '/' . $file))
580
-				$file .= '/index.php';
617
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
618
+							$file .= '/index.php';
619
+			}
581 620
 
582 621
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
583 622
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
584 623
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
585 624
 
586 625
 			// Hmm, okay, try just for write in that case...
587
-			if (!is_resource($fp))
588
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
626
+			if (!is_resource($fp)) {
627
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
628
+			}
589 629
 
590
-			if (!is_resource($fp))
591
-				$failed_files[] = $file;
630
+			if (!is_resource($fp)) {
631
+							$failed_files[] = $file;
632
+			}
592 633
 
593 634
 			@fclose($fp);
594 635
 		}
595
-		foreach ($extra_files as $file)
596
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
636
+		foreach ($extra_files as $file) {
637
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
638
+		}
597 639
 	}
598 640
 
599 641
 	$failure = count($failed_files) >= 1;
600 642
 
601
-	if (!isset($_SERVER))
602
-		return !$failure;
643
+	if (!isset($_SERVER)) {
644
+			return !$failure;
645
+	}
603 646
 
604 647
 	// Put the list into context.
605 648
 	$incontext['failed_files'] = $failed_files;
@@ -647,19 +690,23 @@  discard block
 block discarded – undo
647 690
 
648 691
 		if (!isset($ftp) || $ftp->error !== false)
649 692
 		{
650
-			if (!isset($ftp))
651
-				$ftp = new ftp_connection(null);
693
+			if (!isset($ftp)) {
694
+							$ftp = new ftp_connection(null);
695
+			}
652 696
 			// Save the error so we can mess with listing...
653
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
654
-				$incontext['ftp_errors'][] = $ftp->last_message;
697
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
698
+							$incontext['ftp_errors'][] = $ftp->last_message;
699
+			}
655 700
 
656 701
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
657 702
 
658
-			if (empty($_POST['ftp_path']) && $found_path)
659
-				$_POST['ftp_path'] = $detect_path;
703
+			if (empty($_POST['ftp_path']) && $found_path) {
704
+							$_POST['ftp_path'] = $detect_path;
705
+			}
660 706
 
661
-			if (!isset($_POST['ftp_username']))
662
-				$_POST['ftp_username'] = $username;
707
+			if (!isset($_POST['ftp_username'])) {
708
+							$_POST['ftp_username'] = $username;
709
+			}
663 710
 
664 711
 			// Set the username etc, into context.
665 712
 			$incontext['ftp'] = array(
@@ -671,8 +718,7 @@  discard block
 block discarded – undo
671 718
 			);
672 719
 
673 720
 			return false;
674
-		}
675
-		else
721
+		} else
676 722
 		{
677 723
 			$_SESSION['installer_temp_ftp'] = array(
678 724
 				'server' => $_POST['ftp_server'],
@@ -686,10 +732,12 @@  discard block
 block discarded – undo
686 732
 
687 733
 			foreach ($failed_files as $file)
688 734
 			{
689
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
690
-					$ftp->chmod($file, 0755);
691
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
692
-					$ftp->chmod($file, 0777);
735
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
736
+									$ftp->chmod($file, 0755);
737
+				}
738
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
739
+									$ftp->chmod($file, 0777);
740
+				}
693 741
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
694 742
 				{
695 743
 					$failed_files_updated[] = $file;
@@ -745,15 +793,17 @@  discard block
 block discarded – undo
745 793
 
746 794
 			if (!$foundOne)
747 795
 			{
748
-				if (isset($db['default_host']))
749
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
796
+				if (isset($db['default_host'])) {
797
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
798
+				}
750 799
 				if (isset($db['default_user']))
751 800
 				{
752 801
 					$incontext['db']['user'] = ini_get($db['default_user']);
753 802
 					$incontext['db']['name'] = ini_get($db['default_user']);
754 803
 				}
755
-				if (isset($db['default_password']))
756
-					$incontext['db']['pass'] = ini_get($db['default_password']);
804
+				if (isset($db['default_password'])) {
805
+									$incontext['db']['pass'] = ini_get($db['default_password']);
806
+				}
757 807
 
758 808
 				// For simplicity and less confusion, leave the port blank by default
759 809
 				$incontext['db']['port'] = '';
@@ -772,10 +822,10 @@  discard block
 block discarded – undo
772 822
 		$incontext['db']['server'] = $_POST['db_server'];
773 823
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
774 824
 
775
-		if (!empty($_POST['db_port']))
776
-			$incontext['db']['port'] = $_POST['db_port'];
777
-	}
778
-	else
825
+		if (!empty($_POST['db_port'])) {
826
+					$incontext['db']['port'] = $_POST['db_port'];
827
+		}
828
+	} else
779 829
 	{
780 830
 		$incontext['db']['prefix'] = 'smf_';
781 831
 	}
@@ -811,10 +861,11 @@  discard block
 block discarded – undo
811 861
 		if (!empty($_POST['db_port']))
812 862
 		{
813 863
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
814
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
815
-				$vars['db_port'] = (int) $_POST['db_port'];
816
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
817
-				$vars['db_port'] = (int) $_POST['db_port'];
864
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
865
+							$vars['db_port'] = (int) $_POST['db_port'];
866
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
867
+							$vars['db_port'] = (int) $_POST['db_port'];
868
+			}
818 869
 		}
819 870
 
820 871
 		// God I hope it saved!
@@ -827,8 +878,9 @@  discard block
 block discarded – undo
827 878
 		// Make sure it works.
828 879
 		require(dirname(__FILE__) . '/Settings.php');
829 880
 
830
-		if (empty($sourcedir))
831
-			$sourcedir = dirname(__FILE__) . '/Sources';
881
+		if (empty($sourcedir)) {
882
+					$sourcedir = dirname(__FILE__) . '/Sources';
883
+		}
832 884
 
833 885
 		// Better find the database file!
834 886
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -838,18 +890,21 @@  discard block
 block discarded – undo
838 890
 		}
839 891
 
840 892
 		// Now include it for database functions!
841
-		if (!defined('SMF'))
842
-			define('SMF', 1);
893
+		if (!defined('SMF')) {
894
+					define('SMF', 1);
895
+		}
843 896
 
844 897
 		$modSettings['disableQueryCheck'] = true;
845
-		if (empty($smcFunc))
846
-			$smcFunc = array();
898
+		if (empty($smcFunc)) {
899
+					$smcFunc = array();
900
+		}
847 901
 
848 902
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
849 903
 
850 904
 		// What - running PHP4? The shame!
851
-		if (version_compare(PHP_VERSION, '5', '<'))
852
-			require_once($sourcedir . '/Subs-Compat.php');
905
+		if (version_compare(PHP_VERSION, '5', '<')) {
906
+					require_once($sourcedir . '/Subs-Compat.php');
907
+		}
853 908
 
854 909
 		// Attempt a connection.
855 910
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -937,12 +992,14 @@  discard block
 block discarded – undo
937 992
 	$incontext['page_title'] = $txt['install_settings'];
938 993
 
939 994
 	// Let's see if we got the database type correct.
940
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
941
-		$db_type = $_POST['db_type'];
995
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
996
+			$db_type = $_POST['db_type'];
997
+	}
942 998
 
943 999
 	// Else we'd better be able to get the connection.
944
-	else
945
-		load_database();
1000
+	else {
1001
+			load_database();
1002
+	}
946 1003
 
947 1004
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
948 1005
 
@@ -951,10 +1008,11 @@  discard block
 block discarded – undo
951 1008
 
952 1009
 		$secure = false;
953 1010
 
954
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
955
-			$secure = true;
956
-		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')
957
-			$secure = true;
1011
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1012
+					$secure = true;
1013
+		} 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') {
1014
+					$secure = true;
1015
+		}
958 1016
 
959 1017
 	// Now, to put what we've learned together... and add a path.
960 1018
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -986,18 +1044,21 @@  discard block
 block discarded – undo
986 1044
 	// Submitting?
987 1045
 	if (isset($_POST['boardurl']))
988 1046
 	{
989
-		if (substr($_POST['boardurl'], -10) == '/index.php')
990
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
991
-		elseif (substr($_POST['boardurl'], -1) == '/')
992
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
993
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
994
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1047
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1048
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1049
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1050
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1051
+		}
1052
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1053
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1054
+		}
995 1055
 
996 1056
 		//Make sure boardurl is aligned with ssl setting
997
-		if (empty($_POST['force_ssl']))
998
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
999
-		else
1000
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1057
+		if (empty($_POST['force_ssl'])) {
1058
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1059
+		} else {
1060
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1061
+		}
1001 1062
 
1002 1063
 		// Save these variables.
1003 1064
 		$vars = array(
@@ -1036,10 +1097,10 @@  discard block
 block discarded – undo
1036 1097
 			{
1037 1098
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1038 1099
 				return false;
1039
-			}
1040
-			else
1041
-				// Set the character set here.
1100
+			} else {
1101
+							// Set the character set here.
1042 1102
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1103
+			}
1043 1104
 		}
1044 1105
 
1045 1106
 		// Good, skip on.
@@ -1059,8 +1120,9 @@  discard block
 block discarded – undo
1059 1120
 	$incontext['continue'] = 1;
1060 1121
 
1061 1122
 	// Already done?
1062
-	if (isset($_POST['pop_done']))
1063
-		return true;
1123
+	if (isset($_POST['pop_done'])) {
1124
+			return true;
1125
+	}
1064 1126
 
1065 1127
 	// Reload settings.
1066 1128
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1078,8 +1140,9 @@  discard block
 block discarded – undo
1078 1140
 	$modSettings = array();
1079 1141
 	if ($result !== false)
1080 1142
 	{
1081
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1082
-			$modSettings[$row['variable']] = $row['value'];
1143
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1144
+					$modSettings[$row['variable']] = $row['value'];
1145
+		}
1083 1146
 		$smcFunc['db_free_result']($result);
1084 1147
 
1085 1148
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1092,20 +1155,22 @@  discard block
 block discarded – undo
1092 1155
 	$modSettings['disableQueryCheck'] = true;
1093 1156
 
1094 1157
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1095
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1096
-		$smcFunc['db_query']('', '
1158
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1159
+			$smcFunc['db_query']('', '
1097 1160
 			SET NAMES {string:utf8}',
1098 1161
 			array(
1099 1162
 				'db_error_skip' => true,
1100 1163
 				'utf8' => 'utf8',
1101 1164
 			)
1102 1165
 		);
1166
+	}
1103 1167
 
1104 1168
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1105
-	if (substr(__DIR__, -1) == '\\')
1106
-		$attachdir = __DIR__ . 'attachments';
1107
-	else
1108
-		$attachdir = __DIR__ . '/attachments';
1169
+	if (substr(__DIR__, -1) == '\\') {
1170
+			$attachdir = __DIR__ . 'attachments';
1171
+	} else {
1172
+			$attachdir = __DIR__ . '/attachments';
1173
+	}
1109 1174
 
1110 1175
 	$replaces = array(
1111 1176
 		'{$db_prefix}' => $db_prefix,
@@ -1122,8 +1187,9 @@  discard block
 block discarded – undo
1122 1187
 
1123 1188
 	foreach ($txt as $key => $value)
1124 1189
 	{
1125
-		if (substr($key, 0, 8) == 'default_')
1126
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1190
+		if (substr($key, 0, 8) == 'default_') {
1191
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1192
+		}
1127 1193
 	}
1128 1194
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1129 1195
 
@@ -1138,8 +1204,9 @@  discard block
 block discarded – undo
1138 1204
 
1139 1205
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1140 1206
 		{
1141
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1142
-				$engines[] = $row['Engine'];
1207
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1208
+							$engines[] = $row['Engine'];
1209
+			}
1143 1210
 		}
1144 1211
 
1145 1212
 		// Done with this now
@@ -1163,8 +1230,7 @@  discard block
 block discarded – undo
1163 1230
 			$replaces['START TRANSACTION;'] = '';
1164 1231
 			$replaces['COMMIT;'] = '';
1165 1232
 		}
1166
-	}
1167
-	else
1233
+	} else
1168 1234
 	{
1169 1235
 		$has_innodb = false;
1170 1236
 	}
@@ -1186,21 +1252,24 @@  discard block
 block discarded – undo
1186 1252
 	foreach ($sql_lines as $count => $line)
1187 1253
 	{
1188 1254
 		// No comments allowed!
1189
-		if (substr(trim($line), 0, 1) != '#')
1190
-			$current_statement .= "\n" . rtrim($line);
1255
+		if (substr(trim($line), 0, 1) != '#') {
1256
+					$current_statement .= "\n" . rtrim($line);
1257
+		}
1191 1258
 
1192 1259
 		// Is this the end of the query string?
1193
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1194
-			continue;
1260
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1261
+					continue;
1262
+		}
1195 1263
 
1196 1264
 		// Does this table already exist?  If so, don't insert more data into it!
1197 1265
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1198 1266
 		{
1199 1267
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1200
-			if (!empty($matches[0]))
1201
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1202
-			else
1203
-				$incontext['sql_results']['insert_dups']++;
1268
+			if (!empty($matches[0])) {
1269
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1270
+			} else {
1271
+							$incontext['sql_results']['insert_dups']++;
1272
+			}
1204 1273
 
1205 1274
 			$current_statement = '';
1206 1275
 			continue;
@@ -1209,8 +1278,9 @@  discard block
 block discarded – undo
1209 1278
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1210 1279
 		{
1211 1280
 			// Use the appropriate function based on the DB type
1212
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1213
-				$db_errorno = $db_type . '_errno';
1281
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1282
+							$db_errorno = $db_type . '_errno';
1283
+			}
1214 1284
 
1215 1285
 			// Error 1050: Table already exists!
1216 1286
 			// @todo Needs to be made better!
@@ -1225,18 +1295,18 @@  discard block
 block discarded – undo
1225 1295
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1226 1296
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1227 1297
 			}
1228
-		}
1229
-		else
1298
+		} else
1230 1299
 		{
1231
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1232
-				$incontext['sql_results']['tables']++;
1233
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1300
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1301
+							$incontext['sql_results']['tables']++;
1302
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1234 1303
 			{
1235 1304
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1236
-				if (!empty($matches[0]))
1237
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1238
-				else
1239
-					$incontext['sql_results']['inserts']++;
1305
+				if (!empty($matches[0])) {
1306
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1307
+				} else {
1308
+									$incontext['sql_results']['inserts']++;
1309
+				}
1240 1310
 			}
1241 1311
 		}
1242 1312
 
@@ -1249,15 +1319,17 @@  discard block
 block discarded – undo
1249 1319
 	// Sort out the context for the SQL.
1250 1320
 	foreach ($incontext['sql_results'] as $key => $number)
1251 1321
 	{
1252
-		if ($number == 0)
1253
-			unset($incontext['sql_results'][$key]);
1254
-		else
1255
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1322
+		if ($number == 0) {
1323
+					unset($incontext['sql_results'][$key]);
1324
+		} else {
1325
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1326
+		}
1256 1327
 	}
1257 1328
 
1258 1329
 	// Make sure UTF will be used globally.
1259
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1260
-		$newSettings[] = array('global_character_set', 'UTF-8');
1330
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1331
+			$newSettings[] = array('global_character_set', 'UTF-8');
1332
+	}
1261 1333
 
1262 1334
 	// Auto-detect local & global cookie settings
1263 1335
 	$url_parts = parse_url($boardurl);
@@ -1286,15 +1358,19 @@  discard block
 block discarded – undo
1286 1358
 
1287 1359
 		// Look for subfolder, if found, set localCookie
1288 1360
 		// Checking for len > 1 ensures you don't have just a slash...
1289
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1290
-			$localCookies = '1';
1361
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1362
+					$localCookies = '1';
1363
+		}
1291 1364
 
1292
-		if (isset($globalCookies))
1293
-			$newSettings[] = array('globalCookies', $globalCookies);
1294
-		if (isset($globalCookiesDomain))
1295
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1296
-		if (isset($localCookies))
1297
-			$newSettings[] = array('localCookies', $localCookies);
1365
+		if (isset($globalCookies)) {
1366
+					$newSettings[] = array('globalCookies', $globalCookies);
1367
+		}
1368
+		if (isset($globalCookiesDomain)) {
1369
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1370
+		}
1371
+		if (isset($localCookies)) {
1372
+					$newSettings[] = array('localCookies', $localCookies);
1373
+		}
1298 1374
 	}
1299 1375
 
1300 1376
 	// Are we allowing stat collection?
@@ -1312,16 +1388,17 @@  discard block
 block discarded – undo
1312 1388
 			fwrite($fp, $out);
1313 1389
 
1314 1390
 			$return_data = '';
1315
-			while (!feof($fp))
1316
-				$return_data .= fgets($fp, 128);
1391
+			while (!feof($fp)) {
1392
+							$return_data .= fgets($fp, 128);
1393
+			}
1317 1394
 
1318 1395
 			fclose($fp);
1319 1396
 
1320 1397
 			// Get the unique site ID.
1321 1398
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1322 1399
 
1323
-			if (!empty($ID[1]))
1324
-				$smcFunc['db_insert']('replace',
1400
+			if (!empty($ID[1])) {
1401
+							$smcFunc['db_insert']('replace',
1325 1402
 					$db_prefix . 'settings',
1326 1403
 					array('variable' => 'string', 'value' => 'string'),
1327 1404
 					array(
@@ -1330,11 +1407,12 @@  discard block
 block discarded – undo
1330 1407
 					),
1331 1408
 					array('variable')
1332 1409
 				);
1410
+			}
1333 1411
 		}
1334 1412
 	}
1335 1413
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1336
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1337
-		$smcFunc['db_query']('', '
1414
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1415
+			$smcFunc['db_query']('', '
1338 1416
 			DELETE FROM {db_prefix}settings
1339 1417
 			WHERE variable = {string:enable_sm_stats}',
1340 1418
 			array(
@@ -1342,20 +1420,23 @@  discard block
 block discarded – undo
1342 1420
 				'db_error_skip' => true,
1343 1421
 			)
1344 1422
 		);
1423
+	}
1345 1424
 
1346 1425
 	// Are we enabling SSL?
1347
-	if (!empty($_POST['force_ssl']))
1348
-		$newSettings[] = array('force_ssl', 1);
1426
+	if (!empty($_POST['force_ssl'])) {
1427
+			$newSettings[] = array('force_ssl', 1);
1428
+	}
1349 1429
 
1350 1430
 	// Setting a timezone is required.
1351 1431
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1352 1432
 	{
1353 1433
 		// Get PHP's default timezone, if set
1354 1434
 		$ini_tz = ini_get('date.timezone');
1355
-		if (!empty($ini_tz))
1356
-			$timezone_id = $ini_tz;
1357
-		else
1358
-			$timezone_id = '';
1435
+		if (!empty($ini_tz)) {
1436
+					$timezone_id = $ini_tz;
1437
+		} else {
1438
+					$timezone_id = '';
1439
+		}
1359 1440
 
1360 1441
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1361 1442
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1364,8 +1445,9 @@  discard block
 block discarded – undo
1364 1445
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1365 1446
 		}
1366 1447
 
1367
-		if (date_default_timezone_set($timezone_id))
1368
-			$newSettings[] = array('default_timezone', $timezone_id);
1448
+		if (date_default_timezone_set($timezone_id)) {
1449
+					$newSettings[] = array('default_timezone', $timezone_id);
1450
+		}
1369 1451
 	}
1370 1452
 
1371 1453
 	if (!empty($newSettings))
@@ -1396,16 +1478,18 @@  discard block
 block discarded – undo
1396 1478
 	}
1397 1479
 
1398 1480
 	// MySQL specific stuff
1399
-	if (substr($db_type, 0, 5) != 'mysql')
1400
-		return false;
1481
+	if (substr($db_type, 0, 5) != 'mysql') {
1482
+			return false;
1483
+	}
1401 1484
 
1402 1485
 	// Find database user privileges.
1403 1486
 	$privs = array();
1404 1487
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1405 1488
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1406 1489
 	{
1407
-		if ($row['Privilege'] == 'Alter')
1408
-			$privs[] = $row['Privilege'];
1490
+		if ($row['Privilege'] == 'Alter') {
1491
+					$privs[] = $row['Privilege'];
1492
+		}
1409 1493
 	}
1410 1494
 	$smcFunc['db_free_result']($get_privs);
1411 1495
 
@@ -1435,8 +1519,9 @@  discard block
 block discarded – undo
1435 1519
 	$incontext['continue'] = 1;
1436 1520
 
1437 1521
 	// Skipping?
1438
-	if (!empty($_POST['skip']))
1439
-		return true;
1522
+	if (!empty($_POST['skip'])) {
1523
+			return true;
1524
+	}
1440 1525
 
1441 1526
 	// Need this to check whether we need the database password.
1442 1527
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1453,18 +1538,22 @@  discard block
 block discarded – undo
1453 1538
 	// We need this to properly hash the password for Admin
1454 1539
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1455 1540
 			global $sourcedir;
1456
-			if (function_exists('mb_strtolower'))
1457
-				return mb_strtolower($string, 'UTF-8');
1541
+			if (function_exists('mb_strtolower')) {
1542
+							return mb_strtolower($string, 'UTF-8');
1543
+			}
1458 1544
 			require_once($sourcedir . '/Subs-Charset.php');
1459 1545
 			return utf8_strtolower($string);
1460 1546
 		};
1461 1547
 
1462
-	if (!isset($_POST['username']))
1463
-		$_POST['username'] = '';
1464
-	if (!isset($_POST['email']))
1465
-		$_POST['email'] = '';
1466
-	if (!isset($_POST['server_email']))
1467
-		$_POST['server_email'] = '';
1548
+	if (!isset($_POST['username'])) {
1549
+			$_POST['username'] = '';
1550
+	}
1551
+	if (!isset($_POST['email'])) {
1552
+			$_POST['email'] = '';
1553
+	}
1554
+	if (!isset($_POST['server_email'])) {
1555
+			$_POST['server_email'] = '';
1556
+	}
1468 1557
 
1469 1558
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1470 1559
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1483,8 +1572,9 @@  discard block
 block discarded – undo
1483 1572
 			'admin_group' => 1,
1484 1573
 		)
1485 1574
 	);
1486
-	if ($smcFunc['db_num_rows']($request) != 0)
1487
-		$incontext['skip'] = 1;
1575
+	if ($smcFunc['db_num_rows']($request) != 0) {
1576
+			$incontext['skip'] = 1;
1577
+	}
1488 1578
 	$smcFunc['db_free_result']($request);
1489 1579
 
1490 1580
 	// Trying to create an account?
@@ -1515,8 +1605,9 @@  discard block
 block discarded – undo
1515 1605
 		}
1516 1606
 
1517 1607
 		// Update the webmaster's email?
1518
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1519
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1608
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1609
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1610
+		}
1520 1611
 
1521 1612
 		// Work out whether we're going to have dodgy characters and remove them.
1522 1613
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1539,32 +1630,27 @@  discard block
 block discarded – undo
1539 1630
 			$smcFunc['db_free_result']($result);
1540 1631
 
1541 1632
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1542
-		}
1543
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1633
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1544 1634
 		{
1545 1635
 			// Try the previous step again.
1546 1636
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1547 1637
 			return false;
1548
-		}
1549
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1638
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1550 1639
 		{
1551 1640
 			// Try the previous step again.
1552 1641
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1553 1642
 			return false;
1554
-		}
1555
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1643
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1556 1644
 		{
1557 1645
 			// One step back, this time fill out a proper admin email address.
1558 1646
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1559 1647
 			return false;
1560
-		}
1561
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1648
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1562 1649
 		{
1563 1650
 			// One step back, this time fill out a proper admin email address.
1564 1651
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1565 1652
 			return false;
1566
-		}
1567
-		elseif ($_POST['username'] != '')
1653
+		} elseif ($_POST['username'] != '')
1568 1654
 		{
1569 1655
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1570 1656
 
@@ -1632,17 +1718,19 @@  discard block
 block discarded – undo
1632 1718
 	reloadSettings();
1633 1719
 
1634 1720
 	// Bring a warning over.
1635
-	if (!empty($incontext['account_existed']))
1636
-		$incontext['warning'] = $incontext['account_existed'];
1721
+	if (!empty($incontext['account_existed'])) {
1722
+			$incontext['warning'] = $incontext['account_existed'];
1723
+	}
1637 1724
 
1638
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1639
-		$smcFunc['db_query']('', '
1725
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1726
+			$smcFunc['db_query']('', '
1640 1727
 			SET NAMES {string:db_character_set}',
1641 1728
 			array(
1642 1729
 				'db_character_set' => $db_character_set,
1643 1730
 				'db_error_skip' => true,
1644 1731
 			)
1645 1732
 		);
1733
+	}
1646 1734
 
1647 1735
 	// As track stats is by default enabled let's add some activity.
1648 1736
 	$smcFunc['db_insert']('ignore',
@@ -1663,14 +1751,16 @@  discard block
 block discarded – undo
1663 1751
 	// Only proceed if we can load the data.
1664 1752
 	if ($request)
1665 1753
 	{
1666
-		while ($row = $smcFunc['db_fetch_row']($request))
1667
-			$modSettings[$row[0]] = $row[1];
1754
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1755
+					$modSettings[$row[0]] = $row[1];
1756
+		}
1668 1757
 		$smcFunc['db_free_result']($request);
1669 1758
 	}
1670 1759
 
1671 1760
 	// Automatically log them in ;)
1672
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1673
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1761
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1762
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1763
+	}
1674 1764
 
1675 1765
 	$result = $smcFunc['db_query']('', '
1676 1766
 		SELECT value
@@ -1681,13 +1771,14 @@  discard block
 block discarded – undo
1681 1771
 			'db_error_skip' => true,
1682 1772
 		)
1683 1773
 	);
1684
-	if ($smcFunc['db_num_rows']($result) != 0)
1685
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1774
+	if ($smcFunc['db_num_rows']($result) != 0) {
1775
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1776
+	}
1686 1777
 	$smcFunc['db_free_result']($result);
1687 1778
 
1688
-	if (empty($db_sessions))
1689
-		$_SESSION['admin_time'] = time();
1690
-	else
1779
+	if (empty($db_sessions)) {
1780
+			$_SESSION['admin_time'] = time();
1781
+	} else
1691 1782
 	{
1692 1783
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1693 1784
 
@@ -1711,8 +1802,9 @@  discard block
 block discarded – undo
1711 1802
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1712 1803
 		function($string){
1713 1804
 			global $sourcedir;
1714
-			if (function_exists('mb_strtolower'))
1715
-				return mb_strtolower($string, 'UTF-8');
1805
+			if (function_exists('mb_strtolower')) {
1806
+							return mb_strtolower($string, 'UTF-8');
1807
+			}
1716 1808
 			require_once($sourcedir . '/Subs-Charset.php');
1717 1809
 			return utf8_strtolower($string);
1718 1810
 		};
@@ -1728,8 +1820,9 @@  discard block
 block discarded – undo
1728 1820
 		)
1729 1821
 	);
1730 1822
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1731
-	if ($smcFunc['db_num_rows']($request) > 0)
1732
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1823
+	if ($smcFunc['db_num_rows']($request) > 0) {
1824
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1825
+	}
1733 1826
 	$smcFunc['db_free_result']($request);
1734 1827
 
1735 1828
 	// Now is the perfect time to fetch the SM files.
@@ -1748,8 +1841,9 @@  discard block
 block discarded – undo
1748 1841
 
1749 1842
 	// Check if we need some stupid MySQL fix.
1750 1843
 	$server_version = $smcFunc['db_server_info']();
1751
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1752
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1844
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1845
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1846
+	}
1753 1847
 
1754 1848
 	// Some final context for the template.
1755 1849
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1769,8 +1863,9 @@  discard block
 block discarded – undo
1769 1863
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1770 1864
 
1771 1865
 	// @todo Do we just want to read the file in clean, and split it this way always?
1772
-	if (count($settingsArray) == 1)
1773
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1866
+	if (count($settingsArray) == 1) {
1867
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1868
+	}
1774 1869
 
1775 1870
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1776 1871
 	{
@@ -1778,25 +1873,29 @@  discard block
 block discarded – undo
1778 1873
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1779 1874
 		{
1780 1875
 			// Set the ten lines to nothing.
1781
-			for ($j=0; $j < 10; $j++)
1782
-				$settingsArray[$i++] = '';
1876
+			for ($j=0; $j < 10; $j++) {
1877
+							$settingsArray[$i++] = '';
1878
+			}
1783 1879
 
1784 1880
 			continue;
1785 1881
 		}
1786 1882
 
1787
-		if (trim($settingsArray[$i]) == '?' . '>')
1788
-			$settingsArray[$i] = '';
1883
+		if (trim($settingsArray[$i]) == '?' . '>') {
1884
+					$settingsArray[$i] = '';
1885
+		}
1789 1886
 
1790 1887
 		// Don't trim or bother with it if it's not a variable.
1791
-		if (substr($settingsArray[$i], 0, 1) != '$')
1792
-			continue;
1888
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1889
+					continue;
1890
+		}
1793 1891
 
1794 1892
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1795 1893
 
1796
-		foreach ($vars as $var => $val)
1797
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1894
+		foreach ($vars as $var => $val) {
1895
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1798 1896
 			{
1799 1897
 				$comment = strstr($settingsArray[$i], '#');
1898
+		}
1800 1899
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1801 1900
 				unset($vars[$var]);
1802 1901
 			}
@@ -1806,36 +1905,41 @@  discard block
 block discarded – undo
1806 1905
 	if (!empty($vars))
1807 1906
 	{
1808 1907
 		$settingsArray[$i++] = '';
1809
-		foreach ($vars as $var => $val)
1810
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1908
+		foreach ($vars as $var => $val) {
1909
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1910
+		}
1811 1911
 	}
1812 1912
 
1813 1913
 	// Blank out the file - done to fix a oddity with some servers.
1814 1914
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1815
-	if (!$fp)
1816
-		return false;
1915
+	if (!$fp) {
1916
+			return false;
1917
+	}
1817 1918
 	fclose($fp);
1818 1919
 
1819 1920
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1820 1921
 
1821 1922
 	// Gotta have one of these ;)
1822
-	if (trim($settingsArray[0]) != '<?php')
1823
-		fwrite($fp, "<?php\n");
1923
+	if (trim($settingsArray[0]) != '<?php') {
1924
+			fwrite($fp, "<?php\n");
1925
+	}
1824 1926
 
1825 1927
 	$lines = count($settingsArray);
1826 1928
 	for ($i = 0; $i < $lines - 1; $i++)
1827 1929
 	{
1828 1930
 		// Don't just write a bunch of blank lines.
1829
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1830
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1931
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1932
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1933
+		}
1831 1934
 	}
1832 1935
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1833 1936
 	fclose($fp);
1834 1937
 
1835 1938
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1836 1939
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1837
-	if (function_exists('opcache_invalidate'))
1838
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1940
+	if (function_exists('opcache_invalidate')) {
1941
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1942
+	}
1839 1943
 
1840 1944
 	return true;
1841 1945
 }
@@ -1845,10 +1949,11 @@  discard block
 block discarded – undo
1845 1949
 	global $cachedir;
1846 1950
 
1847 1951
 	// Write out the db_last_error file with the error timestamp
1848
-	if (!empty($cachedir) && is_writable($cachedir))
1849
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1850
-	else
1851
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1952
+	if (!empty($cachedir) && is_writable($cachedir)) {
1953
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1954
+	} else {
1955
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1956
+	}
1852 1957
 
1853 1958
 	return true;
1854 1959
 }
@@ -1865,9 +1970,9 @@  discard block
 block discarded – undo
1865 1970
 	SecFilterScanPOST Off
1866 1971
 </IfModule>';
1867 1972
 
1868
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1869
-		return true;
1870
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1973
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1974
+			return true;
1975
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1871 1976
 	{
1872 1977
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1873 1978
 
@@ -1879,29 +1984,28 @@  discard block
 block discarded – undo
1879 1984
 				fwrite($ht_handle, $htaccess_addition);
1880 1985
 				fclose($ht_handle);
1881 1986
 				return true;
1987
+			} else {
1988
+							return false;
1882 1989
 			}
1883
-			else
1884
-				return false;
1990
+		} else {
1991
+					return true;
1885 1992
 		}
1886
-		else
1887
-			return true;
1888
-	}
1889
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1890
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1891
-	elseif (is_writable(dirname(__FILE__)))
1993
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1994
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1995
+	} elseif (is_writable(dirname(__FILE__)))
1892 1996
 	{
1893 1997
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1894 1998
 		{
1895 1999
 			fwrite($ht_handle, $htaccess_addition);
1896 2000
 			fclose($ht_handle);
1897 2001
 			return true;
2002
+		} else {
2003
+					return false;
1898 2004
 		}
1899
-		else
2005
+	} else {
1900 2006
 			return false;
1901 2007
 	}
1902
-	else
1903
-		return false;
1904
-}
2008
+	}
1905 2009
 
1906 2010
 function template_install_above()
1907 2011
 {
@@ -1940,9 +2044,10 @@  discard block
 block discarded – undo
1940 2044
 							<label for="installer_language">', $txt['installer_language'], ':</label>
1941 2045
 							<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1942 2046
 
1943
-		foreach ($incontext['detected_languages'] as $lang => $name)
1944
-			echo '
2047
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2048
+					echo '
1945 2049
 								<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2050
+		}
1946 2051
 
1947 2052
 		echo '
1948 2053
 							</select>
@@ -1962,9 +2067,10 @@  discard block
 block discarded – undo
1962 2067
 					<h2>', $txt['upgrade_progress'], '</h2>
1963 2068
 					<ul>';
1964 2069
 
1965
-	foreach ($incontext['steps'] as $num => $step)
1966
-		echo '
2070
+	foreach ($incontext['steps'] as $num => $step) {
2071
+			echo '
1967 2072
 						<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2073
+	}
1968 2074
 
1969 2075
 	echo '
1970 2076
 					</ul>
@@ -1990,20 +2096,23 @@  discard block
 block discarded – undo
1990 2096
 		echo '
1991 2097
 							<div class="floatright">';
1992 2098
 
1993
-		if (!empty($incontext['continue']))
1994
-			echo '
2099
+		if (!empty($incontext['continue'])) {
2100
+					echo '
1995 2101
 								<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">';
1996
-		if (!empty($incontext['skip']))
1997
-			echo '
2102
+		}
2103
+		if (!empty($incontext['skip'])) {
2104
+					echo '
1998 2105
 								<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">';
2106
+		}
1999 2107
 		echo '
2000 2108
 							</div>';
2001 2109
 	}
2002 2110
 
2003 2111
 	// Show the closing form tag and other data only if not in the last step
2004
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
2005
-		echo '
2112
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2113
+			echo '
2006 2114
 						</form>';
2115
+	}
2007 2116
 
2008 2117
 	echo '
2009 2118
 					</div><!-- .panel -->
@@ -2036,13 +2145,15 @@  discard block
 block discarded – undo
2036 2145
 		</div>';
2037 2146
 
2038 2147
 	// Show the warnings, or not.
2039
-	if (template_warning_divs())
2040
-		echo '
2148
+	if (template_warning_divs()) {
2149
+			echo '
2041 2150
 		<h3>', $txt['install_all_lovely'], '</h3>';
2151
+	}
2042 2152
 
2043 2153
 	// Say we want the continue button!
2044
-	if (empty($incontext['error']))
2045
-		$incontext['continue'] = 1;
2154
+	if (empty($incontext['error'])) {
2155
+			$incontext['continue'] = 1;
2156
+	}
2046 2157
 
2047 2158
 	// For the latest version stuff.
2048 2159
 	echo '
@@ -2076,19 +2187,21 @@  discard block
 block discarded – undo
2076 2187
 	global $txt, $incontext;
2077 2188
 
2078 2189
 	// Errors are very serious..
2079
-	if (!empty($incontext['error']))
2080
-		echo '
2190
+	if (!empty($incontext['error'])) {
2191
+			echo '
2081 2192
 		<div class="errorbox">
2082 2193
 			<h3>', $txt['upgrade_critical_error'], '</h3>
2083 2194
 			', $incontext['error'], '
2084 2195
 		</div>';
2196
+	}
2085 2197
 	// A warning message?
2086
-	elseif (!empty($incontext['warning']))
2087
-		echo '
2198
+	elseif (!empty($incontext['warning'])) {
2199
+			echo '
2088 2200
 		<div class="errorbox">
2089 2201
 			<h3>', $txt['upgrade_warning'], '</h3>
2090 2202
 			', $incontext['warning'], '
2091 2203
 		</div>';
2204
+	}
2092 2205
 
2093 2206
 	return empty($incontext['error']) && empty($incontext['warning']);
2094 2207
 }
@@ -2104,26 +2217,29 @@  discard block
 block discarded – undo
2104 2217
 			<li>', $incontext['failed_files']), '</li>
2105 2218
 		</ul>';
2106 2219
 
2107
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2108
-		echo '
2220
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2221
+			echo '
2109 2222
 		<hr>
2110 2223
 		<p>', $txt['chmod_linux_info'], '</p>
2111 2224
 		<samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>';
2225
+	}
2112 2226
 
2113 2227
 	// This is serious!
2114
-	if (!template_warning_divs())
2115
-		return;
2228
+	if (!template_warning_divs()) {
2229
+			return;
2230
+	}
2116 2231
 
2117 2232
 	echo '
2118 2233
 		<hr>
2119 2234
 		<p>', $txt['ftp_setup_info'], '</p>';
2120 2235
 
2121
-	if (!empty($incontext['ftp_errors']))
2122
-		echo '
2236
+	if (!empty($incontext['ftp_errors'])) {
2237
+			echo '
2123 2238
 		<div class="error_message">
2124 2239
 			', $txt['error_ftp_no_connect'], '<br><br>
2125 2240
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2126 2241
 		</div>';
2242
+	}
2127 2243
 
2128 2244
 	echo '
2129 2245
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2192,16 +2308,16 @@  discard block
 block discarded – undo
2192 2308
 			<dd>
2193 2309
 				<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2194 2310
 
2195
-	foreach ($incontext['supported_databases'] as $key => $db)
2196
-			echo '
2311
+	foreach ($incontext['supported_databases'] as $key => $db) {
2312
+				echo '
2197 2313
 					<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2314
+	}
2198 2315
 
2199 2316
 	echo '
2200 2317
 				</select>
2201 2318
 				<div class="smalltext">', $txt['db_settings_type_info'], '</div>
2202 2319
 			</dd>';
2203
-	}
2204
-	else
2320
+	} else
2205 2321
 	{
2206 2322
 		echo '
2207 2323
 			<dd>
@@ -2376,9 +2492,10 @@  discard block
 block discarded – undo
2376 2492
 		<div class="red">', $txt['error_db_queries'], '</div>
2377 2493
 		<ul>';
2378 2494
 
2379
-		foreach ($incontext['failures'] as $line => $fail)
2380
-			echo '
2495
+		foreach ($incontext['failures'] as $line => $fail) {
2496
+					echo '
2381 2497
 			<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2498
+		}
2382 2499
 
2383 2500
 		echo '
2384 2501
 		</ul>';
@@ -2443,15 +2560,16 @@  discard block
 block discarded – undo
2443 2560
 			</dd>
2444 2561
 		</dl>';
2445 2562
 
2446
-	if ($incontext['require_db_confirm'])
2447
-		echo '
2563
+	if ($incontext['require_db_confirm']) {
2564
+			echo '
2448 2565
 		<h2>', $txt['user_settings_database'], '</h2>
2449 2566
 		<p>', $txt['user_settings_database_info'], '</p>
2450 2567
 
2451 2568
 		<div class="lefttext">
2452 2569
 			<input type="password" name="password3" size="30">
2453 2570
 		</div>';
2454
-}
2571
+	}
2572
+	}
2455 2573
 
2456 2574
 // Tell them it's done, and to delete.
2457 2575
 function template_delete_install()
@@ -2464,13 +2582,14 @@  discard block
 block discarded – undo
2464 2582
 	template_warning_divs();
2465 2583
 
2466 2584
 	// Install directory still writable?
2467
-	if ($incontext['dir_still_writable'])
2468
-		echo '
2585
+	if ($incontext['dir_still_writable']) {
2586
+			echo '
2469 2587
 		<p><em>', $txt['still_writable'], '</em></p>';
2588
+	}
2470 2589
 
2471 2590
 	// Don't show the box if it's like 99% sure it won't work :P.
2472
-	if ($incontext['probably_delete_install'])
2473
-		echo '
2591
+	if ($incontext['probably_delete_install']) {
2592
+			echo '
2474 2593
 		<label>
2475 2594
 			<input type="checkbox" id="delete_self" onclick="doTheDelete();">
2476 2595
 			<strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong>
@@ -2486,6 +2605,7 @@  discard block
 block discarded – undo
2486 2605
 				theCheck.disabled = true;
2487 2606
 			}
2488 2607
 		</script>';
2608
+	}
2489 2609
 
2490 2610
 	echo '
2491 2611
 		<p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p>
Please login to merge, or discard this patch.
Themes/default/Packages.template.php 1 patch
Braces   +175 added lines, -128 removed lines patch added patch discarded remove patch
@@ -31,25 +31,27 @@  discard block
 block discarded – undo
31 31
 		</div>
32 32
 		<div class="information">';
33 33
 
34
-	if ($context['is_installed'])
35
-		echo '
34
+	if ($context['is_installed']) {
35
+			echo '
36 36
 			<strong>', $txt['package_installed_warning1'], '</strong><br>
37 37
 			<br>
38 38
 			', $txt['package_installed_warning2'], '<br>
39 39
 			<br>';
40
+	}
40 41
 
41 42
 	echo $txt['package_installed_warning3'], '
42 43
 		</div>
43 44
 		<br>';
44 45
 
45 46
 	// Do errors exist in the install? If so light them up like a christmas tree.
46
-	if ($context['has_failure'])
47
-		echo '
47
+	if ($context['has_failure']) {
48
+			echo '
48 49
 		<div class="errorbox">
49 50
 			', sprintf($txt['package_will_fail_title'], $txt['package_' . ($context['uninstalling'] ? 'uninstall' : 'install')]), '<br>
50 51
 			', sprintf($txt['package_will_fail_warning'], $txt['package_' . ($context['uninstalling'] ? 'uninstall' : 'install')]),
51 52
 			!empty($context['failure_details']) ? '<br><br><strong>' . $context['failure_details'] . '</strong>' : '', '
52 53
 		</div>';
54
+	}
53 55
 
54 56
 	// Display the package readme if one exists
55 57
 	if (isset($context['package_readme']))
@@ -63,9 +65,10 @@  discard block
 block discarded – undo
63 65
 			<span class="floatright">', $txt['package_available_readme_language'], '
64 66
 				<select name="readme_language" id="readme_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = smf_prepareScriptUrl(smf_scripturl + \'', '?action=admin;area=packages;sa=', $context['uninstalling'] ? 'uninstall' : 'install', ';package=', $context['filename'], ';readme=\' + this.options[this.selectedIndex].value + \';license=\' + get_selected(\'license_language\'));">';
65 67
 
66
-		foreach ($context['readmes'] as $a => $b)
67
-			echo '
68
+		foreach ($context['readmes'] as $a => $b) {
69
+					echo '
68 70
 					<option value="', $b, '"', $a === 'selected' ? ' selected' : '', '>', $b == 'default' ? $txt['package_readme_default'] : ucfirst($b), '</option>';
71
+		}
69 72
 
70 73
 		echo '
71 74
 				</select>
@@ -86,9 +89,10 @@  discard block
 block discarded – undo
86 89
 			<span class="floatright">', $txt['package_available_license_language'], '
87 90
 				<select name="license_language" id="license_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = smf_prepareScriptUrl(smf_scripturl + \'', '?action=admin;area=packages;sa=install', ';package=', $context['filename'], ';license=\' + this.options[this.selectedIndex].value + \';readme=\' + get_selected(\'readme_language\'));">';
88 91
 
89
-		foreach ($context['licenses'] as $a => $b)
90
-			echo '
92
+		foreach ($context['licenses'] as $a => $b) {
93
+					echo '
91 94
 					<option value="', $b, '"', $a === 'selected' ? ' selected' : '', '>', $b == 'default' ? $txt['package_license_default'] : ucfirst($b), '</option>';
95
+		}
92 96
 		echo '
93 97
 				</select>
94 98
 			</span>
@@ -115,9 +119,10 @@  discard block
 block discarded – undo
115 119
 					', $txt['package_db_uninstall_actions'], ':
116 120
 					<ul>';
117 121
 
118
-		foreach ($context['database_changes'] as $change)
119
-			echo '
122
+		foreach ($context['database_changes'] as $change) {
123
+					echo '
120 124
 						<li>', $change, '</li>';
125
+		}
121 126
 
122 127
 		echo '
123 128
 					</ul>
@@ -128,14 +133,14 @@  discard block
 block discarded – undo
128 133
 	echo '
129 134
 			<div class="information">';
130 135
 
131
-	if (empty($context['actions']) && empty($context['database_changes']))
132
-		echo '
136
+	if (empty($context['actions']) && empty($context['database_changes'])) {
137
+			echo '
133 138
 				<br>
134 139
 				<div class="errorbox">
135 140
 					', $txt['corrupt_compatible'], '
136 141
 				</div>
137 142
 			</div><!-- .information -->';
138
-	else
143
+	} else
139 144
 	{
140 145
 		echo '
141 146
 				', $txt['perform_actions'], '
@@ -239,9 +244,10 @@  discard block
 block discarded – undo
239 244
 						<td></td>
240 245
 						<td>';
241 246
 
242
-				if (!empty($context['themes_locked']))
243
-					echo '
247
+				if (!empty($context['themes_locked'])) {
248
+									echo '
244 249
 							<input type="hidden" name="custom_theme[]" value="', $id, '">';
250
+				}
245 251
 				echo '
246 252
 							<input type="checkbox" name="custom_theme[]" id="custom_theme_', $id, '" value="', $id, '" onclick="', (!empty($theme['has_failure']) ? 'if (this.form.custom_theme_' . $id . '.checked && !confirm(\'' . $txt['package_theme_failure_warning'] . '\')) return false;' : ''), 'invertAll(this, this.form, \'dummy_theme_', $id, '\', true);"', !empty($context['themes_locked']) ? ' disabled checked' : '', '>
247 253
 						</td>
@@ -307,21 +313,23 @@  discard block
 block discarded – undo
307 313
 	}
308 314
 
309 315
 	// Are we effectively ready to install?
310
-	if (!$context['ftp_needed'] && (!empty($context['actions']) || !empty($context['database_changes'])))
311
-		echo '
316
+	if (!$context['ftp_needed'] && (!empty($context['actions']) || !empty($context['database_changes']))) {
317
+			echo '
312 318
 			<div class="righttext padding">
313 319
 				<input type="submit" value="', $context['uninstalling'] ? $txt['package_uninstall_now'] : $txt['package_install_now'], '" onclick="return ', !empty($context['has_failure']) ? '(submitThisOnce(this) &amp;&amp; confirm(\'' . ($context['uninstalling'] ? $txt['package_will_fail_popup_uninstall'] : $txt['package_will_fail_popup']) . '\'))' : 'submitThisOnce(this)', ';" class="button">
314 320
 			</div>';
321
+	}
315 322
 
316 323
 	// If we need ftp information then demand it!
317
-	elseif ($context['ftp_needed'])
318
-		echo '
324
+	elseif ($context['ftp_needed']) {
325
+			echo '
319 326
 			<div class="cat_bar">
320 327
 				<h3 class="catbg">', $txt['package_ftp_necessary'], '</h3>
321 328
 			</div>
322 329
 			<div>
323 330
 				', template_control_chmod(), '
324 331
 			</div>';
332
+	}
325 333
 
326 334
 	echo '
327 335
 
@@ -338,8 +346,8 @@  discard block
 block discarded – undo
338 346
 	// Operations.
339 347
 	if (!empty($js_operations))
340 348
 	{
341
-		foreach ($js_operations as $key => $operation)
342
-			echo '
349
+		foreach ($js_operations as $key => $operation) {
350
+					echo '
343 351
 		aOperationElements[', $key, '] = new smc_Toggle({
344 352
 			bToggleEnabled: true,
345 353
 			bNoAnimate: true,
@@ -357,6 +365,7 @@  discard block
 block discarded – undo
357 365
 				}
358 366
 			]
359 367
 		});';
368
+		}
360 369
 	}
361 370
 
362 371
 	echo '
@@ -378,14 +387,15 @@  discard block
 block discarded – undo
378 387
 	</script>';
379 388
 
380 389
 	// And a bit more for database changes.
381
-	if (!empty($context['database_changes']))
382
-		echo '
390
+	if (!empty($context['database_changes'])) {
391
+			echo '
383 392
 	<script>
384 393
 		var database_changes_area = document.getElementById(\'db_changes_div\');
385 394
 		var db_vis = false;
386 395
 		database_changes_area.style.display = "none";
387 396
 	</script>';
388
-}
397
+	}
398
+	}
389 399
 
390 400
 /**
391 401
  * Extract package contents
@@ -394,8 +404,8 @@  discard block
 block discarded – undo
394 404
 {
395 405
 	global $context, $txt, $scripturl;
396 406
 
397
-	if (!empty($context['redirect_url']))
398
-		echo '
407
+	if (!empty($context['redirect_url'])) {
408
+			echo '
399 409
 	<script>
400 410
 		setTimeout("doRedirect();", ', empty($context['redirect_timeout']) ? '5000' : $context['redirect_timeout'], ');
401 411
 
@@ -404,52 +414,51 @@  discard block
 block discarded – undo
404 414
 			window.location = "', $context['redirect_url'], '";
405 415
 		}
406 416
 	</script>';
417
+	}
407 418
 
408 419
 	echo '
409 420
 	<div id="admincenter">';
410 421
 
411
-	if (empty($context['redirect_url']))
412
-		echo '
422
+	if (empty($context['redirect_url'])) {
423
+			echo '
413 424
 		<div class="cat_bar">
414 425
 			<h3 class="catbg">', $context['uninstalling'] ? $txt['uninstall'] : $txt['extracting'], '</h3>
415 426
 		</div>
416 427
 		<div class="information">', $txt['package_installed_extract'], '</div>';
417
-	else
418
-		echo '
428
+	} else {
429
+			echo '
419 430
 		<div class="cat_bar">
420 431
 			<h3 class="catbg">', $txt['package_installed_redirecting'], '</h3>
421 432
 		</div>';
433
+	}
422 434
 
423 435
 	echo '
424 436
 		<div class="windowbg">';
425 437
 
426 438
 	// If we are going to redirect we have a slightly different agenda.
427
-	if (!empty($context['redirect_url']))
428
-		echo '
439
+	if (!empty($context['redirect_url'])) {
440
+			echo '
429 441
 			', $context['redirect_text'], '<br><br>
430 442
 			<a href="', $context['redirect_url'], '">', $txt['package_installed_redirect_go_now'], '</a> | <a href="', $scripturl, '?action=admin;area=packages;sa=browse">', $txt['package_installed_redirect_cancel'], '</a>';
431
-
432
-	elseif ($context['uninstalling'])
433
-		echo '
443
+	} elseif ($context['uninstalling']) {
444
+			echo '
434 445
 			', $txt['package_uninstall_done'];
435
-
436
-	elseif ($context['install_finished'])
446
+	} elseif ($context['install_finished'])
437 447
 	{
438
-		if ($context['extract_type'] == 'avatar')
439
-			echo '
448
+		if ($context['extract_type'] == 'avatar') {
449
+					echo '
440 450
 			', $txt['avatars_extracted'];
441
-
442
-		elseif ($context['extract_type'] == 'language')
443
-			echo '
451
+		} elseif ($context['extract_type'] == 'language') {
452
+					echo '
444 453
 			', $txt['language_extracted'];
445
-
446
-		else
447
-			echo '
454
+		} else {
455
+					echo '
448 456
 			', $txt['package_installed_done'];
449
-	}
450
-	else
451
-		echo '
457
+		}
458
+	} else {
459
+			echo '
452 460
 			', $txt['corrupt_compatible'];
461
+	}
453 462
 
454 463
 	echo '
455 464
 		</div><!-- .windowbg -->';
@@ -483,9 +492,10 @@  discard block
 block discarded – undo
483 492
 		<div class="windowbg">
484 493
 			<ol>';
485 494
 
486
-	foreach ($context['files'] as $fileinfo)
487
-		echo '
495
+	foreach ($context['files'] as $fileinfo) {
496
+			echo '
488 497
 				<li><a href="', $scripturl, '?action=admin;area=packages;sa=examine;package=', $context['filename'], ';file=', $fileinfo['filename'], '" title="', $txt['view'], '">', $fileinfo['filename'], '</a> (', $fileinfo['size'], ' ', $txt['package_bytes'], ')</li>';
498
+	}
489 499
 
490 500
 	echo '
491 501
 			</ol>
@@ -549,9 +559,10 @@  discard block
 block discarded – undo
549 559
 			</script>
550 560
 			<div id="yourVersion" style="display:none">', $context['forum_version'], '</div>';
551 561
 
552
-	if (empty($modSettings['disable_smf_js']))
553
-		echo '
562
+	if (empty($modSettings['disable_smf_js'])) {
563
+			echo '
554 564
 			<script src="', $scripturl, '?action=viewsmfile;filename=latest-news.js"></script>';
565
+	}
555 566
 
556 567
 	// This sets the announcements and current versions themselves ;).
557 568
 	echo '
@@ -589,12 +600,13 @@  discard block
 block discarded – undo
589 600
 		}
590 601
 	}
591 602
 
592
-	if (!$mods_available)
593
-		echo '
603
+	if (!$mods_available) {
604
+			echo '
594 605
 		<div class="noticebox">', $txt['no_packages'], '</div>';
595
-	else
596
-		echo '
606
+	} else {
607
+			echo '
597 608
 		<br>';
609
+	}
598 610
 
599 611
 	// The advanced (emulation) box, collapsed by default
600 612
 	echo '
@@ -621,9 +633,10 @@  discard block
 block discarded – undo
621 633
 							<a id="revert" name="revert"></a>
622 634
 							<select name="version_emulate" id="ve">';
623 635
 
624
-	foreach ($context['emulation_versions'] as $version)
625
-		echo '
636
+	foreach ($context['emulation_versions'] as $version) {
637
+			echo '
626 638
 								<option value="', $version, '"', ($version == $context['selected_version'] ? ' selected="selected"' : ''), '>', $version, '</option>';
639
+	}
627 640
 
628 641
 	echo '
629 642
 							</select>
@@ -679,11 +692,12 @@  discard block
 block discarded – undo
679 692
 {
680 693
 	global $context, $txt, $scripturl;
681 694
 
682
-	if (!empty($context['package_ftp']['error']))
683
-		echo '
695
+	if (!empty($context['package_ftp']['error'])) {
696
+			echo '
684 697
 	<div class="errorbox">
685 698
 		<pre>', $context['package_ftp']['error'], '</pre>
686 699
 	</div>';
700
+	}
687 701
 
688 702
 	echo '
689 703
 	<div id="admin_form_wrapper">
@@ -766,13 +780,14 @@  discard block
 block discarded – undo
766 780
 					<legend>' . $txt['package_servers'] . '</legend>
767 781
 					<ul class="package_servers">';
768 782
 
769
-	foreach ($context['servers'] as $server)
770
-		echo '
783
+	foreach ($context['servers'] as $server) {
784
+			echo '
771 785
 						<li class="flow_auto">
772 786
 							<span class="floatleft">' . $server['name'] . '</span>
773 787
 							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=remove;server=' . $server['id'] . ';', $context['session_var'], '=', $context['session_id'], '">[ ' . $txt['delete'] . ' ]</a></span>
774 788
 							<span class="package_server floatright"><a href="' . $scripturl . '?action=admin;area=packages;get;sa=browse;server=' . $server['id'] . '">[ ' . $txt['package_browse'] . ' ]</a></span>
775 789
 						</li>';
790
+	}
776 791
 	echo '
777 792
 					</ul>
778 793
 				</fieldset>
@@ -859,11 +874,12 @@  discard block
 block discarded – undo
859 874
 		<div class="windowbg">';
860 875
 
861 876
 	// No packages, as yet.
862
-	if (empty($context['package_list']))
863
-		echo '
877
+	if (empty($context['package_list'])) {
878
+			echo '
864 879
 			<ul>
865 880
 				<li>', $txt['no_packages'], '</li>
866 881
 			</ul>';
882
+	}
867 883
 
868 884
 	// List out the packages...
869 885
 	else
@@ -877,11 +893,12 @@  discard block
 block discarded – undo
877 893
 				<li>
878 894
 					<strong><span id="ps_img_', $i, '" class="toggle_up" alt="*" style="display: none;"></span> ', $packageSection['title'], '</strong>';
879 895
 
880
-			if (!empty($packageSection['text']))
881
-				echo '
896
+			if (!empty($packageSection['text'])) {
897
+							echo '
882 898
 					<div class="sub_bar">
883 899
 						<h3 class="subbg">', $packageSection['text'], '</h3>
884 900
 					</div>';
901
+			}
885 902
 
886 903
 			echo '
887 904
 					<', $context['list_type'], ' id="package_section_', $i, '" class="packages">';
@@ -892,24 +909,28 @@  discard block
 block discarded – undo
892 909
 						<li>';
893 910
 
894 911
 				// Textual message. Could be empty just for a blank line...
895
-				if ($package['is_text'])
896
-					echo '
912
+				if ($package['is_text']) {
913
+									echo '
897 914
 							', empty($package['name']) ? '&nbsp;' : $package['name'];
915
+				}
898 916
 
899 917
 				// This is supposed to be a rule..
900
-				elseif ($package['is_line'])
901
-					echo '
918
+				elseif ($package['is_line']) {
919
+									echo '
902 920
 							<hr>';
921
+				}
903 922
 
904 923
 				// A remote link.
905
-				elseif ($package['is_remote'])
906
-					echo '
924
+				elseif ($package['is_remote']) {
925
+									echo '
907 926
 							<strong>', $package['link'], '</strong>';
927
+				}
908 928
 
909 929
 				// A title?
910
-				elseif ($package['is_heading'] || $package['is_title'])
911
-					echo '
930
+				elseif ($package['is_heading'] || $package['is_title']) {
931
+									echo '
912 932
 							<strong>', $package['name'], '</strong>';
933
+				}
913 934
 
914 935
 				// Otherwise, it's a package.
915 936
 				else
@@ -920,32 +941,36 @@  discard block
 block discarded – undo
920 941
 						<ul id="package_section_', $i, '_pkg_', $id, '" class="package_section">';
921 942
 
922 943
 					// Show the mod type?
923
-					if ($package['type'] != '')
924
-						echo '
944
+					if ($package['type'] != '') {
945
+											echo '
925 946
 							<li class="package_section">
926 947
 								', $txt['package_type'], ':&nbsp; ', $smcFunc['ucwords']($smcFunc['strtolower']($package['type'])), '
927 948
 							</li>';
949
+					}
928 950
 
929 951
 					// Show the version number?
930
-					if ($package['version'] != '')
931
-						echo '
952
+					if ($package['version'] != '') {
953
+											echo '
932 954
 							<li class="package_section">
933 955
 								', $txt['mod_version'], ':&nbsp; ', $package['version'], '
934 956
 							</li>';
957
+					}
935 958
 
936 959
 					// How 'bout the author?
937
-					if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link']))
938
-						echo '
960
+					if (!empty($package['author']) && $package['author']['name'] != '' && isset($package['author']['link'])) {
961
+											echo '
939 962
 							<li class="package_section">
940 963
 								', $txt['mod_author'], ':&nbsp; ', $package['author']['link'], '
941 964
 							</li>';
965
+					}
942 966
 
943 967
 					// The homepage...
944
-					if ($package['author']['website']['link'] != '')
945
-						echo '
968
+					if ($package['author']['website']['link'] != '') {
969
+											echo '
946 970
 							<li class="package_section">
947 971
 								', $txt['author_website'], ':&nbsp; ', $package['author']['website']['link'], '
948 972
 							</li>';
973
+					}
949 974
 
950 975
 					// Description: bleh bleh!
951 976
 					// Location of file: http://someplace/.
@@ -1004,8 +1029,8 @@  discard block
 block discarded – undo
1004 1029
 
1005 1030
 			foreach ($ps['items'] as $id => $package)
1006 1031
 			{
1007
-				if (!$package['is_text'] && !$package['is_line'] && !$package['is_remote'])
1008
-					echo '
1032
+				if (!$package['is_text'] && !$package['is_line'] && !$package['is_remote']) {
1033
+									echo '
1009 1034
 		var oPackageToggle_', $section, '_pkg_', $id, ' = new smc_Toggle({
1010 1035
 			bToggleEnabled: true,
1011 1036
 			bCurrentlyCollapsed: true,
@@ -1020,6 +1045,7 @@  discard block
 block discarded – undo
1020 1045
 				}
1021 1046
 			]
1022 1047
 		});';
1048
+				}
1023 1049
 			}
1024 1050
 		}
1025 1051
 
@@ -1064,9 +1090,10 @@  discard block
 block discarded – undo
1064 1090
 {
1065 1091
 	global $context, $txt, $scripturl;
1066 1092
 
1067
-	if (!empty($context['saved_successful']))
1068
-		echo '
1093
+	if (!empty($context['saved_successful'])) {
1094
+			echo '
1069 1095
 	<div class="infobox">', $txt['settings_saved'], '</div>';
1096
+	}
1070 1097
 
1071 1098
 	echo '
1072 1099
 	<div id="admincenter">
@@ -1128,8 +1155,9 @@  discard block
 block discarded – undo
1128 1155
 	global $context, $txt;
1129 1156
 
1130 1157
 	// Nothing to do? Brilliant!
1131
-	if (empty($context['package_ftp']))
1132
-		return false;
1158
+	if (empty($context['package_ftp'])) {
1159
+			return false;
1160
+	}
1133 1161
 
1134 1162
 	if (empty($context['package_ftp']['form_elements_only']))
1135 1163
 	{
@@ -1139,19 +1167,21 @@  discard block
 block discarded – undo
1139 1167
 					', $txt['package_ftp_why_file_list'], '
1140 1168
 					<ul style="display: inline;">';
1141 1169
 
1142
-		if (!empty($context['notwritable_files']))
1143
-			foreach ($context['notwritable_files'] as $file)
1170
+		if (!empty($context['notwritable_files'])) {
1171
+					foreach ($context['notwritable_files'] as $file)
1144 1172
 				echo '
1145 1173
 						<li>', $file, '</li>';
1174
+		}
1146 1175
 
1147 1176
 		echo '
1148 1177
 					</ul>';
1149 1178
 
1150
-		if (!$context['server']['is_windows'])
1151
-			echo '
1179
+		if (!$context['server']['is_windows']) {
1180
+					echo '
1152 1181
 					<hr>
1153 1182
 					', $txt['package_chmod_linux'], '<br>
1154 1183
 					<samp># chmod a+w ', implode(' ', $context['notwritable_files']), '</samp>';
1184
+		}
1155 1185
 
1156 1186
 		echo '
1157 1187
 				</div><!-- #need_writable_list -->';
@@ -1164,9 +1194,10 @@  discard block
 block discarded – undo
1164 1194
 					</div>
1165 1195
 				</div>';
1166 1196
 
1167
-	if (!empty($context['package_ftp']['destination']))
1168
-		echo '
1197
+	if (!empty($context['package_ftp']['destination'])) {
1198
+			echo '
1169 1199
 				<form action="', $context['package_ftp']['destination'], '" method="post" accept-charset="', $context['character_set'], '">';
1200
+	}
1170 1201
 
1171 1202
 	echo '
1172 1203
 					<fieldset>
@@ -1200,24 +1231,27 @@  discard block
 block discarded – undo
1200 1231
 					</dl>
1201 1232
 					</fieldset>';
1202 1233
 
1203
-	if (empty($context['package_ftp']['form_elements_only']))
1204
-		echo '
1234
+	if (empty($context['package_ftp']['form_elements_only'])) {
1235
+			echo '
1205 1236
 					<div class="righttext" style="margin: 1ex;">
1206 1237
 						<span id="test_ftp_placeholder_full"></span>
1207 1238
 						<input type="submit" value="', $txt['package_proceed'], '" class="button">
1208 1239
 					</div>';
1240
+	}
1209 1241
 
1210
-	if (!empty($context['package_ftp']['destination']))
1211
-		echo '
1242
+	if (!empty($context['package_ftp']['destination'])) {
1243
+			echo '
1212 1244
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1213 1245
 				</form>';
1246
+	}
1214 1247
 
1215 1248
 	// Hide the details of the list.
1216
-	if (empty($context['package_ftp']['form_elements_only']))
1217
-		echo '
1249
+	if (empty($context['package_ftp']['form_elements_only'])) {
1250
+			echo '
1218 1251
 				<script>
1219 1252
 					document.getElementById(\'need_writable_list\').style.display = \'none\';
1220 1253
 				</script>';
1254
+	}
1221 1255
 
1222 1256
 	// Quick generate the test button.
1223 1257
 	echo '
@@ -1574,9 +1608,10 @@  discard block
 block discarded – undo
1574 1608
 					<td width="30%">
1575 1609
 						<strong>';
1576 1610
 
1577
-		if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
1578
-			echo '
1611
+		if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive')) {
1612
+					echo '
1579 1613
 							<span class="generic_icons folder"></span>';
1614
+		}
1580 1615
 
1581 1616
 		echo '
1582 1617
 							', $name, '
@@ -1603,8 +1638,9 @@  discard block
 block discarded – undo
1603 1638
 					</td>
1604 1639
 				</tr>';
1605 1640
 
1606
-		if (!empty($dir['contents']))
1607
-			template_permission_show_contents($name, $dir['contents'], 1);
1641
+		if (!empty($dir['contents'])) {
1642
+					template_permission_show_contents($name, $dir['contents'], 1);
1643
+		}
1608 1644
 	}
1609 1645
 
1610 1646
 	echo '
@@ -1640,13 +1676,14 @@  discard block
 block discarded – undo
1640 1676
 			</fieldset>';
1641 1677
 
1642 1678
 	// Likely to need FTP?
1643
-	if (empty($context['ftp_connected']))
1644
-		echo '
1679
+	if (empty($context['ftp_connected'])) {
1680
+			echo '
1645 1681
 			<p>
1646 1682
 				', $txt['package_file_perms_ftp_details'], ':
1647 1683
 			</p>
1648 1684
 			', template_control_chmod(), '
1649 1685
 			<div class="noticebox">', $txt['package_file_perms_ftp_retain'], '</div>';
1686
+	}
1650 1687
 
1651 1688
 	echo '
1652 1689
 			<span id="test_ftp_placeholder_full"></span>
@@ -1655,9 +1692,10 @@  discard block
 block discarded – undo
1655 1692
 		</div><!-- .windowbg -->';
1656 1693
 
1657 1694
 	// Any looks fors we've already done?
1658
-	foreach ($context['look_for'] as $path)
1659
-		echo '
1695
+	foreach ($context['look_for'] as $path) {
1696
+			echo '
1660 1697
 		<input type="hidden" name="back_look[]" value="', $path, '">';
1698
+	}
1661 1699
 
1662 1700
 	echo '
1663 1701
 	</form>
@@ -1699,9 +1737,10 @@  discard block
 block discarded – undo
1699 1737
 					<td class="smalltext" width="30%">' . str_repeat('&nbsp;', $level * 5), '
1700 1738
 					', (!empty($dir['type']) && $dir['type'] == 'dir_recursive') || !empty($dir['list_contents']) ? '<a id="link_' . $cur_ident . '" href="' . $scripturl . '?action=admin;area=packages;sa=perms;find=' . base64_encode($ident . '/' . $name) . ';back_look=' . $context['back_look_data'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '#fol_' . $cur_ident . '" onclick="return expandFolder(\'' . $cur_ident . '\', \'' . addcslashes($ident . '/' . $name, "'\\") . '\');">' : '';
1701 1739
 
1702
-			if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive'))
1703
-				echo '
1740
+			if (!empty($dir['type']) && ($dir['type'] == 'dir' || $dir['type'] == 'dir_recursive')) {
1741
+							echo '
1704 1742
 						<span class="generic_icons folder"></span>';
1743
+			}
1705 1744
 
1706 1745
 			echo '
1707 1746
 						', $name, '
@@ -1719,34 +1758,38 @@  discard block
 block discarded – undo
1719 1758
 				</tr>
1720 1759
 				<tr id="insert_div_loc_' . $cur_ident . '" style="display: none;"><td></td></tr>';
1721 1760
 
1722
-			if (!empty($dir['contents']))
1723
-				template_permission_show_contents($ident . '/' . $name, $dir['contents'], $level + 1, !empty($dir['more_files']));
1761
+			if (!empty($dir['contents'])) {
1762
+							template_permission_show_contents($ident . '/' . $name, $dir['contents'], $level + 1, !empty($dir['more_files']));
1763
+			}
1724 1764
 		}
1725 1765
 	}
1726 1766
 
1727 1767
 	// We have more files to show?
1728
-	if ($has_more)
1729
-		echo '
1768
+	if ($has_more) {
1769
+			echo '
1730 1770
 				<tr class="windowbg" id="content_', $js_ident, '_more">
1731 1771
 					<td class="smalltext" width="40%">' . str_repeat('&nbsp;', $level * 5), '
1732 1772
 						&#171; <a href="' . $scripturl . '?action=admin;area=packages;sa=perms;find=' . base64_encode($ident) . ';fileoffset=', ($context['file_offset'] + $context['file_limit']), ';' . $context['session_var'] . '=' . $context['session_id'] . '#fol_' . preg_replace('~[^A-Za-z0-9_\-=:]~', ':-:', $ident) . '">', $txt['package_file_perms_more_files'], '</a> &#187;
1733 1773
 					</td>
1734 1774
 					<td colspan="6"></td>
1735 1775
 				</tr>';
1776
+	}
1736 1777
 
1737 1778
 	if ($drawn_div)
1738 1779
 	{
1739 1780
 		// Hide anything too far down the tree.
1740 1781
 		$isFound = false;
1741
-		foreach ($context['look_for'] as $tree)
1742
-			if (substr($tree, 0, strlen($ident)) == $ident)
1782
+		foreach ($context['look_for'] as $tree) {
1783
+					if (substr($tree, 0, strlen($ident)) == $ident)
1743 1784
 				$isFound = true;
1785
+		}
1744 1786
 
1745
-		if ($level > 1 && !$isFound)
1746
-			echo '
1787
+		if ($level > 1 && !$isFound) {
1788
+					echo '
1747 1789
 		<script>
1748 1790
 			expandFolder(\'', $js_ident, '\', \'\');
1749 1791
 		</script>';
1792
+		}
1750 1793
 	}
1751 1794
 }
1752 1795
 
@@ -1766,11 +1809,12 @@  discard block
 block discarded – undo
1766 1809
 				<h3 class="catbg">', $txt['package_file_perms_applying'], '</h3>
1767 1810
 			</div>';
1768 1811
 
1769
-	if (!empty($context['skip_ftp']))
1770
-		echo '
1812
+	if (!empty($context['skip_ftp'])) {
1813
+			echo '
1771 1814
 			<div class="errorbox">
1772 1815
 				', $txt['package_file_perms_skipping_ftp'], '
1773 1816
 			</div>';
1817
+	}
1774 1818
 
1775 1819
 	// How many have we done?
1776 1820
 	$remaining_items = count($context['method'] == 'individual' ? $context['to_process'] : $context['directory_list']);
@@ -1808,28 +1852,31 @@  discard block
 block discarded – undo
1808 1852
 				<br>';
1809 1853
 
1810 1854
 	// Put out the right hidden data.
1811
-	if ($context['method'] == 'individual')
1812
-		echo '
1855
+	if ($context['method'] == 'individual') {
1856
+			echo '
1813 1857
 				<input type="hidden" name="custom_value" value="', $context['custom_value'], '">
1814 1858
 				<input type="hidden" name="totalItems" value="', $context['total_items'], '">
1815 1859
 				<input type="hidden" name="toProcess" value="', $context['to_process_encode'], '">';
1816
-	else
1817
-		echo '
1860
+	} else {
1861
+			echo '
1818 1862
 				<input type="hidden" name="predefined" value="', $context['predefined_type'], '">
1819 1863
 				<input type="hidden" name="fileOffset" value="', $context['file_offset'], '">
1820 1864
 				<input type="hidden" name="totalItems" value="', $context['total_items'], '">
1821 1865
 				<input type="hidden" name="dirList" value="', $context['directory_list_encode'], '">
1822 1866
 				<input type="hidden" name="specialFiles" value="', $context['special_files_encode'], '">';
1867
+	}
1823 1868
 
1824 1869
 	// Are we not using FTP for whatever reason.
1825
-	if (!empty($context['skip_ftp']))
1826
-		echo '
1870
+	if (!empty($context['skip_ftp'])) {
1871
+			echo '
1827 1872
 				<input type="hidden" name="skip_ftp" value="1">';
1873
+	}
1828 1874
 
1829 1875
 	// Retain state.
1830
-	foreach ($context['back_look_data'] as $path)
1831
-		echo '
1876
+	foreach ($context['back_look_data'] as $path) {
1877
+			echo '
1832 1878
 				<input type="hidden" name="back_look[]" value="', $path, '">';
1879
+	}
1833 1880
 
1834 1881
 	echo '
1835 1882
 				<input type="hidden" name="method" value="', $context['method'], '">
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +792 added lines, -597 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
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -392,9 +409,9 @@  discard block
 block discarded – undo
392 409
 				break;
393 410
 			}
394 411
 		}
412
+	} else {
413
+			$id_member = 0;
395 414
 	}
396
-	else
397
-		$id_member = 0;
398 415
 
399 416
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
400 417
 	{
@@ -402,8 +419,9 @@  discard block
 block discarded – undo
402 419
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
403 420
 
404 421
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
405
-		if (empty($cookie_data))
406
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
422
+		if (empty($cookie_data)) {
423
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
424
+		}
407 425
 
408 426
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
409 427
 
@@ -411,16 +429,17 @@  discard block
 block discarded – undo
411 429
 
412 430
 		// Make sure the cookie is set to the correct domain and path
413 431
 		require_once($sourcedir . '/Subs-Auth.php');
414
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
415
-			setLoginCookie((int) $login_span - time(), $id_member);
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
432
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
433
+					setLoginCookie((int) $login_span - time(), $id_member);
434
+		}
435
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 436
 	{
419 437
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 438
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
421 439
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
440
+		if (empty($cookie_data)) {
441
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		}
424 443
 
425 444
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
426 445
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +464,34 @@  discard block
 block discarded – undo
445 464
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 465
 			$smcFunc['db_free_result']($request);
447 466
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
449
-				$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
467
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
468
+							$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
469
+			}
450 470
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
471
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
472
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			}
453 474
 		}
454 475
 
455 476
 		// Did we find 'im?  If not, junk it.
456 477
 		if (!empty($user_settings))
457 478
 		{
458 479
 			// As much as the password should be right, we can assume the integration set things up.
459
-			if (!empty($already_verified) && $already_verified === true)
460
-				$check = true;
480
+			if (!empty($already_verified) && $already_verified === true) {
481
+							$check = true;
482
+			}
461 483
 			// SHA-512 hash should be 128 characters long.
462
-			elseif (strlen($password) == 128)
463
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
464
-			else
465
-				$check = false;
484
+			elseif (strlen($password) == 128) {
485
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
486
+			} else {
487
+							$check = false;
488
+			}
466 489
 
467 490
 			// Wrong password or not activated - either way, you're going nowhere.
468 491
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
492
+		} else {
493
+					$id_member = 0;
469 494
 		}
470
-		else
471
-			$id_member = 0;
472 495
 
473 496
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 497
 		if (!$id_member)
@@ -497,8 +520,9 @@  discard block
 block discarded – undo
497 520
 
498 521
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
499 522
 
500
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
501
-						$tfasecret = null;
523
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
524
+											$tfasecret = null;
525
+					}
502 526
 				}
503 527
 
504 528
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -520,10 +544,12 @@  discard block
 block discarded – undo
520 544
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
521 545
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
522 546
 		{
523
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
547
+			if ($modSettings['tfa_mode'] == 2) {
548
+				//only do this if we are just forcing SOME membergroups
524 549
 			{
525 550
 				//Build an array of ALL user membergroups.
526 551
 				$full_groups = array($user_settings['id_group']);
552
+			}
527 553
 				if (!empty($user_settings['additional_groups']))
528 554
 				{
529 555
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -543,15 +569,17 @@  discard block
 block discarded – undo
543 569
 				);
544 570
 				$row = $smcFunc['db_fetch_assoc']($request);
545 571
 				$smcFunc['db_free_result']($request);
572
+			} else {
573
+							$row['total'] = 1;
546 574
 			}
547
-			else
548
-				$row['total'] = 1; //simplifies logics in the next "if"
575
+			//simplifies logics in the next "if"
549 576
 
550 577
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
551 578
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
552 579
 
553
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
554
-				redirectexit('action=profile;area=tfasetup;forced');
580
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
581
+							redirectexit('action=profile;area=tfasetup;forced');
582
+			}
555 583
 		}
556 584
 	}
557 585
 
@@ -588,29 +616,32 @@  discard block
 block discarded – undo
588 616
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
589 617
 				$user_settings['last_login'] = time();
590 618
 
591
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
592
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
619
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
620
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
621
+				}
593 622
 
594
-				if (!empty($modSettings['cache_enable']))
595
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
623
+				if (!empty($modSettings['cache_enable'])) {
624
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
625
+				}
596 626
 			}
627
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
628
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
597 629
 		}
598
-		elseif (empty($_SESSION['id_msg_last_visit']))
599
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
600 630
 
601 631
 		$username = $user_settings['member_name'];
602 632
 
603
-		if (empty($user_settings['additional_groups']))
604
-			$user_info = array(
633
+		if (empty($user_settings['additional_groups'])) {
634
+					$user_info = array(
605 635
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
606 636
 			);
607
-		else
608
-			$user_info = array(
637
+		} else {
638
+					$user_info = array(
609 639
 				'groups' => array_merge(
610 640
 					array($user_settings['id_group'], $user_settings['id_post_group']),
611 641
 					explode(',', $user_settings['additional_groups'])
612 642
 				)
613 643
 			);
644
+		}
614 645
 
615 646
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
616 647
 		$user_info['groups'] = array_map('intval', $user_info['groups']);
@@ -627,8 +658,7 @@  discard block
 block discarded – undo
627 658
 			$time_system = new DateTime('now', $tz_system);
628 659
 			$time_user = new DateTime('now', $tz_user);
629 660
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
630
-		}
631
-		else
661
+		} else
632 662
 		{
633 663
 			// !!! Compatibility.
634 664
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -642,8 +672,9 @@  discard block
 block discarded – undo
642 672
 		$user_info = array('groups' => array(-1));
643 673
 		$user_settings = array();
644 674
 
645
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
646
-			$_COOKIE[$cookiename] = '';
675
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
676
+					$_COOKIE[$cookiename] = '';
677
+		}
647 678
 
648 679
 		// Expire the 2FA cookie
649 680
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -660,19 +691,20 @@  discard block
 block discarded – undo
660 691
 		}
661 692
 
662 693
 		// Create a login token if it doesn't exist yet.
663
-		if (!isset($_SESSION['token']['post-login']))
664
-			createToken('login');
665
-		else
666
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
694
+		if (!isset($_SESSION['token']['post-login'])) {
695
+					createToken('login');
696
+		} else {
697
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
698
+		}
667 699
 
668 700
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
669 701
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
670 702
 		{
671 703
 			require_once($sourcedir . '/ManageSearchEngines.php');
672 704
 			$user_info['possibly_robot'] = SpiderCheck();
705
+		} elseif (!empty($modSettings['spider_mode'])) {
706
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
673 707
 		}
674
-		elseif (!empty($modSettings['spider_mode']))
675
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
676 708
 		// If we haven't turned on proper spider hunts then have a guess!
677 709
 		else
678 710
 		{
@@ -720,8 +752,9 @@  discard block
 block discarded – undo
720 752
 	$user_info['groups'] = array_unique($user_info['groups']);
721 753
 
722 754
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
723
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
724
-		unset($user_info['ignoreboards'][$tmp]);
755
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
756
+			unset($user_info['ignoreboards'][$tmp]);
757
+	}
725 758
 
726 759
 	// Allow the user to change their language.
727 760
 	if (!empty($modSettings['userLanguage']))
@@ -734,13 +767,14 @@  discard block
 block discarded – undo
734 767
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
735 768
 
736 769
 			// Make it permanent for members.
737
-			if (!empty($user_info['id']))
738
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
739
-			else
740
-				$_SESSION['language'] = $user_info['language'];
770
+			if (!empty($user_info['id'])) {
771
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
772
+			} else {
773
+							$_SESSION['language'] = $user_info['language'];
774
+			}
775
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
776
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
741 777
 		}
742
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
743
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
744 778
 	}
745 779
 
746 780
 	$temp = build_query_board($user_info['id']);
@@ -803,9 +837,9 @@  discard block
 block discarded – undo
803 837
 		}
804 838
 
805 839
 		// Remember redirection is the key to avoiding fallout from your bosses.
806
-		if (!empty($topic))
807
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
808
-		else
840
+		if (!empty($topic)) {
841
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
842
+		} else
809 843
 		{
810 844
 			loadPermissions();
811 845
 			loadTheme();
@@ -823,10 +857,11 @@  discard block
 block discarded – undo
823 857
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
824 858
 	{
825 859
 		// @todo SLOW?
826
-		if (!empty($topic))
827
-			$temp = cache_get_data('topic_board-' . $topic, 120);
828
-		else
829
-			$temp = cache_get_data('board-' . $board, 120);
860
+		if (!empty($topic)) {
861
+					$temp = cache_get_data('topic_board-' . $topic, 120);
862
+		} else {
863
+					$temp = cache_get_data('board-' . $board, 120);
864
+		}
830 865
 
831 866
 		if (!empty($temp))
832 867
 		{
@@ -864,8 +899,9 @@  discard block
 block discarded – undo
864 899
 			$row = $smcFunc['db_fetch_assoc']($request);
865 900
 
866 901
 			// Set the current board.
867
-			if (!empty($row['id_board']))
868
-				$board = $row['id_board'];
902
+			if (!empty($row['id_board'])) {
903
+							$board = $row['id_board'];
904
+			}
869 905
 
870 906
 			// Basic operating information. (globals... :/)
871 907
 			$board_info = array(
@@ -901,21 +937,23 @@  discard block
 block discarded – undo
901 937
 
902 938
 			do
903 939
 			{
904
-				if (!empty($row['id_moderator']))
905
-					$board_info['moderators'][$row['id_moderator']] = array(
940
+				if (!empty($row['id_moderator'])) {
941
+									$board_info['moderators'][$row['id_moderator']] = array(
906 942
 						'id' => $row['id_moderator'],
907 943
 						'name' => $row['real_name'],
908 944
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
909 945
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
910 946
 					);
947
+				}
911 948
 
912
-				if (!empty($row['id_moderator_group']))
913
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
949
+				if (!empty($row['id_moderator_group'])) {
950
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
914 951
 						'id' => $row['id_moderator_group'],
915 952
 						'name' => $row['group_name'],
916 953
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
917 954
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
918 955
 					);
956
+				}
919 957
 			}
920 958
 			while ($row = $smcFunc['db_fetch_assoc']($request));
921 959
 
@@ -947,12 +985,12 @@  discard block
 block discarded – undo
947 985
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
948 986
 			{
949 987
 				// @todo SLOW?
950
-				if (!empty($topic))
951
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
988
+				if (!empty($topic)) {
989
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
990
+				}
952 991
 				cache_put_data('board-' . $board, $board_info, 120);
953 992
 			}
954
-		}
955
-		else
993
+		} else
956 994
 		{
957 995
 			// Otherwise the topic is invalid, there are no moderators, etc.
958 996
 			$board_info = array(
@@ -966,8 +1004,9 @@  discard block
 block discarded – undo
966 1004
 		$smcFunc['db_free_result']($request);
967 1005
 	}
968 1006
 
969
-	if (!empty($topic))
970
-		$_GET['board'] = (int) $board;
1007
+	if (!empty($topic)) {
1008
+			$_GET['board'] = (int) $board;
1009
+	}
971 1010
 
972 1011
 	if (!empty($board))
973 1012
 	{
@@ -977,10 +1016,12 @@  discard block
 block discarded – undo
977 1016
 		// Now check if the user is a moderator.
978 1017
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
979 1018
 
980
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
981
-			$board_info['error'] = 'access';
982
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
983
-			$board_info['error'] = 'access';
1019
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1020
+					$board_info['error'] = 'access';
1021
+		}
1022
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1023
+					$board_info['error'] = 'access';
1024
+		}
984 1025
 
985 1026
 		// Build up the linktree.
986 1027
 		$context['linktree'] = array_merge(
@@ -1003,8 +1044,9 @@  discard block
 block discarded – undo
1003 1044
 	$context['current_board'] = $board;
1004 1045
 
1005 1046
 	// No posting in redirection boards!
1006
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1007
-		$board_info['error'] == 'post_in_redirect';
1047
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1048
+			$board_info['error'] == 'post_in_redirect';
1049
+	}
1008 1050
 
1009 1051
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1010 1052
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1030,24 +1072,23 @@  discard block
 block discarded – undo
1030 1072
 			ob_end_clean();
1031 1073
 			header('HTTP/1.1 403 Forbidden');
1032 1074
 			die;
1033
-		}
1034
-		elseif ($board_info['error'] == 'post_in_redirect')
1075
+		} elseif ($board_info['error'] == 'post_in_redirect')
1035 1076
 		{
1036 1077
 			// Slightly different error message here...
1037 1078
 			fatal_lang_error('cannot_post_redirect', false);
1038
-		}
1039
-		elseif ($user_info['is_guest'])
1079
+		} elseif ($user_info['is_guest'])
1040 1080
 		{
1041 1081
 			loadLanguage('Errors');
1042 1082
 			is_not_guest($txt['topic_gone']);
1083
+		} else {
1084
+					fatal_lang_error('topic_gone', false);
1043 1085
 		}
1044
-		else
1045
-			fatal_lang_error('topic_gone', false);
1046 1086
 	}
1047 1087
 
1048
-	if ($user_info['is_mod'])
1049
-		$user_info['groups'][] = 3;
1050
-}
1088
+	if ($user_info['is_mod']) {
1089
+			$user_info['groups'][] = 3;
1090
+	}
1091
+	}
1051 1092
 
1052 1093
 /**
1053 1094
  * Load this user's permissions.
@@ -1068,8 +1109,9 @@  discard block
 block discarded – undo
1068 1109
 		asort($cache_groups);
1069 1110
 		$cache_groups = implode(',', $cache_groups);
1070 1111
 		// If it's a spider then cache it different.
1071
-		if ($user_info['possibly_robot'])
1072
-			$cache_groups .= '-spider';
1112
+		if ($user_info['possibly_robot']) {
1113
+					$cache_groups .= '-spider';
1114
+		}
1073 1115
 
1074 1116
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1075 1117
 		{
@@ -1077,9 +1119,9 @@  discard block
 block discarded – undo
1077 1119
 			banPermissions();
1078 1120
 
1079 1121
 			return;
1122
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1123
+					list ($user_info['permissions'], $removals) = $temp;
1080 1124
 		}
1081
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1082
-			list ($user_info['permissions'], $removals) = $temp;
1083 1125
 	}
1084 1126
 
1085 1127
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1101,23 +1143,26 @@  discard block
 block discarded – undo
1101 1143
 		$removals = array();
1102 1144
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1103 1145
 		{
1104
-			if (empty($row['add_deny']))
1105
-				$removals[] = $row['permission'];
1106
-			else
1107
-				$user_info['permissions'][] = $row['permission'];
1146
+			if (empty($row['add_deny'])) {
1147
+							$removals[] = $row['permission'];
1148
+			} else {
1149
+							$user_info['permissions'][] = $row['permission'];
1150
+			}
1108 1151
 		}
1109 1152
 		$smcFunc['db_free_result']($request);
1110 1153
 
1111
-		if (isset($cache_groups))
1112
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1154
+		if (isset($cache_groups)) {
1155
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1156
+		}
1113 1157
 	}
1114 1158
 
1115 1159
 	// Get the board permissions.
1116 1160
 	if (!empty($board))
1117 1161
 	{
1118 1162
 		// Make sure the board (if any) has been loaded by loadBoard().
1119
-		if (!isset($board_info['profile']))
1120
-			fatal_lang_error('no_board');
1163
+		if (!isset($board_info['profile'])) {
1164
+					fatal_lang_error('no_board');
1165
+		}
1121 1166
 
1122 1167
 		$request = $smcFunc['db_query']('', '
1123 1168
 			SELECT permission, add_deny
@@ -1133,20 +1178,23 @@  discard block
 block discarded – undo
1133 1178
 		);
1134 1179
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1135 1180
 		{
1136
-			if (empty($row['add_deny']))
1137
-				$removals[] = $row['permission'];
1138
-			else
1139
-				$user_info['permissions'][] = $row['permission'];
1181
+			if (empty($row['add_deny'])) {
1182
+							$removals[] = $row['permission'];
1183
+			} else {
1184
+							$user_info['permissions'][] = $row['permission'];
1185
+			}
1140 1186
 		}
1141 1187
 		$smcFunc['db_free_result']($request);
1142 1188
 	}
1143 1189
 
1144 1190
 	// Remove all the permissions they shouldn't have ;).
1145
-	if (!empty($modSettings['permission_enable_deny']))
1146
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1191
+	if (!empty($modSettings['permission_enable_deny'])) {
1192
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1193
+	}
1147 1194
 
1148
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1149
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1195
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1196
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1197
+	}
1150 1198
 
1151 1199
 	// Banned?  Watch, don't touch..
1152 1200
 	banPermissions();
@@ -1158,17 +1206,18 @@  discard block
 block discarded – undo
1158 1206
 		{
1159 1207
 			require_once($sourcedir . '/Subs-Auth.php');
1160 1208
 			rebuildModCache();
1209
+		} else {
1210
+					$user_info['mod_cache'] = $_SESSION['mc'];
1161 1211
 		}
1162
-		else
1163
-			$user_info['mod_cache'] = $_SESSION['mc'];
1164 1212
 
1165 1213
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1166 1214
 		// For example this drastically simplifies certain changes to the profile area.
1167 1215
 		$user_info['permissions'][] = 'is_not_guest';
1168 1216
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1169 1217
 		$user_info['permissions'][] = 'profile_view_own';
1170
-		if (in_array('profile_view', $user_info['permissions']))
1171
-			$user_info['permissions'][] = 'profile_view_any';
1218
+		if (in_array('profile_view', $user_info['permissions'])) {
1219
+					$user_info['permissions'][] = 'profile_view_any';
1220
+		}
1172 1221
 	}
1173 1222
 }
1174 1223
 
@@ -1186,8 +1235,9 @@  discard block
 block discarded – undo
1186 1235
 	global $image_proxy_enabled, $user_info;
1187 1236
 
1188 1237
 	// Can't just look for no users :P.
1189
-	if (empty($users))
1190
-		return array();
1238
+	if (empty($users)) {
1239
+			return array();
1240
+	}
1191 1241
 
1192 1242
 	// Pass the set value
1193 1243
 	$context['loadMemberContext_set'] = $set;
@@ -1202,8 +1252,9 @@  discard block
 block discarded – undo
1202 1252
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1203 1253
 		{
1204 1254
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1205
-			if ($data == null)
1206
-				continue;
1255
+			if ($data == null) {
1256
+							continue;
1257
+			}
1207 1258
 
1208 1259
 			$loaded_ids[] = $data['id_member'];
1209 1260
 			$user_profile[$data['id_member']] = $data;
@@ -1270,16 +1321,19 @@  discard block
 block discarded – undo
1270 1321
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1271 1322
 
1272 1323
 			// Take care of proxying avatar if required, do this here for maximum reach
1273
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1274
-				$row['avatar'] = get_proxied_url($row['avatar']);
1324
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1325
+							$row['avatar'] = get_proxied_url($row['avatar']);
1326
+			}
1275 1327
 
1276 1328
 			// Keep track of the member's normal member group
1277 1329
 			$row['primary_group'] = !empty($row['member_group']) ? $row['member_group'] : '';
1278 1330
 
1279
-			if (isset($row['member_ip']))
1280
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1281
-			if (isset($row['member_ip2']))
1282
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1331
+			if (isset($row['member_ip'])) {
1332
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1333
+			}
1334
+			if (isset($row['member_ip2'])) {
1335
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1336
+			}
1283 1337
 			$new_loaded_ids[] = $row['id_member'];
1284 1338
 			$loaded_ids[] = $row['id_member'];
1285 1339
 			$row['options'] = array();
@@ -1298,8 +1352,9 @@  discard block
 block discarded – undo
1298 1352
 				'loaded_ids' => $new_loaded_ids,
1299 1353
 			)
1300 1354
 		);
1301
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1302
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1355
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1356
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1357
+		}
1303 1358
 		$smcFunc['db_free_result']($request);
1304 1359
 	}
1305 1360
 
@@ -1310,10 +1365,11 @@  discard block
 block discarded – undo
1310 1365
 	{
1311 1366
 		foreach ($loaded_ids as $a_member)
1312 1367
 		{
1313
-			if (!empty($user_profile[$a_member]['additional_groups']))
1314
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1315
-			else
1316
-				$groups = array($user_profile[$a_member]['id_group']);
1368
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1369
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1370
+			} else {
1371
+							$groups = array($user_profile[$a_member]['id_group']);
1372
+			}
1317 1373
 
1318 1374
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1319 1375
 
@@ -1326,8 +1382,9 @@  discard block
 block discarded – undo
1326 1382
 
1327 1383
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1328 1384
 	{
1329
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1330
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1385
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1386
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1387
+		}
1331 1388
 	}
1332 1389
 
1333 1390
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1353,14 +1410,17 @@  discard block
 block discarded – undo
1353 1410
 		foreach ($temp_mods as $id)
1354 1411
 		{
1355 1412
 			// By popular demand, don't show admins or global moderators as moderators.
1356
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1357
-				$user_profile[$id]['member_group'] = $row['member_group'];
1413
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1414
+							$user_profile[$id]['member_group'] = $row['member_group'];
1415
+			}
1358 1416
 
1359 1417
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1360
-			if (!empty($row['icons']))
1361
-				$user_profile[$id]['icons'] = $row['icons'];
1362
-			if (!empty($row['member_group_color']))
1363
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1418
+			if (!empty($row['icons'])) {
1419
+							$user_profile[$id]['icons'] = $row['icons'];
1420
+			}
1421
+			if (!empty($row['member_group_color'])) {
1422
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1423
+			}
1364 1424
 		}
1365 1425
 	}
1366 1426
 
@@ -1382,12 +1442,14 @@  discard block
 block discarded – undo
1382 1442
 	static $loadedLanguages = array();
1383 1443
 
1384 1444
 	// If this person's data is already loaded, skip it.
1385
-	if (isset($dataLoaded[$user]))
1386
-		return true;
1445
+	if (isset($dataLoaded[$user])) {
1446
+			return true;
1447
+	}
1387 1448
 
1388 1449
 	// We can't load guests or members not loaded by loadMemberData()!
1389
-	if ($user == 0)
1390
-		return false;
1450
+	if ($user == 0) {
1451
+			return false;
1452
+	}
1391 1453
 	if (!isset($user_profile[$user]))
1392 1454
 	{
1393 1455
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1413,12 +1475,16 @@  discard block
 block discarded – undo
1413 1475
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1414 1476
 
1415 1477
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1416
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1478
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1479
+		//icon is set and exists
1417 1480
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1418
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1481
+	} elseif (isset($profile['icons'][1])) {
1482
+		//icon is set and doesn't exist, fallback to default
1419 1483
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1420
-	else //not set, bye bye
1484
+	} else {
1485
+		//not set, bye bye
1421 1486
 		$group_icon_url = '';
1487
+	}
1422 1488
 
1423 1489
 	// These minimal values are always loaded
1424 1490
 	$memberContext[$user] = array(
@@ -1437,8 +1503,9 @@  discard block
 block discarded – undo
1437 1503
 	if ($context['loadMemberContext_set'] != 'minimal')
1438 1504
 	{
1439 1505
 		// Go the extra mile and load the user's native language name.
1440
-		if (empty($loadedLanguages))
1441
-			$loadedLanguages = getLanguages();
1506
+		if (empty($loadedLanguages)) {
1507
+					$loadedLanguages = getLanguages();
1508
+		}
1442 1509
 
1443 1510
 		$memberContext[$user] += array(
1444 1511
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1493,31 +1560,33 @@  discard block
 block discarded – undo
1493 1560
 	{
1494 1561
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1495 1562
 		{
1496
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1497
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1498
-			else
1499
-				$image = get_gravatar_url($profile['email_address']);
1500
-		}
1501
-		else
1563
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1564
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1565
+			} else {
1566
+							$image = get_gravatar_url($profile['email_address']);
1567
+			}
1568
+		} else
1502 1569
 		{
1503 1570
 			// So it's stored in the member table?
1504 1571
 			if (!empty($profile['avatar']))
1505 1572
 			{
1506 1573
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1574
+			} elseif (!empty($profile['filename'])) {
1575
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1507 1576
 			}
1508
-			elseif (!empty($profile['filename']))
1509
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1510 1577
 			// Right... no avatar...use the default one
1511
-			else
1512
-				$image = $modSettings['avatar_url'] . '/default.png';
1578
+			else {
1579
+							$image = $modSettings['avatar_url'] . '/default.png';
1580
+			}
1513 1581
 		}
1514
-		if (!empty($image))
1515
-			$memberContext[$user]['avatar'] = array(
1582
+		if (!empty($image)) {
1583
+					$memberContext[$user]['avatar'] = array(
1516 1584
 				'name' => $profile['avatar'],
1517 1585
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1518 1586
 				'href' => $image,
1519 1587
 				'url' => $image,
1520 1588
 			);
1589
+		}
1521 1590
 	}
1522 1591
 
1523 1592
 	// Are we also loading the members custom fields into context?
@@ -1525,13 +1594,15 @@  discard block
 block discarded – undo
1525 1594
 	{
1526 1595
 		$memberContext[$user]['custom_fields'] = array();
1527 1596
 
1528
-		if (!isset($context['display_fields']))
1529
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1597
+		if (!isset($context['display_fields'])) {
1598
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1599
+		}
1530 1600
 
1531 1601
 		foreach ($context['display_fields'] as $custom)
1532 1602
 		{
1533
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1534
-				continue;
1603
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1604
+							continue;
1605
+			}
1535 1606
 
1536 1607
 			$value = $profile['options'][$custom['col_name']];
1537 1608
 
@@ -1539,31 +1610,36 @@  discard block
 block discarded – undo
1539 1610
 			$currentKey = 0;
1540 1611
 
1541 1612
 			// Create a key => value array for multiple options fields
1542
-			if (!empty($custom['options']))
1543
-				foreach ($custom['options'] as $k => $v)
1613
+			if (!empty($custom['options'])) {
1614
+							foreach ($custom['options'] as $k => $v)
1544 1615
 				{
1545 1616
 					$fieldOptions[] = $v;
1546
-					if (empty($currentKey))
1547
-						$currentKey = $v == $value ? $k : 0;
1617
+			}
1618
+					if (empty($currentKey)) {
1619
+											$currentKey = $v == $value ? $k : 0;
1620
+					}
1548 1621
 				}
1549 1622
 
1550 1623
 			// BBC?
1551
-			if ($custom['bbc'])
1552
-				$value = parse_bbc($value);
1624
+			if ($custom['bbc']) {
1625
+							$value = parse_bbc($value);
1626
+			}
1553 1627
 
1554 1628
 			// ... or checkbox?
1555
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1556
-				$value = $value ? $txt['yes'] : $txt['no'];
1629
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1630
+							$value = $value ? $txt['yes'] : $txt['no'];
1631
+			}
1557 1632
 
1558 1633
 			// Enclosing the user input within some other text?
1559
-			if (!empty($custom['enclose']))
1560
-				$value = strtr($custom['enclose'], array(
1634
+			if (!empty($custom['enclose'])) {
1635
+							$value = strtr($custom['enclose'], array(
1561 1636
 					'{SCRIPTURL}' => $scripturl,
1562 1637
 					'{IMAGES_URL}' => $settings['images_url'],
1563 1638
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1564 1639
 					'{INPUT}' => $value,
1565 1640
 					'{KEY}' => $currentKey,
1566 1641
 				));
1642
+			}
1567 1643
 
1568 1644
 			$memberContext[$user]['custom_fields'][] = array(
1569 1645
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1590,8 +1666,9 @@  discard block
 block discarded – undo
1590 1666
 	global $smcFunc, $txt, $scripturl, $settings;
1591 1667
 
1592 1668
 	// Do not waste my time...
1593
-	if (empty($users) || empty($params))
1594
-		return false;
1669
+	if (empty($users) || empty($params)) {
1670
+			return false;
1671
+	}
1595 1672
 
1596 1673
 	// Make sure it's an array.
1597 1674
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1618,41 +1695,48 @@  discard block
 block discarded – undo
1618 1695
 		$currentKey = 0;
1619 1696
 
1620 1697
 		// Create a key => value array for multiple options fields
1621
-		if (!empty($row['field_options']))
1622
-			foreach (explode(',', $row['field_options']) as $k => $v)
1698
+		if (!empty($row['field_options'])) {
1699
+					foreach (explode(',', $row['field_options']) as $k => $v)
1623 1700
 			{
1624 1701
 				$fieldOptions[] = $v;
1625
-				if (empty($currentKey))
1626
-					$currentKey = $v == $row['value'] ? $k : 0;
1702
+		}
1703
+				if (empty($currentKey)) {
1704
+									$currentKey = $v == $row['value'] ? $k : 0;
1705
+				}
1627 1706
 			}
1628 1707
 
1629 1708
 		// BBC?
1630
-		if (!empty($row['bbc']))
1631
-			$row['value'] = parse_bbc($row['value']);
1709
+		if (!empty($row['bbc'])) {
1710
+					$row['value'] = parse_bbc($row['value']);
1711
+		}
1632 1712
 
1633 1713
 		// ... or checkbox?
1634
-		elseif (isset($row['type']) && $row['type'] == 'check')
1635
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1714
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1715
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1716
+		}
1636 1717
 
1637 1718
 		// Enclosing the user input within some other text?
1638
-		if (!empty($row['enclose']))
1639
-			$row['value'] = strtr($row['enclose'], array(
1719
+		if (!empty($row['enclose'])) {
1720
+					$row['value'] = strtr($row['enclose'], array(
1640 1721
 				'{SCRIPTURL}' => $scripturl,
1641 1722
 				'{IMAGES_URL}' => $settings['images_url'],
1642 1723
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1643 1724
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1644 1725
 				'{KEY}' => $currentKey,
1645 1726
 			));
1727
+		}
1646 1728
 
1647 1729
 		// Send a simple array if there is just 1 param
1648
-		if (count($params) == 1)
1649
-			$return[$row['id_member']] = $row;
1730
+		if (count($params) == 1) {
1731
+					$return[$row['id_member']] = $row;
1732
+		}
1650 1733
 
1651 1734
 		// More than 1? knock yourself out...
1652 1735
 		else
1653 1736
 		{
1654
-			if (!isset($return[$row['id_member']]))
1655
-				$return[$row['id_member']] = array();
1737
+			if (!isset($return[$row['id_member']])) {
1738
+							$return[$row['id_member']] = array();
1739
+			}
1656 1740
 
1657 1741
 			$return[$row['id_member']][$row['variable']] = $row;
1658 1742
 		}
@@ -1686,8 +1770,9 @@  discard block
 block discarded – undo
1686 1770
 	global $context;
1687 1771
 
1688 1772
 	// Don't know any browser!
1689
-	if (empty($context['browser']))
1690
-		detectBrowser();
1773
+	if (empty($context['browser'])) {
1774
+			detectBrowser();
1775
+	}
1691 1776
 
1692 1777
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1693 1778
 }
@@ -1705,8 +1790,9 @@  discard block
 block discarded – undo
1705 1790
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1706 1791
 
1707 1792
 	// The theme was specified by parameter.
1708
-	if (!empty($id_theme))
1709
-		$id_theme = (int) $id_theme;
1793
+	if (!empty($id_theme)) {
1794
+			$id_theme = (int) $id_theme;
1795
+	}
1710 1796
 	// The theme was specified by REQUEST.
1711 1797
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1712 1798
 	{
@@ -1714,32 +1800,38 @@  discard block
 block discarded – undo
1714 1800
 		$_SESSION['id_theme'] = $id_theme;
1715 1801
 	}
1716 1802
 	// The theme was specified by REQUEST... previously.
1717
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1718
-		$id_theme = (int) $_SESSION['id_theme'];
1803
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1804
+			$id_theme = (int) $_SESSION['id_theme'];
1805
+	}
1719 1806
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1720
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1721
-		$id_theme = $user_info['theme'];
1807
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1808
+			$id_theme = $user_info['theme'];
1809
+	}
1722 1810
 	// The theme was specified by the board.
1723
-	elseif (!empty($board_info['theme']))
1724
-		$id_theme = $board_info['theme'];
1811
+	elseif (!empty($board_info['theme'])) {
1812
+			$id_theme = $board_info['theme'];
1813
+	}
1725 1814
 	// The theme is the forum's default.
1726
-	else
1727
-		$id_theme = $modSettings['theme_guests'];
1815
+	else {
1816
+			$id_theme = $modSettings['theme_guests'];
1817
+	}
1728 1818
 
1729 1819
 	// Verify the id_theme... no foul play.
1730 1820
 	// Always allow the board specific theme, if they are overriding.
1731
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1732
-		$id_theme = $board_info['theme'];
1821
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1822
+			$id_theme = $board_info['theme'];
1823
+	}
1733 1824
 	// If they have specified a particular theme to use with SSI allow it to be used.
1734
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1735
-		$id_theme = (int) $id_theme;
1736
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1825
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1826
+			$id_theme = (int) $id_theme;
1827
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1737 1828
 	{
1738 1829
 		$themes = explode(',', $modSettings['enableThemes']);
1739
-		if (!in_array($id_theme, $themes))
1740
-			$id_theme = $modSettings['theme_guests'];
1741
-		else
1742
-			$id_theme = (int) $id_theme;
1830
+		if (!in_array($id_theme, $themes)) {
1831
+					$id_theme = $modSettings['theme_guests'];
1832
+		} else {
1833
+					$id_theme = (int) $id_theme;
1834
+		}
1743 1835
 	}
1744 1836
 		
1745 1837
 	// We already load the basic stuff?
@@ -1748,18 +1840,19 @@  discard block
 block discarded – undo
1748 1840
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1749 1841
 
1750 1842
 		// Disable image proxy if we don't have SSL enabled
1751
-		if (empty($modSettings['force_ssl']))
1752
-			$image_proxy_enabled = false;
1843
+		if (empty($modSettings['force_ssl'])) {
1844
+					$image_proxy_enabled = false;
1845
+		}
1753 1846
 
1754 1847
 		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1755 1848
 		{
1756 1849
 			$themeData = $temp;
1757 1850
 			$flag = true;
1851
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1852
+					$themeData = $temp + array($member => array());
1853
+		} else {
1854
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1758 1855
 		}
1759
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1760
-			$themeData = $temp + array($member => array());
1761
-		else
1762
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1763 1856
 
1764 1857
 		if (empty($flag))
1765 1858
 		{
@@ -1779,31 +1872,37 @@  discard block
 block discarded – undo
1779 1872
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1780 1873
 			{
1781 1874
 				// There are just things we shouldn't be able to change as members.
1782
-				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1783
-					continue;
1875
+				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1876
+									continue;
1877
+				}
1784 1878
 
1785 1879
 				// If this is the theme_dir of the default theme, store it.
1786
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1787
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1880
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1881
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1882
+				}
1788 1883
 
1789 1884
 				// If this isn't set yet, is a theme option, or is not the default theme..
1790
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1791
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1885
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1886
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1887
+				}
1792 1888
 			}
1793 1889
 			$smcFunc['db_free_result']($result);
1794 1890
 
1795
-			if (!empty($themeData[-1]))
1796
-				foreach ($themeData[-1] as $k => $v)
1891
+			if (!empty($themeData[-1])) {
1892
+							foreach ($themeData[-1] as $k => $v)
1797 1893
 				{
1798 1894
 					if (!isset($themeData[$member][$k]))
1799 1895
 						$themeData[$member][$k] = $v;
1896
+			}
1800 1897
 				}
1801 1898
 
1802
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1803
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1899
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1900
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1901
+			}
1804 1902
 			// Only if we didn't already load that part of the cache...
1805
-			elseif (!isset($temp))
1806
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1903
+			elseif (!isset($temp)) {
1904
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1905
+			}
1807 1906
 		}
1808 1907
 
1809 1908
 		$settings = $themeData[0];
@@ -1820,17 +1919,20 @@  discard block
 block discarded – undo
1820 1919
 		$settings['template_dirs'][] = $settings['theme_dir'];
1821 1920
 
1822 1921
 		// Based on theme (if there is one).
1823
-		if (!empty($settings['base_theme_dir']))
1824
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1922
+		if (!empty($settings['base_theme_dir'])) {
1923
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1924
+		}
1825 1925
 
1826 1926
 		// Lastly the default theme.
1827
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1828
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1927
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1928
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1929
+		}
1829 1930
 	}
1830 1931
 
1831 1932
 
1832
-	if (!$initialize)
1833
-		return;
1933
+	if (!$initialize) {
1934
+			return;
1935
+	}
1834 1936
 
1835 1937
 	// Check to see if we're forcing SSL
1836 1938
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1851,8 +1953,9 @@  discard block
 block discarded – undo
1851 1953
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1852 1954
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1853 1955
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1854
-		if ($temp != '/')
1855
-			$detected_url .= $temp;
1956
+		if ($temp != '/') {
1957
+					$detected_url .= $temp;
1958
+		}
1856 1959
 	}
1857 1960
 	if (isset($detected_url) && $detected_url != $boardurl)
1858 1961
 	{
@@ -1864,8 +1967,9 @@  discard block
 block discarded – undo
1864 1967
 			foreach ($aliases as $alias)
1865 1968
 			{
1866 1969
 				// Rip off all the boring parts, spaces, etc.
1867
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1868
-					$do_fix = true;
1970
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1971
+									$do_fix = true;
1972
+				}
1869 1973
 			}
1870 1974
 		}
1871 1975
 
@@ -1873,21 +1977,23 @@  discard block
 block discarded – undo
1873 1977
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1874 1978
 		{
1875 1979
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1876
-			if (empty($_GET))
1877
-				redirectexit('wwwRedirect');
1878
-			else
1980
+			if (empty($_GET)) {
1981
+							redirectexit('wwwRedirect');
1982
+			} else
1879 1983
 			{
1880 1984
 				$k = key($_GET);
1881 1985
 				$v = current($_GET);
1882 1986
 
1883
-				if ($k != 'wwwRedirect')
1884
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1987
+				if ($k != 'wwwRedirect') {
1988
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1989
+				}
1885 1990
 			}
1886 1991
 		}
1887 1992
 
1888 1993
 		// #3 is just a check for SSL...
1889
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1890
-			$do_fix = true;
1994
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1995
+					$do_fix = true;
1996
+		}
1891 1997
 
1892 1998
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1893 1999
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1922,8 +2028,9 @@  discard block
 block discarded – undo
1922 2028
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1923 2029
 				}
1924 2030
 			}
1925
-			foreach ($context['linktree'] as $k => $dummy)
1926
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2031
+			foreach ($context['linktree'] as $k => $dummy) {
2032
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2033
+			}
1927 2034
 		}
1928 2035
 	}
1929 2036
 	// Set up the contextual user array.
@@ -1942,16 +2049,16 @@  discard block
 block discarded – undo
1942 2049
 			'email' => $user_info['email'],
1943 2050
 			'ignoreusers' => $user_info['ignoreusers'],
1944 2051
 		);
1945
-		if (!$context['user']['is_guest'])
1946
-			$context['user']['name'] = $user_info['name'];
1947
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1948
-			$context['user']['name'] = $txt['guest_title'];
2052
+		if (!$context['user']['is_guest']) {
2053
+					$context['user']['name'] = $user_info['name'];
2054
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2055
+					$context['user']['name'] = $txt['guest_title'];
2056
+		}
1949 2057
 
1950 2058
 		// Determine the current smiley set.
1951 2059
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1952 2060
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1953
-	}
1954
-	else
2061
+	} else
1955 2062
 	{
1956 2063
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1957 2064
 		$context['user'] = array(
@@ -1985,18 +2092,24 @@  discard block
 block discarded – undo
1985 2092
 	}
1986 2093
 
1987 2094
 	// Some basic information...
1988
-	if (!isset($context['html_headers']))
1989
-		$context['html_headers'] = '';
1990
-	if (!isset($context['javascript_files']))
1991
-		$context['javascript_files'] = array();
1992
-	if (!isset($context['css_files']))
1993
-		$context['css_files'] = array();
1994
-	if (!isset($context['css_header']))
1995
-		$context['css_header'] = array();
1996
-	if (!isset($context['javascript_inline']))
1997
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1998
-	if (!isset($context['javascript_vars']))
1999
-		$context['javascript_vars'] = array();
2095
+	if (!isset($context['html_headers'])) {
2096
+			$context['html_headers'] = '';
2097
+	}
2098
+	if (!isset($context['javascript_files'])) {
2099
+			$context['javascript_files'] = array();
2100
+	}
2101
+	if (!isset($context['css_files'])) {
2102
+			$context['css_files'] = array();
2103
+	}
2104
+	if (!isset($context['css_header'])) {
2105
+			$context['css_header'] = array();
2106
+	}
2107
+	if (!isset($context['javascript_inline'])) {
2108
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2109
+	}
2110
+	if (!isset($context['javascript_vars'])) {
2111
+			$context['javascript_vars'] = array();
2112
+	}
2000 2113
 
2001 2114
 	$context['login_url'] =  $scripturl . '?action=login2';
2002 2115
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2008,16 +2121,18 @@  discard block
 block discarded – undo
2008 2121
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2009 2122
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2010 2123
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2011
-	if (isset($modSettings['load_average']))
2012
-		$context['load_average'] = $modSettings['load_average'];
2124
+	if (isset($modSettings['load_average'])) {
2125
+			$context['load_average'] = $modSettings['load_average'];
2126
+	}
2013 2127
 
2014 2128
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2015 2129
 	detectBrowser();
2016 2130
 
2017 2131
 	// Set the top level linktree up.
2018 2132
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2019
-	if (empty($context['linktree']))
2020
-		$context['linktree'] = array();
2133
+	if (empty($context['linktree'])) {
2134
+			$context['linktree'] = array();
2135
+	}
2021 2136
 	array_unshift($context['linktree'], array(
2022 2137
 		'url' => $scripturl,
2023 2138
 		'name' => $context['forum_name_html_safe']
@@ -2026,8 +2141,9 @@  discard block
 block discarded – undo
2026 2141
 	// This allows sticking some HTML on the page output - useful for controls.
2027 2142
 	$context['insert_after_template'] = '';
2028 2143
 
2029
-	if (!isset($txt))
2030
-		$txt = array();
2144
+	if (!isset($txt)) {
2145
+			$txt = array();
2146
+	}
2031 2147
 
2032 2148
 	$simpleActions = array(
2033 2149
 		'findmember',
@@ -2073,9 +2189,10 @@  discard block
 block discarded – undo
2073 2189
 
2074 2190
 	// See if theres any extra param to check.
2075 2191
 	$requiresXML = false;
2076
-	foreach ($extraParams as $key => $extra)
2077
-		if (isset($_REQUEST[$extra]))
2192
+	foreach ($extraParams as $key => $extra) {
2193
+			if (isset($_REQUEST[$extra]))
2078 2194
 			$requiresXML = true;
2195
+	}
2079 2196
 
2080 2197
 	// Output is fully XML, so no need for the index template.
2081 2198
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2090,37 +2207,39 @@  discard block
 block discarded – undo
2090 2207
 	{
2091 2208
 		loadLanguage('index+Modifications');
2092 2209
 		$context['template_layers'] = array();
2093
-	}
2094
-
2095
-	else
2210
+	} else
2096 2211
 	{
2097 2212
 		// Custom templates to load, or just default?
2098
-		if (isset($settings['theme_templates']))
2099
-			$templates = explode(',', $settings['theme_templates']);
2100
-		else
2101
-			$templates = array('index');
2213
+		if (isset($settings['theme_templates'])) {
2214
+					$templates = explode(',', $settings['theme_templates']);
2215
+		} else {
2216
+					$templates = array('index');
2217
+		}
2102 2218
 
2103 2219
 		// Load each template...
2104
-		foreach ($templates as $template)
2105
-			loadTemplate($template);
2220
+		foreach ($templates as $template) {
2221
+					loadTemplate($template);
2222
+		}
2106 2223
 
2107 2224
 		// ...and attempt to load their associated language files.
2108 2225
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2109 2226
 		loadLanguage($required_files, '', false);
2110 2227
 
2111 2228
 		// Custom template layers?
2112
-		if (isset($settings['theme_layers']))
2113
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2114
-		else
2115
-			$context['template_layers'] = array('html', 'body');
2229
+		if (isset($settings['theme_layers'])) {
2230
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2231
+		} else {
2232
+					$context['template_layers'] = array('html', 'body');
2233
+		}
2116 2234
 	}
2117 2235
 
2118 2236
 	// Initialize the theme.
2119 2237
 	loadSubTemplate('init', 'ignore');
2120 2238
 
2121 2239
 	// Allow overriding the board wide time/number formats.
2122
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2123
-		$user_info['time_format'] = $txt['time_format'];
2240
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2241
+			$user_info['time_format'] = $txt['time_format'];
2242
+	}
2124 2243
 
2125 2244
 	// Set the character set from the template.
2126 2245
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2128,12 +2247,14 @@  discard block
 block discarded – undo
2128 2247
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2129 2248
 
2130 2249
 	// Guests may still need a name.
2131
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2132
-		$context['user']['name'] = $txt['guest_title'];
2250
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2251
+			$context['user']['name'] = $txt['guest_title'];
2252
+	}
2133 2253
 
2134 2254
 	// Any theme-related strings that need to be loaded?
2135
-	if (!empty($settings['require_theme_strings']))
2136
-		loadLanguage('ThemeStrings', '', false);
2255
+	if (!empty($settings['require_theme_strings'])) {
2256
+			loadLanguage('ThemeStrings', '', false);
2257
+	}
2137 2258
 
2138 2259
 	// Make a special URL for the language.
2139 2260
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2144,8 +2265,9 @@  discard block
 block discarded – undo
2144 2265
 	// Here is my luvly Responsive CSS
2145 2266
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2146 2267
 
2147
-	if ($context['right_to_left'])
2148
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2268
+	if ($context['right_to_left']) {
2269
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2270
+	}
2149 2271
 
2150 2272
 	// We allow theme variants, because we're cool.
2151 2273
 	$context['theme_variant'] = '';
@@ -2153,14 +2275,17 @@  discard block
 block discarded – undo
2153 2275
 	if (!empty($settings['theme_variants']))
2154 2276
 	{
2155 2277
 		// Overriding - for previews and that ilk.
2156
-		if (!empty($_REQUEST['variant']))
2157
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2278
+		if (!empty($_REQUEST['variant'])) {
2279
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2280
+		}
2158 2281
 		// User selection?
2159
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2160
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2282
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2283
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2284
+		}
2161 2285
 		// If not a user variant, select the default.
2162
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2163
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2286
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2287
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2288
+		}
2164 2289
 
2165 2290
 		// Do this to keep things easier in the templates.
2166 2291
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2169,20 +2294,23 @@  discard block
 block discarded – undo
2169 2294
 		if (!empty($context['theme_variant']))
2170 2295
 		{
2171 2296
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2172
-			if ($context['right_to_left'])
2173
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2297
+			if ($context['right_to_left']) {
2298
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2299
+			}
2174 2300
 		}
2175 2301
 	}
2176 2302
 
2177 2303
 	// Let's be compatible with old themes!
2178
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2179
-		$context['template_layers'] = array('main');
2304
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2305
+			$context['template_layers'] = array('main');
2306
+	}
2180 2307
 
2181 2308
 	$context['tabindex'] = 1;
2182 2309
 
2183 2310
 	// Compatibility.
2184
-	if (!isset($settings['theme_version']))
2185
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2311
+	if (!isset($settings['theme_version'])) {
2312
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2313
+	}
2186 2314
 
2187 2315
 	// Default JS variables for use in every theme
2188 2316
 	$context['javascript_vars'] = array(
@@ -2202,18 +2330,18 @@  discard block
 block discarded – undo
2202 2330
 	);
2203 2331
 
2204 2332
 	// Add the JQuery library to the list of files to load.
2205
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2206
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2207
-
2208
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2209
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2210
-
2211
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2212
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2333
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2334
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2335
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2336
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2337
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2338
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2339
+	}
2213 2340
 
2214 2341
 	// Auto loading? template_javascript() will take care of the local half of this.
2215
-	else
2216
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2342
+	else {
2343
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2344
+	}
2217 2345
 
2218 2346
 	// Queue our JQuery plugins!
2219 2347
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2236,12 +2364,12 @@  discard block
 block discarded – undo
2236 2364
 			require_once($sourcedir . '/ScheduledTasks.php');
2237 2365
 
2238 2366
 			// What to do, what to do?!
2239
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2240
-				AutoTask();
2241
-			else
2242
-				ReduceMailQueue();
2243
-		}
2244
-		else
2367
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2368
+							AutoTask();
2369
+			} else {
2370
+							ReduceMailQueue();
2371
+			}
2372
+		} else
2245 2373
 		{
2246 2374
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2247 2375
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2292,8 +2420,9 @@  discard block
 block discarded – undo
2292 2420
 		foreach ($theme_includes as $include)
2293 2421
 		{
2294 2422
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2295
-			if (file_exists($include))
2296
-				require_once($include);
2423
+			if (file_exists($include)) {
2424
+							require_once($include);
2425
+			}
2297 2426
 		}
2298 2427
 	}
2299 2428
 
@@ -2323,16 +2452,19 @@  discard block
 block discarded – undo
2323 2452
 	// Do any style sheets first, cause we're easy with those.
2324 2453
 	if (!empty($style_sheets))
2325 2454
 	{
2326
-		if (!is_array($style_sheets))
2327
-			$style_sheets = array($style_sheets);
2455
+		if (!is_array($style_sheets)) {
2456
+					$style_sheets = array($style_sheets);
2457
+		}
2328 2458
 
2329
-		foreach ($style_sheets as $sheet)
2330
-			loadCSSFile($sheet . '.css', array(), $sheet);
2459
+		foreach ($style_sheets as $sheet) {
2460
+					loadCSSFile($sheet . '.css', array(), $sheet);
2461
+		}
2331 2462
 	}
2332 2463
 
2333 2464
 	// No template to load?
2334
-	if ($template_name === false)
2335
-		return true;
2465
+	if ($template_name === false) {
2466
+			return true;
2467
+	}
2336 2468
 
2337 2469
 	$loaded = false;
2338 2470
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2347,12 +2479,14 @@  discard block
 block discarded – undo
2347 2479
 
2348 2480
 	if ($loaded)
2349 2481
 	{
2350
-		if ($db_show_debug === true)
2351
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2482
+		if ($db_show_debug === true) {
2483
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2484
+		}
2352 2485
 
2353 2486
 		// If they have specified an initialization function for this template, go ahead and call it now.
2354
-		if (function_exists('template_' . $template_name . '_init'))
2355
-			call_user_func('template_' . $template_name . '_init');
2487
+		if (function_exists('template_' . $template_name . '_init')) {
2488
+					call_user_func('template_' . $template_name . '_init');
2489
+		}
2356 2490
 	}
2357 2491
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2358 2492
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2372,13 +2506,14 @@  discard block
 block discarded – undo
2372 2506
 		loadTemplate($template_name);
2373 2507
 	}
2374 2508
 	// Cause an error otherwise.
2375
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2376
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2377
-	elseif ($fatal)
2378
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2379
-	else
2380
-		return false;
2381
-}
2509
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2510
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2511
+	} elseif ($fatal) {
2512
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2513
+	} else {
2514
+			return false;
2515
+	}
2516
+	}
2382 2517
 
2383 2518
 /**
2384 2519
  * Load a sub-template.
@@ -2396,17 +2531,19 @@  discard block
 block discarded – undo
2396 2531
 {
2397 2532
 	global $context, $txt, $db_show_debug;
2398 2533
 
2399
-	if ($db_show_debug === true)
2400
-		$context['debug']['sub_templates'][] = $sub_template_name;
2534
+	if ($db_show_debug === true) {
2535
+			$context['debug']['sub_templates'][] = $sub_template_name;
2536
+	}
2401 2537
 
2402 2538
 	// Figure out what the template function is named.
2403 2539
 	$theme_function = 'template_' . $sub_template_name;
2404
-	if (function_exists($theme_function))
2405
-		$theme_function();
2406
-	elseif ($fatal === false)
2407
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2408
-	elseif ($fatal !== 'ignore')
2409
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2540
+	if (function_exists($theme_function)) {
2541
+			$theme_function();
2542
+	} elseif ($fatal === false) {
2543
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2544
+	} elseif ($fatal !== 'ignore') {
2545
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2546
+	}
2410 2547
 
2411 2548
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2412 2549
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2436,8 +2573,9 @@  discard block
 block discarded – undo
2436 2573
 {
2437 2574
 	global $settings, $context, $modSettings;
2438 2575
 
2439
-	if (empty($context['css_files_order']))
2440
-		$context['css_files_order'] = array();
2576
+	if (empty($context['css_files_order'])) {
2577
+			$context['css_files_order'] = array();
2578
+	}
2441 2579
 
2442 2580
 	$params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
2443 2581
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2448,8 +2586,9 @@  discard block
 block discarded – undo
2448 2586
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2449 2587
 
2450 2588
 	// If this is an external file, automatically set this to false.
2451
-	if (!empty($params['external']))
2452
-		$params['minimize'] = false;
2589
+	if (!empty($params['external'])) {
2590
+			$params['minimize'] = false;
2591
+	}
2453 2592
 
2454 2593
 	// Account for shorthand like admin.css?alp21 filenames
2455 2594
 	$has_seed = strpos($fileName, '.css?');
@@ -2466,16 +2605,12 @@  discard block
 block discarded – undo
2466 2605
 			{
2467 2606
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2468 2607
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2469
-			}
2470
-
2471
-			else
2608
+			} else
2472 2609
 			{
2473 2610
 				$fileUrl = false;
2474 2611
 				$filePath = false;
2475 2612
 			}
2476
-		}
2477
-
2478
-		else
2613
+		} else
2479 2614
 		{
2480 2615
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2481 2616
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2493,16 +2628,18 @@  discard block
 block discarded – undo
2493 2628
 	if (!empty($fileName))
2494 2629
 	{
2495 2630
 		// find a free number/position
2496
-		while (isset($context['css_files_order'][$params['order_pos']]))
2497
-			$params['order_pos']++;
2631
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2632
+					$params['order_pos']++;
2633
+		}
2498 2634
 		$context['css_files_order'][$params['order_pos']] = $id;
2499 2635
 
2500 2636
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2501 2637
 	}
2502 2638
 
2503
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2504
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2505
-}
2639
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2640
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2641
+	}
2642
+	}
2506 2643
 
2507 2644
 /**
2508 2645
  * Add a block of inline css code to be executed later
@@ -2519,8 +2656,9 @@  discard block
 block discarded – undo
2519 2656
 	global $context;
2520 2657
 
2521 2658
 	// Gotta add something...
2522
-	if (empty($css))
2523
-		return false;
2659
+	if (empty($css)) {
2660
+			return false;
2661
+	}
2524 2662
 
2525 2663
 	$context['css_header'][] = $css;
2526 2664
 }
@@ -2556,8 +2694,9 @@  discard block
 block discarded – undo
2556 2694
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2557 2695
 
2558 2696
 	// If this is an external file, automatically set this to false.
2559
-	if (!empty($params['external']))
2560
-		$params['minimize'] = false;
2697
+	if (!empty($params['external'])) {
2698
+			$params['minimize'] = false;
2699
+	}
2561 2700
 
2562 2701
 	// Account for shorthand like admin.js?alp21 filenames
2563 2702
 	$has_seed = strpos($fileName, '.js?');
@@ -2574,16 +2713,12 @@  discard block
 block discarded – undo
2574 2713
 			{
2575 2714
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2576 2715
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2577
-			}
2578
-
2579
-			else
2716
+			} else
2580 2717
 			{
2581 2718
 				$fileUrl = false;
2582 2719
 				$filePath = false;
2583 2720
 			}
2584
-		}
2585
-
2586
-		else
2721
+		} else
2587 2722
 		{
2588 2723
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2589 2724
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2598,9 +2733,10 @@  discard block
 block discarded – undo
2598 2733
 	}
2599 2734
 
2600 2735
 	// Add it to the array for use in the template
2601
-	if (!empty($fileName))
2602
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2603
-}
2736
+	if (!empty($fileName)) {
2737
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2738
+	}
2739
+	}
2604 2740
 
2605 2741
 /**
2606 2742
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2614,9 +2750,10 @@  discard block
 block discarded – undo
2614 2750
 {
2615 2751
 	global $context;
2616 2752
 
2617
-	if (!empty($key) && (!empty($value) || $value === '0'))
2618
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2619
-}
2753
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2754
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2755
+	}
2756
+	}
2620 2757
 
2621 2758
 /**
2622 2759
  * Add a block of inline Javascript code to be executed later
@@ -2633,8 +2770,9 @@  discard block
 block discarded – undo
2633 2770
 {
2634 2771
 	global $context;
2635 2772
 
2636
-	if (empty($javascript))
2637
-		return false;
2773
+	if (empty($javascript)) {
2774
+			return false;
2775
+	}
2638 2776
 
2639 2777
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2640 2778
 }
@@ -2655,15 +2793,18 @@  discard block
 block discarded – undo
2655 2793
 	static $already_loaded = array();
2656 2794
 
2657 2795
 	// Default to the user's language.
2658
-	if ($lang == '')
2659
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2796
+	if ($lang == '') {
2797
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2798
+	}
2660 2799
 
2661 2800
 	// Do we want the English version of language file as fallback?
2662
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2663
-		loadLanguage($template_name, 'english', false);
2801
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2802
+			loadLanguage($template_name, 'english', false);
2803
+	}
2664 2804
 
2665
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2666
-		return $lang;
2805
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2806
+			return $lang;
2807
+	}
2667 2808
 
2668 2809
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2669 2810
 	if (empty($settings['default_theme_dir']))
@@ -2674,8 +2815,9 @@  discard block
 block discarded – undo
2674 2815
 
2675 2816
 	// What theme are we in?
2676 2817
 	$theme_name = basename($settings['theme_url']);
2677
-	if (empty($theme_name))
2678
-		$theme_name = 'unknown';
2818
+	if (empty($theme_name)) {
2819
+			$theme_name = 'unknown';
2820
+	}
2679 2821
 
2680 2822
 	// For each file open it up and write it out!
2681 2823
 	foreach (explode('+', $template_name) as $template)
@@ -2717,8 +2859,9 @@  discard block
 block discarded – undo
2717 2859
 				$found = true;
2718 2860
 
2719 2861
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2720
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2721
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2862
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2863
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2864
+				}
2722 2865
 
2723 2866
 				break;
2724 2867
 			}
@@ -2758,8 +2901,9 @@  discard block
 block discarded – undo
2758 2901
 	}
2759 2902
 
2760 2903
 	// Keep track of what we're up to soldier.
2761
-	if ($db_show_debug === true)
2762
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2904
+	if ($db_show_debug === true) {
2905
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2906
+	}
2763 2907
 
2764 2908
 	// Remember what we have loaded, and in which language.
2765 2909
 	$already_loaded[$template_name] = $lang;
@@ -2805,8 +2949,9 @@  discard block
 block discarded – undo
2805 2949
 				)
2806 2950
 			);
2807 2951
 			// In the EXTREMELY unlikely event this happens, give an error message.
2808
-			if ($smcFunc['db_num_rows']($result) == 0)
2809
-				fatal_lang_error('parent_not_found', 'critical');
2952
+			if ($smcFunc['db_num_rows']($result) == 0) {
2953
+							fatal_lang_error('parent_not_found', 'critical');
2954
+			}
2810 2955
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2811 2956
 			{
2812 2957
 				if (!isset($boards[$row['id_board']]))
@@ -2823,8 +2968,8 @@  discard block
 block discarded – undo
2823 2968
 					);
2824 2969
 				}
2825 2970
 				// If a moderator exists for this board, add that moderator for all children too.
2826
-				if (!empty($row['id_moderator']))
2827
-					foreach ($boards as $id => $dummy)
2971
+				if (!empty($row['id_moderator'])) {
2972
+									foreach ($boards as $id => $dummy)
2828 2973
 					{
2829 2974
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2830 2975
 							'id' => $row['id_moderator'],
@@ -2832,11 +2977,12 @@  discard block
 block discarded – undo
2832 2977
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2833 2978
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2834 2979
 						);
2980
+				}
2835 2981
 					}
2836 2982
 
2837 2983
 				// If a moderator group exists for this board, add that moderator group for all children too
2838
-				if (!empty($row['id_moderator_group']))
2839
-					foreach ($boards as $id => $dummy)
2984
+				if (!empty($row['id_moderator_group'])) {
2985
+									foreach ($boards as $id => $dummy)
2840 2986
 					{
2841 2987
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2842 2988
 							'id' => $row['id_moderator_group'],
@@ -2844,6 +2990,7 @@  discard block
 block discarded – undo
2844 2990
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2845 2991
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2846 2992
 						);
2993
+				}
2847 2994
 					}
2848 2995
 			}
2849 2996
 			$smcFunc['db_free_result']($result);
@@ -2870,23 +3017,27 @@  discard block
 block discarded – undo
2870 3017
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2871 3018
 	{
2872 3019
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2873
-		if (empty($smcFunc['ucwords']))
2874
-			reloadSettings();
3020
+		if (empty($smcFunc['ucwords'])) {
3021
+					reloadSettings();
3022
+		}
2875 3023
 
2876 3024
 		// If we don't have our theme information yet, let's get it.
2877
-		if (empty($settings['default_theme_dir']))
2878
-			loadTheme(0, false);
3025
+		if (empty($settings['default_theme_dir'])) {
3026
+					loadTheme(0, false);
3027
+		}
2879 3028
 
2880 3029
 		// Default language directories to try.
2881 3030
 		$language_directories = array(
2882 3031
 			$settings['default_theme_dir'] . '/languages',
2883 3032
 		);
2884
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2885
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3033
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3034
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3035
+		}
2886 3036
 
2887 3037
 		// We possibly have a base theme directory.
2888
-		if (!empty($settings['base_theme_dir']))
2889
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3038
+		if (!empty($settings['base_theme_dir'])) {
3039
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3040
+		}
2890 3041
 
2891 3042
 		// Remove any duplicates.
2892 3043
 		$language_directories = array_unique($language_directories);
@@ -2900,20 +3051,21 @@  discard block
 block discarded – undo
2900 3051
 		foreach ($language_directories as $language_dir)
2901 3052
 		{
2902 3053
 			// Can't look in here... doesn't exist!
2903
-			if (!file_exists($language_dir))
2904
-				continue;
3054
+			if (!file_exists($language_dir)) {
3055
+							continue;
3056
+			}
2905 3057
 
2906 3058
 			$dir = dir($language_dir);
2907 3059
 			while ($entry = $dir->read())
2908 3060
 			{
2909 3061
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2910
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2911
-					continue;
2912
-
2913
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2914
-					$langName = $langList[$matches[1]];
3062
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3063
+									continue;
3064
+				}
2915 3065
 
2916
-				else
3066
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3067
+									$langName = $langList[$matches[1]];
3068
+				} else
2917 3069
 				{
2918 3070
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2919 3071
 
@@ -2954,12 +3106,14 @@  discard block
 block discarded – undo
2954 3106
 		}
2955 3107
 
2956 3108
 		// Do we need to store the lang list?
2957
-		if (empty($langList))
2958
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3109
+		if (empty($langList)) {
3110
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3111
+		}
2959 3112
 
2960 3113
 		// Let's cash in on this deal.
2961
-		if (!empty($modSettings['cache_enable']))
2962
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3114
+		if (!empty($modSettings['cache_enable'])) {
3115
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3116
+		}
2963 3117
 	}
2964 3118
 
2965 3119
 	return $context['languages'];
@@ -2982,8 +3136,9 @@  discard block
 block discarded – undo
2982 3136
 	global $modSettings, $options, $txt;
2983 3137
 	static $censor_vulgar = null, $censor_proper;
2984 3138
 
2985
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2986
-		return $text;
3139
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3140
+			return $text;
3141
+	}
2987 3142
 
2988 3143
 	// If they haven't yet been loaded, load them.
2989 3144
 	if ($censor_vulgar == null)
@@ -3014,9 +3169,9 @@  discard block
 block discarded – undo
3014 3169
 	{
3015 3170
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3016 3171
 		$text = $func($censor_vulgar, $censor_proper, $text);
3172
+	} else {
3173
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3017 3174
 	}
3018
-	else
3019
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3020 3175
 
3021 3176
 	return $text;
3022 3177
 }
@@ -3042,30 +3197,35 @@  discard block
 block discarded – undo
3042 3197
 	@ini_set('track_errors', '1');
3043 3198
 
3044 3199
 	// Don't include the file more than once, if $once is true.
3045
-	if ($once && in_array($filename, $templates))
3046
-		return;
3200
+	if ($once && in_array($filename, $templates)) {
3201
+			return;
3202
+	}
3047 3203
 	// Add this file to the include list, whether $once is true or not.
3048
-	else
3049
-		$templates[] = $filename;
3204
+	else {
3205
+			$templates[] = $filename;
3206
+	}
3050 3207
 
3051 3208
 
3052 3209
 	$file_found = file_exists($filename);
3053 3210
 
3054
-	if ($once && $file_found)
3055
-		require_once($filename);
3056
-	elseif ($file_found)
3057
-		require($filename);
3211
+	if ($once && $file_found) {
3212
+			require_once($filename);
3213
+	} elseif ($file_found) {
3214
+			require($filename);
3215
+	}
3058 3216
 
3059 3217
 	if ($file_found !== true)
3060 3218
 	{
3061 3219
 		ob_end_clean();
3062
-		if (!empty($modSettings['enableCompressedOutput']))
3063
-			@ob_start('ob_gzhandler');
3064
-		else
3065
-			ob_start();
3220
+		if (!empty($modSettings['enableCompressedOutput'])) {
3221
+					@ob_start('ob_gzhandler');
3222
+		} else {
3223
+					ob_start();
3224
+		}
3066 3225
 
3067
-		if (isset($_GET['debug']))
3068
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3226
+		if (isset($_GET['debug'])) {
3227
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3228
+		}
3069 3229
 
3070 3230
 		// Don't cache error pages!!
3071 3231
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3084,12 +3244,13 @@  discard block
 block discarded – undo
3084 3244
 		echo '<!DOCTYPE html>
3085 3245
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3086 3246
 	<head>';
3087
-		if (isset($context['character_set']))
3088
-			echo '
3247
+		if (isset($context['character_set'])) {
3248
+					echo '
3089 3249
 		<meta charset="', $context['character_set'], '">';
3250
+		}
3090 3251
 
3091
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3092
-			echo '
3252
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3253
+					echo '
3093 3254
 		<title>', $mtitle, '</title>
3094 3255
 	</head>
3095 3256
 	<body>
@@ -3097,8 +3258,8 @@  discard block
 block discarded – undo
3097 3258
 		', $mmessage, '
3098 3259
 	</body>
3099 3260
 </html>';
3100
-		elseif (!allowedTo('admin_forum'))
3101
-			echo '
3261
+		} elseif (!allowedTo('admin_forum')) {
3262
+					echo '
3102 3263
 		<title>', $txt['template_parse_error'], '</title>
3103 3264
 	</head>
3104 3265
 	<body>
@@ -3106,14 +3267,16 @@  discard block
 block discarded – undo
3106 3267
 		', $txt['template_parse_error_message'], '
3107 3268
 	</body>
3108 3269
 </html>';
3109
-		else
3270
+		} else
3110 3271
 		{
3111 3272
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3112 3273
 			$error_array = error_get_last();
3113
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3114
-				$error = $error_array['message'];
3115
-			if (empty($error))
3116
-				$error = $txt['template_parse_errmsg'];
3274
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3275
+							$error = $error_array['message'];
3276
+			}
3277
+			if (empty($error)) {
3278
+							$error = $txt['template_parse_errmsg'];
3279
+			}
3117 3280
 
3118 3281
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3119 3282
 
@@ -3124,11 +3287,12 @@  discard block
 block discarded – undo
3124 3287
 		<h3>', $txt['template_parse_error'], '</h3>
3125 3288
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3126 3289
 
3127
-			if (!empty($error))
3128
-				echo '
3290
+			if (!empty($error)) {
3291
+							echo '
3129 3292
 		<hr>
3130 3293
 
3131 3294
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3295
+			}
3132 3296
 
3133 3297
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3134 3298
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3138,10 +3302,11 @@  discard block
 block discarded – undo
3138 3302
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3139 3303
 
3140 3304
 				// Fix the PHP code stuff...
3141
-				if (!isBrowser('gecko'))
3142
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3143
-				else
3144
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3305
+				if (!isBrowser('gecko')) {
3306
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3307
+				} else {
3308
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3309
+				}
3145 3310
 
3146 3311
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3147 3312
 				$j = -1;
@@ -3149,8 +3314,9 @@  discard block
 block discarded – undo
3149 3314
 				{
3150 3315
 					$j++;
3151 3316
 
3152
-					if (substr_count($line, '<br>') == 0)
3153
-						continue;
3317
+					if (substr_count($line, '<br>') == 0) {
3318
+											continue;
3319
+					}
3154 3320
 
3155 3321
 					$n = substr_count($line, '<br>');
3156 3322
 					for ($i = 0; $i < $n; $i++)
@@ -3169,38 +3335,42 @@  discard block
 block discarded – undo
3169 3335
 				// Figure out what the color coding was before...
3170 3336
 				$line = max($match[1] - 9, 1);
3171 3337
 				$last_line = '';
3172
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3173
-					if (strpos($data2[$line2], '<') !== false)
3338
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3339
+									if (strpos($data2[$line2], '<') !== false)
3174 3340
 					{
3175 3341
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3176 3342
 							$last_line = $color_match[1];
3343
+				}
3177 3344
 						break;
3178 3345
 					}
3179 3346
 
3180 3347
 				// Show the relevant lines...
3181 3348
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3182 3349
 				{
3183
-					if ($line == $match[1])
3184
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3350
+					if ($line == $match[1]) {
3351
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3352
+					}
3185 3353
 
3186 3354
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3187
-					if (isset($data2[$line]) && $data2[$line] != '')
3188
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3355
+					if (isset($data2[$line]) && $data2[$line] != '') {
3356
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3357
+					}
3189 3358
 
3190 3359
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3191 3360
 					{
3192 3361
 						$last_line = $color_match[1];
3193 3362
 						echo '</', substr($last_line, 1, 4), '>';
3363
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3364
+											$last_line = '';
3365
+					} elseif ($last_line != '' && $data2[$line] != '') {
3366
+											echo '</', substr($last_line, 1, 4), '>';
3194 3367
 					}
3195
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3196
-						$last_line = '';
3197
-					elseif ($last_line != '' && $data2[$line] != '')
3198
-						echo '</', substr($last_line, 1, 4), '>';
3199 3368
 
3200
-					if ($line == $match[1])
3201
-						echo '</pre></div><pre style="margin: 0;">';
3202
-					else
3203
-						echo "\n";
3369
+					if ($line == $match[1]) {
3370
+											echo '</pre></div><pre style="margin: 0;">';
3371
+					} else {
3372
+											echo "\n";
3373
+					}
3204 3374
 				}
3205 3375
 
3206 3376
 				echo '</pre></div>';
@@ -3224,8 +3394,9 @@  discard block
 block discarded – undo
3224 3394
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4;
3225 3395
 
3226 3396
 	// Figure out what type of database we are using.
3227
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3228
-		$db_type = 'mysql';
3397
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3398
+			$db_type = 'mysql';
3399
+	}
3229 3400
 
3230 3401
 	// Load the file for the database.
3231 3402
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3233,11 +3404,13 @@  discard block
 block discarded – undo
3233 3404
 	$db_options = array();
3234 3405
 
3235 3406
 	// Add in the port if needed
3236
-	if (!empty($db_port))
3237
-		$db_options['port'] = $db_port;
3407
+	if (!empty($db_port)) {
3408
+			$db_options['port'] = $db_port;
3409
+	}
3238 3410
 
3239
-	if (!empty($db_mb4))
3240
-		$db_options['db_mb4'] = $db_mb4;
3411
+	if (!empty($db_mb4)) {
3412
+			$db_options['db_mb4'] = $db_mb4;
3413
+	}
3241 3414
 
3242 3415
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3243 3416
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3256,13 +3429,15 @@  discard block
 block discarded – undo
3256 3429
 	}
3257 3430
 
3258 3431
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3259
-	if (!$db_connection)
3260
-		display_db_error();
3432
+	if (!$db_connection) {
3433
+			display_db_error();
3434
+	}
3261 3435
 
3262 3436
 	// If in SSI mode fix up the prefix.
3263
-	if (SMF == 'SSI')
3264
-		db_fix_prefix($db_prefix, $db_name);
3265
-}
3437
+	if (SMF == 'SSI') {
3438
+			db_fix_prefix($db_prefix, $db_name);
3439
+	}
3440
+	}
3266 3441
 
3267 3442
 /**
3268 3443
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3276,10 +3451,11 @@  discard block
 block discarded – undo
3276 3451
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3277 3452
 
3278 3453
 	// Not overriding this and we have a cacheAPI, send it back.
3279
-	if (empty($overrideCache) && is_object($cacheAPI))
3280
-		return $cacheAPI;
3281
-	elseif (is_null($cacheAPI))
3282
-		$cacheAPI = false;
3454
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3455
+			return $cacheAPI;
3456
+	} elseif (is_null($cacheAPI)) {
3457
+			$cacheAPI = false;
3458
+	}
3283 3459
 
3284 3460
 	// Make sure our class is in session.
3285 3461
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3300,8 +3476,9 @@  discard block
 block discarded – undo
3300 3476
 		if (!$testAPI->isSupported())
3301 3477
 		{
3302 3478
 			// Can we save ourselves?
3303
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3304
-				return loadCacheAccelerator(null, false);
3479
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3480
+							return loadCacheAccelerator(null, false);
3481
+			}
3305 3482
 			return false;
3306 3483
 		}
3307 3484
 
@@ -3313,9 +3490,9 @@  discard block
 block discarded – undo
3313 3490
 		{
3314 3491
 			$cacheAPI = $testAPI;
3315 3492
 			return $cacheAPI;
3493
+		} else {
3494
+					return $testAPI;
3316 3495
 		}
3317
-		else
3318
-			return $testAPI;
3319 3496
 	}
3320 3497
 }
3321 3498
 
@@ -3335,8 +3512,9 @@  discard block
 block discarded – undo
3335 3512
 
3336 3513
 	// @todo Why are we doing this if caching is disabled?
3337 3514
 
3338
-	if (function_exists('call_integration_hook'))
3339
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3515
+	if (function_exists('call_integration_hook')) {
3516
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3517
+	}
3340 3518
 
3341 3519
 	/* Refresh the cache if either:
3342 3520
 		1. Caching is disabled.
@@ -3350,16 +3528,19 @@  discard block
 block discarded – undo
3350 3528
 		require_once($sourcedir . '/' . $file);
3351 3529
 		$cache_block = call_user_func_array($function, $params);
3352 3530
 
3353
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3354
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3531
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3532
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3533
+		}
3355 3534
 	}
3356 3535
 
3357 3536
 	// Some cached data may need a freshening up after retrieval.
3358
-	if (!empty($cache_block['post_retri_eval']))
3359
-		eval($cache_block['post_retri_eval']);
3537
+	if (!empty($cache_block['post_retri_eval'])) {
3538
+			eval($cache_block['post_retri_eval']);
3539
+	}
3360 3540
 
3361
-	if (function_exists('call_integration_hook'))
3362
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3541
+	if (function_exists('call_integration_hook')) {
3542
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3543
+	}
3363 3544
 
3364 3545
 	return $cache_block['data'];
3365 3546
 }
@@ -3386,8 +3567,9 @@  discard block
 block discarded – undo
3386 3567
 	global $smcFunc, $cache_enable, $cacheAPI;
3387 3568
 	global $cache_hits, $cache_count, $db_show_debug;
3388 3569
 
3389
-	if (empty($cache_enable) || empty($cacheAPI))
3390
-		return;
3570
+	if (empty($cache_enable) || empty($cacheAPI)) {
3571
+			return;
3572
+	}
3391 3573
 
3392 3574
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3393 3575
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3400,12 +3582,14 @@  discard block
 block discarded – undo
3400 3582
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3401 3583
 	$cacheAPI->putData($key, $value, $ttl);
3402 3584
 
3403
-	if (function_exists('call_integration_hook'))
3404
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3585
+	if (function_exists('call_integration_hook')) {
3586
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3587
+	}
3405 3588
 
3406
-	if (isset($db_show_debug) && $db_show_debug === true)
3407
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3408
-}
3589
+	if (isset($db_show_debug) && $db_show_debug === true) {
3590
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3591
+	}
3592
+	}
3409 3593
 
3410 3594
 /**
3411 3595
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3421,8 +3605,9 @@  discard block
 block discarded – undo
3421 3605
 	global $smcFunc, $cache_enable, $cacheAPI;
3422 3606
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3423 3607
 
3424
-	if (empty($cache_enable) || empty($cacheAPI))
3425
-		return;
3608
+	if (empty($cache_enable) || empty($cacheAPI)) {
3609
+			return;
3610
+	}
3426 3611
 
3427 3612
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3428 3613
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3442,16 +3627,18 @@  discard block
 block discarded – undo
3442 3627
 
3443 3628
 		if (empty($value))
3444 3629
 		{
3445
-			if (!is_array($cache_misses))
3446
-				$cache_misses = array();
3630
+			if (!is_array($cache_misses)) {
3631
+							$cache_misses = array();
3632
+			}
3447 3633
 
3448 3634
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3449 3635
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3450 3636
 		}
3451 3637
 	}
3452 3638
 
3453
-	if (function_exists('call_integration_hook') && isset($value))
3454
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3639
+	if (function_exists('call_integration_hook') && isset($value)) {
3640
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3641
+	}
3455 3642
 
3456 3643
 	return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3457 3644
 }
@@ -3473,8 +3660,9 @@  discard block
 block discarded – undo
3473 3660
 	global $cacheAPI;
3474 3661
 
3475 3662
 	// If we can't get to the API, can't do this.
3476
-	if (empty($cacheAPI))
3477
-		return;
3663
+	if (empty($cacheAPI)) {
3664
+			return;
3665
+	}
3478 3666
 
3479 3667
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3480 3668
 	$cacheAPI->cleanCache($type);
@@ -3499,8 +3687,9 @@  discard block
 block discarded – undo
3499 3687
 	global $modSettings, $smcFunc, $image_proxy_enabled, $user_info;
3500 3688
 
3501 3689
 	// Come on!
3502
-	if (empty($data))
3503
-		return array();
3690
+	if (empty($data)) {
3691
+			return array();
3692
+	}
3504 3693
 
3505 3694
 	// Set a nice default var.
3506 3695
 	$image = '';
@@ -3508,11 +3697,11 @@  discard block
 block discarded – undo
3508 3697
 	// Gravatar has been set as mandatory!
3509 3698
 	if (!empty($modSettings['gravatarOverride']))
3510 3699
 	{
3511
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3512
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3513
-
3514
-		else if (!empty($data['email']))
3515
-			$image = get_gravatar_url($data['email']);
3700
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3701
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3702
+		} else if (!empty($data['email'])) {
3703
+					$image = get_gravatar_url($data['email']);
3704
+		}
3516 3705
 	}
3517 3706
 
3518 3707
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3524,54 +3713,60 @@  discard block
 block discarded – undo
3524 3713
 			// Gravatar.
3525 3714
 			if (stristr($data['avatar'], 'gravatar://'))
3526 3715
 			{
3527
-				if ($data['avatar'] == 'gravatar://')
3528
-					$image = get_gravatar_url($data['email']);
3529
-
3530
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3531
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3716
+				if ($data['avatar'] == 'gravatar://') {
3717
+									$image = get_gravatar_url($data['email']);
3718
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3719
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3720
+				}
3532 3721
 			}
3533 3722
 
3534 3723
 			// External url.
3535 3724
 			else
3536 3725
 			{
3537 3726
 				// Using ssl?
3538
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3539
-					$image = get_proxied_url($data['avatar']);
3727
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3728
+									$image = get_proxied_url($data['avatar']);
3729
+				}
3540 3730
 
3541 3731
 				// Just a plain external url.
3542
-				else
3543
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3732
+				else {
3733
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3734
+				}
3544 3735
 			}
3545 3736
 		}
3546 3737
 
3547 3738
 		// Perhaps this user has an attachment as avatar...
3548
-		else if (!empty($data['filename']))
3549
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3739
+		else if (!empty($data['filename'])) {
3740
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3741
+		}
3550 3742
 
3551 3743
 		// Right... no avatar... use our default image.
3552
-		else
3553
-			$image = $modSettings['avatar_url'] . '/default.png';
3744
+		else {
3745
+					$image = $modSettings['avatar_url'] . '/default.png';
3746
+		}
3554 3747
 	}
3555 3748
 
3556 3749
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3557 3750
 
3558 3751
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3559
-	if (!empty($image))
3560
-		return array(
3752
+	if (!empty($image)) {
3753
+			return array(
3561 3754
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3562 3755
 			'image' => '<img class="avatar" src="' . $image . '" />',
3563 3756
 			'href' => $image,
3564 3757
 			'url' => $image,
3565 3758
 		);
3759
+	}
3566 3760
 
3567 3761
 	// Fallback to make life easier for everyone...
3568
-	else
3569
-		return array(
3762
+	else {
3763
+			return array(
3570 3764
 			'name' => '',
3571 3765
 			'image' => '',
3572 3766
 			'href' => '',
3573 3767
 			'url' => '',
3574 3768
 		);
3575
-}
3769
+	}
3770
+	}
3576 3771
 
3577 3772
 ?>
3578 3773
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/BoardIndex.php 1 patch
Braces   +20 added lines, -13 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
  * This function shows the board index.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	$context['canonical_url'] = $scripturl;
35 36
 
36 37
 	// Do not let search engines index anything if there is a random thing in $_GET.
37
-	if (!empty($_GET))
38
-		$context['robot_no_index'] = true;
38
+	if (!empty($_GET)) {
39
+			$context['robot_no_index'] = true;
40
+	}
39 41
 
40 42
 	// Retrieve the categories and boards.
41 43
 	require_once($sourcedir . '/Subs-BoardIndex.php');
@@ -62,11 +64,12 @@  discard block
 block discarded – undo
62 64
 			$context['latest_posts'] = cache_quick_get('boardindex-latest_posts:' . md5($user_info['query_wanna_see_board'] . $user_info['language']), 'Subs-Recent.php', 'cache_getLastPosts', array($latestPostOptions));
63 65
 		}
64 66
 
65
-		if (!empty($context['latest_posts']) || !empty($context['latest_post']))
66
-			$context['info_center'][] = array(
67
+		if (!empty($context['latest_posts']) || !empty($context['latest_post'])) {
68
+					$context['info_center'][] = array(
67 69
 				'tpl' => 'recent',
68 70
 				'txt' => 'recent_posts',
69 71
 			);
72
+		}
70 73
 	}
71 74
 
72 75
 	// Load the calendar?
@@ -87,20 +90,22 @@  discard block
 block discarded – undo
87 90
 		// This is used to show the "how-do-I-edit" help.
88 91
 		$context['calendar_can_edit'] = allowedTo('calendar_edit_any');
89 92
 
90
-		if (!empty($context['show_calendar']))
91
-			$context['info_center'][] = array(
93
+		if (!empty($context['show_calendar'])) {
94
+					$context['info_center'][] = array(
92 95
 				'tpl' => 'calendar',
93 96
 				'txt' => $context['calendar_only_today'] ? 'calendar_today' : 'calendar_upcoming',
94 97
 			);
98
+		}
95 99
 	}
96 100
 
97 101
 	// And stats.
98 102
 	$context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);
99
-	if ($settings['show_stats_index'])
100
-		$context['info_center'][] = array(
103
+	if ($settings['show_stats_index']) {
104
+			$context['info_center'][] = array(
101 105
 				'tpl' => 'stats',
102 106
 				'txt' => 'forum_stats',
103 107
 			);
108
+	}
104 109
 
105 110
 	// Now the online stuff
106 111
 	require_once($sourcedir . '/Subs-MembersOnline.php');
@@ -118,12 +123,14 @@  discard block
 block discarded – undo
118 123
 			);
119 124
 
120 125
 	// Track most online statistics? (Subs-MembersOnline.php)
121
-	if (!empty($modSettings['trackStats']))
122
-		trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
126
+	if (!empty($modSettings['trackStats'])) {
127
+			trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
128
+	}
123 129
 
124 130
 	// Are we showing all membergroups on the board index?
125
-	if (!empty($settings['show_group_key']))
126
-		$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
131
+	if (!empty($settings['show_group_key'])) {
132
+			$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
133
+	}
127 134
 
128 135
 	// And back to normality.
129 136
 	$context['page_title'] = sprintf($txt['forum_index'], $context['forum_name']);
Please login to merge, or discard this patch.
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
 			header('HTTP/1.1 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/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.
@@ -1350,9 +1410,10 @@  discard block
 block discarded – undo
1350 1410
 			$context['posting_fields']['board']['dd'] .= '
1351 1411
 							<optgroup label="' . $category['name'] . '">';
1352 1412
 
1353
-			foreach ($category['boards'] as $brd)
1354
-				$context['posting_fields']['board']['dd'] .= '
1413
+			foreach ($category['boards'] as $brd) {
1414
+							$context['posting_fields']['board']['dd'] .= '
1355 1415
 								<option value="' . $brd['id'] . '"' . ($brd['selected'] ? ' selected' : '') . '>' . ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=&gt;' : '') . ' ' . $brd['name'] . '</option>';
1416
+			}
1356 1417
 
1357 1418
 			$context['posting_fields']['board']['dd'] .= '
1358 1419
 							</optgroup>';
@@ -1383,8 +1444,9 @@  discard block
 block discarded – undo
1383 1444
 
1384 1445
 
1385 1446
 	// Finally, load the template.
1386
-	if (!isset($_REQUEST['xml']))
1387
-		loadTemplate('Post');
1447
+	if (!isset($_REQUEST['xml'])) {
1448
+			loadTemplate('Post');
1449
+	}
1388 1450
 
1389 1451
 	call_integration_hook('integrate_post_end');
1390 1452
 }
@@ -1405,13 +1467,14 @@  discard block
 block discarded – undo
1405 1467
 	// Sneaking off, are we?
1406 1468
 	if (empty($_POST) && empty($topic))
1407 1469
 	{
1408
-		if (empty($_SERVER['CONTENT_LENGTH']))
1409
-			redirectexit('action=post;board=' . $board . '.0');
1410
-		else
1411
-			fatal_lang_error('post_upload_error', false);
1470
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1471
+					redirectexit('action=post;board=' . $board . '.0');
1472
+		} else {
1473
+					fatal_lang_error('post_upload_error', false);
1474
+		}
1475
+	} elseif (empty($_POST) && !empty($topic)) {
1476
+			redirectexit('action=post;topic=' . $topic . '.0');
1412 1477
 	}
1413
-	elseif (empty($_POST) && !empty($topic))
1414
-		redirectexit('action=post;topic=' . $topic . '.0');
1415 1478
 
1416 1479
 	// No need!
1417 1480
 	$context['robot_no_index'] = true;
@@ -1423,8 +1486,9 @@  discard block
 block discarded – undo
1423 1486
 	$post_errors = array();
1424 1487
 
1425 1488
 	// If the session has timed out, let the user re-submit their form.
1426
-	if (checkSession('post', '', false) != '')
1427
-		$post_errors[] = 'session_timeout';
1489
+	if (checkSession('post', '', false) != '') {
1490
+			$post_errors[] = 'session_timeout';
1491
+	}
1428 1492
 
1429 1493
 	// Wrong verification code?
1430 1494
 	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)))
@@ -1434,8 +1498,9 @@  discard block
 block discarded – undo
1434 1498
 			'id' => 'post',
1435 1499
 		);
1436 1500
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1437
-		if (is_array($context['require_verification']))
1438
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1501
+		if (is_array($context['require_verification'])) {
1502
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1503
+		}
1439 1504
 	}
1440 1505
 
1441 1506
 	require_once($sourcedir . '/Subs-Post.php');
@@ -1444,25 +1509,29 @@  discard block
 block discarded – undo
1444 1509
 	call_integration_hook('integrate_post2_start');
1445 1510
 
1446 1511
 	// Drafts enabled and needed?
1447
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1448
-		require_once($sourcedir . '/Drafts.php');
1512
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1513
+			require_once($sourcedir . '/Drafts.php');
1514
+	}
1449 1515
 
1450 1516
 	// First check to see if they are trying to delete any current attachments.
1451 1517
 	if (isset($_POST['attach_del']))
1452 1518
 	{
1453 1519
 		$keep_temp = array();
1454 1520
 		$keep_ids = array();
1455
-		foreach ($_POST['attach_del'] as $dummy)
1456
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1521
+		foreach ($_POST['attach_del'] as $dummy) {
1522
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1457 1523
 				$keep_temp[] = $dummy;
1458
-			else
1459
-				$keep_ids[] = (int) $dummy;
1524
+		}
1525
+			else {
1526
+							$keep_ids[] = (int) $dummy;
1527
+			}
1460 1528
 
1461
-		if (isset($_SESSION['temp_attachments']))
1462
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1529
+		if (isset($_SESSION['temp_attachments'])) {
1530
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1463 1531
 			{
1464 1532
 				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)
1465 1533
 					continue;
1534
+		}
1466 1535
 
1467 1536
 				unset($_SESSION['temp_attachments'][$attachID]);
1468 1537
 				unlink($attachment['tmp_name']);
@@ -1494,8 +1563,9 @@  discard block
 block discarded – undo
1494 1563
 	{
1495 1564
 		require_once($sourcedir . '/ManageAttachments.php');
1496 1565
 
1497
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
1498
-			removeAttachments(array('id_attach' => $attachID));
1566
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
1567
+					removeAttachments(array('id_attach' => $attachID));
1568
+		}
1499 1569
 
1500 1570
 		unset($_SESSION['already_attached']);
1501 1571
 
@@ -1518,12 +1588,14 @@  discard block
 block discarded – undo
1518 1588
 		$smcFunc['db_free_result']($request);
1519 1589
 
1520 1590
 		// Though the topic should be there, it might have vanished.
1521
-		if (!is_array($topic_info))
1522
-			fatal_lang_error('topic_doesnt_exist', 404);
1591
+		if (!is_array($topic_info)) {
1592
+					fatal_lang_error('topic_doesnt_exist', 404);
1593
+		}
1523 1594
 
1524 1595
 		// Did this topic suddenly move? Just checking...
1525
-		if ($topic_info['id_board'] != $board)
1526
-			fatal_lang_error('not_a_topic');
1596
+		if ($topic_info['id_board'] != $board) {
1597
+					fatal_lang_error('not_a_topic');
1598
+		}
1527 1599
 
1528 1600
 		// Do the permissions and approval stuff...
1529 1601
 		$becomesApproved = true;
@@ -1546,49 +1618,50 @@  discard block
 block discarded – undo
1546 1618
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1547 1619
 	{
1548 1620
 		// Don't allow a post if it's locked.
1549
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1550
-			fatal_lang_error('topic_locked', false);
1621
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1622
+					fatal_lang_error('topic_locked', false);
1623
+		}
1551 1624
 
1552 1625
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1553
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1554
-			unset($_REQUEST['poll']);
1555
-
1556
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1557
-		{
1558
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1559
-				$becomesApproved = false;
1560
-
1561
-			else
1562
-				isAllowedTo('post_reply_any');
1563
-		}
1564
-		elseif (!allowedTo('post_reply_any'))
1626
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1627
+					unset($_REQUEST['poll']);
1628
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1629
+		{
1630
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1631
+							$becomesApproved = false;
1632
+			} else {
1633
+							isAllowedTo('post_reply_any');
1634
+			}
1635
+		} elseif (!allowedTo('post_reply_any'))
1565 1636
 		{
1566
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1567
-				$becomesApproved = false;
1568
-
1569
-			else
1570
-				isAllowedTo('post_reply_own');
1637
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1638
+							$becomesApproved = false;
1639
+			} else {
1640
+							isAllowedTo('post_reply_own');
1641
+			}
1571 1642
 		}
1572 1643
 
1573 1644
 		if (isset($_POST['lock']))
1574 1645
 		{
1575 1646
 			// Nothing is changed to the lock.
1576
-			if (empty($topic_info['locked']) == empty($_POST['lock']))
1577
-				unset($_POST['lock']);
1647
+			if (empty($topic_info['locked']) == empty($_POST['lock'])) {
1648
+							unset($_POST['lock']);
1649
+			}
1578 1650
 
1579 1651
 			// You're have no permission to lock this topic.
1580
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1581
-				unset($_POST['lock']);
1652
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1653
+							unset($_POST['lock']);
1654
+			}
1582 1655
 
1583 1656
 			// You are allowed to (un)lock your own topic only.
1584 1657
 			elseif (!allowedTo('lock_any'))
1585 1658
 			{
1586 1659
 				// You cannot override a moderator lock.
1587
-				if ($topic_info['locked'] == 1)
1588
-					unset($_POST['lock']);
1589
-
1590
-				else
1591
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1660
+				if ($topic_info['locked'] == 1) {
1661
+									unset($_POST['lock']);
1662
+				} else {
1663
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1664
+				}
1592 1665
 			}
1593 1666
 			// Hail mighty moderator, (un)lock this topic immediately.
1594 1667
 			else
@@ -1596,19 +1669,21 @@  discard block
 block discarded – undo
1596 1669
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1597 1670
 
1598 1671
 				// Did someone (un)lock this while you were posting?
1599
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1600
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1672
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1673
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1674
+				}
1601 1675
 			}
1602 1676
 		}
1603 1677
 
1604 1678
 		// So you wanna (un)sticky this...let's see.
1605
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1606
-			unset($_POST['sticky']);
1607
-		elseif (isset($_POST['sticky']))
1679
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1680
+					unset($_POST['sticky']);
1681
+		} elseif (isset($_POST['sticky']))
1608 1682
 		{
1609 1683
 			// Did someone (un)sticky this while you were posting?
1610
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1611
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1684
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1685
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1686
+			}
1612 1687
 		}
1613 1688
 
1614 1689
 		// If drafts are enabled, then pass this off
@@ -1635,26 +1710,31 @@  discard block
 block discarded – undo
1635 1710
 
1636 1711
 		// Do like, the permissions, for safety and stuff...
1637 1712
 		$becomesApproved = true;
1638
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1639
-			$becomesApproved = false;
1640
-		else
1641
-			isAllowedTo('post_new');
1713
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1714
+					$becomesApproved = false;
1715
+		} else {
1716
+					isAllowedTo('post_new');
1717
+		}
1642 1718
 
1643 1719
 		if (isset($_POST['lock']))
1644 1720
 		{
1645 1721
 			// New topics are by default not locked.
1646
-			if (empty($_POST['lock']))
1647
-				unset($_POST['lock']);
1722
+			if (empty($_POST['lock'])) {
1723
+							unset($_POST['lock']);
1724
+			}
1648 1725
 			// Besides, you need permission.
1649
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1650
-				unset($_POST['lock']);
1726
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1727
+							unset($_POST['lock']);
1728
+			}
1651 1729
 			// A moderator-lock (1) can override a user-lock (2).
1652
-			else
1653
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1730
+			else {
1731
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1732
+			}
1654 1733
 		}
1655 1734
 
1656
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1657
-			unset($_POST['sticky']);
1735
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1736
+					unset($_POST['sticky']);
1737
+		}
1658 1738
 
1659 1739
 		// Saving your new topic as a draft first?
1660 1740
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1679,31 +1759,37 @@  discard block
 block discarded – undo
1679 1759
 				'id_msg' => $_REQUEST['msg'],
1680 1760
 			)
1681 1761
 		);
1682
-		if ($smcFunc['db_num_rows']($request) == 0)
1683
-			fatal_lang_error('cant_find_messages', false);
1762
+		if ($smcFunc['db_num_rows']($request) == 0) {
1763
+					fatal_lang_error('cant_find_messages', false);
1764
+		}
1684 1765
 		$row = $smcFunc['db_fetch_assoc']($request);
1685 1766
 		$smcFunc['db_free_result']($request);
1686 1767
 
1687
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1688
-			fatal_lang_error('topic_locked', false);
1768
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1769
+					fatal_lang_error('topic_locked', false);
1770
+		}
1689 1771
 
1690 1772
 		if (isset($_POST['lock']))
1691 1773
 		{
1692 1774
 			// Nothing changes to the lock status.
1693
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1694
-				unset($_POST['lock']);
1775
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1776
+							unset($_POST['lock']);
1777
+			}
1695 1778
 			// You're simply not allowed to (un)lock this.
1696
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1697
-				unset($_POST['lock']);
1779
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1780
+							unset($_POST['lock']);
1781
+			}
1698 1782
 			// You're only allowed to lock your own topics.
1699 1783
 			elseif (!allowedTo('lock_any'))
1700 1784
 			{
1701 1785
 				// You're not allowed to break a moderator's lock.
1702
-				if ($topic_info['locked'] == 1)
1703
-					unset($_POST['lock']);
1786
+				if ($topic_info['locked'] == 1) {
1787
+									unset($_POST['lock']);
1788
+				}
1704 1789
 				// Lock it with a soft lock or unlock it.
1705
-				else
1706
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1790
+				else {
1791
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1792
+				}
1707 1793
 			}
1708 1794
 			// You must be the moderator.
1709 1795
 			else
@@ -1711,44 +1797,46 @@  discard block
 block discarded – undo
1711 1797
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1712 1798
 
1713 1799
 				// Did someone (un)lock this while you were posting?
1714
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1715
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1800
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1801
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1802
+				}
1716 1803
 			}
1717 1804
 		}
1718 1805
 
1719 1806
 		// Change the sticky status of this topic?
1720
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1721
-			unset($_POST['sticky']);
1722
-		elseif (isset($_POST['sticky']))
1807
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1808
+					unset($_POST['sticky']);
1809
+		} elseif (isset($_POST['sticky']))
1723 1810
 		{
1724 1811
 			// Did someone (un)sticky this while you were posting?
1725
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1726
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1812
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1813
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1814
+			}
1727 1815
 		}
1728 1816
 
1729 1817
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1730 1818
 		{
1731
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1732
-				fatal_lang_error('modify_post_time_passed', false);
1733
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1734
-				isAllowedTo('modify_replies');
1735
-			else
1736
-				isAllowedTo('modify_own');
1737
-		}
1738
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1819
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1820
+							fatal_lang_error('modify_post_time_passed', false);
1821
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1822
+							isAllowedTo('modify_replies');
1823
+			} else {
1824
+							isAllowedTo('modify_own');
1825
+			}
1826
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1739 1827
 		{
1740 1828
 			isAllowedTo('modify_replies');
1741 1829
 
1742 1830
 			// If you're modifying a reply, I say it better be logged...
1743 1831
 			$moderationAction = true;
1744
-		}
1745
-		else
1832
+		} else
1746 1833
 		{
1747 1834
 			isAllowedTo('modify_any');
1748 1835
 
1749 1836
 			// Log it, assuming you're not modifying your own post.
1750
-			if ($row['id_member'] != $user_info['id'])
1751
-				$moderationAction = true;
1837
+			if ($row['id_member'] != $user_info['id']) {
1838
+							$moderationAction = true;
1839
+			}
1752 1840
 		}
1753 1841
 
1754 1842
 		// If drafts are enabled, then lets send this off to save
@@ -1775,8 +1863,9 @@  discard block
 block discarded – undo
1775 1863
 		// Update search api
1776 1864
 		require_once($sourcedir . '/Search.php');
1777 1865
 		$searchAPI = findSearchAPI();
1778
-		if ($searchAPI->supportsMethod('postRemoved'))
1779
-			$searchAPI->postRemoved($_REQUEST['msg']);
1866
+		if ($searchAPI->supportsMethod('postRemoved')) {
1867
+					$searchAPI->postRemoved($_REQUEST['msg']);
1868
+		}
1780 1869
 
1781 1870
 	}
1782 1871
 
@@ -1794,20 +1883,24 @@  discard block
 block discarded – undo
1794 1883
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1795 1884
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1796 1885
 
1797
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1798
-			$post_errors[] = 'no_name';
1799
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1800
-			$post_errors[] = 'long_name';
1886
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1887
+					$post_errors[] = 'no_name';
1888
+		}
1889
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1890
+					$post_errors[] = 'long_name';
1891
+		}
1801 1892
 
1802 1893
 		if (empty($modSettings['guest_post_no_email']))
1803 1894
 		{
1804 1895
 			// Only check if they changed it!
1805 1896
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1806 1897
 			{
1807
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1808
-					$post_errors[] = 'no_email';
1809
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1810
-					$post_errors[] = 'bad_email';
1898
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1899
+									$post_errors[] = 'no_email';
1900
+				}
1901
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1902
+									$post_errors[] = 'bad_email';
1903
+				}
1811 1904
 			}
1812 1905
 
1813 1906
 			// Now make sure this email address is not banned from posting.
@@ -1823,76 +1916,90 @@  discard block
 block discarded – undo
1823 1916
 	}
1824 1917
 
1825 1918
 	// Coming from the quickReply?
1826
-	if (isset($_POST['quickReply']))
1827
-		$_POST['message'] = $_POST['quickReply'];
1919
+	if (isset($_POST['quickReply'])) {
1920
+			$_POST['message'] = $_POST['quickReply'];
1921
+	}
1828 1922
 
1829 1923
 	// Check the subject and message.
1830
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1831
-		$post_errors[] = 'no_subject';
1832
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1833
-		$post_errors[] = 'no_message';
1834
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1835
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1836
-	else
1924
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1925
+			$post_errors[] = 'no_subject';
1926
+	}
1927
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1928
+			$post_errors[] = 'no_message';
1929
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1930
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1931
+	} else
1837 1932
 	{
1838 1933
 		// Prepare the message a bit for some additional testing.
1839 1934
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1840 1935
 
1841 1936
 		// Preparse code. (Zef)
1842
-		if ($user_info['is_guest'])
1843
-			$user_info['name'] = $_POST['guestname'];
1937
+		if ($user_info['is_guest']) {
1938
+					$user_info['name'] = $_POST['guestname'];
1939
+		}
1844 1940
 		preparsecode($_POST['message']);
1845 1941
 
1846 1942
 		// Let's see if there's still some content left without the tags.
1847
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1848
-			$post_errors[] = 'no_message';
1943
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1944
+					$post_errors[] = 'no_message';
1945
+		}
1849 1946
 
1850 1947
 	}
1851
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1852
-		$post_errors[] = 'no_event';
1948
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1949
+			$post_errors[] = 'no_event';
1950
+	}
1853 1951
 	// You are not!
1854
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1855
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1952
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1953
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1954
+	}
1856 1955
 
1857 1956
 	// Validate the poll...
1858 1957
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1859 1958
 	{
1860
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1861
-			fatal_lang_error('no_access', false);
1959
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1960
+					fatal_lang_error('no_access', false);
1961
+		}
1862 1962
 
1863 1963
 		// This is a new topic... so it's a new poll.
1864
-		if (empty($topic))
1865
-			isAllowedTo('poll_post');
1964
+		if (empty($topic)) {
1965
+					isAllowedTo('poll_post');
1966
+		}
1866 1967
 		// Can you add to your own topics?
1867
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1868
-			isAllowedTo('poll_add_own');
1968
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1969
+					isAllowedTo('poll_add_own');
1970
+		}
1869 1971
 		// Can you add polls to any topic, then?
1870
-		else
1871
-			isAllowedTo('poll_add_any');
1972
+		else {
1973
+					isAllowedTo('poll_add_any');
1974
+		}
1872 1975
 
1873
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1874
-			$post_errors[] = 'no_question';
1976
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1977
+					$post_errors[] = 'no_question';
1978
+		}
1875 1979
 
1876 1980
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1877 1981
 
1878 1982
 		// Get rid of empty ones.
1879
-		foreach ($_POST['options'] as $k => $option)
1880
-			if ($option == '')
1983
+		foreach ($_POST['options'] as $k => $option) {
1984
+					if ($option == '')
1881 1985
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1986
+		}
1882 1987
 
1883 1988
 		// What are you going to vote between with one choice?!?
1884
-		if (count($_POST['options']) < 2)
1885
-			$post_errors[] = 'poll_few';
1886
-		elseif (count($_POST['options']) > 256)
1887
-			$post_errors[] = 'poll_many';
1989
+		if (count($_POST['options']) < 2) {
1990
+					$post_errors[] = 'poll_few';
1991
+		} elseif (count($_POST['options']) > 256) {
1992
+					$post_errors[] = 'poll_many';
1993
+		}
1888 1994
 	}
1889 1995
 
1890 1996
 	if ($posterIsGuest)
1891 1997
 	{
1892 1998
 		// If user is a guest, make sure the chosen name isn't taken.
1893 1999
 		require_once($sourcedir . '/Subs-Members.php');
1894
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1895
-			$post_errors[] = 'bad_name';
2000
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
2001
+					$post_errors[] = 'bad_name';
2002
+		}
1896 2003
 	}
1897 2004
 	// If the user isn't a guest, get his or her name and email.
1898 2005
 	elseif (!isset($_REQUEST['msg']))
@@ -1923,8 +2030,9 @@  discard block
 block discarded – undo
1923 2030
 	}
1924 2031
 
1925 2032
 	// Make sure the user isn't spamming the board.
1926
-	if (!isset($_REQUEST['msg']))
1927
-		spamProtection('post');
2033
+	if (!isset($_REQUEST['msg'])) {
2034
+			spamProtection('post');
2035
+	}
1928 2036
 
1929 2037
 	// At about this point, we're posting and that's that.
1930 2038
 	ignore_user_abort(true);
@@ -1937,32 +2045,36 @@  discard block
 block discarded – undo
1937 2045
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1938 2046
 
1939 2047
 	// At this point, we want to make sure the subject isn't too long.
1940
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1941
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2048
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
2049
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2050
+	}
1942 2051
 
1943 2052
 	// Same with the "why did you edit this" text.
1944
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1945
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2053
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2054
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2055
+	}
1946 2056
 
1947 2057
 	// Make the poll...
1948 2058
 	if (isset($_REQUEST['poll']))
1949 2059
 	{
1950 2060
 		// Make sure that the user has not entered a ridiculous number of options..
1951
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1952
-			$_POST['poll_max_votes'] = 1;
1953
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1954
-			$_POST['poll_max_votes'] = count($_POST['options']);
1955
-		else
1956
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2061
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
2062
+					$_POST['poll_max_votes'] = 1;
2063
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
2064
+					$_POST['poll_max_votes'] = count($_POST['options']);
2065
+		} else {
2066
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2067
+		}
1957 2068
 
1958 2069
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1959 2070
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1960 2071
 
1961 2072
 		// Just set it to zero if it's not there..
1962
-		if (!isset($_POST['poll_hide']))
1963
-			$_POST['poll_hide'] = 0;
1964
-		else
1965
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2073
+		if (!isset($_POST['poll_hide'])) {
2074
+					$_POST['poll_hide'] = 0;
2075
+		} else {
2076
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2077
+		}
1966 2078
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1967 2079
 
1968 2080
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1971,16 +2083,19 @@  discard block
 block discarded – undo
1971 2083
 		{
1972 2084
 			require_once($sourcedir . '/Subs-Members.php');
1973 2085
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1974
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1975
-				$_POST['poll_guest_vote'] = 0;
2086
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2087
+							$_POST['poll_guest_vote'] = 0;
2088
+			}
1976 2089
 		}
1977 2090
 
1978 2091
 		// If the user tries to set the poll too far in advance, don't let them.
1979
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1980
-			fatal_lang_error('poll_range_error', false);
2092
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2093
+					fatal_lang_error('poll_range_error', false);
2094
+		}
1981 2095
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1982
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1983
-			$_POST['poll_hide'] = 1;
2096
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2097
+					$_POST['poll_hide'] = 1;
2098
+		}
1984 2099
 
1985 2100
 		// Clean up the question and answers.
1986 2101
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1994,13 +2109,15 @@  discard block
 block discarded – undo
1994 2109
 	{
1995 2110
 		$attachIDs = array();
1996 2111
 		$attach_errors = array();
1997
-		if (!empty($context['we_are_history']))
1998
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2112
+		if (!empty($context['we_are_history'])) {
2113
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2114
+		}
1999 2115
 
2000 2116
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
2001 2117
 		{
2002
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
2003
-				continue;
2118
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2119
+							continue;
2120
+			}
2004 2121
 
2005 2122
 			// If there was an initial error just show that message.
2006 2123
 			if ($attachID == 'initial_error')
@@ -2029,12 +2146,13 @@  discard block
 block discarded – undo
2029 2146
 				if (createAttachment($attachmentOptions))
2030 2147
 				{
2031 2148
 					$attachIDs[] = $attachmentOptions['id'];
2032
-					if (!empty($attachmentOptions['thumb']))
2033
-						$attachIDs[] = $attachmentOptions['thumb'];
2149
+					if (!empty($attachmentOptions['thumb'])) {
2150
+											$attachIDs[] = $attachmentOptions['thumb'];
2151
+					}
2034 2152
 				}
2153
+			} else {
2154
+							$attach_errors[] = '<dt>&nbsp;</dt>';
2035 2155
 			}
2036
-			else
2037
-				$attach_errors[] = '<dt>&nbsp;</dt>';
2038 2156
 
2039 2157
 			if (!empty($attachmentOptions['errors']))
2040 2158
 			{
@@ -2046,14 +2164,16 @@  discard block
 block discarded – undo
2046 2164
 					if (!is_array($error))
2047 2165
 					{
2048 2166
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
2049
-						if (in_array($error, $log_these))
2050
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2167
+						if (in_array($error, $log_these)) {
2168
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2169
+						}
2170
+					} else {
2171
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2051 2172
 					}
2052
-					else
2053
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2054 2173
 				}
2055
-				if (file_exists($attachment['tmp_name']))
2056
-					unlink($attachment['tmp_name']);
2174
+				if (file_exists($attachment['tmp_name'])) {
2175
+									unlink($attachment['tmp_name']);
2176
+				}
2057 2177
 			}
2058 2178
 		}
2059 2179
 		unset($_SESSION['temp_attachments']);
@@ -2094,24 +2214,24 @@  discard block
 block discarded – undo
2094 2214
 		);
2095 2215
 
2096 2216
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2217
+	} else {
2218
+			$id_poll = 0;
2097 2219
 	}
2098
-	else
2099
-		$id_poll = 0;
2100 2220
 
2101 2221
 	// Creating a new topic?
2102 2222
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2103 2223
 
2104 2224
 	// Check the icon.
2105
-	if (!isset($_POST['icon']))
2106
-		$_POST['icon'] = 'xx';
2107
-
2108
-	else
2225
+	if (!isset($_POST['icon'])) {
2226
+			$_POST['icon'] = 'xx';
2227
+	} else
2109 2228
 	{
2110 2229
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2111 2230
 
2112 2231
 		// Need to figure it out if this is a valid icon name.
2113
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2114
-			$_POST['icon'] = 'xx';
2232
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2233
+					$_POST['icon'] = 'xx';
2234
+		}
2115 2235
 	}
2116 2236
 
2117 2237
 	// Collect all parameters for the creation or modification of a post.
@@ -2152,8 +2272,9 @@  discard block
 block discarded – undo
2152 2272
 		}
2153 2273
 
2154 2274
 		// This will save some time...
2155
-		if (empty($approve_has_changed))
2156
-			unset($msgOptions['approved']);
2275
+		if (empty($approve_has_changed)) {
2276
+					unset($msgOptions['approved']);
2277
+		}
2157 2278
 
2158 2279
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2159 2280
 	}
@@ -2162,8 +2283,9 @@  discard block
 block discarded – undo
2162 2283
 	{
2163 2284
 		createPost($msgOptions, $topicOptions, $posterOptions);
2164 2285
 
2165
-		if (isset($topicOptions['id']))
2166
-			$topic = $topicOptions['id'];
2286
+		if (isset($topicOptions['id'])) {
2287
+					$topic = $topicOptions['id'];
2288
+		}
2167 2289
 	}
2168 2290
 
2169 2291
 	// Are there attachments already uploaded and waiting to be assigned?
@@ -2175,8 +2297,9 @@  discard block
 block discarded – undo
2175 2297
 	}
2176 2298
 
2177 2299
 	// If we had a draft for this, its time to remove it since it was just posted
2178
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2179
-		DeleteDraft($_POST['id_draft']);
2300
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2301
+			DeleteDraft($_POST['id_draft']);
2302
+	}
2180 2303
 
2181 2304
 	// Editing or posting an event?
2182 2305
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2195,8 +2318,7 @@  discard block
 block discarded – undo
2195 2318
 			'member' => $user_info['id'],
2196 2319
 		);
2197 2320
 		insertEvent($eventOptions);
2198
-	}
2199
-	elseif (isset($_POST['calendar']))
2321
+	} elseif (isset($_POST['calendar']))
2200 2322
 	{
2201 2323
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2202 2324
 
@@ -2224,14 +2346,15 @@  discard block
 block discarded – undo
2224 2346
 		}
2225 2347
 
2226 2348
 		// Delete it?
2227
-		if (isset($_REQUEST['deleteevent']))
2228
-			$smcFunc['db_query']('', '
2349
+		if (isset($_REQUEST['deleteevent'])) {
2350
+					$smcFunc['db_query']('', '
2229 2351
 				DELETE FROM {db_prefix}calendar
2230 2352
 				WHERE id_event = {int:id_event}',
2231 2353
 				array(
2232 2354
 					'id_event' => $_REQUEST['eventid'],
2233 2355
 				)
2234 2356
 			);
2357
+		}
2235 2358
 		// ... or just update it?
2236 2359
 		else
2237 2360
 		{
@@ -2273,9 +2396,8 @@  discard block
 block discarded – undo
2273 2396
 			array($user_info['id'], $topic, 0),
2274 2397
 			array('id_member', 'id_topic', 'id_board')
2275 2398
 		);
2276
-	}
2277
-	elseif (!$newTopic)
2278
-		$smcFunc['db_query']('', '
2399
+	} elseif (!$newTopic) {
2400
+			$smcFunc['db_query']('', '
2279 2401
 			DELETE FROM {db_prefix}log_notify
2280 2402
 			WHERE id_member = {int:current_member}
2281 2403
 				AND id_topic = {int:current_topic}',
@@ -2284,16 +2406,20 @@  discard block
 block discarded – undo
2284 2406
 				'current_topic' => $topic,
2285 2407
 			)
2286 2408
 		);
2409
+	}
2287 2410
 
2288 2411
 	// Log an act of moderation - modifying.
2289
-	if (!empty($moderationAction))
2290
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2412
+	if (!empty($moderationAction)) {
2413
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2414
+	}
2291 2415
 
2292
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2293
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2416
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2417
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2418
+	}
2294 2419
 
2295
-	if (isset($_POST['sticky']))
2296
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2420
+	if (isset($_POST['sticky'])) {
2421
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2422
+	}
2297 2423
 
2298 2424
 	// Returning to the topic?
2299 2425
 	if (!empty($_REQUEST['goback']))
@@ -2312,26 +2438,31 @@  discard block
 block discarded – undo
2312 2438
 		);
2313 2439
 	}
2314 2440
 
2315
-	if ($board_info['num_topics'] == 0)
2316
-		cache_put_data('board-' . $board, null, 120);
2441
+	if ($board_info['num_topics'] == 0) {
2442
+			cache_put_data('board-' . $board, null, 120);
2443
+	}
2317 2444
 
2318 2445
 	call_integration_hook('integrate_post2_end');
2319 2446
 
2320
-	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic'))
2321
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2447
+	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) {
2448
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2449
+	}
2322 2450
 
2323
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2324
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2451
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2452
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2453
+	}
2325 2454
 
2326 2455
 	// Return to post if the mod is on.
2327
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2328
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2329
-	elseif (!empty($_REQUEST['goback']))
2330
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2456
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2457
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2458
+	} elseif (!empty($_REQUEST['goback'])) {
2459
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2460
+	}
2331 2461
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2332
-	else
2333
-		redirectexit('board=' . $board . '.0');
2334
-}
2462
+	else {
2463
+			redirectexit('board=' . $board . '.0');
2464
+	}
2465
+	}
2335 2466
 
2336 2467
 /**
2337 2468
  * Handle the announce topic function (action=announce).
@@ -2349,8 +2480,9 @@  discard block
 block discarded – undo
2349 2480
 
2350 2481
 	validateSession();
2351 2482
 
2352
-	if (empty($topic))
2353
-		fatal_lang_error('topic_gone', false);
2483
+	if (empty($topic)) {
2484
+			fatal_lang_error('topic_gone', false);
2485
+	}
2354 2486
 
2355 2487
 	loadLanguage('Post');
2356 2488
 	loadTemplate('Post');
@@ -2377,8 +2509,9 @@  discard block
 block discarded – undo
2377 2509
 	global $txt, $context, $topic, $board_info, $smcFunc;
2378 2510
 
2379 2511
 	$groups = array_merge($board_info['groups'], array(1));
2380
-	foreach ($groups as $id => $group)
2381
-		$groups[$id] = (int) $group;
2512
+	foreach ($groups as $id => $group) {
2513
+			$groups[$id] = (int) $group;
2514
+	}
2382 2515
 
2383 2516
 	$context['groups'] = array();
2384 2517
 	if (in_array(0, $groups))
@@ -2421,8 +2554,9 @@  discard block
 block discarded – undo
2421 2554
 			'group_list' => $groups,
2422 2555
 		)
2423 2556
 	);
2424
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2425
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2557
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2558
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2559
+	}
2426 2560
 	$smcFunc['db_free_result']($request);
2427 2561
 
2428 2562
 	// Get the subject of the topic we're about to announce.
@@ -2464,16 +2598,19 @@  discard block
 block discarded – undo
2464 2598
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2465 2599
 	$groups = array_merge($board_info['groups'], array(1));
2466 2600
 
2467
-	if (isset($_POST['membergroups']))
2468
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2601
+	if (isset($_POST['membergroups'])) {
2602
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2603
+	}
2469 2604
 
2470 2605
 	// Check whether at least one membergroup was selected.
2471
-	if (empty($_POST['who']))
2472
-		fatal_lang_error('no_membergroup_selected');
2606
+	if (empty($_POST['who'])) {
2607
+			fatal_lang_error('no_membergroup_selected');
2608
+	}
2473 2609
 
2474 2610
 	// Make sure all membergroups are integers and can access the board of the announcement.
2475
-	foreach ($_POST['who'] as $id => $mg)
2476
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2611
+	foreach ($_POST['who'] as $id => $mg) {
2612
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2613
+	}
2477 2614
 
2478 2615
 	// Get the topic subject and censor it.
2479 2616
 	$request = $smcFunc['db_query']('', '
@@ -2519,12 +2656,13 @@  discard block
 block discarded – undo
2519 2656
 	if ($smcFunc['db_num_rows']($request) == 0)
2520 2657
 	{
2521 2658
 		logAction('announce_topic', array('topic' => $topic), 'user');
2522
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2523
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2524
-		elseif (!empty($_REQUEST['goback']))
2525
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2526
-		else
2527
-			redirectexit('board=' . $board . '.0');
2659
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2660
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2661
+		} elseif (!empty($_REQUEST['goback'])) {
2662
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2663
+		} else {
2664
+					redirectexit('board=' . $board . '.0');
2665
+		}
2528 2666
 	}
2529 2667
 
2530 2668
 	$announcements = array();
@@ -2543,8 +2681,9 @@  discard block
 block discarded – undo
2543 2681
 	foreach ($rows as $row)
2544 2682
 	{
2545 2683
 		// Force them to have it?
2546
-		if (empty($prefs[$row['id_member']]['announcements']))
2547
-			continue;
2684
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2685
+					continue;
2686
+		}
2548 2687
 
2549 2688
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2550 2689
 
@@ -2572,8 +2711,9 @@  discard block
 block discarded – undo
2572 2711
 	}
2573 2712
 
2574 2713
 	// For each language send a different mail - low priority...
2575
-	foreach ($announcements as $lang => $mail)
2576
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2714
+	foreach ($announcements as $lang => $mail) {
2715
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2716
+	}
2577 2717
 
2578 2718
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2579 2719
 
@@ -2583,9 +2723,10 @@  discard block
 block discarded – undo
2583 2723
 	$context['sub_template'] = 'announcement_send';
2584 2724
 
2585 2725
 	// Go back to the correct language for the user ;).
2586
-	if (!empty($modSettings['userLanguage']))
2587
-		loadLanguage('Post');
2588
-}
2726
+	if (!empty($modSettings['userLanguage'])) {
2727
+			loadLanguage('Post');
2728
+	}
2729
+	}
2589 2730
 
2590 2731
 /**
2591 2732
  * Get the topic for display purposes.
@@ -2598,12 +2739,13 @@  discard block
 block discarded – undo
2598 2739
 {
2599 2740
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2600 2741
 
2601
-	if (isset($_REQUEST['xml']))
2602
-		$limit = '
2742
+	if (isset($_REQUEST['xml'])) {
2743
+			$limit = '
2603 2744
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2604
-	else
2605
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2745
+	} else {
2746
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2606 2747
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2748
+	}
2607 2749
 
2608 2750
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2609 2751
 	$request = $smcFunc['db_query']('', '
@@ -2641,8 +2783,9 @@  discard block
 block discarded – undo
2641 2783
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2642 2784
 		);
2643 2785
 
2644
-		if (!empty($context['new_replies']))
2645
-			$context['new_replies']--;
2786
+		if (!empty($context['new_replies'])) {
2787
+					$context['new_replies']--;
2788
+		}
2646 2789
 	}
2647 2790
 	$smcFunc['db_free_result']($request);
2648 2791
 }
@@ -2659,8 +2802,9 @@  discard block
 block discarded – undo
2659 2802
 	global $sourcedir, $smcFunc;
2660 2803
 
2661 2804
 	loadLanguage('Post');
2662
-	if (!isset($_REQUEST['xml']))
2663
-		loadTemplate('Post');
2805
+	if (!isset($_REQUEST['xml'])) {
2806
+			loadTemplate('Post');
2807
+	}
2664 2808
 
2665 2809
 	include_once($sourcedir . '/Subs-Post.php');
2666 2810
 
@@ -2691,8 +2835,9 @@  discard block
 block discarded – undo
2691 2835
 	$smcFunc['db_free_result']($request);
2692 2836
 
2693 2837
 	$context['sub_template'] = 'quotefast';
2694
-	if (!empty($row))
2695
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2838
+	if (!empty($row)) {
2839
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2840
+	}
2696 2841
 
2697 2842
 	if (!empty($can_view_post))
2698 2843
 	{
@@ -2725,8 +2870,9 @@  discard block
 block discarded – undo
2725 2870
 		}
2726 2871
 
2727 2872
 		// Remove any nested quotes.
2728
-		if (!empty($modSettings['removeNestedQuotes']))
2729
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2873
+		if (!empty($modSettings['removeNestedQuotes'])) {
2874
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2875
+		}
2730 2876
 
2731 2877
 		$lb = "\n";
2732 2878
 
@@ -2752,14 +2898,14 @@  discard block
 block discarded – undo
2752 2898
 				'time' => '',
2753 2899
 			),
2754 2900
 		);
2755
-	}
2756
-	else
2757
-		$context['quote'] = array(
2901
+	} else {
2902
+			$context['quote'] = array(
2758 2903
 			'xml' => '',
2759 2904
 			'mozilla' => '',
2760 2905
 			'text' => '',
2761 2906
 		);
2762
-}
2907
+	}
2908
+	}
2763 2909
 
2764 2910
 /**
2765 2911
  * Used to edit the body or subject of a message inline
@@ -2771,8 +2917,9 @@  discard block
 block discarded – undo
2771 2917
 	global $user_info, $context, $smcFunc, $language, $board_info;
2772 2918
 
2773 2919
 	// We have to have a topic!
2774
-	if (empty($topic))
2775
-		obExit(false);
2920
+	if (empty($topic)) {
2921
+			obExit(false);
2922
+	}
2776 2923
 
2777 2924
 	checkSession('get');
2778 2925
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2798,31 +2945,35 @@  discard block
 block discarded – undo
2798 2945
 			'guest_id' => 0,
2799 2946
 		)
2800 2947
 	);
2801
-	if ($smcFunc['db_num_rows']($request) == 0)
2802
-		fatal_lang_error('no_board', false);
2948
+	if ($smcFunc['db_num_rows']($request) == 0) {
2949
+			fatal_lang_error('no_board', false);
2950
+	}
2803 2951
 	$row = $smcFunc['db_fetch_assoc']($request);
2804 2952
 	$smcFunc['db_free_result']($request);
2805 2953
 
2806 2954
 	// Change either body or subject requires permissions to modify messages.
2807 2955
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2808 2956
 	{
2809
-		if (!empty($row['locked']))
2810
-			isAllowedTo('moderate_board');
2957
+		if (!empty($row['locked'])) {
2958
+					isAllowedTo('moderate_board');
2959
+		}
2811 2960
 
2812 2961
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2813 2962
 		{
2814
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2815
-				fatal_lang_error('modify_post_time_passed', false);
2816
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2817
-				isAllowedTo('modify_replies');
2818
-			else
2819
-				isAllowedTo('modify_own');
2963
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2964
+							fatal_lang_error('modify_post_time_passed', false);
2965
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2966
+							isAllowedTo('modify_replies');
2967
+			} else {
2968
+							isAllowedTo('modify_own');
2969
+			}
2820 2970
 		}
2821 2971
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2822
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2823
-			isAllowedTo('modify_replies');
2824
-		else
2825
-			isAllowedTo('modify_any');
2972
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2973
+					isAllowedTo('modify_replies');
2974
+		} else {
2975
+					isAllowedTo('modify_any');
2976
+		}
2826 2977
 
2827 2978
 		// Only log this action if it wasn't your message.
2828 2979
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2834,10 +2985,10 @@  discard block
 block discarded – undo
2834 2985
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2835 2986
 
2836 2987
 		// Maximum number of characters.
2837
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2838
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2839
-	}
2840
-	elseif (isset($_POST['subject']))
2988
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2989
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2990
+		}
2991
+	} elseif (isset($_POST['subject']))
2841 2992
 	{
2842 2993
 		$post_errors[] = 'no_subject';
2843 2994
 		unset($_POST['subject']);
@@ -2849,13 +3000,11 @@  discard block
 block discarded – undo
2849 3000
 		{
2850 3001
 			$post_errors[] = 'no_message';
2851 3002
 			unset($_POST['message']);
2852
-		}
2853
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
3003
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2854 3004
 		{
2855 3005
 			$post_errors[] = 'long_message';
2856 3006
 			unset($_POST['message']);
2857
-		}
2858
-		else
3007
+		} else
2859 3008
 		{
2860 3009
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2861 3010
 
@@ -2871,31 +3020,34 @@  discard block
 block discarded – undo
2871 3020
 
2872 3021
 	if (isset($_POST['lock']))
2873 3022
 	{
2874
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2875
-			unset($_POST['lock']);
2876
-		elseif (!allowedTo('lock_any'))
3023
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
3024
+					unset($_POST['lock']);
3025
+		} elseif (!allowedTo('lock_any'))
2877 3026
 		{
2878
-			if ($row['locked'] == 1)
2879
-				unset($_POST['lock']);
2880
-			else
2881
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3027
+			if ($row['locked'] == 1) {
3028
+							unset($_POST['lock']);
3029
+			} else {
3030
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3031
+			}
3032
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
3033
+					unset($_POST['lock']);
3034
+		} else {
3035
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2882 3036
 		}
2883
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2884
-			unset($_POST['lock']);
2885
-		else
2886
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2887 3037
 	}
2888 3038
 
2889
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2890
-		unset($_POST['sticky']);
3039
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
3040
+			unset($_POST['sticky']);
3041
+	}
2891 3042
 
2892 3043
 	if (isset($_POST['modify_reason']))
2893 3044
 	{
2894 3045
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2895 3046
 
2896 3047
 		// Maximum number of characters.
2897
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2898
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3048
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
3049
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3050
+		}
2899 3051
 	}
2900 3052
 
2901 3053
 	if (empty($post_errors))
@@ -2932,8 +3084,9 @@  discard block
 block discarded – undo
2932 3084
 			}
2933 3085
 		}
2934 3086
 		// If nothing was changed there's no need to add an entry to the moderation log.
2935
-		else
2936
-			$moderationAction = false;
3087
+		else {
3088
+					$moderationAction = false;
3089
+		}
2937 3090
 
2938 3091
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2939 3092
 
@@ -2951,9 +3104,9 @@  discard block
 block discarded – undo
2951 3104
 			// Get the proper (default language) response prefix first.
2952 3105
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2953 3106
 			{
2954
-				if ($language === $user_info['language'])
2955
-					$context['response_prefix'] = $txt['response_prefix'];
2956
-				else
3107
+				if ($language === $user_info['language']) {
3108
+									$context['response_prefix'] = $txt['response_prefix'];
3109
+				} else
2957 3110
 				{
2958 3111
 					loadLanguage('index', $language, false);
2959 3112
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2975,8 +3128,9 @@  discard block
 block discarded – undo
2975 3128
 			);
2976 3129
 		}
2977 3130
 
2978
-		if (!empty($moderationAction))
2979
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3131
+		if (!empty($moderationAction)) {
3132
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3133
+		}
2980 3134
 	}
2981 3135
 
2982 3136
 	if (isset($_REQUEST['xml']))
@@ -3017,8 +3171,7 @@  discard block
 block discarded – undo
3017 3171
 			);
3018 3172
 
3019 3173
 			censorText($context['message']['subject']);
3020
-		}
3021
-		else
3174
+		} else
3022 3175
 		{
3023 3176
 			$context['message'] = array(
3024 3177
 				'id' => $row['id_msg'],
@@ -3030,15 +3183,16 @@  discard block
 block discarded – undo
3030 3183
 			loadLanguage('Errors');
3031 3184
 			foreach ($post_errors as $post_error)
3032 3185
 			{
3033
-				if ($post_error == 'long_message')
3034
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3035
-				else
3036
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3186
+				if ($post_error == 'long_message') {
3187
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3188
+				} else {
3189
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3190
+				}
3037 3191
 			}
3038 3192
 		}
3193
+	} else {
3194
+			obExit(false);
3195
+	}
3039 3196
 	}
3040
-	else
3041
-		obExit(false);
3042
-}
3043 3197
 
3044 3198
 ?>
3045 3199
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 1 patch
Braces   +48 added lines, -33 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 	<strong>
29 29
 		', $context['error_title'], '
30 30
 	</strong><br>
31 31
 	<div ', $context['error_code'], 'class="padding">
32 32
 		', $context['error_message'], '
33 33
 	</div>';
34
-	else
34
+	} else
35 35
 	{
36 36
 		echo '
37 37
 	<div id="fatal_error">
@@ -85,21 +85,23 @@  discard block
 block discarded – undo
85 85
 
86 86
 	$error_types = array();
87 87
 
88
-	foreach ($context['error_types'] as $type => $details)
89
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
88
+	foreach ($context['error_types'] as $type => $details) {
89
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
90
+	}
90 91
 
91 92
 	echo '
92 93
 						', implode(' | ', $error_types), '
93 94
 					</td>
94 95
 				</tr>';
95 96
 
96
-	if ($context['has_filter'])
97
-		echo '
97
+	if ($context['has_filter']) {
98
+			echo '
98 99
 				<tr>
99 100
 					<td colspan="3" class="windowbg">
100 101
 						<strong>', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], ' [<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
101 102
 					</td>
102 103
 				</tr>';
104
+	}
103 105
 
104 106
 	echo '
105 107
 				<tr>
@@ -110,11 +112,12 @@  discard block
 block discarded – undo
110 112
 				</tr>';
111 113
 
112 114
 	// No errors, then show a message
113
-	if (count($context['errors']) == 0)
114
-		echo '
115
+	if (count($context['errors']) == 0) {
116
+			echo '
115 117
 				<tr class="windowbg">
116 118
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
117 119
 				</tr>';
120
+	}
118 121
 
119 122
 	// We have some errors, must be some mods installed :P
120 123
 	foreach ($context['errors'] as $error)
@@ -128,16 +131,18 @@  discard block
 block discarded – undo
128 131
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
129 132
 							', $error['time'], '<br>';
130 133
 
131
-		if (!empty($error['member']['ip']))
132
-			echo '
134
+		if (!empty($error['member']['ip'])) {
135
+					echo '
133 136
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a>
134 137
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>';
138
+		}
135 139
 
136
-		if ($error['member']['session'] != '')
137
-			echo '
140
+		if ($error['member']['session'] != '') {
141
+					echo '
138 142
 							<br>
139 143
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 						</div>
@@ -152,12 +157,13 @@  discard block
 block discarded – undo
152 157
 							<a href="', $error['url']['html'], '">', $error['url']['html'], '</a>
153 158
 ';
154 159
 
155
-		if (!empty($error['file']))
156
-			echo '
160
+		if (!empty($error['file'])) {
161
+					echo '
157 162
 							<div>
158 163
 								<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '">'
159 164
 				. '					<span class="generic_icons filter"></span></a> ', $error['file']['link'], ' (', $txt['line'], ' ', $error['file']['line'], ')
160 165
 							</div>';
166
+		}
161 167
 
162 168
 		echo '
163 169
 						</div>
@@ -186,9 +192,10 @@  discard block
 block discarded – undo
186 192
 				</div>
187 193
 			</div>';
188 194
 
189
-	if ($context['sort_direction'] == 'down')
190
-		echo '
195
+	if ($context['sort_direction'] == 'down') {
196
+			echo '
191 197
 			<input type="hidden" name="desc" value="1">';
198
+	}
192 199
 
193 200
 	echo '
194 201
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -249,9 +256,10 @@  discard block
 block discarded – undo
249 256
 					$context['error_message'], '
250 257
 				</div>';
251 258
 	
252
-	if (!empty($context['back_link'])) 
253
-		echo '
259
+	if (!empty($context['back_link'])) {
260
+			echo '
254 261
 				<a class="button" href="', $scripturl, $context['back_link'], '">', $txt['back'], '</a>';
262
+	}
255 263
 
256 264
 	echo '
257 265
 				<span style="float: right; margin:.5em;"></span>
@@ -288,25 +296,30 @@  discard block
 block discarded – undo
288 296
 			<div class="windowbg">
289 297
 				<ul class="padding">';
290 298
 
291
-		if (!empty($context['error_info']['error_type']))
292
-			echo '
299
+		if (!empty($context['error_info']['error_type'])) {
300
+					echo '
293 301
 					<li>', $txt['error_type'], ': ', ucfirst($context['error_info']['error_type']), '</li>';
302
+		}
294 303
 
295
-		if (!empty($context['error_info']['message']))
296
-			echo '
304
+		if (!empty($context['error_info']['message'])) {
305
+					echo '
297 306
 					<li>', $txt['error_message'], ': ', $context['error_info']['message'], '</li>';
307
+		}
298 308
 
299
-		if (!empty($context['error_info']['file']))
300
-			echo '
309
+		if (!empty($context['error_info']['file'])) {
310
+					echo '
301 311
 					<li>', $txt['error_file'], ': ', $context['error_info']['file'], '</li>';
312
+		}
302 313
 
303
-		if (!empty($context['error_info']['line']))
304
-			echo '
314
+		if (!empty($context['error_info']['line'])) {
315
+					echo '
305 316
 					<li>', $txt['error_line'], ': ', $context['error_info']['line'], '</li>';
317
+		}
306 318
 
307
-		if (!empty($context['error_info']['url']))
308
-			echo '
319
+		if (!empty($context['error_info']['url'])) {
320
+					echo '
309 321
 					<li>', $txt['error_url'], ': ', $context['error_info']['url'], '</li>';
322
+		}
310 323
 
311 324
 
312 325
 		echo '
@@ -328,10 +341,12 @@  discard block
 block discarded – undo
328 341
 		foreach ($context['error_info']['backtrace'] as $key => $value)
329 342
 		{
330 343
 			//Check for existing
331
-			if (!property_exists($value,'file') || empty($value->file))
332
-				$value->file = $txt['unknown'];
333
-			if (!property_exists($value, 'line') || empty($value->line))
334
-				$value->line = -1;
344
+			if (!property_exists($value,'file') || empty($value->file)) {
345
+							$value->file = $txt['unknown'];
346
+			}
347
+			if (!property_exists($value, 'line') || empty($value->line)) {
348
+							$value->line = -1;
349
+			}
335 350
 
336 351
 				echo '
337 352
 					<li class="backtrace">', sprintf($txt['backtrace_info'], $key, $value->function, $value->file, $value->line, base64_encode($value->file)), '</li>';
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +907 added lines, -664 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
 
@@ -403,15 +424,19 @@  discard block
 block discarded – undo
403 424
 		$seconds = intval($active % 60);
404 425
 
405 426
 		$totalTime = '';
406
-		if ($hours > 0)
407
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
408
-		if ($minutes > 0)
409
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
410
-		if ($seconds > 0)
411
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
427
+		if ($hours > 0) {
428
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
429
+		}
430
+		if ($minutes > 0) {
431
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
432
+		}
433
+		if ($seconds > 0) {
434
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
435
+		}
412 436
 
413
-		if (!empty($totalTime))
414
-			echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
437
+		if (!empty($totalTime)) {
438
+					echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
439
+		}
415 440
 	}
416 441
 
417 442
 	// Bang - gone!
@@ -432,8 +457,9 @@  discard block
 block discarded – undo
432 457
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
433 458
 		while ($entry = $dir->read())
434 459
 		{
435
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
436
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
460
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
461
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
462
+			}
437 463
 		}
438 464
 		$dir->close();
439 465
 	}
@@ -464,10 +490,11 @@  discard block
 block discarded – undo
464 490
 	}
465 491
 
466 492
 	// Override the language file?
467
-	if (isset($_GET['lang_file']))
468
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
469
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
470
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
493
+	if (isset($_GET['lang_file'])) {
494
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
495
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
496
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
497
+	}
471 498
 
472 499
 	// Make sure it exists, if it doesn't reset it.
473 500
 	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']))
@@ -476,12 +503,14 @@  discard block
 block discarded – undo
476 503
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
477 504
 
478 505
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
479
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
480
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
506
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
507
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
508
+		}
481 509
 
482 510
 		// For backup we load the english at first -> second language overwrite the english one
483
-		if (count($incontext['detected_languages']) > 1)
484
-			require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
511
+		if (count($incontext['detected_languages']) > 1) {
512
+					require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
513
+		}
485 514
 	}
486 515
 
487 516
 	// And now include the actual language file itself.
@@ -489,11 +518,12 @@  discard block
 block discarded – undo
489 518
 
490 519
 	// Which language did we load? Assume that he likes his language.
491 520
 	preg_match('~^Install\.(.+[^-utf8])\.php$~', $_SESSION['installer_temp_lang'], $matches);
492
-	if (empty($matches[1]))
493
-		$matches = [
521
+	if (empty($matches[1])) {
522
+			$matches = [
494 523
 			0 => 'nothing',
495 524
 			1 => 'english',
496 525
 		];
526
+	}
497 527
 	$user_info['language'] = $matches[1];
498 528
 }
499 529
 
@@ -503,8 +533,9 @@  discard block
 block discarded – undo
503 533
 	global $upgradeurl, $upcontext, $command_line;
504 534
 
505 535
 	// Command line users can't be redirected.
506
-	if ($command_line)
507
-		upgradeExit(true);
536
+	if ($command_line) {
537
+			upgradeExit(true);
538
+	}
508 539
 
509 540
 	// Are we providing the core info?
510 541
 	if ($addForm)
@@ -530,12 +561,14 @@  discard block
 block discarded – undo
530 561
 	define('SMF', 1);
531 562
 
532 563
 	// Start the session.
533
-	if (@ini_get('session.save_handler') == 'user')
534
-		@ini_set('session.save_handler', 'files');
564
+	if (@ini_get('session.save_handler') == 'user') {
565
+			@ini_set('session.save_handler', 'files');
566
+	}
535 567
 	@session_start();
536 568
 
537
-	if (empty($smcFunc))
538
-		$smcFunc = array();
569
+	if (empty($smcFunc)) {
570
+			$smcFunc = array();
571
+	}
539 572
 
540 573
 	// We need this for authentication and some upgrade code
541 574
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -562,24 +595,27 @@  discard block
 block discarded – undo
562 595
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
563 596
 
564 597
 		// Make the connection...
565
-		if (empty($db_connection))
566
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
567
-		else
568
-			// If we've returned here, ping/reconnect to be safe
598
+		if (empty($db_connection)) {
599
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
600
+		} else {
601
+					// If we've returned here, ping/reconnect to be safe
569 602
 			$smcFunc['db_ping']($db_connection);
603
+		}
570 604
 
571 605
 		// Oh dear god!!
572
-		if ($db_connection === null)
573
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
606
+		if ($db_connection === null) {
607
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
608
+		}
574 609
 
575
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
576
-			$smcFunc['db_query']('', '
610
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
611
+					$smcFunc['db_query']('', '
577 612
 			SET NAMES {string:db_character_set}',
578 613
 			array(
579 614
 				'db_error_skip' => true,
580 615
 				'db_character_set' => $db_character_set,
581 616
 			)
582 617
 		);
618
+		}
583 619
 
584 620
 		// Load the modSettings data...
585 621
 		$request = $smcFunc['db_query']('', '
@@ -590,11 +626,11 @@  discard block
 block discarded – undo
590 626
 			)
591 627
 		);
592 628
 		$modSettings = array();
593
-		while ($row = $smcFunc['db_fetch_assoc']($request))
594
-			$modSettings[$row['variable']] = $row['value'];
629
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
630
+					$modSettings[$row['variable']] = $row['value'];
631
+		}
595 632
 		$smcFunc['db_free_result']($request);
596
-	}
597
-	else
633
+	} else
598 634
 	{
599 635
 		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.');
600 636
 	}
@@ -608,9 +644,10 @@  discard block
 block discarded – undo
608 644
 		cleanRequest();
609 645
 	}
610 646
 
611
-	if (!isset($_GET['substep']))
612
-		$_GET['substep'] = 0;
613
-}
647
+	if (!isset($_GET['substep'])) {
648
+			$_GET['substep'] = 0;
649
+	}
650
+	}
614 651
 
615 652
 function initialize_inputs()
616 653
 {
@@ -640,8 +677,9 @@  discard block
 block discarded – undo
640 677
 		$dh = opendir(dirname(__FILE__));
641 678
 		while ($file = readdir($dh))
642 679
 		{
643
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
644
-				@unlink(dirname(__FILE__) . '/' . $file);
680
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
681
+							@unlink(dirname(__FILE__) . '/' . $file);
682
+			}
645 683
 		}
646 684
 		closedir($dh);
647 685
 
@@ -670,8 +708,9 @@  discard block
 block discarded – undo
670 708
 	$temp = 'upgrade_php?step';
671 709
 	while (strlen($temp) > 4)
672 710
 	{
673
-		if (isset($_GET[$temp]))
674
-			unset($_GET[$temp]);
711
+		if (isset($_GET[$temp])) {
712
+					unset($_GET[$temp]);
713
+		}
675 714
 		$temp = substr($temp, 1);
676 715
 	}
677 716
 
@@ -698,32 +737,39 @@  discard block
 block discarded – undo
698 737
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
699 738
 
700 739
 	// Need legacy scripts?
701
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
702
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
703
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
704
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
705
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
706
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
740
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
741
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
742
+	}
743
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
744
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
745
+	}
746
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
747
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
748
+	}
707 749
 
708 750
 	// We don't need "-utf8" files anymore...
709 751
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
710 752
 
711 753
 	// This needs to exist!
712
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
713
-		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>]');
714
-	else
715
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
754
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
755
+			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>]');
756
+	} else {
757
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
758
+	}
716 759
 
717
-	if (!$check)
718
-		// 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.
760
+	if (!$check) {
761
+			// 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.
719 762
 		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.');
763
+	}
720 764
 
721 765
 	// Do they meet the install requirements?
722
-	if (!php_version_check())
723
-		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.');
766
+	if (!php_version_check()) {
767
+			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.');
768
+	}
724 769
 
725
-	if (!db_version_check())
726
-		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.');
770
+	if (!db_version_check()) {
771
+			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.');
772
+	}
727 773
 
728 774
 	// Do some checks to make sure they have proper privileges
729 775
 	db_extend('packages');
@@ -738,14 +784,16 @@  discard block
 block discarded – undo
738 784
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
739 785
 
740 786
 	// Sorry... we need CREATE, ALTER and DROP
741
-	if (!$create || !$alter || !$drop)
742
-		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.');
787
+	if (!$create || !$alter || !$drop) {
788
+			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.');
789
+	}
743 790
 
744 791
 	// Do a quick version spot check.
745 792
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
746 793
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
747
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
748
-		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.');
794
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
795
+			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.');
796
+	}
749 797
 
750 798
 	// What absolutely needs to be writable?
751 799
 	$writable_files = array(
@@ -754,12 +802,13 @@  discard block
 block discarded – undo
754 802
 	);
755 803
 
756 804
 	// Only check for minified writable files if we have it enabled or not set.
757
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
758
-		$writable_files += array(
805
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
806
+			$writable_files += array(
759 807
 			$modSettings['theme_dir'] . '/css/minified.css',
760 808
 			$modSettings['theme_dir'] . '/scripts/minified.js',
761 809
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
762 810
 		);
811
+	}
763 812
 
764 813
 	// Do we need to add this setting?
765 814
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -771,12 +820,13 @@  discard block
 block discarded – undo
771 820
 	quickFileWritable($custom_av_dir);
772 821
 
773 822
 	// Are we good now?
774
-	if (!is_writable($custom_av_dir))
775
-		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));
776
-	elseif ($need_settings_update)
823
+	if (!is_writable($custom_av_dir)) {
824
+			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));
825
+	} elseif ($need_settings_update)
777 826
 	{
778
-		if (!function_exists('cache_put_data'))
779
-			require_once($sourcedir . '/Load.php');
827
+		if (!function_exists('cache_put_data')) {
828
+					require_once($sourcedir . '/Load.php');
829
+		}
780 830
 
781 831
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
782 832
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
@@ -786,29 +836,34 @@  discard block
 block discarded – undo
786 836
 
787 837
 	// Check the cache directory.
788 838
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
789
-	if (!file_exists($cachedir_temp))
790
-		@mkdir($cachedir_temp);
839
+	if (!file_exists($cachedir_temp)) {
840
+			@mkdir($cachedir_temp);
841
+	}
791 842
 
792
-	if (!file_exists($cachedir_temp))
793
-		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.');
843
+	if (!file_exists($cachedir_temp)) {
844
+			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.');
845
+	}
794 846
 
795
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
796
-		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>.');
797
-	elseif (!isset($_GET['skiplang']))
847
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
848
+			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>.');
849
+	} elseif (!isset($_GET['skiplang']))
798 850
 	{
799 851
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
800 852
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
801 853
 
802
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
803
-			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>]');
854
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
855
+					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>]');
856
+		}
804 857
 	}
805 858
 
806
-	if (!makeFilesWritable($writable_files))
807
-		return false;
859
+	if (!makeFilesWritable($writable_files)) {
860
+			return false;
861
+	}
808 862
 
809 863
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
810
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
811
-		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.');
864
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
865
+			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.');
866
+	}
812 867
 
813 868
 	// Upgrade the agreement.
814 869
 	elseif (isset($modSettings['agreement']))
@@ -819,8 +874,8 @@  discard block
 block discarded – undo
819 874
 	}
820 875
 
821 876
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
822
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
823
-		$upcontext['warning'] = '
877
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
878
+			$upcontext['warning'] = '
824 879
 			'. sprintf($txt['upgrade_boarddir_settings'], $boarddir, dirname(__FILE__)) .'<br>
825 880
 			<ul>
826 881
 				<li>'. $txt['upgrade_boarddir'] .'  ' . $boarddir . '</li>
@@ -828,19 +883,23 @@  discard block
 block discarded – undo
828 883
 				<li>'. $txt['upgrade_cachedir'] .'  ' . $cachedir_temp . '</li>
829 884
 			</ul>
830 885
 			'. $txt['upgrade_incorrect_settings'] .'';
886
+	}
831 887
 
832 888
 	// Confirm mbstring is loaded...
833
-	if (!extension_loaded('mbstring'))
834
-		return throw_error($txt['install_no_mbstring']);
889
+	if (!extension_loaded('mbstring')) {
890
+			return throw_error($txt['install_no_mbstring']);
891
+	}
835 892
 
836 893
 	// Check for https stream support.
837 894
 	$supported_streams = stream_get_wrappers();
838
-	if (!in_array('https', $supported_streams))
839
-		$upcontext['custom_warning'] = $txt['install_no_https'];
895
+	if (!in_array('https', $supported_streams)) {
896
+			$upcontext['custom_warning'] = $txt['install_no_https'];
897
+	}
840 898
 
841 899
 	// Either we're logged in or we're going to present the login.
842
-	if (checkLogin())
843
-		return true;
900
+	if (checkLogin()) {
901
+			return true;
902
+	}
844 903
 
845 904
 	$upcontext += createToken('login');
846 905
 
@@ -854,15 +913,17 @@  discard block
 block discarded – undo
854 913
 	global $smcFunc, $db_type, $support_js;
855 914
 
856 915
 	// Don't bother if the security is disabled.
857
-	if ($disable_security)
858
-		return true;
916
+	if ($disable_security) {
917
+			return true;
918
+	}
859 919
 
860 920
 	// Are we trying to login?
861 921
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
862 922
 	{
863 923
 		// If we've disabled security pick a suitable name!
864
-		if (empty($_POST['user']))
865
-			$_POST['user'] = 'Administrator';
924
+		if (empty($_POST['user'])) {
925
+					$_POST['user'] = 'Administrator';
926
+		}
866 927
 
867 928
 		// Before 2.0 these column names were different!
868 929
 		$oldDB = false;
@@ -877,16 +938,17 @@  discard block
 block discarded – undo
877 938
 					'db_error_skip' => true,
878 939
 				)
879 940
 			);
880
-			if ($smcFunc['db_num_rows']($request) != 0)
881
-				$oldDB = true;
941
+			if ($smcFunc['db_num_rows']($request) != 0) {
942
+							$oldDB = true;
943
+			}
882 944
 			$smcFunc['db_free_result']($request);
883 945
 		}
884 946
 
885 947
 		// Get what we believe to be their details.
886 948
 		if (!$disable_security)
887 949
 		{
888
-			if ($oldDB)
889
-				$request = $smcFunc['db_query']('', '
950
+			if ($oldDB) {
951
+							$request = $smcFunc['db_query']('', '
890 952
 					SELECT id_member, memberName AS member_name, passwd, id_group,
891 953
 					additionalGroups AS additional_groups, lngfile
892 954
 					FROM {db_prefix}members
@@ -896,8 +958,8 @@  discard block
 block discarded – undo
896 958
 						'db_error_skip' => true,
897 959
 					)
898 960
 				);
899
-			else
900
-				$request = $smcFunc['db_query']('', '
961
+			} else {
962
+							$request = $smcFunc['db_query']('', '
901 963
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
902 964
 					FROM {db_prefix}members
903 965
 					WHERE member_name = {string:member_name}',
@@ -906,6 +968,7 @@  discard block
 block discarded – undo
906 968
 						'db_error_skip' => true,
907 969
 					)
908 970
 				);
971
+			}
909 972
 			if ($smcFunc['db_num_rows']($request) != 0)
910 973
 			{
911 974
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -913,16 +976,17 @@  discard block
 block discarded – undo
913 976
 				$groups = explode(',', $addGroups);
914 977
 				$groups[] = $id_group;
915 978
 
916
-				foreach ($groups as $k => $v)
917
-					$groups[$k] = (int) $v;
979
+				foreach ($groups as $k => $v) {
980
+									$groups[$k] = (int) $v;
981
+				}
918 982
 
919 983
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
920 984
 
921 985
 				// We don't use "-utf8" anymore...
922 986
 				$user_language = str_ireplace('-utf8', '', $user_language);
987
+			} else {
988
+							$upcontext['username_incorrect'] = true;
923 989
 			}
924
-			else
925
-				$upcontext['username_incorrect'] = true;
926 990
 
927 991
 			$smcFunc['db_free_result']($request);
928 992
 		}
@@ -933,13 +997,14 @@  discard block
 block discarded – undo
933 997
 		{
934 998
 			$upcontext['upgrade_status']['js'] = 1;
935 999
 			$support_js = 1;
1000
+		} else {
1001
+					$support_js = 0;
936 1002
 		}
937
-		else
938
-			$support_js = 0;
939 1003
 
940 1004
 		// Note down the version we are coming from.
941
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
942
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
1005
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
1006
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
1007
+		}
943 1008
 
944 1009
 		// Didn't get anywhere?
945 1010
 		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']))
@@ -973,15 +1038,15 @@  discard block
 block discarded – undo
973 1038
 							'db_error_skip' => true,
974 1039
 						)
975 1040
 					);
976
-					if ($smcFunc['db_num_rows']($request) == 0)
977
-						return throw_error('You need to be an admin to perform an upgrade!');
1041
+					if ($smcFunc['db_num_rows']($request) == 0) {
1042
+											return throw_error('You need to be an admin to perform an upgrade!');
1043
+					}
978 1044
 					$smcFunc['db_free_result']($request);
979 1045
 				}
980 1046
 
981 1047
 				$upcontext['user']['id'] = $id_member;
982 1048
 				$upcontext['user']['name'] = $name;
983
-			}
984
-			else
1049
+			} else
985 1050
 			{
986 1051
 				$upcontext['user']['id'] = 1;
987 1052
 				$upcontext['user']['name'] = 'Administrator';
@@ -997,11 +1062,11 @@  discard block
 block discarded – undo
997 1062
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
998 1063
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
999 1064
 
1000
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
1001
-					$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'] . '.';
1002
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
1003
-					$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'] . '.';
1004
-				else
1065
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1066
+									$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'] . '.';
1067
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1068
+									$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'] . '.';
1069
+				} else
1005 1070
 				{
1006 1071
 					// Set this as the new language.
1007 1072
 					$upcontext['language'] = $user_language;
@@ -1045,8 +1110,9 @@  discard block
 block discarded – undo
1045 1110
 	unset($member_columns);
1046 1111
 
1047 1112
 	// If we've not submitted then we're done.
1048
-	if (empty($_POST['upcont']))
1049
-		return false;
1113
+	if (empty($_POST['upcont'])) {
1114
+			return false;
1115
+	}
1050 1116
 
1051 1117
 	// Firstly, if they're enabling SM stat collection just do it.
1052 1118
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1066,16 +1132,17 @@  discard block
 block discarded – undo
1066 1132
 				fwrite($fp, $out);
1067 1133
 
1068 1134
 				$return_data = '';
1069
-				while (!feof($fp))
1070
-					$return_data .= fgets($fp, 128);
1135
+				while (!feof($fp)) {
1136
+									$return_data .= fgets($fp, 128);
1137
+				}
1071 1138
 
1072 1139
 				fclose($fp);
1073 1140
 
1074 1141
 				// Get the unique site ID.
1075 1142
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1076 1143
 
1077
-				if (!empty($ID[1]))
1078
-					$smcFunc['db_insert']('replace',
1144
+				if (!empty($ID[1])) {
1145
+									$smcFunc['db_insert']('replace',
1079 1146
 						$db_prefix . 'settings',
1080 1147
 						array('variable' => 'string', 'value' => 'string'),
1081 1148
 						array(
@@ -1084,9 +1151,9 @@  discard block
 block discarded – undo
1084 1151
 						),
1085 1152
 						array('variable')
1086 1153
 					);
1154
+				}
1087 1155
 			}
1088
-		}
1089
-		else
1156
+		} else
1090 1157
 		{
1091 1158
 			$smcFunc['db_insert']('replace',
1092 1159
 				$db_prefix . 'settings',
@@ -1097,8 +1164,8 @@  discard block
 block discarded – undo
1097 1164
 		}
1098 1165
 	}
1099 1166
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1100
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1101
-		$smcFunc['db_query']('', '
1167
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1168
+			$smcFunc['db_query']('', '
1102 1169
 			DELETE FROM {db_prefix}settings
1103 1170
 			WHERE variable = {string:enable_sm_stats}',
1104 1171
 			array(
@@ -1106,6 +1173,7 @@  discard block
 block discarded – undo
1106 1173
 				'db_error_skip' => true,
1107 1174
 			)
1108 1175
 		);
1176
+	}
1109 1177
 
1110 1178
 	// Deleting old karma stuff?
1111 1179
 	if (!empty($_POST['delete_karma']))
@@ -1120,20 +1188,22 @@  discard block
 block discarded – undo
1120 1188
 		);
1121 1189
 
1122 1190
 		// Cleaning up old karma member settings.
1123
-		if ($upcontext['karma_installed']['good'])
1124
-			$smcFunc['db_query']('', '
1191
+		if ($upcontext['karma_installed']['good']) {
1192
+					$smcFunc['db_query']('', '
1125 1193
 				ALTER TABLE {db_prefix}members
1126 1194
 				DROP karma_good',
1127 1195
 				array()
1128 1196
 			);
1197
+		}
1129 1198
 
1130 1199
 		// Does karma bad was enable?
1131
-		if ($upcontext['karma_installed']['bad'])
1132
-			$smcFunc['db_query']('', '
1200
+		if ($upcontext['karma_installed']['bad']) {
1201
+					$smcFunc['db_query']('', '
1133 1202
 				ALTER TABLE {db_prefix}members
1134 1203
 				DROP karma_bad',
1135 1204
 				array()
1136 1205
 			);
1206
+		}
1137 1207
 
1138 1208
 		// Cleaning up old karma permissions.
1139 1209
 		$smcFunc['db_query']('', '
@@ -1151,32 +1221,37 @@  discard block
 block discarded – undo
1151 1221
 	}
1152 1222
 
1153 1223
 	// Emptying the error log?
1154
-	if (!empty($_POST['empty_error']))
1155
-		$smcFunc['db_query']('truncate_table', '
1224
+	if (!empty($_POST['empty_error'])) {
1225
+			$smcFunc['db_query']('truncate_table', '
1156 1226
 			TRUNCATE {db_prefix}log_errors',
1157 1227
 			array(
1158 1228
 			)
1159 1229
 		);
1230
+	}
1160 1231
 
1161 1232
 	$changes = array();
1162 1233
 
1163 1234
 	// Add proxy settings.
1164
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1165
-		$changes += array(
1235
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1236
+			$changes += array(
1166 1237
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1167 1238
 			'image_proxy_maxsize' => 5190,
1168 1239
 			'image_proxy_enabled' => 0,
1169 1240
 		);
1241
+	}
1170 1242
 
1171 1243
 	// If $boardurl reflects https, set force_ssl
1172
-	if (!function_exists('cache_put_data'))
1173
-		require_once($sourcedir . '/Load.php');
1174
-	if (stripos($boardurl, 'https://') !== false)
1175
-		updateSettings(array('force_ssl' => '1'));
1244
+	if (!function_exists('cache_put_data')) {
1245
+			require_once($sourcedir . '/Load.php');
1246
+	}
1247
+	if (stripos($boardurl, 'https://') !== false) {
1248
+			updateSettings(array('force_ssl' => '1'));
1249
+	}
1176 1250
 
1177 1251
 	// If we're overriding the language follow it through.
1178
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1179
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1252
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1253
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1254
+	}
1180 1255
 
1181 1256
 	if (!empty($_POST['maint']))
1182 1257
 	{
@@ -1188,26 +1263,29 @@  discard block
 block discarded – undo
1188 1263
 		{
1189 1264
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1190 1265
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1191
-		}
1192
-		else
1266
+		} else
1193 1267
 		{
1194 1268
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1195 1269
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1196 1270
 		}
1197 1271
 	}
1198 1272
 
1199
-	if ($command_line)
1200
-		echo ' * Updating Settings.php...';
1273
+	if ($command_line) {
1274
+			echo ' * Updating Settings.php...';
1275
+	}
1201 1276
 
1202 1277
 	// Fix some old paths.
1203
-	if (substr($boarddir, 0, 1) == '.')
1204
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1278
+	if (substr($boarddir, 0, 1) == '.') {
1279
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1280
+	}
1205 1281
 
1206
-	if (substr($sourcedir, 0, 1) == '.')
1207
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1282
+	if (substr($sourcedir, 0, 1) == '.') {
1283
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1284
+	}
1208 1285
 
1209
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1210
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1286
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1287
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1288
+	}
1211 1289
 
1212 1290
 	// If they have a "host:port" setup for the host, split that into separate values
1213 1291
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1218,32 +1296,36 @@  discard block
 block discarded – undo
1218 1296
 		$changes['db_server'] = '\'' . $db_server . '\'';
1219 1297
 
1220 1298
 		// Only set this if we're not using the default port
1221
-		if ($db_port != ini_get('mysqli.default_port'))
1222
-			$changes['db_port'] = (int) $db_port;
1223
-	}
1224
-	elseif (!empty($db_port))
1299
+		if ($db_port != ini_get('mysqli.default_port')) {
1300
+					$changes['db_port'] = (int) $db_port;
1301
+		}
1302
+	} elseif (!empty($db_port))
1225 1303
 	{
1226 1304
 		// If db_port is set and is the same as the default, set it to ''
1227 1305
 		if ($db_type == 'mysql')
1228 1306
 		{
1229
-			if ($db_port == ini_get('mysqli.default_port'))
1230
-				$changes['db_port'] = '\'\'';
1231
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1232
-				$changes['db_port'] = '\'\'';
1307
+			if ($db_port == ini_get('mysqli.default_port')) {
1308
+							$changes['db_port'] = '\'\'';
1309
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1310
+							$changes['db_port'] = '\'\'';
1311
+			}
1233 1312
 		}
1234 1313
 	}
1235 1314
 
1236 1315
 	// Maybe we haven't had this option yet?
1237
-	if (empty($packagesdir))
1238
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1316
+	if (empty($packagesdir)) {
1317
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1318
+	}
1239 1319
 
1240 1320
 	// Add support for $tasksdir var.
1241
-	if (empty($tasksdir))
1242
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1321
+	if (empty($tasksdir)) {
1322
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1323
+	}
1243 1324
 
1244 1325
 	// Make sure we fix the language as well.
1245
-	if (stristr($language, '-utf8'))
1246
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1326
+	if (stristr($language, '-utf8')) {
1327
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1328
+	}
1247 1329
 
1248 1330
 	// @todo Maybe change the cookie name if going to 1.1, too?
1249 1331
 
@@ -1254,8 +1336,9 @@  discard block
 block discarded – undo
1254 1336
 	// Tell Settings.php to store db_last_error.php in the cache
1255 1337
 	move_db_last_error_to_cachedir();
1256 1338
 
1257
-	if ($command_line)
1258
-		echo ' Successful.' . "\n";
1339
+	if ($command_line) {
1340
+			echo ' Successful.' . "\n";
1341
+	}
1259 1342
 
1260 1343
 	// Are we doing debug?
1261 1344
 	if (isset($_POST['debug']))
@@ -1265,8 +1348,9 @@  discard block
 block discarded – undo
1265 1348
 	}
1266 1349
 
1267 1350
 	// If we're not backing up then jump one.
1268
-	if (empty($_POST['backup']))
1269
-		$upcontext['current_step']++;
1351
+	if (empty($_POST['backup'])) {
1352
+			$upcontext['current_step']++;
1353
+	}
1270 1354
 
1271 1355
 	// If we've got here then let's proceed to the next step!
1272 1356
 	return true;
@@ -1281,8 +1365,9 @@  discard block
 block discarded – undo
1281 1365
 	$upcontext['page_title'] = $txt['backup_database'];
1282 1366
 
1283 1367
 	// Done it already - js wise?
1284
-	if (!empty($_POST['backup_done']))
1285
-		return true;
1368
+	if (!empty($_POST['backup_done'])) {
1369
+			return true;
1370
+	}
1286 1371
 
1287 1372
 	// Some useful stuff here.
1288 1373
 	db_extend();
@@ -1296,9 +1381,10 @@  discard block
 block discarded – undo
1296 1381
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1297 1382
 
1298 1383
 	$table_names = array();
1299
-	foreach ($tables as $table)
1300
-		if (substr($table, 0, 7) !== 'backup_')
1384
+	foreach ($tables as $table) {
1385
+			if (substr($table, 0, 7) !== 'backup_')
1301 1386
 			$table_names[] = $table;
1387
+	}
1302 1388
 
1303 1389
 	$upcontext['table_count'] = count($table_names);
1304 1390
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1308,12 +1394,14 @@  discard block
 block discarded – undo
1308 1394
 	$file_steps = $upcontext['table_count'];
1309 1395
 
1310 1396
 	// What ones have we already done?
1311
-	foreach ($table_names as $id => $table)
1312
-		if ($id < $_GET['substep'])
1397
+	foreach ($table_names as $id => $table) {
1398
+			if ($id < $_GET['substep'])
1313 1399
 			$upcontext['previous_tables'][] = $table;
1400
+	}
1314 1401
 
1315
-	if ($command_line)
1316
-		echo 'Backing Up Tables.';
1402
+	if ($command_line) {
1403
+			echo 'Backing Up Tables.';
1404
+	}
1317 1405
 
1318 1406
 	// If we don't support javascript we backup here.
1319 1407
 	if (!$support_js || isset($_GET['xml']))
@@ -1332,8 +1420,9 @@  discard block
 block discarded – undo
1332 1420
 			backupTable($table_names[$substep]);
1333 1421
 
1334 1422
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1335
-			if (isset($_GET['xml']))
1336
-				return upgradeExit();
1423
+			if (isset($_GET['xml'])) {
1424
+							return upgradeExit();
1425
+			}
1337 1426
 		}
1338 1427
 
1339 1428
 		if ($command_line)
@@ -1366,9 +1455,10 @@  discard block
 block discarded – undo
1366 1455
 
1367 1456
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1368 1457
 
1369
-	if ($command_line)
1370
-		echo ' done.';
1371
-}
1458
+	if ($command_line) {
1459
+			echo ' done.';
1460
+	}
1461
+	}
1372 1462
 
1373 1463
 // Step 2: Everything.
1374 1464
 function DatabaseChanges()
@@ -1377,8 +1467,9 @@  discard block
 block discarded – undo
1377 1467
 	global $upcontext, $support_js, $db_type;
1378 1468
 
1379 1469
 	// Have we just completed this?
1380
-	if (!empty($_POST['database_done']))
1381
-		return true;
1470
+	if (!empty($_POST['database_done'])) {
1471
+			return true;
1472
+	}
1382 1473
 
1383 1474
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1384 1475
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1393,15 +1484,16 @@  discard block
 block discarded – undo
1393 1484
 	);
1394 1485
 
1395 1486
 	// How many files are there in total?
1396
-	if (isset($_GET['filecount']))
1397
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1398
-	else
1487
+	if (isset($_GET['filecount'])) {
1488
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1489
+	} else
1399 1490
 	{
1400 1491
 		$upcontext['file_count'] = 0;
1401 1492
 		foreach ($files as $file)
1402 1493
 		{
1403
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1404
-				$upcontext['file_count']++;
1494
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1495
+							$upcontext['file_count']++;
1496
+			}
1405 1497
 		}
1406 1498
 	}
1407 1499
 
@@ -1411,9 +1503,9 @@  discard block
 block discarded – undo
1411 1503
 	$upcontext['cur_file_num'] = 0;
1412 1504
 	foreach ($files as $file)
1413 1505
 	{
1414
-		if ($did_not_do)
1415
-			$did_not_do--;
1416
-		else
1506
+		if ($did_not_do) {
1507
+					$did_not_do--;
1508
+		} else
1417 1509
 		{
1418 1510
 			$upcontext['cur_file_num']++;
1419 1511
 			$upcontext['cur_file_name'] = $file[0];
@@ -1440,12 +1532,13 @@  discard block
 block discarded – undo
1440 1532
 					// Flag to move on to the next.
1441 1533
 					$upcontext['completed_step'] = true;
1442 1534
 					// Did we complete the whole file?
1443
-					if ($nextFile)
1444
-						$upcontext['current_debug_item_num'] = -1;
1535
+					if ($nextFile) {
1536
+											$upcontext['current_debug_item_num'] = -1;
1537
+					}
1445 1538
 					return upgradeExit();
1539
+				} elseif ($support_js) {
1540
+									break;
1446 1541
 				}
1447
-				elseif ($support_js)
1448
-					break;
1449 1542
 			}
1450 1543
 			// Set the progress bar to be right as if we had - even if we hadn't...
1451 1544
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1471,8 +1564,9 @@  discard block
 block discarded – undo
1471 1564
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt, $settings;
1472 1565
 
1473 1566
 	// Now it's nice to have some of the basic SMF source files.
1474
-	if (!isset($_GET['ssi']) && !$command_line)
1475
-		redirectLocation('&ssi=1');
1567
+	if (!isset($_GET['ssi']) && !$command_line) {
1568
+			redirectLocation('&ssi=1');
1569
+	}
1476 1570
 
1477 1571
 	$upcontext['sub_template'] = 'upgrade_complete';
1478 1572
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1488,14 +1582,16 @@  discard block
 block discarded – undo
1488 1582
 	// Are we in maintenance mode?
1489 1583
 	if (isset($upcontext['user']['main']))
1490 1584
 	{
1491
-		if ($command_line)
1492
-			echo ' * ';
1585
+		if ($command_line) {
1586
+					echo ' * ';
1587
+		}
1493 1588
 		$upcontext['removed_maintenance'] = true;
1494 1589
 		$changes['maintenance'] = $upcontext['user']['main'];
1495 1590
 	}
1496 1591
 	// Otherwise if somehow we are in 2 let's go to 1.
1497
-	elseif (!empty($maintenance) && $maintenance == 2)
1498
-		$changes['maintenance'] = 1;
1592
+	elseif (!empty($maintenance) && $maintenance == 2) {
1593
+			$changes['maintenance'] = 1;
1594
+	}
1499 1595
 
1500 1596
 	// Wipe this out...
1501 1597
 	$upcontext['user'] = array();
@@ -1510,21 +1606,23 @@  discard block
 block discarded – undo
1510 1606
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1511 1607
 
1512 1608
 	// Now is the perfect time to fetch the SM files.
1513
-	if ($command_line)
1514
-		cli_scheduled_fetchSMfiles();
1515
-	else
1609
+	if ($command_line) {
1610
+			cli_scheduled_fetchSMfiles();
1611
+	} else
1516 1612
 	{
1517 1613
 		require_once($sourcedir . '/ScheduledTasks.php');
1518 1614
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
1519 1615
 		scheduled_fetchSMfiles(); // Now go get those files!
1520 1616
 		// This is needed in case someone invokes the upgrader using https when upgrading an http forum
1521
-		if (httpsOn())
1522
-			$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
1617
+		if (httpsOn()) {
1618
+					$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
1619
+		}
1523 1620
 	}
1524 1621
 
1525 1622
 	// Log what we've done.
1526
-	if (empty($user_info['id']))
1527
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1623
+	if (empty($user_info['id'])) {
1624
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1625
+	}
1528 1626
 
1529 1627
 	// Log the action manually, so CLI still works.
1530 1628
 	$smcFunc['db_insert']('',
@@ -1543,8 +1641,9 @@  discard block
 block discarded – undo
1543 1641
 
1544 1642
 	// Save the current database version.
1545 1643
 	$server_version = $smcFunc['db_server_info']();
1546
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1547
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1644
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1645
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1646
+	}
1548 1647
 
1549 1648
 	if ($command_line)
1550 1649
 	{
@@ -1556,8 +1655,9 @@  discard block
 block discarded – undo
1556 1655
 
1557 1656
 	// Make sure it says we're done.
1558 1657
 	$upcontext['overall_percent'] = 100;
1559
-	if (isset($upcontext['step_progress']))
1560
-		unset($upcontext['step_progress']);
1658
+	if (isset($upcontext['step_progress'])) {
1659
+			unset($upcontext['step_progress']);
1660
+	}
1561 1661
 
1562 1662
 	$_GET['substep'] = 0;
1563 1663
 	return false;
@@ -1568,8 +1668,9 @@  discard block
 block discarded – undo
1568 1668
 {
1569 1669
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1570 1670
 
1571
-	if (empty($modSettings['time_format']))
1572
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1671
+	if (empty($modSettings['time_format'])) {
1672
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1673
+	}
1573 1674
 
1574 1675
 	// What files do we want to get
1575 1676
 	$request = $smcFunc['db_query']('', '
@@ -1603,8 +1704,9 @@  discard block
 block discarded – undo
1603 1704
 		$file_data = fetch_web_data($url);
1604 1705
 
1605 1706
 		// If we got an error - give up - the site might be down.
1606
-		if ($file_data === false)
1607
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1707
+		if ($file_data === false) {
1708
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1709
+		}
1608 1710
 
1609 1711
 		// Save the file to the database.
1610 1712
 		$smcFunc['db_query']('substring', '
@@ -1646,8 +1748,9 @@  discard block
 block discarded – undo
1646 1748
 	$themeData = array();
1647 1749
 	foreach ($values as $variable => $value)
1648 1750
 	{
1649
-		if (!isset($value) || $value === null)
1650
-			$value = 0;
1751
+		if (!isset($value) || $value === null) {
1752
+					$value = 0;
1753
+		}
1651 1754
 
1652 1755
 		$themeData[] = array(0, 1, $variable, $value);
1653 1756
 	}
@@ -1676,8 +1779,9 @@  discard block
 block discarded – undo
1676 1779
 
1677 1780
 	foreach ($values as $variable => $value)
1678 1781
 	{
1679
-		if (empty($modSettings[$value[0]]))
1680
-			continue;
1782
+		if (empty($modSettings[$value[0]])) {
1783
+					continue;
1784
+		}
1681 1785
 
1682 1786
 		$smcFunc['db_query']('', '
1683 1787
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1763,19 +1867,21 @@  discard block
 block discarded – undo
1763 1867
 	set_error_handler(
1764 1868
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1765 1869
 		{
1766
-			if ($support_js)
1767
-				return true;
1768
-			else
1769
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1870
+			if ($support_js) {
1871
+							return true;
1872
+			} else {
1873
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1874
+			}
1770 1875
 		}
1771 1876
 	);
1772 1877
 
1773 1878
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1774 1879
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1775
-	if ($db_type == 'mysql')
1776
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1777
-	else
1778
-		$db_collation = '';
1880
+	if ($db_type == 'mysql') {
1881
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1882
+	} else {
1883
+			$db_collation = '';
1884
+	}
1779 1885
 
1780 1886
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1781 1887
 
@@ -1787,8 +1893,9 @@  discard block
 block discarded – undo
1787 1893
 	$last_step = '';
1788 1894
 
1789 1895
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1790
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1791
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1896
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1897
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1898
+	}
1792 1899
 
1793 1900
 	// Count the total number of steps within this file - for progress.
1794 1901
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1808,15 +1915,18 @@  discard block
 block discarded – undo
1808 1915
 		$do_current = $substep >= $_GET['substep'];
1809 1916
 
1810 1917
 		// Get rid of any comments in the beginning of the line...
1811
-		if (substr(trim($line), 0, 2) === '/*')
1812
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1918
+		if (substr(trim($line), 0, 2) === '/*') {
1919
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1920
+		}
1813 1921
 
1814 1922
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1815
-		if ($is_debug && !$support_js && $command_line)
1816
-			flush();
1923
+		if ($is_debug && !$support_js && $command_line) {
1924
+					flush();
1925
+		}
1817 1926
 
1818
-		if (trim($line) === '')
1819
-			continue;
1927
+		if (trim($line) === '') {
1928
+					continue;
1929
+		}
1820 1930
 
1821 1931
 		if (trim(substr($line, 0, 3)) === '---')
1822 1932
 		{
@@ -1826,8 +1936,9 @@  discard block
 block discarded – undo
1826 1936
 			if (trim($current_data) != '' && $type !== '}')
1827 1937
 			{
1828 1938
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1829
-				if ($command_line)
1830
-					echo $upcontext['error_message'];
1939
+				if ($command_line) {
1940
+									echo $upcontext['error_message'];
1941
+				}
1831 1942
 			}
1832 1943
 
1833 1944
 			if ($type == ' ')
@@ -1845,17 +1956,18 @@  discard block
 block discarded – undo
1845 1956
 				if ($do_current)
1846 1957
 				{
1847 1958
 					$upcontext['actioned_items'][] = $last_step;
1848
-					if ($command_line)
1849
-						echo ' * ';
1959
+					if ($command_line) {
1960
+											echo ' * ';
1961
+					}
1850 1962
 				}
1851
-			}
1852
-			elseif ($type == '#')
1963
+			} elseif ($type == '#')
1853 1964
 			{
1854 1965
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1855 1966
 
1856 1967
 				$upcontext['current_debug_item_num']++;
1857
-				if (trim($line) != '---#')
1858
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1968
+				if (trim($line) != '---#') {
1969
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1970
+				}
1859 1971
 
1860 1972
 				// Have we already done something?
1861 1973
 				if (isset($_GET['xml']) && $done_something)
@@ -1866,34 +1978,36 @@  discard block
 block discarded – undo
1866 1978
 
1867 1979
 				if ($do_current)
1868 1980
 				{
1869
-					if (trim($line) == '---#' && $command_line)
1870
-						echo ' done.', $endl;
1871
-					elseif ($command_line)
1872
-						echo ' +++ ', rtrim(substr($line, 4));
1873
-					elseif (trim($line) != '---#')
1981
+					if (trim($line) == '---#' && $command_line) {
1982
+											echo ' done.', $endl;
1983
+					} elseif ($command_line) {
1984
+											echo ' +++ ', rtrim(substr($line, 4));
1985
+					} elseif (trim($line) != '---#')
1874 1986
 					{
1875
-						if ($is_debug)
1876
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1987
+						if ($is_debug) {
1988
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1989
+						}
1877 1990
 					}
1878 1991
 				}
1879 1992
 
1880 1993
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1881 1994
 				{
1882
-					if ($command_line)
1883
-						echo ' * ';
1884
-					else
1885
-						$upcontext['actioned_items'][] = $last_step;
1995
+					if ($command_line) {
1996
+											echo ' * ';
1997
+					} else {
1998
+											$upcontext['actioned_items'][] = $last_step;
1999
+					}
1886 2000
 				}
1887 2001
 
1888 2002
 				// Small step - only if we're actually doing stuff.
1889
-				if ($do_current)
1890
-					nextSubstep(++$substep);
1891
-				else
1892
-					$substep++;
1893
-			}
1894
-			elseif ($type == '{')
1895
-				$current_type = 'code';
1896
-			elseif ($type == '}')
2003
+				if ($do_current) {
2004
+									nextSubstep(++$substep);
2005
+				} else {
2006
+									$substep++;
2007
+				}
2008
+			} elseif ($type == '{') {
2009
+							$current_type = 'code';
2010
+			} elseif ($type == '}')
1897 2011
 			{
1898 2012
 				$current_type = 'sql';
1899 2013
 
@@ -1906,8 +2020,9 @@  discard block
 block discarded – undo
1906 2020
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1907 2021
 				{
1908 2022
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1909
-					if ($command_line)
1910
-						echo $upcontext['error_message'];
2023
+					if ($command_line) {
2024
+											echo $upcontext['error_message'];
2025
+					}
1911 2026
 				}
1912 2027
 
1913 2028
 				// Done with code!
@@ -1995,8 +2110,9 @@  discard block
 block discarded – undo
1995 2110
 	$db_unbuffered = false;
1996 2111
 
1997 2112
 	// Failure?!
1998
-	if ($result !== false)
1999
-		return $result;
2113
+	if ($result !== false) {
2114
+			return $result;
2115
+	}
2000 2116
 
2001 2117
 	$db_error_message = $smcFunc['db_error']($db_connection);
2002 2118
 	// If MySQL we do something more clever.
@@ -2024,54 +2140,61 @@  discard block
 block discarded – undo
2024 2140
 			{
2025 2141
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2026 2142
 				$result = mysqli_query($db_connection, $string);
2027
-				if ($result !== false)
2028
-					return $result;
2143
+				if ($result !== false) {
2144
+									return $result;
2145
+				}
2029 2146
 			}
2030
-		}
2031
-		elseif ($mysqli_errno == 2013)
2147
+		} elseif ($mysqli_errno == 2013)
2032 2148
 		{
2033 2149
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2034 2150
 			mysqli_select_db($db_connection, $db_name);
2035 2151
 			if ($db_connection)
2036 2152
 			{
2037 2153
 				$result = mysqli_query($db_connection, $string);
2038
-				if ($result !== false)
2039
-					return $result;
2154
+				if ($result !== false) {
2155
+									return $result;
2156
+				}
2040 2157
 			}
2041 2158
 		}
2042 2159
 		// Duplicate column name... should be okay ;).
2043
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2044
-			return false;
2160
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2161
+					return false;
2162
+		}
2045 2163
 		// Duplicate insert... make sure it's the proper type of query ;).
2046
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2047
-			return false;
2164
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2165
+					return false;
2166
+		}
2048 2167
 		// Creating an index on a non-existent column.
2049
-		elseif ($mysqli_errno == 1072)
2050
-			return false;
2051
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2052
-			return false;
2168
+		elseif ($mysqli_errno == 1072) {
2169
+					return false;
2170
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2171
+					return false;
2172
+		}
2053 2173
 	}
2054 2174
 	// If a table already exists don't go potty.
2055 2175
 	else
2056 2176
 	{
2057 2177
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2058 2178
 		{
2059
-			if (strpos($db_error_message, 'exist') !== false)
2060
-				return true;
2061
-		}
2062
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2179
+			if (strpos($db_error_message, 'exist') !== false) {
2180
+							return true;
2181
+			}
2182
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2063 2183
 		{
2064
-			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error)
2065
-				return true;
2184
+			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) {
2185
+							return true;
2186
+			}
2066 2187
 		}
2067 2188
 	}
2068 2189
 
2069 2190
 	// Get the query string so we pass everything.
2070 2191
 	$query_string = '';
2071
-	foreach ($_GET as $k => $v)
2072
-		$query_string .= ';' . $k . '=' . $v;
2073
-	if (strlen($query_string) != 0)
2074
-		$query_string = '?' . substr($query_string, 1);
2192
+	foreach ($_GET as $k => $v) {
2193
+			$query_string .= ';' . $k . '=' . $v;
2194
+	}
2195
+	if (strlen($query_string) != 0) {
2196
+			$query_string = '?' . substr($query_string, 1);
2197
+	}
2075 2198
 
2076 2199
 	if ($command_line)
2077 2200
 	{
@@ -2126,16 +2249,18 @@  discard block
 block discarded – undo
2126 2249
 			{
2127 2250
 				$found |= 1;
2128 2251
 				// Do some checks on the data if we have it set.
2129
-				if (isset($change['col_type']))
2130
-					$found &= $change['col_type'] === $column['type'];
2131
-				if (isset($change['null_allowed']))
2132
-					$found &= $column['null'] == $change['null_allowed'];
2133
-				if (isset($change['default']))
2134
-					$found &= $change['default'] === $column['default'];
2252
+				if (isset($change['col_type'])) {
2253
+									$found &= $change['col_type'] === $column['type'];
2254
+				}
2255
+				if (isset($change['null_allowed'])) {
2256
+									$found &= $column['null'] == $change['null_allowed'];
2257
+				}
2258
+				if (isset($change['default'])) {
2259
+									$found &= $change['default'] === $column['default'];
2260
+				}
2135 2261
 			}
2136 2262
 		}
2137
-	}
2138
-	elseif ($change['type'] === 'index')
2263
+	} elseif ($change['type'] === 'index')
2139 2264
 	{
2140 2265
 		$request = upgrade_query('
2141 2266
 			SHOW INDEX
@@ -2144,9 +2269,10 @@  discard block
 block discarded – undo
2144 2269
 		{
2145 2270
 			$cur_index = array();
2146 2271
 
2147
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2148
-				if ($row['Key_name'] === $change['name'])
2272
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2273
+							if ($row['Key_name'] === $change['name'])
2149 2274
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2275
+			}
2150 2276
 
2151 2277
 			ksort($cur_index, SORT_NUMERIC);
2152 2278
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2156,14 +2282,17 @@  discard block
 block discarded – undo
2156 2282
 	}
2157 2283
 
2158 2284
 	// If we're trying to add and it's added, we're done.
2159
-	if ($found && in_array($change['method'], array('add', 'change')))
2160
-		return true;
2285
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2286
+			return true;
2287
+	}
2161 2288
 	// Otherwise if we're removing and it wasn't found we're also done.
2162
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2163
-		return true;
2289
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2290
+			return true;
2291
+	}
2164 2292
 	// Otherwise is it just a test?
2165
-	elseif ($is_test)
2166
-		return false;
2293
+	elseif ($is_test) {
2294
+			return false;
2295
+	}
2167 2296
 
2168 2297
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2169 2298
 	$running = false;
@@ -2174,8 +2303,9 @@  discard block
 block discarded – undo
2174 2303
 			SHOW FULL PROCESSLIST');
2175 2304
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2176 2305
 		{
2177
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2178
-				$found = true;
2306
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2307
+							$found = true;
2308
+			}
2179 2309
 		}
2180 2310
 
2181 2311
 		// Can't find it? Then we need to run it fools!
@@ -2187,8 +2317,9 @@  discard block
 block discarded – undo
2187 2317
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2188 2318
 				' . $change['text'], true) !== false;
2189 2319
 
2190
-			if (!$success)
2191
-				return false;
2320
+			if (!$success) {
2321
+							return false;
2322
+			}
2192 2323
 
2193 2324
 			// Return
2194 2325
 			$running = true;
@@ -2230,8 +2361,9 @@  discard block
 block discarded – undo
2230 2361
 			'db_error_skip' => true,
2231 2362
 		)
2232 2363
 	);
2233
-	if ($smcFunc['db_num_rows']($request) === 0)
2234
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2364
+	if ($smcFunc['db_num_rows']($request) === 0) {
2365
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2366
+	}
2235 2367
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2236 2368
 	$smcFunc['db_free_result']($request);
2237 2369
 
@@ -2253,18 +2385,19 @@  discard block
 block discarded – undo
2253 2385
 			)
2254 2386
 		);
2255 2387
 		// No results? Just forget it all together.
2256
-		if ($smcFunc['db_num_rows']($request) === 0)
2257
-			unset($table_row['Collation']);
2258
-		else
2259
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2388
+		if ($smcFunc['db_num_rows']($request) === 0) {
2389
+					unset($table_row['Collation']);
2390
+		} else {
2391
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2392
+		}
2260 2393
 		$smcFunc['db_free_result']($request);
2261 2394
 	}
2262 2395
 
2263 2396
 	if ($column_fix)
2264 2397
 	{
2265 2398
 		// Make sure there are no NULL's left.
2266
-		if ($null_fix)
2267
-			$smcFunc['db_query']('', '
2399
+		if ($null_fix) {
2400
+					$smcFunc['db_query']('', '
2268 2401
 				UPDATE {db_prefix}' . $change['table'] . '
2269 2402
 				SET ' . $change['column'] . ' = {string:default}
2270 2403
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2273,6 +2406,7 @@  discard block
 block discarded – undo
2273 2406
 					'db_error_skip' => true,
2274 2407
 				)
2275 2408
 			);
2409
+		}
2276 2410
 
2277 2411
 		// Do the actual alteration.
2278 2412
 		$smcFunc['db_query']('', '
@@ -2301,8 +2435,9 @@  discard block
 block discarded – undo
2301 2435
 	}
2302 2436
 
2303 2437
 	// Not a column we need to check on?
2304
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2305
-		return;
2438
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2439
+			return;
2440
+	}
2306 2441
 
2307 2442
 	// Break it up you (six|seven).
2308 2443
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2321,13 +2456,13 @@  discard block
 block discarded – undo
2321 2456
 				'new_name' => $temp[2],
2322 2457
 		));
2323 2458
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2324
-		if ($smcFunc['db_num_rows'] != 1)
2325
-			return;
2459
+		if ($smcFunc['db_num_rows'] != 1) {
2460
+					return;
2461
+		}
2326 2462
 
2327 2463
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2328 2464
 		$smcFunc['db_free_result']($request);
2329
-	}
2330
-	else
2465
+	} else
2331 2466
 	{
2332 2467
 		// Do this the old fashion, sure method way.
2333 2468
 		$request = $smcFunc['db_query']('', '
@@ -2338,21 +2473,24 @@  discard block
 block discarded – undo
2338 2473
 		));
2339 2474
 		// Mayday!
2340 2475
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2341
-		if ($smcFunc['db_num_rows'] == 0)
2342
-			return;
2476
+		if ($smcFunc['db_num_rows'] == 0) {
2477
+					return;
2478
+		}
2343 2479
 
2344 2480
 		// Oh where, oh where has my little field gone. Oh where can it be...
2345
-		while ($row = $smcFunc['db_query']($request))
2346
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2481
+		while ($row = $smcFunc['db_query']($request)) {
2482
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2347 2483
 			{
2348 2484
 				$current_type = $row['Type'];
2485
+		}
2349 2486
 				break;
2350 2487
 			}
2351 2488
 	}
2352 2489
 
2353 2490
 	// If this doesn't match, the column may of been altered for a reason.
2354
-	if (trim($current_type) != trim($temp[3]))
2355
-		$temp[3] = $current_type;
2491
+	if (trim($current_type) != trim($temp[3])) {
2492
+			$temp[3] = $current_type;
2493
+	}
2356 2494
 
2357 2495
 	// Piece this back together.
2358 2496
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2364,8 +2502,9 @@  discard block
 block discarded – undo
2364 2502
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2365 2503
 	global $step_progress, $is_debug, $upcontext;
2366 2504
 
2367
-	if ($_GET['substep'] < $substep)
2368
-		$_GET['substep'] = $substep;
2505
+	if ($_GET['substep'] < $substep) {
2506
+			$_GET['substep'] = $substep;
2507
+	}
2369 2508
 
2370 2509
 	if ($command_line)
2371 2510
 	{
@@ -2378,29 +2517,33 @@  discard block
 block discarded – undo
2378 2517
 	}
2379 2518
 
2380 2519
 	@set_time_limit(300);
2381
-	if (function_exists('apache_reset_timeout'))
2382
-		@apache_reset_timeout();
2520
+	if (function_exists('apache_reset_timeout')) {
2521
+			@apache_reset_timeout();
2522
+	}
2383 2523
 
2384
-	if (time() - $start_time <= $timeLimitThreshold)
2385
-		return;
2524
+	if (time() - $start_time <= $timeLimitThreshold) {
2525
+			return;
2526
+	}
2386 2527
 
2387 2528
 	// Do we have some custom step progress stuff?
2388 2529
 	if (!empty($step_progress))
2389 2530
 	{
2390 2531
 		$upcontext['substep_progress'] = 0;
2391 2532
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2392
-		if ($step_progress['current'] > $step_progress['total'])
2393
-			$upcontext['substep_progress'] = 99.9;
2394
-		else
2395
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2533
+		if ($step_progress['current'] > $step_progress['total']) {
2534
+					$upcontext['substep_progress'] = 99.9;
2535
+		} else {
2536
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2537
+		}
2396 2538
 
2397 2539
 		// Make it nicely rounded.
2398 2540
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2399 2541
 	}
2400 2542
 
2401 2543
 	// If this is XML we just exit right away!
2402
-	if (isset($_GET['xml']))
2403
-		return upgradeExit();
2544
+	if (isset($_GET['xml'])) {
2545
+			return upgradeExit();
2546
+	}
2404 2547
 
2405 2548
 	// We're going to pause after this!
2406 2549
 	$upcontext['pause'] = true;
@@ -2408,13 +2551,15 @@  discard block
 block discarded – undo
2408 2551
 	$upcontext['query_string'] = '';
2409 2552
 	foreach ($_GET as $k => $v)
2410 2553
 	{
2411
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2412
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2554
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2555
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2556
+		}
2413 2557
 	}
2414 2558
 
2415 2559
 	// Custom warning?
2416
-	if (!empty($custom_warning))
2417
-		$upcontext['custom_warning'] = $custom_warning;
2560
+	if (!empty($custom_warning)) {
2561
+			$upcontext['custom_warning'] = $custom_warning;
2562
+	}
2418 2563
 
2419 2564
 	upgradeExit();
2420 2565
 }
@@ -2429,25 +2574,26 @@  discard block
 block discarded – undo
2429 2574
 	ob_implicit_flush(true);
2430 2575
 	@set_time_limit(600);
2431 2576
 
2432
-	if (!isset($_SERVER['argv']))
2433
-		$_SERVER['argv'] = array();
2577
+	if (!isset($_SERVER['argv'])) {
2578
+			$_SERVER['argv'] = array();
2579
+	}
2434 2580
 	$_GET['maint'] = 1;
2435 2581
 
2436 2582
 	foreach ($_SERVER['argv'] as $i => $arg)
2437 2583
 	{
2438
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2439
-			$_GET['lang'] = $match[1];
2440
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2441
-			continue;
2442
-		elseif ($arg == '--no-maintenance')
2443
-			$_GET['maint'] = 0;
2444
-		elseif ($arg == '--debug')
2445
-			$is_debug = true;
2446
-		elseif ($arg == '--backup')
2447
-			$_POST['backup'] = 1;
2448
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2449
-			$_GET['conv'] = 1;
2450
-		elseif ($i != 0)
2584
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2585
+					$_GET['lang'] = $match[1];
2586
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2587
+					continue;
2588
+		} elseif ($arg == '--no-maintenance') {
2589
+					$_GET['maint'] = 0;
2590
+		} elseif ($arg == '--debug') {
2591
+					$is_debug = true;
2592
+		} elseif ($arg == '--backup') {
2593
+					$_POST['backup'] = 1;
2594
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2595
+					$_GET['conv'] = 1;
2596
+		} elseif ($i != 0)
2451 2597
 		{
2452 2598
 			echo 'SMF Command-line Upgrader
2453 2599
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2461,10 +2607,12 @@  discard block
 block discarded – undo
2461 2607
 		}
2462 2608
 	}
2463 2609
 
2464
-	if (!php_version_check())
2465
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2466
-	if (!db_version_check())
2467
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2610
+	if (!php_version_check()) {
2611
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2612
+	}
2613
+	if (!db_version_check()) {
2614
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2615
+	}
2468 2616
 
2469 2617
 	// Do some checks to make sure they have proper privileges
2470 2618
 	db_extend('packages');
@@ -2479,34 +2627,39 @@  discard block
 block discarded – undo
2479 2627
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2480 2628
 
2481 2629
 	// Sorry... we need CREATE, ALTER and DROP
2482
-	if (!$create || !$alter || !$drop)
2483
-		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);
2630
+	if (!$create || !$alter || !$drop) {
2631
+			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);
2632
+	}
2484 2633
 
2485 2634
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2486 2635
 		&& @file_exists($sourcedir . '/QueryString.php')
2487 2636
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2488
-	if (!$check && !isset($modSettings['smfVersion']))
2489
-		print_error('Error: Some files are missing or out-of-date.', true);
2637
+	if (!$check && !isset($modSettings['smfVersion'])) {
2638
+			print_error('Error: Some files are missing or out-of-date.', true);
2639
+	}
2490 2640
 
2491 2641
 	// Do a quick version spot check.
2492 2642
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2493 2643
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2494
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2495
-		print_error('Error: Some files have not yet been updated properly.');
2644
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2645
+			print_error('Error: Some files have not yet been updated properly.');
2646
+	}
2496 2647
 
2497 2648
 	// Make sure Settings.php is writable.
2498 2649
 	quickFileWritable($boarddir . '/Settings.php');
2499
-	if (!is_writable($boarddir . '/Settings.php'))
2500
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2650
+	if (!is_writable($boarddir . '/Settings.php')) {
2651
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2652
+	}
2501 2653
 
2502 2654
 	// Make sure Settings_bak.php is writable.
2503 2655
 	quickFileWritable($boarddir . '/Settings_bak.php');
2504
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2505
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2656
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2657
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2658
+	}
2506 2659
 
2507
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2508
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2509
-	elseif (isset($modSettings['agreement']))
2660
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2661
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2662
+	} elseif (isset($modSettings['agreement']))
2510 2663
 	{
2511 2664
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2512 2665
 		fwrite($fp, $modSettings['agreement']);
@@ -2516,36 +2669,42 @@  discard block
 block discarded – undo
2516 2669
 	// Make sure Themes is writable.
2517 2670
 	quickFileWritable($modSettings['theme_dir']);
2518 2671
 
2519
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2520
-		print_error('Error: Unable to obtain write access to "Themes".');
2672
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2673
+			print_error('Error: Unable to obtain write access to "Themes".');
2674
+	}
2521 2675
 
2522 2676
 	// Make sure cache directory exists and is writable!
2523 2677
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2524
-	if (!file_exists($cachedir_temp))
2525
-		@mkdir($cachedir_temp);
2678
+	if (!file_exists($cachedir_temp)) {
2679
+			@mkdir($cachedir_temp);
2680
+	}
2526 2681
 
2527 2682
 	// Make sure the cache temp dir is writable.
2528 2683
 	quickFileWritable($cachedir_temp);
2529 2684
 
2530
-	if (!is_writable($cachedir_temp))
2531
-		print_error('Error: Unable to obtain write access to "cache".', true);
2685
+	if (!is_writable($cachedir_temp)) {
2686
+			print_error('Error: Unable to obtain write access to "cache".', true);
2687
+	}
2532 2688
 
2533 2689
 	// Make sure db_last_error.php is writable.
2534 2690
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2535
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2536
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2691
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2692
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2693
+	}
2537 2694
 
2538
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2539
-		print_error('Error: Unable to find language files!', true);
2540
-	else
2695
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2696
+			print_error('Error: Unable to find language files!', true);
2697
+	} else
2541 2698
 	{
2542 2699
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2543 2700
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2544 2701
 
2545
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2546
-			print_error('Error: Language files out of date.', true);
2547
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2548
-			print_error('Error: Install language is missing for selected language.', true);
2702
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2703
+					print_error('Error: Language files out of date.', true);
2704
+		}
2705
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2706
+					print_error('Error: Install language is missing for selected language.', true);
2707
+		}
2549 2708
 
2550 2709
 		// Otherwise include it!
2551 2710
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2565,8 +2724,9 @@  discard block
 block discarded – undo
2565 2724
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2566 2725
 
2567 2726
 	// Done it already?
2568
-	if (!empty($_POST['utf8_done']))
2569
-		return true;
2727
+	if (!empty($_POST['utf8_done'])) {
2728
+			return true;
2729
+	}
2570 2730
 
2571 2731
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2572 2732
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2579,8 +2739,7 @@  discard block
 block discarded – undo
2579 2739
 		);
2580 2740
 
2581 2741
 		return true;
2582
-	}
2583
-	else
2742
+	} else
2584 2743
 	{
2585 2744
 		$upcontext['page_title'] = $txt['converting_utf8'];
2586 2745
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2624,8 +2783,9 @@  discard block
 block discarded – undo
2624 2783
 			)
2625 2784
 		);
2626 2785
 		$db_charsets = array();
2627
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2628
-			$db_charsets[] = $row['Charset'];
2786
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2787
+					$db_charsets[] = $row['Charset'];
2788
+		}
2629 2789
 
2630 2790
 		$smcFunc['db_free_result']($request);
2631 2791
 
@@ -2661,13 +2821,15 @@  discard block
 block discarded – undo
2661 2821
 		// If there's a fulltext index, we need to drop it first...
2662 2822
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2663 2823
 		{
2664
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2665
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2824
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2825
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2666 2826
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2827
+			}
2667 2828
 			$smcFunc['db_free_result']($request);
2668 2829
 
2669
-			if (isset($upcontext['fulltext_index']))
2670
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2830
+			if (isset($upcontext['fulltext_index'])) {
2831
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2832
+			}
2671 2833
 		}
2672 2834
 
2673 2835
 		// Drop it and make a note...
@@ -2857,8 +3019,9 @@  discard block
 block discarded – undo
2857 3019
 			$replace = '%field%';
2858 3020
 
2859 3021
 			// Build a huge REPLACE statement...
2860
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2861
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3022
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3023
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3024
+			}
2862 3025
 		}
2863 3026
 
2864 3027
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2868,9 +3031,10 @@  discard block
 block discarded – undo
2868 3031
 		$upcontext['table_count'] = count($queryTables);
2869 3032
 
2870 3033
 		// What ones have we already done?
2871
-		foreach ($queryTables as $id => $table)
2872
-			if ($id < $_GET['substep'])
3034
+		foreach ($queryTables as $id => $table) {
3035
+					if ($id < $_GET['substep'])
2873 3036
 				$upcontext['previous_tables'][] = $table;
3037
+		}
2874 3038
 
2875 3039
 		$upcontext['cur_table_num'] = $_GET['substep'];
2876 3040
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2907,8 +3071,9 @@  discard block
 block discarded – undo
2907 3071
 			nextSubstep($substep);
2908 3072
 
2909 3073
 			// Just to make sure it doesn't time out.
2910
-			if (function_exists('apache_reset_timeout'))
2911
-				@apache_reset_timeout();
3074
+			if (function_exists('apache_reset_timeout')) {
3075
+							@apache_reset_timeout();
3076
+			}
2912 3077
 
2913 3078
 			$table_charsets = array();
2914 3079
 
@@ -2931,8 +3096,9 @@  discard block
 block discarded – undo
2931 3096
 
2932 3097
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2933 3098
 						if ($charset != 'utf8') {
2934
-							if (!isset($table_charsets[$charset]))
2935
-								$table_charsets[$charset] = array();
3099
+							if (!isset($table_charsets[$charset])) {
3100
+															$table_charsets[$charset] = array();
3101
+							}
2936 3102
 
2937 3103
 							$table_charsets[$charset][] = $column_info;
2938 3104
 						}
@@ -2973,10 +3139,11 @@  discard block
 block discarded – undo
2973 3139
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2974 3140
 				{
2975 3141
 					$update = '';
2976
-					foreach ($table_charsets as $charset => $columns)
2977
-						foreach ($columns as $column)
3142
+					foreach ($table_charsets as $charset => $columns) {
3143
+											foreach ($columns as $column)
2978 3144
 							$update .= '
2979 3145
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3146
+					}
2980 3147
 
2981 3148
 					$smcFunc['db_query']('', '
2982 3149
 						UPDATE {raw:table_name}
@@ -3001,8 +3168,9 @@  discard block
 block discarded – undo
3001 3168
 			// Now do the actual conversion (if still needed).
3002 3169
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
3003 3170
 			{
3004
-				if ($command_line)
3005
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3171
+				if ($command_line) {
3172
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3173
+				}
3006 3174
 
3007 3175
 				$smcFunc['db_query']('', '
3008 3176
 					ALTER TABLE {raw:table_name}
@@ -3012,12 +3180,14 @@  discard block
 block discarded – undo
3012 3180
 					)
3013 3181
 				);
3014 3182
 
3015
-				if ($command_line)
3016
-					echo " done.\n";
3183
+				if ($command_line) {
3184
+									echo " done.\n";
3185
+				}
3017 3186
 			}
3018 3187
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3019
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
3020
-				return upgradeExit();
3188
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3189
+							return upgradeExit();
3190
+			}
3021 3191
 		}
3022 3192
 
3023 3193
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3046,8 +3216,8 @@  discard block
 block discarded – undo
3046 3216
 		);
3047 3217
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3048 3218
 		{
3049
-			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)
3050
-				$smcFunc['db_query']('', '
3219
+			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) {
3220
+							$smcFunc['db_query']('', '
3051 3221
 					UPDATE {db_prefix}log_actions
3052 3222
 					SET extra = {string:extra}
3053 3223
 					WHERE id_action = {int:current_action}',
@@ -3056,6 +3226,7 @@  discard block
 block discarded – undo
3056 3226
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3057 3227
 					)
3058 3228
 				);
3229
+			}
3059 3230
 		}
3060 3231
 		$smcFunc['db_free_result']($request);
3061 3232
 
@@ -3077,15 +3248,17 @@  discard block
 block discarded – undo
3077 3248
 	// First thing's first - did we already do this?
3078 3249
 	if (!empty($modSettings['json_done']))
3079 3250
 	{
3080
-		if ($command_line)
3081
-			return DeleteUpgrade();
3082
-		else
3083
-			return true;
3251
+		if ($command_line) {
3252
+					return DeleteUpgrade();
3253
+		} else {
3254
+					return true;
3255
+		}
3084 3256
 	}
3085 3257
 
3086 3258
 	// Done it already - js wise?
3087
-	if (!empty($_POST['json_done']))
3088
-		return true;
3259
+	if (!empty($_POST['json_done'])) {
3260
+			return true;
3261
+	}
3089 3262
 
3090 3263
 	// List of tables affected by this function
3091 3264
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3117,12 +3290,14 @@  discard block
 block discarded – undo
3117 3290
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3118 3291
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3119 3292
 
3120
-	foreach ($keys as $id => $table)
3121
-		if ($id < $_GET['substep'])
3293
+	foreach ($keys as $id => $table) {
3294
+			if ($id < $_GET['substep'])
3122 3295
 			$upcontext['previous_tables'][] = $table;
3296
+	}
3123 3297
 
3124
-	if ($command_line)
3125
-		echo 'Converting data from serialize() to json_encode().';
3298
+	if ($command_line) {
3299
+			echo 'Converting data from serialize() to json_encode().';
3300
+	}
3126 3301
 
3127 3302
 	if (!$support_js || isset($_GET['xml']))
3128 3303
 	{
@@ -3162,8 +3337,9 @@  discard block
 block discarded – undo
3162 3337
 
3163 3338
 				// Loop through and fix these...
3164 3339
 				$new_settings = array();
3165
-				if ($command_line)
3166
-					echo "\n" . 'Fixing some settings...';
3340
+				if ($command_line) {
3341
+									echo "\n" . 'Fixing some settings...';
3342
+				}
3167 3343
 
3168 3344
 				foreach ($serialized_settings as $var)
3169 3345
 				{
@@ -3171,22 +3347,24 @@  discard block
 block discarded – undo
3171 3347
 					{
3172 3348
 						// Attempt to unserialize the setting
3173 3349
 						$temp = @safe_unserialize($modSettings[$var]);
3174
-						if (!$temp && $command_line)
3175
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3176
-						elseif ($temp !== false)
3177
-							$new_settings[$var] = json_encode($temp);
3350
+						if (!$temp && $command_line) {
3351
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3352
+						} elseif ($temp !== false) {
3353
+													$new_settings[$var] = json_encode($temp);
3354
+						}
3178 3355
 					}
3179 3356
 				}
3180 3357
 
3181 3358
 				// Update everything at once
3182
-				if (!function_exists('cache_put_data'))
3183
-					require_once($sourcedir . '/Load.php');
3359
+				if (!function_exists('cache_put_data')) {
3360
+									require_once($sourcedir . '/Load.php');
3361
+				}
3184 3362
 				updateSettings($new_settings, true);
3185 3363
 
3186
-				if ($command_line)
3187
-					echo ' done.';
3188
-			}
3189
-			elseif ($table == 'themes')
3364
+				if ($command_line) {
3365
+									echo ' done.';
3366
+				}
3367
+			} elseif ($table == 'themes')
3190 3368
 			{
3191 3369
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3192 3370
 				$query = $smcFunc['db_query']('', '
@@ -3205,10 +3383,11 @@  discard block
 block discarded – undo
3205 3383
 
3206 3384
 						if ($command_line)
3207 3385
 						{
3208
-							if ($temp === false)
3209
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3210
-							else
3211
-								echo "\n" . 'Fixing admin preferences...';
3386
+							if ($temp === false) {
3387
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3388
+							} else {
3389
+															echo "\n" . 'Fixing admin preferences...';
3390
+							}
3212 3391
 						}
3213 3392
 
3214 3393
 						if ($temp !== false)
@@ -3230,15 +3409,15 @@  discard block
 block discarded – undo
3230 3409
 								)
3231 3410
 							);
3232 3411
 
3233
-							if ($command_line)
3234
-								echo ' done.';
3412
+							if ($command_line) {
3413
+															echo ' done.';
3414
+							}
3235 3415
 						}
3236 3416
 					}
3237 3417
 
3238 3418
 					$smcFunc['db_free_result']($query);
3239 3419
 				}
3240
-			}
3241
-			else
3420
+			} else
3242 3421
 			{
3243 3422
 				// First item is always the key...
3244 3423
 				$key = $info[0];
@@ -3249,8 +3428,7 @@  discard block
 block discarded – undo
3249 3428
 				{
3250 3429
 					$col_select = $info[1];
3251 3430
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3252
-				}
3253
-				else
3431
+				} else
3254 3432
 				{
3255 3433
 					$col_select = implode(', ', $info);
3256 3434
 				}
@@ -3283,8 +3461,7 @@  discard block
 block discarded – undo
3283 3461
 								if ($temp === false && $command_line)
3284 3462
 								{
3285 3463
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3286
-								}
3287
-								else
3464
+								} else
3288 3465
 								{
3289 3466
 									$row[$col] = json_encode($temp);
3290 3467
 
@@ -3309,16 +3486,18 @@  discard block
 block discarded – undo
3309 3486
 						}
3310 3487
 					}
3311 3488
 
3312
-					if ($command_line)
3313
-						echo ' done.';
3489
+					if ($command_line) {
3490
+											echo ' done.';
3491
+					}
3314 3492
 
3315 3493
 					// Free up some memory...
3316 3494
 					$smcFunc['db_free_result']($query);
3317 3495
 				}
3318 3496
 			}
3319 3497
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3320
-			if (isset($_GET['xml']))
3321
-				return upgradeExit();
3498
+			if (isset($_GET['xml'])) {
3499
+							return upgradeExit();
3500
+			}
3322 3501
 		}
3323 3502
 
3324 3503
 		if ($command_line)
@@ -3333,8 +3512,9 @@  discard block
 block discarded – undo
3333 3512
 
3334 3513
 		$_GET['substep'] = 0;
3335 3514
 		// Make sure we move on!
3336
-		if ($command_line)
3337
-			return DeleteUpgrade();
3515
+		if ($command_line) {
3516
+					return DeleteUpgrade();
3517
+		}
3338 3518
 
3339 3519
 		return true;
3340 3520
 	}
@@ -3391,14 +3571,16 @@  discard block
 block discarded – undo
3391 3571
 	global $upcontext, $txt, $settings;
3392 3572
 
3393 3573
 	// Don't call me twice!
3394
-	if (!empty($upcontext['chmod_called']))
3395
-		return;
3574
+	if (!empty($upcontext['chmod_called'])) {
3575
+			return;
3576
+	}
3396 3577
 
3397 3578
 	$upcontext['chmod_called'] = true;
3398 3579
 
3399 3580
 	// Nothing?
3400
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3401
-		return;
3581
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3582
+			return;
3583
+	}
3402 3584
 
3403 3585
 	// Was it a problem with Windows?
3404 3586
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3430,11 +3612,12 @@  discard block
 block discarded – undo
3430 3612
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3431 3613
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3432 3614
 
3433
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3434
-		echo '
3615
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3616
+			echo '
3435 3617
 					content.write(\'<hr>\n\t\t\t\');
3436 3618
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3437 3619
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3620
+	}
3438 3621
 
3439 3622
 	echo '
3440 3623
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3442,16 +3625,18 @@  discard block
 block discarded – undo
3442 3625
 				}
3443 3626
 			</script>';
3444 3627
 
3445
-	if (!empty($upcontext['chmod']['ftp_error']))
3446
-		echo '
3628
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3629
+			echo '
3447 3630
 			<div class="error_message red">
3448 3631
 				<p>', $txt['upgrade_ftp_error'], '<p>
3449 3632
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3450 3633
 			</div>';
3634
+	}
3451 3635
 
3452
-	if (empty($upcontext['chmod_in_form']))
3453
-		echo '
3636
+	if (empty($upcontext['chmod_in_form'])) {
3637
+			echo '
3454 3638
 			<form action="', $upcontext['form_url'], '" method="post">';
3639
+	}
3455 3640
 
3456 3641
 	echo '
3457 3642
 				<dl class="settings">
@@ -3493,9 +3678,10 @@  discard block
 block discarded – undo
3493 3678
 					<input type="submit" value="', $txt['ftp_connect'], '" class="button">
3494 3679
 				</div>';
3495 3680
 
3496
-	if (empty($upcontext['chmod_in_form']))
3497
-		echo '
3681
+	if (empty($upcontext['chmod_in_form'])) {
3682
+			echo '
3498 3683
 			</form>';
3684
+	}
3499 3685
 
3500 3686
 	echo '
3501 3687
 		</div><!-- .panel -->';
@@ -3559,9 +3745,10 @@  discard block
 block discarded – undo
3559 3745
 					<h2>', $txt['upgrade_progress'], '</h2>
3560 3746
 					<ul>';
3561 3747
 
3562
-	foreach ($upcontext['steps'] as $num => $step)
3563
-		echo '
3748
+	foreach ($upcontext['steps'] as $num => $step) {
3749
+			echo '
3564 3750
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3751
+	}
3565 3752
 
3566 3753
 	echo '
3567 3754
 					</ul>
@@ -3574,13 +3761,14 @@  discard block
 block discarded – undo
3574 3761
 						<span id="overall_text">', $upcontext['overall_percent'], '%</span>
3575 3762
 					</div>';
3576 3763
 
3577
-	if (isset($upcontext['step_progress']))
3578
-		echo '
3764
+	if (isset($upcontext['step_progress'])) {
3765
+			echo '
3579 3766
 					<div id="progress_bar_step" class="progress_bar progress_yellow">
3580 3767
 						<h3>', $txt['upgrade_step_progress'], '</h3>
3581 3768
 						<div id="step_progress" class="bar" style="width: ', $upcontext['step_progress'], '%;"></div>
3582 3769
 						<span id="step_text">', $upcontext['step_progress'], '%</span>
3583 3770
 					</div>';
3771
+	}
3584 3772
 
3585 3773
 	echo '
3586 3774
 					<h3>', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', '</h3>
@@ -3611,31 +3799,35 @@  discard block
 block discarded – undo
3611 3799
 {
3612 3800
 	global $upcontext, $txt;
3613 3801
 
3614
-	if (!empty($upcontext['pause']))
3615
-		echo '
3802
+	if (!empty($upcontext['pause'])) {
3803
+			echo '
3616 3804
 					<em>', $txt['upgrade_incomplete'], '.</em><br>
3617 3805
 
3618 3806
 					<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3619 3807
 					<h3>
3620 3808
 						', $txt['upgrade_paused_overload'], '
3621 3809
 					</h3>';
3810
+	}
3622 3811
 
3623
-	if (!empty($upcontext['custom_warning']))
3624
-		echo '
3812
+	if (!empty($upcontext['custom_warning'])) {
3813
+			echo '
3625 3814
 					<div class="errorbox">
3626 3815
 						<h3>', $txt['upgrade_note'], '</h3>
3627 3816
 						', $upcontext['custom_warning'], '
3628 3817
 					</div>';
3818
+	}
3629 3819
 
3630 3820
 	echo '
3631 3821
 					<div class="righttext" style="margin: 1ex;">';
3632 3822
 
3633
-	if (!empty($upcontext['continue']))
3634
-		echo '
3823
+	if (!empty($upcontext['continue'])) {
3824
+			echo '
3635 3825
 						<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3636
-	if (!empty($upcontext['skip']))
3637
-		echo '
3826
+	}
3827
+	if (!empty($upcontext['skip'])) {
3828
+			echo '
3638 3829
 						<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3830
+	}
3639 3831
 
3640 3832
 	echo '
3641 3833
 					</div>
@@ -3686,11 +3878,12 @@  discard block
 block discarded – undo
3686 3878
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3687 3879
 	<smf>';
3688 3880
 
3689
-	if (!empty($upcontext['get_data']))
3690
-		foreach ($upcontext['get_data'] as $k => $v)
3881
+	if (!empty($upcontext['get_data'])) {
3882
+			foreach ($upcontext['get_data'] as $k => $v)
3691 3883
 			echo '
3692 3884
 		<get key="', $k, '">', $v, '</get>';
3693
-}
3885
+	}
3886
+	}
3694 3887
 
3695 3888
 function template_xml_below()
3696 3889
 {
@@ -3730,20 +3923,22 @@  discard block
 block discarded – undo
3730 3923
 	template_chmod();
3731 3924
 
3732 3925
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3733
-	if ($upcontext['is_large_forum'])
3734
-		echo '
3926
+	if ($upcontext['is_large_forum']) {
3927
+			echo '
3735 3928
 					<div class="errorbox">
3736 3929
 						<h3>', $txt['upgrade_warning'], '</h3>
3737 3930
 						', $txt['upgrade_warning_lots_data'], '
3738 3931
 					</div>';
3932
+	}
3739 3933
 
3740 3934
 	// A warning message?
3741
-	if (!empty($upcontext['warning']))
3742
-		echo '
3935
+	if (!empty($upcontext['warning'])) {
3936
+			echo '
3743 3937
 					<div class="errorbox">
3744 3938
 						<h3>', $txt['upgrade_warning'], '</h3>
3745 3939
 						', $upcontext['warning'], '
3746 3940
 					</div>';
3941
+	}
3747 3942
 
3748 3943
 	// Paths are incorrect?
3749 3944
 	echo '
@@ -3756,35 +3951,39 @@  discard block
 block discarded – undo
3756 3951
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3757 3952
 	{
3758 3953
 		$ago = time() - $upcontext['started'];
3759
-		if ($ago < 60)
3760
-			$ago = $ago . ' seconds';
3761
-		elseif ($ago < 3600)
3762
-			$ago = (int) ($ago / 60) . ' minutes';
3763
-		else
3764
-			$ago = (int) ($ago / 3600) . ' hours';
3954
+		if ($ago < 60) {
3955
+					$ago = $ago . ' seconds';
3956
+		} elseif ($ago < 3600) {
3957
+					$ago = (int) ($ago / 60) . ' minutes';
3958
+		} else {
3959
+					$ago = (int) ($ago / 3600) . ' hours';
3960
+		}
3765 3961
 
3766 3962
 		$active = time() - $upcontext['updated'];
3767
-		if ($active < 60)
3768
-			$updated = $active . ' seconds';
3769
-		elseif ($active < 3600)
3770
-			$updated = (int) ($active / 60) . ' minutes';
3771
-		else
3772
-			$updated = (int) ($active / 3600) . ' hours';
3963
+		if ($active < 60) {
3964
+					$updated = $active . ' seconds';
3965
+		} elseif ($active < 3600) {
3966
+					$updated = (int) ($active / 60) . ' minutes';
3967
+		} else {
3968
+					$updated = (int) ($active / 3600) . ' hours';
3969
+		}
3773 3970
 
3774 3971
 		echo '
3775 3972
 					<div class="errorbox">
3776 3973
 						<h3>', $txt['upgrade_warning'], '</h3>
3777 3974
 						<p>', sprintf($txt['upgrade_time'], $upcontext['user']['name'], $ago, $updated), '</p>';
3778
-		if ($active < 600)
3779
-			echo '
3975
+		if ($active < 600) {
3976
+					echo '
3780 3977
 						<p>', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '</p>';
3978
+		}
3781 3979
 
3782
-		if ($active > $upcontext['inactive_timeout'])
3783
-			echo '
3980
+		if ($active > $upcontext['inactive_timeout']) {
3981
+					echo '
3784 3982
 						<p>',$txt['upgrade_run'], '</p>';
3785
-		else
3786
-			echo '
3983
+		} else {
3984
+					echo '
3787 3985
 						<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>';
3986
+		}
3788 3987
 
3789 3988
 		echo '
3790 3989
 					</div>';
@@ -3800,9 +3999,10 @@  discard block
 block discarded – undo
3800 3999
 						<dd>
3801 4000
 							<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3802 4001
 
3803
-	if (!empty($upcontext['username_incorrect']))
3804
-		echo '
4002
+	if (!empty($upcontext['username_incorrect'])) {
4003
+			echo '
3805 4004
 							<div class="smalltext red">', $txt['upgrade_wrong_username'], '</div>';
4005
+	}
3806 4006
 
3807 4007
 	echo '
3808 4008
 						</dd>
@@ -3813,9 +4013,10 @@  discard block
 block discarded – undo
3813 4013
 							<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3814 4014
 							<input type="hidden" name="hash_passwrd" value="">';
3815 4015
 
3816
-	if (!empty($upcontext['password_failed']))
3817
-		echo '
4016
+	if (!empty($upcontext['password_failed'])) {
4017
+			echo '
3818 4018
 							<div class="smalltext red">', $txt['upgrade_wrong_password'], '</div>';
4019
+	}
3819 4020
 
3820 4021
 	echo '
3821 4022
 						</dd>';
@@ -3883,12 +4084,13 @@  discard block
 block discarded – undo
3883 4084
 				<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3884 4085
 
3885 4086
 	// Warning message?
3886
-	if (!empty($upcontext['upgrade_options_warning']))
3887
-		echo '
4087
+	if (!empty($upcontext['upgrade_options_warning'])) {
4088
+			echo '
3888 4089
 				<div class="errorbox">
3889 4090
 					<h3>', $txt['upgrade_warning'] ,'</h3>
3890 4091
 					', $upcontext['upgrade_options_warning'], '
3891 4092
 				</div>';
4093
+	}
3892 4094
 
3893 4095
 	echo '
3894 4096
 				<ul class="upgrade_settings">
@@ -3917,12 +4119,13 @@  discard block
 block discarded – undo
3917 4119
 						<label for="empty_error">', $txt['upgrade_empty_errlog'], '</label>
3918 4120
 					</li>';
3919 4121
 
3920
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3921
-		echo '
4122
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4123
+			echo '
3922 4124
 					<li>
3923 4125
 						<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
3924 4126
 						<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3925 4127
 					</li>';
4128
+	}
3926 4129
 
3927 4130
 	echo '
3928 4131
 					<li>
@@ -3956,10 +4159,11 @@  discard block
 block discarded – undo
3956 4159
 					</div>';
3957 4160
 
3958 4161
 	// Dont any tables so far?
3959
-	if (!empty($upcontext['previous_tables']))
3960
-		foreach ($upcontext['previous_tables'] as $table)
4162
+	if (!empty($upcontext['previous_tables'])) {
4163
+			foreach ($upcontext['previous_tables'] as $table)
3961 4164
 			echo '
3962 4165
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4166
+	}
3963 4167
 
3964 4168
 	echo '
3965 4169
 					<h3 id="current_tab">
@@ -3998,12 +4202,13 @@  discard block
 block discarded – undo
3998 4202
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3999 4203
 
4000 4204
 		// If debug flood the screen.
4001
-		if ($is_debug)
4002
-			echo '
4205
+		if ($is_debug) {
4206
+					echo '
4003 4207
 							setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4004 4208
 
4005 4209
 							if (document.getElementById(\'debug_section\').scrollHeight)
4006 4210
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4211
+		}
4007 4212
 
4008 4213
 		echo '
4009 4214
 							// Get the next update...
@@ -4036,8 +4241,9 @@  discard block
 block discarded – undo
4036 4241
 {
4037 4242
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4038 4243
 
4039
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4040
-		$is_debug = true;
4244
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4245
+			$is_debug = true;
4246
+	}
4041 4247
 
4042 4248
 	echo '
4043 4249
 				<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4052,8 +4258,9 @@  discard block
 block discarded – undo
4052 4258
 	{
4053 4259
 		foreach ($upcontext['actioned_items'] as $num => $item)
4054 4260
 		{
4055
-			if ($num != 0)
4056
-				echo ' Successful!';
4261
+			if ($num != 0) {
4262
+							echo ' Successful!';
4263
+			}
4057 4264
 			echo '<br>' . $item;
4058 4265
 		}
4059 4266
 		if (!empty($upcontext['changes_complete']))
@@ -4066,29 +4273,33 @@  discard block
 block discarded – undo
4066 4273
 				$seconds = intval($active % 60);
4067 4274
 
4068 4275
 				$totalTime = '';
4069
-				if ($hours > 0)
4070
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4071
-				if ($minutes > 0)
4072
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4073
-				if ($seconds > 0)
4074
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4276
+				if ($hours > 0) {
4277
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4278
+				}
4279
+				if ($minutes > 0) {
4280
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4281
+				}
4282
+				if ($seconds > 0) {
4283
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4284
+				}
4075 4285
 			}
4076 4286
 
4077
-			if ($is_debug && !empty($totalTime))
4078
-				echo '', sprintf($txt['upgrade_success_time'], $totalTime), '<br>';
4079
-			else
4080
-				echo '', $txt['upgrade_success'], '<br>';
4287
+			if ($is_debug && !empty($totalTime)) {
4288
+							echo '', sprintf($txt['upgrade_success_time'], $totalTime), '<br>';
4289
+			} else {
4290
+							echo '', $txt['upgrade_success'], '<br>';
4291
+			}
4081 4292
 
4082 4293
 			echo '
4083 4294
 					<p id="commess">', $txt['upgrade_db_complete'], '</p>';
4084 4295
 		}
4085
-	}
4086
-	else
4296
+	} else
4087 4297
 	{
4088 4298
 		// Tell them how many files we have in total.
4089
-		if ($upcontext['file_count'] > 1)
4090
-			echo '
4299
+		if ($upcontext['file_count'] > 1) {
4300
+					echo '
4091 4301
 					<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4302
+		}
4092 4303
 
4093 4304
 		echo '
4094 4305
 					<h3 id="info2">
@@ -4106,19 +4317,23 @@  discard block
 block discarded – undo
4106 4317
 				$seconds = intval($active % 60);
4107 4318
 
4108 4319
 				$totalTime = '';
4109
-				if ($hours > 0)
4110
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4111
-				if ($minutes > 0)
4112
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4113
-				if ($seconds > 0)
4114
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4320
+				if ($hours > 0) {
4321
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4322
+				}
4323
+				if ($minutes > 0) {
4324
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4325
+				}
4326
+				if ($seconds > 0) {
4327
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4328
+				}
4115 4329
 			}
4116 4330
 
4117 4331
 			echo '
4118 4332
 					<p id="upgradeCompleted">';
4119 4333
 
4120
-			if (!empty($totalTime))
4121
-				echo '', sprintf($txt['upgrade_completed_time2'], $totalTime), '';
4334
+			if (!empty($totalTime)) {
4335
+							echo '', sprintf($txt['upgrade_completed_time2'], $totalTime), '';
4336
+			}
4122 4337
 
4123 4338
 			echo '
4124 4339
 					</p>
@@ -4155,9 +4370,10 @@  discard block
 block discarded – undo
4155 4370
 						var getData = "";
4156 4371
 						var debugItems = ', $upcontext['debug_items'], ';';
4157 4372
 
4158
-		if ($is_debug)
4159
-			echo '
4373
+		if ($is_debug) {
4374
+					echo '
4160 4375
 						var upgradeStartTime = ' . $upcontext['started'] . ';';
4376
+		}
4161 4377
 
4162 4378
 		echo '
4163 4379
 						function getNextItem()
@@ -4197,9 +4413,10 @@  discard block
 block discarded – undo
4197 4413
 									document.getElementById("error_block").style.display = "";
4198 4414
 									setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4199 4415
 
4200
-	if ($is_debug)
4201
-		echo '
4416
+	if ($is_debug) {
4417
+			echo '
4202 4418
 									setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4419
+	}
4203 4420
 
4204 4421
 	echo '
4205 4422
 								}
@@ -4220,9 +4437,10 @@  discard block
 block discarded – undo
4220 4437
 									document.getElementById("error_block").style.display = "";
4221 4438
 									setInnerHTML(document.getElementById("error_message"), "', $txt['upgrade_loop'], '" + sDebugName);';
4222 4439
 
4223
-	if ($is_debug)
4224
-		echo '
4440
+	if ($is_debug) {
4441
+			echo '
4225 4442
 									setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4443
+	}
4226 4444
 
4227 4445
 	echo '
4228 4446
 								}
@@ -4279,8 +4497,8 @@  discard block
 block discarded – undo
4279 4497
 							if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4280 4498
 							{';
4281 4499
 
4282
-		if ($is_debug)
4283
-			echo '
4500
+		if ($is_debug) {
4501
+					echo '
4284 4502
 								document.getElementById(\'debug_section\').style.display = "none";
4285 4503
 
4286 4504
 								var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4298,6 +4516,7 @@  discard block
 block discarded – undo
4298 4516
 									totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4299 4517
 
4300 4518
 								setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4519
+		}
4301 4520
 
4302 4521
 		echo '
4303 4522
 
@@ -4305,9 +4524,10 @@  discard block
 block discarded – undo
4305 4524
 								document.getElementById(\'contbutt\').disabled = 0;
4306 4525
 								document.getElementById(\'database_done\').value = 1;';
4307 4526
 
4308
-		if ($upcontext['file_count'] > 1)
4309
-			echo '
4527
+		if ($upcontext['file_count'] > 1) {
4528
+					echo '
4310 4529
 								document.getElementById(\'info1\').style.display = "none";';
4530
+		}
4311 4531
 
4312 4532
 		echo '
4313 4533
 								document.getElementById(\'info2\').style.display = "none";
@@ -4320,9 +4540,10 @@  discard block
 block discarded – undo
4320 4540
 								lastItem = 0;
4321 4541
 								prevFile = curFile;';
4322 4542
 
4323
-		if ($is_debug)
4324
-			echo '
4543
+		if ($is_debug) {
4544
+					echo '
4325 4545
 								setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4546
+		}
4326 4547
 
4327 4548
 		echo '
4328 4549
 								getNextItem();
@@ -4330,8 +4551,8 @@  discard block
 block discarded – undo
4330 4551
 							}';
4331 4552
 
4332 4553
 		// If debug scroll the screen.
4333
-		if ($is_debug)
4334
-			echo '
4554
+		if ($is_debug) {
4555
+					echo '
4335 4556
 							if (iLastSubStepProgress == -1)
4336 4557
 							{
4337 4558
 								// Give it consistent dots.
@@ -4350,6 +4571,7 @@  discard block
 block discarded – undo
4350 4571
 
4351 4572
 							if (document.getElementById(\'debug_section\').scrollHeight)
4352 4573
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4574
+		}
4353 4575
 
4354 4576
 		echo '
4355 4577
 							// Update the page.
@@ -4410,9 +4632,10 @@  discard block
 block discarded – undo
4410 4632
 						}';
4411 4633
 
4412 4634
 		// Start things off assuming we've not errored.
4413
-		if (empty($upcontext['error_message']))
4414
-			echo '
4635
+		if (empty($upcontext['error_message'])) {
4636
+					echo '
4415 4637
 						getNextItem();';
4638
+		}
4416 4639
 
4417 4640
 		echo '
4418 4641
 					//# sourceURL=dynamicScript-dbch.js
@@ -4430,18 +4653,21 @@  discard block
 block discarded – undo
4430 4653
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4431 4654
 	<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>';
4432 4655
 
4433
-	if (!empty($upcontext['error_message']))
4434
-		echo '
4656
+	if (!empty($upcontext['error_message'])) {
4657
+			echo '
4435 4658
 	<error>', $upcontext['error_message'], '</error>';
4659
+	}
4436 4660
 
4437
-	if (!empty($upcontext['error_string']))
4438
-		echo '
4661
+	if (!empty($upcontext['error_string'])) {
4662
+			echo '
4439 4663
 	<sql>', $upcontext['error_string'], '</sql>';
4664
+	}
4440 4665
 
4441
-	if ($is_debug)
4442
-		echo '
4666
+	if ($is_debug) {
4667
+			echo '
4443 4668
 	<curtime>', time(), '</curtime>';
4444
-}
4669
+	}
4670
+	}
4445 4671
 
4446 4672
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4447 4673
 function template_convert_utf8()
@@ -4458,10 +4684,11 @@  discard block
 block discarded – undo
4458 4684
 					</div>';
4459 4685
 
4460 4686
 	// Done any tables so far?
4461
-	if (!empty($upcontext['previous_tables']))
4462
-		foreach ($upcontext['previous_tables'] as $table)
4687
+	if (!empty($upcontext['previous_tables'])) {
4688
+			foreach ($upcontext['previous_tables'] as $table)
4463 4689
 			echo '
4464 4690
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4691
+	}
4465 4692
 
4466 4693
 	echo '
4467 4694
 					<h3 id="current_tab">
@@ -4469,9 +4696,10 @@  discard block
 block discarded – undo
4469 4696
 					</h3>';
4470 4697
 
4471 4698
 	// If we dropped their index, let's let them know
4472
-	if ($upcontext['dropping_index'])
4473
-		echo '
4699
+	if ($upcontext['dropping_index']) {
4700
+			echo '
4474 4701
 					<p id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</p>';
4702
+	}
4475 4703
 
4476 4704
 	// Completion notification
4477 4705
 	echo '
@@ -4508,12 +4736,13 @@  discard block
 block discarded – undo
4508 4736
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4509 4737
 
4510 4738
 		// If debug flood the screen.
4511
-		if ($is_debug)
4512
-			echo '
4739
+		if ($is_debug) {
4740
+					echo '
4513 4741
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4514 4742
 
4515 4743
 						if (document.getElementById(\'debug_section\').scrollHeight)
4516 4744
 							document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4745
+		}
4517 4746
 
4518 4747
 		echo '
4519 4748
 						// Get the next update...
@@ -4559,10 +4788,11 @@  discard block
 block discarded – undo
4559 4788
 					</div>';
4560 4789
 
4561 4790
 	// Dont any tables so far?
4562
-	if (!empty($upcontext['previous_tables']))
4563
-		foreach ($upcontext['previous_tables'] as $table)
4791
+	if (!empty($upcontext['previous_tables'])) {
4792
+			foreach ($upcontext['previous_tables'] as $table)
4564 4793
 			echo '
4565 4794
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4795
+	}
4566 4796
 
4567 4797
 	echo '
4568 4798
 					<h3 id="current_tab">
@@ -4571,9 +4801,10 @@  discard block
 block discarded – undo
4571 4801
 					<p id="commess" style="display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</p>';
4572 4802
 
4573 4803
 	// Try to make sure substep was reset.
4574
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4575
-		echo '
4804
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4805
+			echo '
4576 4806
 					<input type="hidden" name="substep" id="substep" value="0">';
4807
+	}
4577 4808
 
4578 4809
 	// Continue please!
4579 4810
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4606,12 +4837,13 @@  discard block
 block discarded – undo
4606 4837
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4607 4838
 
4608 4839
 		// If debug flood the screen.
4609
-		if ($is_debug)
4610
-			echo '
4840
+		if ($is_debug) {
4841
+					echo '
4611 4842
 							setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4612 4843
 
4613 4844
 							if (document.getElementById(\'debug_section\').scrollHeight)
4614 4845
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4846
+		}
4615 4847
 
4616 4848
 		echo '
4617 4849
 							// Get the next update...
@@ -4647,8 +4879,8 @@  discard block
 block discarded – undo
4647 4879
 				<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4648 4880
 				<form action="', $boardurl, '/index.php">';
4649 4881
 
4650
-	if (!empty($upcontext['can_delete_script']))
4651
-		echo '
4882
+	if (!empty($upcontext['can_delete_script'])) {
4883
+			echo '
4652 4884
 					<label>
4653 4885
 						<input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '
4654 4886
 					</label>
@@ -4662,6 +4894,7 @@  discard block
 block discarded – undo
4662 4894
 						}
4663 4895
 					</script>
4664 4896
 					<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4897
+	}
4665 4898
 
4666 4899
 	$active = time() - $upcontext['started'];
4667 4900
 	$hours = floor($active / 3600);
@@ -4671,17 +4904,21 @@  discard block
 block discarded – undo
4671 4904
 	if ($is_debug)
4672 4905
 	{
4673 4906
 		$totalTime = '';
4674
-		if ($hours > 0)
4675
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4676
-		if ($minutes > 0)
4677
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4678
-		if ($seconds > 0)
4679
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4907
+		if ($hours > 0) {
4908
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4909
+		}
4910
+		if ($minutes > 0) {
4911
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4912
+		}
4913
+		if ($seconds > 0) {
4914
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4915
+		}
4680 4916
 	}
4681 4917
 
4682
-	if ($is_debug && !empty($totalTime))
4683
-		echo '
4918
+	if ($is_debug && !empty($totalTime)) {
4919
+			echo '
4684 4920
 					<p> ', $txt['upgrade_completed_time'], ' ', $totalTime, '</p>';
4921
+	}
4685 4922
 
4686 4923
 	echo '
4687 4924
 					<p>
@@ -4710,8 +4947,9 @@  discard block
 block discarded – undo
4710 4947
 
4711 4948
 	$current_substep = $_GET['substep'];
4712 4949
 
4713
-	if (empty($_GET['a']))
4714
-		$_GET['a'] = 0;
4950
+	if (empty($_GET['a'])) {
4951
+			$_GET['a'] = 0;
4952
+	}
4715 4953
 	$step_progress['name'] = 'Converting ips';
4716 4954
 	$step_progress['current'] = $_GET['a'];
4717 4955
 
@@ -4754,16 +4992,19 @@  discard block
 block discarded – undo
4754 4992
 				'empty' => '',
4755 4993
 				'limit' => $limit,
4756 4994
 		));
4757
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4758
-			$arIp[] = $row[$oldCol];
4995
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4996
+					$arIp[] = $row[$oldCol];
4997
+		}
4759 4998
 		$smcFunc['db_free_result']($request);
4760 4999
 
4761 5000
 		// Special case, null ip could keep us in a loop.
4762
-		if (is_null($arIp[0]))
4763
-			unset($arIp[0]);
5001
+		if (is_null($arIp[0])) {
5002
+					unset($arIp[0]);
5003
+		}
4764 5004
 
4765
-		if (empty($arIp))
4766
-			$is_done = true;
5005
+		if (empty($arIp)) {
5006
+					$is_done = true;
5007
+		}
4767 5008
 
4768 5009
 		$updates = array();
4769 5010
 		$cases = array();
@@ -4772,16 +5013,18 @@  discard block
 block discarded – undo
4772 5013
 		{
4773 5014
 			$arIp[$i] = trim($arIp[$i]);
4774 5015
 
4775
-			if (empty($arIp[$i]))
4776
-				continue;
5016
+			if (empty($arIp[$i])) {
5017
+							continue;
5018
+			}
4777 5019
 
4778 5020
 			$updates['ip' . $i] = $arIp[$i];
4779 5021
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4780 5022
 
4781 5023
 			if ($setSize > 0 && $i % $setSize === 0)
4782 5024
 			{
4783
-				if (count($updates) == 1)
4784
-					continue;
5025
+				if (count($updates) == 1) {
5026
+									continue;
5027
+				}
4785 5028
 
4786 5029
 				$updates['whereSet'] = array_values($updates);
4787 5030
 				$smcFunc['db_query']('', '
@@ -4815,8 +5058,7 @@  discard block
 block discarded – undo
4815 5058
 							'ip' => $ip
4816 5059
 					));
4817 5060
 				}
4818
-			}
4819
-			else
5061
+			} else
4820 5062
 			{
4821 5063
 				$updates['whereSet'] = array_values($updates);
4822 5064
 				$smcFunc['db_query']('', '
@@ -4830,9 +5072,9 @@  discard block
 block discarded – undo
4830 5072
 					$updates
4831 5073
 				);
4832 5074
 			}
5075
+		} else {
5076
+					$is_done = true;
4833 5077
 		}
4834
-		else
4835
-			$is_done = true;
4836 5078
 
4837 5079
 		$_GET['a'] += $limit;
4838 5080
 		$step_progress['current'] = $_GET['a'];
@@ -4858,10 +5100,11 @@  discard block
 block discarded – undo
4858 5100
 
4859 5101
 	$columns = $smcFunc['db_list_columns']($targetTable, true);
4860 5102
 
4861
-	if (isset($columns[$column]))
4862
-		return $columns[$column];
4863
-	else
4864
-		return null;
4865
-}
5103
+	if (isset($columns[$column])) {
5104
+			return $columns[$column];
5105
+	} else {
5106
+			return null;
5107
+	}
5108
+	}
4866 5109
 
4867 5110
 ?>
4868 5111
\ No newline at end of file
Please login to merge, or discard this patch.