Completed
Push — release-2.1 ( 6a11a6...e75011 )
by Michael
07:33
created
Sources/LogInOut.php 1 patch
Braces   +158 added lines, -124 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -102,19 +106,20 @@  discard block
 block discarded – undo
102 106
 			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
103 107
 
104 108
 			// That didn't work... Maybe it's using serialize?
105
-			if (is_null($timeout))
106
-				list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
107
-		}
108
-		elseif (isset($_SESSION['login_' . $cookiename]))
109
+			if (is_null($timeout)) {
110
+							list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
111
+			}
112
+		} elseif (isset($_SESSION['login_' . $cookiename]))
109 113
 		{
110 114
 			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
111 115
 
112 116
 			// Try for old format
113
-			if (is_null($timeout))
114
-				list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
117
+			if (is_null($timeout)) {
118
+							list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
119
+			}
120
+		} else {
121
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
115 122
 		}
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
118 123
 
119 124
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 125
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -127,10 +132,11 @@  discard block
 block discarded – undo
127 132
 			list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
128 133
 
129 134
 			// If we're preserving the cookie, reset it with updated salt
130
-			if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp)
131
-				setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
132
-			else
133
-				setTFACookie(-3600, 0, '');
135
+			if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) {
136
+							setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
137
+			} else {
138
+							setTFACookie(-3600, 0, '');
139
+			}
134 140
 		}
135 141
 
136 142
 		setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
@@ -141,20 +147,20 @@  discard block
 block discarded – undo
141 147
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
142 148
 	{
143 149
 		// Strike!  You're outta there!
144
-		if ($_GET['member'] != $user_info['id'])
145
-			fatal_lang_error('login_cookie_error', false);
150
+		if ($_GET['member'] != $user_info['id']) {
151
+					fatal_lang_error('login_cookie_error', false);
152
+		}
146 153
 
147 154
 		$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']))));
148 155
 
149 156
 		// Some whitelisting for login_url...
150
-		if (empty($_SESSION['login_url']))
151
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
152
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
157
+		if (empty($_SESSION['login_url'])) {
158
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
159
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
153 160
 		{
154 161
 			unset ($_SESSION['login_url']);
155 162
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
156
-		}
157
-		else
163
+		} else
158 164
 		{
159 165
 			// Best not to clutter the session data too much...
160 166
 			$temp = $_SESSION['login_url'];
@@ -165,8 +171,9 @@  discard block
 block discarded – undo
165 171
 	}
166 172
 
167 173
 	// Beyond this point you are assumed to be a guest trying to login.
168
-	if (!$user_info['is_guest'])
169
-		redirectexit();
174
+	if (!$user_info['is_guest']) {
175
+			redirectexit();
176
+	}
170 177
 
171 178
 	// Are you guessing with a script?
172 179
 	checkSession();
@@ -174,18 +181,21 @@  discard block
 block discarded – undo
174 181
 	spamProtection('login');
175 182
 
176 183
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
177
-	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))
178
-		$_SESSION['login_url'] = $_SESSION['old_url'];
184
+	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)) {
185
+			$_SESSION['login_url'] = $_SESSION['old_url'];
186
+	}
179 187
 
180 188
 	// Been guessing a lot, haven't we?
181
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
182
-		fatal_lang_error('login_threshold_fail', 'login');
189
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
190
+			fatal_lang_error('login_threshold_fail', 'login');
191
+	}
183 192
 
184 193
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
185
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
186
-		$modSettings['cookieTime'] = 3153600;
187
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
188
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
194
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
195
+			$modSettings['cookieTime'] = 3153600;
196
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
197
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
198
+	}
189 199
 
190 200
 	loadLanguage('Login');
191 201
 	// Load the template stuff.
@@ -305,8 +315,9 @@  discard block
 block discarded – undo
305 315
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
306 316
 
307 317
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
308
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
309
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
318
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
319
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
320
+			}
310 321
 
311 322
 			// phpBB3 users new hashing.  We now support it as well ;).
312 323
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -326,27 +337,29 @@  discard block
 block discarded – undo
326 337
 			// Some common md5 ones.
327 338
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
328 339
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
329
-		}
330
-		elseif (strlen($user_settings['passwd']) == 40)
340
+		} elseif (strlen($user_settings['passwd']) == 40)
331 341
 		{
332 342
 			// Maybe they are using a hash from before the password fix.
333 343
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
334 344
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
335 345
 
336 346
 			// BurningBoard3 style of hashing.
337
-			if (!empty($modSettings['enable_password_conversion']))
338
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
347
+			if (!empty($modSettings['enable_password_conversion'])) {
348
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
349
+			}
339 350
 
340 351
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
341 352
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
342 353
 			{
343 354
 				// Try iconv first, for no particular reason.
344
-				if (function_exists('iconv'))
345
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
355
+				if (function_exists('iconv')) {
356
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
357
+				}
346 358
 
347 359
 				// Say it aint so, iconv failed!
348
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
349
-					$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'])));
360
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
361
+									$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'])));
362
+				}
350 363
 			}
351 364
 		}
352 365
 
@@ -376,8 +389,9 @@  discard block
 block discarded – undo
376 389
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
377 390
 
378 391
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
379
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
380
-				redirectexit('action=reminder');
392
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
393
+							redirectexit('action=reminder');
394
+			}
381 395
 			// We'll give you another chance...
382 396
 			else
383 397
 			{
@@ -388,8 +402,7 @@  discard block
 block discarded – undo
388 402
 				return;
389 403
 			}
390 404
 		}
391
-	}
392
-	elseif (!empty($user_settings['passwd_flood']))
405
+	} elseif (!empty($user_settings['passwd_flood']))
393 406
 	{
394 407
 		// Let's be sure they weren't a little hacker.
395 408
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -406,8 +419,9 @@  discard block
 block discarded – undo
406 419
 	}
407 420
 
408 421
 	// Check their activation status.
409
-	if (!checkActivation())
410
-		return;
422
+	if (!checkActivation()) {
423
+			return;
424
+	}
411 425
 
412 426
 	DoLogin();
413 427
 }
@@ -419,8 +433,9 @@  discard block
 block discarded – undo
419 433
 {
420 434
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
421 435
 
422
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
423
-		fatal_lang_error('no_access', false);
436
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
437
+			fatal_lang_error('no_access', false);
438
+	}
424 439
 
425 440
 	loadLanguage('Profile');
426 441
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -428,8 +443,9 @@  discard block
 block discarded – undo
428 443
 	$member = $context['tfa_member'];
429 444
 
430 445
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
431
-	if (time() - $member['last_login'] < 120)
432
-		fatal_lang_error('tfa_wait', false);
446
+	if (time() - $member['last_login'] < 120) {
447
+			fatal_lang_error('tfa_wait', false);
448
+	}
433 449
 
434 450
 	$totp = new \TOTP\Auth($member['tfa_secret']);
435 451
 	$totp->setRange(1);
@@ -443,8 +459,9 @@  discard block
 block discarded – undo
443 459
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
444 460
 	{
445 461
 		// Check to ensure we're forcing SSL for authentication
446
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
447
-			fatal_lang_error('login_ssl_required');
462
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
463
+					fatal_lang_error('login_ssl_required');
464
+		}
448 465
 
449 466
 		$code = $_POST['tfa_code'];
450 467
 
@@ -454,20 +471,19 @@  discard block
 block discarded – undo
454 471
 
455 472
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve']));
456 473
 			redirectexit();
457
-		}
458
-		else
474
+		} else
459 475
 		{
460 476
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
461 477
 
462 478
 			$context['tfa_error'] = true;
463 479
 			$context['tfa_value'] = $_POST['tfa_code'];
464 480
 		}
465
-	}
466
-	elseif (!empty($_POST['tfa_backup']))
481
+	} elseif (!empty($_POST['tfa_backup']))
467 482
 	{
468 483
 		// Check to ensure we're forcing SSL for authentication
469
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
470
-			fatal_lang_error('login_ssl_required');
484
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
485
+					fatal_lang_error('login_ssl_required');
486
+		}
471 487
 
472 488
 		$backup = $_POST['tfa_backup'];
473 489
 
@@ -481,8 +497,7 @@  discard block
 block discarded – undo
481 497
 			));
482 498
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
483 499
 			redirectexit('action=profile;area=tfasetup;backup');
484
-		}
485
-		else
500
+		} else
486 501
 		{
487 502
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
488 503
 
@@ -505,8 +520,9 @@  discard block
 block discarded – undo
505 520
 {
506 521
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
507 522
 
508
-	if (!isset($context['login_errors']))
509
-		$context['login_errors'] = array();
523
+	if (!isset($context['login_errors'])) {
524
+			$context['login_errors'] = array();
525
+	}
510 526
 
511 527
 	// What is the true activation status of this account?
512 528
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -518,8 +534,9 @@  discard block
 block discarded – undo
518 534
 		return false;
519 535
 	}
520 536
 	// Awaiting approval still?
521
-	elseif ($activation_status == 3)
522
-		fatal_lang_error('still_awaiting_approval', 'user');
537
+	elseif ($activation_status == 3) {
538
+			fatal_lang_error('still_awaiting_approval', 'user');
539
+	}
523 540
 	// Awaiting deletion, changed their mind?
524 541
 	elseif ($activation_status == 4)
525 542
 	{
@@ -527,8 +544,7 @@  discard block
 block discarded – undo
527 544
 		{
528 545
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
529 546
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
530
-		}
531
-		else
547
+		} else
532 548
 		{
533 549
 			$context['disable_login_hashing'] = true;
534 550
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -568,8 +584,9 @@  discard block
 block discarded – undo
568 584
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
569 585
 
570 586
 	// Reset the login threshold.
571
-	if (isset($_SESSION['failed_login']))
572
-		unset($_SESSION['failed_login']);
587
+	if (isset($_SESSION['failed_login'])) {
588
+			unset($_SESSION['failed_login']);
589
+	}
573 590
 
574 591
 	$user_info['is_guest'] = false;
575 592
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -591,16 +608,18 @@  discard block
 block discarded – undo
591 608
 			'id_member' => $user_info['id'],
592 609
 		)
593 610
 	);
594
-	if ($smcFunc['db_num_rows']($request) == 1)
595
-		$_SESSION['first_login'] = true;
596
-	else
597
-		unset($_SESSION['first_login']);
611
+	if ($smcFunc['db_num_rows']($request) == 1) {
612
+			$_SESSION['first_login'] = true;
613
+	} else {
614
+			unset($_SESSION['first_login']);
615
+	}
598 616
 	$smcFunc['db_free_result']($request);
599 617
 
600 618
 	// You've logged in, haven't you?
601 619
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
602
-	if (empty($user_settings['tfa_secret']))
603
-		$update['last_login'] = time();
620
+	if (empty($user_settings['tfa_secret'])) {
621
+			$update['last_login'] = time();
622
+	}
604 623
 	updateMemberData($user_info['id'], $update);
605 624
 
606 625
 	// Get rid of the online entry for that old guest....
@@ -614,8 +633,8 @@  discard block
 block discarded – undo
614 633
 	$_SESSION['log_time'] = 0;
615 634
 
616 635
 	// Log this entry, only if we have it enabled.
617
-	if (!empty($modSettings['loginHistoryDays']))
618
-		$smcFunc['db_insert']('insert',
636
+	if (!empty($modSettings['loginHistoryDays'])) {
637
+			$smcFunc['db_insert']('insert',
619 638
 			'{db_prefix}member_logins',
620 639
 			array(
621 640
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -627,13 +646,15 @@  discard block
 block discarded – undo
627 646
 				'id_member', 'time'
628 647
 			)
629 648
 		);
649
+	}
630 650
 
631 651
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
632
-	if (empty($maintenance) || allowedTo('admin_forum'))
633
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
634
-	else
635
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
636
-}
652
+	if (empty($maintenance) || allowedTo('admin_forum')) {
653
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
654
+	} else {
655
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
656
+	}
657
+	}
637 658
 
