Completed
Pull Request — release-2.1 (#4873)
by Fran
08:24
created
Themes/default/Login.template.php 1 patch
Braces   +44 added lines, -30 removed lines patch added patch discarded remove patch
@@ -28,15 +28,17 @@  discard block
 block discarded – undo
28 28
 				<form class="login" action="', $context['login_url'], '" name="frmLogin" id="frmLogin" method="post" accept-charset="', $context['character_set'], '">';
29 29
 
30 30
 	// Did they make a mistake last time?
31
-	if (!empty($context['login_errors']))
32
-		echo '
31
+	if (!empty($context['login_errors'])) {
32
+			echo '
33 33
 					<div class="errorbox">', implode('<br>', $context['login_errors']), '</div>
34 34
 					<br>';
35
+	}
35 36
 
36 37
 	// Or perhaps there's some special description for this time?
37
-	if (isset($context['description']))
38
-		echo '
38
+	if (isset($context['description'])) {
39
+			echo '
39 40
 					<div class="information">', $context['description'], '</div>';
41
+	}
40 42
 
41 43
 	// Now just get the basic information - username, password, etc.
42 44
 	echo '
@@ -55,19 +57,21 @@  discard block
 block discarded – undo
55 57
 						<dd>
56 58
 							<select name="cookielength" id="cookielength">';
57 59
 
58
-	foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt)
59
-		echo '
60
+	foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt) {
61
+			echo '
60 62
 								<option value="', $cookie_time, '"', $modSettings['cookieTime'] == $cookie_time ? ' selected' : '', '>', $txt[$cookie_txt], '</option>';
63
+	}
61 64
 
62 65
 	echo '
63 66
 							</select>
64 67
 						</dd>';
65 68
 
66 69
 	// If they have deleted their account, give them a chance to change their mind.
67
-	if (isset($context['login_show_undelete']))
68
-		echo '
70
+	if (isset($context['login_show_undelete'])) {
71
+			echo '
69 72
 						<dt class="alert">', $txt['undelete_account'], ':</dt>
70 73
 						<dd><input type="checkbox" name="undelete"></dd>';
74
+	}
71 75
 
72 76
 	echo '
73 77
 					</dl>
@@ -85,8 +89,8 @@  discard block
 block discarded – undo
85 89
 							document.getElementById("', !empty($context['from_ajax']) ? 'ajax_' : '', isset($context['default_username']) && $context['default_username'] != '' ? 'loginpass' : 'loginuser', '").focus();
86 90
 						}, 150);';
87 91
 
88
-	if (!empty($context['from_ajax']))
89
-		echo '
92
+	if (!empty($context['from_ajax'])) {
93
+			echo '
90 94
 						form = $("#frmLogin");
91 95
 						form.submit(function(e) {
92 96
 							e.preventDefault();
@@ -119,16 +123,18 @@  discard block
 block discarded – undo
119 123
 
120 124
 							return false;
121 125
 						});';
126
+	}
122 127
 
123 128
 	echo '
124 129
 					</script>
125 130
 				</form>';
126 131
 
127 132
 	// It is a long story as to why we have this when we're clearly not going to use it.
128
-	if (!empty($context['from_ajax']))
129
-		echo '
133
+	if (!empty($context['from_ajax'])) {
134
+			echo '
130 135
 				<br>
131 136
 				<a href="javascript:self.close();"></a>';
137
+	}
132 138
 
133 139
 	echo '
134 140
 			</div><!-- .roundframe -->
@@ -151,11 +157,12 @@  discard block
 block discarded – undo
151 157
 			</div>
152 158
 			<div class="roundframe">';
153 159
 
154
-	if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error']))
155
-		echo '
160
+	if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error'])) {
161
+			echo '
156 162
 				<div class="error">
157 163
 					', $txt['tfa_' . (!empty($context['tfa_error']) ? 'code_' : 'backup_') . 'invalid'], '
158 164
 				</div>';
165
+	}
159 166
 
160 167
 	echo '
161 168
 				<form action="', $context['tfa_url'], '" method="post" id="frmTfa">
@@ -183,8 +190,8 @@  discard block
 block discarded – undo
183 190
 				<script>
184 191
 					form = $("#frmTfa");';
185 192
 
186
-	if (!empty($context['from_ajax']))
187
-		echo '
193
+	if (!empty($context['from_ajax'])) {
194
+			echo '
188 195
 					form.submit(function(e) {
189 196
 						// If we are submitting backup code, let normal workflow follow since it redirects a couple times into a different page
190 197
 						if (form.find("input[name=tfa_backup]:first").val().length > 0)
@@ -203,6 +210,7 @@  discard block
 block discarded – undo
203 210
 
204 211
 						return false;
205 212
 					});';
213
+	}
206 214
 
207 215
 	echo '
208 216
 					form.find("input[name=backup]").click(function(e) {
@@ -234,10 +242,11 @@  discard block
 block discarded – undo
234 242
 			<p class="information centertext">
235 243
 				', empty($context['kick_message']) ? $txt['only_members_can_access'] : $context['kick_message'], '<br>';
236 244
 
237
-	if ($context['can_register'])
238
-		echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
239
-	else
240
-		echo $txt['login_below'];
245
+	if ($context['can_register']) {
246
+			echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
247
+	} else {
248
+			echo $txt['login_below'];
249
+	}
241 250
 
242 251
 	// And now the login information.
243 252
 	echo '
@@ -256,9 +265,10 @@  discard block
 block discarded – undo
256 265
 					<dd>
257 266
 							<select name="cookielength" id="cookielength">';
258 267
 
259
-	foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt)
260
-		echo '
268
+	foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt) {
269
+			echo '
261 270
 								<option value="', $cookie_time, '"', $modSettings['cookieTime'] == $cookie_time ? ' selected' : '', '>', $txt[$cookie_txt], '</option>';
271
+	}
262 272
 
263 273
 	echo '
264 274
 							</select>
@@ -315,9 +325,10 @@  discard block
 block discarded – undo
315 325
 					<dd>
316 326
 							<select name="cookielength" id="cookielength">';
317 327
 
318
-	foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt)
319
-		echo '
328
+	foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt) {
329
+			echo '
320 330
 								<option value="', $cookie_time, '"', $modSettings['cookieTime'] == $cookie_time ? ' selected' : '', '>', $txt[$cookie_txt], '</option>';
331
+	}
321 332
 
322 333
 	echo '
323 334
 							</select>
@@ -351,9 +362,10 @@  discard block
 block discarded – undo
351 362
 			</div>
352 363
 			<div class="roundframe centertext">';
353 364
 
354
-	if (!empty($context['incorrect_password']))
355
-		echo '
365
+	if (!empty($context['incorrect_password'])) {
366
+			echo '
356 367
 				<div class="error">', $txt['admin_incorrect_password'], '</div>';
368
+	}
357 369
 
358 370
 	echo '
359 371
 				<strong>', $txt['password'], ':</strong>
@@ -394,10 +406,11 @@  discard block
 block discarded – undo
394 406
 				<dl>';
395 407
 
396 408
 	// You didn't even have an ID?
397
-	if (empty($context['member_id']))
398
-		echo '
409
+	if (empty($context['member_id'])) {
410
+			echo '
399 411
 					<dt>', $txt['invalid_activation_username'], ':</dt>
400 412
 					<dd><input type="text" name="user" size="30"></dd>';
413
+	}
401 414
 
402 415
 	echo '
403 416
 					<dt>', $txt['invalid_activation_retry'], ':</dt>
@@ -434,13 +447,14 @@  discard block
 block discarded – undo
434 447
 					<dd><input type="password" name="passwd" size="30"></dd>
435 448
 				</dl>';
436 449
 
437
-	if ($context['can_activate'])
438
-		echo '
450
+	if ($context['can_activate']) {
451
+			echo '
439 452
 				<p>', $txt['invalid_activation_known'], '</p>
440 453
 				<dl>
441 454
 					<dt>', $txt['invalid_activation_retry'], ':</dt>
442 455
 					<dd><input type="text" name="code" size="30"></dd>
443 456
 				</dl>';
457
+	}
444 458
 
445 459
 	echo '
446 460
 				<p><input type="submit" value="', $txt['invalid_activation_resend'], '" class="button"></p>
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +154 added lines, -121 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -92,8 +95,9 @@  discard block
 block discarded – undo
92 95
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
93 96
 
94 97
 	// Check to ensure we're forcing SSL for authentication
95
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
96
-		fatal_lang_error('login_ssl_required');
98
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
99
+			fatal_lang_error('login_ssl_required');
100
+	}
97 101
 