638 659
 /**
639 660
  * Logs the current user out of their account.
@@ -649,13 +670,15 @@  discard block
 block discarded – undo
649 670
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
650 671
 
651 672
 	// Make sure they aren't being auto-logged out.
652
-	if (!$internal)
653
-		checkSession('get');
673
+	if (!$internal) {
674
+			checkSession('get');
675
+	}
654 676
 
655 677
 	require_once($sourcedir . '/Subs-Auth.php');
656 678
 
657
-	if (isset($_SESSION['pack_ftp']))
658
-		$_SESSION['pack_ftp'] = null;
679
+	if (isset($_SESSION['pack_ftp'])) {
680
+			$_SESSION['pack_ftp'] = null;
681
+	}
659 682
 
660 683
 	// It won't be first login anymore.
661 684
 	unset($_SESSION['first_login']);
@@ -683,8 +706,9 @@  discard block
 block discarded – undo
683 706
 
684 707
 	// And some other housekeeping while we're at it.
685 708
 	$salt = substr(md5(mt_rand()), 0, 4);
686
-	if (!empty($user_info['id']))
687
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
709
+	if (!empty($user_info['id'])) {
710
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
711
+	}
688 712
 
689 713
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
690 714
 	{
@@ -693,10 +717,11 @@  discard block
 block discarded – undo
693 717
 		list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
694 718
 
695 719
 		// If we're preserving the cookie, reset it with updated salt
696
-		if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp)
697
-			setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
698
-		else
699
-			setTFACookie(-3600, 0, '');
720
+		if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) {
721
+					setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
722
+		} else {
723
+					setTFACookie(-3600, 0, '');
724
+		}
700 725
 	}
701 726
 
702 727
 	session_destroy();
@@ -704,14 +729,13 @@  discard block
 block discarded – undo
704 729
 	// Off to the merry board index we go!
705 730
 	if ($redirect)
706 731
 	{
707
-		if (empty($_SESSION['logout_url']))
708
-			redirectexit('', $context['server']['needs_login_fix']);
709
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
732
+		if (empty($_SESSION['logout_url'])) {
733
+					redirectexit('', $context['server']['needs_login_fix']);
734
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
710 735
 		{
711 736
 			unset ($_SESSION['logout_url']);
712 737
 			redirectexit();
713
-		}
714
-		else
738
+		} else
715 739
 		{
716 740
 			$temp = $_SESSION['logout_url'];
717 741
 			unset($_SESSION['logout_url']);
@@ -744,8 +768,9 @@  discard block
 block discarded – undo
744 768
 function phpBB3_password_check($passwd, $passwd_hash)
745 769
 {
746 770
 	// Too long or too short?
747
-	if (strlen($passwd_hash) != 34)
748
-		return;
771
+	if (strlen($passwd_hash) != 34) {
772
+			return;
773
+	}
749 774
 
750 775
 	// Range of characters allowed.
751 776
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -756,8 +781,9 @@  discard block
 block discarded – undo
756 781
 	$salt = substr($passwd_hash, 4, 8);
757 782
 
758 783
 	$hash = md5($salt . $passwd, true);
759
-	for (; $count != 0; --$count)
760
-		$hash = md5($hash . $passwd, true);
784
+	for (; $count != 0; --$count) {
785
+			$hash = md5($hash . $passwd, true);
786
+	}
761 787
 
762 788
 	$output = substr($passwd_hash, 0, 12);
763 789
 	$i = 0;
@@ -766,21 +792,25 @@  discard block
 block discarded – undo
766 792
 		$value = ord($hash[$i++]);
767 793
 		$output .= $range[$value & 0x3f];
768 794
 
769
-		if ($i < 16)
770
-			$value |= ord($hash[$i]) << 8;
795
+		if ($i < 16) {
796
+					$value |= ord($hash[$i]) << 8;
797
+		}
771 798
 
772 799
 		$output .= $range[($value >> 6) & 0x3f];
773 800
 
774
-		if ($i++ >= 16)
775
-			break;
801
+		if ($i++ >= 16) {
802
+					break;
803
+		}
776 804
 
777
-		if ($i < 16)
778
-			$value |= ord($hash[$i]) << 16;
805
+		if ($i < 16) {
806
+					$value |= ord($hash[$i]) << 16;
807
+		}
779 808
 
780 809
 		$output .= $range[($value >> 12) & 0x3f];
781 810
 
782
-		if ($i++ >= 16)
783
-			break;
811
+		if ($i++ >= 16) {
812
+					break;
813
+		}
784 814
 
785 815
 		$output .= $range[($value >> 18) & 0x3f];
786 816
 	}
@@ -809,8 +839,9 @@  discard block
 block discarded – undo
809 839
 	// Only if they're not validating for 2FA
810 840
 	if (!$tfa)
811 841
 	{
812
-		if (isset($_SESSION['login_' . $cookiename]))
813
-			unset($_SESSION['login_' . $cookiename]);
842
+		if (isset($_SESSION['login_' . $cookiename])) {
843
+					unset($_SESSION['login_' . $cookiename]);
844
+		}
814 845
 	}
815 846
 
816 847
 	// We need a member!
@@ -824,8 +855,9 @@  discard block
 block discarded – undo
824 855
 	}
825 856
 
826 857
 	// Right, have we got a flood value?
827
-	if ($password_flood_value !== false)
828
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
858
+	if ($password_flood_value !== false) {
859
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
860
+	}
829 861
 
830 862
 	// Timestamp or number of tries invalid?
831 863
 	if (empty($number_tries) || empty($time_stamp))
@@ -841,15 +873,17 @@  discard block
 block discarded – undo
841 873
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
842 874
 
843 875
 		// They are trying too fast, make them wait longer
844
-		if ($time_stamp < time() - 10)
845
-			$time_stamp = time();
876
+		if ($time_stamp < time() - 10) {
877
+					$time_stamp = time();
878
+		}
846 879
 	}
847 880
 
848 881
 	$number_tries++;
849 882
 
850 883
 	// Broken the law?
851
-	if ($number_tries > 5)
852
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
884
+	if ($number_tries > 5) {
885
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
886
+	}
853 887
 
854 888
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
855 889
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +785 added lines, -595 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('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($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
 
@@ -403,27 +420,28 @@  discard block
 block discarded – undo
403 420
 				break;
404 421
 			}
405 422
 		}
423
+	} else {
424
+			$id_member = 0;
406 425
 	}
407
-	else
408
-		$id_member = 0;
409 426
 
410 427
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
411 428
 	{
412 429
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
413 430
 
414
-		if (empty($cookie_data))
415
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
431
+		if (empty($cookie_data)) {
432
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
433
+		}
416 434
 
417 435
 		list ($id_member, $password) = $cookie_data;
418 436
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
419
-	}
420
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
437
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
421 438
 	{
422 439
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
423 440
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
424 441
 
425
-		if (empty($cookie_data))
426
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		if (empty($cookie_data)) {
443
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
444
+		}
427 445
 
428 446
 		list ($id_member, $password, $login_span) = $cookie_data;
429 447
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -448,24 +466,28 @@  discard block
 block discarded – undo
448 466
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
449 467
 			$smcFunc['db_free_result']($request);
450 468
 
451
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
452
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
469
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
470
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
471
+			}
453 472
 
454
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
455
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
474
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
475
+			}
456 476
 		}
457 477
 
458 478
 		// Did we find 'im?  If not, junk it.
459 479
 		if (!empty($user_settings))
460 480
 		{
461 481
 			// As much as the password should be right, we can assume the integration set things up.
462
-			if (!empty($already_verified) && $already_verified === true)
463
-				$check = true;
482
+			if (!empty($already_verified) && $already_verified === true) {
483
+							$check = true;
484
+			}
464 485
 			// SHA-512 hash should be 128 characters long.
465
-			elseif (strlen($password) == 128)
466
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
467
-			else
468
-				$check = false;
486
+			elseif (strlen($password) == 128) {
487
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
488
+			} else {
489
+							$check = false;
490
+			}
469 491
 
470 492
 			// Wrong password or not activated - either way, you're going nowhere.
471 493
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
@@ -474,9 +496,9 @@  discard block
 block discarded – undo
474 496
 				setLoginCookie(-3600, 0);
475 497
 				$user_settings = array();
476 498
 			}
499
+		} else {
500
+					$id_member = 0;
477 501
 		}
478
-		else
479
-			$id_member = 0;
480 502
 
481 503
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
482 504
 		if (!empty($id_member))
@@ -505,8 +527,9 @@  discard block
 block discarded – undo
505 527
 
506 528
 					list ($tfamember, $tfasecret) = $tfa_data;
507 529
 
508
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
509
-						$tfasecret = null;
530
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
531
+											$tfasecret = null;
532
+					}
510 533
 				}
511 534
 
512 535
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -526,10 +549,12 @@  discard block
 block discarded – undo
526 549
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
527 550
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
528 551
 		{
529
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
552
+			if ($modSettings['tfa_mode'] == 2) {
553
+				//only do this if we are just forcing SOME membergroups
530 554
 			{
531 555
 				//Build an array of ALL user membergroups.
532 556
 				$full_groups = array($user_settings['id_group']);
557
+			}
533 558
 				if (!empty($user_settings['additional_groups']))
534 559
 				{
535 560
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -549,17 +574,18 @@  discard block
 block discarded – undo
549 574
 				);
550 575
 				$row = $smcFunc['db_fetch_assoc']($request);
551 576
 				$smcFunc['db_free_result']($request);
577
+			} else {
578
+							$row['total'] = 1;
552 579
 			}
553
-			else
554
-				$row['total'] = 1; //simplifies logics in the next "if"
580
+			//simplifies logics in the next "if"
555 581
 
556 582
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
557 583
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
558 584
 
559
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
560
-				redirectexit('action=profile;area=tfasetup;forced');
561
-		}
562
-		else if (!empty($user_settings) && empty($id_member))
585
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
586
+							redirectexit('action=profile;area=tfasetup;forced');
587
+			}
588
+		} else if (!empty($user_settings) && empty($id_member))
563 589
 		{
564 590
 			$user_settings = array();
565 591
 		}
@@ -598,33 +624,37 @@  discard block
 block discarded – undo
598 624
 				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']));
599 625
 				$user_settings['last_login'] = time();
600 626
 
601
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
602
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
627
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
628
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
629
+				}
603 630
 
604
-				if (!empty($modSettings['cache_enable']))
605
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
631
+				if (!empty($modSettings['cache_enable'])) {
632
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
633
+				}
606 634
 			}
635
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
636
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
607 637
 		}
608
-		elseif (empty($_SESSION['id_msg_last_visit']))
609
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
610 638
 
611 639
 		$username = $user_settings['member_name'];
612 640
 
613
-		if (empty($user_settings['additional_groups']))
614
-			$user_info = array(
641
+		if (empty($user_settings['additional_groups'])) {
642
+					$user_info = array(
615 643
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
616 644
 			);
617
-		else
618
-			$user_info = array(
645
+		} else {
646
+					$user_info = array(
619 647
 				'groups' => array_merge(
620 648
 					array($user_settings['id_group'], $user_settings['id_post_group']),
621 649
 					explode(',', $user_settings['additional_groups'])
622 650
 				)
623 651
 			);
652
+		}
624 653
 
625 654
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
626
-		foreach ($user_info['groups'] as $k => $v)
627
-			$user_info['groups'][$k] = (int) $v;
655
+		foreach ($user_info['groups'] as $k => $v) {
656
+					$user_info['groups'][$k] = (int) $v;
657
+		}
628 658
 
629 659
 		// This is a logged in user, so definitely not a spider.
630 660
 		$user_info['possibly_robot'] = false;
@@ -638,8 +668,7 @@  discard block
 block discarded – undo
638 668
 			$time_system = new DateTime('now', $tz_system);
639 669
 			$time_user = new DateTime('now', $tz_user);
640 670
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
641
-		}
642
-		else
671
+		} else
643 672
 		{
644 673
 			// !!! Compatibility.
645 674
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -653,8 +682,9 @@  discard block
 block discarded – undo
653 682
 		$user_info = array('groups' => array(-1));
654 683
 		$user_settings = array();
655 684
 
656
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
657
-			$_COOKIE[$cookiename] = '';
685
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
686
+					$_COOKIE[$cookiename] = '';
687
+		}
658 688
 
659 689
 		// Expire the 2FA cookie
660 690
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -671,19 +701,20 @@  discard block
 block discarded – undo
671 701
 		}
672 702
 
673 703
 		// Create a login token if it doesn't exist yet.
674
-		if (!isset($_SESSION['token']['post-login']))
675
-			createToken('login');
676
-		else
677
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
704
+		if (!isset($_SESSION['token']['post-login'])) {
705
+					createToken('login');
706
+		} else {
707
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
708
+		}
678 709
 
679 710
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
680 711
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
681 712
 		{
682 713
 			require_once($sourcedir . '/ManageSearchEngines.php');
683 714
 			$user_info['possibly_robot'] = SpiderCheck();
715
+		} elseif (!empty($modSettings['spider_mode'])) {
716
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
684 717
 		}
685
-		elseif (!empty($modSettings['spider_mode']))
686
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
687 718
 		// If we haven't turned on proper spider hunts then have a guess!
688 719
 		else
689 720
 		{
@@ -731,8 +762,9 @@  discard block
 block discarded – undo
731 762
 	$user_info['groups'] = array_unique($user_info['groups']);
732 763
 
733 764
 	// 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.
734
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
735
-		unset($user_info['ignoreboards'][$tmp]);
765
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
766
+			unset($user_info['ignoreboards'][$tmp]);
767
+	}
736 768
 
737 769
 	// Allow the user to change their language.
738 770
 	if (!empty($modSettings['userLanguage']))
@@ -745,13 +777,14 @@  discard block
 block discarded – undo
745 777
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
746 778
 
747 779
 			// Make it permanent for members.
748
-			if (!empty($user_info['id']))
749
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
750
-			else
751
-				$_SESSION['language'] = $user_info['language'];
780
+			if (!empty($user_info['id'])) {
781
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
782
+			} else {
783
+							$_SESSION['language'] = $user_info['language'];
784
+			}
785
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
786
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
752 787
 		}
753
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
754
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
755 788
 	}
756 789
 
757 790
 	$temp = build_query_board($user_info['id']);
@@ -814,9 +847,9 @@  discard block
 block discarded – undo
814 847
 		}
815 848
 
816 849
 		// Remember redirection is the key to avoiding fallout from your bosses.
817
-		if (!empty($topic))
818
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
819
-		else
850
+		if (!empty($topic)) {
851
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
852
+		} else
820 853
 		{
821 854
 			loadPermissions();
822 855
 			loadTheme();
@@ -834,10 +867,11 @@  discard block
 block discarded – undo
834 867
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
835 868
 	{
836 869
 		// @todo SLOW?
837
-		if (!empty($topic))
838
-			$temp = cache_get_data('topic_board-' . $topic, 120);
839
-		else
840
-			$temp = cache_get_data('board-' . $board, 120);
870
+		if (!empty($topic)) {
871
+					$temp = cache_get_data('topic_board-' . $topic, 120);
872
+		} else {
873
+					$temp = cache_get_data('board-' . $board, 120);
874
+		}
841 875
 
842 876
 		if (!empty($temp))
843 877
 		{
@@ -875,8 +909,9 @@  discard block
 block discarded – undo
875 909
 			$row = $smcFunc['db_fetch_assoc']($request);
876 910
 
877 911
 			// Set the current board.
878
-			if (!empty($row['id_board']))
879
-				$board = $row['id_board'];
912
+			if (!empty($row['id_board'])) {
913
+							$board = $row['id_board'];
914
+			}
880 915
 
881 916
 			// Basic operating information. (globals... :/)
882 917
 			$board_info = array(
@@ -912,21 +947,23 @@  discard block
 block discarded – undo
912 947
 
913 948
 			do
914 949
 			{
915
-				if (!empty($row['id_moderator']))
916
-					$board_info['moderators'][$row['id_moderator']] = array(
950
+				if (!empty($row['id_moderator'])) {
951
+									$board_info['moderators'][$row['id_moderator']] = array(
917 952
 						'id' => $row['id_moderator'],
918 953
 						'name' => $row['real_name'],
919 954
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
920 955
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
921 956
 					);
957
+				}
922 958
 
923
-				if (!empty($row['id_moderator_group']))
924
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
959
+				if (!empty($row['id_moderator_group'])) {
960
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
925 961
 						'id' => $row['id_moderator_group'],
926 962
 						'name' => $row['group_name'],
927 963
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
928 964
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
929 965
 					);
966
+				}
930 967
 			}
931 968
 			while ($row = $smcFunc['db_fetch_assoc']($request));
932 969
 
@@ -958,12 +995,12 @@  discard block
 block discarded – undo
958 995
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
959 996
 			{
960 997
 				// @todo SLOW?
961
-				if (!empty($topic))
962
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
998
+				if (!empty($topic)) {
999
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1000
+				}
963 1001
 				cache_put_data('board-' . $board, $board_info, 120);
964 1002
 			}
965
-		}
966
-		else
1003
+		} else
967 1004
 		{
968 1005
 			// Otherwise the topic is invalid, there are no moderators, etc.
969 1006
 			$board_info = array(
@@ -977,8 +1014,9 @@  discard block
 block discarded – undo
977 1014
 		$smcFunc['db_free_result']($request);
978 1015
 	}
979 1016
 
980
-	if (!empty($topic))
981
-		$_GET['board'] = (int) $board;
1017
+	if (!empty($topic)) {
1018
+			$_GET['board'] = (int) $board;
1019
+	}
982 1020
 
983 1021
 	if (!empty($board))
984 1022
 	{
@@ -988,10 +1026,12 @@  discard block
 block discarded – undo
988 1026
 		// Now check if the user is a moderator.
989 1027
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
990 1028
 
991
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
992
-			$board_info['error'] = 'access';
993
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
994
-			$board_info['error'] = 'access';
1029
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1030
+					$board_info['error'] = 'access';
1031
+		}
1032
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1033
+					$board_info['error'] = 'access';
1034
+		}
995 1035
 
996 1036
 		// Build up the linktree.
997 1037
 		$context['linktree'] = array_merge(
@@ -1014,8 +1054,9 @@  discard block
 block discarded – undo
1014 1054
 	$context['current_board'] = $board;
1015 1055
 
1016 1056
 	// No posting in redirection boards!
1017
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1018
-		$board_info['error'] == 'post_in_redirect';
1057
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1058
+			$board_info['error'] == 'post_in_redirect';
1059
+	}
1019 1060
 
1020 1061
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1021 1062
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1041,24 +1082,23 @@  discard block
 block discarded – undo
1041 1082
 			ob_end_clean();
1042 1083
 			header('HTTP/1.1 403 Forbidden');
1043 1084
 			die;
1044
-		}
1045
-		elseif ($board_info['error'] == 'post_in_redirect')
1085
+		} elseif ($board_info['error'] == 'post_in_redirect')
1046 1086
 		{
1047 1087
 			// Slightly different error message here...
1048 1088
 			fatal_lang_error('cannot_post_redirect', false);
1049
-		}
1050
-		elseif ($user_info['is_guest'])
1089
+		} elseif ($user_info['is_guest'])
1051 1090
 		{
1052 1091
 			loadLanguage('Errors');
1053 1092
 			is_not_guest($txt['topic_gone']);
1093
+		} else {
1094
+					fatal_lang_error('topic_gone', false);
1054 1095
 		}
1055
-		else
1056
-			fatal_lang_error('topic_gone', false);
1057 1096
 	}
1058 1097
 
1059
-	if ($user_info['is_mod'])
1060
-		$user_info['groups'][] = 3;
1061
-}
1098
+	if ($user_info['is_mod']) {
1099
+			$user_info['groups'][] = 3;
1100
+	}
1101
+	}
1062 1102
 
1063 1103
 /**
1064 1104
  * Load this user's permissions.
@@ -1079,8 +1119,9 @@  discard block
 block discarded – undo
1079 1119
 		asort($cache_groups);
1080 1120
 		$cache_groups = implode(',', $cache_groups);
1081 1121
 		// If it's a spider then cache it different.
1082
-		if ($user_info['possibly_robot'])
1083
-			$cache_groups .= '-spider';
1122
+		if ($user_info['possibly_robot']) {
1123
+					$cache_groups .= '-spider';
1124
+		}
1084 1125
 
1085 1126
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1086 1127
 		{
@@ -1088,9 +1129,9 @@  discard block
 block discarded – undo
1088 1129
 			banPermissions();
1089 1130
 
1090 1131
 			return;
1132
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1133
+					list ($user_info['permissions'], $removals) = $temp;
1091 1134
 		}
1092
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1093
-			list ($user_info['permissions'], $removals) = $temp;
1094 1135
 	}
1095 1136
 
1096 1137
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1112,23 +1153,26 @@  discard block
 block discarded – undo
1112 1153
 		$removals = array();
1113 1154
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1114 1155
 		{
1115
-			if (empty($row['add_deny']))
1116
-				$removals[] = $row['permission'];
1117
-			else
1118
-				$user_info['permissions'][] = $row['permission'];
1156
+			if (empty($row['add_deny'])) {
1157
+							$removals[] = $row['permission'];
1158
+			} else {
1159
+							$user_info['permissions'][] = $row['permission'];
1160
+			}
1119 1161
 		}
1120 1162
 		$smcFunc['db_free_result']($request);
1121 1163
 
1122
-		if (isset($cache_groups))
1123
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1164
+		if (isset($cache_groups)) {
1165
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1166
+		}
1124 1167
 	}
1125 1168
 
1126 1169
 	// Get the board permissions.
1127 1170
 	if (!empty($board))
1128 1171
 	{
1129 1172
 		// Make sure the board (if any) has been loaded by loadBoard().
1130
-		if (!isset($board_info['profile']))
1131
-			fatal_lang_error('no_board');
1173
+		if (!isset($board_info['profile'])) {
1174
+					fatal_lang_error('no_board');
1175
+		}
1132 1176
 
1133 1177
 		$request = $smcFunc['db_query']('', '
1134 1178
 			SELECT permission, add_deny
@@ -1144,20 +1188,23 @@  discard block
 block discarded – undo
1144 1188
 		);
1145 1189
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1146 1190
 		{
1147
-			if (empty($row['add_deny']))
1148
-				$removals[] = $row['permission'];
1149
-			else
1150
-				$user_info['permissions'][] = $row['permission'];
1191
+			if (empty($row['add_deny'])) {
1192
+							$removals[] = $row['permission'];
1193
+			} else {
1194
+							$user_info['permissions'][] = $row['permission'];
1195
+			}
1151 1196
 		}
1152 1197
 		$smcFunc['db_free_result']($request);
1153 1198
 	}
1154 1199
 
1155 1200
 	// Remove all the permissions they shouldn't have ;).
1156
-	if (!empty($modSettings['permission_enable_deny']))
1157
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1201
+	if (!empty($modSettings['permission_enable_deny'])) {
1202
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1203
+	}
1158 1204
 
1159
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1160
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1205
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1206
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1207
+	}
1161 1208
 
1162 1209
 	// Banned?  Watch, don't touch..
1163 1210
 	banPermissions();
@@ -1169,17 +1216,18 @@  discard block
 block discarded – undo
1169 1216
 		{
1170 1217
 			require_once($sourcedir . '/Subs-Auth.php');
1171 1218
 			rebuildModCache();
1219
+		} else {
1220
+					$user_info['mod_cache'] = $_SESSION['mc'];
1172 1221
 		}
1173
-		else
1174
-			$user_info['mod_cache'] = $_SESSION['mc'];
1175 1222
 
1176 1223
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1177 1224
 		// For example this drastically simplifies certain changes to the profile area.
1178 1225
 		$user_info['permissions'][] = 'is_not_guest';
1179 1226
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1180 1227
 		$user_info['permissions'][] = 'profile_view_own';
1181
-		if (in_array('profile_view', $user_info['permissions']))
1182
-			$user_info['permissions'][] = 'profile_view_any';
1228
+		if (in_array('profile_view', $user_info['permissions'])) {
1229
+					$user_info['permissions'][] = 'profile_view_any';
1230
+		}
1183 1231
 	}
1184 1232
 }
1185 1233
 
@@ -1197,8 +1245,9 @@  discard block
 block discarded – undo
1197 1245
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1198 1246
 
1199 1247
 	// Can't just look for no users :P.
1200
-	if (empty($users))
1201
-		return array();
1248
+	if (empty($users)) {
1249
+			return array();
1250
+	}
1202 1251
 
1203 1252
 	// Pass the set value
1204 1253
 	$context['loadMemberContext_set'] = $set;
@@ -1213,8 +1262,9 @@  discard block
 block discarded – undo
1213 1262
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1214 1263
 		{
1215 1264
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1216
-			if ($data == null)
1217
-				continue;
1265
+			if ($data == null) {
1266
+							continue;
1267
+			}
1218 1268
 
1219 1269
 			$loaded_ids[] = $data['id_member'];
1220 1270
 			$user_profile[$data['id_member']] = $data;
@@ -1281,16 +1331,19 @@  discard block
 block discarded – undo
1281 1331
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1282 1332
 
1283 1333
 			// Take care of proxying avatar if required, do this here for maximum reach
1284
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1285
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1334
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1335
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1336
+			}
1286 1337
 
1287 1338
 			// Keep track of the member's normal member group
1288 1339
 			$row['primary_group'] = $row['member_group'];
1289 1340
 
1290
-			if (isset($row['member_ip']))
1291
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1292
-			if (isset($row['member_ip2']))
1293
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1341
+			if (isset($row['member_ip'])) {
1342
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1343
+			}
1344
+			if (isset($row['member_ip2'])) {
1345
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1346
+			}
1294 1347
 			$new_loaded_ids[] = $row['id_member'];
1295 1348
 			$loaded_ids[] = $row['id_member'];
1296 1349
 			$row['options'] = array();
@@ -1309,8 +1362,9 @@  discard block
 block discarded – undo
1309 1362
 				'loaded_ids' => $new_loaded_ids,
1310 1363
 			)
1311 1364
 		);
1312
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1313
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1365
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1366
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1367
+		}
1314 1368
 		$smcFunc['db_free_result']($request);
1315 1369
 	}
1316 1370
 
@@ -1321,10 +1375,11 @@  discard block
 block discarded – undo
1321 1375
 	{
1322 1376
 		foreach ($loaded_ids as $a_member)
1323 1377
 		{
1324
-			if (!empty($user_profile[$a_member]['additional_groups']))
1325
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1326
-			else
1327
-				$groups = array($user_profile[$a_member]['id_group']);
1378
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1379
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1380
+			} else {
1381
+							$groups = array($user_profile[$a_member]['id_group']);
1382
+			}
1328 1383
 
1329 1384
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1330 1385
 
@@ -1337,8 +1392,9 @@  discard block
 block discarded – undo
1337 1392
 
1338 1393
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1339 1394
 	{
1340
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1341
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1395
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1396
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1397
+		}
1342 1398
 	}
1343 1399
 
1344 1400
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1364,14 +1420,17 @@  discard block
 block discarded – undo
1364 1420
 		foreach ($temp_mods as $id)
1365 1421
 		{
1366 1422
 			// By popular demand, don't show admins or global moderators as moderators.
1367
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1368
-				$user_profile[$id]['member_group'] = $row['member_group'];
1423
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1424
+							$user_profile[$id]['member_group'] = $row['member_group'];
1425
+			}
1369 1426
 
1370 1427
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1371
-			if (!empty($row['icons']))
1372
-				$user_profile[$id]['icons'] = $row['icons'];
1373
-			if (!empty($row['member_group_color']))
1374
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1428
+			if (!empty($row['icons'])) {
1429
+							$user_profile[$id]['icons'] = $row['icons'];
1430
+			}
1431
+			if (!empty($row['member_group_color'])) {
1432
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1433
+			}
1375 1434
 		}
1376 1435
 	}
1377 1436
 
@@ -1393,12 +1452,14 @@  discard block
 block discarded – undo
1393 1452
 	static $loadedLanguages = array();
1394 1453
 
1395 1454
 	// If this person's data is already loaded, skip it.
1396
-	if (isset($dataLoaded[$user]))
1397
-		return true;
1455
+	if (isset($dataLoaded[$user])) {
1456
+			return true;
1457
+	}
1398 1458
 
1399 1459
 	// We can't load guests or members not loaded by loadMemberData()!
1400
-	if ($user == 0)
1401
-		return false;
1460
+	if ($user == 0) {
1461
+			return false;
1462
+	}
1402 1463
 	if (!isset($user_profile[$user]))
1403 1464
 	{
1404 1465
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1424,12 +1485,16 @@  discard block
 block discarded – undo
1424 1485
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1425 1486
 
1426 1487
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1427
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1488
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1489
+		//icon is set and exists
1428 1490
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1429
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1491
+	} elseif (isset($profile['icons'][1])) {
1492
+		//icon is set and doesn't exist, fallback to default
1430 1493
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1431
-	else //not set, bye bye
1494
+	} else {
1495
+		//not set, bye bye
1432 1496
 		$group_icon_url = '';
1497
+	}
1433 1498
 
1434 1499
 	// These minimal values are always loaded
1435 1500
 	$memberContext[$user] = array(
@@ -1448,8 +1513,9 @@  discard block
 block discarded – undo
1448 1513
 	if ($context['loadMemberContext_set'] != 'minimal')
1449 1514
 	{
1450 1515
 		// Go the extra mile and load the user's native language name.
1451
-		if (empty($loadedLanguages))
1452
-			$loadedLanguages = getLanguages();
1516
+		if (empty($loadedLanguages)) {
1517
+					$loadedLanguages = getLanguages();
1518
+		}
1453 1519
 
1454 1520
 		$memberContext[$user] += array(
1455 1521
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1504,31 +1570,33 @@  discard block
 block discarded – undo
1504 1570
 	{
1505 1571
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1506 1572
 		{
1507
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1508
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1509
-			else
1510
-				$image = get_gravatar_url($profile['email_address']);
1511
-		}
1512
-		else
1573
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1574
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1575
+			} else {
1576
+							$image = get_gravatar_url($profile['email_address']);
1577
+			}
1578
+		} else
1513 1579
 		{
1514 1580
 			// So it's stored in the member table?
1515 1581
 			if (!empty($profile['avatar']))
1516 1582
 			{
1517 1583
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1584
+			} elseif (!empty($profile['filename'])) {
1585
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1518 1586
 			}
1519
-			elseif (!empty($profile['filename']))
1520
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1521 1587
 			// Right... no avatar...use the default one
1522
-			else
1523
-				$image = $modSettings['avatar_url'] . '/default.png';
1588
+			else {
1589
+							$image = $modSettings['avatar_url'] . '/default.png';
1590
+			}
1524 1591
 		}
1525
-		if (!empty($image))
1526
-			$memberContext[$user]['avatar'] = array(
1592
+		if (!empty($image)) {
1593
+					$memberContext[$user]['avatar'] = array(
1527 1594
 				'name' => $profile['avatar'],
1528 1595
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1529 1596
 				'href' => $image,
1530 1597
 				'url' => $image,
1531 1598
 			);
1599
+		}
1532 1600
 	}
1533 1601
 
1534 1602
 	// Are we also loading the members custom fields into context?
@@ -1536,35 +1604,41 @@  discard block
 block discarded – undo
1536 1604
 	{
1537 1605
 		$memberContext[$user]['custom_fields'] = array();
1538 1606
 
1539
-		if (!isset($context['display_fields']))
1540
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1607
+		if (!isset($context['display_fields'])) {
1608
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1609
+		}
1541 1610
 
1542 1611
 		foreach ($context['display_fields'] as $custom)
1543 1612
 		{
1544
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1545
-				continue;
1613
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1614
+							continue;
1615
+			}
1546 1616
 
1547 1617
 			$value = $profile['options'][$custom['col_name']];
1548 1618
 
1549 1619
 			// Don't show the "disabled" option for the "gender" field.
1550
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1551
-				continue;
1620
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1621
+							continue;
1622
+			}
1552 1623
 
1553 1624
 			// BBC?
1554
-			if ($custom['bbc'])
1555
-				$value = parse_bbc($value);
1625
+			if ($custom['bbc']) {
1626
+							$value = parse_bbc($value);
1627
+			}
1556 1628
 			// ... or checkbox?
1557
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1558
-				$value = $value ? $txt['yes'] : $txt['no'];
1629
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1630
+							$value = $value ? $txt['yes'] : $txt['no'];
1631
+			}
1559 1632
 
1560 1633
 			// Enclosing the user input within some other text?
1561
-			if (!empty($custom['enclose']))
1562
-				$value = strtr($custom['enclose'], array(
1634
+			if (!empty($custom['enclose'])) {
1635
+							$value = strtr($custom['enclose'], array(
1563 1636
 					'{SCRIPTURL}' => $scripturl,
1564 1637
 					'{IMAGES_URL}' => $settings['images_url'],
1565 1638
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1566 1639
 					'{INPUT}' => $value,
1567 1640
 				));
1641
+			}
1568 1642
 
1569 1643
 			$memberContext[$user]['custom_fields'][] = array(
1570 1644
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1591,8 +1665,9 @@  discard block
 block discarded – undo
1591 1665
 	global $smcFunc, $txt, $scripturl, $settings;
1592 1666
 
1593 1667
 	// Do not waste my time...
1594
-	if (empty($users) || empty($params))
1595
-		return false;
1668
+	if (empty($users) || empty($params)) {
1669
+			return false;
1670
+	}
1596 1671
 
1597 1672
 	// Make sure it's an array.
1598 1673
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1616,31 +1691,36 @@  discard block
 block discarded – undo
1616 1691
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1617 1692
 	{
1618 1693
 		// BBC?
1619
-		if (!empty($row['bbc']))
1620
-			$row['value'] = parse_bbc($row['value']);
1694
+		if (!empty($row['bbc'])) {
1695
+					$row['value'] = parse_bbc($row['value']);
1696
+		}
1621 1697
 
1622 1698
 		// ... or checkbox?
1623
-		elseif (isset($row['type']) && $row['type'] == 'check')
1624
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1699
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1700
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1701
+		}
1625 1702
 
1626 1703
 		// Enclosing the user input within some other text?
1627
-		if (!empty($row['enclose']))
1628
-			$row['value'] = strtr($row['enclose'], array(
1704
+		if (!empty($row['enclose'])) {
1705
+					$row['value'] = strtr($row['enclose'], array(
1629 1706
 				'{SCRIPTURL}' => $scripturl,
1630 1707
 				'{IMAGES_URL}' => $settings['images_url'],
1631 1708
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1632 1709
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1633 1710
 			));
1711
+		}
1634 1712
 
1635 1713
 		// Send a simple array if there is just 1 param
1636
-		if (count($params) == 1)
1637
-			$return[$row['id_member']] = $row;
1714
+		if (count($params) == 1) {
1715
+					$return[$row['id_member']] = $row;
1716
+		}
1638 1717
 
1639 1718
 		// More than 1? knock yourself out...
1640 1719
 		else
1641 1720
 		{
1642
-			if (!isset($return[$row['id_member']]))
1643
-				$return[$row['id_member']] = array();
1721
+			if (!isset($return[$row['id_member']])) {
1722
+							$return[$row['id_member']] = array();
1723
+			}
1644 1724
 
1645 1725
 			$return[$row['id_member']][$row['variable']] = $row;
1646 1726
 		}
@@ -1674,8 +1754,9 @@  discard block
 block discarded – undo
1674 1754
 	global $context;
1675 1755
 
1676 1756
 	// Don't know any browser!
1677
-	if (empty($context['browser']))
1678
-		detectBrowser();
1757
+	if (empty($context['browser'])) {
1758
+			detectBrowser();
1759
+	}
1679 1760
 
1680 1761
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1681 1762
 }
@@ -1693,8 +1774,9 @@  discard block
 block discarded – undo
1693 1774
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1694 1775
 
1695 1776
 	// The theme was specified by parameter.
1696
-	if (!empty($id_theme))
1697
-		$id_theme = (int) $id_theme;
1777
+	if (!empty($id_theme)) {
1778
+			$id_theme = (int) $id_theme;
1779
+	}
1698 1780
 	// The theme was specified by REQUEST.
1699 1781
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1700 1782
 	{
@@ -1702,54 +1784,61 @@  discard block
 block discarded – undo
1702 1784
 		$_SESSION['id_theme'] = $id_theme;
1703 1785
 	}
1704 1786
 	// The theme was specified by REQUEST... previously.
1705
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1706
-		$id_theme = (int) $_SESSION['id_theme'];
1787
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1788
+			$id_theme = (int) $_SESSION['id_theme'];
1789
+	}
1707 1790
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1708
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1709
-		$id_theme = $user_info['theme'];
1791
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1792
+			$id_theme = $user_info['theme'];
1793
+	}
1710 1794
 	// The theme was specified by the board.
1711
-	elseif (!empty($board_info['theme']))
1712
-		$id_theme = $board_info['theme'];
1795
+	elseif (!empty($board_info['theme'])) {
1796
+			$id_theme = $board_info['theme'];
1797
+	}
1713 1798
 	// The theme is the forum's default.
1714
-	else
1715
-		$id_theme = $modSettings['theme_guests'];
1799
+	else {
1800
+			$id_theme = $modSettings['theme_guests'];
1801
+	}
1716 1802
 
1717 1803
 	// We already load the basic stuff?
1718 1804
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1719 1805
 	{
1720 1806
 		// Verify the id_theme... no foul play.
1721 1807
 		// Always allow the board specific theme, if they are overriding.
1722
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1723
-			$id_theme = $board_info['theme'];
1808
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1809
+					$id_theme = $board_info['theme'];
1810
+		}
1724 1811
 		// If they have specified a particular theme to use with SSI allow it to be used.
1725
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1726
-			$id_theme = (int) $id_theme;
1727
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1812
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1813
+					$id_theme = (int) $id_theme;
1814
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1728 1815
 		{
1729 1816
 			$themes = explode(',', $modSettings['enableThemes']);
1730
-			if (!in_array($id_theme, $themes))
1731
-				$id_theme = $modSettings['theme_guests'];
1732
-			else
1733
-				$id_theme = (int) $id_theme;
1817
+			if (!in_array($id_theme, $themes)) {
1818
+							$id_theme = $modSettings['theme_guests'];
1819
+			} else {
1820
+							$id_theme = (int) $id_theme;
1821
+			}
1822
+		} else {
1823
+					$id_theme = (int) $id_theme;
1734 1824
 		}
1735
-		else
1736
-			$id_theme = (int) $id_theme;
1737 1825
 
1738 1826
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1739 1827
 
1740 1828
 		// Disable image proxy if we don't have SSL enabled
1741
-		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1742
-			$image_proxy_enabled = false;
1829
+		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1830
+					$image_proxy_enabled = false;
1831
+		}
1743 1832
 
1744 1833
 		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'])
1745 1834
 		{
1746 1835
 			$themeData = $temp;
1747 1836
 			$flag = true;
1837
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1838
+					$themeData = $temp + array($member => array());
1839
+		} else {
1840
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1748 1841
 		}
1749
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1750
-			$themeData = $temp + array($member => array());
1751
-		else
1752
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1753 1842
 
1754 1843
 		if (empty($flag))
1755 1844
 		{
@@ -1768,31 +1857,37 @@  discard block
 block discarded – undo
1768 1857
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1769 1858
 			{
1770 1859
 				// There are just things we shouldn't be able to change as members.
1771
-				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')))
1772
-					continue;
1860
+				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'))) {
1861
+									continue;
1862
+				}
1773 1863
 
1774 1864
 				// If this is the theme_dir of the default theme, store it.
1775
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1776
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1865
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1866
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1867
+				}
1777 1868
 
1778 1869
 				// If this isn't set yet, is a theme option, or is not the default theme..
1779
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1780
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1870
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1871
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1872
+				}
1781 1873
 			}
1782 1874
 			$smcFunc['db_free_result']($result);
1783 1875
 
1784
-			if (!empty($themeData[-1]))
1785
-				foreach ($themeData[-1] as $k => $v)
1876
+			if (!empty($themeData[-1])) {
1877
+							foreach ($themeData[-1] as $k => $v)
1786 1878
 				{
1787 1879
 					if (!isset($themeData[$member][$k]))
1788 1880
 						$themeData[$member][$k] = $v;
1881
+			}
1789 1882
 				}
1790 1883
 
1791
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1792
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1884
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1885
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1886
+			}
1793 1887
 			// Only if we didn't already load that part of the cache...
1794
-			elseif (!isset($temp))
1795
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1888
+			elseif (!isset($temp)) {
1889
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1890
+			}
1796 1891
 		}
1797 1892
 
1798 1893
 		$settings = $themeData[0];
@@ -1809,22 +1904,26 @@  discard block
 block discarded – undo
1809 1904
 		$settings['template_dirs'][] = $settings['theme_dir'];
1810 1905
 
1811 1906
 		// Based on theme (if there is one).
1812
-		if (!empty($settings['base_theme_dir']))
1813
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1907
+		if (!empty($settings['base_theme_dir'])) {
1908
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1909
+		}
1814 1910
 
1815 1911
 		// Lastly the default theme.
1816
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1817
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1912
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1913
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1914
+		}
1818 1915
 	}
1819 1916
 	
1820 1917
 
1821
-	if (!$initialize)
1822
-		return;
1918
+	if (!$initialize) {
1919
+			return;
1920
+	}
1823 1921
 
1824 1922
 	// Check to see if we're forcing SSL
1825 1923
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1826
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1827
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1924
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1925
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1926
+	}
1828 1927
 
1829 1928
 	// Check to see if they're accessing it from the wrong place.
1830 1929
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1832,8 +1931,9 @@  discard block
 block discarded – undo
1832 1931
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1833 1932
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1834 1933
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1835
-		if ($temp != '/')
1836
-			$detected_url .= $temp;
1934
+		if ($temp != '/') {
1935
+					$detected_url .= $temp;
1936
+		}
1837 1937
 	}
1838 1938
 	if (isset($detected_url) && $detected_url != $boardurl)
1839 1939
 	{
@@ -1845,8 +1945,9 @@  discard block
 block discarded – undo
1845 1945
 			foreach ($aliases as $alias)
1846 1946
 			{
1847 1947
 				// Rip off all the boring parts, spaces, etc.
1848
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1849
-					$do_fix = true;
1948
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1949
+									$do_fix = true;
1950
+				}
1850 1951
 			}
1851 1952
 		}
1852 1953
 
@@ -1854,20 +1955,22 @@  discard block
 block discarded – undo
1854 1955
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1855 1956
 		{
1856 1957
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1857
-			if (empty($_GET))
1858
-				redirectexit('wwwRedirect');
1859
-			else
1958
+			if (empty($_GET)) {
1959
+							redirectexit('wwwRedirect');
1960
+			} else
1860 1961
 			{
1861 1962
 				list ($k, $v) = each($_GET);
1862 1963
 
1863
-				if ($k != 'wwwRedirect')
1864
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1964
+				if ($k != 'wwwRedirect') {
1965
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1966
+				}
1865 1967
 			}
1866 1968
 		}
1867 1969
 
1868 1970
 		// #3 is just a check for SSL...
1869
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1870
-			$do_fix = true;
1971
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1972
+					$do_fix = true;
1973
+		}
1871 1974
 
1872 1975
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1873 1976
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1901,8 +2004,9 @@  discard block
 block discarded – undo
1901 2004
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1902 2005
 				}
1903 2006
 			}
1904
-			foreach ($context['linktree'] as $k => $dummy)
1905
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2007
+			foreach ($context['linktree'] as $k => $dummy) {
2008
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2009
+			}
1906 2010
 		}
1907 2011
 	}
1908 2012
 	// Set up the contextual user array.
@@ -1921,16 +2025,16 @@  discard block
 block discarded – undo
1921 2025
 			'email' => $user_info['email'],
1922 2026
 			'ignoreusers' => $user_info['ignoreusers'],
1923 2027
 		);
1924
-		if (!$context['user']['is_guest'])
1925
-			$context['user']['name'] = $user_info['name'];
1926
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1927
-			$context['user']['name'] = $txt['guest_title'];
2028
+		if (!$context['user']['is_guest']) {
2029
+					$context['user']['name'] = $user_info['name'];
2030
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2031
+					$context['user']['name'] = $txt['guest_title'];
2032
+		}
1928 2033
 
1929 2034
 		// Determine the current smiley set.
1930 2035
 		$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'];
1931 2036
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1932
-	}
1933
-	else
2037
+	} else
1934 2038
 	{
1935 2039
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1936 2040
 		$context['user'] = array(
@@ -1964,18 +2068,24 @@  discard block
 block discarded – undo
1964 2068
 	}
1965 2069
 
1966 2070
 	// Some basic information...
1967
-	if (!isset($context['html_headers']))
1968
-		$context['html_headers'] = '';
1969
-	if (!isset($context['javascript_files']))
1970
-		$context['javascript_files'] = array();
1971
-	if (!isset($context['css_files']))
1972
-		$context['css_files'] = array();
1973
-	if (!isset($context['css_header']))
1974
-		$context['css_header'] = array();
1975
-	if (!isset($context['javascript_inline']))
1976
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1977
-	if (!isset($context['javascript_vars']))
1978
-		$context['javascript_vars'] = array();
2071
+	if (!isset($context['html_headers'])) {
2072
+			$context['html_headers'] = '';
2073
+	}
2074
+	if (!isset($context['javascript_files'])) {
2075
+			$context['javascript_files'] = array();
2076
+	}
2077
+	if (!isset($context['css_files'])) {
2078
+			$context['css_files'] = array();
2079
+	}
2080
+	if (!isset($context['css_header'])) {
2081
+			$context['css_header'] = array();
2082
+	}
2083
+	if (!isset($context['javascript_inline'])) {
2084
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2085
+	}
2086
+	if (!isset($context['javascript_vars'])) {
2087
+			$context['javascript_vars'] = array();
2088
+	}
1979 2089
 
1980 2090
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1981 2091
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1987,16 +2097,18 @@  discard block
 block discarded – undo
1987 2097
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1988 2098
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1989 2099
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1990
-	if (isset($modSettings['load_average']))
1991
-		$context['load_average'] = $modSettings['load_average'];
2100
+	if (isset($modSettings['load_average'])) {
2101
+			$context['load_average'] = $modSettings['load_average'];
2102
+	}
1992 2103
 
1993 2104
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1994 2105
 	detectBrowser();
1995 2106
 
1996 2107
 	// Set the top level linktree up.
1997 2108
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
1998
-	if (empty($context['linktree']))
1999
-		$context['linktree'] = array();
2109
+	if (empty($context['linktree'])) {
2110
+			$context['linktree'] = array();
2111
+	}
2000 2112
 	array_unshift($context['linktree'], array(
2001 2113
 		'url' => $scripturl,
2002 2114
 		'name' => $context['forum_name_html_safe']
@@ -2005,8 +2117,9 @@  discard block
 block discarded – undo
2005 2117
 	// This allows sticking some HTML on the page output - useful for controls.
2006 2118
 	$context['insert_after_template'] = '';
2007 2119
 
2008
-	if (!isset($txt))
2009
-		$txt = array();
2120
+	if (!isset($txt)) {
2121
+			$txt = array();
2122
+	}
2010 2123
 
2011 2124
 	$simpleActions = array(
2012 2125
 		'findmember',
@@ -2052,9 +2165,10 @@  discard block
 block discarded – undo
2052 2165
 
2053 2166
 	// See if theres any extra param to check.
2054 2167
 	$requiresXML = false;
2055
-	foreach ($extraParams as $key => $extra)
2056
-		if (isset($_REQUEST[$extra]))
2168
+	foreach ($extraParams as $key => $extra) {
2169
+			if (isset($_REQUEST[$extra]))
2057 2170
 			$requiresXML = true;
2171
+	}
2058 2172
 
2059 2173
 	// Output is fully XML, so no need for the index template.
2060 2174
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2069,37 +2183,39 @@  discard block
 block discarded – undo
2069 2183
 	{
2070 2184
 		loadLanguage('index+Modifications');
2071 2185
 		$context['template_layers'] = array();
2072
-	}
2073
-
2074
-	else
2186
+	} else
2075 2187
 	{
2076 2188
 		// Custom templates to load, or just default?
2077
-		if (isset($settings['theme_templates']))
2078
-			$templates = explode(',', $settings['theme_templates']);
2079
-		else
2080
-			$templates = array('index');
2189
+		if (isset($settings['theme_templates'])) {
2190
+					$templates = explode(',', $settings['theme_templates']);
2191
+		} else {
2192
+					$templates = array('index');
2193
+		}
2081 2194
 
2082 2195
 		// Load each template...
2083
-		foreach ($templates as $template)
2084
-			loadTemplate($template);
2196
+		foreach ($templates as $template) {
2197
+					loadTemplate($template);
2198
+		}
2085 2199
 
2086 2200
 		// ...and attempt to load their associated language files.
2087 2201
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2088 2202
 		loadLanguage($required_files, '', false);
2089 2203
 
2090 2204
 		// Custom template layers?
2091
-		if (isset($settings['theme_layers']))
2092
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2093
-		else
2094
-			$context['template_layers'] = array('html', 'body');
2205
+		if (isset($settings['theme_layers'])) {
2206
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2207
+		} else {
2208
+					$context['template_layers'] = array('html', 'body');
2209
+		}
2095 2210
 	}
2096 2211
 
2097 2212
 	// Initialize the theme.
2098 2213
 	loadSubTemplate('init', 'ignore');
2099 2214
 
2100 2215
 	// Allow overriding the board wide time/number formats.
2101
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2102
-		$user_info['time_format'] = $txt['time_format'];
2216
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2217
+			$user_info['time_format'] = $txt['time_format'];
2218
+	}
2103 2219
 
2104 2220
 	// Set the character set from the template.
2105 2221
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2107,12 +2223,14 @@  discard block
 block discarded – undo
2107 2223
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2108 2224
 
2109 2225
 	// Guests may still need a name.
2110
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2111
-		$context['user']['name'] = $txt['guest_title'];
2226
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2227
+			$context['user']['name'] = $txt['guest_title'];
2228
+	}
2112 2229
 
2113 2230
 	// Any theme-related strings that need to be loaded?
2114
-	if (!empty($settings['require_theme_strings']))
2115
-		loadLanguage('ThemeStrings', '', false);
2231
+	if (!empty($settings['require_theme_strings'])) {
2232
+			loadLanguage('ThemeStrings', '', false);
2233
+	}
2116 2234
 
2117 2235
 	// Make a special URL for the language.
2118 2236
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2123,8 +2241,9 @@  discard block
 block discarded – undo
2123 2241
 	// Here is my luvly Responsive CSS
2124 2242
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2125 2243
 
2126
-	if ($context['right_to_left'])
2127
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2244
+	if ($context['right_to_left']) {
2245
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2246
+	}
2128 2247
 
2129 2248
 	// We allow theme variants, because we're cool.
2130 2249
 	$context['theme_variant'] = '';
@@ -2132,14 +2251,17 @@  discard block
 block discarded – undo
2132 2251
 	if (!empty($settings['theme_variants']))
2133 2252
 	{
2134 2253
 		// Overriding - for previews and that ilk.
2135
-		if (!empty($_REQUEST['variant']))
2136
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2254
+		if (!empty($_REQUEST['variant'])) {
2255
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2256
+		}
2137 2257
 		// User selection?
2138
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2139
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2258
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2259
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2260
+		}
2140 2261
 		// If not a user variant, select the default.
2141
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2142
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2262
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2263
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2264
+		}
2143 2265
 
2144 2266
 		// Do this to keep things easier in the templates.
2145 2267
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2148,20 +2270,23 @@  discard block
 block discarded – undo
2148 2270
 		if (!empty($context['theme_variant']))
2149 2271
 		{
2150 2272
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2151
-			if ($context['right_to_left'])
2152
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2273
+			if ($context['right_to_left']) {
2274
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2275
+			}
2153 2276
 		}
2154 2277
 	}
2155 2278
 
2156 2279
 	// Let's be compatible with old themes!
2157
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2158
-		$context['template_layers'] = array('main');
2280
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2281
+			$context['template_layers'] = array('main');
2282
+	}
2159 2283
 
2160 2284
 	$context['tabindex'] = 1;
2161 2285
 
2162 2286
 	// Compatibility.
2163
-	if (!isset($settings['theme_version']))
2164
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2287
+	if (!isset($settings['theme_version'])) {
2288
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2289
+	}
2165 2290
 
2166 2291
 	// Default JS variables for use in every theme
2167 2292
 	$context['javascript_vars'] = array(
@@ -2180,18 +2305,18 @@  discard block
 block discarded – undo
2180 2305
 	);
2181 2306
 
2182 2307
 	// Add the JQuery library to the list of files to load.
2183
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2184
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2185
-
2186
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2187
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2188
-
2189
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2190
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2308
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2309
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2310
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2311
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2312
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2313
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2314
+	}
2191 2315
 
2192 2316
 	// Auto loading? template_javascript() will take care of the local half of this.
2193
-	else
2194
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2317
+	else {
2318
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2319
+	}
2195 2320
 
2196 2321
 	// Queue our JQuery plugins!
2197 2322
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2214,12 +2339,12 @@  discard block
 block discarded – undo
2214 2339
 			require_once($sourcedir . '/ScheduledTasks.php');
2215 2340
 
2216 2341
 			// What to do, what to do?!
2217
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2218
-				AutoTask();
2219
-			else
2220
-				ReduceMailQueue();
2221
-		}
2222
-		else
2342
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2343
+							AutoTask();
2344
+			} else {
2345
+							ReduceMailQueue();
2346
+			}
2347
+		} else
2223 2348
 		{
2224 2349
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2225 2350
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2270,8 +2395,9 @@  discard block
 block discarded – undo
2270 2395
 		foreach ($theme_includes as $include)
2271 2396
 		{
2272 2397
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2273
-			if (file_exists($include))
2274
-				require_once($include);
2398
+			if (file_exists($include)) {
2399
+							require_once($include);
2400
+			}
2275 2401
 		}
2276 2402
 	}
2277 2403
 
@@ -2301,16 +2427,19 @@  discard block
 block discarded – undo
2301 2427
 	// Do any style sheets first, cause we're easy with those.
2302 2428
 	if (!empty($style_sheets))
2303 2429
 	{
2304
-		if (!is_array($style_sheets))
2305
-			$style_sheets = array($style_sheets);
2430
+		if (!is_array($style_sheets)) {
2431
+					$style_sheets = array($style_sheets);
2432
+		}
2306 2433
 
2307
-		foreach ($style_sheets as $sheet)
2308
-			loadCSSFile($sheet . '.css', array(), $sheet);
2434
+		foreach ($style_sheets as $sheet) {
2435
+					loadCSSFile($sheet . '.css', array(), $sheet);
2436
+		}
2309 2437
 	}
2310 2438
 
2311 2439
 	// No template to load?
2312
-	if ($template_name === false)
2313
-		return true;
2440
+	if ($template_name === false) {
2441
+			return true;
2442
+	}
2314 2443
 
2315 2444
 	$loaded = false;
2316 2445
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2325,12 +2454,14 @@  discard block
 block discarded – undo
2325 2454
 
2326 2455
 	if ($loaded)
2327 2456
 	{
2328
-		if ($db_show_debug === true)
2329
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2457
+		if ($db_show_debug === true) {
2458
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2459
+		}
2330 2460
 
2331 2461
 		// If they have specified an initialization function for this template, go ahead and call it now.
2332
-		if (function_exists('template_' . $template_name . '_init'))
2333
-			call_user_func('template_' . $template_name . '_init');
2462
+		if (function_exists('template_' . $template_name . '_init')) {
2463
+					call_user_func('template_' . $template_name . '_init');
2464
+		}
2334 2465
 	}
2335 2466
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2336 2467
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2350,13 +2481,14 @@  discard block
 block discarded – undo
2350 2481
 		loadTemplate($template_name);
2351 2482
 	}
2352 2483
 	// Cause an error otherwise.
2353
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2354
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2355
-	elseif ($fatal)
2356
-		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'));
2357
-	else
2358
-		return false;
2359
-}
2484
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2485
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2486
+	} elseif ($fatal) {
2487
+			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'));
2488
+	} else {
2489
+			return false;
2490
+	}
2491
+	}
2360 2492
 
2361 2493
 /**
2362 2494
  * Load a sub-template.
@@ -2374,17 +2506,19 @@  discard block
 block discarded – undo
2374 2506
 {
2375 2507
 	global $context, $txt, $db_show_debug;
2376 2508
 
2377
-	if ($db_show_debug === true)
2378
-		$context['debug']['sub_templates'][] = $sub_template_name;
2509
+	if ($db_show_debug === true) {
2510
+			$context['debug']['sub_templates'][] = $sub_template_name;
2511
+	}
2379 2512
 
2380 2513
 	// Figure out what the template function is named.
2381 2514
 	$theme_function = 'template_' . $sub_template_name;
2382
-	if (function_exists($theme_function))
2383
-		$theme_function();
2384
-	elseif ($fatal === false)
2385
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2386
-	elseif ($fatal !== 'ignore')
2387
-		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'));
2515
+	if (function_exists($theme_function)) {
2516
+			$theme_function();
2517
+	} elseif ($fatal === false) {
2518
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2519
+	} elseif ($fatal !== 'ignore') {
2520
+			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'));
2521
+	}
2388 2522
 
2389 2523
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2390 2524
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2421,8 +2555,9 @@  discard block
 block discarded – undo
2421 2555
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2422 2556
 
2423 2557
 	// If this is an external file, automatically set this to false.
2424
-	if (!empty($params['external']))
2425
-		$params['minimize'] = false;
2558
+	if (!empty($params['external'])) {
2559
+			$params['minimize'] = false;
2560
+	}
2426 2561
 
2427 2562
 	// Account for shorthand like admin.css?alp21 filenames
2428 2563
 	$has_seed = strpos($fileName, '.css?');
@@ -2439,13 +2574,10 @@  discard block
 block discarded – undo
2439 2574
 			{
2440 2575
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2441 2576
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2577
+			} else {
2578
+							$fileUrl = false;
2442 2579
 			}
2443
-
2444
-			else
2445
-				$fileUrl = false;
2446
-		}
2447
-
2448
-		else
2580
+		} else
2449 2581
 		{
2450 2582
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2451 2583
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2460,12 +2592,14 @@  discard block
 block discarded – undo
2460 2592
 	}
2461 2593
 
2462 2594
 	// Add it to the array for use in the template
2463
-	if (!empty($fileName))
2464
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2595
+	if (!empty($fileName)) {
2596
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2597
+	}
2465 2598
 
2466
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2467
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2468
-}
2599
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2600
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2601
+	}
2602
+	}
2469 2603
 
2470 2604
 /**
2471 2605
  * Add a block of inline css code to be executed later
@@ -2482,8 +2616,9 @@  discard block
 block discarded – undo
2482 2616
 	global $context;
2483 2617
 
2484 2618
 	// Gotta add something...
2485
-	if (empty($css))
2486
-		return false;
2619
+	if (empty($css)) {
2620
+			return false;
2621
+	}
2487 2622
 
2488 2623
 	$context['css_header'][] = $css;
2489 2624
 }
@@ -2518,8 +2653,9 @@  discard block
 block discarded – undo
2518 2653
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2519 2654
 
2520 2655
 	// If this is an external file, automatically set this to false.
2521
-	if (!empty($params['external']))
2522
-		$params['minimize'] = false;
2656
+	if (!empty($params['external'])) {
2657
+			$params['minimize'] = false;
2658
+	}
2523 2659
 
2524 2660
 	// Account for shorthand like admin.js?alp21 filenames
2525 2661
 	$has_seed = strpos($fileName, '.js?');
@@ -2536,16 +2672,12 @@  discard block
 block discarded – undo
2536 2672
 			{
2537 2673
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2538 2674
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2539
-			}
2540
-
2541
-			else
2675
+			} else
2542 2676
 			{
2543 2677
 				$fileUrl = false;
2544 2678
 				$filePath = false;
2545 2679
 			}
2546
-		}
2547
-
2548
-		else
2680
+		} else
2549 2681
 		{
2550 2682
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2551 2683
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2560,9 +2692,10 @@  discard block
 block discarded – undo
2560 2692
 	}
2561 2693
 
2562 2694
 	// Add it to the array for use in the template
2563
-	if (!empty($fileName))
2564
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2565
-}
2695
+	if (!empty($fileName)) {
2696
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2697
+	}
2698
+	}
2566 2699
 
2567 2700
 /**
2568 2701
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2576,9 +2709,10 @@  discard block
 block discarded – undo
2576 2709
 {
2577 2710
 	global $context;
2578 2711
 
2579
-	if (!empty($key) && (!empty($value) || $value === '0'))
2580
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2581
-}
2712
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2713
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2714
+	}
2715
+	}
2582 2716
 
2583 2717
 /**
2584 2718
  * Add a block of inline Javascript code to be executed later
@@ -2595,8 +2729,9 @@  discard block
 block discarded – undo
2595 2729
 {
2596 2730
 	global $context;
2597 2731
 
2598
-	if (empty($javascript))
2599
-		return false;
2732
+	if (empty($javascript)) {
2733
+			return false;
2734
+	}
2600 2735
 
2601 2736
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2602 2737
 }
@@ -2617,15 +2752,18 @@  discard block
 block discarded – undo
2617 2752
 	static $already_loaded = array();
2618 2753
 
2619 2754
 	// Default to the user's language.
2620
-	if ($lang == '')
2621
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2755
+	if ($lang == '') {
2756
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2757
+	}
2622 2758
 
2623 2759
 	// Do we want the English version of language file as fallback?
2624
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2625
-		loadLanguage($template_name, 'english', false);
2760
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2761
+			loadLanguage($template_name, 'english', false);
2762
+	}
2626 2763
 
2627
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2628
-		return $lang;
2764
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2765
+			return $lang;
2766
+	}
2629 2767
 
2630 2768
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2631 2769
 	if (empty($settings['default_theme_dir']))
@@ -2636,8 +2774,9 @@  discard block
 block discarded – undo
2636 2774
 
2637 2775
 	// What theme are we in?
2638 2776
 	$theme_name = basename($settings['theme_url']);
2639
-	if (empty($theme_name))
2640
-		$theme_name = 'unknown';
2777
+	if (empty($theme_name)) {
2778
+			$theme_name = 'unknown';
2779
+	}
2641 2780
 
2642 2781
 	// For each file open it up and write it out!
2643 2782
 	foreach (explode('+', $template_name) as $template)
@@ -2679,8 +2818,9 @@  discard block
 block discarded – undo
2679 2818
 				$found = true;
2680 2819
 
2681 2820
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2682
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2683
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2821
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2822
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2823
+				}
2684 2824
 
2685 2825
 				break;
2686 2826
 			}
@@ -2720,8 +2860,9 @@  discard block
 block discarded – undo
2720 2860
 	}
2721 2861
 
2722 2862
 	// Keep track of what we're up to soldier.
2723
-	if ($db_show_debug === true)
2724
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2863
+	if ($db_show_debug === true) {
2864
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2865
+	}
2725 2866
 
2726 2867
 	// Remember what we have loaded, and in which language.
2727 2868
 	$already_loaded[$template_name] = $lang;
@@ -2767,8 +2908,9 @@  discard block
 block discarded – undo
2767 2908
 				)
2768 2909
 			);
2769 2910
 			// In the EXTREMELY unlikely event this happens, give an error message.
2770
-			if ($smcFunc['db_num_rows']($result) == 0)
2771
-				fatal_lang_error('parent_not_found', 'critical');
2911
+			if ($smcFunc['db_num_rows']($result) == 0) {
2912
+							fatal_lang_error('parent_not_found', 'critical');
2913
+			}
2772 2914
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2773 2915
 			{
2774 2916
 				if (!isset($boards[$row['id_board']]))
@@ -2785,8 +2927,8 @@  discard block
 block discarded – undo
2785 2927
 					);
2786 2928
 				}
2787 2929
 				// If a moderator exists for this board, add that moderator for all children too.
2788
-				if (!empty($row['id_moderator']))
2789
-					foreach ($boards as $id => $dummy)
2930
+				if (!empty($row['id_moderator'])) {
2931
+									foreach ($boards as $id => $dummy)
2790 2932
 					{
2791 2933
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2792 2934
 							'id' => $row['id_moderator'],
@@ -2794,11 +2936,12 @@  discard block
 block discarded – undo
2794 2936
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2795 2937
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2796 2938
 						);
2939
+				}
2797 2940
 					}
2798 2941
 
2799 2942
 				// If a moderator group exists for this board, add that moderator group for all children too
2800
-				if (!empty($row['id_moderator_group']))
2801
-					foreach ($boards as $id => $dummy)
2943
+				if (!empty($row['id_moderator_group'])) {
2944
+									foreach ($boards as $id => $dummy)
2802 2945
 					{
2803 2946
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2804 2947
 							'id' => $row['id_moderator_group'],
@@ -2806,6 +2949,7 @@  discard block
 block discarded – undo
2806 2949
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2807 2950
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2808 2951
 						);
2952
+				}
2809 2953
 					}
2810 2954
 			}
2811 2955
 			$smcFunc['db_free_result']($result);
@@ -2832,23 +2976,27 @@  discard block
 block discarded – undo
2832 2976
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2833 2977
 	{
2834 2978
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2835
-		if (empty($smcFunc['ucwords']))
2836
-			reloadSettings();
2979
+		if (empty($smcFunc['ucwords'])) {
2980
+					reloadSettings();
2981
+		}
2837 2982
 
2838 2983
 		// If we don't have our theme information yet, let's get it.
2839
-		if (empty($settings['default_theme_dir']))
2840
-			loadTheme(0, false);
2984
+		if (empty($settings['default_theme_dir'])) {
2985
+					loadTheme(0, false);
2986
+		}
2841 2987
 
2842 2988
 		// Default language directories to try.
2843 2989
 		$language_directories = array(
2844 2990
 			$settings['default_theme_dir'] . '/languages',
2845 2991
 		);
2846
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2847
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2992
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2993
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2994
+		}
2848 2995
 
2849 2996
 		// We possibly have a base theme directory.
2850
-		if (!empty($settings['base_theme_dir']))
2851
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2997
+		if (!empty($settings['base_theme_dir'])) {
2998
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2999
+		}
2852 3000
 
2853 3001
 		// Remove any duplicates.
2854 3002
 		$language_directories = array_unique($language_directories);
@@ -2862,20 +3010,21 @@  discard block
 block discarded – undo
2862 3010
 		foreach ($language_directories as $language_dir)
2863 3011
 		{
2864 3012
 			// Can't look in here... doesn't exist!
2865
-			if (!file_exists($language_dir))
2866
-				continue;
3013
+			if (!file_exists($language_dir)) {
3014
+							continue;
3015
+			}
2867 3016
 
2868 3017
 			$dir = dir($language_dir);
2869 3018
 			while ($entry = $dir->read())
2870 3019
 			{
2871 3020
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2872
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2873
-					continue;
2874
-
2875
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2876
-					$langName = $langList[$matches[1]];
3021
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3022
+									continue;
3023
+				}
2877 3024
 
2878
-				else
3025
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3026
+									$langName = $langList[$matches[1]];
3027
+				} else
2879 3028
 				{
2880 3029
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2881 3030
 
@@ -2916,12 +3065,14 @@  discard block
 block discarded – undo
2916 3065
 		}
2917 3066
 
2918 3067
 		// Do we need to store the lang list?
2919
-		if (empty($langList))
2920
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3068
+		if (empty($langList)) {
3069
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3070
+		}
2921 3071
 
2922 3072
 		// Let's cash in on this deal.
2923
-		if (!empty($modSettings['cache_enable']))
2924
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3073
+		if (!empty($modSettings['cache_enable'])) {
3074
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3075
+		}
2925 3076
 	}
2926 3077
 
2927 3078
 	return $context['languages'];
@@ -2944,8 +3095,9 @@  discard block
 block discarded – undo
2944 3095
 	global $modSettings, $options, $txt;
2945 3096
 	static $censor_vulgar = null, $censor_proper;
2946 3097
 
2947
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2948
-		return $text;
3098
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3099
+			return $text;
3100
+	}
2949 3101
 
2950 3102
 	// If they haven't yet been loaded, load them.
2951 3103
 	if ($censor_vulgar == null)
@@ -2973,9 +3125,9 @@  discard block
 block discarded – undo
2973 3125
 	{
2974 3126
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2975 3127
 		$text = $func($censor_vulgar, $censor_proper, $text);
3128
+	} else {
3129
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2976 3130
 	}
2977
-	else
2978
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2979 3131
 
2980 3132
 	return $text;
2981 3133
 }
@@ -3001,38 +3153,42 @@  discard block
 block discarded – undo
3001 3153
 	@ini_set('track_errors', '1');
3002 3154
 
3003 3155
 	// Don't include the file more than once, if $once is true.
3004
-	if ($once && in_array($filename, $templates))
3005
-		return;
3156
+	if ($once && in_array($filename, $templates)) {
3157
+			return;
3158
+	}
3006 3159
 	// Add this file to the include list, whether $once is true or not.
3007
-	else
3008
-		$templates[] = $filename;
3160
+	else {
3161
+			$templates[] = $filename;
3162
+	}
3009 3163
 
3010 3164
 	// Are we going to use eval?
3011 3165
 	if (empty($modSettings['disableTemplateEval']))
3012 3166
 	{
3013 3167
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3014 3168
 		$settings['current_include_filename'] = $filename;
3015
-	}
3016
-	else
3169
+	} else
3017 3170
 	{
3018 3171
 		$file_found = file_exists($filename);
3019 3172
 
3020
-		if ($once && $file_found)
3021
-			require_once($filename);
3022
-		elseif ($file_found)
3023
-			require($filename);
3173
+		if ($once && $file_found) {
3174
+					require_once($filename);
3175
+		} elseif ($file_found) {
3176
+					require($filename);
3177
+		}
3024 3178
 	}
3025 3179
 
3026 3180
 	if ($file_found !== true)
3027 3181
 	{
3028 3182
 		ob_end_clean();
3029
-		if (!empty($modSettings['enableCompressedOutput']))
3030
-			@ob_start('ob_gzhandler');
3031
-		else
3032
-			ob_start();
3183
+		if (!empty($modSettings['enableCompressedOutput'])) {
3184
+					@ob_start('ob_gzhandler');
3185
+		} else {
3186
+					ob_start();
3187
+		}
3033 3188
 
3034
-		if (isset($_GET['debug']))
3035
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3189
+		if (isset($_GET['debug'])) {
3190
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3191
+		}
3036 3192
 
3037 3193
 		// Don't cache error pages!!
3038 3194
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3051,12 +3207,13 @@  discard block
 block discarded – undo
3051 3207
 		echo '<!DOCTYPE html>
3052 3208
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3053 3209
 	<head>';
3054
-		if (isset($context['character_set']))
3055
-			echo '
3210
+		if (isset($context['character_set'])) {
3211
+					echo '
3056 3212
 		<meta charset="', $context['character_set'], '">';
3213
+		}
3057 3214
 
3058
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3059
-			echo '
3215
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3216
+					echo '
3060 3217
 		<title>', $mtitle, '</title>
3061 3218
 	</head>
3062 3219
 	<body>
@@ -3064,8 +3221,8 @@  discard block
 block discarded – undo
3064 3221
 		', $mmessage, '
3065 3222
 	</body>
3066 3223
 </html>';
3067
-		elseif (!allowedTo('admin_forum'))
3068
-			echo '
3224
+		} elseif (!allowedTo('admin_forum')) {
3225
+					echo '
3069 3226
 		<title>', $txt['template_parse_error'], '</title>
3070 3227
 	</head>
3071 3228
 	<body>
@@ -3073,16 +3230,18 @@  discard block
 block discarded – undo
3073 3230
 		', $txt['template_parse_error_message'], '
3074 3231
 	</body>
3075 3232
 </html>';
3076
-		else
3233
+		} else
3077 3234
 		{
3078 3235
 			require_once($sourcedir . '/Subs-Package.php');
3079 3236
 
3080 3237
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3081 3238
 			$error_array = error_get_last();
3082
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3083
-				$error = $error_array['message'];
3084
-			if (empty($error))
3085
-				$error = $txt['template_parse_errmsg'];
3239
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3240
+							$error = $error_array['message'];
3241
+			}
3242
+			if (empty($error)) {
3243
+							$error = $txt['template_parse_errmsg'];
3244
+			}
3086 3245
 
3087 3246
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3088 3247
 
@@ -3093,11 +3252,12 @@  discard block
 block discarded – undo
3093 3252
 		<h3>', $txt['template_parse_error'], '</h3>
3094 3253
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3095 3254
 
3096
-			if (!empty($error))
3097
-				echo '
3255
+			if (!empty($error)) {
3256
+							echo '
3098 3257
 		<hr>
3099 3258
 
3100 3259
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3260
+			}
3101 3261
 
3102 3262
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3103 3263
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3107,10 +3267,11 @@  discard block
 block discarded – undo
3107 3267
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3108 3268
 
3109 3269
 				// Fix the PHP code stuff...
3110
-				if (!isBrowser('gecko'))
3111
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3112
-				else
3113
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3270
+				if (!isBrowser('gecko')) {
3271
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3272
+				} else {
3273
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3274
+				}
3114 3275
 
3115 3276
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3116 3277
 				$j = -1;
@@ -3118,8 +3279,9 @@  discard block
 block discarded – undo
3118 3279
 				{
3119 3280
 					$j++;
3120 3281
 
3121
-					if (substr_count($line, '<br>') == 0)
3122
-						continue;
3282
+					if (substr_count($line, '<br>') == 0) {
3283
+											continue;
3284
+					}
3123 3285
 
3124 3286
 					$n = substr_count($line, '<br>');
3125 3287
 					for ($i = 0; $i < $n; $i++)
@@ -3138,38 +3300,42 @@  discard block
 block discarded – undo
3138 3300
 				// Figure out what the color coding was before...
3139 3301
 				$line = max($match[1] - 9, 1);
3140 3302
 				$last_line = '';
3141
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3142
-					if (strpos($data2[$line2], '<') !== false)
3303
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3304
+									if (strpos($data2[$line2], '<') !== false)
3143 3305
 					{
3144 3306
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3145 3307
 							$last_line = $color_match[1];
3308
+				}
3146 3309
 						break;
3147 3310
 					}
3148 3311
 
3149 3312
 				// Show the relevant lines...
3150 3313
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3151 3314
 				{
3152
-					if ($line == $match[1])
3153
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3315
+					if ($line == $match[1]) {
3316
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3317
+					}
3154 3318
 
3155 3319
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3156
-					if (isset($data2[$line]) && $data2[$line] != '')
3157
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3320
+					if (isset($data2[$line]) && $data2[$line] != '') {
3321
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3322
+					}
3158 3323
 
3159 3324
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3160 3325
 					{
3161 3326
 						$last_line = $color_match[1];
3162 3327
 						echo '</', substr($last_line, 1, 4), '>';
3328
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3329
+											$last_line = '';
3330
+					} elseif ($last_line != '' && $data2[$line] != '') {
3331
+											echo '</', substr($last_line, 1, 4), '>';
3163 3332
 					}
3164
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3165
-						$last_line = '';
3166
-					elseif ($last_line != '' && $data2[$line] != '')
3167
-						echo '</', substr($last_line, 1, 4), '>';
3168 3333
 
3169
-					if ($line == $match[1])
3170
-						echo '</pre></div><pre style="margin: 0;">';
3171
-					else
3172
-						echo "\n";
3334
+					if ($line == $match[1]) {
3335
+											echo '</pre></div><pre style="margin: 0;">';
3336
+					} else {
3337
+											echo "\n";
3338
+					}
3173 3339
 				}
3174 3340
 
3175 3341
 				echo '</pre></div>';
@@ -3193,8 +3359,9 @@  discard block
 block discarded – undo
3193 3359
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3194 3360
 
3195 3361
 	// Figure out what type of database we are using.
3196
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3197
-		$db_type = 'mysql';
3362
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3363
+			$db_type = 'mysql';
3364
+	}
3198 3365
 
3199 3366
 	// Load the file for the database.
3200 3367
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3202,8 +3369,9 @@  discard block
 block discarded – undo
3202 3369
 	$db_options = array();
3203 3370
 
3204 3371
 	// Add in the port if needed
3205
-	if (!empty($db_port))
3206
-		$db_options['port'] = $db_port;
3372
+	if (!empty($db_port)) {
3373
+			$db_options['port'] = $db_port;
3374
+	}
3207 3375
 
3208 3376
 	// 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.
3209 3377
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3222,13 +3390,15 @@  discard block
 block discarded – undo
3222 3390
 	}
3223 3391
 
3224 3392
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3225
-	if (!$db_connection)
3226
-		display_db_error();
3393
+	if (!$db_connection) {
3394
+			display_db_error();
3395
+	}
3227 3396
 
3228 3397
 	// If in SSI mode fix up the prefix.
3229
-	if (SMF == 'SSI')
3230
-		db_fix_prefix($db_prefix, $db_name);
3231
-}
3398
+	if (SMF == 'SSI') {
3399
+			db_fix_prefix($db_prefix, $db_name);
3400
+	}
3401
+	}
3232 3402
 
3233 3403
 /**
3234 3404
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3242,10 +3412,11 @@  discard block
 block discarded – undo
3242 3412
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3243 3413
 
3244 3414
 	// Not overriding this and we have a cacheAPI, send it back.
3245
-	if (empty($overrideCache) && is_object($cacheAPI))
3246
-		return $cacheAPI;
3247
-	elseif (is_null($cacheAPI))
3248
-		$cacheAPI = false;
3415
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3416
+			return $cacheAPI;
3417
+	} elseif (is_null($cacheAPI)) {
3418
+			$cacheAPI = false;
3419
+	}
3249 3420
 
3250 3421
 	// Make sure our class is in session.
3251 3422
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3266,8 +3437,9 @@  discard block
 block discarded – undo
3266 3437
 		if (!$testAPI->isSupported())
3267 3438
 		{
3268 3439
 			// Can we save ourselves?
3269
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3270
-				return loadCacheAccelerator(null, false);
3440
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3441
+							return loadCacheAccelerator(null, false);
3442
+			}
3271 3443
 			return false;
3272 3444
 		}
3273 3445
 
@@ -3279,9 +3451,9 @@  discard block
 block discarded – undo
3279 3451
 		{
3280 3452
 			$cacheAPI = $testAPI;
3281 3453
 			return $cacheAPI;
3454
+		} else {
3455
+					return $testAPI;
3282 3456
 		}
3283
-		else
3284
-			return $testAPI;
3285 3457
 	}
3286 3458
 }
3287 3459
 
@@ -3301,8 +3473,9 @@  discard block
 block discarded – undo
3301 3473
 
3302 3474
 	// @todo Why are we doing this if caching is disabled?
3303 3475
 
3304
-	if (function_exists('call_integration_hook'))
3305
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3476
+	if (function_exists('call_integration_hook')) {
3477
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3478
+	}
3306 3479
 
3307 3480
 	/* Refresh the cache if either:
3308 3481
 		1. Caching is disabled.
@@ -3316,16 +3489,19 @@  discard block
 block discarded – undo
3316 3489
 		require_once($sourcedir . '/' . $file);
3317 3490
 		$cache_block = call_user_func_array($function, $params);
3318 3491
 
3319
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3320
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3492
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3493
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3494
+		}
3321 3495
 	}
3322 3496
 
3323 3497
 	// Some cached data may need a freshening up after retrieval.
3324
-	if (!empty($cache_block['post_retri_eval']))
3325
-		eval($cache_block['post_retri_eval']);
3498
+	if (!empty($cache_block['post_retri_eval'])) {
3499
+			eval($cache_block['post_retri_eval']);
3500
+	}
3326 3501
 
3327
-	if (function_exists('call_integration_hook'))
3328
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3502
+	if (function_exists('call_integration_hook')) {
3503
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3504
+	}
3329 3505
 
3330 3506
 	return $cache_block['data'];
3331 3507
 }
@@ -3352,8 +3528,9 @@  discard block
 block discarded – undo
3352 3528
 	global $smcFunc, $cache_enable, $cacheAPI;
3353 3529
 	global $cache_hits, $cache_count, $db_show_debug;
3354 3530
 
3355
-	if (empty($cache_enable) || empty($cacheAPI))
3356
-		return;
3531
+	if (empty($cache_enable) || empty($cacheAPI)) {
3532
+			return;
3533
+	}
3357 3534
 
3358 3535
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3359 3536
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3366,12 +3543,14 @@  discard block
 block discarded – undo
3366 3543
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3367 3544
 	$cacheAPI->putData($key, $value, $ttl);
3368 3545
 
3369
-	if (function_exists('call_integration_hook'))
3370
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3546
+	if (function_exists('call_integration_hook')) {
3547
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3548
+	}
3371 3549
 
3372
-	if (isset($db_show_debug) && $db_show_debug === true)
3373
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3374
-}
3550
+	if (isset($db_show_debug) && $db_show_debug === true) {
3551
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3552
+	}
3553
+	}
3375 3554
 
3376 3555
 /**
3377 3556
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3387,8 +3566,9 @@  discard block
 block discarded – undo
3387 3566
 	global $smcFunc, $cache_enable, $cacheAPI;
3388 3567
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3389 3568
 
3390
-	if (empty($cache_enable) || empty($cacheAPI))
3391
-		return;
3569
+	if (empty($cache_enable) || empty($cacheAPI)) {
3570
+			return;
3571
+	}
3392 3572
 
3393 3573
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3394 3574
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3408,16 +3588,18 @@  discard block
 block discarded – undo
3408 3588
 
3409 3589
 		if (empty($value))
3410 3590
 		{
3411
-			if (!is_array($cache_misses))
3412
-				$cache_misses = array();
3591
+			if (!is_array($cache_misses)) {
3592
+							$cache_misses = array();
3593
+			}
3413 3594
 
3414 3595
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3415 3596
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3416 3597
 		}
3417 3598
 	}
3418 3599
 
3419
-	if (function_exists('call_integration_hook') && isset($value))
3420
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3600
+	if (function_exists('call_integration_hook') && isset($value)) {
3601
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3602
+	}
3421 3603
 
3422 3604
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3423 3605
 }
@@ -3439,8 +3621,9 @@  discard block
 block discarded – undo
3439 3621
 	global $cacheAPI;
3440 3622
 
3441 3623
 	// If we can't get to the API, can't do this.
3442
-	if (empty($cacheAPI))
3443
-		return;
3624
+	if (empty($cacheAPI)) {
3625
+			return;
3626
+	}
3444 3627
 
3445 3628
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3446 3629
 	$cacheAPI->cleanCache($type);
@@ -3465,8 +3648,9 @@  discard block
 block discarded – undo
3465 3648
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3466 3649
 
3467 3650
 	// Come on!
3468
-	if (empty($data))
3469
-		return array();
3651
+	if (empty($data)) {
3652
+			return array();
3653
+	}
3470 3654
 
3471 3655
 	// Set a nice default var.
3472 3656
 	$image = '';
@@ -3474,11 +3658,11 @@  discard block
 block discarded – undo
3474 3658
 	// Gravatar has been set as mandatory!
3475 3659
 	if (!empty($modSettings['gravatarOverride']))
3476 3660
 	{
3477
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3478
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3479
-
3480
-		else if (!empty($data['email']))
3481
-			$image = get_gravatar_url($data['email']);
3661
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3662
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3663
+		} else if (!empty($data['email'])) {
3664
+					$image = get_gravatar_url($data['email']);
3665
+		}
3482 3666
 	}
3483 3667
 
3484 3668
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3490,54 +3674,60 @@  discard block
 block discarded – undo
3490 3674
 			// Gravatar.
3491 3675
 			if (stristr($data['avatar'], 'gravatar://'))
3492 3676
 			{
3493
-				if ($data['avatar'] == 'gravatar://')
3494
-					$image = get_gravatar_url($data['email']);
3495
-
3496
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3497
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3677
+				if ($data['avatar'] == 'gravatar://') {
3678
+									$image = get_gravatar_url($data['email']);
3679
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3680
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3681
+				}
3498 3682
 			}
3499 3683
 
3500 3684
 			// External url.
3501 3685
 			else
3502 3686
 			{
3503 3687
 				// Using ssl?
3504
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3505
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3688
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3689
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3690
+				}
3506 3691
 
3507 3692
 				// Just a plain external url.
3508
-				else
3509
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3693
+				else {
3694
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3695
+				}
3510 3696
 			}
3511 3697
 		}
3512 3698
 
3513 3699
 		// Perhaps this user has an attachment as avatar...
3514
-		else if (!empty($data['filename']))
3515
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3700
+		else if (!empty($data['filename'])) {
3701
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3702
+		}
3516 3703
 
3517 3704
 		// Right... no avatar... use our default image.
3518
-		else
3519
-			$image = $modSettings['avatar_url'] . '/default.png';
3705
+		else {
3706
+					$image = $modSettings['avatar_url'] . '/default.png';
3707
+		}
3520 3708
 	}
3521 3709
 
3522 3710
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3523 3711
 
3524 3712
 	// 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.
3525
-	if (!empty($image))
3526
-		return array(
3713
+	if (!empty($image)) {
3714
+			return array(
3527 3715
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3528 3716
 			'image' => '<img class="avatar" src="' . $image . '" />',
3529 3717
 			'href' => $image,
3530 3718
 			'url' => $image,
3531 3719
 		);
3720
+	}
3532 3721
 
3533 3722
 	// Fallback to make life easier for everyone...
3534
-	else
3535
-		return array(
3723
+	else {
3724
+			return array(
3536 3725
 			'name' => '',
3537 3726
 			'image' => '',
3538 3727
 			'href' => '',
3539 3728
 			'url' => '',
3540 3729
 		);
3541
-}
3730
+	}
3731
+	}
3542 3732
 
3543 3733
 ?>
3544 3734
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
 
59 59
 	// Get the data and path to set it on.
60 60
 	$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
61
-	$dataAr = empty($id) ? array(0, '', 0, 'path' => $cookie_url[1]) : array($id, $password, time() + $cookie_length, $cookie_state,'path' => $cookie_url[1]);
61
+	$dataAr = empty($id) ? array(0, '', 0, 'path' => $cookie_url[1]) : array($id, $password, time() + $cookie_length, $cookie_state, 'path' => $cookie_url[1]);
62 62
 	$data = $smcFunc['json_encode']($dataAr);
63 63
 	
64 64
 	// Set the cookie, $_COOKIE, and session variable.
Please login to merge, or discard this patch.
Braces   +163 added lines, -117 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
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -43,15 +44,17 @@  discard block
 block discarded – undo
43 44
 		$array = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
44 45
 
45 46
 		// Legacy format
46
-		if (is_null($array))
47
-			$array = safe_unserialize($_COOKIE[$cookiename]);
47
+		if (is_null($array)) {
48
+					$array = safe_unserialize($_COOKIE[$cookiename]);
49
+		}
48 50
 
49 51
 		// Out with the old, in with the new!
50 52
 		if (isset($array[3]) && $array[3] != $cookie_state)
51 53
 		{
52 54
 			$cookie_url = url_parts($array[3] & 1 > 0, $array[3] & 2 > 0);
53
-			if (isset($_COOKIE[$cookiename]['path']))
54
-				$cookie_url[1] = $_COOKIE[$cookiename]['path'];
55
+			if (isset($_COOKIE[$cookiename]['path'])) {
56
+							$cookie_url[1] = $_COOKIE[$cookiename]['path'];
57
+			}
55 58
 			smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, 'path' => $cookie_url[1])), 1, $cookie_url[1], $cookie_url[0]);
56 59
 		}
57 60
 	}
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
 	smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
66 69
 
67 70
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
68
-	if (empty($id) && !empty($modSettings['globalCookies']))
69
-		smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
71
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
72
+			smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], '');
73
+	}
70 74
 
71 75
 	// Any alias URLs?  This is mainly for use with frames, etc.
72 76
 	if (!empty($modSettings['forum_alias_urls']))
@@ -82,8 +86,9 @@  discard block
 block discarded – undo
82 86
 
83 87
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
84 88
 
85
-			if ($cookie_url[0] == '')
86
-				$cookie_url[0] = strtok($alias, '/');
89
+			if ($cookie_url[0] == '') {
90
+							$cookie_url[0] = strtok($alias, '/');
91
+			}
87 92
 			
88 93
 			$dataAr['path'] = $cookie_url[1];
89 94
 			$data = $smcFunc['json_encode']($dataAr);
@@ -132,8 +137,9 @@  discard block
 block discarded – undo
132 137
 	$identifier = $cookiename . '_tfa';
133 138
 	$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
134 139
 
135
-	if ($preserve)
136
-		$cookie_length = 81600 * 30;
140
+	if ($preserve) {
141
+			$cookie_length = 81600 * 30;
142
+	}
137 143
 
138 144
 	// Get the data and path to set it on.
139 145
 	$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
@@ -143,8 +149,9 @@  discard block
 block discarded – undo
143 149
 	smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
144 150
 
145 151
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
146
-	if (empty($id) && !empty($modSettings['globalCookies']))
147
-		smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
152
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
153
+			smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
154
+	}
148 155
 
149 156
 	$_COOKIE[$identifier] = $data;
150 157
 }
@@ -166,23 +173,28 @@  discard block
 block discarded – undo
166 173
 	$parsed_url = parse_url($boardurl);
167 174
 
168 175
 	// Is local cookies off?
169
-	if (empty($parsed_url['path']) || !$local)
170
-		$parsed_url['path'] = '';
176
+	if (empty($parsed_url['path']) || !$local) {
177
+			$parsed_url['path'] = '';
178
+	}
171 179
 
172
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
173
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
180
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
181
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
182
+	}
174 183
 
175 184
 	// Globalize cookies across domains (filter out IP-addresses)?
176
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
177
-		$parsed_url['host'] = '.' . $parts[1];
185
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
186
+			$parsed_url['host'] = '.' . $parts[1];
187
+	}
178 188
 
179 189
 	// We shouldn't use a host at all if both options are off.
180
-	elseif (!$local && !$global)
181
-		$parsed_url['host'] = '';
190
+	elseif (!$local && !$global) {
191
+			$parsed_url['host'] = '';
192
+	}
182 193
 
183 194
 	// The host also shouldn't be set if there aren't any dots in it.
184
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
185
-		$parsed_url['host'] = '';
195
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
196
+			$parsed_url['host'] = '';
197
+	}
186 198
 
187 199
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
188 200
 }
@@ -201,8 +213,9 @@  discard block
 block discarded – undo
201 213
 	createToken('login');
202 214
 
203 215
 	// Never redirect to an attachment
204
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
205
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
216
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
217
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
218
+	}
206 219
 
207 220
 	$context['sub_template'] = 'kick_guest';
208 221
 	$context['page_title'] = $txt['login'];
@@ -257,10 +270,12 @@  discard block
 block discarded – undo
257 270
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
258 271
 		log_error($txt['security_wrong'], 'critical');
259 272
 
260
-		if (isset($_POST[$type . '_hash_pass']))
261
-			unset($_POST[$type . '_hash_pass']);
262
-		if (isset($_POST[$type . '_pass']))
263
-			unset($_POST[$type . '_pass']);
273
+		if (isset($_POST[$type . '_hash_pass'])) {
274
+					unset($_POST[$type . '_hash_pass']);
275
+		}
276
+		if (isset($_POST[$type . '_pass'])) {
277
+					unset($_POST[$type . '_pass']);
278
+		}
264 279
 
265 280
 		$context['incorrect_password'] = true;
266 281
 	}
@@ -273,15 +288,17 @@  discard block
 block discarded – undo
273 288
 
274 289
 	// Now go through $_POST.  Make sure the session hash is sent.
275 290
 	$_POST[$context['session_var']] = $context['session_id'];
276
-	foreach ($_POST as $k => $v)
277
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
291
+	foreach ($_POST as $k => $v) {
292
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
293
+	}
278 294
 
279 295
 	// Now we'll use the admin_login sub template of the Login template.
280 296
 	$context['sub_template'] = 'admin_login';
281 297
 
282 298
 	// And title the page something like "Login".
283
-	if (!isset($context['page_title']))
284
-		$context['page_title'] = $txt['login'];
299
+	if (!isset($context['page_title'])) {
300
+			$context['page_title'] = $txt['login'];
301
+	}
285 302
 
286 303
 	// The type of action.
287 304
 	$context['sessionCheckType'] = $type;
@@ -304,14 +321,15 @@  discard block
 block discarded – undo
304 321
 {
305 322
 	global $smcFunc;
306 323
 
307
-	if (!is_array($v))
308
-		return '
324
+	if (!is_array($v)) {
325
+			return '
309 326
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
310
-	else
327
+	} else
311 328
 	{
312 329
 		$ret = '';
313
-		foreach ($v as $k2 => $v2)
314
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
330
+		foreach ($v as $k2 => $v2) {
331
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
332
+		}
315 333
 
316 334
 		return $ret;
317 335
 	}
@@ -338,18 +356,20 @@  discard block
 block discarded – undo
338 356
 		foreach ($get as $k => $v)
339 357
 		{
340 358
 			// Only if it's not already in the $scripturl!
341
-			if (!isset($temp[$k]))
342
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
359
+			if (!isset($temp[$k])) {
360
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
361
+			}
343 362
 			// If it changed, put it out there, but with an ampersand.
344
-			elseif ($temp[$k] != $get[$k])
345
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
363
+			elseif ($temp[$k] != $get[$k]) {
364
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
365
+			}
346 366
 		}
347
-	}
348
-	else
367
+	} else
349 368
 	{
350 369
 		// Add up all the data from $_GET into get_data.
351
-		foreach ($get as $k => $v)
352
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
370
+		foreach ($get as $k => $v) {
371
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
372
+		}
353 373
 	}
354 374
 
355 375
 	$query_string = substr($query_string, 0, -1);
@@ -372,8 +392,9 @@  discard block
 block discarded – undo
372 392
 	global $scripturl, $user_info, $smcFunc;
373 393
 
374 394
 	// If it's not already an array, make it one.
375
-	if (!is_array($names))
376
-		$names = explode(',', $names);
395
+	if (!is_array($names)) {
396
+			$names = explode(',', $names);
397
+	}
377 398
 
378 399
 	$maybe_email = false;
379 400
 	foreach ($names as $i => $name)
@@ -384,10 +405,11 @@  discard block
 block discarded – undo
384 405
 		$maybe_email |= strpos($name, '@') !== false;
385 406
 
386 407
 		// Make it so standard wildcards will work. (* and ?)
387
-		if ($use_wildcards)
388
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
389
-		else
390
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
408
+		if ($use_wildcards) {
409
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
410
+		} else {
411
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
412
+		}
391 413
 	}
392 414
 
393 415
 	// What are we using to compare?
@@ -397,11 +419,12 @@  discard block
 block discarded – undo
397 419
 	$results = array();
398 420
 
399 421
 	// This ensures you can't search someones email address if you can't see it.
400
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
401
-		$email_condition = '
422
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
423
+			$email_condition = '
402 424
 			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
403
-	else
404
-		$email_condition = '';
425
+	} else {
426
+			$email_condition = '';
427
+	}
405 428
 
406 429
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
407 430
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -459,10 +482,11 @@  discard block
 block discarded – undo
459 482
 	$context['template_layers'] = array();
460 483
 	$context['sub_template'] = 'find_members';
461 484
 
462
-	if (isset($_REQUEST['search']))
463
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
464
-	else
465
-		$_REQUEST['start'] = 0;
485
+	if (isset($_REQUEST['search'])) {
486
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
487
+	} else {
488
+			$_REQUEST['start'] = 0;
489
+	}
466 490
 
467 491
 	// Allow the user to pass the input to be added to to the box.
468 492
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -503,10 +527,10 @@  discard block
 block discarded – undo
503 527
 		);
504 528
 
505 529
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
530
+	} else {
531
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
532
+	}
506 533
 	}
507
-	else
508
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
509
-}
510 534
 
511 535
 /**
512 536
  * Outputs each member name on its own line.
@@ -522,8 +546,9 @@  discard block
 block discarded – undo
522 546
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
523 547
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
524 548
 
525
-	if (function_exists('iconv'))
526
-		header('Content-Type: text/plain; charset=UTF-8');
549
+	if (function_exists('iconv')) {
550
+			header('Content-Type: text/plain; charset=UTF-8');
551
+	}
527 552
 
528 553
 	$request = $smcFunc['db_query']('', '
529 554
 		SELECT real_name
@@ -543,14 +568,16 @@  discard block
 block discarded – undo
543 568
 		if (function_exists('iconv'))
544 569
 		{
545 570
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
546
-			if ($utf8)
547
-				$row['real_name'] = $utf8;
571
+			if ($utf8) {
572
+							$row['real_name'] = $utf8;
573
+			}
548 574
 		}
549 575
 
550 576
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
551 577
 
552
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
553
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
578
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
579
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
580
+		}
554 581
 
555 582
 		echo $row['real_name'], "\n";
556 583
 	}
@@ -607,9 +634,9 @@  discard block
 block discarded – undo
607 634
 
608 635
 		// Update the database...
609 636
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
637
+	} else {
638
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
610 639
 	}
611
-	else
612
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
613 640
 
614 641
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
615 642
 
@@ -640,31 +667,37 @@  discard block
 block discarded – undo
640 667
 	$errors = array();
641 668
 
642 669
 	// Don't use too long a name.
643
-	if ($smcFunc['strlen']($username) > 25)
644
-		$errors[] = array('lang', 'error_long_name');
670
+	if ($smcFunc['strlen']($username) > 25) {
671
+			$errors[] = array('lang', 'error_long_name');
672
+	}
645 673
 
646 674
 	// No name?!  How can you register with no name?
647
-	if ($username == '')
648
-		$errors[] = array('lang', 'need_username');
675
+	if ($username == '') {
676
+			$errors[] = array('lang', 'need_username');
677
+	}
649 678
 
650 679
 	// Only these characters are permitted.
651
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
652
-		$errors[] = array('lang', 'error_invalid_characters_username');
680
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
681
+			$errors[] = array('lang', 'error_invalid_characters_username');
682
+	}
653 683
 
654
-	if (stristr($username, $txt['guest_title']) !== false)
655
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
684
+	if (stristr($username, $txt['guest_title']) !== false) {
685
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
686
+	}
656 687
 
657 688
 	if ($check_reserved_name)
658 689
 	{
659 690
 		require_once($sourcedir . '/Subs-Members.php');
660
-		if (isReservedName($username, $memID, false))
661
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
691
+		if (isReservedName($username, $memID, false)) {
692
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
693
+		}
662 694
 	}
663 695
 
664
-	if ($return_error)
665
-		return $errors;
666
-	elseif (empty($errors))
667
-		return null;
696
+	if ($return_error) {
697
+			return $errors;
698
+	} elseif (empty($errors)) {
699
+			return null;
700
+	}
668 701
 
669 702
 	loadLanguage('Errors');
670 703
 	$error = $errors[0];
@@ -690,22 +723,26 @@  discard block
 block discarded – undo
690 723
 	global $modSettings, $smcFunc;
691 724
 
692 725
 	// Perform basic requirements first.
693
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
694
-		return 'short';
726
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
727
+			return 'short';
728
+	}
695 729
 
696 730
 	// Is this enough?
697
-	if (empty($modSettings['password_strength']))
698
-		return null;
731
+	if (empty($modSettings['password_strength'])) {
732
+			return null;
733
+	}
699 734
 
700 735
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
701
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
702
-		return 'restricted_words';
703
-	elseif ($smcFunc['strpos']($password, $username) !== false)
704
-		return 'restricted_words';
736
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
737
+			return 'restricted_words';
738
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
739
+			return 'restricted_words';
740
+	}
705 741
 
706 742
 	// If just medium, we're done.
707
-	if ($modSettings['password_strength'] == 1)
708
-		return null;
743
+	if ($modSettings['password_strength'] == 1) {
744
+			return null;
745
+	}
709 746
 
710 747
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
711 748
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -737,14 +774,16 @@  discard block
 block discarded – undo
737 774
 			)
738 775
 		);
739 776
 		$groups = array();
740
-		while ($row = $smcFunc['db_fetch_assoc']($request))
741
-			$groups[] = $row['id_group'];
777
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
778
+					$groups[] = $row['id_group'];
779
+		}
742 780
 		$smcFunc['db_free_result']($request);
743 781
 
744
-		if (empty($groups))
745
-			$group_query = '0=1';
746
-		else
747
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
782
+		if (empty($groups)) {
783
+					$group_query = '0=1';
784
+		} else {
785
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
786
+		}
748 787
 	}
749 788
 
750 789
 	// Then, same again, just the boards this time!
@@ -754,10 +793,11 @@  discard block
 block discarded – undo
754 793
 	{
755 794
 		$boards = boardsAllowedTo('moderate_board', true);
756 795
 
757
-		if (empty($boards))
758
-			$board_query = '0=1';
759
-		else
760
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
796
+		if (empty($boards)) {
797
+					$board_query = '0=1';
798
+		} else {
799
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
800
+		}
761 801
 	}
762 802
 
763 803
 	// What boards are they the moderator of?
@@ -772,8 +812,9 @@  discard block
 block discarded – undo
772 812
 				'current_member' => $user_info['id'],
773 813
 			)
774 814
 		);
775
-		while ($row = $smcFunc['db_fetch_assoc']($request))
776
-			$boards_mod[] = $row['id_board'];
815
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
816
+					$boards_mod[] = $row['id_board'];
817
+		}
777 818
 		$smcFunc['db_free_result']($request);
778 819
 
779 820
 		// Can any of the groups they're in moderate any of the boards?
@@ -785,8 +826,9 @@  discard block
 block discarded – undo
785 826
 				'groups' => $user_info['groups'],
786 827
 			)
787 828
 		);
788
-		while ($row = $smcFunc['db_fetch_assoc']($request))
789
-			$boards_mod[] = $row['id_board'];
829
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
830
+					$boards_mod[] = $row['id_board'];
831
+		}
790 832
 		$smcFunc['db_free_result']($request);
791 833
 
792 834
 		// Just in case we've got duplicates here...
@@ -831,10 +873,12 @@  discard block
 block discarded – undo
831 873
 	global $modSettings;
832 874
 
833 875
 	// In case a customization wants to override the default settings
834
-	if ($httponly === null)
835
-		$httponly = !empty($modSettings['httponlyCookies']);
836
-	if ($secure === null)
837
-		$secure = !empty($modSettings['secureCookies']);
876
+	if ($httponly === null) {
877
+			$httponly = !empty($modSettings['httponlyCookies']);
878
+	}
879
+	if ($secure === null) {
880
+			$secure = !empty($modSettings['secureCookies']);
881
+	}
838 882
 
839 883
 	// Intercept cookie?
840 884
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -854,8 +898,9 @@  discard block
 block discarded – undo
854 898
 function hash_password($username, $password, $cost = null)
855 899
 {
856 900
 	global $sourcedir, $smcFunc, $modSettings;
857
-	if (!function_exists('password_hash'))
858
-		require_once($sourcedir . '/Subs-Password.php');
901
+	if (!function_exists('password_hash')) {
902
+			require_once($sourcedir . '/Subs-Password.php');
903
+	}
859 904
 
860 905
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
861 906
 
@@ -887,8 +932,9 @@  discard block
 block discarded – undo
887 932
 function hash_verify_password($username, $password, $hash)
888 933
 {
889 934
 	global $sourcedir, $smcFunc;
890
-	if (!function_exists('password_verify'))
891
-		require_once($sourcedir . '/Subs-Password.php');
935
+	if (!function_exists('password_verify')) {
936
+			require_once($sourcedir . '/Subs-Password.php');
937
+	}
892 938
 
893 939
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
894 940
 }
Please login to merge, or discard this patch.