98 102
 	// Load cookie authentication stuff.
99 103
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -107,23 +111,26 @@  discard block
 block discarded – undo
107 111
 	if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest'])
108 112
 	{
109 113
 		// First check for 2.1 json-format cookie in $_COOKIE
110
-		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1)
111
-			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
114
+		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) {
115
+					list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
116
+		}
112 117
 
113 118
 		// Try checking for 2.1 json-format cookie in $_SESSION
114
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1)
115
-			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
119
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) {
120
+					list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
121
+		}
116 122
 
117 123
 		// Next, try checking for 2.0 serialized string cookie in $_COOKIE
118
-		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1)
119
-			list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
124
+		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) {
125
+					list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
126
+		}
120 127
 
121 128
 		// Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION
122
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1)
123
-			list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
124
-
125
-		else
126
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
129
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) {
130
+					list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
131
+		} else {
132
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
133
+		}
127 134
 
128 135
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
129 136
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -143,24 +150,23 @@  discard block
 block discarded – undo
143 150
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
144 151
 	{
145 152
 		// Strike!  You're outta there!
146
-		if ($_GET['member'] != $user_info['id'])
147
-			fatal_lang_error('login_cookie_error', false);
153
+		if ($_GET['member'] != $user_info['id']) {
154
+					fatal_lang_error('login_cookie_error', false);
155
+		}
148 156
 
149 157
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
150 158
 
151 159
 		// Some whitelisting for login_url...
152
-		if (empty($_SESSION['login_url']))
153
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
154
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
160
+		if (empty($_SESSION['login_url'])) {
161
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
162
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
155 163
 		{
156 164
 			unset ($_SESSION['login_url']);
157 165
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
158
-		}
159
-		elseif (!empty($user_settings['tfa_secret']))
166
+		} elseif (!empty($user_settings['tfa_secret']))
160 167
 		{
161 168
 			redirectexit('action=logintfa');
162
-		}
163
-		else
169
+		} else
164 170
 		{
165 171
 			// Best not to clutter the session data too much...
166 172
 			$temp = $_SESSION['login_url'];
@@ -171,8 +177,9 @@  discard block
 block discarded – undo
171 177
 	}
172 178
 
173 179
 	// Beyond this point you are assumed to be a guest trying to login.
174
-	if (!$user_info['is_guest'])
175
-		redirectexit();
180
+	if (!$user_info['is_guest']) {
181
+			redirectexit();
182
+	}
176 183
 
177 184
 	// Are you guessing with a script?
178 185
 	checkSession();
@@ -180,18 +187,21 @@  discard block
 block discarded – undo
180 187
 	spamProtection('login');
181 188
 
182 189
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
183
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
184
-		$_SESSION['login_url'] = $_SESSION['old_url'];
190
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
191
+			$_SESSION['login_url'] = $_SESSION['old_url'];
192
+	}
185 193
 
186 194
 	// Been guessing a lot, haven't we?
187
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
188
-		fatal_lang_error('login_threshold_fail', 'login');
195
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
196
+			fatal_lang_error('login_threshold_fail', 'login');
197
+	}
189 198
 
190 199
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
191
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
192
-		$modSettings['cookieTime'] = 3153600;
193
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600))
194
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
200
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
201
+			$modSettings['cookieTime'] = 3153600;
202
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 3153600)) {
203
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
204
+	}
195 205
 
196 206
 	// Login Cookie times. Format: time => txt
197 207
 	$context['login_cookie_times'] = array(
@@ -320,8 +330,9 @@  discard block
 block discarded – undo
320 330
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
321 331
 
322 332
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
323
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
324
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
333
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
334
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
335
+			}
325 336
 
326 337
 			// phpBB3 users new hashing.  We now support it as well ;).
327 338
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -341,27 +352,29 @@  discard block
 block discarded – undo
341 352
 			// Some common md5 ones.
342 353
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
343 354
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
344
-		}
345
-		elseif (strlen($user_settings['passwd']) == 40)
355
+		} elseif (strlen($user_settings['passwd']) == 40)
346 356
 		{
347 357
 			// Maybe they are using a hash from before the password fix.
348 358
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
349 359
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
350 360
 
351 361
 			// BurningBoard3 style of hashing.
352
-			if (!empty($modSettings['enable_password_conversion']))
353
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
362
+			if (!empty($modSettings['enable_password_conversion'])) {
363
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
364
+			}
354 365
 
355 366
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
356 367
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
357 368
 			{
358 369
 				// Try iconv first, for no particular reason.
359
-				if (function_exists('iconv'))
360
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
370
+				if (function_exists('iconv')) {
371
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
372
+				}
361 373
 
362 374
 				// Say it aint so, iconv failed!
363
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
364
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
375
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
376
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
377
+				}
365 378
 			}
366 379
 		}
367 380
 
@@ -391,8 +404,9 @@  discard block
 block discarded – undo
391 404
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
392 405
 
393 406
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
394
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
395
-				redirectexit('action=reminder');
407
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
408
+							redirectexit('action=reminder');
409
+			}
396 410
 			// We'll give you another chance...
397 411
 			else
398 412
 			{
@@ -403,8 +417,7 @@  discard block
 block discarded – undo
403 417
 				return;
404 418
 			}
405 419
 		}
406
-	}
407
-	elseif (!empty($user_settings['passwd_flood']))
420
+	} elseif (!empty($user_settings['passwd_flood']))
408 421
 	{
409 422
 		// Let's be sure they weren't a little hacker.
410 423
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -421,8 +434,9 @@  discard block
 block discarded – undo
421 434
 	}
422 435
 
423 436
 	// Check their activation status.
424
-	if (!checkActivation())
425
-		return;
437
+	if (!checkActivation()) {
438
+			return;
439
+	}
426 440
 
427 441
 	DoLogin();
428 442
 }
@@ -434,8 +448,9 @@  discard block
 block discarded – undo
434 448
 {
435 449
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
436 450
 
437
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
438
-		fatal_lang_error('no_access', false);
451
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
452
+			fatal_lang_error('no_access', false);
453
+	}
439 454
 
440 455
 	loadLanguage('Profile');
441 456
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -443,8 +458,9 @@  discard block
 block discarded – undo
443 458
 	$member = $context['tfa_member'];
444 459
 
445 460
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
446
-	if (time() - $member['last_login'] < 120)
447
-		fatal_lang_error('tfa_wait', false);
461
+	if (time() - $member['last_login'] < 120) {
462
+			fatal_lang_error('tfa_wait', false);
463
+	}
448 464
 
449 465
 	$totp = new \TOTP\Auth($member['tfa_secret']);
450 466
 	$totp->setRange(1);
@@ -458,8 +474,9 @@  discard block
 block discarded – undo
458 474
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
459 475
 	{
460 476
 		// Check to ensure we're forcing SSL for authentication
461
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
462
-			fatal_lang_error('login_ssl_required');
477
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
478
+					fatal_lang_error('login_ssl_required');
479
+		}
463 480
 
464 481
 		$code = $_POST['tfa_code'];
465 482
 
@@ -469,20 +486,19 @@  discard block
 block discarded – undo
469 486
 
470 487
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
471 488
 			redirectexit();
472
-		}
473
-		else
489
+		} else
474 490
 		{
475 491
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
476 492
 
477 493
 			$context['tfa_error'] = true;
478 494
 			$context['tfa_value'] = $_POST['tfa_code'];
479 495
 		}
480
-	}
481
-	elseif (!empty($_POST['tfa_backup']))
496
+	} elseif (!empty($_POST['tfa_backup']))
482 497
 	{
483 498
 		// Check to ensure we're forcing SSL for authentication
484
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
485
-			fatal_lang_error('login_ssl_required');
499
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
500
+					fatal_lang_error('login_ssl_required');
501
+		}
486 502
 
487 503
 		$backup = $_POST['tfa_backup'];
488 504
 
@@ -496,8 +512,7 @@  discard block
 block discarded – undo
496 512
 			));
497 513
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
498 514
 			redirectexit('action=profile;area=tfasetup;backup');
499
-		}
500
-		else
515
+		} else
501 516
 		{
502 517
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
503 518
 
@@ -520,8 +535,9 @@  discard block
 block discarded – undo
520 535
 {
521 536
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
522 537
 
523
-	if (!isset($context['login_errors']))
524
-		$context['login_errors'] = array();
538
+	if (!isset($context['login_errors'])) {
539
+			$context['login_errors'] = array();
540
+	}
525 541
 
526 542
 	// What is the true activation status of this account?
527 543
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -533,8 +549,9 @@  discard block
 block discarded – undo
533 549
 		return false;
534 550
 	}
535 551
 	// Awaiting approval still?
536
-	elseif ($activation_status == 3)
537
-		fatal_lang_error('still_awaiting_approval', 'user');
552
+	elseif ($activation_status == 3) {
553
+			fatal_lang_error('still_awaiting_approval', 'user');
554
+	}
538 555
 	// Awaiting deletion, changed their mind?
539 556
 	elseif ($activation_status == 4)
540 557
 	{
@@ -542,8 +559,7 @@  discard block
 block discarded – undo
542 559
 		{
543 560
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
544 561
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
545
-		}
546
-		else
562
+		} else
547 563
 		{
548 564
 			$context['disable_login_hashing'] = true;
549 565
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -583,8 +599,9 @@  discard block
 block discarded – undo
583 599
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
584 600
 
585 601
 	// Reset the login threshold.
586
-	if (isset($_SESSION['failed_login']))
587
-		unset($_SESSION['failed_login']);
602
+	if (isset($_SESSION['failed_login'])) {
603
+			unset($_SESSION['failed_login']);
604
+	}
588 605
 
589 606
 	$user_info['is_guest'] = false;
590 607
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -606,16 +623,18 @@  discard block
 block discarded – undo
606 623
 			'id_member' => $user_info['id'],
607 624
 		)
608 625
 	);
609
-	if ($smcFunc['db_num_rows']($request) == 1)
610
-		$_SESSION['first_login'] = true;
611
-	else
612
-		unset($_SESSION['first_login']);
626
+	if ($smcFunc['db_num_rows']($request) == 1) {
627
+			$_SESSION['first_login'] = true;
628
+	} else {
629
+			unset($_SESSION['first_login']);
630
+	}
613 631
 	$smcFunc['db_free_result']($request);
614 632
 
615 633
 	// You've logged in, haven't you?
616 634
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
617
-	if (empty($user_settings['tfa_secret']))
618
-		$update['last_login'] = time();
635
+	if (empty($user_settings['tfa_secret'])) {
636
+			$update['last_login'] = time();
637
+	}
619 638
 	updateMemberData($user_info['id'], $update);
620 639
 
621 640
 	// Get rid of the online entry for that old guest....
@@ -629,8 +648,8 @@  discard block
 block discarded – undo
629 648
 	$_SESSION['log_time'] = 0;
630 649
 
631 650
 	// Log this entry, only if we have it enabled.
632
-	if (!empty($modSettings['loginHistoryDays']))
633
-		$smcFunc['db_insert']('insert',
651
+	if (!empty($modSettings['loginHistoryDays'])) {
652
+			$smcFunc['db_insert']('insert',
634 653
 			'{db_prefix}member_logins',
635 654
 			array(
636 655
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -642,13 +661,15 @@  discard block
 block discarded – undo
642 661
 				'id_member', 'time'
643 662
 			)
644 663
 		);
664
+	}
645 665
 
646 666
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
647
-	if (empty($maintenance) || allowedTo('admin_forum'))
648
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
649
-	else
650
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
651
-}
667
+	if (empty($maintenance) || allowedTo('admin_forum')) {
668
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
669
+	} else {
670
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
671
+	}
672
+	}
652 673
 
653 674
 /**
654 675
  * Logs the current user out of their account.
@@ -664,13 +685,15 @@  discard block
 block discarded – undo
664 685
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
665 686
 
666 687
 	// Make sure they aren't being auto-logged out.
667
-	if (!$internal)
668
-		checkSession('get');
688
+	if (!$internal) {
689
+			checkSession('get');
690
+	}
669 691
 
670 692
 	require_once($sourcedir . '/Subs-Auth.php');
671 693
 
672
-	if (isset($_SESSION['pack_ftp']))
673
-		$_SESSION['pack_ftp'] = null;
694
+	if (isset($_SESSION['pack_ftp'])) {
695
+			$_SESSION['pack_ftp'] = null;
696
+	}
674 697
 
675 698
 	// It won't be first login anymore.
676 699
 	unset($_SESSION['first_login']);
@@ -698,8 +721,9 @@  discard block
 block discarded – undo
698 721
 
699 722
 	// And some other housekeeping while we're at it.
700 723
 	$salt = substr(md5(mt_rand()), 0, 4);
701
-	if (!empty($user_info['id']))
702
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
724
+	if (!empty($user_info['id'])) {
725
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
726
+	}
703 727
 
704 728
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
705 729
 	{
@@ -712,14 +736,13 @@  discard block
 block discarded – undo
712 736
 	// Off to the merry board index we go!
713 737
 	if ($redirect)
714 738
 	{
715
-		if (empty($_SESSION['logout_url']))
716
-			redirectexit('', $context['server']['needs_login_fix']);
717
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
739
+		if (empty($_SESSION['logout_url'])) {
740
+					redirectexit('', $context['server']['needs_login_fix']);
741
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
718 742
 		{
719 743
 			unset ($_SESSION['logout_url']);
720 744
 			redirectexit();
721
-		}
722
-		else
745
+		} else
723 746
 		{
724 747
 			$temp = $_SESSION['logout_url'];
725 748
 			unset($_SESSION['logout_url']);
@@ -752,8 +775,9 @@  discard block
 block discarded – undo
752 775
 function phpBB3_password_check($passwd, $passwd_hash)
753 776
 {
754 777
 	// Too long or too short?
755
-	if (strlen($passwd_hash) != 34)
756
-		return;
778
+	if (strlen($passwd_hash) != 34) {
779
+			return;
780
+	}
757 781
 
758 782
 	// Range of characters allowed.
759 783
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -764,8 +788,9 @@  discard block
 block discarded – undo
764 788
 	$salt = substr($passwd_hash, 4, 8);
765 789
 
766 790
 	$hash = md5($salt . $passwd, true);
767
-	for (; $count != 0; --$count)
768
-		$hash = md5($hash . $passwd, true);
791
+	for (; $count != 0; --$count) {
792
+			$hash = md5($hash . $passwd, true);
793
+	}
769 794
 
770 795
 	$output = substr($passwd_hash, 0, 12);
771 796
 	$i = 0;
@@ -774,21 +799,25 @@  discard block
 block discarded – undo
774 799
 		$value = ord($hash[$i++]);
775 800
 		$output .= $range[$value & 0x3f];
776 801
 
777
-		if ($i < 16)
778
-			$value |= ord($hash[$i]) << 8;
802
+		if ($i < 16) {
803
+					$value |= ord($hash[$i]) << 8;
804
+		}
779 805
 
780 806
 		$output .= $range[($value >> 6) & 0x3f];
781 807
 
782
-		if ($i++ >= 16)
783
-			break;
808
+		if ($i++ >= 16) {
809
+					break;
810
+		}
784 811
 
785
-		if ($i < 16)
786
-			$value |= ord($hash[$i]) << 16;
812
+		if ($i < 16) {
813
+					$value |= ord($hash[$i]) << 16;
814
+		}
787 815
 
788 816
 		$output .= $range[($value >> 12) & 0x3f];
789 817
 
790
-		if ($i++ >= 16)
791
-			break;
818
+		if ($i++ >= 16) {
819
+					break;
820
+		}
792 821
 
793 822
 		$output .= $range[($value >> 18) & 0x3f];
794 823
 	}
@@ -820,8 +849,9 @@  discard block
 block discarded – undo
820 849
 		require_once($sourcedir . '/Subs-Auth.php');
821 850
 		setLoginCookie(-3600, 0);
822 851
 
823
-		if (isset($_SESSION['login_' . $cookiename]))
824
-			unset($_SESSION['login_' . $cookiename]);
852
+		if (isset($_SESSION['login_' . $cookiename])) {
853
+					unset($_SESSION['login_' . $cookiename]);
854
+		}
825 855
 	}
826 856
 
827 857
 	// We need a member!
@@ -835,8 +865,9 @@  discard block
 block discarded – undo
835 865
 	}
836 866
 
837 867
 	// Right, have we got a flood value?
838
-	if ($password_flood_value !== false)
839
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
868
+	if ($password_flood_value !== false) {
869
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
870
+	}
840 871
 
841 872
 	// Timestamp or number of tries invalid?
842 873
 	if (empty($number_tries) || empty($time_stamp))
@@ -852,15 +883,17 @@  discard block
 block discarded – undo
852 883
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
853 884
 
854 885
 		// They are trying too fast, make them wait longer
855
-		if ($time_stamp < time() - 10)
856
-			$time_stamp = time();
886
+		if ($time_stamp < time() - 10) {
887
+					$time_stamp = time();
888
+		}
857 889
 	}
858 890
 
859 891
 	$number_tries++;
860 892
 
861 893
 	// Broken the law?
862
-	if ($number_tries > 5)
863
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
894
+	if ($number_tries > 5) {
895
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
896
+	}
864 897
 
865 898
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
866 899
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/BoardIndex.php 1 patch
Braces   +20 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * This function shows the board index.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	$context['canonical_url'] = $scripturl;
35 36
 
36 37
 	// Do not let search engines index anything if there is a random thing in $_GET.
37
-	if (!empty($_GET))
38
-		$context['robot_no_index'] = true;
38
+	if (!empty($_GET)) {
39
+			$context['robot_no_index'] = true;
40
+	}
39 41
 
40 42
 	// Retrieve the categories and boards.
41 43
 	require_once($sourcedir . '/Subs-BoardIndex.php');
@@ -62,11 +64,12 @@  discard block
 block discarded – undo
62 64
 			$context['latest_posts'] = cache_quick_get('boardindex-latest_posts:' . md5($user_info['query_wanna_see_board'] . $user_info['language']), 'Subs-Recent.php', 'cache_getLastPosts', array($latestPostOptions));
63 65
 		}
64 66
 
65
-		if (!empty($context['latest_posts']) || !empty($context['latest_post']))
66
-			$context['info_center'][] = array(
67
+		if (!empty($context['latest_posts']) || !empty($context['latest_post'])) {
68
+					$context['info_center'][] = array(
67 69
 				'tpl' => 'recent',
68 70
 				'txt' => 'recent_posts',
69 71
 			);
72
+		}
70 73
 	}
71 74
 
72 75
 	// Load the calendar?
@@ -87,20 +90,22 @@  discard block
 block discarded – undo
87 90
 		// This is used to show the "how-do-I-edit" help.
88 91
 		$context['calendar_can_edit'] = allowedTo('calendar_edit_any');
89 92
 
90
-		if (!empty($context['show_calendar']))
91
-			$context['info_center'][] = array(
93
+		if (!empty($context['show_calendar'])) {
94
+					$context['info_center'][] = array(
92 95
 				'tpl' => 'calendar',
93 96
 				'txt' => $context['calendar_only_today'] ? 'calendar_today' : 'calendar_upcoming',
94 97
 			);
98
+		}
95 99
 	}
96 100
 
97 101
 	// And stats.
98 102
 	$context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);
99
-	if ($settings['show_stats_index'])
100
-		$context['info_center'][] = array(
103
+	if ($settings['show_stats_index']) {
104
+			$context['info_center'][] = array(
101 105
 				'tpl' => 'stats',
102 106
 				'txt' => 'forum_stats',
103 107
 			);
108
+	}
104 109
 
105 110
 	// Now the online stuff
106 111
 	require_once($sourcedir . '/Subs-MembersOnline.php');
@@ -118,12 +123,14 @@  discard block
 block discarded – undo
118 123
 			);
119 124
 
120 125
 	// Track most online statistics? (Subs-MembersOnline.php)
121
-	if (!empty($modSettings['trackStats']))
122
-		trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
126
+	if (!empty($modSettings['trackStats'])) {
127
+			trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
128
+	}
123 129
 
124 130
 	// Are we showing all membergroups on the board index?
125
-	if (!empty($settings['show_group_key']))
126
-		$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
131
+	if (!empty($settings['show_group_key'])) {
132
+			$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
133
+	}
127 134
 
128 135
 	// And back to normality.
129 136
 	$context['page_title'] = sprintf($txt['forum_index'], $context['forum_name']);
Please login to merge, or discard this patch.
Sources/Security.php 1 patch
Braces   +255 added lines, -197 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Check if the user is who he/she says he is
@@ -42,12 +43,14 @@  discard block
 block discarded – undo
42 43
 	$refreshTime = isset($_GET['xml']) ? 4200 : 3600;
43 44
 
44 45
 	// Is the security option off?
45
-	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')]))
46
-		return;
46
+	if (!empty($modSettings['securityDisable' . ($type != 'admin' ? '_' . $type : '')])) {
47
+			return;
48
+	}
47 49
 
48 50
 	// Or are they already logged in?, Moderator or admin session is need for this area
49
-	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time()))
50
-		return;
51
+	if ((!empty($_SESSION[$type . '_time']) && $_SESSION[$type . '_time'] + $refreshTime >= time()) || (!empty($_SESSION['admin_time']) && $_SESSION['admin_time'] + $refreshTime >= time())) {
52
+			return;
53
+	}
51 54
 
52 55
 	require_once($sourcedir . '/Subs-Auth.php');
53 56
 
@@ -55,8 +58,9 @@  discard block
 block discarded – undo
55 58
 	if (isset($_POST[$type . '_pass']))
56 59
 	{
57 60
 		// Check to ensure we're forcing SSL for authentication
58
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
59
-			fatal_lang_error('login_ssl_required');
61
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
62
+					fatal_lang_error('login_ssl_required');
63
+		}
60 64
 
61 65
 		checkSession();
62 66
 
@@ -72,17 +76,19 @@  discard block
 block discarded – undo
72 76
 	}
73 77
 
74 78
 	// Better be sure to remember the real referer
75
-	if (empty($_SESSION['request_referer']))
76
-		$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
77
-	elseif (empty($_POST))
78
-		unset($_SESSION['request_referer']);
79
+	if (empty($_SESSION['request_referer'])) {
80
+			$_SESSION['request_referer'] = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
81
+	} elseif (empty($_POST)) {
82
+			unset($_SESSION['request_referer']);
83
+	}
79 84
 
80 85
 	// Need to type in a password for that, man.
81
-	if (!isset($_GET['xml']))
82
-		adminLogin($type);
83
-	else
84
-		return 'session_verify_fail';
85
-}
86
+	if (!isset($_GET['xml'])) {
87
+			adminLogin($type);
88
+	} else {
89
+			return 'session_verify_fail';
90
+	}
91
+	}
86 92
 
87 93
 /**
88 94
  * Require a user who is logged in. (not a guest.)
@@ -96,25 +102,30 @@  discard block
 block discarded – undo
96 102
 	global $user_info, $txt, $context, $scripturl, $modSettings;
97 103
 
98 104
 	// Luckily, this person isn't a guest.
99
-	if (!$user_info['is_guest'])
100
-		return;
105
+	if (!$user_info['is_guest']) {
106
+			return;
107
+	}
101 108
 
102 109
 	// Log what they were trying to do didn't work)
103
-	if (!empty($modSettings['who_enabled']))
104
-		$_GET['error'] = 'guest_login';
110
+	if (!empty($modSettings['who_enabled'])) {
111
+			$_GET['error'] = 'guest_login';
112
+	}
105 113
 	writeLog(true);
106 114
 
107 115
 	// Just die.
108
-	if (isset($_REQUEST['xml']))
109
-		obExit(false);
116
+	if (isset($_REQUEST['xml'])) {
117
+			obExit(false);
118
+	}
110 119
 
111 120
 	// Attempt to detect if they came from dlattach.
112
-	if (SMF != 'SSI' && empty($context['theme_loaded']))
113
-		loadTheme();
121
+	if (SMF != 'SSI' && empty($context['theme_loaded'])) {
122
+			loadTheme();
123
+	}
114 124
 
115 125
 	// Never redirect to an attachment
116
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
117
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
126
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
127
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
128
+	}
118 129
 
119 130
 	// Load the Login template and language file.
120 131
 	loadLanguage('Login');
@@ -124,8 +135,7 @@  discard block
 block discarded – undo
124 135
 	{
125 136
 		$_SESSION['login_url'] = $scripturl . '?' . $_SERVER['QUERY_STRING'];
126 137
 		redirectexit('action=login');
127
-	}
128
-	else
138
+	} else
129 139
 	{
130 140
 		loadTemplate('Login');
131 141
 		$context['sub_template'] = 'kick_guest';
@@ -155,8 +165,9 @@  discard block
 block discarded – undo
155 165
 	global $sourcedir, $cookiename, $user_settings, $smcFunc;
156 166
 
157 167
 	// You cannot be banned if you are an admin - doesn't help if you log out.
158
-	if ($user_info['is_admin'])
159
-		return;
168
+	if ($user_info['is_admin']) {
169
+			return;
170
+	}
160 171
 
161 172
 	// Only check the ban every so often. (to reduce load.)
162 173
 	if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || ($_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated']) || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || (isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']))
@@ -177,8 +188,9 @@  discard block
 block discarded – undo
177 188
 		// Check both IP addresses.
178 189
 		foreach (array('ip', 'ip2') as $ip_number)
179 190
 		{
180
-			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip'])
181
-				continue;
191
+			if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) {
192
+							continue;
193
+			}
182 194
 			$ban_query[] = ' {inet:' . $ip_number . '} BETWEEN bi.ip_low and bi.ip_high';
183 195
 			$ban_query_vars[$ip_number] = $user_info[$ip_number];
184 196
 			// IP was valid, maybe there's also a hostname...
@@ -228,24 +240,28 @@  discard block
 block discarded – undo
228 240
 			// Store every type of ban that applies to you in your session.
229 241
 			while ($row = $smcFunc['db_fetch_assoc']($request))
230 242
 			{
231
-				foreach ($restrictions as $restriction)
232
-					if (!empty($row[$restriction]))
243
+				foreach ($restrictions as $restriction) {
244
+									if (!empty($row[$restriction]))
233 245
 					{
234 246
 						$_SESSION['ban'][$restriction]['reason'] = $row['reason'];
247
+				}
235 248
 						$_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
236
-						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])))
237
-							$_SESSION['ban']['expire_time'] = $row['expire_time'];
249
+						if (!isset($_SESSION['ban']['expire_time']) || ($_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time']))) {
250
+													$_SESSION['ban']['expire_time'] = $row['expire_time'];
251
+						}
238 252
 
239
-						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email']))
240
-							$flag_is_activated = true;
253
+						if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
254
+													$flag_is_activated = true;
255
+						}
241 256
 					}
242 257
 			}
243 258
 			$smcFunc['db_free_result']($request);
244 259
 		}
245 260
 
246 261
 		// Mark the cannot_access and cannot_post bans as being 'hit'.
247
-		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login']))
248
-			log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
262
+		if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
263
+					log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
264
+		}
249 265
 
250 266
 		// If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
251 267
 		if ($user_info['id'] && (($user_settings['is_activated'] >= 10 && !$flag_is_activated)
@@ -260,8 +276,9 @@  discard block
 block discarded – undo
260 276
 	if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_']))
261 277
 	{
262 278
 		$bans = explode(',', $_COOKIE[$cookiename . '_']);
263
-		foreach ($bans as $key => $value)
264
-			$bans[$key] = (int) $value;
279
+		foreach ($bans as $key => $value) {
280
+					$bans[$key] = (int) $value;
281
+		}
265 282
 		$request = $smcFunc['db_query']('', '
266 283
 			SELECT bi.id_ban, bg.reason, COALESCE(bg.expire_time, 0) AS expire_time
267 284
 			FROM {db_prefix}ban_items AS bi
@@ -298,14 +315,15 @@  discard block
 block discarded – undo
298 315
 	if (isset($_SESSION['ban']['cannot_access']))
299 316
 	{
300 317
 		// We don't wanna see you!
301
-		if (!$user_info['is_guest'])
302
-			$smcFunc['db_query']('', '
318
+		if (!$user_info['is_guest']) {
319
+					$smcFunc['db_query']('', '
303 320
 				DELETE FROM {db_prefix}log_online
304 321
 				WHERE id_member = {int:current_member}',
305 322
 				array(
306 323
 					'current_member' => $user_info['id'],
307 324
 				)
308 325
 			);
326
+		}
309 327
 
310 328
 		// 'Log' the user out.  Can't have any funny business... (save the name!)
311 329
 		$old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
@@ -391,9 +409,10 @@  discard block
 block discarded – undo
391 409
 	}
392 410
 
393 411
 	// Fix up the banning permissions.
394
-	if (isset($user_info['permissions']))
395
-		banPermissions();
396
-}
412
+	if (isset($user_info['permissions'])) {
413
+			banPermissions();
414
+	}
415
+	}
397 416
 
398 417
 /**
399 418
  * Fix permissions according to ban status.
@@ -404,8 +423,9 @@  discard block
 block discarded – undo
404 423
 	global $user_info, $sourcedir, $modSettings, $context;
405 424
 
406 425
 	// Somehow they got here, at least take away all permissions...
407
-	if (isset($_SESSION['ban']['cannot_access']))
408
-		$user_info['permissions'] = array();
426
+	if (isset($_SESSION['ban']['cannot_access'])) {
427
+			$user_info['permissions'] = array();
428
+	}
409 429
 	// Okay, well, you can watch, but don't touch a thing.
410 430
 	elseif (isset($_SESSION['ban']['cannot_post']) || (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $user_info['warning']))
411 431
 	{
@@ -447,19 +467,20 @@  discard block
 block discarded – undo
447 467
 		call_integration_hook('integrate_warn_permissions', array(&$permission_change));
448 468
 		foreach ($permission_change as $old => $new)
449 469
 		{
450
-			if (!in_array($old, $user_info['permissions']))
451
-				unset($permission_change[$old]);
452
-			else
453
-				$user_info['permissions'][] = $new;
470
+			if (!in_array($old, $user_info['permissions'])) {
471
+							unset($permission_change[$old]);
472
+			} else {
473
+							$user_info['permissions'][] = $new;
474
+			}
454 475
 		}
455 476
 		$user_info['permissions'] = array_diff($user_info['permissions'], array_keys($permission_change));
456 477
 	}
457 478
 
458 479
 	// @todo Find a better place to call this? Needs to be after permissions loaded!
459 480
 	// Finally, some bits we cache in the session because it saves queries.
460
-	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id'])
461
-		$user_info['mod_cache'] = $_SESSION['mc'];
462
-	else
481
+	if (isset($_SESSION['mc']) && $_SESSION['mc']['time'] > $modSettings['settings_updated'] && $_SESSION['mc']['id'] == $user_info['id']) {
482
+			$user_info['mod_cache'] = $_SESSION['mc'];
483
+	} else
463 484
 	{
464 485
 		require_once($sourcedir . '/Subs-Auth.php');
465 486
 		rebuildModCache();
@@ -470,14 +491,12 @@  discard block
 block discarded – undo
470 491
 	{
471 492
 		$context['open_mod_reports'] = $_SESSION['rc']['reports'];
472 493
 		$context['open_member_reports'] = $_SESSION['rc']['member_reports'];
473
-	}
474
-	elseif ($_SESSION['mc']['bq'] != '0=1')
494
+	} elseif ($_SESSION['mc']['bq'] != '0=1')
475 495
 	{
476 496
 		require_once($sourcedir . '/Subs-ReportedContent.php');
477 497
 		$context['open_mod_reports'] = recountOpenReports('posts');
478 498
 		$context['open_member_reports'] = recountOpenReports('members');
479
-	}
480
-	else
499
+	} else
481 500
 	{
482 501
 		$context['open_mod_reports'] = 0;
483 502
 		$context['open_member_reports'] = 0;
@@ -497,8 +516,9 @@  discard block
 block discarded – undo
497 516
 	global $user_info, $smcFunc;
498 517
 
499 518
 	// Don't log web accelerators, it's very confusing...
500
-	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
501
-		return;
519
+	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch') {
520
+			return;
521
+	}
502 522
 
503 523
 	$smcFunc['db_insert']('',
504 524
 		'{db_prefix}log_banned',
@@ -508,8 +528,8 @@  discard block
 block discarded – undo
508 528
 	);
509 529
 
510 530
 	// One extra point for these bans.
511
-	if (!empty($ban_ids))
512
-		$smcFunc['db_query']('', '
531
+	if (!empty($ban_ids)) {
532
+			$smcFunc['db_query']('', '
513 533
 			UPDATE {db_prefix}ban_items
514 534
 			SET hits = hits + 1
515 535
 			WHERE id_ban IN ({array_int:ban_ids})',
@@ -517,7 +537,8 @@  discard block
 block discarded – undo
517 537
 				'ban_ids' => $ban_ids,
518 538
 			)
519 539
 		);
520
-}
540
+	}
541
+	}
521 542
 
522 543
 /**
523 544
  * Checks if a given email address might be banned.
@@ -533,8 +554,9 @@  discard block
 block discarded – undo
533 554
 	global $txt, $smcFunc;
534 555
 
535 556
 	// Can't ban an empty email
536
-	if (empty($email) || trim($email) == '')
537
-		return;
557
+	if (empty($email) || trim($email) == '') {
558
+			return;
559
+	}
538 560
 
539 561
 	// Let's start with the bans based on your IP/hostname/memberID...
540 562
 	$ban_ids = isset($_SESSION['ban'][$restriction]) ? $_SESSION['ban'][$restriction]['ids'] : array();
@@ -607,16 +629,18 @@  discard block
 block discarded – undo
607 629
 	if ($type == 'post')
608 630
 	{
609 631
 		$check = isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null);
610
-		if ($check !== $sc)
611
-			$error = 'session_timeout';
632
+		if ($check !== $sc) {
633
+					$error = 'session_timeout';
634
+		}
612 635
 	}
613 636
 
614 637
 	// How about $_GET['sesc']?
615 638
 	elseif ($type == 'get')
616 639
 	{
617 640
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : null);
618
-		if ($check !== $sc)
619
-			$error = 'session_verify_fail';
641
+		if ($check !== $sc) {
642
+					$error = 'session_verify_fail';
643
+		}
620 644
 	}
621 645
 
622 646
 	// Or can it be in either?
@@ -624,13 +648,15 @@  discard block
 block discarded – undo
624 648
 	{
625 649
 		$check = isset($_GET[$_SESSION['session_var']]) ? $_GET[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_GET['sesc']) ? $_GET['sesc'] : (isset($_POST[$_SESSION['session_var']]) ? $_POST[$_SESSION['session_var']] : (empty($modSettings['strictSessionCheck']) && isset($_POST['sc']) ? $_POST['sc'] : null)));
626 650
 
627
-		if ($check !== $sc)
628
-			$error = 'session_verify_fail';
651
+		if ($check !== $sc) {
652
+					$error = 'session_verify_fail';
653
+		}
629 654
 	}
630 655
 
631 656
 	// Verify that they aren't changing user agents on us - that could be bad.
632
-	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA']))
633
-		$error = 'session_verify_fail';
657
+	if ((!isset($_SESSION['USER_AGENT']) || $_SESSION['USER_AGENT'] != $_SERVER['HTTP_USER_AGENT']) && empty($modSettings['disableCheckUA'])) {
658
+			$error = 'session_verify_fail';
659
+	}
634 660
 
635 661
 	// Make sure a page with session check requirement is not being prefetched.
636 662
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -641,30 +667,35 @@  discard block
 block discarded – undo
641 667
 	}
642 668
 
643 669
 	// Check the referring site - it should be the same server at least!
644
-	if (isset($_SESSION['request_referer']))
645
-		$referrer = $_SESSION['request_referer'];
646
-	else
647
-		$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
670
+	if (isset($_SESSION['request_referer'])) {
671
+			$referrer = $_SESSION['request_referer'];
672
+	} else {
673
+			$referrer = isset($_SERVER['HTTP_REFERER']) ? @parse_url($_SERVER['HTTP_REFERER']) : array();
674
+	}
648 675
 	if (!empty($referrer['host']))
649 676
 	{
650
-		if (strpos($_SERVER['HTTP_HOST'], ':') !== false)
651
-			$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
652
-		else
653
-			$real_host = $_SERVER['HTTP_HOST'];
677
+		if (strpos($_SERVER['HTTP_HOST'], ':') !== false) {
678
+					$real_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':'));
679
+		} else {
680
+					$real_host = $_SERVER['HTTP_HOST'];
681
+		}
654 682
 
655 683
 		$parsed_url = parse_url($boardurl);
656 684
 
657 685
 		// Are global cookies on?  If so, let's check them ;).
658 686
 		if (!empty($modSettings['globalCookies']))
659 687
 		{
660
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
661
-				$parsed_url['host'] = $parts[1];
688
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
689
+							$parsed_url['host'] = $parts[1];
690
+			}
662 691
 
663
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1)
664
-				$referrer['host'] = $parts[1];
692
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $referrer['host'], $parts) == 1) {
693
+							$referrer['host'] = $parts[1];
694
+			}
665 695
 
666
-			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1)
667
-				$real_host = $parts[1];
696
+			if (preg_match('~(?:[^\.]+\.)?([^\.]{3,}\..+)\z~i', $real_host, $parts) == 1) {
697
+							$real_host = $parts[1];
698
+			}
668 699
 		}
669 700
 
670 701
 		// Okay: referrer must either match parsed_url or real_host.
@@ -682,12 +713,14 @@  discard block
 block discarded – undo
682 713
 		$log_error = true;
683 714
 	}
684 715
 
685
-	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker')
686
-		fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
716
+	if (strtolower($_SERVER['HTTP_USER_AGENT']) == 'hacker') {
717
+			fatal_error('Sound the alarm!  It\'s a hacker!  Close the castle gates!!', false);
718
+	}
687 719
 
688 720
 	// Everything is ok, return an empty string.
689
-	if (!isset($error))
690
-		return '';
721
+	if (!isset($error)) {
722
+			return '';
723
+	}
691 724
 	// A session error occurred, show the error.
692 725
 	elseif ($is_fatal)
693 726
 	{
@@ -696,13 +729,14 @@  discard block
 block discarded – undo
696 729
 			ob_end_clean();
697 730
 			header('HTTP/1.1 403 Forbidden - Session timeout');
698 731
 			die;
732
+		} else {
733
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
699 734
 		}
700
-		else
701
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
702 735
 	}
703 736
 	// A session error occurred, return the error to the calling function.
704
-	else
705
-		return $error;
737
+	else {
738
+			return $error;
739
+	}
706 740
 
707 741
 	// We really should never fall through here, for very important reasons.  Let's make sure.
708 742
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -718,10 +752,9 @@  discard block
 block discarded – undo
718 752
 {
719 753
 	global $modSettings;
720 754
 
721
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
722
-		return true;
723
-
724
-	else
755
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
756
+			return true;
757
+	} else
725 758
 	{
726 759
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
727 760
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -772,9 +805,9 @@  discard block
 block discarded – undo
772 805
 			$return = $_SESSION['token'][$type . '-' . $action][3];
773 806
 			unset($_SESSION['token'][$type . '-' . $action]);
774 807
 			return $return;
808
+		} else {
809
+					return '';
775 810
 		}
776
-		else
777
-			return '';
778 811
 	}
779 812
 
780 813
 	// This nasty piece of code validates a token.
@@ -805,12 +838,14 @@  discard block
 block discarded – undo
805 838
 		fatal_lang_error('token_verify_fail', false);
806 839
 	}
807 840
 	// Remove this token as its useless
808
-	else
809
-		unset($_SESSION['token'][$type . '-' . $action]);
841
+	else {
842
+			unset($_SESSION['token'][$type . '-' . $action]);
843
+	}
810 844
 
811 845
 	// Randomly check if we should remove some older tokens.
812
-	if (mt_rand(0, 138) == 23)
813
-		cleanTokens();
846
+	if (mt_rand(0, 138) == 23) {
847
+			cleanTokens();
848
+	}
814 849
 
815 850
 	return false;
816 851
 }
@@ -825,14 +860,16 @@  discard block
 block discarded – undo
825 860
 function cleanTokens($complete = false)
826 861
 {
827 862
 	// We appreciate cleaning up after yourselves.
828
-	if (!isset($_SESSION['token']))
829
-		return;
863
+	if (!isset($_SESSION['token'])) {
864
+			return;
865
+	}
830 866
 
831 867
 	// Clean up tokens, trying to give enough time still.
832
-	foreach ($_SESSION['token'] as $key => $data)
833
-		if ($data[2] + 10800 < time() || $complete)
868
+	foreach ($_SESSION['token'] as $key => $data) {
869
+			if ($data[2] + 10800 < time() || $complete)
834 870
 			unset($_SESSION['token'][$key]);
835
-}
871
+	}
872
+	}
836 873
 
837 874
 /**
838 875
  * Check whether a form has been submitted twice.
@@ -850,37 +887,40 @@  discard block
 block discarded – undo
850 887
 {
851 888
 	global $context;
852 889
 
853
-	if (!isset($_SESSION['forms']))
854
-		$_SESSION['forms'] = array();
890
+	if (!isset($_SESSION['forms'])) {
891
+			$_SESSION['forms'] = array();
892
+	}
855 893
 
856 894
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
857 895
 	if ($action == 'register')
858 896
 	{
859 897
 		$context['form_sequence_number'] = 0;
860
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
861
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
898
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
899
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
900
+		}
862 901
 	}
863 902
 	// Check whether the submitted number can be found in the session.
864 903
 	elseif ($action == 'check')
865 904
 	{
866
-		if (!isset($_REQUEST['seqnum']))
867
-			return true;
868
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
905
+		if (!isset($_REQUEST['seqnum'])) {
906
+					return true;
907
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
869 908
 		{
870 909
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
871 910
 			return true;
911
+		} elseif ($is_fatal) {
912
+					fatal_lang_error('error_form_already_submitted', false);
913
+		} else {
914
+					return false;
872 915
 		}
873
-		elseif ($is_fatal)
874
-			fatal_lang_error('error_form_already_submitted', false);
875
-		else
876
-			return false;
877 916
 	}
878 917
 	// Don't check, just free the stack number.
879
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
880
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
881
-	elseif ($action != 'free')
882
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
883
-}
918
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
919
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
920
+	} elseif ($action != 'free') {
921
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
922
+	}
923
+	}
884 924
 
885 925
 /**
886 926
  * Check the user's permissions.
@@ -899,16 +939,19 @@  discard block
 block discarded – undo
899 939
 	global $user_info, $smcFunc;
900 940
 
901 941
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
902
-	if (empty($permission))
903
-		return true;
942
+	if (empty($permission)) {
943
+			return true;
944
+	}
904 945
 
905 946
 	// You're never allowed to do something if your data hasn't been loaded yet!
906
-	if (empty($user_info))
907
-		return false;
947
+	if (empty($user_info)) {
948
+			return false;
949
+	}
908 950
 
909 951
 	// Administrators are supermen :P.
910
-	if ($user_info['is_admin'])
911
-		return true;
952
+	if ($user_info['is_admin']) {
953
+			return true;
954
+	}
912 955
 
913 956
 	// Let's ensure this is an array.
914 957
 	$permission = (array) $permission;
@@ -916,14 +959,16 @@  discard block
 block discarded – undo
916 959
 	// Are we checking the _current_ board, or some other boards?
917 960
 	if ($boards === null)
918 961
 	{
919
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
920
-			return true;
962
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
963
+					return true;
964
+		}
921 965
 		// You aren't allowed, by default.
922
-		else
923
-			return false;
966
+		else {
967
+					return false;
968
+		}
969
+	} elseif (!is_array($boards)) {
970
+			$boards = array($boards);
924 971
 	}
925
-	elseif (!is_array($boards))
926
-		$boards = array($boards);
927 972
 
928 973
 	$request = $smcFunc['db_query']('', '
929 974
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -951,20 +996,23 @@  discard block
 block discarded – undo
951 996
 		while ($row = $smcFunc['db_fetch_assoc']($request))
952 997
 		{
953 998
 			$result = !empty($row['add_deny']);
954
-			if ($result == true)
955
-				break;
999
+			if ($result == true) {
1000
+							break;
1001
+			}
956 1002
 		}
957 1003
 		$smcFunc['db_free_result']($request);
958 1004
 		return $result;
959 1005
 	}
960 1006
 
961 1007
 	// Make sure they can do it on all of the boards.
962
-	if ($smcFunc['db_num_rows']($request) != count($boards))
963
-		return false;
1008
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
1009
+			return false;
1010
+	}
964 1011
 
965 1012
 	$result = true;
966
-	while ($row = $smcFunc['db_fetch_assoc']($request))
967
-		$result &= !empty($row['add_deny']);
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$result &= !empty($row['add_deny']);
1015
+	}
968 1016
 	$smcFunc['db_free_result']($request);
969 1017
 
970 1018
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1031,9 +1079,10 @@  discard block
 block discarded – undo
1031 1079
 
1032 1080
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1033 1081
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1034
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1035
-		validateSession();
1036
-}
1082
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1083
+			validateSession();
1084
+	}
1085
+	}
1037 1086
 
1038 1087
 /**
1039 1088
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1064,13 +1113,14 @@  discard block
 block discarded – undo
1064 1113
 	// Administrators are all powerful, sorry.
1065 1114
 	if ($user_info['is_admin'])
1066 1115
 	{
1067
-		if ($simple)
1068
-			return array(0);
1069
-		else
1116
+		if ($simple) {
1117
+					return array(0);
1118
+		} else
1070 1119
 		{
1071 1120
 			$boards = array();
1072
-			foreach ($permissions as $permission)
1073
-				$boards[$permission] = array(0);
1121
+			foreach ($permissions as $permission) {
1122
+							$boards[$permission] = array(0);
1123
+			}
1074 1124
 
1075 1125
 			return $boards;
1076 1126
 		}
@@ -1102,31 +1152,32 @@  discard block
 block discarded – undo
1102 1152
 	{
1103 1153
 		if ($simple)
1104 1154
 		{
1105
-			if (empty($row['add_deny']))
1106
-				$deny_boards[] = $row['id_board'];
1107
-			else
1108
-				$boards[] = $row['id_board'];
1109
-		}
1110
-		else
1155
+			if (empty($row['add_deny'])) {
1156
+							$deny_boards[] = $row['id_board'];
1157
+			} else {
1158
+							$boards[] = $row['id_board'];
1159
+			}
1160
+		} else
1111 1161
 		{
1112
-			if (empty($row['add_deny']))
1113
-				$deny_boards[$row['permission']][] = $row['id_board'];
1114
-			else
1115
-				$boards[$row['permission']][] = $row['id_board'];
1162
+			if (empty($row['add_deny'])) {
1163
+							$deny_boards[$row['permission']][] = $row['id_board'];
1164
+			} else {
1165
+							$boards[$row['permission']][] = $row['id_board'];
1166
+			}
1116 1167
 		}
1117 1168
 	}
1118 1169
 	$smcFunc['db_free_result']($request);
1119 1170
 
1120
-	if ($simple)
1121
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1122
-	else
1171
+	if ($simple) {
1172
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1173
+	} else
1123 1174
 	{
1124 1175
 		foreach ($permissions as $permission)
1125 1176
 		{
1126 1177
 			// never had it to start with
1127
-			if (empty($boards[$permission]))
1128
-				$boards[$permission] = array();
1129
-			else
1178
+			if (empty($boards[$permission])) {
1179
+							$boards[$permission] = array();
1180
+			} else
1130 1181
 			{
1131 1182
 				// Or it may have been removed
1132 1183
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1162,10 +1213,11 @@  discard block
 block discarded – undo
1162 1213
 
1163 1214
 
1164 1215
 	// Moderators are free...
1165
-	if (!allowedTo('moderate_board'))
1166
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1167
-	else
1168
-		$timeLimit = 2;
1216
+	if (!allowedTo('moderate_board')) {
1217
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1218
+	} else {
1219
+			$timeLimit = 2;
1220
+	}
1169 1221
 
1170 1222
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1171 1223
 
@@ -1192,8 +1244,9 @@  discard block
 block discarded – undo
1192 1244
 	if ($smcFunc['db_affected_rows']() != 1)
1193 1245
 	{
1194 1246
 		// Spammer!  You only have to wait a *few* seconds!
1195
-		if (!$only_return_result)
1196
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1247
+		if (!$only_return_result) {
1248
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1249
+		}
1197 1250
 
1198 1251
 		return true;
1199 1252
 	}
@@ -1211,11 +1264,13 @@  discard block
 block discarded – undo
1211 1264
  */
1212 1265
 function secureDirectory($path, $attachments = false)
1213 1266
 {
1214
-	if (empty($path))
1215
-		return 'empty_path';
1267
+	if (empty($path)) {
1268
+			return 'empty_path';
1269
+	}
1216 1270
 
1217
-	if (!is_writable($path))
1218
-		return 'path_not_writable';
1271
+	if (!is_writable($path)) {
1272
+			return 'path_not_writable';
1273
+	}
1219 1274
 
1220 1275
 	$directoryname = basename($path);
1221 1276
 
@@ -1227,9 +1282,9 @@  discard block
 block discarded – undo
1227 1282
 
1228 1283
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1229 1284
 
1230
-	if (file_exists($path . '/.htaccess'))
1231
-		$errors[] = 'htaccess_exists';
1232
-	else
1285
+	if (file_exists($path . '/.htaccess')) {
1286
+			$errors[] = 'htaccess_exists';
1287
+	} else
1233 1288
 	{
1234 1289
 		$fh = @fopen($path . '/.htaccess', 'w');
1235 1290
 		if ($fh)
@@ -1242,9 +1297,9 @@  discard block
 block discarded – undo
1242 1297
 		$errors[] = 'htaccess_cannot_create_file';
1243 1298
 	}
1244 1299
 
1245
-	if (file_exists($path . '/index.php'))
1246
-		$errors[] = 'index-php_exists';
1247
-	else
1300
+	if (file_exists($path . '/index.php')) {
1301
+			$errors[] = 'index-php_exists';
1302
+	} else
1248 1303
 	{
1249 1304
 		$fh = @fopen($path . '/index.php', 'w');
1250 1305
 		if ($fh)
@@ -1272,11 +1327,12 @@  discard block
 block discarded – undo
1272 1327
 		$errors[] = 'index-php_cannot_create_file';
1273 1328
 	}
1274 1329
 
1275
-	if (!empty($errors))
1276
-		return $errors;
1277
-	else
1278
-		return true;
1279
-}
1330
+	if (!empty($errors)) {
1331
+			return $errors;
1332
+	} else {
1333
+			return true;
1334
+	}
1335
+	}
1280 1336
 
1281 1337
 /**
1282 1338
 * This sets the X-Frame-Options header.
@@ -1289,14 +1345,16 @@  discard block
 block discarded – undo
1289 1345
 	global $modSettings;
1290 1346
 
1291 1347
 	$option = 'SAMEORIGIN';
1292
-	if (is_null($override) && !empty($modSettings['frame_security']))
1293
-		$option = $modSettings['frame_security'];
1294
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1295
-		$option = $override;
1348
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1349
+			$option = $modSettings['frame_security'];
1350
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1351
+			$option = $override;
1352
+	}
1296 1353
 
1297 1354
 	// Don't bother setting the header if we have disabled it.
1298
-	if ($option == 'DISABLE')
1299
-		return;
1355
+	if ($option == 'DISABLE') {
1356
+			return;
1357
+	}
1300 1358
 
1301 1359
 	// Finally set it.
1302 1360
 	header('x-frame-options: ' . $option);
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -328,7 +328,7 @@
 block discarded – undo
328 328
 		foreach ($context['error_info']['backtrace'] as $key => $value)
329 329
 		{
330 330
 			//Check for existing
331
-			if (!property_exists($value,'file') || empty($value->file))
331
+			if (!property_exists($value, 'file') || empty($value->file))
332 332
 				$value->file = $txt['unknown'];
333 333
 			if (!property_exists($value, 'line') || empty($value->line))
334 334
 				$value->line = -1;
Please login to merge, or discard this patch.
Braces   +48 added lines, -33 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 	<strong>
29 29
 		', $context['error_title'], '
30 30
 	</strong><br>
31 31
 	<div ', $context['error_code'], 'class="padding">
32 32
 		', $context['error_message'], '
33 33
 	</div>';
34
-	else
34
+	} else
35 35
 	{
36 36
 		echo '
37 37
 	<div id="fatal_error">
@@ -85,21 +85,23 @@  discard block
 block discarded – undo
85 85
 
86 86
 	$error_types = array();
87 87
 
88
-	foreach ($context['error_types'] as $type => $details)
89
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
88
+	foreach ($context['error_types'] as $type => $details) {
89
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
90
+	}
90 91
 
91 92
 	echo '
92 93
 						', implode(' | ', $error_types), '
93 94
 					</td>
94 95
 				</tr>';
95 96
 
96
-	if ($context['has_filter'])
97
-		echo '
97
+	if ($context['has_filter']) {
98
+			echo '
98 99
 				<tr>
99 100
 					<td colspan="3" class="windowbg">
100 101
 						<strong>', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], ' [<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
101 102
 					</td>
102 103
 				</tr>';
104
+	}
103 105
 
104 106
 	echo '
105 107
 				<tr>
@@ -110,11 +112,12 @@  discard block
 block discarded – undo
110 112
 				</tr>';
111 113
 
112 114
 	// No errors, then show a message
113
-	if (count($context['errors']) == 0)
114
-		echo '
115
+	if (count($context['errors']) == 0) {
116
+			echo '
115 117
 				<tr class="windowbg">
116 118
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
117 119
 				</tr>';
120
+	}
118 121
 
119 122
 	// We have some errors, must be some mods installed :P
120 123
 	foreach ($context['errors'] as $error)
@@ -128,16 +131,18 @@  discard block
 block discarded – undo
128 131
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
129 132
 							', $error['time'], '<br>';
130 133
 
131
-		if (!empty($error['member']['ip']))
132
-			echo '
134
+		if (!empty($error['member']['ip'])) {
135
+					echo '
133 136
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a>
134 137
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>';
138
+		}
135 139
 
136
-		if ($error['member']['session'] != '')
137
-			echo '
140
+		if ($error['member']['session'] != '') {
141
+					echo '
138 142
 							<br>
139 143
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 						</div>
@@ -152,12 +157,13 @@  discard block
 block discarded – undo
152 157
 							<a href="', $error['url']['html'], '">', $error['url']['html'], '</a>
153 158
 ';
154 159
 
155
-		if (!empty($error['file']))
156
-			echo '
160
+		if (!empty($error['file'])) {
161
+					echo '
157 162
 							<div>
158 163
 								<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '">'
159 164
 				. '					<span class="generic_icons filter"></span></a> ', $error['file']['link'], ' (', $txt['line'], ' ', $error['file']['line'], ')
160 165
 							</div>';
166
+		}
161 167
 
162 168
 		echo '
163 169
 						</div>
@@ -186,9 +192,10 @@  discard block
 block discarded – undo
186 192
 				</div>
187 193
 			</div>';
188 194
 
189
-	if ($context['sort_direction'] == 'down')
190
-		echo '
195
+	if ($context['sort_direction'] == 'down') {
196
+			echo '
191 197
 			<input type="hidden" name="desc" value="1">';
198
+	}
192 199
 
193 200
 	echo '
194 201
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -249,9 +256,10 @@  discard block
 block discarded – undo
249 256
 					$context['error_message'], '
250 257
 				</div>';
251 258
 	
252
-	if (!empty($context['back_link'])) 
253
-		echo '
259
+	if (!empty($context['back_link'])) {
260
+			echo '
254 261
 				<a class="button" href="', $scripturl, $context['back_link'], '">', $txt['back'], '</a>';
262
+	}
255 263
 
256 264
 	echo '
257 265
 				<span style="float: right; margin:.5em;"></span>
@@ -288,25 +296,30 @@  discard block
 block discarded – undo
288 296
 			<div class="windowbg">
289 297
 				<ul class="padding">';
290 298
 
291
-		if (!empty($context['error_info']['error_type']))
292
-			echo '
299
+		if (!empty($context['error_info']['error_type'])) {
300
+					echo '
293 301
 					<li>', $txt['error_type'], ': ', ucfirst($context['error_info']['error_type']), '</li>';
302
+		}
294 303
 
295
-		if (!empty($context['error_info']['message']))
296
-			echo '
304
+		if (!empty($context['error_info']['message'])) {
305
+					echo '
297 306
 					<li>', $txt['error_message'], ': ', $context['error_info']['message'], '</li>';
307
+		}
298 308
 
299
-		if (!empty($context['error_info']['file']))
300
-			echo '
309
+		if (!empty($context['error_info']['file'])) {
310
+					echo '
301 311
 					<li>', $txt['error_file'], ': ', $context['error_info']['file'], '</li>';
312
+		}
302 313
 
303
-		if (!empty($context['error_info']['line']))
304
-			echo '
314
+		if (!empty($context['error_info']['line'])) {
315
+					echo '
305 316
 					<li>', $txt['error_line'], ': ', $context['error_info']['line'], '</li>';
317
+		}
306 318
 
307
-		if (!empty($context['error_info']['url']))
308
-			echo '
319
+		if (!empty($context['error_info']['url'])) {
320
+					echo '
309 321
 					<li>', $txt['error_url'], ': ', $context['error_info']['url'], '</li>';
322
+		}
310 323
 
311 324
 
312 325
 		echo '
@@ -328,10 +341,12 @@  discard block
 block discarded – undo
328 341
 		foreach ($context['error_info']['backtrace'] as $key => $value)
329 342
 		{
330 343
 			//Check for existing
331
-			if (!property_exists($value,'file') || empty($value->file))
332
-				$value->file = $txt['unknown'];
333
-			if (!property_exists($value, 'line') || empty($value->line))
334
-				$value->line = -1;
344
+			if (!property_exists($value,'file') || empty($value->file)) {
345
+							$value->file = $txt['unknown'];
346
+			}
347
+			if (!property_exists($value, 'line') || empty($value->line)) {
348
+							$value->line = -1;
349
+			}
335 350
 
336 351
 				echo '
337 352
 					<li class="backtrace">', sprintf($txt['backtrace_info'], $key, $value->function, $value->file, $value->line, base64_encode($value->file)), '</li>';
Please login to merge, or discard this patch.