Completed
Pull Request — release-2.1 (#4996)
by Jeremy
06:16
created
Sources/Errors.php 1 patch
Braces   +127 added lines, -90 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Log an error, if the error logging is enabled.
@@ -39,10 +40,11 @@  discard block
 block discarded – undo
39 40
 	$error_call++;
40 41
 
41 42
 	// Collect a backtrace
42
-	if (!isset($db_show_debug) || $db_show_debug === false)
43
-		$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
44
-	else
45
-		$backtrace = debug_backtrace();
43
+	if (!isset($db_show_debug) || $db_show_debug === false) {
44
+			$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
45
+	} else {
46
+			$backtrace = debug_backtrace();
47
+	}
46 48
 
47 49
 	// are we in a loop?
48 50
 	if($error_call > 2)
@@ -52,8 +54,9 @@  discard block
 block discarded – undo
52 54
 	}
53 55
 
54 56
 	// Check if error logging is actually on.
55
-	if (empty($modSettings['enableErrorLogging']))
56
-		return $error_message;
57
+	if (empty($modSettings['enableErrorLogging'])) {
58
+			return $error_message;
59
+	}
57 60
 
58 61
 	// Basically, htmlspecialchars it minus &. (for entities!)
59 62
 	$error_message = strtr($error_message, array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
@@ -61,33 +64,39 @@  discard block
 block discarded – undo
61 64
 
62 65
 	// Add a file and line to the error message?
63 66
 	// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
64
-	if ($file == null)
65
-		$file = '';
66
-	else
67
-		// Window style slashes don't play well, lets convert them to the unix style.
67
+	if ($file == null) {
68
+			$file = '';
69
+	} else {
70
+			// Window style slashes don't play well, lets convert them to the unix style.
68 71
 		$file = str_replace('\\', '/', $file);
72
+	}
69 73
 
70
-	if ($line == null)
71
-		$line = 0;
72
-	else
73
-		$line = (int) $line;
74
+	if ($line == null) {
75
+			$line = 0;
76
+	} else {
77
+			$line = (int) $line;
78
+	}
74 79
 
75 80
 	// Just in case there's no id_member or IP set yet.
76
-	if (empty($user_info['id']))
77
-		$user_info['id'] = 0;
78
-	if (empty($user_info['ip']))
79
-		$user_info['ip'] = '';
81
+	if (empty($user_info['id'])) {
82
+			$user_info['id'] = 0;
83
+	}
84
+	if (empty($user_info['ip'])) {
85
+			$user_info['ip'] = '';
86
+	}
80 87
 
81 88
 	// Find the best query string we can...
82 89
 	$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
83 90
 
84 91
 	// Don't log the session hash in the url twice, it's a waste.
85
-	if (!empty($smcFunc['htmlspecialchars']))
86
-		$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
92
+	if (!empty($smcFunc['htmlspecialchars'])) {
93
+			$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
94
+	}
87 95
 
88 96
 	// Just so we know what board error messages are from.
89
-	if (isset($_POST['board']) && !isset($_GET['board']))
90
-		$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
97
+	if (isset($_POST['board']) && !isset($_GET['board'])) {
98
+			$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
99
+	}
91 100
 
92 101
 	// What types of categories do we have?
93 102
 	$known_error_types = array(
@@ -140,9 +149,9 @@  discard block
 block discarded – undo
140 149
 
141 150
 			list($context['num_errors']) = $smcFunc['db_fetch_row']($query);
142 151
 			$smcFunc['db_free_result']($query);
152
+		} else {
153
+					$context['num_errors']++;
143 154
 		}
144
-		else
145
-			$context['num_errors']++;
146 155
 	}
147 156
 
148 157
 	// reset error call
@@ -164,12 +173,14 @@  discard block
 block discarded – undo
164 173
 	global $txt;
165 174
 
166 175
 	// Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all
167
-	if (!empty($status))
168
-		send_http_status($status);
176
+	if (!empty($status)) {
177
+			send_http_status($status);
178
+	}
169 179
 
170 180
 	// We don't have $txt yet, but that's okay...
171
-	if (empty($txt))
172
-		die($error);
181
+	if (empty($txt)) {
182
+			die($error);
183
+	}
173 184
 
174 185
 	log_error_online($error, false);
175 186
 	setup_fatal_error_context($log ? log_error($error, $log) : $error);
@@ -196,8 +207,9 @@  discard block
 block discarded – undo
196 207
 	static $fatal_error_called = false;
197 208
 
198 209
 	// Send the status header - set this to 0 or false if you don't want to send one at all
199
-	if (!empty($status))
200
-		send_http_status($status);
210
+	if (!empty($status)) {
211
+			send_http_status($status);
212
+	}
201 213
 
202 214
 	// Try to load a theme if we don't have one.
203 215
 	if (empty($context['theme_loaded']) && empty($fatal_error_called))
@@ -207,8 +219,9 @@  discard block
 block discarded – undo
207 219
 	}
208 220
 
209 221
 	// If we have no theme stuff we can't have the language file...
210
-	if (empty($context['theme_loaded']))
211
-		die($error);
222
+	if (empty($context['theme_loaded'])) {
223
+			die($error);
224
+	}
212 225
 
213 226
 	$reload_lang_file = true;
214 227
 	// Log the error in the forum's language, but don't waste the time if we aren't logging
@@ -244,8 +257,9 @@  discard block
 block discarded – undo
244 257
 	global $settings, $modSettings, $db_show_debug;
245 258
 
246 259
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5
247
-	if (error_reporting() == 0)
248
-		return;
260
+	if (error_reporting() == 0) {
261
+			return;
262
+	}
249 263
 
250 264
 	if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))
251 265
 	{
@@ -253,19 +267,22 @@  discard block
 block discarded – undo
253 267
 		$count = count($array);
254 268
 		for ($i = 0; $i < $count; $i++)
255 269
 		{
256
-			if ($array[$i]['function'] != 'loadSubTemplate')
257
-				continue;
270
+			if ($array[$i]['function'] != 'loadSubTemplate') {
271
+							continue;
272
+			}
258 273
 
259 274
 			// This is a bug in PHP, with eval, it seems!
260
-			if (empty($array[$i]['args']))
261
-				$i++;
275
+			if (empty($array[$i]['args'])) {
276
+							$i++;
277
+			}
262 278
 			break;
263 279
 		}
264 280
 
265
-		if (isset($array[$i]) && !empty($array[$i]['args']))
266
-			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
267
-		else
268
-			$file = realpath($settings['current_include_filename']) . ' (eval?)';
281
+		if (isset($array[$i]) && !empty($array[$i]['args'])) {
282
+					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
283
+		} else {
284
+					$file = realpath($settings['current_include_filename']) . ' (eval?)';
285
+		}
269 286
 	}
270 287
 
271 288
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -274,8 +291,9 @@  discard block
 block discarded – undo
274 291
 		if ($error_level % 255 != E_ERROR)
275 292
 		{
276 293
 			$temporary = ob_get_contents();
277
-			if (substr($temporary, -2) == '="')
278
-				echo '"';
294
+			if (substr($temporary, -2) == '="') {
295
+							echo '"';
296
+			}
279 297
 		}
280 298
 
281 299
 		// Debugging!  This should look like a PHP error message.
@@ -291,23 +309,27 @@  discard block
 block discarded – undo
291 309
 	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line));
292 310
 
293 311
 	// Dying on these errors only causes MORE problems (blank pages!)
294
-	if ($file == 'Unknown')
295
-		return;
312
+	if ($file == 'Unknown') {
313
+			return;
314
+	}
296 315
 
297 316
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
298
-	if ($error_level % 255 == E_ERROR)
299
-		obExit(false);
300
-	else
301
-		return;
317
+	if ($error_level % 255 == E_ERROR) {
318
+			obExit(false);
319
+	} else {
320
+			return;
321
+	}
302 322
 
303 323
 	// If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die.  Violently so.
304
-	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)
305
-		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
324
+	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) {
325
+			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
326
+	}
306 327
 
307 328
 	// We should NEVER get to this point.  Any fatal error MUST quit, or very bad things can happen.
308
-	if ($error_level % 255 == E_ERROR)
309
-		die('No direct access...');
310
-}
329
+	if ($error_level % 255 == E_ERROR) {
330
+			die('No direct access...');
331
+	}
332
+	}
311 333
 
312 334
 /**
313 335
  * It is called by {@link fatal_error()} and {@link fatal_lang_error()}.
@@ -323,24 +345,28 @@  discard block
 block discarded – undo
323 345
 
324 346
 	// Attempt to prevent a recursive loop.
325 347
 	++$level;
326
-	if ($level > 1)
327
-		return false;
348
+	if ($level > 1) {
349
+			return false;
350
+	}
328 351
 
329 352
 	// Maybe they came from dlattach or similar?
330
-	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))
331
-		loadTheme();
353
+	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) {
354
+			loadTheme();
355
+	}
332 356
 
333 357
 	// Don't bother indexing errors mate...
334 358
 	$context['robot_no_index'] = true;
335 359
 
336
-	if (!isset($context['error_title']))
337
-		$context['error_title'] = $txt['error_occured'];
360
+	if (!isset($context['error_title'])) {
361
+			$context['error_title'] = $txt['error_occured'];
362
+	}
338 363
 	$context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
339 364
 
340 365
 	$context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';
341 366
 
342
-	if (empty($context['page_title']))
343
-		$context['page_title'] = $context['error_title'];
367
+	if (empty($context['page_title'])) {
368
+			$context['page_title'] = $context['error_title'];
369
+	}
344 370
 
345 371
 	loadTemplate('Errors');
346 372
 	$context['sub_template'] = 'fatal_error';
@@ -348,23 +374,26 @@  discard block
 block discarded – undo
348 374
 	// If this is SSI, what do they want us to do?
349 375
 	if (SMF == 'SSI')
350 376
 	{
351
-		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))
352
-			$ssi_on_error_method();
353
-		elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
354
-			loadSubTemplate('fatal_error');
377
+		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
378
+					$ssi_on_error_method();
379
+		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
380
+					loadSubTemplate('fatal_error');
381
+		}
355 382
 
356 383
 		// No layers?
357
-		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
358
-			exit;
384
+		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
385
+					exit;
386
+		}
359 387
 	}
360 388
 	// Alternatively from the cron call?
361 389
 	elseif (SMF == 'BACKGROUND')
362 390
 	{
363 391
 		// We can't rely on even having language files available.
364
-		if (defined('FROM_CLI') && FROM_CLI)
365
-			echo 'cron error: ', $context['error_message'];
366
-		else
367
-			echo 'An error occurred. More information may be available in your logs.';
392
+		if (defined('FROM_CLI') && FROM_CLI) {
393
+					echo 'cron error: ', $context['error_message'];
394
+		} else {
395
+					echo 'An error occurred. More information may be available in your logs.';
396
+		}
368 397
 		exit;
369 398
 	}
370 399
 
@@ -392,8 +421,8 @@  discard block
 block discarded – undo
392 421
 
393 422
 	set_fatal_error_headers();
394 423
 
395
-	if (!empty($maintenance))
396
-		echo '<!DOCTYPE html>
424
+	if (!empty($maintenance)) {
425
+			echo '<!DOCTYPE html>
397 426
 <html>
398 427
 	<head>
399 428
 		<meta name="robots" content="noindex">
@@ -404,6 +433,7 @@  discard block
 block discarded – undo
404 433
 		', $mmessage, '
405 434
 	</body>
406 435
 </html>';
436
+	}
407 437
 
408 438
 	die();
409 439
 }
@@ -425,15 +455,17 @@  discard block
 block discarded – undo
425 455
 	// For our purposes, we're gonna want this on if at all possible.
426 456
 	$modSettings['cache_enable'] = '1';
427 457
 
428
-	if (($temp = cache_get_data('db_last_error', 600)) !== null)
429
-		$db_last_error = max($db_last_error, $temp);
458
+	if (($temp = cache_get_data('db_last_error', 600)) !== null) {
459
+			$db_last_error = max($db_last_error, $temp);
460
+	}
430 461
 
431 462
 	if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))
432 463
 	{
433 464
 		// Avoid writing to the Settings.php file if at all possible; use shared memory instead.
434 465
 		cache_put_data('db_last_error', time(), 600);
435
-		if (($temp = cache_get_data('db_last_error', 600)) === null)
436
-			logLastDatabaseError();
466
+		if (($temp = cache_get_data('db_last_error', 600)) === null) {
467
+					logLastDatabaseError();
468
+		}
437 469
 
438 470
 		// Language files aren't loaded yet :(.
439 471
 		$db_error = @$smcFunc['db_error']($db_connection);
@@ -490,8 +522,9 @@  discard block
 block discarded – undo
490 522
  */
491 523
 function set_fatal_error_headers()
492 524
 {
493
-	if (headers_sent())
494
-		return;
525
+	if (headers_sent()) {
526
+			return;
527
+	}
495 528
 
496 529
 	// Don't cache this page!
497 530
 	header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -517,12 +550,14 @@  discard block
 block discarded – undo
517 550
 	global $smcFunc, $user_info, $modSettings;
518 551
 
519 552
 	// Don't bother if Who's Online is disabled.
520
-	if (empty($modSettings['who_enabled']))
521
-		return;
553
+	if (empty($modSettings['who_enabled'])) {
554
+			return;
555
+	}
522 556
 
523 557
 	// Maybe they came from SSI or similar where sessions are not recorded?
524
-	if (SMF == 'SSI' || SMF == 'BACKGROUND')
525
-		return;
558
+	if (SMF == 'SSI' || SMF == 'BACKGROUND') {
559
+			return;
560
+	}
526 561
 
527 562
 	$session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id();
528 563
 
@@ -548,11 +583,13 @@  discard block
 block discarded – undo
548 583
 		$url = $smcFunc['json_decode']($url, true);
549 584
 		$url['error'] = $error;
550 585
 		// Url field got a max length of 1024 in db
551
-		if (strlen($url['error']) > 500)
552
-			$url['error'] = substr($url['error'],0,500);
586
+		if (strlen($url['error']) > 500) {
587
+					$url['error'] = substr($url['error'],0,500);
588
+		}
553 589
 
554
-		if (!empty($sprintf))
555
-			$url['error_params'] = $sprintf;
590
+		if (!empty($sprintf)) {
591
+					$url['error_params'] = $sprintf;
592
+		}
556 593
 
557 594
 		$smcFunc['db_query']('', '
558 595
 			UPDATE {db_prefix}log_online
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
 			send_http_status(403, 'Forbidden - Session timeout');
698 731
 			die;
732
+		} else {
733
+					fatal_lang_error($error, isset($log_error) ? 'user' : false);
699 734
 		}
700
-		else
701
-			fatal_lang_error($error, isset($log_error) ? 'user' : false);
702 735
 	}
703 736
 	// A session error occurred, return the error to the calling function.
704
-	else
705
-		return $error;
737
+	else {
738
+			return $error;
739
+	}
706 740
 
707 741
 	// We really should never fall through here, for very important reasons.  Let's make sure.
708 742
 	trigger_error('Hacking attempt...', E_USER_ERROR);
@@ -718,10 +752,9 @@  discard block
 block discarded – undo
718 752
 {
719 753
 	global $modSettings;
720 754
 
721
-	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action])
722
-		return true;
723
-
724
-	else
755
+	if (isset($_GET['confirm']) && isset($_SESSION['confirm_' . $action]) && md5($_GET['confirm'] . $_SERVER['HTTP_USER_AGENT']) == $_SESSION['confirm_' . $action]) {
756
+			return true;
757
+	} else
725 758
 	{
726 759
 		$token = md5(mt_rand() . session_id() . (string) microtime() . $modSettings['rand_seed']);
727 760
 		$_SESSION['confirm_' . $action] = md5($token . $_SERVER['HTTP_USER_AGENT']);
@@ -772,9 +805,9 @@  discard block
 block discarded – undo
772 805
 			$return = $_SESSION['token'][$type . '-' . $action][3];
773 806
 			unset($_SESSION['token'][$type . '-' . $action]);
774 807
 			return $return;
808
+		} else {
809
+					return '';
775 810
 		}
776
-		else
777
-			return '';
778 811
 	}
779 812
 
780 813
 	// This nasty piece of code validates a token.
@@ -805,12 +838,14 @@  discard block
 block discarded – undo
805 838
 		fatal_lang_error('token_verify_fail', false);
806 839
 	}
807 840
 	// Remove this token as its useless
808
-	else
809
-		unset($_SESSION['token'][$type . '-' . $action]);
841
+	else {
842
+			unset($_SESSION['token'][$type . '-' . $action]);
843
+	}
810 844
 
811 845
 	// Randomly check if we should remove some older tokens.
812
-	if (mt_rand(0, 138) == 23)
813
-		cleanTokens();
846
+	if (mt_rand(0, 138) == 23) {
847
+			cleanTokens();
848
+	}
814 849
 
815 850
 	return false;
816 851
 }
@@ -825,14 +860,16 @@  discard block
 block discarded – undo
825 860
 function cleanTokens($complete = false)
826 861
 {
827 862
 	// We appreciate cleaning up after yourselves.
828
-	if (!isset($_SESSION['token']))
829
-		return;
863
+	if (!isset($_SESSION['token'])) {
864
+			return;
865
+	}
830 866
 
831 867
 	// Clean up tokens, trying to give enough time still.
832
-	foreach ($_SESSION['token'] as $key => $data)
833
-		if ($data[2] + 10800 < time() || $complete)
868
+	foreach ($_SESSION['token'] as $key => $data) {
869
+			if ($data[2] + 10800 < time() || $complete)
834 870
 			unset($_SESSION['token'][$key]);
835
-}
871
+	}
872
+	}
836 873
 
837 874
 /**
838 875
  * Check whether a form has been submitted twice.
@@ -850,37 +887,40 @@  discard block
 block discarded – undo
850 887
 {
851 888
 	global $context;
852 889
 
853
-	if (!isset($_SESSION['forms']))
854
-		$_SESSION['forms'] = array();
890
+	if (!isset($_SESSION['forms'])) {
891
+			$_SESSION['forms'] = array();
892
+	}
855 893
 
856 894
 	// Register a form number and store it in the session stack. (use this on the page that has the form.)
857 895
 	if ($action == 'register')
858 896
 	{
859 897
 		$context['form_sequence_number'] = 0;
860
-		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms']))
861
-			$context['form_sequence_number'] = mt_rand(1, 16000000);
898
+		while (empty($context['form_sequence_number']) || in_array($context['form_sequence_number'], $_SESSION['forms'])) {
899
+					$context['form_sequence_number'] = mt_rand(1, 16000000);
900
+		}
862 901
 	}
863 902
 	// Check whether the submitted number can be found in the session.
864 903
 	elseif ($action == 'check')
865 904
 	{
866
-		if (!isset($_REQUEST['seqnum']))
867
-			return true;
868
-		elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
905
+		if (!isset($_REQUEST['seqnum'])) {
906
+					return true;
907
+		} elseif (!in_array($_REQUEST['seqnum'], $_SESSION['forms']))
869 908
 		{
870 909
 			$_SESSION['forms'][] = (int) $_REQUEST['seqnum'];
871 910
 			return true;
911
+		} elseif ($is_fatal) {
912
+					fatal_lang_error('error_form_already_submitted', false);
913
+		} else {
914
+					return false;
872 915
 		}
873
-		elseif ($is_fatal)
874
-			fatal_lang_error('error_form_already_submitted', false);
875
-		else
876
-			return false;
877 916
 	}
878 917
 	// Don't check, just free the stack number.
879
-	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms']))
880
-		$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
881
-	elseif ($action != 'free')
882
-		trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
883
-}
918
+	elseif ($action == 'free' && isset($_REQUEST['seqnum']) && in_array($_REQUEST['seqnum'], $_SESSION['forms'])) {
919
+			$_SESSION['forms'] = array_diff($_SESSION['forms'], array($_REQUEST['seqnum']));
920
+	} elseif ($action != 'free') {
921
+			trigger_error('checkSubmitOnce(): Invalid action \'' . $action . '\'', E_USER_WARNING);
922
+	}
923
+	}
884 924
 
885 925
 /**
886 926
  * Check the user's permissions.
@@ -899,16 +939,19 @@  discard block
 block discarded – undo
899 939
 	global $user_info, $smcFunc;
900 940
 
901 941
 	// You're always allowed to do nothing. (unless you're a working man, MR. LAZY :P!)
902
-	if (empty($permission))
903
-		return true;
942
+	if (empty($permission)) {
943
+			return true;
944
+	}
904 945
 
905 946
 	// You're never allowed to do something if your data hasn't been loaded yet!
906
-	if (empty($user_info))
907
-		return false;
947
+	if (empty($user_info)) {
948
+			return false;
949
+	}
908 950
 
909 951
 	// Administrators are supermen :P.
910
-	if ($user_info['is_admin'])
911
-		return true;
952
+	if ($user_info['is_admin']) {
953
+			return true;
954
+	}
912 955
 
913 956
 	// Let's ensure this is an array.
914 957
 	$permission = (array) $permission;
@@ -916,14 +959,16 @@  discard block
 block discarded – undo
916 959
 	// Are we checking the _current_ board, or some other boards?
917 960
 	if ($boards === null)
918 961
 	{
919
-		if (count(array_intersect($permission, $user_info['permissions'])) != 0)
920
-			return true;
962
+		if (count(array_intersect($permission, $user_info['permissions'])) != 0) {
963
+					return true;
964
+		}
921 965
 		// You aren't allowed, by default.
922
-		else
923
-			return false;
966
+		else {
967
+					return false;
968
+		}
969
+	} elseif (!is_array($boards)) {
970
+			$boards = array($boards);
924 971
 	}
925
-	elseif (!is_array($boards))
926
-		$boards = array($boards);
927 972
 
928 973
 	$request = $smcFunc['db_query']('', '
929 974
 		SELECT MIN(bp.add_deny) AS add_deny
@@ -951,20 +996,23 @@  discard block
 block discarded – undo
951 996
 		while ($row = $smcFunc['db_fetch_assoc']($request))
952 997
 		{
953 998
 			$result = !empty($row['add_deny']);
954
-			if ($result == true)
955
-				break;
999
+			if ($result == true) {
1000
+							break;
1001
+			}
956 1002
 		}
957 1003
 		$smcFunc['db_free_result']($request);
958 1004
 		return $result;
959 1005
 	}
960 1006
 
961 1007
 	// Make sure they can do it on all of the boards.
962
-	if ($smcFunc['db_num_rows']($request) != count($boards))
963
-		return false;
1008
+	if ($smcFunc['db_num_rows']($request) != count($boards)) {
1009
+			return false;
1010
+	}
964 1011
 
965 1012
 	$result = true;
966
-	while ($row = $smcFunc['db_fetch_assoc']($request))
967
-		$result &= !empty($row['add_deny']);
1013
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1014
+			$result &= !empty($row['add_deny']);
1015
+	}
968 1016
 	$smcFunc['db_free_result']($request);
969 1017
 
970 1018
 	// If the query returned 1, they can do it... otherwise, they can't.
@@ -1031,9 +1079,10 @@  discard block
 block discarded – undo
1031 1079
 
1032 1080
 	// If you're doing something on behalf of some "heavy" permissions, validate your session.
1033 1081
 	// (take out the heavy permissions, and if you can't do anything but those, you need a validated session.)
1034
-	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards))
1035
-		validateSession();
1036
-}
1082
+	if (!allowedTo(array_diff($permission, $heavy_permissions), $boards)) {
1083
+			validateSession();
1084
+	}
1085
+	}
1037 1086
 
1038 1087
 /**
1039 1088
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
@@ -1064,13 +1113,14 @@  discard block
 block discarded – undo
1064 1113
 	// Administrators are all powerful, sorry.
1065 1114
 	if ($user_info['is_admin'])
1066 1115
 	{
1067
-		if ($simple)
1068
-			return array(0);
1069
-		else
1116
+		if ($simple) {
1117
+					return array(0);
1118
+		} else
1070 1119
 		{
1071 1120
 			$boards = array();
1072
-			foreach ($permissions as $permission)
1073
-				$boards[$permission] = array(0);
1121
+			foreach ($permissions as $permission) {
1122
+							$boards[$permission] = array(0);
1123
+			}
1074 1124
 
1075 1125
 			return $boards;
1076 1126
 		}
@@ -1102,31 +1152,32 @@  discard block
 block discarded – undo
1102 1152
 	{
1103 1153
 		if ($simple)
1104 1154
 		{
1105
-			if (empty($row['add_deny']))
1106
-				$deny_boards[] = $row['id_board'];
1107
-			else
1108
-				$boards[] = $row['id_board'];
1109
-		}
1110
-		else
1155
+			if (empty($row['add_deny'])) {
1156
+							$deny_boards[] = $row['id_board'];
1157
+			} else {
1158
+							$boards[] = $row['id_board'];
1159
+			}
1160
+		} else
1111 1161
 		{
1112
-			if (empty($row['add_deny']))
1113
-				$deny_boards[$row['permission']][] = $row['id_board'];
1114
-			else
1115
-				$boards[$row['permission']][] = $row['id_board'];
1162
+			if (empty($row['add_deny'])) {
1163
+							$deny_boards[$row['permission']][] = $row['id_board'];
1164
+			} else {
1165
+							$boards[$row['permission']][] = $row['id_board'];
1166
+			}
1116 1167
 		}
1117 1168
 	}
1118 1169
 	$smcFunc['db_free_result']($request);
1119 1170
 
1120
-	if ($simple)
1121
-		$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1122
-	else
1171
+	if ($simple) {
1172
+			$boards = array_unique(array_values(array_diff($boards, $deny_boards)));
1173
+	} else
1123 1174
 	{
1124 1175
 		foreach ($permissions as $permission)
1125 1176
 		{
1126 1177
 			// never had it to start with
1127
-			if (empty($boards[$permission]))
1128
-				$boards[$permission] = array();
1129
-			else
1178
+			if (empty($boards[$permission])) {
1179
+							$boards[$permission] = array();
1180
+			} else
1130 1181
 			{
1131 1182
 				// Or it may have been removed
1132 1183
 				$deny_boards[$permission] = isset($deny_boards[$permission]) ? $deny_boards[$permission] : array();
@@ -1162,10 +1213,11 @@  discard block
 block discarded – undo
1162 1213
 
1163 1214
 
1164 1215
 	// Moderators are free...
1165
-	if (!allowedTo('moderate_board'))
1166
-		$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1167
-	else
1168
-		$timeLimit = 2;
1216
+	if (!allowedTo('moderate_board')) {
1217
+			$timeLimit = isset($timeOverrides[$error_type]) ? $timeOverrides[$error_type] : $modSettings['spamWaitTime'];
1218
+	} else {
1219
+			$timeLimit = 2;
1220
+	}
1169 1221
 
1170 1222
 	call_integration_hook('integrate_spam_protection', array(&$timeOverrides, &$timeLimit));
1171 1223
 
@@ -1192,8 +1244,9 @@  discard block
 block discarded – undo
1192 1244
 	if ($smcFunc['db_affected_rows']() != 1)
1193 1245
 	{
1194 1246
 		// Spammer!  You only have to wait a *few* seconds!
1195
-		if (!$only_return_result)
1196
-			fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1247
+		if (!$only_return_result) {
1248
+					fatal_lang_error($error_type . '_WaitTime_broken', false, array($timeLimit));
1249
+		}
1197 1250
 
1198 1251
 		return true;
1199 1252
 	}
@@ -1211,11 +1264,13 @@  discard block
 block discarded – undo
1211 1264
  */
1212 1265
 function secureDirectory($path, $attachments = false)
1213 1266
 {
1214
-	if (empty($path))
1215
-		return 'empty_path';
1267
+	if (empty($path)) {
1268
+			return 'empty_path';
1269
+	}
1216 1270
 
1217
-	if (!is_writable($path))
1218
-		return 'path_not_writable';
1271
+	if (!is_writable($path)) {
1272
+			return 'path_not_writable';
1273
+	}
1219 1274
 
1220 1275
 	$directoryname = basename($path);
1221 1276
 
@@ -1227,9 +1282,9 @@  discard block
 block discarded – undo
1227 1282
 
1228 1283
 RemoveHandler .php .php3 .phtml .cgi .fcgi .pl .fpl .shtml';
1229 1284
 
1230
-	if (file_exists($path . '/.htaccess'))
1231
-		$errors[] = 'htaccess_exists';
1232
-	else
1285
+	if (file_exists($path . '/.htaccess')) {
1286
+			$errors[] = 'htaccess_exists';
1287
+	} else
1233 1288
 	{
1234 1289
 		$fh = @fopen($path . '/.htaccess', 'w');
1235 1290
 		if ($fh)
@@ -1242,9 +1297,9 @@  discard block
 block discarded – undo
1242 1297
 		$errors[] = 'htaccess_cannot_create_file';
1243 1298
 	}
1244 1299
 
1245
-	if (file_exists($path . '/index.php'))
1246
-		$errors[] = 'index-php_exists';
1247
-	else
1300
+	if (file_exists($path . '/index.php')) {
1301
+			$errors[] = 'index-php_exists';
1302
+	} else
1248 1303
 	{
1249 1304
 		$fh = @fopen($path . '/index.php', 'w');
1250 1305
 		if ($fh)
@@ -1272,11 +1327,12 @@  discard block
 block discarded – undo
1272 1327
 		$errors[] = 'index-php_cannot_create_file';
1273 1328
 	}
1274 1329
 
1275
-	if (!empty($errors))
1276
-		return $errors;
1277
-	else
1278
-		return true;
1279
-}
1330
+	if (!empty($errors)) {
1331
+			return $errors;
1332
+	} else {
1333
+			return true;
1334
+	}
1335
+	}
1280 1336
 
1281 1337
 /**
1282 1338
 * This sets the X-Frame-Options header.
@@ -1289,14 +1345,16 @@  discard block
 block discarded – undo
1289 1345
 	global $modSettings;
1290 1346
 
1291 1347
 	$option = 'SAMEORIGIN';
1292
-	if (is_null($override) && !empty($modSettings['frame_security']))
1293
-		$option = $modSettings['frame_security'];
1294
-	elseif (in_array($override, array('SAMEORIGIN', 'DENY')))
1295
-		$option = $override;
1348
+	if (is_null($override) && !empty($modSettings['frame_security'])) {
1349
+			$option = $modSettings['frame_security'];
1350
+	} elseif (in_array($override, array('SAMEORIGIN', 'DENY'))) {
1351
+			$option = $override;
1352
+	}
1296 1353
 
1297 1354
 	// Don't bother setting the header if we have disabled it.
1298
-	if ($option == 'DISABLE')
1299
-		return;
1355
+	if ($option == 'DISABLE') {
1356
+			return;
1357
+	}
1300 1358
 
1301 1359
 	// Finally set it.
1302 1360
 	header('x-frame-options: ' . $option);
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1477 added lines, -1105 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,24 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-
195
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
196 199
 			{
197 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
198 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -213,8 +216,9 @@  discard block
 block discarded – undo
213 216
 
214 217
 		case 'postgroups':
215 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
216
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
217
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
218 222
 
219 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
220 224
 			if ($postgroups == null || $parameter1 == null)
@@ -229,8 +233,9 @@  discard block
 block discarded – undo
229 233
 					)
230 234
 				);
231 235
 				$postgroups = array();
232
-				while ($row = $smcFunc['db_fetch_assoc']($request))
233
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
234 239
 
235 240
 				$smcFunc['db_free_result']($request);
236 241
 
@@ -241,8 +246,9 @@  discard block
 block discarded – undo
241 246
 			}
242 247
 
243 248
 			// Oh great, they've screwed their post groups.
244
-			if (empty($postgroups))
245
-				return;
249
+			if (empty($postgroups)) {
250
+							return;
251
+			}
246 252
 
247 253
 			// Set all membergroups from most posts to least posts.
248 254
 			$conditions = '';
@@ -301,12 +307,9 @@  discard block
 block discarded – undo
301 307
 	{
302 308
 		$condition = 'id_member IN ({array_int:members})';
303 309
 		$parameters['members'] = $members;
304
-	}
305
-
306
-	elseif ($members === null)
307
-		$condition = '1=1';
308
-
309
-	else
310
+	} elseif ($members === null) {
311
+			$condition = '1=1';
312
+	} else
310 313
 	{
311 314
 		$condition = 'id_member = {int:member}';
312 315
 		$parameters['member'] = $members;
@@ -346,9 +349,9 @@  discard block
 block discarded – undo
346 349
 		if (count($vars_to_integrate) != 0)
347 350
 		{
348 351
 			// Fetch a list of member_names if necessary
349
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
350
-				$member_names = array($user_info['username']);
351
-			else
352
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
353
+							$member_names = array($user_info['username']);
354
+			} else
352 355
 			{
353 356
 				$member_names = array();
354 357
 				$request = $smcFunc['db_query']('', '
@@ -357,14 +360,16 @@  discard block
 block discarded – undo
357 360
 					WHERE ' . $condition,
358 361
 					$parameters
359 362
 				);
360
-				while ($row = $smcFunc['db_fetch_assoc']($request))
361
-					$member_names[] = $row['member_name'];
363
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
364
+									$member_names[] = $row['member_name'];
365
+				}
362 366
 				$smcFunc['db_free_result']($request);
363 367
 			}
364 368
 
365
-			if (!empty($member_names))
366
-				foreach ($vars_to_integrate as $var)
369
+			if (!empty($member_names)) {
370
+							foreach ($vars_to_integrate as $var)
367 371
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
372
+			}
368 373
 		}
369 374
 	}
370 375
 
@@ -372,16 +377,17 @@  discard block
 block discarded – undo
372 377
 	foreach ($data as $var => $val)
373 378
 	{
374 379
 		$type = 'string';
375
-		if (in_array($var, $knownInts))
376
-			$type = 'int';
377
-		elseif (in_array($var, $knownFloats))
378
-			$type = 'float';
379
-		elseif ($var == 'birthdate')
380
-			$type = 'date';
381
-		elseif ($var == 'member_ip')
382
-			$type = 'inet';
383
-		elseif ($var == 'member_ip2')
384
-			$type = 'inet';
380
+		if (in_array($var, $knownInts)) {
381
+					$type = 'int';
382
+		} elseif (in_array($var, $knownFloats)) {
383
+					$type = 'float';
384
+		} elseif ($var == 'birthdate') {
385
+					$type = 'date';
386
+		} elseif ($var == 'member_ip') {
387
+					$type = 'inet';
388
+		} elseif ($var == 'member_ip2') {
389
+					$type = 'inet';
390
+		}
385 391
 
386 392
 		// Doing an increment?
387 393
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -390,18 +396,17 @@  discard block
 block discarded – undo
390 396
 			if (is_array($members))
391 397
 			{
392 398
 				$val = 'CASE ';
393
-				foreach ($members as $k => $v)
394
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				foreach ($members as $k => $v) {
400
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
401
+				}
395 402
 				$val = $val . ' END';
396 403
 				$type = 'raw';
397
-			}
398
-			else
404
+			} else
399 405
 			{
400 406
 				$blub = fetch_alerts($members, false, 0, array(), false);
401 407
 				$val = count($blub);
402 408
 			}
403
-		}
404
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
409
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
405 410
 		{
406 411
 			$val = $var . ' ' . $val . ' 1';
407 412
 			$type = 'raw';
@@ -412,8 +417,9 @@  discard block
 block discarded – undo
412 417
 		{
413 418
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
414 419
 			{
415
-				if ($match[1] != '+ ')
416
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				if ($match[1] != '+ ') {
421
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
422
+				}
417 423
 				$type = 'raw';
418 424
 			}
419 425
 		}
@@ -434,8 +440,9 @@  discard block
 block discarded – undo
434 440
 	// Clear any caching?
435 441
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
436 442
 	{
437
-		if (!is_array($members))
438
-			$members = array($members);
443
+		if (!is_array($members)) {
444
+					$members = array($members);
445
+		}
439 446
 
440 447
 		foreach ($members as $member)
441 448
 		{
@@ -468,29 +475,32 @@  discard block
 block discarded – undo
468 475
 {
469 476
 	global $modSettings, $smcFunc;
470 477
 
471
-	if (empty($changeArray) || !is_array($changeArray))
472
-		return;
478
+	if (empty($changeArray) || !is_array($changeArray)) {
479
+			return;
480
+	}
473 481
 
474 482
 	$toRemove = array();
475 483
 
476 484
 	// Go check if there is any setting to be removed.
477
-	foreach ($changeArray as $k => $v)
478
-		if ($v === null)
485
+	foreach ($changeArray as $k => $v) {
486
+			if ($v === null)
479 487
 		{
480 488
 			// Found some, remove them from the original array and add them to ours.
481 489
 			unset($changeArray[$k]);
490
+	}
482 491
 			$toRemove[] = $k;
483 492
 		}
484 493
 
485 494
 	// Proceed with the deletion.
486
-	if (!empty($toRemove))
487
-		$smcFunc['db_query']('', '
495
+	if (!empty($toRemove)) {
496
+			$smcFunc['db_query']('', '
488 497
 			DELETE FROM {db_prefix}settings
489 498
 			WHERE variable IN ({array_string:remove})',
490 499
 			array(
491 500
 				'remove' => $toRemove,
492 501
 			)
493 502
 		);
503
+	}
494 504
 
495 505
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
496 506
 	if ($update)
@@ -519,19 +529,22 @@  discard block
 block discarded – undo
519 529
 	foreach ($changeArray as $variable => $value)
520 530
 	{
521 531
 		// Don't bother if it's already like that ;).
522
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
523
-			continue;
532
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
533
+					continue;
534
+		}
524 535
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
525
-		elseif (!isset($modSettings[$variable]) && empty($value))
526
-			continue;
536
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
537
+					continue;
538
+		}
527 539
 
528 540
 		$replaceArray[] = array($variable, $value);
529 541
 
530 542
 		$modSettings[$variable] = $value;
531 543
 	}
532 544
 
533
-	if (empty($replaceArray))
534
-		return;
545
+	if (empty($replaceArray)) {
546
+			return;
547
+	}
535 548
 
536 549
 	$smcFunc['db_insert']('replace',
537 550
 		'{db_prefix}settings',
@@ -577,14 +590,17 @@  discard block
 block discarded – undo
577 590
 	$start_invalid = $start < 0;
578 591
 
579 592
 	// Make sure $start is a proper variable - not less than 0.
580
-	if ($start_invalid)
581
-		$start = 0;
593
+	if ($start_invalid) {
594
+			$start = 0;
595
+	}
582 596
 	// Not greater than the upper bound.
583
-	elseif ($start >= $max_value)
584
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
597
+	elseif ($start >= $max_value) {
598
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
599
+	}
585 600
 	// And it has to be a multiple of $num_per_page!
586
-	else
587
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	else {
602
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
603
+	}
588 604
 
589 605
 	$context['current_page'] = $start / $num_per_page;
590 606
 
@@ -614,77 +630,87 @@  discard block
 block discarded – undo
614 630
 
615 631
 		// Show all the pages.
616 632
 		$display_page = 1;
617
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
618
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
634
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
635
+		}
619 636
 
620 637
 		// Show the right arrow.
621 638
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
622
-		if ($start != $counter - $max_value && !$start_invalid)
623
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
624
-	}
625
-	else
639
+		if ($start != $counter - $max_value && !$start_invalid) {
640
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
641
+		}
642
+	} else
626 643
 	{
627 644
 		// If they didn't enter an odd value, pretend they did.
628 645
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
629 646
 
630 647
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
631
-		if (!empty($start) && $show_prevnext)
632
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
633
-		else
634
-			$pageindex .= '';
648
+		if (!empty($start) && $show_prevnext) {
649
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
650
+		} else {
651
+					$pageindex .= '';
652
+		}
635 653
 
636 654
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
637
-		if ($start > $num_per_page * $PageContiguous)
638
-			$pageindex .= sprintf($base_link, 0, '1');
655
+		if ($start > $num_per_page * $PageContiguous) {
656
+					$pageindex .= sprintf($base_link, 0, '1');
657
+		}
639 658
 
640 659
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
641
-		if ($start > $num_per_page * ($PageContiguous + 1))
642
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
660
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
661
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
643 662
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
644 663
 				'{FIRST_PAGE}' => $num_per_page,
645 664
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
646 665
 				'{PER_PAGE}' => $num_per_page,
647 666
 			));
667
+		}
648 668
 
649 669
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
650
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
651
-			if ($start >= $num_per_page * $nCont)
670
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
671
+					if ($start >= $num_per_page * $nCont)
652 672
 			{
653 673
 				$tmpStart = $start - $num_per_page * $nCont;
674
+		}
654 675
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
655 676
 			}
656 677
 
657 678
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
658
-		if (!$start_invalid)
659
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
660
-		else
661
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
679
+		if (!$start_invalid) {
680
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
681
+		} else {
682
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
683
+		}
662 684
 
663 685
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
664 686
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
665
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
666
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
687
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
688
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
667 689
 			{
668 690
 				$tmpStart = $start + $num_per_page * $nCont;
691
+		}
669 692
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
670 693
 			}
671 694
 
672 695
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
673
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
674
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
696
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
697
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
675 698
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
676 699
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
677 700
 				'{LAST_PAGE}' => $tmpMaxPages,
678 701
 				'{PER_PAGE}' => $num_per_page,
679 702
 			));
703
+		}
680 704
 
681 705
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
682
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
683
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
707
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
708
+		}
684 709
 
685 710
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
686
-		if ($start != $tmpMaxPages && $show_prevnext)
687
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		if ($start != $tmpMaxPages && $show_prevnext) {
712
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
713
+		}
688 714
 	}
689 715
 	$pageindex .= $settings['page_index']['extra_after'];
690 716
 
@@ -710,8 +736,9 @@  discard block
 block discarded – undo
710 736
 	if ($decimal_separator === null)
711 737
 	{
712 738
 		// Not set for whatever reason?
713
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
714
-			return $number;
739
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
740
+					return $number;
741
+		}
715 742
 
716 743
 		// Cache these each load...
717 744
 		$thousands_separator = $matches[1];
@@ -752,17 +779,20 @@  discard block
 block discarded – undo
752 779
 	$user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M');
753 780
 
754 781
 	// Offset the time.
755
-	if (!$offset_type)
756
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
782
+	if (!$offset_type) {
783
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
784
+	}
757 785
 	// Just the forum offset?
758
-	elseif ($offset_type == 'forum')
759
-		$time = $log_time + $modSettings['time_offset'] * 3600;
760
-	else
761
-		$time = $log_time;
786
+	elseif ($offset_type == 'forum') {
787
+			$time = $log_time + $modSettings['time_offset'] * 3600;
788
+	} else {
789
+			$time = $log_time;
790
+	}
762 791
 
763 792
 	// We can't have a negative date (on Windows, at least.)
764
-	if ($log_time < 0)
765
-		$log_time = 0;
793
+	if ($log_time < 0) {
794
+			$log_time = 0;
795
+	}
766 796
 
767 797
 	// Today and Yesterday?
768 798
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -779,24 +809,27 @@  discard block
 block discarded – undo
779 809
 		{
780 810
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
781 811
 			$today_fmt = $h . ':%M' . $s . ' %p';
812
+		} else {
813
+					$today_fmt = '%H:%M' . $s;
782 814
 		}
783
-		else
784
-			$today_fmt = '%H:%M' . $s;
785 815
 
786 816
 		// Same day of the year, same year.... Today!
787
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
788
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
817
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
818
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
819
+		}
789 820
 
790 821
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
791
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
792
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
822
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
823
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
824
+		}
793 825
 	}
794 826
 
795 827
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
796 828
 
797 829
 	// Use the cached formats if available
798
-	if (is_null($finalizedFormats))
799
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
830
+	if (is_null($finalizedFormats)) {
831
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
832
+	}
800 833
 
801 834
 	// Make a supported version for this format if we don't already have one
802 835
 	if (empty($finalizedFormats[$str]))
@@ -825,8 +858,9 @@  discard block
 block discarded – undo
825 858
 		);
826 859
 
827 860
 		// No need to do this part again if we already did it once
828
-		if (is_null($unsupportedFormats))
829
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
861
+		if (is_null($unsupportedFormats)) {
862
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
863
+		}
830 864
 		if (empty($unsupportedFormats))
831 865
 		{
832 866
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -842,20 +876,23 @@  discard block
 block discarded – undo
842 876
 
843 877
 				// Windows will return false for unsupported formats
844 878
 				// Other operating systems return the format string as a literal
845
-				if ($value === false || $value === $format)
846
-					$unsupportedFormats[] = $format;
879
+				if ($value === false || $value === $format) {
880
+									$unsupportedFormats[] = $format;
881
+				}
847 882
 			}
848 883
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
849 884
 		}
850 885
 
851 886
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
852
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
853
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
887
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
888
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
889
+		}
854 890
 
855 891
 		// Substitute unsupported formats with supported ones
856
-		if (!empty($unsupportedFormats))
857
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
892
+		if (!empty($unsupportedFormats)) {
893
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
858 894
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
895
+		}
859 896
 
860 897
 		// Remember this so we don't need to do it again
861 898
 		$finalizedFormats[$str] = $timeformat;
@@ -864,33 +901,39 @@  discard block
 block discarded – undo
864 901
 
865 902
 	$str = $finalizedFormats[$str];
866 903
 
867
-	if (!isset($locale_cache))
868
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
904
+	if (!isset($locale_cache)) {
905
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
906
+	}
869 907
 
870 908
 	if ($locale_cache !== false)
871 909
 	{
872 910
 		// Check if another process changed the locale
873
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
874
-			setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
911
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
912
+					setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
913
+		}
875 914
 
876
-		if (!isset($non_twelve_hour))
877
-			$non_twelve_hour = trim(strftime('%p')) === '';
878
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
879
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
915
+		if (!isset($non_twelve_hour)) {
916
+					$non_twelve_hour = trim(strftime('%p')) === '';
917
+		}
918
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
919
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
920
+		}
880 921
 
881
-		foreach (array('%a', '%A', '%b', '%B') as $token)
882
-			if (strpos($str, $token) !== false)
922
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
923
+					if (strpos($str, $token) !== false)
883 924
 				$str = str_replace($token, strftime($token, $time), $str);
884
-	}
885
-	else
925
+		}
926
+	} else
886 927
 	{
887 928
 		// Do-it-yourself time localization.  Fun.
888
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
889
-			if (strpos($str, $token) !== false)
929
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
930
+					if (strpos($str, $token) !== false)
890 931
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
932
+		}
891 933
 
892
-		if (strpos($str, '%p') !== false)
893
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
934
+		if (strpos($str, '%p') !== false) {
935
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
936
+		}
894 937
 	}
895 938
 
896 939
 	// Format the time and then restore any literal percent characters
@@ -913,16 +956,19 @@  discard block
 block discarded – undo
913 956
 	static $translation = array();
914 957
 
915 958
 	// Determine the character set... Default to UTF-8
916
-	if (empty($context['character_set']))
917
-		$charset = 'UTF-8';
959
+	if (empty($context['character_set'])) {
960
+			$charset = 'UTF-8';
961
+	}
918 962
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
919
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
920
-		$charset = 'ISO-8859-1';
921
-	else
922
-		$charset = $context['character_set'];
963
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
964
+			$charset = 'ISO-8859-1';
965
+	} else {
966
+			$charset = $context['character_set'];
967
+	}
923 968
 
924
-	if (empty($translation))
925
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
969
+	if (empty($translation)) {
970
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
971
+	}
926 972
 
927 973
 	return strtr($string, $translation);
928 974
 }
@@ -944,8 +990,9 @@  discard block
 block discarded – undo
944 990
 	global $smcFunc;
945 991
 
946 992
 	// It was already short enough!
947
-	if ($smcFunc['strlen']($subject) <= $len)
948
-		return $subject;
993
+	if ($smcFunc['strlen']($subject) <= $len) {
994
+			return $subject;
995
+	}
949 996
 
950 997
 	// Shorten it by the length it was too long, and strip off junk from the end.
951 998
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -964,10 +1011,11 @@  discard block
 block discarded – undo
964 1011
 {
965 1012
 	global $user_info, $modSettings;
966 1013
 
967
-	if ($timestamp === null)
968
-		$timestamp = time();
969
-	elseif ($timestamp == 0)
970
-		return 0;
1014
+	if ($timestamp === null) {
1015
+			$timestamp = time();
1016
+	} elseif ($timestamp == 0) {
1017
+			return 0;
1018
+	}
971 1019
 
972 1020
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
973 1021
 }
@@ -996,8 +1044,9 @@  discard block
 block discarded – undo
996 1044
 		$array[$i] = $array[$j];
997 1045
 		$array[$j] = $temp;
998 1046
 
999
-		for ($i = 1; $p[$i] == 0; $i++)
1000
-			$p[$i] = 1;
1047
+		for ($i = 1; $p[$i] == 0; $i++) {
1048
+					$p[$i] = 1;
1049
+		}
1001 1050
 
1002 1051
 		$orders[] = $array;
1003 1052
 	}
@@ -1029,12 +1078,14 @@  discard block
 block discarded – undo
1029 1078
 	static $disabled;
1030 1079
 
1031 1080
 	// Don't waste cycles
1032
-	if ($message === '')
1033
-		return '';
1081
+	if ($message === '') {
1082
+			return '';
1083
+	}
1034 1084
 
1035 1085
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1036
-	if (!isset($context['utf8']))
1037
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1086
+	if (!isset($context['utf8'])) {
1087
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1088
+	}
1038 1089
 
1039 1090
 	// Clean up any cut/paste issues we may have
1040 1091
 	$message = sanitizeMSCutPaste($message);
@@ -1046,13 +1097,15 @@  discard block
 block discarded – undo
1046 1097
 		return $message;
1047 1098
 	}
1048 1099
 
1049
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1050
-		$smileys = (bool) $smileys;
1100
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1101
+			$smileys = (bool) $smileys;
1102
+	}
1051 1103
 
1052 1104
 	if (empty($modSettings['enableBBC']) && $message !== false)
1053 1105
 	{
1054
-		if ($smileys === true)
1055
-			parsesmileys($message);
1106
+		if ($smileys === true) {
1107
+					parsesmileys($message);
1108
+		}
1056 1109
 
1057 1110
 		return $message;
1058 1111
 	}
@@ -1065,8 +1118,9 @@  discard block
 block discarded – undo
1065 1118
 	}
1066 1119
 
1067 1120
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1068
-	if (!empty($modSettings['autoLinkUrls']))
1069
-		set_tld_regex();
1121
+	if (!empty($modSettings['autoLinkUrls'])) {
1122
+			set_tld_regex();
1123
+	}
1070 1124
 
1071 1125
 	// Allow mods access before entering the main parse_bbc loop
1072 1126
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1080,8 +1134,9 @@  discard block
 block discarded – undo
1080 1134
 
1081 1135
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1082 1136
 
1083
-			foreach ($temp as $tag)
1084
-				$disabled[trim($tag)] = true;
1137
+			foreach ($temp as $tag) {
1138
+							$disabled[trim($tag)] = true;
1139
+			}
1085 1140
 		}
1086 1141
 
1087 1142
 		/* The following bbc are formatted as an array, with keys as follows:
@@ -1211,8 +1266,9 @@  discard block
 block discarded – undo
1211 1266
 					$returnContext = '';
1212 1267
 
1213 1268
 					// BBC or the entire attachments feature is disabled
1214
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1215
-						return $data;
1269
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1270
+											return $data;
1271
+					}
1216 1272
 
1217 1273
 					// Save the attach ID.
1218 1274
 					$attachID = $data;
@@ -1223,8 +1279,9 @@  discard block
 block discarded – undo
1223 1279
 					$currentAttachment = parseAttachBBC($attachID);
1224 1280
 
1225 1281
 					// parseAttachBBC will return a string ($txt key) rather than dying with a fatal_error. Up to you to decide what to do.
1226
-					if (is_string($currentAttachment))
1227
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1282
+					if (is_string($currentAttachment)) {
1283
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1284
+					}
1228 1285
 
1229 1286
 					if (!empty($currentAttachment['is_image']))
1230 1287
 					{
@@ -1240,15 +1297,17 @@  discard block
 block discarded – undo
1240 1297
 							$height = ' height="' . $currentAttachment['height'] . '"';
1241 1298
 						}
1242 1299
 
1243
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1244
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1245
-						else
1246
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1300
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1301
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1302
+						} else {
1303
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1304
+						}
1247 1305
 					}
1248 1306
 
1249 1307
 					// No image. Show a link.
1250
-					else
1251
-						$returnContext .= $currentAttachment['link'];
1308
+					else {
1309
+											$returnContext .= $currentAttachment['link'];
1310
+					}
1252 1311
 
1253 1312
 					// Gotta append what we just did.
1254 1313
 					$data = $returnContext;
@@ -1302,8 +1361,9 @@  discard block
 block discarded – undo
1302 1361
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1303 1362
 						{
1304 1363
 							// Do PHP code coloring?
1305
-							if ($php_parts[$php_i] != '&lt;?php')
1306
-								continue;
1364
+							if ($php_parts[$php_i] != '&lt;?php') {
1365
+															continue;
1366
+							}
1307 1367
 
1308 1368
 							$php_string = '';
1309 1369
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1319,8 +1379,9 @@  discard block
 block discarded – undo
1319 1379
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1320 1380
 
1321 1381
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1322
-						if ($context['browser']['is_opera'])
1323
-							$data .= '&nbsp;';
1382
+						if ($context['browser']['is_opera']) {
1383
+													$data .= '&nbsp;';
1384
+						}
1324 1385
 					}
1325 1386
 				},
1326 1387
 				'block_level' => true,
@@ -1339,8 +1400,9 @@  discard block
 block discarded – undo
1339 1400
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1340 1401
 						{
1341 1402
 							// Do PHP code coloring?
1342
-							if ($php_parts[$php_i] != '&lt;?php')
1343
-								continue;
1403
+							if ($php_parts[$php_i] != '&lt;?php') {
1404
+															continue;
1405
+							}
1344 1406
 
1345 1407
 							$php_string = '';
1346 1408
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1356,8 +1418,9 @@  discard block
 block discarded – undo
1356 1418
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1357 1419
 
1358 1420
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1359
-						if ($context['browser']['is_opera'])
1360
-							$data[0] .= '&nbsp;';
1421
+						if ($context['browser']['is_opera']) {
1422
+													$data[0] .= '&nbsp;';
1423
+						}
1361 1424
 					}
1362 1425
 				},
1363 1426
 				'block_level' => true,
@@ -1398,10 +1461,11 @@  discard block
 block discarded – undo
1398 1461
 				{
1399 1462
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1400 1463
 
1401
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1402
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1403
-					else
1404
-						$css = '';
1464
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1465
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1466
+					} else {
1467
+											$css = '';
1468
+					}
1405 1469
 
1406 1470
 					$data = $class . $css;
1407 1471
 				},
@@ -1416,8 +1480,9 @@  discard block
 block discarded – undo
1416 1480
 				{
1417 1481
 					$data = strtr($data, array('<br />' => ''));
1418 1482
 
1419
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1420
-						$data = 'ftp://' . $data;
1483
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1484
+											$data = 'ftp://' . $data;
1485
+					}
1421 1486
 				},
1422 1487
 			),
1423 1488
 			array(
@@ -1427,8 +1492,9 @@  discard block
 block discarded – undo
1427 1492
 				'after' => '</a>',
1428 1493
 				'validate' => function(&$tag, &$data, $disabled)
1429 1494
 				{
1430
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1431
-						$data = 'ftp://' . $data;
1495
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1496
+											$data = 'ftp://' . $data;
1497
+					}
1432 1498
 				},
1433 1499
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1434 1500
 				'disabled_after' => ' ($1)',
@@ -1488,17 +1554,20 @@  discard block
 block discarded – undo
1488 1554
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1489 1555
 					if ($image_proxy_enabled)
1490 1556
 					{
1491
-						if (!empty($user_info['possibly_robot']))
1492
-							return;
1557
+						if (!empty($user_info['possibly_robot'])) {
1558
+													return;
1559
+						}
1493 1560
 
1494
-						if (empty($scheme))
1495
-							$data = 'http://' . ltrim($data, ':/');
1561
+						if (empty($scheme)) {
1562
+													$data = 'http://' . ltrim($data, ':/');
1563
+						}
1496 1564
 
1497
-						if ($scheme != 'https')
1498
-							$data = get_proxied_url($data);
1565
+						if ($scheme != 'https') {
1566
+													$data = get_proxied_url($data);
1567
+						}
1568
+					} elseif (empty($scheme)) {
1569
+											$data = '//' . ltrim($data, ':/');
1499 1570
 					}
1500
-					elseif (empty($scheme))
1501
-						$data = '//' . ltrim($data, ':/');
1502 1571
 				},
1503 1572
 				'disabled_content' => '($1)',
1504 1573
 			),
@@ -1514,17 +1583,20 @@  discard block
 block discarded – undo
1514 1583
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1515 1584
 					if ($image_proxy_enabled)
1516 1585
 					{
1517
-						if (!empty($user_info['possibly_robot']))
1518
-							return;
1586
+						if (!empty($user_info['possibly_robot'])) {
1587
+													return;
1588
+						}
1519 1589
 
1520
-						if (empty($scheme))
1521
-							$data = 'http://' . ltrim($data, ':/');
1590
+						if (empty($scheme)) {
1591
+													$data = 'http://' . ltrim($data, ':/');
1592
+						}
1522 1593
 
1523
-						if ($scheme != 'https')
1524
-							$data = get_proxied_url($data);
1594
+						if ($scheme != 'https') {
1595
+													$data = get_proxied_url($data);
1596
+						}
1597
+					} elseif (empty($scheme)) {
1598
+											$data = '//' . ltrim($data, ':/');
1525 1599
 					}
1526
-					elseif (empty($scheme))
1527
-						$data = '//' . ltrim($data, ':/');
1528 1600
 				},
1529 1601
 				'disabled_content' => '($1)',
1530 1602
 			),
@@ -1536,8 +1608,9 @@  discard block
 block discarded – undo
1536 1608
 				{
1537 1609
 					$data = strtr($data, array('<br>' => ''));
1538 1610
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1539
-					if (empty($scheme))
1540
-						$data = '//' . ltrim($data, ':/');
1611
+					if (empty($scheme)) {
1612
+											$data = '//' . ltrim($data, ':/');
1613
+					}
1541 1614
 				},
1542 1615
 			),
1543 1616
 			array(
@@ -1548,13 +1621,14 @@  discard block
 block discarded – undo
1548 1621
 				'after' => '</a>',
1549 1622
 				'validate' => function (&$tag, &$data, $disabled)
1550 1623
 				{
1551
-					if (substr($data, 0, 1) == '#')
1552
-						$data = '#post_' . substr($data, 1);
1553
-					else
1624
+					if (substr($data, 0, 1) == '#') {
1625
+											$data = '#post_' . substr($data, 1);
1626
+					} else
1554 1627
 					{
1555 1628
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1556
-						if (empty($scheme))
1557
-							$data = '//' . ltrim($data, ':/');
1629
+						if (empty($scheme)) {
1630
+													$data = '//' . ltrim($data, ':/');
1631
+						}
1558 1632
 					}
1559 1633
 				},
1560 1634
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1645,8 +1719,9 @@  discard block
 block discarded – undo
1645 1719
 					{
1646 1720
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1647 1721
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1648
-						if ($add_begin)
1649
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1722
+						if ($add_begin) {
1723
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1724
+						}
1650 1725
 					}
1651 1726
 				},
1652 1727
 				'block_level' => false,
@@ -1759,20 +1834,17 @@  discard block
 block discarded – undo
1759 1834
 					: function(&$tag, &$data, $disabled)
1760 1835
 					{
1761 1836
 
1762
-						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50))
1763
-							$data[1] = '0 -2px 1px';
1764
-
1765
-						elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100))
1766
-							$data[1] = '2px 0 1px';
1767
-
1768
-						elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190))
1769
-							$data[1] = '0 2px 1px';
1770
-
1771
-						elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280))
1772
-							$data[1] = '-2px 0 1px';
1773
-
1774
-						else
1775
-							$data[1] = '1px 1px 1px';
1837
+						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) {
1838
+													$data[1] = '0 -2px 1px';
1839
+						} elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) {
1840
+													$data[1] = '2px 0 1px';
1841
+						} elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) {
1842
+													$data[1] = '0 2px 1px';
1843
+						} elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) {
1844
+													$data[1] = '-2px 0 1px';
1845
+						} else {
1846
+													$data[1] = '1px 1px 1px';
1847
+						}
1776 1848
 					},
1777 1849
 			),
1778 1850
 			array(
@@ -1828,10 +1900,11 @@  discard block
 block discarded – undo
1828 1900
 				'content' => '$1',
1829 1901
 				'validate' => function (&$tag, &$data, $disabled)
1830 1902
 				{
1831
-					if (is_numeric($data))
1832
-						$data = timeformat($data);
1833
-					else
1834
-						$tag['content'] = '[time]$1[/time]';
1903
+					if (is_numeric($data)) {
1904
+											$data = timeformat($data);
1905
+					} else {
1906
+											$tag['content'] = '[time]$1[/time]';
1907
+					}
1835 1908
 				},
1836 1909
 			),
1837 1910
 			array(
@@ -1863,8 +1936,9 @@  discard block
 block discarded – undo
1863 1936
 				{
1864 1937
 					$data = strtr($data, array('<br>' => ''));
1865 1938
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1866
-					if (empty($scheme))
1867
-						$data = '//' . ltrim($data, ':/');
1939
+					if (empty($scheme)) {
1940
+											$data = '//' . ltrim($data, ':/');
1941
+					}
1868 1942
 				},
1869 1943
 			),
1870 1944
 			array(
@@ -1876,8 +1950,9 @@  discard block
 block discarded – undo
1876 1950
 				'validate' => function (&$tag, &$data, $disabled)
1877 1951
 				{
1878 1952
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1879
-					if (empty($scheme))
1880
-						$data = '//' . ltrim($data, ':/');
1953
+					if (empty($scheme)) {
1954
+											$data = '//' . ltrim($data, ':/');
1955
+					}
1881 1956
 				},
1882 1957
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1883 1958
 				'disabled_after' => ' ($1)',
@@ -1897,12 +1972,13 @@  discard block
 block discarded – undo
1897 1972
 		);
1898 1973
 
1899 1974
 		// Handle legacy bbc codes.
1900
-		foreach ($context['legacy_bbc'] as $bbc)
1901
-			$codes[] = array(
1975
+		foreach ($context['legacy_bbc'] as $bbc) {
1976
+					$codes[] = array(
1902 1977
 				'tag' => $bbc,
1903 1978
 				'before' => '',
1904 1979
 				'after' => '',
1905 1980
 			);
1981
+		}
1906 1982
 
1907 1983
 		// Let mods add new BBC without hassle.
1908 1984
 		call_integration_hook('integrate_bbc_codes', array(&$codes, &$no_autolink_tags));
@@ -1910,8 +1986,9 @@  discard block
 block discarded – undo
1910 1986
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1911 1987
 		if ($message === false)
1912 1988
 		{
1913
-			if (isset($temp_bbc))
1914
-				$bbc_codes = $temp_bbc;
1989
+			if (isset($temp_bbc)) {
1990
+							$bbc_codes = $temp_bbc;
1991
+			}
1915 1992
 			usort($codes, function ($a, $b) {
1916 1993
 				return strcmp($a['tag'], $b['tag']);
1917 1994
 			});
@@ -1931,8 +2008,9 @@  discard block
 block discarded – undo
1931 2008
 		);
1932 2009
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1933 2010
 		{
1934
-			foreach ($itemcodes as $c => $dummy)
1935
-				$bbc_codes[$c] = array();
2011
+			foreach ($itemcodes as $c => $dummy) {
2012
+							$bbc_codes[$c] = array();
2013
+			}
1936 2014
 		}
1937 2015
 
1938 2016
 		// Shhhh!
@@ -1953,12 +2031,14 @@  discard block
 block discarded – undo
1953 2031
 		foreach ($codes as $code)
1954 2032
 		{
1955 2033
 			// Make it easier to process parameters later
1956
-			if (!empty($code['parameters']))
1957
-				ksort($code['parameters'], SORT_STRING);
2034
+			if (!empty($code['parameters'])) {
2035
+							ksort($code['parameters'], SORT_STRING);
2036
+			}
1958 2037
 
1959 2038
 			// If we are not doing every tag only do ones we are interested in.
1960
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1961
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2039
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
2040
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2041
+			}
1962 2042
 		}
1963 2043
 		$codes = null;
1964 2044
 	}
@@ -1969,8 +2049,9 @@  discard block
 block discarded – undo
1969 2049
 		// It's likely this will change if the message is modified.
1970 2050
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1971 2051
 
1972
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1973
-			return $temp;
2052
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
2053
+					return $temp;
2054
+		}
1974 2055
 
1975 2056
 		$cache_t = microtime();
1976 2057
 	}
@@ -2002,8 +2083,9 @@  discard block
 block discarded – undo
2002 2083
 		$disabled['flash'] = true;
2003 2084
 
2004 2085
 		// @todo Change maybe?
2005
-		if (!isset($_GET['images']))
2006
-			$disabled['img'] = true;
2086
+		if (!isset($_GET['images'])) {
2087
+					$disabled['img'] = true;
2088
+		}
2007 2089
 
2008 2090
 		// @todo Interface/setting to add more?
2009 2091
 	}
@@ -2014,8 +2096,9 @@  discard block
 block discarded – undo
2014 2096
 	$alltags = array();
2015 2097
 	foreach ($bbc_codes as $section)
2016 2098
 	{
2017
-		foreach ($section as $code)
2018
-			$alltags[] = $code['tag'];
2099
+		foreach ($section as $code) {
2100
+					$alltags[] = $code['tag'];
2101
+		}
2019 2102
 	}
2020 2103
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
2021 2104
 
@@ -2027,8 +2110,9 @@  discard block
 block discarded – undo
2027 2110
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
2028 2111
 
2029 2112
 		// Failsafe.
2030
-		if ($pos === false || $last_pos > $pos)
2031
-			$pos = strlen($message) + 1;
2113
+		if ($pos === false || $last_pos > $pos) {
2114
+					$pos = strlen($message) + 1;
2115
+		}
2032 2116
 
2033 2117
 		// Can't have a one letter smiley, URL, or email! (sorry.)
2034 2118
 		if ($last_pos < $pos - 1)
@@ -2046,8 +2130,9 @@  discard block
 block discarded – undo
2046 2130
 
2047 2131
 				// <br> should be empty.
2048 2132
 				$empty_tags = array('br', 'hr');
2049
-				foreach ($empty_tags as $tag)
2050
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2133
+				foreach ($empty_tags as $tag) {
2134
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2135
+				}
2051 2136
 
2052 2137
 				// b, u, i, s, pre... basic tags.
2053 2138
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -2056,8 +2141,9 @@  discard block
 block discarded – undo
2056 2141
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
2057 2142
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
2058 2143
 
2059
-					if ($diff > 0)
2060
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2144
+					if ($diff > 0) {
2145
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2146
+					}
2061 2147
 				}
2062 2148
 
2063 2149
 				// Do <img ...> - with security... action= -> action-.
@@ -2070,8 +2156,9 @@  discard block
 block discarded – undo
2070 2156
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
2071 2157
 
2072 2158
 						// Remove action= from the URL - no funny business, now.
2073
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
2074
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2159
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2160
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2161
+						}
2075 2162
 
2076 2163
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
2077 2164
 					}
@@ -2086,16 +2173,18 @@  discard block
 block discarded – undo
2086 2173
 				$no_autolink_area = false;
2087 2174
 				if (!empty($open_tags))
2088 2175
 				{
2089
-					foreach ($open_tags as $open_tag)
2090
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2176
+					foreach ($open_tags as $open_tag) {
2177
+											if (in_array($open_tag['tag'], $no_autolink_tags))
2091 2178
 							$no_autolink_area = true;
2179
+					}
2092 2180
 				}
2093 2181
 
2094 2182
 				// Don't go backwards.
2095 2183
 				// @todo Don't think is the real solution....
2096 2184
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
2097
-				if ($pos < $lastAutoPos)
2098
-					$no_autolink_area = true;
2185
+				if ($pos < $lastAutoPos) {
2186
+									$no_autolink_area = true;
2187
+				}
2099 2188
 				$lastAutoPos = $pos;
2100 2189
 
2101 2190
 				if (!$no_autolink_area)
@@ -2200,29 +2289,33 @@  discard block
 block discarded – undo
2200 2289
 							$url = array_shift($matches);
2201 2290
 
2202 2291
 							// If this isn't a clean URL, bail out
2203
-							if ($url != sanitize_iri($url))
2204
-								return $url;
2292
+							if ($url != sanitize_iri($url)) {
2293
+															return $url;
2294
+							}
2205 2295
 
2206 2296
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2207 2297
 
2208 2298
 							if ($scheme == 'mailto')
2209 2299
 							{
2210 2300
 								$email_address = str_replace('mailto:', '', $url);
2211
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2212
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2213
-								else
2214
-									return $url;
2301
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2302
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2303
+								} else {
2304
+																	return $url;
2305
+								}
2215 2306
 							}
2216 2307
 
2217 2308
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2218
-							if (empty($scheme))
2219
-								$fullUrl = '//' . ltrim($url, ':/');
2220
-							else
2221
-								$fullUrl = $url;
2309
+							if (empty($scheme)) {
2310
+															$fullUrl = '//' . ltrim($url, ':/');
2311
+							} else {
2312
+															$fullUrl = $url;
2313
+							}
2222 2314
 
2223 2315
 							// Make sure that $fullUrl really is valid
2224
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2225
-								return $url;
2316
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2317
+															return $url;
2318
+							}
2226 2319
 
2227 2320
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2228 2321
 						}, $data);
@@ -2271,22 +2364,25 @@  discard block
 block discarded – undo
2271 2364
 		}
2272 2365
 
2273 2366
 		// Are we there yet?  Are we there yet?
2274
-		if ($pos >= strlen($message) - 1)
2275
-			break;
2367
+		if ($pos >= strlen($message) - 1) {
2368
+					break;
2369
+		}
2276 2370
 
2277 2371
 		$tags = strtolower($message[$pos + 1]);
2278 2372
 
2279 2373
 		if ($tags == '/' && !empty($open_tags))
2280 2374
 		{
2281 2375
 			$pos2 = strpos($message, ']', $pos + 1);
2282
-			if ($pos2 == $pos + 2)
2283
-				continue;
2376
+			if ($pos2 == $pos + 2) {
2377
+							continue;
2378
+			}
2284 2379
 
2285 2380
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2286 2381
 
2287 2382
 			// A closing tag that doesn't match any open tags? Skip it.
2288
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2289
-				continue;
2383
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2384
+							continue;
2385
+			}
2290 2386
 
2291 2387
 			$to_close = array();
2292 2388
 			$block_level = null;
@@ -2294,8 +2390,9 @@  discard block
 block discarded – undo
2294 2390
 			do
2295 2391
 			{
2296 2392
 				$tag = array_pop($open_tags);
2297
-				if (!$tag)
2298
-					break;
2393
+				if (!$tag) {
2394
+									break;
2395
+				}
2299 2396
 
2300 2397
 				if (!empty($tag['block_level']))
2301 2398
 				{
@@ -2309,10 +2406,11 @@  discard block
 block discarded – undo
2309 2406
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2310 2407
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2311 2408
 					{
2312
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2313
-							if ($temp['tag'] == $look_for)
2409
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2410
+													if ($temp['tag'] == $look_for)
2314 2411
 							{
2315 2412
 								$block_level = !empty($temp['block_level']);
2413
+						}
2316 2414
 								break;
2317 2415
 							}
2318 2416
 					}
@@ -2334,15 +2432,15 @@  discard block
 block discarded – undo
2334 2432
 			{
2335 2433
 				$open_tags = $to_close;
2336 2434
 				continue;
2337
-			}
2338
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2435
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2339 2436
 			{
2340 2437
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2341 2438
 				{
2342
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2343
-						if ($temp['tag'] == $look_for)
2439
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2440
+											if ($temp['tag'] == $look_for)
2344 2441
 						{
2345 2442
 							$block_level = !empty($temp['block_level']);
2443
+					}
2346 2444
 							break;
2347 2445
 						}
2348 2446
 				}
@@ -2350,8 +2448,9 @@  discard block
 block discarded – undo
2350 2448
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2351 2449
 				if (!$block_level)
2352 2450
 				{
2353
-					foreach ($to_close as $tag)
2354
-						array_push($open_tags, $tag);
2451
+					foreach ($to_close as $tag) {
2452
+											array_push($open_tags, $tag);
2453
+					}
2355 2454
 					continue;
2356 2455
 				}
2357 2456
 			}
@@ -2364,14 +2463,17 @@  discard block
 block discarded – undo
2364 2463
 
2365 2464
 				// See the comment at the end of the big loop - just eating whitespace ;).
2366 2465
 				$whitespace_regex = '';
2367
-				if (!empty($tag['block_level']))
2368
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2466
+				if (!empty($tag['block_level'])) {
2467
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2468
+				}
2369 2469
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2370
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2371
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2470
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2471
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2472
+				}
2372 2473
 
2373
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2374
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2474
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2475
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2476
+				}
2375 2477
 			}
2376 2478
 
2377 2479
 			if (!empty($to_close))
@@ -2384,8 +2486,9 @@  discard block
 block discarded – undo
2384 2486
 		}
2385 2487
 
2386 2488
 		// No tags for this character, so just keep going (fastest possible course.)
2387
-		if (!isset($bbc_codes[$tags]))
2388
-			continue;
2489
+		if (!isset($bbc_codes[$tags])) {
2490
+					continue;
2491
+		}
2389 2492
 
2390 2493
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2391 2494
 		$tag = null;
@@ -2394,48 +2497,57 @@  discard block
 block discarded – undo
2394 2497
 			$pt_strlen = strlen($possible['tag']);
2395 2498
 
2396 2499
 			// Not a match?
2397
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2398
-				continue;
2500
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2501
+							continue;
2502
+			}
2399 2503
 
2400 2504
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2401 2505
 
2402 2506
 			// A tag is the last char maybe
2403
-			if ($next_c == '')
2404
-				break;
2507
+			if ($next_c == '') {
2508
+							break;
2509
+			}
2405 2510
 
2406 2511
 			// A test validation?
2407
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2408
-				continue;
2512
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2513
+							continue;
2514
+			}
2409 2515
 			// Do we want parameters?
2410 2516
 			elseif (!empty($possible['parameters']))
2411 2517
 			{
2412
-				if ($next_c != ' ')
2413
-					continue;
2414
-			}
2415
-			elseif (isset($possible['type']))
2518
+				if ($next_c != ' ') {
2519
+									continue;
2520
+				}
2521
+			} elseif (isset($possible['type']))
2416 2522
 			{
2417 2523
 				// Do we need an equal sign?
2418
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2419
-					continue;
2524
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2525
+									continue;
2526
+				}
2420 2527
 				// Maybe we just want a /...
2421
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2422
-					continue;
2528
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2529
+									continue;
2530
+				}
2423 2531
 				// An immediate ]?
2424
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2425
-					continue;
2532
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2533
+									continue;
2534
+				}
2426 2535
 			}
2427 2536
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2428
-			elseif ($next_c != ']')
2429
-				continue;
2537
+			elseif ($next_c != ']') {
2538
+							continue;
2539
+			}
2430 2540
 
2431 2541
 			// Check allowed tree?
2432
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2433
-				continue;
2434
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2435
-				continue;
2542
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2543
+							continue;
2544
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2545
+							continue;
2546
+			}
2436 2547
 			// If this is in the list of disallowed child tags, don't parse it.
2437
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2438
-				continue;
2548
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2549
+							continue;
2550
+			}
2439 2551
 
2440 2552
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2441 2553
 
@@ -2447,8 +2559,9 @@  discard block
 block discarded – undo
2447 2559
 				foreach ($open_tags as $open_quote)
2448 2560
 				{
2449 2561
 					// Every parent quote this quote has flips the styling
2450
-					if ($open_quote['tag'] == 'quote')
2451
-						$quote_alt = !$quote_alt;
2562
+					if ($open_quote['tag'] == 'quote') {
2563
+											$quote_alt = !$quote_alt;
2564
+					}
2452 2565
 				}
2453 2566
 				// Add a class to the quote to style alternating blockquotes
2454 2567
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2459,8 +2572,9 @@  discard block
 block discarded – undo
2459 2572
 			{
2460 2573
 				// Build a regular expression for each parameter for the current tag.
2461 2574
 				$preg = array();
2462
-				foreach ($possible['parameters'] as $p => $info)
2463
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2575
+				foreach ($possible['parameters'] as $p => $info) {
2576
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2577
+				}
2464 2578
 
2465 2579
 				// Extract the string that potentially holds our parameters.
2466 2580
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2479,24 +2593,27 @@  discard block
 block discarded – undo
2479 2593
 
2480 2594
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2481 2595
 
2482
-					if ($match)
2483
-						$blob_counter = count($blobs) + 1;
2596
+					if ($match) {
2597
+											$blob_counter = count($blobs) + 1;
2598
+					}
2484 2599
 				}
2485 2600
 
2486 2601
 				// Didn't match our parameter list, try the next possible.
2487
-				if (!$match)
2488
-					continue;
2602
+				if (!$match) {
2603
+									continue;
2604
+				}
2489 2605
 
2490 2606
 				$params = array();
2491 2607
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2492 2608
 				{
2493 2609
 					$key = strtok(ltrim($matches[$i]), '=');
2494
-					if (isset($possible['parameters'][$key]['value']))
2495
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2496
-					elseif (isset($possible['parameters'][$key]['validate']))
2497
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2498
-					else
2499
-						$params['{' . $key . '}'] = $matches[$i + 1];
2610
+					if (isset($possible['parameters'][$key]['value'])) {
2611
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2612
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2613
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2614
+					} else {
2615
+											$params['{' . $key . '}'] = $matches[$i + 1];
2616
+					}
2500 2617
 
2501 2618
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2502 2619
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2504,23 +2621,26 @@  discard block
 block discarded – undo
2504 2621
 
2505 2622
 				foreach ($possible['parameters'] as $p => $info)
2506 2623
 				{
2507
-					if (!isset($params['{' . $p . '}']))
2508
-						$params['{' . $p . '}'] = '';
2624
+					if (!isset($params['{' . $p . '}'])) {
2625
+											$params['{' . $p . '}'] = '';
2626
+					}
2509 2627
 				}
2510 2628
 
2511 2629
 				$tag = $possible;
2512 2630
 
2513 2631
 				// Put the parameters into the string.
2514
-				if (isset($tag['before']))
2515
-					$tag['before'] = strtr($tag['before'], $params);
2516
-				if (isset($tag['after']))
2517
-					$tag['after'] = strtr($tag['after'], $params);
2518
-				if (isset($tag['content']))
2519
-					$tag['content'] = strtr($tag['content'], $params);
2632
+				if (isset($tag['before'])) {
2633
+									$tag['before'] = strtr($tag['before'], $params);
2634
+				}
2635
+				if (isset($tag['after'])) {
2636
+									$tag['after'] = strtr($tag['after'], $params);
2637
+				}
2638
+				if (isset($tag['content'])) {
2639
+									$tag['content'] = strtr($tag['content'], $params);
2640
+				}
2520 2641
 
2521 2642
 				$pos1 += strlen($given_param_string);
2522
-			}
2523
-			else
2643
+			} else
2524 2644
 			{
2525 2645
 				$tag = $possible;
2526 2646
 				$params = array();
@@ -2531,8 +2651,9 @@  discard block
 block discarded – undo
2531 2651
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2532 2652
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2533 2653
 		{
2534
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2535
-				continue;
2654
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2655
+							continue;
2656
+			}
2536 2657
 
2537 2658
 			$tag = $itemcodes[$message[$pos + 1]];
2538 2659
 
@@ -2553,9 +2674,9 @@  discard block
 block discarded – undo
2553 2674
 			{
2554 2675
 				array_pop($open_tags);
2555 2676
 				$code = '</li>';
2677
+			} else {
2678
+							$code = '';
2556 2679
 			}
2557
-			else
2558
-				$code = '';
2559 2680
 
2560 2681
 			// Now we open a new tag.
2561 2682
 			$open_tags[] = array(
@@ -2602,12 +2723,14 @@  discard block
 block discarded – undo
2602 2723
 		}
2603 2724
 
2604 2725
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2605
-		if ($tag === null)
2606
-			continue;
2726
+		if ($tag === null) {
2727
+					continue;
2728
+		}
2607 2729
 
2608 2730
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2609
-		if (isset($inside['disallow_children']))
2610
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2731
+		if (isset($inside['disallow_children'])) {
2732
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2733
+		}
2611 2734
 
2612 2735
 		// Is this tag disabled?
2613 2736
 		if (isset($disabled[$tag['tag']]))
@@ -2617,14 +2740,13 @@  discard block
 block discarded – undo
2617 2740
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2618 2741
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2619 2742
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2620
-			}
2621
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2743
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2622 2744
 			{
2623 2745
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2624 2746
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2747
+			} else {
2748
+							$tag['content'] = $tag['disabled_content'];
2625 2749
 			}
2626
-			else
2627
-				$tag['content'] = $tag['disabled_content'];
2628 2750
 		}
2629 2751
 
2630 2752
 		// we use this a lot
@@ -2634,8 +2756,9 @@  discard block
 block discarded – undo
2634 2756
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2635 2757
 		{
2636 2758
 			$n = count($open_tags) - 1;
2637
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2638
-				$n--;
2759
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2760
+							$n--;
2761
+			}
2639 2762
 
2640 2763
 			// Close all the non block level tags so this tag isn't surrounded by them.
2641 2764
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2647,12 +2770,15 @@  discard block
 block discarded – undo
2647 2770
 
2648 2771
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2649 2772
 				$whitespace_regex = '';
2650
-				if (!empty($tag['block_level']))
2651
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2652
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2653
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2654
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2655
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2773
+				if (!empty($tag['block_level'])) {
2774
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2775
+				}
2776
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2777
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2778
+				}
2779
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2780
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2781
+				}
2656 2782
 
2657 2783
 				array_pop($open_tags);
2658 2784
 			}
@@ -2673,16 +2799,19 @@  discard block
 block discarded – undo
2673 2799
 		elseif ($tag['type'] == 'unparsed_content')
2674 2800
 		{
2675 2801
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2676
-			if ($pos2 === false)
2677
-				continue;
2802
+			if ($pos2 === false) {
2803
+							continue;
2804
+			}
2678 2805
 
2679 2806
 			$data = substr($message, $pos1, $pos2 - $pos1);
2680 2807
 
2681
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2682
-				$data = substr($data, 4);
2808
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2809
+							$data = substr($data, 4);
2810
+			}
2683 2811
 
2684
-			if (isset($tag['validate']))
2685
-				$tag['validate']($tag, $data, $disabled, $params);
2812
+			if (isset($tag['validate'])) {
2813
+							$tag['validate']($tag, $data, $disabled, $params);
2814
+			}
2686 2815
 
2687 2816
 			$code = strtr($tag['content'], array('$1' => $data));
2688 2817
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2697,34 +2826,40 @@  discard block
 block discarded – undo
2697 2826
 			if (isset($tag['quoted']))
2698 2827
 			{
2699 2828
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2700
-				if ($tag['quoted'] != 'optional' && !$quoted)
2701
-					continue;
2829
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2830
+									continue;
2831
+				}
2702 2832
 
2703
-				if ($quoted)
2704
-					$pos1 += 6;
2833
+				if ($quoted) {
2834
+									$pos1 += 6;
2835
+				}
2836
+			} else {
2837
+							$quoted = false;
2705 2838
 			}
2706
-			else
2707
-				$quoted = false;
2708 2839
 
2709 2840
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2710
-			if ($pos2 === false)
2711
-				continue;
2841
+			if ($pos2 === false) {
2842
+							continue;
2843
+			}
2712 2844
 
2713 2845
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2714
-			if ($pos3 === false)
2715
-				continue;
2846
+			if ($pos3 === false) {
2847
+							continue;
2848
+			}
2716 2849
 
2717 2850
 			$data = array(
2718 2851
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2719 2852
 				substr($message, $pos1, $pos2 - $pos1)
2720 2853
 			);
2721 2854
 
2722
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2723
-				$data[0] = substr($data[0], 4);
2855
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2856
+							$data[0] = substr($data[0], 4);
2857
+			}
2724 2858
 
2725 2859
 			// Validation for my parking, please!
2726
-			if (isset($tag['validate']))
2727
-				$tag['validate']($tag, $data, $disabled, $params);
2860
+			if (isset($tag['validate'])) {
2861
+							$tag['validate']($tag, $data, $disabled, $params);
2862
+			}
2728 2863
 
2729 2864
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2730 2865
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2741,23 +2876,27 @@  discard block
 block discarded – undo
2741 2876
 		elseif ($tag['type'] == 'unparsed_commas_content')
2742 2877
 		{
2743 2878
 			$pos2 = strpos($message, ']', $pos1);
2744
-			if ($pos2 === false)
2745
-				continue;
2879
+			if ($pos2 === false) {
2880
+							continue;
2881
+			}
2746 2882
 
2747 2883
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2748
-			if ($pos3 === false)
2749
-				continue;
2884
+			if ($pos3 === false) {
2885
+							continue;
2886
+			}
2750 2887
 
2751 2888
 			// We want $1 to be the content, and the rest to be csv.
2752 2889
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2753 2890
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2754 2891
 
2755
-			if (isset($tag['validate']))
2756
-				$tag['validate']($tag, $data, $disabled, $params);
2892
+			if (isset($tag['validate'])) {
2893
+							$tag['validate']($tag, $data, $disabled, $params);
2894
+			}
2757 2895
 
2758 2896
 			$code = $tag['content'];
2759
-			foreach ($data as $k => $d)
2760
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2897
+			foreach ($data as $k => $d) {
2898
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2899
+			}
2761 2900
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2762 2901
 			$pos += strlen($code) - 1 + 2;
2763 2902
 		}
@@ -2765,24 +2904,28 @@  discard block
 block discarded – undo
2765 2904
 		elseif ($tag['type'] == 'unparsed_commas')
2766 2905
 		{
2767 2906
 			$pos2 = strpos($message, ']', $pos1);
2768
-			if ($pos2 === false)
2769
-				continue;
2907
+			if ($pos2 === false) {
2908
+							continue;
2909
+			}
2770 2910
 
2771 2911
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2772 2912
 
2773
-			if (isset($tag['validate']))
2774
-				$tag['validate']($tag, $data, $disabled, $params);
2913
+			if (isset($tag['validate'])) {
2914
+							$tag['validate']($tag, $data, $disabled, $params);
2915
+			}
2775 2916
 
2776 2917
 			// Fix after, for disabled code mainly.
2777
-			foreach ($data as $k => $d)
2778
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2918
+			foreach ($data as $k => $d) {
2919
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2920
+			}
2779 2921
 
2780 2922
 			$open_tags[] = $tag;
2781 2923
 
2782 2924
 			// Replace them out, $1, $2, $3, $4, etc.
2783 2925
 			$code = $tag['before'];
2784
-			foreach ($data as $k => $d)
2785
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2926
+			foreach ($data as $k => $d) {
2927
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2928
+			}
2786 2929
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2787 2930
 			$pos += strlen($code) - 1 + 2;
2788 2931
 		}
@@ -2793,28 +2936,33 @@  discard block
 block discarded – undo
2793 2936
 			if (isset($tag['quoted']))
2794 2937
 			{
2795 2938
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2796
-				if ($tag['quoted'] != 'optional' && !$quoted)
2797
-					continue;
2939
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2940
+									continue;
2941
+				}
2798 2942
 
2799
-				if ($quoted)
2800
-					$pos1 += 6;
2943
+				if ($quoted) {
2944
+									$pos1 += 6;
2945
+				}
2946
+			} else {
2947
+							$quoted = false;
2801 2948
 			}
2802
-			else
2803
-				$quoted = false;
2804 2949
 
2805 2950
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2806
-			if ($pos2 === false)
2807
-				continue;
2951
+			if ($pos2 === false) {
2952
+							continue;
2953
+			}
2808 2954
 
2809 2955
 			$data = substr($message, $pos1, $pos2 - $pos1);
2810 2956
 
2811 2957
 			// Validation for my parking, please!
2812
-			if (isset($tag['validate']))
2813
-				$tag['validate']($tag, $data, $disabled, $params);
2958
+			if (isset($tag['validate'])) {
2959
+							$tag['validate']($tag, $data, $disabled, $params);
2960
+			}
2814 2961
 
2815 2962
 			// For parsed content, we must recurse to avoid security problems.
2816
-			if ($tag['type'] != 'unparsed_equals')
2817
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2963
+			if ($tag['type'] != 'unparsed_equals') {
2964
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2965
+			}
2818 2966
 
2819 2967
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2820 2968
 
@@ -2826,34 +2974,40 @@  discard block
 block discarded – undo
2826 2974
 		}
2827 2975
 
2828 2976
 		// If this is block level, eat any breaks after it.
2829
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2830
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2977
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2978
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2979
+		}
2831 2980
 
2832 2981
 		// Are we trimming outside this tag?
2833
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2834
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2982
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2983
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2984
+		}
2835 2985
 	}
2836 2986
 
2837 2987
 	// Close any remaining tags.
2838
-	while ($tag = array_pop($open_tags))
2839
-		$message .= "\n" . $tag['after'] . "\n";
2988
+	while ($tag = array_pop($open_tags)) {
2989
+			$message .= "\n" . $tag['after'] . "\n";
2990
+	}
2840 2991
 
2841 2992
 	// Parse the smileys within the parts where it can be done safely.
2842 2993
 	if ($smileys === true)
2843 2994
 	{
2844 2995
 		$message_parts = explode("\n", $message);
2845
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2846
-			parsesmileys($message_parts[$i]);
2996
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2997
+					parsesmileys($message_parts[$i]);
2998
+		}
2847 2999
 
2848 3000
 		$message = implode('', $message_parts);
2849 3001
 	}
2850 3002
 
2851 3003
 	// No smileys, just get rid of the markers.
2852
-	else
2853
-		$message = strtr($message, array("\n" => ''));
3004
+	else {
3005
+			$message = strtr($message, array("\n" => ''));
3006
+	}
2854 3007
 
2855
-	if ($message !== '' && $message[0] === ' ')
2856
-		$message = '&nbsp;' . substr($message, 1);
3008
+	if ($message !== '' && $message[0] === ' ') {
3009
+			$message = '&nbsp;' . substr($message, 1);
3010
+	}
2857 3011
 
2858 3012
 	// Cleanup whitespace.
2859 3013
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2862,15 +3016,16 @@  discard block
 block discarded – undo
2862 3016
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2863 3017
 
2864 3018
 	// Cache the output if it took some time...
2865
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2866
-		cache_put_data($cache_key, $message, 240);
3019
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
3020
+			cache_put_data($cache_key, $message, 240);
3021
+	}
2867 3022
 
2868 3023
 	// If this was a force parse revert if needed.
2869 3024
 	if (!empty($parse_tags))
2870 3025
 	{
2871
-		if (empty($temp_bbc))
2872
-			$bbc_codes = array();
2873
-		else
3026
+		if (empty($temp_bbc)) {
3027
+					$bbc_codes = array();
3028
+		} else
2874 3029
 		{
2875 3030
 			$bbc_codes = $temp_bbc;
2876 3031
 			unset($temp_bbc);
@@ -2897,8 +3052,9 @@  discard block
 block discarded – undo
2897 3052
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2898 3053
 
2899 3054
 	// No smiley set at all?!
2900
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2901
-		return;
3055
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
3056
+			return;
3057
+	}
2902 3058
 
2903 3059
 	// Maybe a mod wants to implement an alternative method (e.g. emojis instead of images)
2904 3060
 	call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements));
@@ -2912,8 +3068,7 @@  discard block
 block discarded – undo
2912 3068
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', 'O:-)');
2913 3069
 			$smileysto = array('evil.png', 'cheesy.png', 'rolleyes.png', 'angry.png', 'laugh.png', 'smiley.png', 'wink.png', 'grin.png', 'sad.png', 'shocked.png', 'cool.png', 'tongue.png', 'huh.png', 'embarrassed.png', 'lipsrsealed.png', 'kiss.png', 'cry.png', 'undecided.png', 'azn.png', 'afro.png', 'police.png', 'angel.png');
2914 3070
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2915
-		}
2916
-		else
3071
+		} else
2917 3072
 		{
2918 3073
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2919 3074
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2937,9 +3092,9 @@  discard block
 block discarded – undo
2937 3092
 				$smcFunc['db_free_result']($result);
2938 3093
 
2939 3094
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
3095
+			} else {
3096
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2940 3097
 			}
2941
-			else
2942
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2943 3098
 		}
2944 3099
 
2945 3100
 		// The non-breaking-space is a complex thing...
@@ -2961,16 +3116,18 @@  discard block
 block discarded – undo
2961 3116
 				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2962 3117
 				if (!empty($alt_images))
2963 3118
 				{
2964
-					foreach ($exts as $ext)
2965
-						if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
3119
+					foreach ($exts as $ext) {
3120
+											if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
2966 3121
 						{
2967 3122
 							$smileysto[$i] = $fname . '.' . $ext;
3123
+					}
2968 3124
 							break;
2969 3125
 						}
2970 3126
 				}
2971 3127
 				// If we have no image, just leave the text version in place
2972
-				else
2973
-					continue;
3128
+				else {
3129
+									continue;
3130
+				}
2974 3131
 			}
2975 3132
 
2976 3133
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
@@ -3046,12 +3203,14 @@  discard block
 block discarded – undo
3046 3203
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
3047 3204
 
3048 3205
 	// Only use the proxy if enabled and necessary
3049
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
3050
-		return $url;
3206
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3207
+			return $url;
3208
+	}
3051 3209
 
3052 3210
 	// We don't need to proxy our own resources
3053
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
3054
-		return strtr($url, array('http://' => 'https://'));
3211
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3212
+			return strtr($url, array('http://' => 'https://'));
3213
+	}
3055 3214
 
3056 3215
 	// By default, use SMF's own image proxy script
3057 3216
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -3076,35 +3235,41 @@  discard block
 block discarded – undo
3076 3235
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
3077 3236
 
3078 3237
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
3079
-	if (!empty($context['flush_mail']))
3080
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3238
+	if (!empty($context['flush_mail'])) {
3239
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3081 3240
 		AddMailQueue(true);
3241
+	}
3082 3242
 
3083 3243
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
3084 3244
 
3085
-	if ($add)
3086
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3245
+	if ($add) {
3246
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3247
+	}
3087 3248
 
3088 3249
 	// Put the session ID in.
3089
-	if (defined('SID') && SID != '')
3090
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3250
+	if (defined('SID') && SID != '') {
3251
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3252
+	}
3091 3253
 	// Keep that debug in their for template debugging!
3092
-	elseif (isset($_GET['debug']))
3093
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3254
+	elseif (isset($_GET['debug'])) {
3255
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3256
+	}
3094 3257
 
3095 3258
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
3096 3259
 	{
3097
-		if (defined('SID') && SID != '')
3098
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3260
+		if (defined('SID') && SID != '') {
3261
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3099 3262
 				function ($m) use ($scripturl)
3100 3263
 				{
3101 3264
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3265
+		}
3102 3266
 				}, $setLocation);
3103
-		else
3104
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3267
+		else {
3268
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3105 3269
 				function ($m) use ($scripturl)
3106 3270
 				{
3107 3271
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3272
+		}
3108 3273
 				}, $setLocation);
3109 3274
 	}
3110 3275
 
@@ -3115,8 +3280,9 @@  discard block
 block discarded – undo
3115 3280
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
3116 3281
 
3117 3282
 	// Debugging.
3118
-	if (isset($db_show_debug) && $db_show_debug === true)
3119
-		$_SESSION['debug_redirect'] = $db_cache;
3283
+	if (isset($db_show_debug) && $db_show_debug === true) {
3284
+			$_SESSION['debug_redirect'] = $db_cache;
3285
+	}
3120 3286
 
3121 3287
 	obExit(false);
3122 3288
 }
@@ -3135,51 +3301,60 @@  discard block
 block discarded – undo
3135 3301
 
3136 3302
 	// Attempt to prevent a recursive loop.
3137 3303
 	++$level;
3138
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
3139
-		exit;
3140
-	if ($from_fatal_error)
3141
-		$has_fatal_error = true;
3304
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3305
+			exit;
3306
+	}
3307
+	if ($from_fatal_error) {
3308
+			$has_fatal_error = true;
3309
+	}
3142 3310
 
3143 3311
 	// Clear out the stat cache.
3144 3312
 	trackStats();
3145 3313
 
3146 3314
 	// If we have mail to send, send it.
3147
-	if (!empty($context['flush_mail']))
3148
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3315
+	if (!empty($context['flush_mail'])) {
3316
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3149 3317
 		AddMailQueue(true);
3318
+	}
3150 3319
 
3151 3320
 	$do_header = $header === null ? !$header_done : $header;
3152
-	if ($do_footer === null)
3153
-		$do_footer = $do_header;
3321
+	if ($do_footer === null) {
3322
+			$do_footer = $do_header;
3323
+	}
3154 3324
 
3155 3325
 	// Has the template/header been done yet?
3156 3326
 	if ($do_header)
3157 3327
 	{
3158 3328
 		// Was the page title set last minute? Also update the HTML safe one.
3159
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
3160
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3329
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3330
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3331
+		}
3161 3332
 
3162 3333
 		// Start up the session URL fixer.
3163 3334
 		ob_start('ob_sessrewrite');
3164 3335
 
3165
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3166
-			$buffers = explode(',', $settings['output_buffers']);
3167
-		elseif (!empty($settings['output_buffers']))
3168
-			$buffers = $settings['output_buffers'];
3169
-		else
3170
-			$buffers = array();
3336
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3337
+					$buffers = explode(',', $settings['output_buffers']);
3338
+		} elseif (!empty($settings['output_buffers'])) {
3339
+					$buffers = $settings['output_buffers'];
3340
+		} else {
3341
+					$buffers = array();
3342
+		}
3171 3343
 
3172
-		if (isset($modSettings['integrate_buffer']))
3173
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3344
+		if (isset($modSettings['integrate_buffer'])) {
3345
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3346
+		}
3174 3347
 
3175
-		if (!empty($buffers))
3176
-			foreach ($buffers as $function)
3348
+		if (!empty($buffers)) {
3349
+					foreach ($buffers as $function)
3177 3350
 			{
3178 3351
 				$call = call_helper($function, true);
3352
+		}
3179 3353
 
3180 3354
 				// Is it valid?
3181
-				if (!empty($call))
3182
-					ob_start($call);
3355
+				if (!empty($call)) {
3356
+									ob_start($call);
3357
+				}
3183 3358
 			}
3184 3359
 
3185 3360
 		// Display the screen in the logical order.
@@ -3191,8 +3366,9 @@  discard block
 block discarded – undo
3191 3366
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3192 3367
 
3193 3368
 		// Anything special to put out?
3194
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3195
-			echo $context['insert_after_template'];
3369
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3370
+					echo $context['insert_after_template'];
3371
+		}
3196 3372
 
3197 3373
 		// Just so we don't get caught in an endless loop of errors from the footer...
3198 3374
 		if (!$footer_done)
@@ -3201,14 +3377,16 @@  discard block
 block discarded – undo
3201 3377
 			template_footer();
3202 3378
 
3203 3379
 			// (since this is just debugging... it's okay that it's after </html>.)
3204
-			if (!isset($_REQUEST['xml']))
3205
-				displayDebug();
3380
+			if (!isset($_REQUEST['xml'])) {
3381
+							displayDebug();
3382
+			}
3206 3383
 		}
3207 3384
 	}
3208 3385
 
3209 3386
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3210
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3211
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3387
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3388
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3389
+	}
3212 3390
 
3213 3391
 	// For session check verification.... don't switch browsers...
3214 3392
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3217,9 +3395,10 @@  discard block
 block discarded – undo
3217 3395
 	call_integration_hook('integrate_exit', array($do_footer));
3218 3396
 
3219 3397
 	// Don't exit if we're coming from index.php; that will pass through normally.
3220
-	if (!$from_index)
3221
-		exit;
3222
-}
3398
+	if (!$from_index) {
3399
+			exit;
3400
+	}
3401
+	}
3223 3402
 
3224 3403
 /**
3225 3404
  * Get the size of a specified image with better error handling.
@@ -3238,8 +3417,9 @@  discard block
 block discarded – undo
3238 3417
 	$url = str_replace(' ', '%20', $url);
3239 3418
 
3240 3419
 	// Can we pull this from the cache... please please?
3241
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3242
-		return $temp;
3420
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3421
+			return $temp;
3422
+	}
3243 3423
 	$t = microtime();
3244 3424
 
3245 3425
 	// Get the host to pester...
@@ -3249,12 +3429,10 @@  discard block
 block discarded – undo
3249 3429
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3250 3430
 	{
3251 3431
 		return false;
3252
-	}
3253
-	elseif (!isset($match[1]))
3432
+	} elseif (!isset($match[1]))
3254 3433
 	{
3255 3434
 		$size = @getimagesize($url);
3256
-	}
3257
-	else
3435
+	} else
3258 3436
 	{
3259 3437
 		// Try to connect to the server... give it half a second.
3260 3438
 		$temp = 0;
@@ -3291,12 +3469,14 @@  discard block
 block discarded – undo
3291 3469
 	}
3292 3470
 
3293 3471
 	// If we didn't get it, we failed.
3294
-	if (!isset($size))
3295
-		$size = false;
3472
+	if (!isset($size)) {
3473
+			$size = false;
3474
+	}
3296 3475
 
3297 3476
 	// If this took a long time, we may never have to do it again, but then again we might...
3298
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3299
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3477
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3478
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3479
+	}
3300 3480
 
3301 3481
 	// Didn't work.
3302 3482
 	return $size;
@@ -3314,8 +3494,9 @@  discard block
 block discarded – undo
3314 3494
 
3315 3495
 	// Under SSI this function can be called more then once.  That can cause some problems.
3316 3496
 	//   So only run the function once unless we are forced to run it again.
3317
-	if ($loaded && !$forceload)
3318
-		return;
3497
+	if ($loaded && !$forceload) {
3498
+			return;
3499
+	}
3319 3500
 
3320 3501
 	$loaded = true;
3321 3502
 
@@ -3327,14 +3508,16 @@  discard block
 block discarded – undo
3327 3508
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3328 3509
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3329 3510
 	{
3330
-		if (trim($context['news_lines'][$i]) == '')
3331
-			continue;
3511
+		if (trim($context['news_lines'][$i]) == '') {
3512
+					continue;
3513
+		}
3332 3514
 
3333 3515
 		// Clean it up for presentation ;).
3334 3516
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3335 3517
 	}
3336
-	if (!empty($context['news_lines']))
3337
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3518
+	if (!empty($context['news_lines'])) {
3519
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3520
+	}
3338 3521
 
3339 3522
 	if (!$user_info['is_guest'])
3340 3523
 	{
@@ -3343,40 +3526,48 @@  discard block
 block discarded – undo
3343 3526
 		$context['user']['alerts'] = &$user_info['alerts'];
3344 3527
 
3345 3528
 		// Personal message popup...
3346
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3347
-			$context['user']['popup_messages'] = true;
3348
-		else
3349
-			$context['user']['popup_messages'] = false;
3529
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3530
+					$context['user']['popup_messages'] = true;
3531
+		} else {
3532
+					$context['user']['popup_messages'] = false;
3533
+		}
3350 3534
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3351 3535
 
3352
-		if (allowedTo('moderate_forum'))
3353
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3536
+		if (allowedTo('moderate_forum')) {
3537
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3538
+		}
3354 3539
 
3355 3540
 		$context['user']['avatar'] = array();
3356 3541
 
3357 3542
 		// Check for gravatar first since we might be forcing them...
3358 3543
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3359 3544
 		{
3360
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3361
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3362
-			else
3363
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3545
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3546
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3547
+			} else {
3548
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3549
+			}
3364 3550
 		}
3365 3551
 		// Uploaded?
3366
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3367
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3552
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3553
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3554
+		}
3368 3555
 		// Full URL?
3369
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3370
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3556
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3557
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3558
+		}
3371 3559
 		// Otherwise we assume it's server stored.
3372
-		elseif ($user_info['avatar']['url'] != '')
3373
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3560
+		elseif ($user_info['avatar']['url'] != '') {
3561
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3562
+		}
3374 3563
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3375
-		else
3376
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3564
+		else {
3565
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3566
+		}
3377 3567
 
3378
-		if (!empty($context['user']['avatar']))
3379
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3568
+		if (!empty($context['user']['avatar'])) {
3569
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3570
+		}
3380 3571
 
3381 3572
 		// Figure out how long they've been logged in.
3382 3573
 		$context['user']['total_time_logged_in'] = array(
@@ -3384,8 +3575,7 @@  discard block
 block discarded – undo
3384 3575
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3385 3576
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3386 3577
 		);
3387
-	}
3388
-	else
3578
+	} else
3389 3579
 	{
3390 3580
 		$context['user']['messages'] = 0;
3391 3581
 		$context['user']['unread_messages'] = 0;
@@ -3393,12 +3583,14 @@  discard block
 block discarded – undo
3393 3583
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3394 3584
 		$context['user']['popup_messages'] = false;
3395 3585
 
3396
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3397
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3586
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3587
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3588
+		}
3398 3589
 
3399 3590
 		// If we've upgraded recently, go easy on the passwords.
3400
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3401
-			$context['disable_login_hashing'] = true;
3591
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3592
+					$context['disable_login_hashing'] = true;
3593
+		}
3402 3594
 	}
3403 3595
 
3404 3596
 	// Setup the main menu items.
@@ -3411,8 +3603,8 @@  discard block
 block discarded – undo
3411 3603
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3412 3604
 
3413 3605
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3414
-	if ($context['show_pm_popup'])
3415
-		addInlineJavaScript('
3606
+	if ($context['show_pm_popup']) {
3607
+			addInlineJavaScript('
3416 3608
 		jQuery(document).ready(function($) {
3417 3609
 			new smc_Popup({
3418 3610
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3420,24 +3612,28 @@  discard block
 block discarded – undo
3420 3612
 				icon_class: \'generic_icons mail_new\'
3421 3613
 			});
3422 3614
 		});');
3615
+	}
3423 3616
 
3424 3617
 	// Add a generic "Are you sure?" confirmation message.
3425 3618
 	addInlineJavaScript('
3426 3619
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3427 3620
 
3428 3621
 	// Now add the capping code for avatars.
3429
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3430
-		addInlineCss('
3622
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3623
+			addInlineCss('
3431 3624
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3625
+	}
3432 3626
 
3433 3627
 	// Add max image limits
3434
-	if (!empty($modSettings['max_image_width']))
3435
-		addInlineCss('
3628
+	if (!empty($modSettings['max_image_width'])) {
3629
+			addInlineCss('
3436 3630
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3631
+	}
3437 3632
 
3438
-	if (!empty($modSettings['max_image_height']))
3439
-		addInlineCss('
3633
+	if (!empty($modSettings['max_image_height'])) {
3634
+			addInlineCss('
3440 3635
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3636
+	}
3441 3637
 
3442 3638
 	// This looks weird, but it's because BoardIndex.php references the variable.
3443 3639
 	$context['common_stats']['latest_member'] = array(
@@ -3454,11 +3650,13 @@  discard block
 block discarded – undo
3454 3650
 	);
3455 3651
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3456 3652
 
3457
-	if (empty($settings['theme_version']))
3458
-		addJavaScriptVar('smf_scripturl', $scripturl);
3653
+	if (empty($settings['theme_version'])) {
3654
+			addJavaScriptVar('smf_scripturl', $scripturl);
3655
+	}
3459 3656
 
3460
-	if (!isset($context['page_title']))
3461
-		$context['page_title'] = '';
3657
+	if (!isset($context['page_title'])) {
3658
+			$context['page_title'] = '';
3659
+	}
3462 3660
 
3463 3661
 	// Set some specific vars.
3464 3662
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3468,21 +3666,23 @@  discard block
 block discarded – undo
3468 3666
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3469 3667
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3470 3668
 
3471
-	if (!empty($context['meta_keywords']))
3472
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3669
+	if (!empty($context['meta_keywords'])) {
3670
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3671
+	}
3473 3672
 
3474
-	if (!empty($context['canonical_url']))
3475
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3673
+	if (!empty($context['canonical_url'])) {
3674
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3675
+	}
3476 3676
 
3477
-	if (!empty($settings['og_image']))
3478
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3677
+	if (!empty($settings['og_image'])) {
3678
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3679
+	}
3479 3680
 
3480 3681
 	if (!empty($context['meta_description']))
3481 3682
 	{
3482 3683
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3483 3684
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3484
-	}
3485
-	else
3685
+	} else
3486 3686
 	{
3487 3687
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3488 3688
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3507,8 +3707,9 @@  discard block
 block discarded – undo
3507 3707
 	$memory_needed = memoryReturnBytes($needed);
3508 3708
 
3509 3709
 	// should we account for how much is currently being used?
3510
-	if ($in_use)
3511
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3710
+	if ($in_use) {
3711
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3712
+	}
3512 3713
 
3513 3714
 	// if more is needed, request it
3514 3715
 	if ($memory_current < $memory_needed)
@@ -3531,8 +3732,9 @@  discard block
 block discarded – undo
3531 3732
  */
3532 3733
 function memoryReturnBytes($val)
3533 3734
 {
3534
-	if (is_integer($val))
3535
-		return $val;
3735
+	if (is_integer($val)) {
3736
+			return $val;
3737
+	}
3536 3738
 
3537 3739
 	// Separate the number from the designator
3538 3740
 	$val = trim($val);
@@ -3568,10 +3770,11 @@  discard block
 block discarded – undo
3568 3770
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3569 3771
 
3570 3772
 		// Are we debugging the template/html content?
3571
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3572
-			header('content-type: application/xhtml+xml');
3573
-		elseif (!isset($_REQUEST['xml']))
3574
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3773
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3774
+					header('content-type: application/xhtml+xml');
3775
+		} elseif (!isset($_REQUEST['xml'])) {
3776
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3777
+		}
3575 3778
 	}
3576 3779
 
3577 3780
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3580,8 +3783,9 @@  discard block
 block discarded – undo
3580 3783
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3581 3784
 	{
3582 3785
 		$position = array_search('body', $context['template_layers']);
3583
-		if ($position === false)
3584
-			$position = array_search('main', $context['template_layers']);
3786
+		if ($position === false) {
3787
+					$position = array_search('main', $context['template_layers']);
3788
+		}
3585 3789
 
3586 3790
 		if ($position !== false)
3587 3791
 		{
@@ -3609,23 +3813,25 @@  discard block
 block discarded – undo
3609 3813
 
3610 3814
 			foreach ($securityFiles as $i => $securityFile)
3611 3815
 			{
3612
-				if (!file_exists($boarddir . '/' . $securityFile))
3613
-					unset($securityFiles[$i]);
3816
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3817
+									unset($securityFiles[$i]);
3818
+				}
3614 3819
 			}
3615 3820
 
3616 3821
 			// We are already checking so many files...just few more doesn't make any difference! :P
3617
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3618
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3619
-
3620
-			else
3621
-				$path = $modSettings['attachmentUploadDir'];
3822
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3823
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3824
+			} else {
3825
+							$path = $modSettings['attachmentUploadDir'];
3826
+			}
3622 3827
 
3623 3828
 			secureDirectory($path, true);
3624 3829
 			secureDirectory($cachedir);
3625 3830
 
3626 3831
 			// If agreement is enabled, at least the english version shall exists
3627
-			if ($modSettings['requireAgreement'])
3628
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3832
+			if ($modSettings['requireAgreement']) {
3833
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3834
+			}
3629 3835
 
3630 3836
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3631 3837
 			{
@@ -3640,18 +3846,21 @@  discard block
 block discarded – undo
3640 3846
 					echo '
3641 3847
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3642 3848
 
3643
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3644
-						echo '
3849
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3850
+											echo '
3645 3851
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3852
+					}
3646 3853
 				}
3647 3854
 
3648
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3649
-					echo '
3855
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3856
+									echo '
3650 3857
 				<strong>', $txt['cache_writable'], '</strong><br>';
3858
+				}
3651 3859
 
3652
-				if (!empty($agreement))
3653
-					echo '
3860
+				if (!empty($agreement)) {
3861
+									echo '
3654 3862
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3863
+				}
3655 3864
 
3656 3865
 				echo '
3657 3866
 			</p>
@@ -3666,16 +3875,18 @@  discard block
 block discarded – undo
3666 3875
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3667 3876
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3668 3877
 
3669
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3670
-				echo '
3878
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3879
+							echo '
3671 3880
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3881
+			}
3672 3882
 
3673
-			if (!empty($_SESSION['ban']['expire_time']))
3674
-				echo '
3883
+			if (!empty($_SESSION['ban']['expire_time'])) {
3884
+							echo '
3675 3885
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3676
-			else
3677
-				echo '
3886
+			} else {
3887
+							echo '
3678 3888
 					<div>', $txt['your_ban_expires_never'], '</div>';
3889
+			}
3679 3890
 
3680 3891
 			echo '
3681 3892
 				</div>';
@@ -3691,8 +3902,9 @@  discard block
 block discarded – undo
3691 3902
 	global $forum_copyright, $software_year, $forum_version;
3692 3903
 
3693 3904
 	// Don't display copyright for things like SSI.
3694
-	if (!isset($forum_version) || !isset($software_year))
3695
-		return;
3905
+	if (!isset($forum_version) || !isset($software_year)) {
3906
+			return;
3907
+	}
3696 3908
 
3697 3909
 	// Put in the version...
3698 3910
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3710,9 +3922,10 @@  discard block
 block discarded – undo
3710 3922
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3711 3923
 	$context['load_queries'] = $db_count;
3712 3924
 
3713
-	foreach (array_reverse($context['template_layers']) as $layer)
3714
-		loadSubTemplate($layer . '_below', true);
3715
-}
3925
+	foreach (array_reverse($context['template_layers']) as $layer) {
3926
+			loadSubTemplate($layer . '_below', true);
3927
+	}
3928
+	}
3716 3929
 
3717 3930
 /**
3718 3931
  * Output the Javascript files
@@ -3746,8 +3959,7 @@  discard block
 block discarded – undo
3746 3959
 			{
3747 3960
 				echo '
3748 3961
 		var ', $key, ';';
3749
-			}
3750
-			else
3962
+			} else
3751 3963
 			{
3752 3964
 				echo '
3753 3965
 		var ', $key, ' = ', $value, ';';
@@ -3766,27 +3978,29 @@  discard block
 block discarded – undo
3766 3978
 		foreach ($context['javascript_files'] as $id => $js_file)
3767 3979
 		{
3768 3980
 			// Last minute call! allow theme authors to disable single files.
3769
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3770
-				continue;
3981
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3982
+							continue;
3983
+			}
3771 3984
 
3772 3985
 			// By default files don't get minimized unless the file explicitly says so!
3773 3986
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3774 3987
 			{
3775
-				if (!empty($js_file['options']['async']))
3776
-					$toMinify['async'][] = $js_file;
3777
-				elseif (!empty($js_file['options']['defer']))
3778
-					$toMinify['defer'][] = $js_file;
3779
-				else
3780
-					$toMinify['standard'][] = $js_file;
3988
+				if (!empty($js_file['options']['async'])) {
3989
+									$toMinify['async'][] = $js_file;
3990
+				} elseif (!empty($js_file['options']['defer'])) {
3991
+									$toMinify['defer'][] = $js_file;
3992
+				} else {
3993
+									$toMinify['standard'][] = $js_file;
3994
+				}
3781 3995
 
3782 3996
 				// Grab a random seed.
3783
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3784
-					$minSeed = $js_file['options']['seed'];
3785
-			}
3786
-
3787
-			else
3788
-				echo '
3997
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3998
+									$minSeed = $js_file['options']['seed'];
3999
+				}
4000
+			} else {
4001
+							echo '
3789 4002
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
4003
+			}
3790 4004
 		}
3791 4005
 
3792 4006
 		foreach ($toMinify as $js_files)
@@ -3797,9 +4011,10 @@  discard block
 block discarded – undo
3797 4011
 
3798 4012
 				$minSuccessful = array_keys($result) === array('smf_minified');
3799 4013
 
3800
-				foreach ($result as $minFile)
3801
-					echo '
4014
+				foreach ($result as $minFile) {
4015
+									echo '
3802 4016
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
4017
+				}
3803 4018
 			}
3804 4019
 		}
3805 4020
 	}
@@ -3813,8 +4028,9 @@  discard block
 block discarded – undo
3813 4028
 <script>
3814 4029
 window.addEventListener("DOMContentLoaded", function() {';
3815 4030
 
3816
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3817
-				echo $js_code;
4031
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
4032
+							echo $js_code;
4033
+			}
3818 4034
 
3819 4035
 			echo '
3820 4036
 });
@@ -3826,8 +4042,9 @@  discard block
 block discarded – undo
3826 4042
 			echo '
3827 4043
 	<script>';
3828 4044
 
3829
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3830
-				echo $js_code;
4045
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
4046
+							echo $js_code;
4047
+			}
3831 4048
 
3832 4049
 			echo '
3833 4050
 	</script>';
@@ -3855,23 +4072,26 @@  discard block
 block discarded – undo
3855 4072
 	foreach ($context['css_files'] as $id => $file)
3856 4073
 	{
3857 4074
 		// Last minute call! allow theme authors to disable single files.
3858
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3859
-			continue;
4075
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
4076
+					continue;
4077
+		}
3860 4078
 
3861 4079
 		// Files are minimized unless they explicitly opt out.
3862
-		if (!isset($file['options']['minimize']))
3863
-			$file['options']['minimize'] = true;
4080
+		if (!isset($file['options']['minimize'])) {
4081
+					$file['options']['minimize'] = true;
4082
+		}
3864 4083
 
3865 4084
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3866 4085
 		{
3867 4086
 			$toMinify[] = $file;
3868 4087
 
3869 4088
 			// Grab a random seed.
3870
-			if (!isset($minSeed) && isset($file['options']['seed']))
3871
-				$minSeed = $file['options']['seed'];
4089
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
4090
+							$minSeed = $file['options']['seed'];
4091
+			}
4092
+		} else {
4093
+					$normal[] = $file['fileUrl'];
3872 4094
 		}
3873
-		else
3874
-			$normal[] = $file['fileUrl'];
3875 4095
 	}
3876 4096
 
3877 4097
 	if (!empty($toMinify))
@@ -3880,23 +4100,26 @@  discard block
 block discarded – undo
3880 4100
 
3881 4101
 		$minSuccessful = array_keys($result) === array('smf_minified');
3882 4102
 
3883
-		foreach ($result as $minFile)
3884
-			echo '
4103
+		foreach ($result as $minFile) {
4104
+					echo '
3885 4105
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
4106
+		}
3886 4107
 	}
3887 4108
 
3888 4109
 	// Print the rest after the minified files.
3889
-	if (!empty($normal))
3890
-		foreach ($normal as $nf)
4110
+	if (!empty($normal)) {
4111
+			foreach ($normal as $nf)
3891 4112
 			echo '
3892 4113
 	<link rel="stylesheet" href="', $nf ,'">';
4114
+	}
3893 4115
 
3894 4116
 	if ($db_show_debug === true)
3895 4117
 	{
3896 4118
 		// Try to keep only what's useful.
3897 4119
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3898
-		foreach ($context['css_files'] as $file)
3899
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4120
+		foreach ($context['css_files'] as $file) {
4121
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4122
+		}
3900 4123
 	}
3901 4124
 
3902 4125
 	if (!empty($context['css_header']))
@@ -3904,9 +4127,10 @@  discard block
 block discarded – undo
3904 4127
 		echo '
3905 4128
 	<style>';
3906 4129
 
3907
-		foreach ($context['css_header'] as $css)
3908
-			echo $css .'
4130
+		foreach ($context['css_header'] as $css) {
4131
+					echo $css .'
3909 4132
 	';
4133
+		}
3910 4134
 
3911 4135
 		echo'
3912 4136
 	</style>';
@@ -3929,8 +4153,9 @@  discard block
 block discarded – undo
3929 4153
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3930 4154
 	$data = is_array($data) ? $data : array();
3931 4155
 
3932
-	if (empty($type) || empty($data))
3933
-		return $data;
4156
+	if (empty($type) || empty($data)) {
4157
+			return $data;
4158
+	}
3934 4159
 
3935 4160
 	// Different pages include different files, so we use a hash to label the different combinations
3936 4161
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3939,13 +4164,14 @@  discard block
 block discarded – undo
3939 4164
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3940 4165
 
3941 4166
 	// Already done?
3942
-	if (!empty($toCache))
3943
-		return array('smf_minified' => array(
4167
+	if (!empty($toCache)) {
4168
+			return array('smf_minified' => array(
3944 4169
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3945 4170
 			'filePath' => $toCache,
3946 4171
 			'fileName' => basename($toCache),
3947 4172
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3948 4173
 		));
4174
+	}
3949 4175
 
3950 4176
 
3951 4177
 	// No namespaces, sorry!
@@ -3975,9 +4201,9 @@  discard block
 block discarded – undo
3975 4201
 
3976 4202
 	foreach ($data as $id => $file)
3977 4203
 	{
3978
-		if (empty($file['filePath']))
3979
-			$toAdd = false;
3980
-		else
4204
+		if (empty($file['filePath'])) {
4205
+					$toAdd = false;
4206
+		} else
3981 4207
 		{
3982 4208
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3983 4209
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3985,12 +4211,14 @@  discard block
 block discarded – undo
3985 4211
 		}
3986 4212
 
3987 4213
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3988
-		if (empty($file['options']['async']))
3989
-			$async = false;
4214
+		if (empty($file['options']['async'])) {
4215
+					$async = false;
4216
+		}
3990 4217
 
3991 4218
 		// A minified script should only be deferred if all its components wanted to be.
3992
-		if (empty($file['options']['defer']))
3993
-			$defer = false;
4219
+		if (empty($file['options']['defer'])) {
4220
+					$defer = false;
4221
+		}
3994 4222
 
3995 4223
 		// The file couldn't be located so it won't be added. Log this error.
3996 4224
 		if (empty($toAdd))
@@ -4056,12 +4284,14 @@  discard block
 block discarded – undo
4056 4284
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
4057 4285
 			{
4058 4286
 				// Remove the cache entry
4059
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
4060
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4287
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4288
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4289
+				}
4061 4290
 
4062 4291
 				// Try to delete the file. Add it to our error list if it fails.
4063
-				if (!@unlink($filename))
4064
-					$not_deleted[] = $filename;
4292
+				if (!@unlink($filename)) {
4293
+									$not_deleted[] = $filename;
4294
+				}
4065 4295
 			}
4066 4296
 		}
4067 4297
 	}
@@ -4093,8 +4323,9 @@  discard block
 block discarded – undo
4093 4323
 	global $modSettings, $smcFunc;
4094 4324
 
4095 4325
 	// Just make up a nice hash...
4096
-	if ($new)
4097
-		return sha1(md5($filename . time()) . mt_rand());
4326
+	if ($new) {
4327
+			return sha1(md5($filename . time()) . mt_rand());
4328
+	}
4098 4329
 
4099 4330
 	// Just make sure that attachment id is only a int
4100 4331
 	$attachment_id = (int) $attachment_id;
@@ -4111,23 +4342,25 @@  discard block
 block discarded – undo
4111 4342
 				'id_attach' => $attachment_id,
4112 4343
 			));
4113 4344
 
4114
-		if ($smcFunc['db_num_rows']($request) === 0)
4115
-			return false;
4345
+		if ($smcFunc['db_num_rows']($request) === 0) {
4346
+					return false;
4347
+		}
4116 4348
 
4117 4349
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
4118 4350
 		$smcFunc['db_free_result']($request);
4119 4351
 	}
4120 4352
 
4121 4353
 	// Still no hash? mmm...
4122
-	if (empty($file_hash))
4123
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4354
+	if (empty($file_hash)) {
4355
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4356
+	}
4124 4357
 
4125 4358
 	// Are we using multiple directories?
4126
-	if (is_array($modSettings['attachmentUploadDir']))
4127
-		$path = $modSettings['attachmentUploadDir'][$dir];
4128
-
4129
-	else
4130
-		$path = $modSettings['attachmentUploadDir'];
4359
+	if (is_array($modSettings['attachmentUploadDir'])) {
4360
+			$path = $modSettings['attachmentUploadDir'][$dir];
4361
+	} else {
4362
+			$path = $modSettings['attachmentUploadDir'];
4363
+	}
4131 4364
 
4132 4365
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4133 4366
 }
@@ -4142,8 +4375,9 @@  discard block
 block discarded – undo
4142 4375
 function ip2range($fullip)
4143 4376
 {
4144 4377
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
4145
-	if ($fullip == 'unknown')
4146
-		$fullip = '255.255.255.255';
4378
+	if ($fullip == 'unknown') {
4379
+			$fullip = '255.255.255.255';
4380
+	}
4147 4381
 
4148 4382
 	$ip_parts = explode('-', $fullip);
4149 4383
 	$ip_array = array();
@@ -4167,10 +4401,11 @@  discard block
 block discarded – undo
4167 4401
 		$ip_array['low'] = $ip_parts[0];
4168 4402
 		$ip_array['high'] = $ip_parts[1];
4169 4403
 		return $ip_array;
4170
-	}
4171
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4404
+	} elseif (count($ip_parts) == 2) {
4405
+		// if ip 22.22.*-22.22.*
4172 4406
 	{
4173 4407
 		$valid_low = isValidIP($ip_parts[0]);
4408
+	}
4174 4409
 		$valid_high = isValidIP($ip_parts[1]);
4175 4410
 		$count = 0;
4176 4411
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4185,7 +4420,9 @@  discard block
 block discarded – undo
4185 4420
 				$ip_parts[0] .= $mode . $min;
4186 4421
 				$valid_low = isValidIP($ip_parts[0]);
4187 4422
 				$count++;
4188
-				if ($count > 9) break;
4423
+				if ($count > 9) {
4424
+					break;
4425
+				}
4189 4426
 			}
4190 4427
 		}
4191 4428
 
@@ -4199,7 +4436,9 @@  discard block
 block discarded – undo
4199 4436
 				$ip_parts[1] .= $mode . $max;
4200 4437
 				$valid_high = isValidIP($ip_parts[1]);
4201 4438
 				$count++;
4202
-				if ($count > 9) break;
4439
+				if ($count > 9) {
4440
+					break;
4441
+				}
4203 4442
 			}
4204 4443
 		}
4205 4444
 
@@ -4223,46 +4462,54 @@  discard block
 block discarded – undo
4223 4462
 {
4224 4463
 	global $modSettings;
4225 4464
 
4226
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4227
-		return $host;
4465
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4466
+			return $host;
4467
+	}
4228 4468
 	$t = microtime();
4229 4469
 
4230 4470
 	// Try the Linux host command, perhaps?
4231 4471
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4232 4472
 	{
4233
-		if (!isset($modSettings['host_to_dis']))
4234
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4235
-		else
4236
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4473
+		if (!isset($modSettings['host_to_dis'])) {
4474
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4475
+		} else {
4476
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4477
+		}
4237 4478
 
4238 4479
 		// Did host say it didn't find anything?
4239
-		if (strpos($test, 'not found') !== false)
4240
-			$host = '';
4480
+		if (strpos($test, 'not found') !== false) {
4481
+					$host = '';
4482
+		}
4241 4483
 		// Invalid server option?
4242
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4243
-			updateSettings(array('host_to_dis' => 1));
4484
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4485
+					updateSettings(array('host_to_dis' => 1));
4486
+		}
4244 4487
 		// Maybe it found something, after all?
4245
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4246
-			$host = $match[1];
4488
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4489
+					$host = $match[1];
4490
+		}
4247 4491
 	}
4248 4492
 
4249 4493
 	// This is nslookup; usually only Windows, but possibly some Unix?
4250 4494
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4251 4495
 	{
4252 4496
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4253
-		if (strpos($test, 'Non-existent domain') !== false)
4254
-			$host = '';
4255
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4256
-			$host = $match[1];
4497
+		if (strpos($test, 'Non-existent domain') !== false) {
4498
+					$host = '';
4499
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4500
+					$host = $match[1];
4501
+		}
4257 4502
 	}
4258 4503
 
4259 4504
 	// This is the last try :/.
4260
-	if (!isset($host) || $host === false)
4261
-		$host = @gethostbyaddr($ip);
4505
+	if (!isset($host) || $host === false) {
4506
+			$host = @gethostbyaddr($ip);
4507
+	}
4262 4508
 
4263 4509
 	// It took a long time, so let's cache it!
4264
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4265
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4510
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4511
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4512
+	}
4266 4513
 
4267 4514
 	return $host;
4268 4515
 }
@@ -4298,20 +4545,21 @@  discard block
 block discarded – undo
4298 4545
 			{
4299 4546
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4300 4547
 				$total = 0;
4301
-				for ($i = 0; $i < $max_chars; $i++)
4302
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4548
+				for ($i = 0; $i < $max_chars; $i++) {
4549
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4550
+				}
4303 4551
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4304 4552
 			}
4305 4553
 		}
4306 4554
 		return array_unique($returned_ints);
4307
-	}
4308
-	else
4555
+	} else
4309 4556
 	{
4310 4557
 		// Trim characters before and after and add slashes for database insertion.
4311 4558
 		$returned_words = array();
4312
-		foreach ($words as $word)
4313
-			if (($word = trim($word, '-_\'')) !== '')
4559
+		foreach ($words as $word) {
4560
+					if (($word = trim($word, '-_\'')) !== '')
4314 4561
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4562
+		}
4315 4563
 
4316 4564
 		// Filter out all words that occur more than once.
4317 4565
 		return array_unique($returned_words);
@@ -4333,16 +4581,18 @@  discard block
 block discarded – undo
4333 4581
 	global $settings, $txt;
4334 4582
 
4335 4583
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4336
-	if (function_exists('template_create_button') && !$force_use)
4337
-		return template_create_button($name, $alt, $label = '', $custom = '');
4584
+	if (function_exists('template_create_button') && !$force_use) {
4585
+			return template_create_button($name, $alt, $label = '', $custom = '');
4586
+	}
4338 4587
 
4339
-	if (!$settings['use_image_buttons'])
4340
-		return $txt[$alt];
4341
-	elseif (!empty($settings['use_buttons']))
4342
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4343
-	else
4344
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4345
-}
4588
+	if (!$settings['use_image_buttons']) {
4589
+			return $txt[$alt];
4590
+	} elseif (!empty($settings['use_buttons'])) {
4591
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4592
+	} else {
4593
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4594
+	}
4595
+	}
4346 4596
 
4347 4597
 /**
4348 4598
  * Sets up all of the top menu buttons
@@ -4385,9 +4635,10 @@  discard block
 block discarded – undo
4385 4635
 	var user_menus = new smc_PopupMenu();
4386 4636
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4387 4637
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4388
-		if ($context['allow_pm'])
4389
-			addInlineJavaScript('
4638
+		if ($context['allow_pm']) {
4639
+					addInlineJavaScript('
4390 4640
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4641
+		}
4391 4642
 
4392 4643
 		if (!empty($modSettings['enable_ajax_alerts']))
4393 4644
 		{
@@ -4547,88 +4798,96 @@  discard block
 block discarded – undo
4547 4798
 
4548 4799
 		// Now we put the buttons in the context so the theme can use them.
4549 4800
 		$menu_buttons = array();
4550
-		foreach ($buttons as $act => $button)
4551
-			if (!empty($button['show']))
4801
+		foreach ($buttons as $act => $button) {
4802
+					if (!empty($button['show']))
4552 4803
 			{
4553 4804
 				$button['active_button'] = false;
4805
+		}
4554 4806
 
4555 4807
 				// This button needs some action.
4556
-				if (isset($button['action_hook']))
4557
-					$needs_action_hook = true;
4808
+				if (isset($button['action_hook'])) {
4809
+									$needs_action_hook = true;
4810
+				}
4558 4811
 
4559 4812
 				// Make sure the last button truly is the last button.
4560 4813
 				if (!empty($button['is_last']))
4561 4814
 				{
4562
-					if (isset($last_button))
4563
-						unset($menu_buttons[$last_button]['is_last']);
4815
+					if (isset($last_button)) {
4816
+											unset($menu_buttons[$last_button]['is_last']);
4817
+					}
4564 4818
 					$last_button = $act;
4565 4819
 				}
4566 4820
 
4567 4821
 				// Go through the sub buttons if there are any.
4568
-				if (!empty($button['sub_buttons']))
4569
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4822
+				if (!empty($button['sub_buttons'])) {
4823
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4570 4824
 					{
4571 4825
 						if (empty($subbutton['show']))
4572 4826
 							unset($button['sub_buttons'][$key]);
4827
+				}
4573 4828
 
4574 4829
 						// 2nd level sub buttons next...
4575 4830
 						if (!empty($subbutton['sub_buttons']))
4576 4831
 						{
4577 4832
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4578 4833
 							{
4579
-								if (empty($sub_button2['show']))
4580
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4834
+								if (empty($sub_button2['show'])) {
4835
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4836
+								}
4581 4837
 							}
4582 4838
 						}
4583 4839
 					}
4584 4840
 
4585 4841
 				// Does this button have its own icon?
4586
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4587
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4588
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4589
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4590
-				elseif (isset($button['icon']))
4591
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4592
-				else
4593
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4842
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4843
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4844
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4845
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4846
+				} elseif (isset($button['icon'])) {
4847
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4848
+				} else {
4849
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4850
+				}
4594 4851
 
4595 4852
 				$menu_buttons[$act] = $button;
4596 4853
 			}
4597 4854
 
4598
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4599
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4855
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4856
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4857
+		}
4600 4858
 	}
4601 4859
 
4602 4860
 	$context['menu_buttons'] = $menu_buttons;
4603 4861
 
4604 4862
 	// Logging out requires the session id in the url.
4605
-	if (isset($context['menu_buttons']['logout']))
4606
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4863
+	if (isset($context['menu_buttons']['logout'])) {
4864
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4865
+	}
4607 4866
 
4608 4867
 	// Figure out which action we are doing so we can set the active tab.
4609 4868
 	// Default to home.
4610 4869
 	$current_action = 'home';
4611 4870
 
4612
-	if (isset($context['menu_buttons'][$context['current_action']]))
4613
-		$current_action = $context['current_action'];
4614
-	elseif ($context['current_action'] == 'search2')
4615
-		$current_action = 'search';
4616
-	elseif ($context['current_action'] == 'theme')
4617
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4618
-	elseif ($context['current_action'] == 'register2')
4619
-		$current_action = 'register';
4620
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4621
-		$current_action = 'login';
4622
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4623
-		$current_action = 'moderate';
4871
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4872
+			$current_action = $context['current_action'];
4873
+	} elseif ($context['current_action'] == 'search2') {
4874
+			$current_action = 'search';
4875
+	} elseif ($context['current_action'] == 'theme') {
4876
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4877
+	} elseif ($context['current_action'] == 'register2') {
4878
+			$current_action = 'register';
4879
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4880
+			$current_action = 'login';
4881
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4882
+			$current_action = 'moderate';
4883
+	}
4624 4884
 
4625 4885
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4626 4886
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4627 4887
 	{
4628 4888
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4629 4889
 		$context[$current_action] = true;
4630
-	}
4631
-	elseif ($context['current_action'] == 'pm')
4890
+	} elseif ($context['current_action'] == 'pm')
4632 4891
 	{
4633 4892
 		$current_action = 'self_pm';
4634 4893
 		$context['self_pm'] = true;
@@ -4685,12 +4944,14 @@  discard block
 block discarded – undo
4685 4944
 	}
4686 4945
 
4687 4946
 	// Not all actions are simple.
4688
-	if (!empty($needs_action_hook))
4689
-		call_integration_hook('integrate_current_action', array(&$current_action));
4947
+	if (!empty($needs_action_hook)) {
4948
+			call_integration_hook('integrate_current_action', array(&$current_action));
4949
+	}
4690 4950
 
4691
-	if (isset($context['menu_buttons'][$current_action]))
4692
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4693
-}
4951
+	if (isset($context['menu_buttons'][$current_action])) {
4952
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4953
+	}
4954
+	}
4694 4955
 
4695 4956
 /**
4696 4957
  * Generate a random seed and ensure it's stored in settings.
@@ -4714,30 +4975,35 @@  discard block
 block discarded – undo
4714 4975
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4715 4976
 	global $context, $txt;
4716 4977
 
4717
-	if ($db_show_debug === true)
4718
-		$context['debug']['hooks'][] = $hook;
4978
+	if ($db_show_debug === true) {
4979
+			$context['debug']['hooks'][] = $hook;
4980
+	}
4719 4981
 
4720 4982
 	// Need to have some control.
4721
-	if (!isset($context['instances']))
4722
-		$context['instances'] = array();
4983
+	if (!isset($context['instances'])) {
4984
+			$context['instances'] = array();
4985
+	}
4723 4986
 
4724 4987
 	$results = array();
4725
-	if (empty($modSettings[$hook]))
4726
-		return $results;
4988
+	if (empty($modSettings[$hook])) {
4989
+			return $results;
4990
+	}
4727 4991
 
4728 4992
 	$functions = explode(',', $modSettings[$hook]);
4729 4993
 	// Loop through each function.
4730 4994
 	foreach ($functions as $function)
4731 4995
 	{
4732 4996
 		// Hook has been marked as "disabled". Skip it!
4733
-		if (strpos($function, '!') !== false)
4734
-			continue;
4997
+		if (strpos($function, '!') !== false) {
4998
+					continue;
4999
+		}
4735 5000
 
4736 5001
 		$call = call_helper($function, true);
4737 5002
 
4738 5003
 		// Is it valid?
4739
-		if (!empty($call))
4740
-			$results[$function] = call_user_func_array($call, $parameters);
5004
+		if (!empty($call)) {
5005
+					$results[$function] = call_user_func_array($call, $parameters);
5006
+		}
4741 5007
 
4742 5008
 		// Whatever it was suppose to call, it failed :(
4743 5009
 		elseif (!empty($function))
@@ -4753,8 +5019,9 @@  discard block
 block discarded – undo
4753 5019
 			}
4754 5020
 
4755 5021
 			// "Assume" the file resides on $boarddir somewhere...
4756
-			else
4757
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5022
+			else {
5023
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5024
+			}
4758 5025
 		}
4759 5026
 	}
4760 5027
 
@@ -4776,12 +5043,14 @@  discard block
 block discarded – undo
4776 5043
 	global $smcFunc, $modSettings;
4777 5044
 
4778 5045
 	// Any objects?
4779
-	if ($object)
4780
-		$function = $function . '#';
5046
+	if ($object) {
5047
+			$function = $function . '#';
5048
+	}
4781 5049
 
4782 5050
 	// Any files  to load?
4783
-	if (!empty($file) && is_string($file))
4784
-		$function = $file . (!empty($function) ? '|' . $function : '');
5051
+	if (!empty($file) && is_string($file)) {
5052
+			$function = $file . (!empty($function) ? '|' . $function : '');
5053
+	}
4785 5054
 
4786 5055
 	// Get the correct string.
4787 5056
 	$integration_call = $function;
@@ -4803,13 +5072,14 @@  discard block
 block discarded – undo
4803 5072
 		if (!empty($current_functions))
4804 5073
 		{
4805 5074
 			$current_functions = explode(',', $current_functions);
4806
-			if (in_array($integration_call, $current_functions))
4807
-				return;
5075
+			if (in_array($integration_call, $current_functions)) {
5076
+							return;
5077
+			}
4808 5078
 
4809 5079
 			$permanent_functions = array_merge($current_functions, array($integration_call));
5080
+		} else {
5081
+					$permanent_functions = array($integration_call);
4810 5082
 		}
4811
-		else
4812
-			$permanent_functions = array($integration_call);
4813 5083
 
4814 5084
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4815 5085
 	}
@@ -4818,8 +5088,9 @@  discard block
 block discarded – undo
4818 5088
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4819 5089
 
4820 5090
 	// Do nothing, if it's already there.
4821
-	if (in_array($integration_call, $functions))
4822
-		return;
5091
+	if (in_array($integration_call, $functions)) {
5092
+			return;
5093
+	}
4823 5094
 
4824 5095
 	$functions[] = $integration_call;
4825 5096
 	$modSettings[$hook] = implode(',', $functions);
@@ -4842,12 +5113,14 @@  discard block
 block discarded – undo
4842 5113
 	global $smcFunc, $modSettings;
4843 5114
 
4844 5115
 	// Any objects?
4845
-	if ($object)
4846
-		$function = $function . '#';
5116
+	if ($object) {
5117
+			$function = $function . '#';
5118
+	}
4847 5119
 
4848 5120
 	// Any files  to load?
4849
-	if (!empty($file) && is_string($file))
4850
-		$function = $file . '|' . $function;
5121
+	if (!empty($file) && is_string($file)) {
5122
+			$function = $file . '|' . $function;
5123
+	}
4851 5124
 
4852 5125
 	// Get the correct string.
4853 5126
 	$integration_call = $function;
@@ -4868,16 +5141,18 @@  discard block
 block discarded – undo
4868 5141
 	{
4869 5142
 		$current_functions = explode(',', $current_functions);
4870 5143
 
4871
-		if (in_array($integration_call, $current_functions))
4872
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5144
+		if (in_array($integration_call, $current_functions)) {
5145
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5146
+		}
4873 5147
 	}
4874 5148
 
4875 5149
 	// Turn the function list into something usable.
4876 5150
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4877 5151
 
4878 5152
 	// You can only remove it if it's available.
4879
-	if (!in_array($integration_call, $functions))
4880
-		return;
5153
+	if (!in_array($integration_call, $functions)) {
5154
+			return;
5155
+	}
4881 5156
 
4882 5157
 	$functions = array_diff($functions, array($integration_call));
4883 5158
 	$modSettings[$hook] = implode(',', $functions);
@@ -4898,17 +5173,20 @@  discard block
 block discarded – undo
4898 5173
 	global $context, $smcFunc, $txt, $db_show_debug;
4899 5174
 
4900 5175
 	// Really?
4901
-	if (empty($string))
4902
-		return false;
5176
+	if (empty($string)) {
5177
+			return false;
5178
+	}
4903 5179
 
4904 5180
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4905 5181
 	// A closure? should be a callable one.
4906
-	if (is_array($string) || $string instanceof Closure)
4907
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5182
+	if (is_array($string) || $string instanceof Closure) {
5183
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5184
+	}
4908 5185
 
4909 5186
 	// No full objects, sorry! pass a method or a property instead!
4910
-	if (is_object($string))
4911
-		return false;
5187
+	if (is_object($string)) {
5188
+			return false;
5189
+	}
4912 5190
 
4913 5191
 	// Stay vitaminized my friends...
4914 5192
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4917,8 +5195,9 @@  discard block
 block discarded – undo
4917 5195
 	$string = load_file($string);
4918 5196
 
4919 5197
 	// Loaded file failed
4920
-	if (empty($string))
4921
-		return false;
5198
+	if (empty($string)) {
5199
+			return false;
5200
+	}
4922 5201
 
4923 5202
 	// Found a method.
4924 5203
 	if (strpos($string, '::') !== false)
@@ -4939,8 +5218,9 @@  discard block
 block discarded – undo
4939 5218
 				// Add another one to the list.
4940 5219
 				if ($db_show_debug === true)
4941 5220
 				{
4942
-					if (!isset($context['debug']['instances']))
4943
-						$context['debug']['instances'] = array();
5221
+					if (!isset($context['debug']['instances'])) {
5222
+											$context['debug']['instances'] = array();
5223
+					}
4944 5224
 
4945 5225
 					$context['debug']['instances'][$class] = $class;
4946 5226
 				}
@@ -4950,13 +5230,15 @@  discard block
 block discarded – undo
4950 5230
 		}
4951 5231
 
4952 5232
 		// Right then. This is a call to a static method.
4953
-		else
4954
-			$func = array($class, $method);
5233
+		else {
5234
+					$func = array($class, $method);
5235
+		}
4955 5236
 	}
4956 5237
 
4957 5238
 	// Nope! just a plain regular function.
4958
-	else
4959
-		$func = $string;
5239
+	else {
5240
+			$func = $string;
5241
+	}
4960 5242
 
4961 5243
 	// Right, we got what we need, time to do some checks.
4962 5244
 	if (!is_callable($func, false, $callable_name))
@@ -4972,17 +5254,18 @@  discard block
 block discarded – undo
4972 5254
 	else
4973 5255
 	{
4974 5256
 		// What are we gonna do about it?
4975
-		if ($return)
4976
-			return $func;
5257
+		if ($return) {
5258
+					return $func;
5259
+		}
4977 5260
 
4978 5261
 		// If this is a plain function, avoid the heat of calling call_user_func().
4979 5262
 		else
4980 5263
 		{
4981
-			if (is_array($func))
4982
-				call_user_func($func);
4983
-
4984
-			else
4985
-				$func();
5264
+			if (is_array($func)) {
5265
+							call_user_func($func);
5266
+			} else {
5267
+							$func();
5268
+			}
4986 5269
 		}
4987 5270
 	}
4988 5271
 }
@@ -4999,31 +5282,34 @@  discard block
 block discarded – undo
4999 5282
 {
5000 5283
 	global $sourcedir, $txt, $boarddir, $settings;
5001 5284
 
5002
-	if (empty($string))
5003
-		return false;
5285
+	if (empty($string)) {
5286
+			return false;
5287
+	}
5004 5288
 
5005 5289
 	if (strpos($string, '|') !== false)
5006 5290
 	{
5007 5291
 		list ($file, $string) = explode('|', $string);
5008 5292
 
5009 5293
 		// Match the wildcards to their regular vars.
5010
-		if (empty($settings['theme_dir']))
5011
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5012
-
5013
-		else
5014
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5294
+		if (empty($settings['theme_dir'])) {
5295
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5296
+		} else {
5297
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5298
+		}
5015 5299
 
5016 5300
 		// Load the file if it can be loaded.
5017
-		if (file_exists($absPath))
5018
-			require_once($absPath);
5301
+		if (file_exists($absPath)) {
5302
+					require_once($absPath);
5303
+		}
5019 5304
 
5020 5305
 		// No? try a fallback to $sourcedir
5021 5306
 		else
5022 5307
 		{
5023 5308
 			$absPath = $sourcedir .'/'. $file;
5024 5309
 
5025
-			if (file_exists($absPath))
5026
-				require_once($absPath);
5310
+			if (file_exists($absPath)) {
5311
+							require_once($absPath);
5312
+			}
5027 5313
 
5028 5314
 			// Sorry, can't do much for you at this point.
5029 5315
 			else
@@ -5062,8 +5348,9 @@  discard block
 block discarded – undo
5062 5348
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
5063 5349
 
5064 5350
 	// No scheme? No data for you!
5065
-	if (empty($match[1]))
5066
-		return false;
5351
+	if (empty($match[1])) {
5352
+			return false;
5353
+	}
5067 5354
 
5068 5355
 	// An FTP url. We should try connecting and RETRieving it...
5069 5356
 	elseif ($match[1] == 'ftp')
@@ -5073,23 +5360,26 @@  discard block
 block discarded – undo
5073 5360
 
5074 5361
 		// Establish a connection and attempt to enable passive mode.
5075 5362
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
5076
-		if ($ftp->error !== false || !$ftp->passive())
5077
-			return false;
5363
+		if ($ftp->error !== false || !$ftp->passive()) {
5364
+					return false;
5365
+		}
5078 5366
 
5079 5367
 		// I want that one *points*!
5080 5368
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
5081 5369
 
5082 5370
 		// Since passive mode worked (or we would have returned already!) open the connection.
5083 5371
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
5084
-		if (!$fp)
5085
-			return false;
5372
+		if (!$fp) {
5373
+					return false;
5374
+		}
5086 5375
 
5087 5376
 		// The server should now say something in acknowledgement.
5088 5377
 		$ftp->check_response(150);
5089 5378
 
5090 5379
 		$data = '';
5091
-		while (!feof($fp))
5092
-			$data .= fread($fp, 4096);
5380
+		while (!feof($fp)) {
5381
+					$data .= fread($fp, 4096);
5382
+		}
5093 5383
 		fclose($fp);
5094 5384
 
5095 5385
 		// All done, right?  Good.
@@ -5101,8 +5391,9 @@  discard block
 block discarded – undo
5101 5391
 	elseif (isset($match[1]) && $match[1] == 'http')
5102 5392
 	{
5103 5393
 		// First try to use fsockopen, because it is fastest.
5104
-		if ($keep_alive && $match[3] == $keep_alive_dom)
5105
-			$fp = $keep_alive_fp;
5394
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5395
+					$fp = $keep_alive_fp;
5396
+		}
5106 5397
 		if (empty($fp))
5107 5398
 		{
5108 5399
 			// Open the socket on the port we want...
@@ -5122,20 +5413,21 @@  discard block
 block discarded – undo
5122 5413
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
5123 5414
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5124 5415
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5125
-				if ($keep_alive)
5126
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5127
-				else
5128
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
5129
-			}
5130
-			else
5416
+				if ($keep_alive) {
5417
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5418
+				} else {
5419
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5420
+				}
5421
+			} else
5131 5422
 			{
5132 5423
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
5133 5424
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5134 5425
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5135
-				if ($keep_alive)
5136
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5137
-				else
5138
-					fwrite($fp, 'connection: close' . "\r\n");
5426
+				if ($keep_alive) {
5427
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5428
+				} else {
5429
+									fwrite($fp, 'connection: close' . "\r\n");
5430
+				}
5139 5431
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
5140 5432
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
5141 5433
 				fwrite($fp, $post_data);
@@ -5148,30 +5440,33 @@  discard block
 block discarded – undo
5148 5440
 			{
5149 5441
 				$header = '';
5150 5442
 				$location = '';
5151
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5152
-					if (strpos($header, 'location:') !== false)
5443
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5444
+									if (strpos($header, 'location:') !== false)
5153 5445
 						$location = trim(substr($header, strpos($header, ':') + 1));
5446
+				}
5154 5447
 
5155
-				if (empty($location))
5156
-					return false;
5157
-				else
5448
+				if (empty($location)) {
5449
+									return false;
5450
+				} else
5158 5451
 				{
5159
-					if (!$keep_alive)
5160
-						fclose($fp);
5452
+					if (!$keep_alive) {
5453
+											fclose($fp);
5454
+					}
5161 5455
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
5162 5456
 				}
5163 5457
 			}
5164 5458
 
5165 5459
 			// Make sure we get a 200 OK.
5166
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5167
-				return false;
5460
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5461
+							return false;
5462
+			}
5168 5463
 
5169 5464
 			// Skip the headers...
5170 5465
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5171 5466
 			{
5172
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5173
-					$content_length = $match[1];
5174
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5467
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5468
+									$content_length = $match[1];
5469
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5175 5470
 				{
5176 5471
 					$keep_alive_dom = null;
5177 5472
 					$keep_alive = false;
@@ -5183,17 +5478,19 @@  discard block
 block discarded – undo
5183 5478
 			$data = '';
5184 5479
 			if (isset($content_length))
5185 5480
 			{
5186
-				while (!feof($fp) && strlen($data) < $content_length)
5187
-					$data .= fread($fp, $content_length - strlen($data));
5188
-			}
5189
-			else
5481
+				while (!feof($fp) && strlen($data) < $content_length) {
5482
+									$data .= fread($fp, $content_length - strlen($data));
5483
+				}
5484
+			} else
5190 5485
 			{
5191
-				while (!feof($fp))
5192
-					$data .= fread($fp, 4096);
5486
+				while (!feof($fp)) {
5487
+									$data .= fread($fp, 4096);
5488
+				}
5193 5489
 			}
5194 5490
 
5195
-			if (!$keep_alive)
5196
-				fclose($fp);
5491
+			if (!$keep_alive) {
5492
+							fclose($fp);
5493
+			}
5197 5494
 		}
5198 5495
 
5199 5496
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5206,17 +5503,18 @@  discard block
 block discarded – undo
5206 5503
 			$fetch_data->get_url_data($url, $post_data);
5207 5504
 
5208 5505
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5209
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5210
-				$data = $fetch_data->result('body');
5211
-			else
5212
-				return false;
5506
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5507
+							$data = $fetch_data->result('body');
5508
+			} else {
5509
+							return false;
5510
+			}
5213 5511
 		}
5214 5512
 
5215 5513
 		// Neither fsockopen nor curl are available. Well, phooey.
5216
-		else
5217
-			return false;
5218
-	}
5219
-	else
5514
+		else {
5515
+					return false;
5516
+		}
5517
+	} else
5220 5518
 	{
5221 5519
 		// Umm, this shouldn't happen?
5222 5520
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5236,8 +5534,9 @@  discard block
 block discarded – undo
5236 5534
 	global $user_info, $smcFunc;
5237 5535
 
5238 5536
 	// Make sure we have something to work with.
5239
-	if (empty($topic))
5240
-		return array();
5537
+	if (empty($topic)) {
5538
+			return array();
5539
+	}
5241 5540
 
5242 5541
 
5243 5542
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5260,8 +5559,9 @@  discard block
 block discarded – undo
5260 5559
 				'topic' => $topic,
5261 5560
 			)
5262 5561
 		);
5263
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5264
-			$temp[] = (int) $row['content_id'];
5562
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5563
+					$temp[] = (int) $row['content_id'];
5564
+		}
5265 5565
 
5266 5566
 		cache_put_data($cache_key, $temp, $ttl);
5267 5567
 	}
@@ -5282,8 +5582,9 @@  discard block
 block discarded – undo
5282 5582
 {
5283 5583
 	global $context;
5284 5584
 
5285
-	if (empty($string))
5286
-		return $string;
5585
+	if (empty($string)) {
5586
+			return $string;
5587
+	}
5287 5588
 
5288 5589
 	// UTF-8 occurences of MS special characters
5289 5590
 	$findchars_utf8 = array(
@@ -5324,10 +5625,11 @@  discard block
 block discarded – undo
5324 5625
 		'--',	// &mdash;
5325 5626
 	);
5326 5627
 
5327
-	if ($context['utf8'])
5328
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5329
-	else
5330
-		$string = str_replace($findchars_iso, $replacechars, $string);
5628
+	if ($context['utf8']) {
5629
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5630
+	} else {
5631
+			$string = str_replace($findchars_iso, $replacechars, $string);
5632
+	}
5331 5633
 
5332 5634
 	return $string;
5333 5635
 }
@@ -5346,49 +5648,59 @@  discard block
 block discarded – undo
5346 5648
 {
5347 5649
 	global $context;
5348 5650
 
5349
-	if (!isset($matches[2]))
5350
-		return '';
5651
+	if (!isset($matches[2])) {
5652
+			return '';
5653
+	}
5351 5654
 
5352 5655
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5353 5656
 
5354 5657
 	// remove left to right / right to left overrides
5355
-	if ($num === 0x202D || $num === 0x202E)
5356
-		return '';
5658
+	if ($num === 0x202D || $num === 0x202E) {
5659
+			return '';
5660
+	}
5357 5661
 
5358 5662
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5359
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5360
-		return '&#' . $num . ';';
5663
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5664
+			return '&#' . $num . ';';
5665
+	}
5361 5666
 
5362 5667
 	if (empty($context['utf8']))
5363 5668
 	{
5364 5669
 		// no control characters
5365
-		if ($num < 0x20)
5366
-			return '';
5670
+		if ($num < 0x20) {
5671
+					return '';
5672
+		}
5367 5673
 		// text is text
5368
-		elseif ($num < 0x80)
5369
-			return chr($num);
5674
+		elseif ($num < 0x80) {
5675
+					return chr($num);
5676
+		}
5370 5677
 		// all others get html-ised
5371
-		else
5372
-			return '&#' . $matches[2] . ';';
5373
-	}
5374
-	else
5678
+		else {
5679
+					return '&#' . $matches[2] . ';';
5680
+		}
5681
+	} else
5375 5682
 	{
5376 5683
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5377 5684
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5378
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5379
-			return '';
5685
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5686
+					return '';
5687
+		}
5380 5688
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5381
-		elseif ($num < 0x80)
5382
-			return chr($num);
5689
+		elseif ($num < 0x80) {
5690
+					return chr($num);
5691
+		}
5383 5692
 		// <0x800 (2048)
5384
-		elseif ($num < 0x800)
5385
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5693
+		elseif ($num < 0x800) {
5694
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5695
+		}
5386 5696
 		// < 0x10000 (65536)
5387
-		elseif ($num < 0x10000)
5388
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5697
+		elseif ($num < 0x10000) {
5698
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5699
+		}
5389 5700
 		// <= 0x10FFFF (1114111)
5390
-		else
5391
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5701
+		else {
5702
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5703
+		}
5392 5704
 	}
5393 5705
 }
5394 5706
 
@@ -5404,28 +5716,34 @@  discard block
 block discarded – undo
5404 5716
  */
5405 5717
 function fixchar__callback($matches)
5406 5718
 {
5407
-	if (!isset($matches[1]))
5408
-		return '';
5719
+	if (!isset($matches[1])) {
5720
+			return '';
5721
+	}
5409 5722
 
5410 5723
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5411 5724
 
5412 5725
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5413 5726
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5414
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5415
-		return '';
5727
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5728
+			return '';
5729
+	}
5416 5730
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5417
-	elseif ($num < 0x80)
5418
-		return chr($num);
5731
+	elseif ($num < 0x80) {
5732
+			return chr($num);
5733
+	}
5419 5734
 	// <0x800 (2048)
5420
-	elseif ($num < 0x800)
5421
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5735
+	elseif ($num < 0x800) {
5736
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5737
+	}
5422 5738
 	// < 0x10000 (65536)
5423
-	elseif ($num < 0x10000)
5424
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5739
+	elseif ($num < 0x10000) {
5740
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5741
+	}
5425 5742
 	// <= 0x10FFFF (1114111)
5426
-	else
5427
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5428
-}
5743
+	else {
5744
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5745
+	}
5746
+	}
5429 5747
 
5430 5748
 /**
5431 5749
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5438,17 +5756,19 @@  discard block
 block discarded – undo
5438 5756
  */
5439 5757
 function entity_fix__callback($matches)
5440 5758
 {
5441
-	if (!isset($matches[2]))
5442
-		return '';
5759
+	if (!isset($matches[2])) {
5760
+			return '';
5761
+	}
5443 5762
 
5444 5763
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5445 5764
 
5446 5765
 	// we don't allow control characters, characters out of range, byte markers, etc
5447
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5448
-		return '';
5449
-	else
5450
-		return '&#' . $num . ';';
5451
-}
5766
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5767
+			return '';
5768
+	} else {
5769
+			return '&#' . $num . ';';
5770
+	}
5771
+	}
5452 5772
 
5453 5773
 /**
5454 5774
  * Return a Gravatar URL based on
@@ -5472,18 +5792,23 @@  discard block
 block discarded – undo
5472 5792
 		$ratings = array('G', 'PG', 'R', 'X');
5473 5793
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5474 5794
 		$url_params = array();
5475
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5476
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5477
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5478
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5479
-		if (!empty($modSettings['avatar_max_width_external']))
5480
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5481
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5482
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5795
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5796
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5797
+		}
5798
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5799
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5800
+		}
5801
+		if (!empty($modSettings['avatar_max_width_external'])) {
5802
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5803
+		}
5804
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5805
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5483 5806
 				$size_string = $modSettings['avatar_max_height_external'];
5807
+		}
5484 5808
 
5485
-		if (!empty($size_string))
5486
-			$url_params[] = 's=' . $size_string;
5809
+		if (!empty($size_string)) {
5810
+					$url_params[] = 's=' . $size_string;
5811
+		}
5487 5812
 	}
5488 5813
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5489 5814
 
@@ -5502,22 +5827,26 @@  discard block
 block discarded – undo
5502 5827
 	static $timezones = null, $lastwhen = null;
5503 5828
 
5504 5829
 	// No point doing this over if we already did it once
5505
-	if (!empty($timezones) && $when == $lastwhen)
5506
-		return $timezones;
5507
-	else
5508
-		$lastwhen = $when;
5830
+	if (!empty($timezones) && $when == $lastwhen) {
5831
+			return $timezones;
5832
+	} else {
5833
+			$lastwhen = $when;
5834
+	}
5509 5835
 
5510 5836
 	// Parseable datetime string?
5511
-	if (is_int($timestamp = strtotime($when)))
5512
-		$when = $timestamp;
5837
+	if (is_int($timestamp = strtotime($when))) {
5838
+			$when = $timestamp;
5839
+	}
5513 5840
 
5514 5841
 	// A Unix timestamp?
5515
-	elseif (is_numeric($when))
5516
-		$when = intval($when);
5842
+	elseif (is_numeric($when)) {
5843
+			$when = intval($when);
5844
+	}
5517 5845
 
5518 5846
 	// Invalid value? Just get current Unix timestamp.
5519
-	else
5520
-		$when = time();
5847
+	else {
5848
+			$when = time();
5849
+	}
5521 5850
 
5522 5851
 	// We'll need these too
5523 5852
 	$date_when = date_create('@' . $when);
@@ -5532,8 +5861,9 @@  discard block
 block discarded – undo
5532 5861
 	foreach ($priority_countries as $country)
5533 5862
 	{
5534 5863
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5535
-		if (!empty($country_tzids))
5536
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5864
+		if (!empty($country_tzids)) {
5865
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5866
+		}
5537 5867
 	}
5538 5868
 
5539 5869
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5547,8 +5877,9 @@  discard block
 block discarded – undo
5547 5877
 	foreach ($tzids as $tzid)
5548 5878
 	{
5549 5879
 		// We don't want UTC right now
5550
-		if ($tzid == 'UTC')
5551
-			continue;
5880
+		if ($tzid == 'UTC') {
5881
+					continue;
5882
+		}
5552 5883
 
5553 5884
 		$tz = timezone_open($tzid);
5554 5885
 
@@ -5569,13 +5900,14 @@  discard block
 block discarded – undo
5569 5900
 		}
5570 5901
 
5571 5902
 		// A time zone from a prioritized country?
5572
-		if (in_array($tzid, $priority_tzids))
5573
-			$priority_zones[$tzkey] = true;
5903
+		if (in_array($tzid, $priority_tzids)) {
5904
+					$priority_zones[$tzkey] = true;
5905
+		}
5574 5906
 
5575 5907
 		// Keep track of the location and offset for this tzid
5576
-		if (!empty($txt[$tzid]))
5577
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5578
-		else
5908
+		if (!empty($txt[$tzid])) {
5909
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5910
+		} else
5579 5911
 		{
5580 5912
 			$tzid_parts = explode('/', $tzid);
5581 5913
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5595,23 +5927,27 @@  discard block
 block discarded – undo
5595 5927
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5596 5928
 
5597 5929
 		// Use the custom description, if there is one
5598
-		if (!empty($tztxt[$tzvalue['tzid']]))
5599
-			$desc = $tztxt[$tzvalue['tzid']];
5930
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5931
+					$desc = $tztxt[$tzvalue['tzid']];
5932
+		}
5600 5933
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5601
-		else
5602
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5934
+		else {
5935
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5936
+		}
5603 5937
 
5604 5938
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5605 5939
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5606 5940
 
5607
-		if (isset($priority_zones[$tzkey]))
5608
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5609
-		else
5610
-			$timezones[$tzvalue['tzid']] = $desc;
5941
+		if (isset($priority_zones[$tzkey])) {
5942
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5943
+		} else {
5944
+					$timezones[$tzvalue['tzid']] = $desc;
5945
+		}
5611 5946
 	}
5612 5947
 
5613
-	if (!empty($priority_timezones))
5614
-		$priority_timezones[] = '-----';
5948
+	if (!empty($priority_timezones)) {
5949
+			$priority_timezones[] = '-----';
5950
+	}
5615 5951
 
5616 5952
 	$timezones = array_merge(
5617 5953
 		$priority_timezones,
@@ -5628,8 +5964,9 @@  discard block
 block discarded – undo
5628 5964
  */
5629 5965
 function inet_ptod($ip_address)
5630 5966
 {
5631
-	if (!isValidIP($ip_address))
5632
-		return $ip_address;
5967
+	if (!isValidIP($ip_address)) {
5968
+			return $ip_address;
5969
+	}
5633 5970
 
5634 5971
 	$bin = inet_pton($ip_address);
5635 5972
 	return $bin;
@@ -5641,13 +5978,15 @@  discard block
 block discarded – undo
5641 5978
  */
5642 5979
 function inet_dtop($bin)
5643 5980
 {
5644
-	if(empty($bin))
5645
-		return '';
5981
+	if(empty($bin)) {
5982
+			return '';
5983
+	}
5646 5984
 
5647 5985
 	global $db_type;
5648 5986
 
5649
-	if ($db_type == 'postgresql')
5650
-		return $bin;
5987
+	if ($db_type == 'postgresql') {
5988
+			return $bin;
5989
+	}
5651 5990
 
5652 5991
 	$ip_address = inet_ntop($bin);
5653 5992
 
@@ -5672,26 +6011,32 @@  discard block
 block discarded – undo
5672 6011
  */
5673 6012
 function _safe_serialize($value)
5674 6013
 {
5675
-	if(is_null($value))
5676
-		return 'N;';
6014
+	if(is_null($value)) {
6015
+			return 'N;';
6016
+	}
5677 6017
 
5678
-	if(is_bool($value))
5679
-		return 'b:'. (int) $value .';';
6018
+	if(is_bool($value)) {
6019
+			return 'b:'. (int) $value .';';
6020
+	}
5680 6021
 
5681
-	if(is_int($value))
5682
-		return 'i:'. $value .';';
6022
+	if(is_int($value)) {
6023
+			return 'i:'. $value .';';
6024
+	}
5683 6025
 
5684
-	if(is_float($value))
5685
-		return 'd:'. str_replace(',', '.', $value) .';';
6026
+	if(is_float($value)) {
6027
+			return 'd:'. str_replace(',', '.', $value) .';';
6028
+	}
5686 6029
 
5687
-	if(is_string($value))
5688
-		return 's:'. strlen($value) .':"'. $value .'";';
6030
+	if(is_string($value)) {
6031
+			return 's:'. strlen($value) .':"'. $value .'";';
6032
+	}
5689 6033
 
5690 6034
 	if(is_array($value))
5691 6035
 	{
5692 6036
 		$out = '';
5693
-		foreach($value as $k => $v)
5694
-			$out .= _safe_serialize($k) . _safe_serialize($v);
6037
+		foreach($value as $k => $v) {
6038
+					$out .= _safe_serialize($k) . _safe_serialize($v);
6039
+		}
5695 6040
 
5696 6041
 		return 'a:'. count($value) .':{'. $out .'}';
5697 6042
 	}
@@ -5717,8 +6062,9 @@  discard block
 block discarded – undo
5717 6062
 
5718 6063
 	$out = _safe_serialize($value);
5719 6064
 
5720
-	if (isset($mbIntEnc))
5721
-		mb_internal_encoding($mbIntEnc);
6065
+	if (isset($mbIntEnc)) {
6066
+			mb_internal_encoding($mbIntEnc);
6067
+	}
5722 6068
 
5723 6069
 	return $out;
5724 6070
 }
@@ -5735,8 +6081,9 @@  discard block
 block discarded – undo
5735 6081
 function _safe_unserialize($str)
5736 6082
 {
5737 6083
 	// Input  is not a string.
5738
-	if(empty($str) || !is_string($str))
5739
-		return false;
6084
+	if(empty($str) || !is_string($str)) {
6085
+			return false;
6086
+	}
5740 6087
 
5741 6088
 	$stack = array();
5742 6089
 	$expected = array();
@@ -5752,43 +6099,38 @@  discard block
 block discarded – undo
5752 6099
 	while($state != 1)
5753 6100
 	{
5754 6101
 		$type = isset($str[0]) ? $str[0] : '';
5755
-		if($type == '}')
5756
-			$str = substr($str, 1);
5757
-
5758
-		else if($type == 'N' && $str[1] == ';')
6102
+		if($type == '}') {
6103
+					$str = substr($str, 1);
6104
+		} else if($type == 'N' && $str[1] == ';')
5759 6105
 		{
5760 6106
 			$value = null;
5761 6107
 			$str = substr($str, 2);
5762
-		}
5763
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
6108
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5764 6109
 		{
5765 6110
 			$value = $matches[1] == '1' ? true : false;
5766 6111
 			$str = substr($str, 4);
5767
-		}
5768
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
6112
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5769 6113
 		{
5770 6114
 			$value = (int)$matches[1];
5771 6115
 			$str = $matches[2];
5772
-		}
5773
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
6116
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5774 6117
 		{
5775 6118
 			$value = (float)$matches[1];
5776 6119
 			$str = $matches[3];
5777
-		}
5778
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
6120
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5779 6121
 		{
5780 6122
 			$value = substr($matches[2], 0, (int)$matches[1]);
5781 6123
 			$str = substr($matches[2], (int)$matches[1] + 2);
5782
-		}
5783
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
6124
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5784 6125
 		{
5785 6126
 			$expectedLength = (int)$matches[1];
5786 6127
 			$str = $matches[2];
5787 6128
 		}
5788 6129
 
5789 6130
 		// Object or unknown/malformed type.
5790
-		else
5791
-			return false;
6131
+		else {
6132
+					return false;
6133
+		}
5792 6134
 
5793 6135
 		switch($state)
5794 6136
 		{
@@ -5816,8 +6158,9 @@  discard block
 block discarded – undo
5816 6158
 				if($type == '}')
5817 6159
 				{
5818 6160
 					// Array size is less than expected.
5819
-					if(count($list) < end($expected))
5820
-						return false;
6161
+					if(count($list) < end($expected)) {
6162
+											return false;
6163
+					}
5821 6164
 
5822 6165
 					unset($list);
5823 6166
 					$list = &$stack[count($stack)-1];
@@ -5826,8 +6169,9 @@  discard block
 block discarded – undo
5826 6169
 					// Go to terminal state if we're at the end of the root array.
5827 6170
 					array_pop($expected);
5828 6171
 
5829
-					if(count($expected) == 0)
5830
-						$state = 1;
6172
+					if(count($expected) == 0) {
6173
+											$state = 1;
6174
+					}
5831 6175
 
5832 6176
 					break;
5833 6177
 				}
@@ -5835,8 +6179,9 @@  discard block
 block discarded – undo
5835 6179
 				if($type == 'i' || $type == 's')
5836 6180
 				{
5837 6181
 					// Array size exceeds expected length.
5838
-					if(count($list) >= end($expected))
5839
-						return false;
6182
+					if(count($list) >= end($expected)) {
6183
+											return false;
6184
+					}
5840 6185
 
5841 6186
 					$key = $value;
5842 6187
 					$state = 3;
@@ -5870,8 +6215,9 @@  discard block
 block discarded – undo
5870 6215
 	}
5871 6216
 
5872 6217
 	// Trailing data in input.
5873
-	if(!empty($str))
5874
-		return false;
6218
+	if(!empty($str)) {
6219
+			return false;
6220
+	}
5875 6221
 
5876 6222
 	return $data;
5877 6223
 }
@@ -5894,8 +6240,9 @@  discard block
 block discarded – undo
5894 6240
 
5895 6241
 	$out = _safe_unserialize($str);
5896 6242
 
5897
-	if (isset($mbIntEnc))
5898
-		mb_internal_encoding($mbIntEnc);
6243
+	if (isset($mbIntEnc)) {
6244
+			mb_internal_encoding($mbIntEnc);
6245
+	}
5899 6246
 
5900 6247
 	return $out;
5901 6248
 }
@@ -5910,12 +6257,14 @@  discard block
 block discarded – undo
5910 6257
 function smf_chmod($file, $value = 0)
5911 6258
 {
5912 6259
 	// No file? no checks!
5913
-	if (empty($file))
5914
-		return false;
6260
+	if (empty($file)) {
6261
+			return false;
6262
+	}
5915 6263
 
5916 6264
 	// Already writable?
5917
-	if (is_writable($file))
5918
-		return true;
6265
+	if (is_writable($file)) {
6266
+			return true;
6267
+	}
5919 6268
 
5920 6269
 	// Do we have a file or a dir?
5921 6270
 	$isDir = is_dir($file);
@@ -5931,10 +6280,9 @@  discard block
 block discarded – undo
5931 6280
 		{
5932 6281
 			$isWritable = true;
5933 6282
 			break;
6283
+		} else {
6284
+					@chmod($file, $val);
5934 6285
 		}
5935
-
5936
-		else
5937
-			@chmod($file, $val);
5938 6286
 	}
5939 6287
 
5940 6288
 	return $isWritable;
@@ -5953,8 +6301,9 @@  discard block
 block discarded – undo
5953 6301
 	global $txt;
5954 6302
 
5955 6303
 	// Come on...
5956
-	if (empty($json) || !is_string($json))
5957
-		return array();
6304
+	if (empty($json) || !is_string($json)) {
6305
+			return array();
6306
+	}
5958 6307
 
5959 6308
 	$returnArray = @json_decode($json, $returnAsArray);
5960 6309
 
@@ -5992,11 +6341,11 @@  discard block
 block discarded – undo
5992 6341
 		$jsonDebug = $jsonDebug[0];
5993 6342
 		loadLanguage('Errors');
5994 6343
 
5995
-		if (!empty($jsonDebug))
5996
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5997
-
5998
-		else
5999
-			log_error($txt['json_'. $jsonError], 'critical');
6344
+		if (!empty($jsonDebug)) {
6345
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6346
+		} else {
6347
+					log_error($txt['json_'. $jsonError], 'critical');
6348
+		}
6000 6349
 
6001 6350
 		// Everyone expects an array.
6002 6351
 		return array();
@@ -6030,8 +6379,9 @@  discard block
 block discarded – undo
6030 6379
 	global $db_show_debug, $modSettings;
6031 6380
 
6032 6381
 	// Defensive programming anyone?
6033
-	if (empty($data))
6034
-		return false;
6382
+	if (empty($data)) {
6383
+			return false;
6384
+	}
6035 6385
 
6036 6386
 	// Don't need extra stuff...
6037 6387
 	$db_show_debug = false;
@@ -6039,11 +6389,11 @@  discard block
 block discarded – undo
6039 6389
 	// Kill anything else.
6040 6390
 	ob_end_clean();
6041 6391
 
6042
-	if (!empty($modSettings['CompressedOutput']))
6043
-		@ob_start('ob_gzhandler');
6044
-
6045
-	else
6046
-		ob_start();
6392
+	if (!empty($modSettings['CompressedOutput'])) {
6393
+			@ob_start('ob_gzhandler');
6394
+	} else {
6395
+			ob_start();
6396
+	}
6047 6397
 
6048 6398
 	// Set the header.
6049 6399
 	header($type);
@@ -6075,8 +6425,9 @@  discard block
 block discarded – undo
6075 6425
 	static $done = false;
6076 6426
 
6077 6427
 	// If we don't need to do anything, don't
6078
-	if (!$update && $done)
6079
-		return;
6428
+	if (!$update && $done) {
6429
+			return;
6430
+	}
6080 6431
 
6081 6432
 	// Should we get a new copy of the official list of TLDs?
6082 6433
 	if ($update)
@@ -6088,8 +6439,9 @@  discard block
 block discarded – undo
6088 6439
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
6089 6440
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
6090 6441
 		// update to see if civilization has been restored.
6091
-		if ($tlds === false)
6092
-			$postapocalypticNightmare = true;
6442
+		if ($tlds === false) {
6443
+					$postapocalypticNightmare = true;
6444
+		}
6093 6445
 	}
6094 6446
 	// If we aren't updating and the regex is valid, we're done
6095 6447
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -6104,10 +6456,11 @@  discard block
 block discarded – undo
6104 6456
 		// Clean $tlds and convert it to an array
6105 6457
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
6106 6458
 			$line = trim($line);
6107
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
6108
-				return false;
6109
-			else
6110
-				return true;
6459
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6460
+							return false;
6461
+			} else {
6462
+							return true;
6463
+			}
6111 6464
 		});
6112 6465
 
6113 6466
 		// Convert Punycode to Unicode
@@ -6199,8 +6552,7 @@  discard block
 block discarded – undo
6199 6552
 
6200 6553
 		$strlen = 'mb_strlen';
6201 6554
 		$substr = 'mb_substr';
6202
-	}
6203
-	else
6555
+	} else
6204 6556
 	{
6205 6557
 		$strlen = $smcFunc['strlen'];
6206 6558
 		$substr = $smcFunc['substr'];
@@ -6214,20 +6566,21 @@  discard block
 block discarded – undo
6214 6566
 
6215 6567
 		$first = $substr($string, 0, 1);
6216 6568
 
6217
-		if (empty($index[$first]))
6218
-			$index[$first] = array();
6569
+		if (empty($index[$first])) {
6570
+					$index[$first] = array();
6571
+		}
6219 6572
 
6220 6573
 		if ($strlen($string) > 1)
6221 6574
 		{
6222 6575
 			// Sanity check on recursion
6223
-			if ($depth > 99)
6224
-				$index[$first][$substr($string, 1)] = '';
6225
-
6226
-			else
6227
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6576
+			if ($depth > 99) {
6577
+							$index[$first][$substr($string, 1)] = '';
6578
+			} else {
6579
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6580
+			}
6581
+		} else {
6582
+					$index[$first][''] = '';
6228 6583
 		}
6229
-		else
6230
-			$index[$first][''] = '';
6231 6584
 
6232 6585
 		$depth--;
6233 6586
 		return $index;
@@ -6250,9 +6603,9 @@  discard block
 block discarded – undo
6250 6603
 			$key_regex = preg_quote($key, $delim);
6251 6604
 			$new_key = $key;
6252 6605
 
6253
-			if (empty($value))
6254
-				$sub_regex = '';
6255
-			else
6606
+			if (empty($value)) {
6607
+							$sub_regex = '';
6608
+			} else
6256 6609
 			{
6257 6610
 				$sub_regex = $index_to_regex($value, $delim);
6258 6611
 
@@ -6260,22 +6613,22 @@  discard block
 block discarded – undo
6260 6613
 				{
6261 6614
 					$new_key_array = explode('(?'.'>', $sub_regex);
6262 6615
 					$new_key .= $new_key_array[0];
6616
+				} else {
6617
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6263 6618
 				}
6264
-				else
6265
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6266 6619
 			}
6267 6620
 
6268
-			if ($depth > 1)
6269
-				$regex[$new_key] = $key_regex . $sub_regex;
6270
-			else
6621
+			if ($depth > 1) {
6622
+							$regex[$new_key] = $key_regex . $sub_regex;
6623
+			} else
6271 6624
 			{
6272 6625
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6273 6626
 				{
6274 6627
 					$regex[$new_key] = $key_regex . $sub_regex;
6275 6628
 					unset($index[$key]);
6629
+				} else {
6630
+									break;
6276 6631
 				}
6277
-				else
6278
-					break;
6279 6632
 			}
6280 6633
 		}
6281 6634
 
@@ -6284,10 +6637,11 @@  discard block
 block discarded – undo
6284 6637
 			$l1 = $strlen($k1);
6285 6638
 			$l2 = $strlen($k2);
6286 6639
 
6287
-			if ($l1 == $l2)
6288
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6289
-			else
6290
-				return $l1 > $l2 ? -1 : 1;
6640
+			if ($l1 == $l2) {
6641
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6642
+			} else {
6643
+							return $l1 > $l2 ? -1 : 1;
6644
+			}
6291 6645
 		});
6292 6646
 
6293 6647
 		$depth--;
@@ -6298,21 +6652,24 @@  discard block
 block discarded – undo
6298 6652
 	$index = array();
6299 6653
 	$regex = '';
6300 6654
 
6301
-	foreach ($strings as $string)
6302
-		$index = $add_string_to_index($string, $index);
6655
+	foreach ($strings as $string) {
6656
+			$index = $add_string_to_index($string, $index);
6657
+	}
6303 6658
 
6304 6659
 	if ($returnArray === true)
6305 6660
 	{
6306 6661
 		$regex = array();
6307
-		while (!empty($index))
6308
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6662
+		while (!empty($index)) {
6663
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6664
+		}
6665
+	} else {
6666
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6309 6667
 	}
6310
-	else
6311
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6312 6668
 
6313 6669
 	// Restore PHP's internal character encoding to whatever it was originally
6314
-	if (!empty($current_encoding))
6315
-		mb_internal_encoding($current_encoding);
6670
+	if (!empty($current_encoding)) {
6671
+			mb_internal_encoding($current_encoding);
6672
+	}
6316 6673
 
6317 6674
 	return $regex;
6318 6675
 }
@@ -6355,13 +6712,15 @@  discard block
 block discarded – undo
6355 6712
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6356 6713
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6357 6714
 	$headers = @get_headers($url);
6358
-	if ($headers === false)
6359
-		return false;
6715
+	if ($headers === false) {
6716
+			return false;
6717
+	}
6360 6718
 
6361 6719
 	// Now to see if it came back https...
6362 6720
 	// First check for a redirect status code in first row (301, 302, 307)
6363
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6364
-		return false;
6721
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6722
+			return false;
6723
+	}
6365 6724
 
6366 6725
 	// Search for the location entry to confirm https
6367 6726
 	$result = false;
@@ -6399,8 +6758,7 @@  discard block
 block discarded – undo
6399 6758
 		$is_admin = $user_info['is_admin'];
6400 6759
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6401 6760
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6402
-	}
6403
-	else
6761
+	} else
6404 6762
 	{
6405 6763
 		$request = $smcFunc['db_query']('', '
6406 6764
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6414,17 +6772,19 @@  discard block
 block discarded – undo
6414 6772
 
6415 6773
 		$row = $smcFunc['db_fetch_assoc']($request);
6416 6774
 
6417
-		if (empty($row['additional_groups']))
6418
-			$groups = array($row['id_group'], $row['id_post_group']);
6419
-		else
6420
-			$groups = array_merge(
6775
+		if (empty($row['additional_groups'])) {
6776
+					$groups = array($row['id_group'], $row['id_post_group']);
6777
+		} else {
6778
+					$groups = array_merge(
6421 6779
 					array($row['id_group'], $row['id_post_group']),
6422 6780
 					explode(',', $row['additional_groups'])
6423 6781
 			);
6782
+		}
6424 6783
 
6425 6784
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6426
-		foreach ($groups as $k => $v)
6427
-			$groups[$k] = (int) $v;
6785
+		foreach ($groups as $k => $v) {
6786
+					$groups[$k] = (int) $v;
6787
+		}
6428 6788
 
6429 6789
 		$is_admin = in_array(1, $groups);
6430 6790
 
@@ -6441,8 +6801,9 @@  discard block
 block discarded – undo
6441 6801
 				'current_member' => $userid,
6442 6802
 			)
6443 6803
 		);
6444
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6445
-			$boards_mod[] = $row['id_board'];
6804
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6805
+					$boards_mod[] = $row['id_board'];
6806
+		}
6446 6807
 		$smcFunc['db_free_result']($request);
6447 6808
 
6448 6809
 		// Can any of the groups they're in moderate any of the boards?
@@ -6454,8 +6815,9 @@  discard block
 block discarded – undo
6454 6815
 				'groups' => $groups,
6455 6816
 			)
6456 6817
 		);
6457
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6458
-			$boards_mod[] = $row['id_board'];
6818
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6819
+					$boards_mod[] = $row['id_board'];
6820
+		}
6459 6821
 		$smcFunc['db_free_result']($request);
6460 6822
 
6461 6823
 		// Just in case we've got duplicates here...
@@ -6465,21 +6827,25 @@  discard block
 block discarded – undo
6465 6827
 	}
6466 6828
 
6467 6829
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6468
-	if ($is_admin)
6469
-		$query_part['query_see_board'] = '1=1';
6830
+	if ($is_admin) {
6831
+			$query_part['query_see_board'] = '1=1';
6832
+	}
6470 6833
 	// Otherwise just the groups in $user_info['groups'].
6471
-	else
6472
-		$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6834
+	else {
6835
+			$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6836
+	}
6473 6837
 
6474 6838
 	// Build the list of boards they WANT to see.
6475 6839
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6476 6840
 
6477 6841
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6478
-	if (empty($ignoreboards))
6479
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6842
+	if (empty($ignoreboards)) {
6843
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6844
+	}
6480 6845
 	// Ok I guess they don't want to see all the boards
6481
-	else
6482
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6846
+	else {
6847
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6848
+	}
6483 6849
 
6484 6850
 	return $query_part;
6485 6851
 }
@@ -6493,10 +6859,11 @@  discard block
 block discarded – undo
6493 6859
 {
6494 6860
 	$secure = false;
6495 6861
 
6496
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6497
-		$secure = true;
6498
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
6499
-		$secure = true;
6862
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6863
+			$secure = true;
6864
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
6865
+			$secure = true;
6866
+	}
6500 6867
 
6501 6868
 	return $secure;
6502 6869
 }
@@ -6513,11 +6880,12 @@  discard block
 block discarded – undo
6513 6880
 {
6514 6881
 	$url = iri_to_url($iri);
6515 6882
 
6516
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6517
-		return $iri;
6518
-	else
6519
-		return false;
6520
-}
6883
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6884
+			return $iri;
6885
+	} else {
6886
+			return false;
6887
+	}
6888
+	}
6521 6889
 
6522 6890
 /**
6523 6891
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6560,8 +6928,9 @@  discard block
 block discarded – undo
6560 6928
 
6561 6929
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6562 6930
 
6563
-	if (empty($host))
6564
-		return $iri;
6931
+	if (empty($host)) {
6932
+			return $iri;
6933
+	}
6565 6934
 
6566 6935
 	// Convert the domain using the Punycode algorithm
6567 6936
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6597,8 +6966,9 @@  discard block
 block discarded – undo
6597 6966
 
6598 6967
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6599 6968
 
6600
-	if (empty($host))
6601
-		return $url;
6969
+	if (empty($host)) {
6970
+			return $url;
6971
+	}
6602 6972
 
6603 6973
 	// Decode the domain from Punycode
6604 6974
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6624,8 +6994,9 @@  discard block
 block discarded – undo
6624 6994
 {
6625 6995
 	global $user_info, $modSettings, $smcFunc, $txt;
6626 6996
 
6627
-	if (empty($modSettings['cron_last_checked']))
6628
-		$modSettings['cron_last_checked'] = 0;
6997
+	if (empty($modSettings['cron_last_checked'])) {
6998
+			$modSettings['cron_last_checked'] = 0;
6999
+	}
6629 7000
 
6630 7001
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6631 7002
 	{
@@ -6645,9 +7016,9 @@  discard block
 block discarded – undo
6645 7016
 			loadLanguage('ManageScheduledTasks');
6646 7017
 			log_error($txt['cron_not_working']);
6647 7018
 			updateSettings(array('cron_is_real_cron' => 0));
7019
+		} else {
7020
+					updateSettings(array('cron_last_checked' => time()));
6648 7021
 		}
6649
-		else
6650
-			updateSettings(array('cron_last_checked' => time()));
6651 7022
 	}
6652 7023
 }
6653 7024
 
@@ -6671,10 +7042,11 @@  discard block
 block discarded – undo
6671 7042
 	
6672 7043
 	$protocol = preg_match('~^\s*(HTTP/[12]\.\d)\s*$~i', $_SERVER['SERVER_PROTOCOL'], $matches) ? $matches[1] : 'HTTP/1.0';
6673 7044
 
6674
-	if (!isset($statuses[$code]) && empty($status))
6675
-		header($protocol . ' 500 Internal Server Error');
6676
-	else
6677
-		header($protocol . ' ' . $code . ' ' . !empty($status) ? $status : $statuses[$code]);
6678
-}
7045
+	if (!isset($statuses[$code]) && empty($status)) {
7046
+			header($protocol . ' 500 Internal Server Error');
7047
+	} else {
7048
+			header($protocol . ' ' . $code . ' ' . !empty($status) ? $status : $statuses[$code]);
7049
+	}
7050
+	}
6679 7051
 
6680 7052
 ?>
6681 7053
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Display.php 1 patch
Braces   +298 added lines, -219 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * The central part of the board - topic display.
@@ -34,8 +35,9 @@  discard block
 block discarded – undo
34 35
 	global $messages_request, $language, $smcFunc;
35 36
 
36 37
 	// What are you gonna display if these are empty?!
37
-	if (empty($topic))
38
-		fatal_lang_error('no_board', false);
38
+	if (empty($topic)) {
39
+			fatal_lang_error('no_board', false);
40
+	}
39 41
 
40 42
 	// Load the proper template.
41 43
 	loadTemplate('Display');
@@ -52,15 +54,17 @@  discard block
 block discarded – undo
52 54
 	$context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages'];
53 55
 
54 56
 	// Let's do some work on what to search index.
55
-	if (count($_GET) > 2)
56
-		foreach ($_GET as $k => $v)
57
+	if (count($_GET) > 2) {
58
+			foreach ($_GET as $k => $v)
57 59
 		{
58 60
 			if (!in_array($k, array('topic', 'board', 'start', session_name())))
59 61
 				$context['robot_no_index'] = true;
62
+	}
60 63
 		}
61 64
 
62
-	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0))
63
-		$context['robot_no_index'] = true;
65
+	if (!empty($_REQUEST['start']) && (!is_numeric($_REQUEST['start']) || $_REQUEST['start'] % $context['messages_per_page'] != 0)) {
66
+			$context['robot_no_index'] = true;
67
+	}
64 68
 
65 69
 	// Find the previous or next topic.  Make a fuss if there are no more.
66 70
 	if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
@@ -172,8 +176,9 @@  discard block
 block discarded – undo
172 176
 			$topic_parameters
173 177
 	);
174 178
 
175
-	if ($smcFunc['db_num_rows']($request) == 0)
176
-		fatal_lang_error('not_a_topic', false, 404);
179
+	if ($smcFunc['db_num_rows']($request) == 0) {
180
+			fatal_lang_error('not_a_topic', false, 404);
181
+	}
177 182
 	$context['topicinfo'] = $smcFunc['db_fetch_assoc']($request);
178 183
 	$smcFunc['db_free_result']($request);
179 184
 
@@ -210,8 +215,9 @@  discard block
 block discarded – undo
210 215
 	$context['topic_unwatched'] = isset($context['topicinfo']['unwatched']) ? $context['topicinfo']['unwatched'] : 0;
211 216
 
212 217
 	// Add up unapproved replies to get real number of replies...
213
-	if ($modSettings['postmod_active'] && $approve_posts)
214
-		$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
218
+	if ($modSettings['postmod_active'] && $approve_posts) {
219
+			$context['real_num_replies'] += $context['topicinfo']['unapproved_posts'] - ($context['topicinfo']['approved'] ? 0 : 1);
220
+	}
215 221
 
216 222
 	// If this topic has unapproved posts, we need to work out how many posts the user can see, for page indexing.
217 223
 	if ($modSettings['postmod_active'] && $context['topicinfo']['unapproved_posts'] && !$user_info['is_guest'] && !$approve_posts)
@@ -231,11 +237,11 @@  discard block
 block discarded – undo
231 237
 		$smcFunc['db_free_result']($request);
232 238
 
233 239
 		$context['total_visible_posts'] = $context['num_replies'] + $myUnapprovedPosts + ($context['topicinfo']['approved'] ? 1 : 0);
240
+	} elseif ($user_info['is_guest']) {
241
+			$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
242
+	} else {
243
+			$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
234 244
 	}
235
-	elseif ($user_info['is_guest'])
236
-		$context['total_visible_posts'] = $context['num_replies'] + ($context['topicinfo']['approved'] ? 1 : 0);
237
-	else
238
-		$context['total_visible_posts'] = $context['num_replies'] + $context['topicinfo']['unapproved_posts'] + ($context['topicinfo']['approved'] ? 1 : 0);
239 245
 
240 246
 	// The start isn't a number; it's information about what to do, where to go.
241 247
 	if (!is_numeric($_REQUEST['start']))
@@ -248,8 +254,7 @@  discard block
 block discarded – undo
248 254
 			{
249 255
 				$context['start_from'] = $context['total_visible_posts'] - 1;
250 256
 				$_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
251
-			}
252
-			else
257
+			} else
253 258
 			{
254 259
 				// Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
255 260
 				$request = $smcFunc['db_query']('', '
@@ -277,9 +282,9 @@  discard block
 block discarded – undo
277 282
 		if (substr($_REQUEST['start'], 0, 4) == 'from')
278 283
 		{
279 284
 			$timestamp = (int) substr($_REQUEST['start'], 4);
280
-			if ($timestamp === 0)
281
-				$_REQUEST['start'] = 0;
282
-			else
285
+			if ($timestamp === 0) {
286
+							$_REQUEST['start'] = 0;
287
+			} else
283 288
 			{
284 289
 				// Find the number of messages posted before said time...
285 290
 				$request = $smcFunc['db_query']('', '
@@ -307,11 +312,11 @@  discard block
 block discarded – undo
307 312
 		elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
308 313
 		{
309 314
 			$virtual_msg = (int) substr($_REQUEST['start'], 3);
310
-			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg'])
311
-				$context['start_from'] = $context['total_visible_posts'] - 1;
312
-			elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg'])
313
-				$context['start_from'] = 0;
314
-			else
315
+			if (!$context['topicinfo']['unapproved_posts'] && $virtual_msg >= $context['topicinfo']['id_last_msg']) {
316
+							$context['start_from'] = $context['total_visible_posts'] - 1;
317
+			} elseif (!$context['topicinfo']['unapproved_posts'] && $virtual_msg <= $context['topicinfo']['id_first_msg']) {
318
+							$context['start_from'] = 0;
319
+			} else
315 320
 			{
316 321
 				// Find the start value for that message......
317 322
 				$request = $smcFunc['db_query']('', '
@@ -365,9 +370,10 @@  discard block
 block discarded – undo
365 370
 		list ($sig_limits, $sig_bbc) = explode(':', $modSettings['signature_settings']);
366 371
 		$sig_limits = explode(',', $sig_limits);
367 372
 
368
-		if (!empty($sig_limits[5]) || !empty($sig_limits[6]))
369
-			addInlineCss('
373
+		if (!empty($sig_limits[5]) || !empty($sig_limits[6])) {
374
+					addInlineCss('
370 375
 	.signature img { ' . (!empty($sig_limits[5]) ? 'max-width: ' . (int) $sig_limits[5] . 'px; ' : '') . (!empty($sig_limits[6]) ? 'max-height: ' . (int) $sig_limits[6] . 'px; ' : '') . '}');
376
+		}
371 377
 	}
372 378
 
373 379
 	// Censor the title...
@@ -405,21 +411,25 @@  discard block
 block discarded – undo
405 411
 		);
406 412
 		while ($row = $smcFunc['db_fetch_assoc']($request))
407 413
 		{
408
-			if (empty($row['id_member']))
409
-				continue;
414
+			if (empty($row['id_member'])) {
415
+							continue;
416
+			}
410 417
 
411
-			if (!empty($row['online_color']))
412
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
413
-			else
414
-				$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
418
+			if (!empty($row['online_color'])) {
419
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
420
+			} else {
421
+							$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';
422
+			}
415 423
 
416 424
 			$is_buddy = in_array($row['id_member'], $user_info['buddies']);
417
-			if ($is_buddy)
418
-				$link = '<strong>' . $link . '</strong>';
425
+			if ($is_buddy) {
426
+							$link = '<strong>' . $link . '</strong>';
427
+			}
419 428
 
420 429
 			// Add them both to the list and to the more detailed list.
421
-			if (!empty($row['show_online']) || allowedTo('moderate_forum'))
422
-				$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
430
+			if (!empty($row['show_online']) || allowedTo('moderate_forum')) {
431
+							$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
432
+			}
423 433
 			$context['view_members'][$row['log_time'] . $row['member_name']] = array(
424 434
 				'id' => $row['id_member'],
425 435
 				'username' => $row['member_name'],
@@ -431,8 +441,9 @@  discard block
 block discarded – undo
431 441
 				'hidden' => empty($row['show_online']),
432 442
 			);
433 443
 
434
-			if (empty($row['show_online']))
435
-				$context['view_num_hidden']++;
444
+			if (empty($row['show_online'])) {
445
+							$context['view_num_hidden']++;
446
+			}
436 447
 		}
437 448
 
438 449
 		// The number of guests is equal to the rows minus the ones we actually used ;).
@@ -446,11 +457,13 @@  discard block
 block discarded – undo
446 457
 
447 458
 	// If all is set, but not allowed... just unset it.
448 459
 	$can_show_all = !empty($modSettings['enableAllMessages']) && $context['total_visible_posts'] > $context['messages_per_page'] && $context['total_visible_posts'] < $modSettings['enableAllMessages'];
449
-	if (isset($_REQUEST['all']) && !$can_show_all)
450
-		unset($_REQUEST['all']);
460
+	if (isset($_REQUEST['all']) && !$can_show_all) {
461
+			unset($_REQUEST['all']);
462
+	}
451 463
 	// Otherwise, it must be allowed... so pretend start was -1.
452
-	elseif (isset($_REQUEST['all']))
453
-		$_REQUEST['start'] = -1;
464
+	elseif (isset($_REQUEST['all'])) {
465
+			$_REQUEST['start'] = -1;
466
+	}
454 467
 
455 468
 	// Construct the page index, allowing for the .START method...
456 469
 	$context['page_index'] = constructPageIndex($scripturl . '?topic=' . $topic . '.%1$d', $_REQUEST['start'], $context['total_visible_posts'], $context['messages_per_page'], true);
@@ -487,8 +500,9 @@  discard block
 block discarded – undo
487 500
 			$_REQUEST['start'] = 0;
488 501
 		}
489 502
 		// They aren't using it, but the *option* is there, at least.
490
-		else
491
-			$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
503
+		else {
504
+					$context['page_index'] .= '&nbsp;<a href="' . $scripturl . '?topic=' . $topic . '.0;all">' . $txt['all'] . '</a> ';
505
+		}
492 506
 	}
493 507
 
494 508
 	// Build the link tree.
@@ -504,14 +518,16 @@  discard block
 block discarded – undo
504 518
 	if (!empty($board_info['moderators']))
505 519
 	{
506 520
 		// Add a link for each moderator...
507
-		foreach ($board_info['moderators'] as $mod)
508
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
521
+		foreach ($board_info['moderators'] as $mod) {
522
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=profile;u=' . $mod['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod['name'] . '</a>';
523
+		}
509 524
 	}
510 525
 	if (!empty($board_info['moderator_groups']))
511 526
 	{
512 527
 		// Add a link for each moderator group as well...
513
-		foreach ($board_info['moderator_groups'] as $mod_group)
514
-			$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
528
+		foreach ($board_info['moderator_groups'] as $mod_group) {
529
+					$context['link_moderators'][] = '<a href="' . $scripturl . '?action=groups;sa=viewmemberes;group=' . $mod_group['id'] . '" title="' . $txt['board_moderator'] . '">' . $mod_group['name'] . '</a>';
530
+		}
515 531
 	}
516 532
 
517 533
 	if (!empty($context['link_moderators']))
@@ -542,9 +558,9 @@  discard block
 block discarded – undo
542 558
 	// For quick reply we need a response prefix in the default forum language.
543 559
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix', 600)))
544 560
 	{
545
-		if ($language === $user_info['language'])
546
-			$context['response_prefix'] = $txt['response_prefix'];
547
-		else
561
+		if ($language === $user_info['language']) {
562
+					$context['response_prefix'] = $txt['response_prefix'];
563
+		} else
548 564
 		{
549 565
 			loadLanguage('index', $language, false);
550 566
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -576,8 +592,9 @@  discard block
 block discarded – undo
576 592
 			list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row);
577 593
 
578 594
 			// Sanity check
579
-			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count']))
580
-				continue;
595
+			if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) {
596
+							continue;
597
+			}
581 598
 
582 599
 			$linked_calendar_event = array(
583 600
 				'id' => $row['id_event'],
@@ -626,8 +643,9 @@  discard block
 block discarded – undo
626 643
 		}
627 644
 		$smcFunc['db_free_result']($request);
628 645
 
629
-		if (!empty($context['linked_calendar_events']))
630
-			$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
646
+		if (!empty($context['linked_calendar_events'])) {
647
+					$context['linked_calendar_events'][count($context['linked_calendar_events']) - 1]['is_last'] = true;
648
+		}
631 649
 	}
632 650
 
633 651
 	// Create the poll info if it exists.
@@ -651,9 +669,9 @@  discard block
 block discarded – undo
651 669
 	}
652 670
 
653 671
 	// Create the poll info if it exists and is valid.
654
-	if ($context['is_poll'] && empty($pollinfo))
655
-		$context['is_poll'] = false;
656
-	elseif ($context['is_poll'])
672
+	if ($context['is_poll'] && empty($pollinfo)) {
673
+			$context['is_poll'] = false;
674
+	} elseif ($context['is_poll'])
657 675
 	{
658 676
 		$request = $smcFunc['db_query']('', '
659 677
 			SELECT COUNT(DISTINCT id_member) AS total
@@ -696,8 +714,9 @@  discard block
 block discarded – undo
696 714
 		$smcFunc['db_free_result']($request);
697 715
 
698 716
 		// Got we multi choice?
699
-		if ($pollinfo['max_votes'] > 1)
700
-			$realtotal = $pollinfo['total'];
717
+		if ($pollinfo['max_votes'] > 1) {
718
+					$realtotal = $pollinfo['total'];
719
+		}
701 720
 
702 721
 		// If this is a guest we need to do our best to work out if they have voted, and what they voted for.
703 722
 		if ($user_info['is_guest'] && $pollinfo['guest_vote'] && allowedTo('poll_vote'))
@@ -710,20 +729,21 @@  discard block
 block discarded – undo
710 729
 				foreach ($guestinfo as $i => $guestvoted)
711 730
 				{
712 731
 					$guestvoted = explode(',', $guestvoted);
713
-					if ($guestvoted[0] == $context['topicinfo']['id_poll'])
714
-						break;
732
+					if ($guestvoted[0] == $context['topicinfo']['id_poll']) {
733
+											break;
734
+					}
715 735
 				}
716 736
 				// Has the poll been reset since guest voted?
717 737
 				if ($pollinfo['reset_poll'] > $guestvoted[1])
718 738
 				{
719 739
 					// Remove the poll info from the cookie to allow guest to vote again
720 740
 					unset($guestinfo[$i]);
721
-					if (!empty($guestinfo))
722
-						$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
723
-					else
724
-						unset($_COOKIE['guest_poll_vote']);
725
-				}
726
-				else
741
+					if (!empty($guestinfo)) {
742
+											$_COOKIE['guest_poll_vote'] = ';' . implode(';', $guestinfo);
743
+					} else {
744
+											unset($_COOKIE['guest_poll_vote']);
745
+					}
746
+				} else
727 747
 				{
728 748
 					// What did they vote for?
729 749
 					unset($guestvoted[0], $guestvoted[1]);
@@ -837,23 +857,29 @@  discard block
 block discarded – undo
837 857
 		// Build the poll moderation button array.
838 858
 		$context['poll_buttons'] = array();
839 859
 
840
-		if ($context['allow_return_vote'])
841
-			$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
860
+		if ($context['allow_return_vote']) {
861
+					$context['poll_buttons']['vote'] = array('text' => 'poll_return_vote', 'image' => 'poll_options.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start']);
862
+		}
842 863
 
843
-		if ($context['show_view_results_button'])
844
-			$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
864
+		if ($context['show_view_results_button']) {
865
+					$context['poll_buttons']['results'] = array('text' => 'poll_results', 'image' => 'poll_results.png', 'url' => $scripturl . '?topic=' . $context['current_topic'] . '.' . $context['start'] . ';viewresults');
866
+		}
845 867
 
846
-		if ($context['allow_change_vote'])
847
-			$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
868
+		if ($context['allow_change_vote']) {
869
+					$context['poll_buttons']['change_vote'] = array('text' => 'poll_change_vote', 'image' => 'poll_change_vote.png', 'url' => $scripturl . '?action=vote;topic=' . $context['current_topic'] . '.' . $context['start'] . ';poll=' . $context['poll']['id'] . ';' . $context['session_var'] . '=' . $context['session_id']);
870
+		}
848 871
 
849
-		if ($context['allow_lock_poll'])
850
-			$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
872
+		if ($context['allow_lock_poll']) {
873
+					$context['poll_buttons']['lock'] = array('text' => (!$context['poll']['is_locked'] ? 'poll_lock' : 'poll_unlock'), 'image' => 'poll_lock.png', 'url' => $scripturl . '?action=lockvoting;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
874
+		}
851 875
 
852
-		if ($context['allow_edit_poll'])
853
-			$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
876
+		if ($context['allow_edit_poll']) {
877
+					$context['poll_buttons']['edit'] = array('text' => 'poll_edit', 'image' => 'poll_edit.png', 'url' => $scripturl . '?action=editpoll;topic=' . $context['current_topic'] . '.' . $context['start']);
878
+		}
854 879
 
855
-		if ($context['can_remove_poll'])
856
-			$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
880
+		if ($context['can_remove_poll']) {
881
+					$context['poll_buttons']['remove_poll'] = array('text' => 'poll_remove', 'image' => 'admin_remove_poll.png', 'custom' => 'data-confirm="' . $txt['poll_remove_warn'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
882
+		}
857 883
 
858 884
 		// Allow mods to add additional buttons here
859 885
 		call_integration_hook('integrate_poll_buttons');
@@ -889,9 +915,9 @@  discard block
 block discarded – undo
889 915
 	{
890 916
 		$start_char = 'C';
891 917
 		$page_id = $ascending ? $context['topicinfo']['id_first_msg'] : $context['topicinfo']['id_last_msg'];
918
+	} else {
919
+			$start_char = null;
892 920
 	}
893
-	else
894
-		$start_char = null;
895 921
 
896 922
 	$limit = $context['messages_per_page'];
897 923
 
@@ -905,17 +931,17 @@  discard block
 block discarded – undo
905 931
 		{
906 932
 			$ascending_seek = true;
907 933
 			$page_operator = $ascending ? '>=' : '<=';
908
-		}
909
-		else
934
+		} else
910 935
 		{
911 936
 			$ascending_seek = false;
912 937
 			$page_operator = $ascending ? '<=' : '>=';
913 938
 		}
914 939
 
915
-		if ($start_char === 'C')
916
-			$limit_seek = $limit;
917
-		else
918
-			$limit_seek  = $limit + 1;
940
+		if ($start_char === 'C') {
941
+					$limit_seek = $limit;
942
+		} else {
943
+					$limit_seek  = $limit + 1;
944
+		}
919 945
 
920 946
 		$request = $smcFunc['db_query']('', '
921 947
 			SELECT id_msg, id_member, approved
@@ -938,21 +964,23 @@  discard block
 block discarded – undo
938 964
 		$found_msg = false;
939 965
 
940 966
 		// Fallback
941
-		if ($smcFunc['db_num_rows']($request) < 1)
942
-			unset($start_char);
943
-		else
967
+		if ($smcFunc['db_num_rows']($request) < 1) {
968
+					unset($start_char);
969
+		} else
944 970
 		{
945 971
 			while ($row = $smcFunc['db_fetch_assoc']($request))
946 972
 			{
947 973
 				// Check if the start msg is in our result
948
-				if ($row['id_msg'] == $page_id)
949
-					$found_msg = true;
974
+				if ($row['id_msg'] == $page_id) {
975
+									$found_msg = true;
976
+				}
950 977
 
951 978
 				// Skip the the start msg if we not in mode C
952 979
 				if ($start_char === 'C' || $row['id_msg'] != $page_id)
953 980
 				{
954
-					if (!empty($row['id_member']))
955
-						$all_posters[$row['id_msg']] = $row['id_member'];
981
+					if (!empty($row['id_member'])) {
982
+											$all_posters[$row['id_msg']] = $row['id_member'];
983
+					}
956 984
 
957 985
 					$messages[] = $row['id_msg'];
958 986
 				}
@@ -968,8 +996,9 @@  discard block
 block discarded – undo
968 996
 		}
969 997
 
970 998
 		// Before Page bring in the right order
971
-		if (!empty($start_char) && $start_char === 'L')
972
-			krsort($messages);
999
+		if (!empty($start_char) && $start_char === 'L') {
1000
+					krsort($messages);
1001
+		}
973 1002
 	}
974 1003
 
975 1004
 	// Jump to page
@@ -1004,14 +1033,16 @@  discard block
 block discarded – undo
1004 1033
 
1005 1034
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1006 1035
 		{
1007
-			if (!empty($row['id_member']))
1008
-				$all_posters[$row['id_msg']] = $row['id_member'];
1036
+			if (!empty($row['id_member'])) {
1037
+							$all_posters[$row['id_msg']] = $row['id_member'];
1038
+			}
1009 1039
 			$messages[] = $row['id_msg'];
1010 1040
 		}
1011 1041
 
1012 1042
 		// Sort the messages into the correct display order
1013
-		if (!$ascending)
1014
-			sort($messages);
1043
+		if (!$ascending) {
1044
+					sort($messages);
1045
+		}
1015 1046
 	}
1016 1047
 
1017 1048
 	// Remember the paging data for next time
@@ -1031,8 +1062,9 @@  discard block
 block discarded – undo
1031 1062
 	if (!$user_info['is_guest'] && !empty($messages))
1032 1063
 	{
1033 1064
 		$mark_at_msg = max($messages);
1034
-		if ($mark_at_msg >= $context['topicinfo']['id_last_msg'])
1035
-			$mark_at_msg = $modSettings['maxMsgID'];
1065
+		if ($mark_at_msg >= $context['topicinfo']['id_last_msg']) {
1066
+					$mark_at_msg = $modSettings['maxMsgID'];
1067
+		}
1036 1068
 		if ($mark_at_msg >= $context['topicinfo']['new_from'])
1037 1069
 		{
1038 1070
 			$smcFunc['db_insert']($context['topicinfo']['new_from'] == 0 ? 'ignore' : 'replace',
@@ -1064,8 +1096,9 @@  discard block
 block discarded – undo
1064 1096
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1065 1097
 		{
1066 1098
 			// Find if this topic is marked for notification...
1067
-			if (!empty($row['id_topic']))
1068
-				$context['is_marked_notify'] = true;
1099
+			if (!empty($row['id_topic'])) {
1100
+							$context['is_marked_notify'] = true;
1101
+			}
1069 1102
 
1070 1103
 			// Only do this once, but mark the notifications as "not sent yet" for next time.
1071 1104
 			if (!empty($row['sent']) && $do_once)
@@ -1087,8 +1120,9 @@  discard block
 block discarded – undo
1087 1120
 		}
1088 1121
 
1089 1122
 		// Have we recently cached the number of new topics in this board, and it's still a lot?
1090
-		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5)
1091
-			$_SESSION['topicseen_cache'][$board]--;
1123
+		if (isset($_REQUEST['topicseen']) && isset($_SESSION['topicseen_cache'][$board]) && $_SESSION['topicseen_cache'][$board] > 5) {
1124
+					$_SESSION['topicseen_cache'][$board]--;
1125
+		}
1092 1126
 		// Mark board as seen if this is the only new topic.
1093 1127
 		elseif (isset($_REQUEST['topicseen']))
1094 1128
 		{
@@ -1112,14 +1146,16 @@  discard block
 block discarded – undo
1112 1146
 			$smcFunc['db_free_result']($request);
1113 1147
 
1114 1148
 			// If there're no real new topics in this board, mark the board as seen.
1115
-			if (empty($numNewTopics))
1116
-				$_REQUEST['boardseen'] = true;
1117
-			else
1118
-				$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1149
+			if (empty($numNewTopics)) {
1150
+							$_REQUEST['boardseen'] = true;
1151
+			} else {
1152
+							$_SESSION['topicseen_cache'][$board] = $numNewTopics;
1153
+			}
1119 1154
 		}
1120 1155
 		// Probably one less topic - maybe not, but even if we decrease this too fast it will only make us look more often.
1121
-		elseif (isset($_SESSION['topicseen_cache'][$board]))
1122
-			$_SESSION['topicseen_cache'][$board]--;
1156
+		elseif (isset($_SESSION['topicseen_cache'][$board])) {
1157
+					$_SESSION['topicseen_cache'][$board]--;
1158
+		}
1123 1159
 
1124 1160
 		// Mark board as seen if we came using last post link from BoardIndex. (or other places...)
1125 1161
 		if (isset($_REQUEST['boardseen']))
@@ -1176,23 +1212,26 @@  discard block
 block discarded – undo
1176 1212
 			$temp = array();
1177 1213
 			while ($row = $smcFunc['db_fetch_assoc']($request))
1178 1214
 			{
1179
-				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id']))
1180
-					continue;
1215
+				if (!$row['approved'] && $modSettings['postmod_active'] && !allowedTo('approve_posts') && (!isset($all_posters[$row['id_msg']]) || $all_posters[$row['id_msg']] != $user_info['id'])) {
1216
+									continue;
1217
+				}
1181 1218
 
1182 1219
 				$temp[$row['id_attach']] = $row;
1183 1220
 				$temp[$row['id_attach']]['topic'] = $topic;
1184 1221
 				$temp[$row['id_attach']]['board'] = $board;
1185 1222
 
1186
-				if (!isset($context['loaded_attachments'][$row['id_msg']]))
1187
-					$context['loaded_attachments'][$row['id_msg']] = array();
1223
+				if (!isset($context['loaded_attachments'][$row['id_msg']])) {
1224
+									$context['loaded_attachments'][$row['id_msg']] = array();
1225
+				}
1188 1226
 			}
1189 1227
 			$smcFunc['db_free_result']($request);
1190 1228
 
1191 1229
 			// This is better than sorting it with the query...
1192 1230
 			ksort($temp);
1193 1231
 
1194
-			foreach ($temp as $row)
1195
-				$context['loaded_attachments'][$row['id_msg']][] = $row;
1232
+			foreach ($temp as $row) {
1233
+							$context['loaded_attachments'][$row['id_msg']][] = $row;
1234
+			}
1196 1235
 		}
1197 1236
 
1198 1237
 		$msg_parameters = array(
@@ -1219,21 +1258,23 @@  discard block
 block discarded – undo
1219 1258
 		);
1220 1259
 
1221 1260
 		// And the likes
1222
-		if (!empty($modSettings['enable_likes']))
1223
-			$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1261
+		if (!empty($modSettings['enable_likes'])) {
1262
+					$context['my_likes'] = $context['user']['is_guest'] ? array() : prepareLikesContext($topic);
1263
+		}
1224 1264
 
1225 1265
 		// Go to the last message if the given time is beyond the time of the last message.
1226
-		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies'])
1227
-			$context['start_from'] = $context['topicinfo']['num_replies'];
1266
+		if (isset($context['start_from']) && $context['start_from'] >= $context['topicinfo']['num_replies']) {
1267
+					$context['start_from'] = $context['topicinfo']['num_replies'];
1268
+		}
1228 1269
 
1229 1270
 		// Since the anchor information is needed on the top of the page we load these variables beforehand.
1230 1271
 		$context['first_message'] = isset($messages[$firstIndex]) ? $messages[$firstIndex] : $messages[0];
1231
-		if (empty($options['view_newest_first']))
1232
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1233
-		else
1234
-			$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1235
-	}
1236
-	else
1272
+		if (empty($options['view_newest_first'])) {
1273
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['start_from'];
1274
+		} else {
1275
+					$context['first_new_message'] = isset($context['start_from']) && $_REQUEST['start'] == $context['topicinfo']['num_replies'] - $context['start_from'];
1276
+		}
1277
+	} else
1237 1278
 	{
1238 1279
 		$messages_request = false;
1239 1280
 		$context['first_message'] = 0;
@@ -1268,8 +1309,9 @@  discard block
 block discarded – undo
1268 1309
 		'can_restore_msg' => 'move_any',
1269 1310
 		'can_like' => 'likes_like',
1270 1311
 	);
1271
-	foreach ($common_permissions as $contextual => $perm)
1272
-		$context[$contextual] = allowedTo($perm);
1312
+	foreach ($common_permissions as $contextual => $perm) {
1313
+			$context[$contextual] = allowedTo($perm);
1314
+	}
1273 1315
 
1274 1316
 	// Permissions with _any/_own versions.  $context[YYY] => ZZZ_any/_own.
1275 1317
 	$anyown_permissions = array(
@@ -1282,8 +1324,9 @@  discard block
 block discarded – undo
1282 1324
 		'can_reply_unapproved' => 'post_unapproved_replies',
1283 1325
 		'can_view_warning' => 'profile_warning',
1284 1326
 	);
1285
-	foreach ($anyown_permissions as $contextual => $perm)
1286
-		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1327
+	foreach ($anyown_permissions as $contextual => $perm) {
1328
+			$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
1329
+	}
1287 1330
 
1288 1331
 	if (!$user_info['is_admin'] && $context['can_move'] && !$modSettings['topic_move_any'])
1289 1332
 	{
@@ -1329,8 +1372,9 @@  discard block
 block discarded – undo
1329 1372
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
1330 1373
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
1331 1374
 	$context['drafts_autosave'] = !empty($context['drafts_save']) && !empty($modSettings['drafts_autosave_enabled']);
1332
-	if (!empty($context['drafts_save']))
1333
-		loadLanguage('Drafts');
1375
+	if (!empty($context['drafts_save'])) {
1376
+			loadLanguage('Drafts');
1377
+	}
1334 1378
 
1335 1379
 	// When was the last time this topic was replied to?  Should we warn them about it?
1336 1380
 	if (!empty($modSettings['oldTopicDays']) && ($context['can_reply'] || $context['can_reply_unapproved']) && empty($context['topicinfo']['is_sticky']))
@@ -1391,26 +1435,31 @@  discard block
 block discarded – undo
1391 1435
 	// Message icons - customized icons are off?
1392 1436
 	$context['icons'] = getMessageIcons($board);
1393 1437
 
1394
-	if (!empty($context['icons']))
1395
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1438
+	if (!empty($context['icons'])) {
1439
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1440
+	}
1396 1441
 
1397 1442
 	// Build the normal button array.
1398 1443
 	$context['normal_buttons'] = array();
1399 1444
 
1400
-	if ($context['can_reply'])
1401
-		$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1445
+	if ($context['can_reply']) {
1446
+			$context['normal_buttons']['reply'] = array('text' => 'reply', 'image' => 'reply.png', 'url' => $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';last_msg=' . $context['topic_last_message'], 'active' => true);
1447
+	}
1402 1448
 
1403
-	if ($context['can_add_poll'])
1404
-		$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1449
+	if ($context['can_add_poll']) {
1450
+			$context['normal_buttons']['add_poll'] = array('text' => 'add_poll', 'image' => 'add_poll.png', 'url' => $scripturl . '?action=editpoll;add;topic=' . $context['current_topic'] . '.' . $context['start']);
1451
+	}
1405 1452
 
1406
-	if ($context['can_mark_unread'])
1407
-		$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1453
+	if ($context['can_mark_unread']) {
1454
+			$context['normal_buttons']['mark_unread'] = array('text' => 'mark_unread', 'image' => 'markunread.png', 'url' => $scripturl . '?action=markasread;sa=topic;t=' . $context['mark_unread_time'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1455
+	}
1408 1456
 
1409
-	if ($context['can_print'])
1410
-		$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1457
+	if ($context['can_print']) {
1458
+			$context['normal_buttons']['print'] = array('text' => 'print', 'image' => 'print.png', 'custom' => 'rel="nofollow"', 'url' => $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0');
1459
+	}
1411 1460
 
1412
-	if ($context['can_set_notify'])
1413
-		$context['normal_buttons']['notify'] = array(
1461
+	if ($context['can_set_notify']) {
1462
+			$context['normal_buttons']['notify'] = array(
1414 1463
 			'text' => 'notify_topic_' . $context['topic_notification_mode'],
1415 1464
 			'sub_buttons' => array(
1416 1465
 				array(
@@ -1432,38 +1481,47 @@  discard block
 block discarded – undo
1432 1481
 				),
1433 1482
 			),
1434 1483
 		);
1484
+	}
1435 1485
 
1436 1486
 	// Build the mod button array
1437 1487
 	$context['mod_buttons'] = array();
1438 1488
 
1439
-	if ($context['can_move'])
1440
-		$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1489
+	if ($context['can_move']) {
1490
+			$context['mod_buttons']['move'] = array('text' => 'move_topic', 'image' => 'admin_move.png', 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0');
1491
+	}
1441 1492
 
1442
-	if ($context['can_delete'])
1443
-		$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1493
+	if ($context['can_delete']) {
1494
+			$context['mod_buttons']['delete'] = array('text' => 'remove_topic', 'image' => 'admin_rem.png', 'custom' => 'data-confirm="' . $txt['are_sure_remove_topic'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']);
1495
+	}
1444 1496
 
1445
-	if ($context['can_lock'])
1446
-		$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_locked'] ? 'unlock' : 'lock') . ';' . $context['session_var'] . '=' . $context['session_id']);
1497
+	if ($context['can_lock']) {
1498
+			$context['mod_buttons']['lock'] = array('text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_locked'] ? 'unlock' : 'lock') . ';' . $context['session_var'] . '=' . $context['session_id']);
1499
+	}
1447 1500
 
1448
-	if ($context['can_sticky'])
1449
-		$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_sticky'] ? 'nonsticky' : 'sticky') . ';' . $context['session_var'] . '=' . $context['session_id']);
1501
+	if ($context['can_sticky']) {
1502
+			$context['mod_buttons']['sticky'] = array('text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sa=' . ($context['is_sticky'] ? 'nonsticky' : 'sticky') . ';' . $context['session_var'] . '=' . $context['session_id']);
1503
+	}
1450 1504
 
1451
-	if ($context['can_merge'])
1452
-		$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1505
+	if ($context['can_merge']) {
1506
+			$context['mod_buttons']['merge'] = array('text' => 'merge', 'image' => 'merge.png', 'url' => $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic']);
1507
+	}
1453 1508
 
1454
-	if ($context['calendar_post'])
1455
-		$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1509
+	if ($context['calendar_post']) {
1510
+			$context['mod_buttons']['calendar'] = array('text' => 'calendar_link', 'image' => 'linktocal.png', 'url' => $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0');
1511
+	}
1456 1512
 
1457 1513
 	// Restore topic. eh?  No monkey business.
1458
-	if ($context['can_restore_topic'])
1459
-		$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1514
+	if ($context['can_restore_topic']) {
1515
+			$context['mod_buttons']['restore_topic'] = array('text' => 'restore_topic', 'image' => '', 'url' => $scripturl . '?action=restoretopic;topics=' . $context['current_topic'] . ';' . $context['session_var'] . '=' . $context['session_id']);
1516
+	}
1460 1517
 
1461 1518
 	// Show a message in case a recently posted message became unapproved.
1462 1519
 	$context['becomesUnapproved'] = !empty($_SESSION['becomesUnapproved']) ? true : false;
1463 1520
 
1464 1521
 	// Don't want to show this forever...
1465
-	if ($context['becomesUnapproved'])
1466
-		unset($_SESSION['becomesUnapproved']);
1522
+	if ($context['becomesUnapproved']) {
1523
+			unset($_SESSION['becomesUnapproved']);
1524
+	}
1467 1525
 
1468 1526
 	// Allow adding new mod buttons easily.
1469 1527
 	// Note: $context['normal_buttons'] and $context['mod_buttons'] are added for backward compatibility with 2.0, but are deprecated and should not be used
@@ -1472,12 +1530,14 @@  discard block
 block discarded – undo
1472 1530
 	call_integration_hook('integrate_mod_buttons', array(&$context['mod_buttons']));
1473 1531
 
1474 1532
 	// Load the drafts js file
1475
-	if ($context['drafts_autosave'])
1476
-		loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts');
1533
+	if ($context['drafts_autosave']) {
1534
+			loadJavaScriptFile('drafts.js', array('defer' => false, 'minimize' => true), 'smf_drafts');
1535
+	}
1477 1536
 
1478 1537
 	// Spellcheck
1479
-	if ($context['show_spellchecking'])
1480
-		loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
1538
+	if ($context['show_spellchecking']) {
1539
+			loadJavaScriptFile('spellcheck.js', array('defer' => false, 'minimize' => true), 'smf_spellcheck');
1540
+	}
1481 1541
 
1482 1542
 	// topic.js
1483 1543
 	loadJavaScriptFile('topic.js', array('defer' => false, 'minimize' => true), 'smf_topic');
@@ -1511,16 +1571,19 @@  discard block
 block discarded – undo
1511 1571
 	static $counter = null;
1512 1572
 
1513 1573
 	// If the query returned false, bail.
1514
-	if ($messages_request == false)
1515
-		return false;
1574
+	if ($messages_request == false) {
1575
+			return false;
1576
+	}
1516 1577
 
1517 1578
 	// Remember which message this is.  (ie. reply #83)
1518
-	if ($counter === null || $reset)
1519
-		$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1579
+	if ($counter === null || $reset) {
1580
+			$counter = empty($options['view_newest_first']) ? $context['start'] : $context['total_visible_posts'] - $context['start'];
1581
+	}
1520 1582
 
1521 1583
 	// Start from the beginning...
1522
-	if ($reset)
1523
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1584
+	if ($reset) {
1585
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1586
+	}
1524 1587
 
1525 1588
 	// Attempt to get the next message.
1526 1589
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
@@ -1534,19 +1597,21 @@  discard block
 block discarded – undo
1534 1597
 	if (empty($context['icon_sources']))
1535 1598
 	{
1536 1599
 		$context['icon_sources'] = array();
1537
-		foreach ($context['stable_icons'] as $icon)
1538
-			$context['icon_sources'][$icon] = 'images_url';
1600
+		foreach ($context['stable_icons'] as $icon) {
1601
+					$context['icon_sources'][$icon] = 'images_url';
1602
+		}
1539 1603
 	}
1540 1604
 
1541 1605
 	// Message Icon Management... check the images exist.
1542 1606
 	if (empty($modSettings['messageIconChecks_disable']))
1543 1607
 	{
1544 1608
 		// If the current icon isn't known, then we need to do something...
1545
-		if (!isset($context['icon_sources'][$message['icon']]))
1546
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1609
+		if (!isset($context['icon_sources'][$message['icon']])) {
1610
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1611
+		}
1612
+	} elseif (!isset($context['icon_sources'][$message['icon']])) {
1613
+			$context['icon_sources'][$message['icon']] = 'images_url';
1547 1614
 	}
1548
-	elseif (!isset($context['icon_sources'][$message['icon']]))
1549
-		$context['icon_sources'][$message['icon']] = 'images_url';
1550 1615
 
1551 1616
 	// If you're a lazy bum, you probably didn't give a subject...
1552 1617
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1571,8 +1636,7 @@  discard block
 block discarded – undo
1571 1636
 		$memberContext[$message['id_member']]['email'] = $message['poster_email'];
1572 1637
 		$memberContext[$message['id_member']]['show_email'] = allowedTo('moderate_forum');
1573 1638
 		$memberContext[$message['id_member']]['is_guest'] = true;
1574
-	}
1575
-	else
1639
+	} else
1576 1640
 	{
1577 1641
 		// Define this here to make things a bit more readable
1578 1642
 		$can_view_warning = $context['user']['can_mod'] || allowedTo('view_warning_any') || ($message['id_member'] == $user_info['id'] && allowedTo('view_warning_own'));
@@ -1595,8 +1659,9 @@  discard block
 block discarded – undo
1595 1659
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
1596 1660
 
1597 1661
 	// If it's in the recycle bin we need to override whatever icon we did have.
1598
-	if (!empty($board_info['recycle']))
1599
-		$message['icon'] = 'recycled';
1662
+	if (!empty($board_info['recycle'])) {
1663
+			$message['icon'] = 'recycled';
1664
+	}
1600 1665
 
1601 1666
 	require_once($sourcedir . '/Subs-Attachments.php');
1602 1667
 
@@ -1640,32 +1705,36 @@  discard block
 block discarded – undo
1640 1705
 	}
1641 1706
 
1642 1707
 	// Are likes enable?
1643
-	if (!empty($modSettings['enable_likes']))
1644
-		$output['likes'] = array(
1708
+	if (!empty($modSettings['enable_likes'])) {
1709
+			$output['likes'] = array(
1645 1710
 			'count' => $message['likes'],
1646 1711
 			'you' => in_array($message['id_msg'], $context['my_likes']),
1647 1712
 			'can_like' => !$context['user']['is_guest'] && $message['id_member'] != $context['user']['id'] && !empty($context['can_like']),
1648 1713
 		);
1714
+	}
1649 1715
 
1650 1716
 	// Is this user the message author?
1651 1717
 	$output['is_message_author'] = $message['id_member'] == $user_info['id'];
1652
-	if (!empty($output['modified']['name']))
1653
-		$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1718
+	if (!empty($output['modified']['name'])) {
1719
+			$output['modified']['last_edit_text'] = sprintf($txt['last_edit_by'], $output['modified']['time'], $output['modified']['name']);
1720
+	}
1654 1721
 
1655 1722
 	// Did they give a reason for editing?
1656
-	if (!empty($output['modified']['name']) && !empty($output['modified']['reason']))
1657
-		$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1723
+	if (!empty($output['modified']['name']) && !empty($output['modified']['reason'])) {
1724
+			$output['modified']['last_edit_text'] .= '&nbsp;' . sprintf($txt['last_edit_reason'], $output['modified']['reason']);
1725
+	}
1658 1726
 
1659 1727
 	// Any custom profile fields?
1660
-	if (!empty($memberContext[$message['id_member']]['custom_fields']))
1661
-		foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1728
+	if (!empty($memberContext[$message['id_member']]['custom_fields'])) {
1729
+			foreach ($memberContext[$message['id_member']]['custom_fields'] as $custom)
1662 1730
 			$output['custom_fields'][$context['cust_profile_fields_placement'][$custom['placement']]][] = $custom;
1731
+	}
1663 1732
 
1664
-	if (empty($options['view_newest_first']))
1665
-		$counter++;
1666
-
1667
-	else
1668
-		$counter--;
1733
+	if (empty($options['view_newest_first'])) {
1734
+			$counter++;
1735
+	} else {
1736
+			$counter--;
1737
+	}
1669 1738
 
1670 1739
 	call_integration_hook('integrate_prepare_display_context', array(&$output, &$message, $counter));
1671 1740
 
@@ -1691,8 +1760,9 @@  discard block
 block discarded – undo
1691 1760
  */
1692 1761
 function approved_attach_sort($a, $b)
1693 1762
 {
1694
-	if ($a['is_approved'] == $b['is_approved'])
1695
-		return 0;
1763
+	if ($a['is_approved'] == $b['is_approved']) {
1764
+			return 0;
1765
+	}
1696 1766
 
1697 1767
 	return $a['is_approved'] > $b['is_approved'] ? -1 : 1;
1698 1768
 }
@@ -1709,16 +1779,19 @@  discard block
 block discarded – undo
1709 1779
 
1710 1780
 	require_once($sourcedir . '/RemoveTopic.php');
1711 1781
 
1712
-	if (empty($_REQUEST['msgs']))
1713
-		redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1782
+	if (empty($_REQUEST['msgs'])) {
1783
+			redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
1784
+	}
1714 1785
 
1715 1786
 	$messages = array();
1716
-	foreach ($_REQUEST['msgs'] as $dummy)
1717
-		$messages[] = (int) $dummy;
1787
+	foreach ($_REQUEST['msgs'] as $dummy) {
1788
+			$messages[] = (int) $dummy;
1789
+	}
1718 1790
 
1719 1791
 	// We are restoring messages. We handle this in another place.
1720
-	if (isset($_REQUEST['restore_selected']))
1721
-		redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1792
+	if (isset($_REQUEST['restore_selected'])) {
1793
+			redirectexit('action=restoretopic;msgs=' . implode(',', $messages) . ';' . $context['session_var'] . '=' . $context['session_id']);
1794
+	}
1722 1795
 	if (isset($_REQUEST['split_selection']))
1723 1796
 	{
1724 1797
 		$request = $smcFunc['db_query']('', '
@@ -1737,8 +1810,9 @@  discard block
 block discarded – undo
1737 1810
 	}
1738 1811
 
1739 1812
 	// Allowed to delete any message?
1740
-	if (allowedTo('delete_any'))
1741
-		$allowed_all = true;
1813
+	if (allowedTo('delete_any')) {
1814
+			$allowed_all = true;
1815
+	}
1742 1816
 	// Allowed to delete replies to their messages?
1743 1817
 	elseif (allowedTo('delete_replies'))
1744 1818
 	{
@@ -1755,13 +1829,14 @@  discard block
 block discarded – undo
1755 1829
 		$smcFunc['db_free_result']($request);
1756 1830
 
1757 1831
 		$allowed_all = $starter == $user_info['id'];
1832
+	} else {
1833
+			$allowed_all = false;
1758 1834
 	}
1759
-	else
1760
-		$allowed_all = false;
1761 1835
 
1762 1836
 	// Make sure they're allowed to delete their own messages, if not any.
1763
-	if (!$allowed_all)
1764
-		isAllowedTo('delete_own');
1837
+	if (!$allowed_all) {
1838
+			isAllowedTo('delete_own');
1839
+	}
1765 1840
 
1766 1841
 	// Allowed to remove which messages?
1767 1842
 	$request = $smcFunc['db_query']('', '
@@ -1781,8 +1856,9 @@  discard block
 block discarded – undo
1781 1856
 	$messages = array();
1782 1857
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1783 1858
 	{
1784
-		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time())
1785
-			continue;
1859
+		if (!$allowed_all && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + $modSettings['edit_disable_time'] * 60 < time()) {
1860
+					continue;
1861
+		}
1786 1862
 
1787 1863
 		$messages[$row['id_msg']] = array($row['subject'], $row['id_member']);
1788 1864
 	}
@@ -1805,17 +1881,20 @@  discard block
 block discarded – undo
1805 1881
 	foreach ($messages as $message => $info)
1806 1882
 	{
1807 1883
 		// Just skip the first message - if it's not the last.
1808
-		if ($message == $first_message && $message != $last_message)
1809
-			continue;
1884
+		if ($message == $first_message && $message != $last_message) {
1885
+					continue;
1886
+		}
1810 1887
 		// If the first message is going then don't bother going back to the topic as we're effectively deleting it.
1811
-		elseif ($message == $first_message)
1812
-			$topicGone = true;
1888
+		elseif ($message == $first_message) {
1889
+					$topicGone = true;
1890
+		}
1813 1891
 
1814 1892
 		removeMessage($message);
1815 1893
 
1816 1894
 		// Log this moderation action ;).
1817
-		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id']))
1818
-			logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1895
+		if (allowedTo('delete_any') && (!allowedTo('delete_own') || $info[1] != $user_info['id'])) {
1896
+					logAction('delete', array('topic' => $topic, 'subject' => $info[0], 'member' => $info[1], 'board' => $board));
1897
+		}
1819 1898
 	}
1820 1899
 
1821 1900
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
Please login to merge, or discard this patch.
Themes/default/Memberlist.template.php 1 patch
Braces   +30 added lines, -20 removed lines patch added patch discarded remove patch
@@ -27,9 +27,10 @@  discard block
 block discarded – undo
27 27
 			<h3 class="catbg">
28 28
 				<span class="floatleft">', $txt['members_list'], '</span>';
29 29
 
30
-	if (!isset($context['old_search']))
31
-		echo '
30
+	if (!isset($context['old_search'])) {
31
+			echo '
32 32
 				<span class="floatright">', $context['letter_links'], '</span>';
33
+	}
33 34
 	echo '
34 35
 			</h3>
35 36
 		</div>';
@@ -44,20 +45,23 @@  discard block
 block discarded – undo
44 45
 	foreach ($context['columns'] as $key => $column)
45 46
 	{
46 47
 		// @TODO maybe find something nicer?
47
-		if ($key == 'email_address' && !$context['can_send_email'])
48
-			continue;
48
+		if ($key == 'email_address' && !$context['can_send_email']) {
49
+					continue;
50
+		}
49 51
 
50 52
 		// This is a selected column, so underline it or some such.
51
-		if ($column['selected'])
52
-			echo '
53
+		if ($column['selected']) {
54
+					echo '
53 55
 						<th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', ' selected" style="width: auto;"' . (isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '') . '>
54 56
 							<a href="' . $column['href'] . '" rel="nofollow">' . $column['label'] . '</a><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></th>';
57
+		}
55 58
 
56 59
 		// This is just some column... show the link and be done with it.
57
-		else
58
-			echo '
60
+		else {
61
+					echo '
59 62
 						<th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', '"', isset($column['width']) ? ' style="width: ' . $column['width'] . '"' : '', isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '', '>
60 63
 						', $column['link'], '</th>';
64
+		}
61 65
 	}
62 66
 
63 67
 	echo '
@@ -77,9 +81,10 @@  discard block
 block discarded – undo
77 81
 						</td>
78 82
 						<td class="real_name lefttext">', $member['link'], '</td>';
79 83
 
80
-			if (!isset($context['disabled_fields']['website']))
81
-				echo '
84
+			if (!isset($context['disabled_fields']['website'])) {
85
+							echo '
82 86
 						<td class="website_url centertext">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" rel="noopener"><span class="generic_icons www" title="' . $member['website']['title'] . '"></span></a>' : '', '</td>';
87
+			}
83 88
 
84 89
 			// Group and date.
85 90
 			echo '
@@ -91,33 +96,36 @@  discard block
 block discarded – undo
91 96
 				echo '
92 97
 						<td class="post_count centertext">';
93 98
 
94
-				if (!empty($member['post_percent']))
95
-					echo '
99
+				if (!empty($member['post_percent'])) {
100
+									echo '
96 101
 							<div class="generic_bar">
97 102
 								<div class="bar" style="width: ', $member['post_percent'], '%;"></div>
98 103
 								<span>', $member['posts'], '</span>
99 104
 							</div>';
105
+				}
100 106
 
101 107
 				echo '
102 108
 						</td>';
103 109
 			}
104 110
 
105 111
 			// Show custom fields marked to be shown here
106
-			if (!empty($context['custom_profile_fields']['columns']))
107
-				foreach ($context['custom_profile_fields']['columns'] as $key => $column)
112
+			if (!empty($context['custom_profile_fields']['columns'])) {
113
+							foreach ($context['custom_profile_fields']['columns'] as $key => $column)
108 114
 					echo '
109 115
 						<td class="' , $key , ' centertext">', $member['options'][$key], '</td>';
116
+			}
110 117
 
111 118
 			echo '
112 119
 					</tr>';
113 120
 		}
114 121
 	}
115 122
 	// No members?
116
-	else
117
-		echo '
123
+	else {
124
+			echo '
118 125
 					<tr>
119 126
 						<td colspan="', $context['colspan'], '" class="windowbg">', $txt['search_no_results'], '</td>
120 127
 					</tr>';
128
+	}
121 129
 
122 130
 	echo '
123 131
 				</tbody>
@@ -130,11 +138,12 @@  discard block
 block discarded – undo
130 138
 			<div class="pagelinks floatleft">', $context['page_index'], '</div>';
131 139
 
132 140
 	// If it is displaying the result of a search show a "search again" link to edit their criteria.
133
-	if (isset($context['old_search']))
134
-		echo '
141
+	if (isset($context['old_search'])) {
142
+			echo '
135 143
 			<div class="buttonlist floatright">
136 144
 				<a class="button" href="', $scripturl, '?action=mlist;sa=search;search=', $context['old_search_value'], '">', $txt['mlist_search_again'], '</a>
137 145
 			</div>';
146
+	}
138 147
 	echo '
139 148
 		</div>
140 149
 	</div><!-- #memberlist -->';
@@ -174,12 +183,13 @@  discard block
 block discarded – undo
174 183
 					<dd>
175 184
 						<ul>';
176 185
 
177
-	foreach ($context['search_fields'] as $id => $title)
178
-		echo '
186
+	foreach ($context['search_fields'] as $id => $title) {
187
+			echo '
179 188
 							<li>
180 189
 								<input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '"', in_array($id, $context['search_defaults']) ? ' checked' : '', '>
181 190
 								<label for="fields-', $id, '">', $title, '</label>
182 191
 							</li>';
192
+	}
183 193
 
184 194
 	echo '
185 195
 						</ul>
Please login to merge, or discard this patch.
Sources/tasks/CreatePost-Notify.php 1 patch
Braces   +74 added lines, -54 removed lines patch added patch discarded remove patch
@@ -96,8 +96,9 @@  discard block
 block discarded – undo
96 96
 		while ($row = $smcFunc['db_fetch_assoc']($request))
97 97
 		{
98 98
 			$groups = array_merge(array($row['id_group'], $row['id_post_group']), (empty($row['additional_groups']) ? array() : explode(',', $row['additional_groups'])));
99
-			if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0)
100
-				continue;
99
+			if (!in_array(1, $groups) && count(array_intersect($groups, explode(',', $row['member_groups']))) == 0) {
100
+							continue;
101
+			}
101 102
 
102 103
 			$members[] = $row['id_member'];
103 104
 			$watched[$row['id_member']] = $row;
@@ -105,8 +106,9 @@  discard block
 block discarded – undo
105 106
 
106 107
 		$smcFunc['db_free_result']($request);
107 108
 
108
-		if (empty($members))
109
-			return true;
109
+		if (empty($members)) {
110
+					return true;
111
+		}
110 112
 
111 113
 		$members = array_unique($members);
112 114
 		$prefs = getNotifyPrefs($members, '', true);
@@ -122,8 +124,9 @@  discard block
 block discarded – undo
122 124
 		self::handleQuoteNotifications($msgOptions, $posterOptions, $quotedMembers, $prefs, $done_members, $alert_rows);
123 125
 
124 126
 		// Save ourselves a bit of work in the big loop below
125
-		foreach ($done_members as $done_member)
126
-			unset($watched[$done_member]);
127
+		foreach ($done_members as $done_member) {
128
+					unset($watched[$done_member]);
129
+		}
127 130
 
128 131
 		// Handle rest of the notifications for watched topics and boards
129 132
 		foreach ($watched as $member => $data)
@@ -132,26 +135,31 @@  discard block
 block discarded – undo
132 135
 			$notify_types = !empty($prefs[$member]['msg_notify_type']) ? $prefs[$member]['msg_notify_type'] : self::NOTIFY_TYPE_REPLY_AND_MODIFY;
133 136
 
134 137
 			// Don't send a notification if the watching member ignored the member who made the action.
135
-			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list'])))
136
-				continue;
137
-			if (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_REPLY_AND_TOPIC_START_FOLLOWING && $member != $data['id_member_started'])
138
-				continue;
139
-			elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id'])
140
-				continue;
141
-			elseif (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_ONLY_REPLIES)
142
-				continue;
143
-			elseif ($notify_types == self::NOTIFY_TYPE_NOTHING)
144
-				continue;
138
+			if (!empty($data['pm_ignore_list']) && in_array($data['id_member_updated'], explode(',', $data['pm_ignore_list']))) {
139
+							continue;
140
+			}
141
+			if (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_REPLY_AND_TOPIC_START_FOLLOWING && $member != $data['id_member_started']) {
142
+							continue;
143
+			} elseif (in_array($type, array('reply', 'topic')) && $member == $posterOptions['id']) {
144
+							continue;
145
+			} elseif (!in_array($type, array('reply', 'topic')) && $notify_types == self::NOTIFY_TYPE_ONLY_REPLIES) {
146
+							continue;
147
+			} elseif ($notify_types == self::NOTIFY_TYPE_NOTHING) {
148
+							continue;
149
+			}
145 150
 
146 151
 			// Don't send a notification if they don't want any...
147
-			if (in_array($frequency, array(self::FREQUENCY_NOTHING, self::FREQUENCY_DAILY_DIGEST, self::FREQUENCY_WEEKLY_DIGEST)))
148
-				continue;
152
+			if (in_array($frequency, array(self::FREQUENCY_NOTHING, self::FREQUENCY_DAILY_DIGEST, self::FREQUENCY_WEEKLY_DIGEST))) {
153
+							continue;
154
+			}
149 155
 			// ... or if we already sent one and they don't want more...
150
-			elseif ($frequency === self::FREQUENCY_FIRST_UNREAD_MSG && $data['sent'])
151
-				continue;
156
+			elseif ($frequency === self::FREQUENCY_FIRST_UNREAD_MSG && $data['sent']) {
157
+							continue;
158
+			}
152 159
 			// ... or if they aren't on the bouncer's list.
153
-			elseif (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only']))
154
-				continue;
160
+			elseif (!empty($this->_details['members_only']) && !in_array($member, $this->_details['members_only'])) {
161
+							continue;
162
+			}
155 163
 
156 164
 			// Watched topic?
157 165
 			if (!empty($data['id_topic']) && $type != 'topic' && !empty($prefs[$member]))
@@ -161,10 +169,12 @@  discard block
 block discarded – undo
161 169
 
162 170
 				if ($type == 'reply')
163 171
 				{
164
-					if (!empty($prefs[$member]['msg_receive_body']))
165
-						$message_type .= '_body';
166
-					if (!empty($frequency))
167
-						$message_type .= '_once';
172
+					if (!empty($prefs[$member]['msg_receive_body'])) {
173
+											$message_type .= '_body';
174
+					}
175
+					if (!empty($frequency)) {
176
+											$message_type .= '_once';
177
+					}
168 178
 				}
169 179
 
170 180
 				$content_type = 'topic';
@@ -177,12 +187,14 @@  discard block
 block discarded – undo
177 187
 				$content_type = 'board';
178 188
 
179 189
 				$message_type = !empty($frequency) ? 'notify_boards_once' : 'notify_boards';
180
-				if (!empty($prefs[$member]['msg_receive_body']))
181
-					$message_type .= '_body';
190
+				if (!empty($prefs[$member]['msg_receive_body'])) {
191
+									$message_type .= '_body';
192
+				}
182 193
 			}
183 194
 			// If neither of the above, this might be a redundent row due to the OR clause in our SQL query, skip
184
-			else
185
-				continue;
195
+			else {
196
+							continue;
197
+			}
186 198
 
187 199
 			// Bitwise check: Receiving a email notification?
188 200
 			if ($pref & self::RECEIVE_NOTIFY_EMAIL)
@@ -199,8 +211,9 @@  discard block
 block discarded – undo
199 211
 				$mail_result = sendmail($data['email_address'], $emaildata['subject'], $emaildata['body'], null, 'm' . $topicOptions['id'], $emaildata['is_html']);
200 212
 
201 213
 				// We failed, don't trigger a alert as we don't have a way to attempt to resend just the email currently.
202
-				if ($mail_result === false)
203
-					continue;
214
+				if ($mail_result === false) {
215
+									continue;
216
+				}
204 217
 			}
205 218
 
206 219
 			// Bitwise check: Receiving a alert?
@@ -251,14 +264,15 @@  discard block
 block discarded – undo
251 264
 		);
252 265
 
253 266
 		// Insert the alerts if any
254
-		if (!empty($alert_rows))
255
-			$smcFunc['db_insert']('',
267
+		if (!empty($alert_rows)) {
268
+					$smcFunc['db_insert']('',
256 269
 				'{db_prefix}user_alerts',
257 270
 				array('alert_time' => 'int', 'id_member' => 'int', 'id_member_started' => 'int', 'member_name' => 'string',
258 271
 					'content_type' => 'string', 'content_id' => 'int', 'content_action' => 'string', 'is_read' => 'int', 'extra' => 'string'),
259 272
 				$alert_rows,
260 273
 				array()
261 274
 			);
275
+		}
262 276
 
263 277
 		return true;
264 278
 	}
@@ -269,8 +283,9 @@  discard block
 block discarded – undo
269 283
 
270 284
 		foreach ($quotedMembers as $id => $member)
271 285
 		{
272
-			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote']))
273
-				continue;
286
+			if (!isset($prefs[$id]) || $id == $posterOptions['id'] || empty($prefs[$id]['msg_quote'])) {
287
+							continue;
288
+			}
274 289
 
275 290
 			$done_members[] = $id;
276 291
 
@@ -324,32 +339,35 @@  discard block
 block discarded – undo
324 339
 		{
325 340
 			if (preg_match('/\[quote(.*)?\]/i', $block, $matches))
326 341
 			{
327
-				if ($quote_level == 0)
328
-					$message .= '[quote' . $matches[1] . ']';
342
+				if ($quote_level == 0) {
343
+									$message .= '[quote' . $matches[1] . ']';
344
+				}
329 345
 				$quote_level++;
330
-			}
331
-			elseif (preg_match('/\[\/quote\]/i', $block))
346
+			} elseif (preg_match('/\[\/quote\]/i', $block))
332 347
 			{
333
-				if ($quote_level <= 1)
334
-					$message .= '[/quote]';
348
+				if ($quote_level <= 1) {
349
+									$message .= '[/quote]';
350
+				}
335 351
 				if ($quote_level >= 1)
336 352
 				{
337 353
 					$quote_level--;
338 354
 					$message .= "\n";
339 355
 				}
356
+			} elseif ($quote_level <= 1) {
357
+							$message .= $block;
340 358
 			}
341
-			elseif ($quote_level <= 1)
342
-				$message .= $block;
343 359
 		}
344 360
 
345 361
 		preg_match_all('/\[quote.*?link=msg=([0-9]+).*?\]/i', $message, $matches);
346 362
 
347 363
 		$id_msgs = $matches[1];
348
-		foreach ($id_msgs as $k => $id_msg)
349
-			$id_msgs[$k] = (int) $id_msg;
364
+		foreach ($id_msgs as $k => $id_msg) {
365
+					$id_msgs[$k] = (int) $id_msg;
366
+		}
350 367
 
351
-		if (empty($id_msgs))
352
-			return array();
368
+		if (empty($id_msgs)) {
369
+					return array();
370
+		}
353 371
 
354 372
 		// Get the messages
355 373
 		$request = $smcFunc['db_query']('', '
@@ -367,8 +385,9 @@  discard block
 block discarded – undo
367 385
 		$members = array();
368 386
 		while ($row = $smcFunc['db_fetch_assoc']($request))
369 387
 		{
370
-			if ($posterOptions['id'] == $row['id_member'])
371
-				continue;
388
+			if ($posterOptions['id'] == $row['id_member']) {
389
+							continue;
390
+			}
372 391
 
373 392
 			$members[$row['id_member']] = $row;
374 393
 		}
@@ -382,10 +401,11 @@  discard block
 block discarded – undo
382 401
 
383 402
 		foreach ($members as $id => $member)
384 403
 		{
385
-			if (!empty($prefs[$id]['msg_mention']))
386
-				$done_members[] = $id;
387
-			else
388
-				continue;
404
+			if (!empty($prefs[$id]['msg_mention'])) {
405
+							$done_members[] = $id;
406
+			} else {
407
+							continue;
408
+			}
389 409
 
390 410
 			// Alerts' emails are always instant
391 411
 			if ($prefs[$id]['msg_mention'] & self::RECEIVE_NOTIFY_EMAIL)
Please login to merge, or discard this patch.
Sources/Load.php 1 patch
Braces   +792 added lines, -597 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We explicitly do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -410,9 +427,9 @@  discard block
 block discarded – undo
410 427
 				break;
411 428
 			}
412 429
 		}
430
+	} else {
431
+			$id_member = 0;
413 432
 	}
414
-	else
415
-		$id_member = 0;
416 433
 
417 434
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
418 435
 	{
@@ -420,8 +437,9 @@  discard block
 block discarded – undo
420 437
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
421 438
 
422 439
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
423
-		if (empty($cookie_data))
424
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
440
+		if (empty($cookie_data)) {
441
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
442
+		}
425 443
 
426 444
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
427 445
 
@@ -429,16 +447,17 @@  discard block
 block discarded – undo
429 447
 
430 448
 		// Make sure the cookie is set to the correct domain and path
431 449
 		require_once($sourcedir . '/Subs-Auth.php');
432
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
433
-			setLoginCookie((int) $login_span - time(), $id_member);
434
-	}
435
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
450
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
451
+					setLoginCookie((int) $login_span - time(), $id_member);
452
+		}
453
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
436 454
 	{
437 455
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
438 456
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
439 457
 
440
-		if (empty($cookie_data))
441
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
458
+		if (empty($cookie_data)) {
459
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
460
+		}
442 461
 
443 462
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
444 463
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -463,30 +482,34 @@  discard block
 block discarded – undo
463 482
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
464 483
 			$smcFunc['db_free_result']($request);
465 484
 
466
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
467
-				$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
485
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
486
+							$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
487
+			}
468 488
 
469
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
470
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
489
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
490
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
491
+			}
471 492
 		}
472 493
 
473 494
 		// Did we find 'im?  If not, junk it.
474 495
 		if (!empty($user_settings))
475 496
 		{
476 497
 			// As much as the password should be right, we can assume the integration set things up.
477
-			if (!empty($already_verified) && $already_verified === true)
478
-				$check = true;
498
+			if (!empty($already_verified) && $already_verified === true) {
499
+							$check = true;
500
+			}
479 501
 			// SHA-512 hash should be 128 characters long.
480
-			elseif (strlen($password) == 128)
481
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
482
-			else
483
-				$check = false;
502
+			elseif (strlen($password) == 128) {
503
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
504
+			} else {
505
+							$check = false;
506
+			}
484 507
 
485 508
 			// Wrong password or not activated - either way, you're going nowhere.
486 509
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
510
+		} else {
511
+					$id_member = 0;
487 512
 		}
488
-		else
489
-			$id_member = 0;
490 513
 
491 514
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
492 515
 		if (!$id_member)
@@ -515,8 +538,9 @@  discard block
 block discarded – undo
515 538
 
516 539
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
517 540
 
518
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
519
-						$tfasecret = null;
541
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
542
+											$tfasecret = null;
543
+					}
520 544
 				}
521 545
 
522 546
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -538,10 +562,12 @@  discard block
 block discarded – undo
538 562
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
539 563
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
540 564
 		{
541
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
565
+			if ($modSettings['tfa_mode'] == 2) {
566
+				//only do this if we are just forcing SOME membergroups
542 567
 			{
543 568
 				//Build an array of ALL user membergroups.
544 569
 				$full_groups = array($user_settings['id_group']);
570
+			}
545 571
 				if (!empty($user_settings['additional_groups']))
546 572
 				{
547 573
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -561,15 +587,17 @@  discard block
 block discarded – undo
561 587
 				);
562 588
 				$row = $smcFunc['db_fetch_assoc']($request);
563 589
 				$smcFunc['db_free_result']($request);
590
+			} else {
591
+							$row['total'] = 1;
564 592
 			}
565
-			else
566
-				$row['total'] = 1; //simplifies logics in the next "if"
593
+			//simplifies logics in the next "if"
567 594
 
568 595
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
569 596
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
570 597
 
571
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
572
-				redirectexit('action=profile;area=tfasetup;forced');
598
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
599
+							redirectexit('action=profile;area=tfasetup;forced');
600
+			}
573 601
 		}
574 602
 	}
575 603
 
@@ -606,29 +634,32 @@  discard block
 block discarded – undo
606 634
 				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']));
607 635
 				$user_settings['last_login'] = time();
608 636
 
609
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
610
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
637
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
638
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
639
+				}
611 640
 
612
-				if (!empty($modSettings['cache_enable']))
613
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
641
+				if (!empty($modSettings['cache_enable'])) {
642
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
643
+				}
614 644
 			}
645
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
646
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
615 647
 		}
616
-		elseif (empty($_SESSION['id_msg_last_visit']))
617
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
618 648
 
619 649
 		$username = $user_settings['member_name'];
620 650
 
621
-		if (empty($user_settings['additional_groups']))
622
-			$user_info = array(
651
+		if (empty($user_settings['additional_groups'])) {
652
+					$user_info = array(
623 653
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
624 654
 			);
625
-		else
626
-			$user_info = array(
655
+		} else {
656
+					$user_info = array(
627 657
 				'groups' => array_merge(
628 658
 					array($user_settings['id_group'], $user_settings['id_post_group']),
629 659
 					explode(',', $user_settings['additional_groups'])
630 660
 				)
631 661
 			);
662
+		}
632 663
 
633 664
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
634 665
 		$user_info['groups'] = array_map('intval', $user_info['groups']);
@@ -645,8 +676,7 @@  discard block
 block discarded – undo
645 676
 			$time_system = new DateTime('now', $tz_system);
646 677
 			$time_user = new DateTime('now', $tz_user);
647 678
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
648
-		}
649
-		else
679
+		} else
650 680
 		{
651 681
 			// !!! Compatibility.
652 682
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -660,8 +690,9 @@  discard block
 block discarded – undo
660 690
 		$user_info = array('groups' => array(-1));
661 691
 		$user_settings = array();
662 692
 
663
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
664
-			$_COOKIE[$cookiename] = '';
693
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
694
+					$_COOKIE[$cookiename] = '';
695
+		}
665 696
 
666 697
 		// Expire the 2FA cookie
667 698
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -678,19 +709,20 @@  discard block
 block discarded – undo
678 709
 		}
679 710
 
680 711
 		// Create a login token if it doesn't exist yet.
681
-		if (!isset($_SESSION['token']['post-login']))
682
-			createToken('login');
683
-		else
684
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
712
+		if (!isset($_SESSION['token']['post-login'])) {
713
+					createToken('login');
714
+		} else {
715
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
716
+		}
685 717
 
686 718
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
687 719
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
688 720
 		{
689 721
 			require_once($sourcedir . '/ManageSearchEngines.php');
690 722
 			$user_info['possibly_robot'] = SpiderCheck();
723
+		} elseif (!empty($modSettings['spider_mode'])) {
724
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
691 725
 		}
692
-		elseif (!empty($modSettings['spider_mode']))
693
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
694 726
 		// If we haven't turned on proper spider hunts then have a guess!
695 727
 		else
696 728
 		{
@@ -738,8 +770,9 @@  discard block
 block discarded – undo
738 770
 	$user_info['groups'] = array_unique($user_info['groups']);
739 771
 
740 772
 	// 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.
741
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
742
-		unset($user_info['ignoreboards'][$tmp]);
773
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
774
+			unset($user_info['ignoreboards'][$tmp]);
775
+	}
743 776
 
744 777
 	// Allow the user to change their language.
745 778
 	if (!empty($modSettings['userLanguage']))
@@ -752,13 +785,14 @@  discard block
 block discarded – undo
752 785
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
753 786
 
754 787
 			// Make it permanent for members.
755
-			if (!empty($user_info['id']))
756
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
757
-			else
758
-				$_SESSION['language'] = $user_info['language'];
788
+			if (!empty($user_info['id'])) {
789
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
790
+			} else {
791
+							$_SESSION['language'] = $user_info['language'];
792
+			}
793
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
794
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
759 795
 		}
760
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
761
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
762 796
 	}
763 797
 
764 798
 	$temp = build_query_board($user_info['id']);
@@ -821,9 +855,9 @@  discard block
 block discarded – undo
821 855
 		}
822 856
 
823 857
 		// Remember redirection is the key to avoiding fallout from your bosses.
824
-		if (!empty($topic))
825
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
826
-		else
858
+		if (!empty($topic)) {
859
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
860
+		} else
827 861
 		{
828 862
 			loadPermissions();
829 863
 			loadTheme();
@@ -841,10 +875,11 @@  discard block
 block discarded – undo
841 875
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
842 876
 	{
843 877
 		// @todo SLOW?
844
-		if (!empty($topic))
845
-			$temp = cache_get_data('topic_board-' . $topic, 120);
846
-		else
847
-			$temp = cache_get_data('board-' . $board, 120);
878
+		if (!empty($topic)) {
879
+					$temp = cache_get_data('topic_board-' . $topic, 120);
880
+		} else {
881
+					$temp = cache_get_data('board-' . $board, 120);
882
+		}
848 883
 
849 884
 		if (!empty($temp))
850 885
 		{
@@ -882,8 +917,9 @@  discard block
 block discarded – undo
882 917
 			$row = $smcFunc['db_fetch_assoc']($request);
883 918
 
884 919
 			// Set the current board.
885
-			if (!empty($row['id_board']))
886
-				$board = $row['id_board'];
920
+			if (!empty($row['id_board'])) {
921
+							$board = $row['id_board'];
922
+			}
887 923
 
888 924
 			// Basic operating information. (globals... :/)
889 925
 			$board_info = array(
@@ -919,21 +955,23 @@  discard block
 block discarded – undo
919 955
 
920 956
 			do
921 957
 			{
922
-				if (!empty($row['id_moderator']))
923
-					$board_info['moderators'][$row['id_moderator']] = array(
958
+				if (!empty($row['id_moderator'])) {
959
+									$board_info['moderators'][$row['id_moderator']] = array(
924 960
 						'id' => $row['id_moderator'],
925 961
 						'name' => $row['real_name'],
926 962
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
927 963
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
928 964
 					);
965
+				}
929 966
 
930
-				if (!empty($row['id_moderator_group']))
931
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
967
+				if (!empty($row['id_moderator_group'])) {
968
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
932 969
 						'id' => $row['id_moderator_group'],
933 970
 						'name' => $row['group_name'],
934 971
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
935 972
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
936 973
 					);
974
+				}
937 975
 			}
938 976
 			while ($row = $smcFunc['db_fetch_assoc']($request));
939 977
 
@@ -965,12 +1003,12 @@  discard block
 block discarded – undo
965 1003
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
966 1004
 			{
967 1005
 				// @todo SLOW?
968
-				if (!empty($topic))
969
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1006
+				if (!empty($topic)) {
1007
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1008
+				}
970 1009
 				cache_put_data('board-' . $board, $board_info, 120);
971 1010
 			}
972
-		}
973
-		else
1011
+		} else
974 1012
 		{
975 1013
 			// Otherwise the topic is invalid, there are no moderators, etc.
976 1014
 			$board_info = array(
@@ -984,8 +1022,9 @@  discard block
 block discarded – undo
984 1022
 		$smcFunc['db_free_result']($request);
985 1023
 	}
986 1024
 
987
-	if (!empty($topic))
988
-		$_GET['board'] = (int) $board;
1025
+	if (!empty($topic)) {
1026
+			$_GET['board'] = (int) $board;
1027
+	}
989 1028
 
990 1029
 	if (!empty($board))
991 1030
 	{
@@ -995,10 +1034,12 @@  discard block
 block discarded – undo
995 1034
 		// Now check if the user is a moderator.
996 1035
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
997 1036
 
998
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
999
-			$board_info['error'] = 'access';
1000
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
1001
-			$board_info['error'] = 'access';
1037
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1038
+					$board_info['error'] = 'access';
1039
+		}
1040
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1041
+					$board_info['error'] = 'access';
1042
+		}
1002 1043
 
1003 1044
 		// Build up the linktree.
1004 1045
 		$context['linktree'] = array_merge(
@@ -1021,8 +1062,9 @@  discard block
 block discarded – undo
1021 1062
 	$context['current_board'] = $board;
1022 1063
 
1023 1064
 	// No posting in redirection boards!
1024
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1025
-		$board_info['error'] == 'post_in_redirect';
1065
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1066
+			$board_info['error'] == 'post_in_redirect';
1067
+	}
1026 1068
 
1027 1069
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1028 1070
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1048,24 +1090,23 @@  discard block
 block discarded – undo
1048 1090
 			ob_end_clean();
1049 1091
 			send_http_status(403);
1050 1092
 			die;
1051
-		}
1052
-		elseif ($board_info['error'] == 'post_in_redirect')
1093
+		} elseif ($board_info['error'] == 'post_in_redirect')
1053 1094
 		{
1054 1095
 			// Slightly different error message here...
1055 1096
 			fatal_lang_error('cannot_post_redirect', false);
1056
-		}
1057
-		elseif ($user_info['is_guest'])
1097
+		} elseif ($user_info['is_guest'])
1058 1098
 		{
1059 1099
 			loadLanguage('Errors');
1060 1100
 			is_not_guest($txt['topic_gone']);
1101
+		} else {
1102
+					fatal_lang_error('topic_gone', false);
1061 1103
 		}
1062
-		else
1063
-			fatal_lang_error('topic_gone', false);
1064 1104
 	}
1065 1105
 
1066
-	if ($user_info['is_mod'])
1067
-		$user_info['groups'][] = 3;
1068
-}
1106
+	if ($user_info['is_mod']) {
1107
+			$user_info['groups'][] = 3;
1108
+	}
1109
+	}
1069 1110
 
1070 1111
 /**
1071 1112
  * Load this user's permissions.
@@ -1086,8 +1127,9 @@  discard block
 block discarded – undo
1086 1127
 		asort($cache_groups);
1087 1128
 		$cache_groups = implode(',', $cache_groups);
1088 1129
 		// If it's a spider then cache it different.
1089
-		if ($user_info['possibly_robot'])
1090
-			$cache_groups .= '-spider';
1130
+		if ($user_info['possibly_robot']) {
1131
+					$cache_groups .= '-spider';
1132
+		}
1091 1133
 
1092 1134
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1093 1135
 		{
@@ -1095,9 +1137,9 @@  discard block
 block discarded – undo
1095 1137
 			banPermissions();
1096 1138
 
1097 1139
 			return;
1140
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1141
+					list ($user_info['permissions'], $removals) = $temp;
1098 1142
 		}
1099
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1100
-			list ($user_info['permissions'], $removals) = $temp;
1101 1143
 	}
1102 1144
 
1103 1145
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1119,23 +1161,26 @@  discard block
 block discarded – undo
1119 1161
 		$removals = array();
1120 1162
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1121 1163
 		{
1122
-			if (empty($row['add_deny']))
1123
-				$removals[] = $row['permission'];
1124
-			else
1125
-				$user_info['permissions'][] = $row['permission'];
1164
+			if (empty($row['add_deny'])) {
1165
+							$removals[] = $row['permission'];
1166
+			} else {
1167
+							$user_info['permissions'][] = $row['permission'];
1168
+			}
1126 1169
 		}
1127 1170
 		$smcFunc['db_free_result']($request);
1128 1171
 
1129
-		if (isset($cache_groups))
1130
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1172
+		if (isset($cache_groups)) {
1173
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1174
+		}
1131 1175
 	}
1132 1176
 
1133 1177
 	// Get the board permissions.
1134 1178
 	if (!empty($board))
1135 1179
 	{
1136 1180
 		// Make sure the board (if any) has been loaded by loadBoard().
1137
-		if (!isset($board_info['profile']))
1138
-			fatal_lang_error('no_board');
1181
+		if (!isset($board_info['profile'])) {
1182
+					fatal_lang_error('no_board');
1183
+		}
1139 1184
 
1140 1185
 		$request = $smcFunc['db_query']('', '
1141 1186
 			SELECT permission, add_deny
@@ -1151,20 +1196,23 @@  discard block
 block discarded – undo
1151 1196
 		);
1152 1197
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1153 1198
 		{
1154
-			if (empty($row['add_deny']))
1155
-				$removals[] = $row['permission'];
1156
-			else
1157
-				$user_info['permissions'][] = $row['permission'];
1199
+			if (empty($row['add_deny'])) {
1200
+							$removals[] = $row['permission'];
1201
+			} else {
1202
+							$user_info['permissions'][] = $row['permission'];
1203
+			}
1158 1204
 		}
1159 1205
 		$smcFunc['db_free_result']($request);
1160 1206
 	}
1161 1207
 
1162 1208
 	// Remove all the permissions they shouldn't have ;).
1163
-	if (!empty($modSettings['permission_enable_deny']))
1164
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1209
+	if (!empty($modSettings['permission_enable_deny'])) {
1210
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1211
+	}
1165 1212
 
1166
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1167
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1213
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1214
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1215
+	}
1168 1216
 
1169 1217
 	// Banned?  Watch, don't touch..
1170 1218
 	banPermissions();
@@ -1176,17 +1224,18 @@  discard block
 block discarded – undo
1176 1224
 		{
1177 1225
 			require_once($sourcedir . '/Subs-Auth.php');
1178 1226
 			rebuildModCache();
1227
+		} else {
1228
+					$user_info['mod_cache'] = $_SESSION['mc'];
1179 1229
 		}
1180
-		else
1181
-			$user_info['mod_cache'] = $_SESSION['mc'];
1182 1230
 
1183 1231
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1184 1232
 		// For example this drastically simplifies certain changes to the profile area.
1185 1233
 		$user_info['permissions'][] = 'is_not_guest';
1186 1234
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1187 1235
 		$user_info['permissions'][] = 'profile_view_own';
1188
-		if (in_array('profile_view', $user_info['permissions']))
1189
-			$user_info['permissions'][] = 'profile_view_any';
1236
+		if (in_array('profile_view', $user_info['permissions'])) {
1237
+					$user_info['permissions'][] = 'profile_view_any';
1238
+		}
1190 1239
 	}
1191 1240
 }
1192 1241
 
@@ -1204,8 +1253,9 @@  discard block
 block discarded – undo
1204 1253
 	global $image_proxy_enabled, $user_info;
1205 1254
 
1206 1255
 	// Can't just look for no users :P.
1207
-	if (empty($users))
1208
-		return array();
1256
+	if (empty($users)) {
1257
+			return array();
1258
+	}
1209 1259
 
1210 1260
 	// Pass the set value
1211 1261
 	$context['loadMemberContext_set'] = $set;
@@ -1220,8 +1270,9 @@  discard block
 block discarded – undo
1220 1270
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1221 1271
 		{
1222 1272
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1223
-			if ($data == null)
1224
-				continue;
1273
+			if ($data == null) {
1274
+							continue;
1275
+			}
1225 1276
 
1226 1277
 			$loaded_ids[] = $data['id_member'];
1227 1278
 			$user_profile[$data['id_member']] = $data;
@@ -1288,16 +1339,19 @@  discard block
 block discarded – undo
1288 1339
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1289 1340
 
1290 1341
 			// Take care of proxying avatar if required, do this here for maximum reach
1291
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1292
-				$row['avatar'] = get_proxied_url($row['avatar']);
1342
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1343
+							$row['avatar'] = get_proxied_url($row['avatar']);
1344
+			}
1293 1345
 
1294 1346
 			// Keep track of the member's normal member group
1295 1347
 			$row['primary_group'] = !empty($row['member_group']) ? $row['member_group'] : '';
1296 1348
 
1297
-			if (isset($row['member_ip']))
1298
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1299
-			if (isset($row['member_ip2']))
1300
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1349
+			if (isset($row['member_ip'])) {
1350
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1351
+			}
1352
+			if (isset($row['member_ip2'])) {
1353
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1354
+			}
1301 1355
 			$row['id_member'] = (int) $row['id_member'];
1302 1356
 			$new_loaded_ids[] = $row['id_member'];
1303 1357
 			$loaded_ids[] = $row['id_member'];
@@ -1317,8 +1371,9 @@  discard block
 block discarded – undo
1317 1371
 				'loaded_ids' => $new_loaded_ids,
1318 1372
 			)
1319 1373
 		);
1320
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1321
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1374
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1375
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1376
+		}
1322 1377
 		$smcFunc['db_free_result']($request);
1323 1378
 	}
1324 1379
 
@@ -1329,10 +1384,11 @@  discard block
 block discarded – undo
1329 1384
 	{
1330 1385
 		foreach ($loaded_ids as $a_member)
1331 1386
 		{
1332
-			if (!empty($user_profile[$a_member]['additional_groups']))
1333
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1334
-			else
1335
-				$groups = array($user_profile[$a_member]['id_group']);
1387
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1388
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1389
+			} else {
1390
+							$groups = array($user_profile[$a_member]['id_group']);
1391
+			}
1336 1392
 
1337 1393
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1338 1394
 
@@ -1345,8 +1401,9 @@  discard block
 block discarded – undo
1345 1401
 
1346 1402
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1347 1403
 	{
1348
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1349
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1404
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1405
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1406
+		}
1350 1407
 	}
1351 1408
 
1352 1409
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1372,14 +1429,17 @@  discard block
 block discarded – undo
1372 1429
 		foreach ($temp_mods as $id)
1373 1430
 		{
1374 1431
 			// By popular demand, don't show admins or global moderators as moderators.
1375
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1376
-				$user_profile[$id]['member_group'] = $row['member_group'];
1432
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1433
+							$user_profile[$id]['member_group'] = $row['member_group'];
1434
+			}
1377 1435
 
1378 1436
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1379
-			if (!empty($row['icons']))
1380
-				$user_profile[$id]['icons'] = $row['icons'];
1381
-			if (!empty($row['member_group_color']))
1382
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1437
+			if (!empty($row['icons'])) {
1438
+							$user_profile[$id]['icons'] = $row['icons'];
1439
+			}
1440
+			if (!empty($row['member_group_color'])) {
1441
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1442
+			}
1383 1443
 		}
1384 1444
 	}
1385 1445
 
@@ -1401,12 +1461,14 @@  discard block
 block discarded – undo
1401 1461
 	static $loadedLanguages = array();
1402 1462
 
1403 1463
 	// If this person's data is already loaded, skip it.
1404
-	if (isset($dataLoaded[$user]))
1405
-		return true;
1464
+	if (isset($dataLoaded[$user])) {
1465
+			return true;
1466
+	}
1406 1467
 
1407 1468
 	// We can't load guests or members not loaded by loadMemberData()!
1408
-	if ($user == 0)
1409
-		return false;
1469
+	if ($user == 0) {
1470
+			return false;
1471
+	}
1410 1472
 	if (!isset($user_profile[$user]))
1411 1473
 	{
1412 1474
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1432,12 +1494,16 @@  discard block
 block discarded – undo
1432 1494
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1433 1495
 
1434 1496
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1435
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1497
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1498
+		//icon is set and exists
1436 1499
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1437
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1500
+	} elseif (isset($profile['icons'][1])) {
1501
+		//icon is set and doesn't exist, fallback to default
1438 1502
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1439
-	else //not set, bye bye
1503
+	} else {
1504
+		//not set, bye bye
1440 1505
 		$group_icon_url = '';
1506
+	}
1441 1507
 
1442 1508
 	// These minimal values are always loaded
1443 1509
 	$memberContext[$user] = array(
@@ -1456,8 +1522,9 @@  discard block
 block discarded – undo
1456 1522
 	if ($context['loadMemberContext_set'] != 'minimal')
1457 1523
 	{
1458 1524
 		// Go the extra mile and load the user's native language name.
1459
-		if (empty($loadedLanguages))
1460
-			$loadedLanguages = getLanguages();
1525
+		if (empty($loadedLanguages)) {
1526
+					$loadedLanguages = getLanguages();
1527
+		}
1461 1528
 
1462 1529
 		$memberContext[$user] += array(
1463 1530
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1512,31 +1579,33 @@  discard block
 block discarded – undo
1512 1579
 	{
1513 1580
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1514 1581
 		{
1515
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1516
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1517
-			else
1518
-				$image = get_gravatar_url($profile['email_address']);
1519
-		}
1520
-		else
1582
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1583
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1584
+			} else {
1585
+							$image = get_gravatar_url($profile['email_address']);
1586
+			}
1587
+		} else
1521 1588
 		{
1522 1589
 			// So it's stored in the member table?
1523 1590
 			if (!empty($profile['avatar']))
1524 1591
 			{
1525 1592
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1593
+			} elseif (!empty($profile['filename'])) {
1594
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1526 1595
 			}
1527
-			elseif (!empty($profile['filename']))
1528
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1529 1596
 			// Right... no avatar...use the default one
1530
-			else
1531
-				$image = $modSettings['avatar_url'] . '/default.png';
1597
+			else {
1598
+							$image = $modSettings['avatar_url'] . '/default.png';
1599
+			}
1532 1600
 		}
1533
-		if (!empty($image))
1534
-			$memberContext[$user]['avatar'] = array(
1601
+		if (!empty($image)) {
1602
+					$memberContext[$user]['avatar'] = array(
1535 1603
 				'name' => $profile['avatar'],
1536 1604
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1537 1605
 				'href' => $image,
1538 1606
 				'url' => $image,
1539 1607
 			);
1608
+		}
1540 1609
 	}
1541 1610
 
1542 1611
 	// Are we also loading the members custom fields into context?
@@ -1544,13 +1613,15 @@  discard block
 block discarded – undo
1544 1613
 	{
1545 1614
 		$memberContext[$user]['custom_fields'] = array();
1546 1615
 
1547
-		if (!isset($context['display_fields']))
1548
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1616
+		if (!isset($context['display_fields'])) {
1617
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1618
+		}
1549 1619
 
1550 1620
 		foreach ($context['display_fields'] as $custom)
1551 1621
 		{
1552
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1553
-				continue;
1622
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1623
+							continue;
1624
+			}
1554 1625
 
1555 1626
 			$value = $profile['options'][$custom['col_name']];
1556 1627
 
@@ -1558,31 +1629,36 @@  discard block
 block discarded – undo
1558 1629
 			$currentKey = 0;
1559 1630
 
1560 1631
 			// Create a key => value array for multiple options fields
1561
-			if (!empty($custom['options']))
1562
-				foreach ($custom['options'] as $k => $v)
1632
+			if (!empty($custom['options'])) {
1633
+							foreach ($custom['options'] as $k => $v)
1563 1634
 				{
1564 1635
 					$fieldOptions[] = $v;
1565
-					if (empty($currentKey))
1566
-						$currentKey = $v == $value ? $k : 0;
1636
+			}
1637
+					if (empty($currentKey)) {
1638
+											$currentKey = $v == $value ? $k : 0;
1639
+					}
1567 1640
 				}
1568 1641
 
1569 1642
 			// BBC?
1570
-			if ($custom['bbc'])
1571
-				$value = parse_bbc($value);
1643
+			if ($custom['bbc']) {
1644
+							$value = parse_bbc($value);
1645
+			}
1572 1646
 
1573 1647
 			// ... or checkbox?
1574
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1575
-				$value = $value ? $txt['yes'] : $txt['no'];
1648
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1649
+							$value = $value ? $txt['yes'] : $txt['no'];
1650
+			}
1576 1651
 
1577 1652
 			// Enclosing the user input within some other text?
1578
-			if (!empty($custom['enclose']))
1579
-				$value = strtr($custom['enclose'], array(
1653
+			if (!empty($custom['enclose'])) {
1654
+							$value = strtr($custom['enclose'], array(
1580 1655
 					'{SCRIPTURL}' => $scripturl,
1581 1656
 					'{IMAGES_URL}' => $settings['images_url'],
1582 1657
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1583 1658
 					'{INPUT}' => $value,
1584 1659
 					'{KEY}' => $currentKey,
1585 1660
 				));
1661
+			}
1586 1662
 
1587 1663
 			$memberContext[$user]['custom_fields'][] = array(
1588 1664
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1609,8 +1685,9 @@  discard block
 block discarded – undo
1609 1685
 	global $smcFunc, $txt, $scripturl, $settings;
1610 1686
 
1611 1687
 	// Do not waste my time...
1612
-	if (empty($users) || empty($params))
1613
-		return false;
1688
+	if (empty($users) || empty($params)) {
1689
+			return false;
1690
+	}
1614 1691
 
1615 1692
 	// Make sure it's an array.
1616 1693
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1637,41 +1714,48 @@  discard block
 block discarded – undo
1637 1714
 		$currentKey = 0;
1638 1715
 
1639 1716
 		// Create a key => value array for multiple options fields
1640
-		if (!empty($row['field_options']))
1641
-			foreach (explode(',', $row['field_options']) as $k => $v)
1717
+		if (!empty($row['field_options'])) {
1718
+					foreach (explode(',', $row['field_options']) as $k => $v)
1642 1719
 			{
1643 1720
 				$fieldOptions[] = $v;
1644
-				if (empty($currentKey))
1645
-					$currentKey = $v == $row['value'] ? $k : 0;
1721
+		}
1722
+				if (empty($currentKey)) {
1723
+									$currentKey = $v == $row['value'] ? $k : 0;
1724
+				}
1646 1725
 			}
1647 1726
 
1648 1727
 		// BBC?
1649
-		if (!empty($row['bbc']))
1650
-			$row['value'] = parse_bbc($row['value']);
1728
+		if (!empty($row['bbc'])) {
1729
+					$row['value'] = parse_bbc($row['value']);
1730
+		}
1651 1731
 
1652 1732
 		// ... or checkbox?
1653
-		elseif (isset($row['type']) && $row['type'] == 'check')
1654
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1733
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1734
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1735
+		}
1655 1736
 
1656 1737
 		// Enclosing the user input within some other text?
1657
-		if (!empty($row['enclose']))
1658
-			$row['value'] = strtr($row['enclose'], array(
1738
+		if (!empty($row['enclose'])) {
1739
+					$row['value'] = strtr($row['enclose'], array(
1659 1740
 				'{SCRIPTURL}' => $scripturl,
1660 1741
 				'{IMAGES_URL}' => $settings['images_url'],
1661 1742
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1662 1743
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1663 1744
 				'{KEY}' => $currentKey,
1664 1745
 			));
1746
+		}
1665 1747
 
1666 1748
 		// Send a simple array if there is just 1 param
1667
-		if (count($params) == 1)
1668
-			$return[$row['id_member']] = $row;
1749
+		if (count($params) == 1) {
1750
+					$return[$row['id_member']] = $row;
1751
+		}
1669 1752
 
1670 1753
 		// More than 1? knock yourself out...
1671 1754
 		else
1672 1755
 		{
1673
-			if (!isset($return[$row['id_member']]))
1674
-				$return[$row['id_member']] = array();
1756
+			if (!isset($return[$row['id_member']])) {
1757
+							$return[$row['id_member']] = array();
1758
+			}
1675 1759
 
1676 1760
 			$return[$row['id_member']][$row['variable']] = $row;
1677 1761
 		}
@@ -1705,8 +1789,9 @@  discard block
 block discarded – undo
1705 1789
 	global $context;
1706 1790
 
1707 1791
 	// Don't know any browser!
1708
-	if (empty($context['browser']))
1709
-		detectBrowser();
1792
+	if (empty($context['browser'])) {
1793
+			detectBrowser();
1794
+	}
1710 1795
 
1711 1796
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1712 1797
 }
@@ -1724,8 +1809,9 @@  discard block
 block discarded – undo
1724 1809
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1725 1810
 
1726 1811
 	// The theme was specified by parameter.
1727
-	if (!empty($id_theme))
1728
-		$id_theme = (int) $id_theme;
1812
+	if (!empty($id_theme)) {
1813
+			$id_theme = (int) $id_theme;
1814
+	}
1729 1815
 	// The theme was specified by REQUEST.
1730 1816
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1731 1817
 	{
@@ -1733,32 +1819,38 @@  discard block
 block discarded – undo
1733 1819
 		$_SESSION['id_theme'] = $id_theme;
1734 1820
 	}
1735 1821
 	// The theme was specified by REQUEST... previously.
1736
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1737
-		$id_theme = (int) $_SESSION['id_theme'];
1822
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1823
+			$id_theme = (int) $_SESSION['id_theme'];
1824
+	}
1738 1825
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1739
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1740
-		$id_theme = $user_info['theme'];
1826
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1827
+			$id_theme = $user_info['theme'];
1828
+	}
1741 1829
 	// The theme was specified by the board.
1742
-	elseif (!empty($board_info['theme']))
1743
-		$id_theme = $board_info['theme'];
1830
+	elseif (!empty($board_info['theme'])) {
1831
+			$id_theme = $board_info['theme'];
1832
+	}
1744 1833
 	// The theme is the forum's default.
1745
-	else
1746
-		$id_theme = $modSettings['theme_guests'];
1834
+	else {
1835
+			$id_theme = $modSettings['theme_guests'];
1836
+	}
1747 1837
 
1748 1838
 	// Verify the id_theme... no foul play.
1749 1839
 	// Always allow the board specific theme, if they are overriding.
1750
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1751
-		$id_theme = $board_info['theme'];
1840
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1841
+			$id_theme = $board_info['theme'];
1842
+	}
1752 1843
 	// If they have specified a particular theme to use with SSI allow it to be used.
1753
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1754
-		$id_theme = (int) $id_theme;
1755
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1844
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1845
+			$id_theme = (int) $id_theme;
1846
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1756 1847
 	{
1757 1848
 		$themes = explode(',', $modSettings['enableThemes']);
1758
-		if (!in_array($id_theme, $themes))
1759
-			$id_theme = $modSettings['theme_guests'];
1760
-		else
1761
-			$id_theme = (int) $id_theme;
1849
+		if (!in_array($id_theme, $themes)) {
1850
+					$id_theme = $modSettings['theme_guests'];
1851
+		} else {
1852
+					$id_theme = (int) $id_theme;
1853
+		}
1762 1854
 	}
1763 1855
 		
1764 1856
 	// We already load the basic stuff?
@@ -1767,18 +1859,19 @@  discard block
 block discarded – undo
1767 1859
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1768 1860
 
1769 1861
 		// Disable image proxy if we don't have SSL enabled
1770
-		if (empty($modSettings['force_ssl']))
1771
-			$image_proxy_enabled = false;
1862
+		if (empty($modSettings['force_ssl'])) {
1863
+					$image_proxy_enabled = false;
1864
+		}
1772 1865
 
1773 1866
 		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'])
1774 1867
 		{
1775 1868
 			$themeData = $temp;
1776 1869
 			$flag = true;
1870
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1871
+					$themeData = $temp + array($member => array());
1872
+		} else {
1873
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1777 1874
 		}
1778
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1779
-			$themeData = $temp + array($member => array());
1780
-		else
1781
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1782 1875
 
1783 1876
 		if (empty($flag))
1784 1877
 		{
@@ -1798,31 +1891,37 @@  discard block
 block discarded – undo
1798 1891
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1799 1892
 			{
1800 1893
 				// There are just things we shouldn't be able to change as members.
1801
-				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')))
1802
-					continue;
1894
+				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'))) {
1895
+									continue;
1896
+				}
1803 1897
 
1804 1898
 				// If this is the theme_dir of the default theme, store it.
1805
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1806
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1899
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1900
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1901
+				}
1807 1902
 
1808 1903
 				// If this isn't set yet, is a theme option, or is not the default theme..
1809
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1810
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1904
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1905
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1906
+				}
1811 1907
 			}
1812 1908
 			$smcFunc['db_free_result']($result);
1813 1909
 
1814
-			if (!empty($themeData[-1]))
1815
-				foreach ($themeData[-1] as $k => $v)
1910
+			if (!empty($themeData[-1])) {
1911
+							foreach ($themeData[-1] as $k => $v)
1816 1912
 				{
1817 1913
 					if (!isset($themeData[$member][$k]))
1818 1914
 						$themeData[$member][$k] = $v;
1915
+			}
1819 1916
 				}
1820 1917
 
1821
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1822
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1918
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1919
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1920
+			}
1823 1921
 			// Only if we didn't already load that part of the cache...
1824
-			elseif (!isset($temp))
1825
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1922
+			elseif (!isset($temp)) {
1923
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1924
+			}
1826 1925
 		}
1827 1926
 
1828 1927
 		$settings = $themeData[0];
@@ -1839,17 +1938,20 @@  discard block
 block discarded – undo
1839 1938
 		$settings['template_dirs'][] = $settings['theme_dir'];
1840 1939
 
1841 1940
 		// Based on theme (if there is one).
1842
-		if (!empty($settings['base_theme_dir']))
1843
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1941
+		if (!empty($settings['base_theme_dir'])) {
1942
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1943
+		}
1844 1944
 
1845 1945
 		// Lastly the default theme.
1846
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1847
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1946
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1947
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1948
+		}
1848 1949
 	}
1849 1950
 
1850 1951
 
1851
-	if (!$initialize)
1852
-		return;
1952
+	if (!$initialize) {
1953
+			return;
1954
+	}
1853 1955
 
1854 1956
 	// Check to see if we're forcing SSL
1855 1957
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1870,8 +1972,9 @@  discard block
 block discarded – undo
1870 1972
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1871 1973
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1872 1974
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1873
-		if ($temp != '/')
1874
-			$detected_url .= $temp;
1975
+		if ($temp != '/') {
1976
+					$detected_url .= $temp;
1977
+		}
1875 1978
 	}
1876 1979
 	if (isset($detected_url) && $detected_url != $boardurl)
1877 1980
 	{
@@ -1883,8 +1986,9 @@  discard block
 block discarded – undo
1883 1986
 			foreach ($aliases as $alias)
1884 1987
 			{
1885 1988
 				// Rip off all the boring parts, spaces, etc.
1886
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1887
-					$do_fix = true;
1989
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1990
+									$do_fix = true;
1991
+				}
1888 1992
 			}
1889 1993
 		}
1890 1994
 
@@ -1892,21 +1996,23 @@  discard block
 block discarded – undo
1892 1996
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1893 1997
 		{
1894 1998
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1895
-			if (empty($_GET))
1896
-				redirectexit('wwwRedirect');
1897
-			else
1999
+			if (empty($_GET)) {
2000
+							redirectexit('wwwRedirect');
2001
+			} else
1898 2002
 			{
1899 2003
 				$k = key($_GET);
1900 2004
 				$v = current($_GET);
1901 2005
 
1902
-				if ($k != 'wwwRedirect')
1903
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
2006
+				if ($k != 'wwwRedirect') {
2007
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
2008
+				}
1904 2009
 			}
1905 2010
 		}
1906 2011
 
1907 2012
 		// #3 is just a check for SSL...
1908
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1909
-			$do_fix = true;
2013
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
2014
+					$do_fix = true;
2015
+		}
1910 2016
 
1911 2017
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1912 2018
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1941,8 +2047,9 @@  discard block
 block discarded – undo
1941 2047
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1942 2048
 				}
1943 2049
 			}
1944
-			foreach ($context['linktree'] as $k => $dummy)
1945
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2050
+			foreach ($context['linktree'] as $k => $dummy) {
2051
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2052
+			}
1946 2053
 		}
1947 2054
 	}
1948 2055
 	// Set up the contextual user array.
@@ -1961,16 +2068,16 @@  discard block
 block discarded – undo
1961 2068
 			'email' => $user_info['email'],
1962 2069
 			'ignoreusers' => $user_info['ignoreusers'],
1963 2070
 		);
1964
-		if (!$context['user']['is_guest'])
1965
-			$context['user']['name'] = $user_info['name'];
1966
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1967
-			$context['user']['name'] = $txt['guest_title'];
2071
+		if (!$context['user']['is_guest']) {
2072
+					$context['user']['name'] = $user_info['name'];
2073
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2074
+					$context['user']['name'] = $txt['guest_title'];
2075
+		}
1968 2076
 
1969 2077
 		// Determine the current smiley set.
1970 2078
 		$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'];
1971 2079
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1972
-	}
1973
-	else
2080
+	} else
1974 2081
 	{
1975 2082
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1976 2083
 		$context['user'] = array(
@@ -2004,18 +2111,24 @@  discard block
 block discarded – undo
2004 2111
 	}
2005 2112
 
2006 2113
 	// Some basic information...
2007
-	if (!isset($context['html_headers']))
2008
-		$context['html_headers'] = '';
2009
-	if (!isset($context['javascript_files']))
2010
-		$context['javascript_files'] = array();
2011
-	if (!isset($context['css_files']))
2012
-		$context['css_files'] = array();
2013
-	if (!isset($context['css_header']))
2014
-		$context['css_header'] = array();
2015
-	if (!isset($context['javascript_inline']))
2016
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2017
-	if (!isset($context['javascript_vars']))
2018
-		$context['javascript_vars'] = array();
2114
+	if (!isset($context['html_headers'])) {
2115
+			$context['html_headers'] = '';
2116
+	}
2117
+	if (!isset($context['javascript_files'])) {
2118
+			$context['javascript_files'] = array();
2119
+	}
2120
+	if (!isset($context['css_files'])) {
2121
+			$context['css_files'] = array();
2122
+	}
2123
+	if (!isset($context['css_header'])) {
2124
+			$context['css_header'] = array();
2125
+	}
2126
+	if (!isset($context['javascript_inline'])) {
2127
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2128
+	}
2129
+	if (!isset($context['javascript_vars'])) {
2130
+			$context['javascript_vars'] = array();
2131
+	}
2019 2132
 
2020 2133
 	$context['login_url'] =  $scripturl . '?action=login2';
2021 2134
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2027,16 +2140,18 @@  discard block
 block discarded – undo
2027 2140
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2028 2141
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2029 2142
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2030
-	if (isset($modSettings['load_average']))
2031
-		$context['load_average'] = $modSettings['load_average'];
2143
+	if (isset($modSettings['load_average'])) {
2144
+			$context['load_average'] = $modSettings['load_average'];
2145
+	}
2032 2146
 
2033 2147
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2034 2148
 	detectBrowser();
2035 2149
 
2036 2150
 	// Set the top level linktree up.
2037 2151
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2038
-	if (empty($context['linktree']))
2039
-		$context['linktree'] = array();
2152
+	if (empty($context['linktree'])) {
2153
+			$context['linktree'] = array();
2154
+	}
2040 2155
 	array_unshift($context['linktree'], array(
2041 2156
 		'url' => $scripturl,
2042 2157
 		'name' => $context['forum_name_html_safe']
@@ -2045,8 +2160,9 @@  discard block
 block discarded – undo
2045 2160
 	// This allows sticking some HTML on the page output - useful for controls.
2046 2161
 	$context['insert_after_template'] = '';
2047 2162
 
2048
-	if (!isset($txt))
2049
-		$txt = array();
2163
+	if (!isset($txt)) {
2164
+			$txt = array();
2165
+	}
2050 2166
 
2051 2167
 	$simpleActions = array(
2052 2168
 		'findmember',
@@ -2092,9 +2208,10 @@  discard block
 block discarded – undo
2092 2208
 
2093 2209
 	// See if theres any extra param to check.
2094 2210
 	$requiresXML = false;
2095
-	foreach ($extraParams as $key => $extra)
2096
-		if (isset($_REQUEST[$extra]))
2211
+	foreach ($extraParams as $key => $extra) {
2212
+			if (isset($_REQUEST[$extra]))
2097 2213
 			$requiresXML = true;
2214
+	}
2098 2215
 
2099 2216
 	// Output is fully XML, so no need for the index template.
2100 2217
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2109,37 +2226,39 @@  discard block
 block discarded – undo
2109 2226
 	{
2110 2227
 		loadLanguage('index+Modifications');
2111 2228
 		$context['template_layers'] = array();
2112
-	}
2113
-
2114
-	else
2229
+	} else
2115 2230
 	{
2116 2231
 		// Custom templates to load, or just default?
2117
-		if (isset($settings['theme_templates']))
2118
-			$templates = explode(',', $settings['theme_templates']);
2119
-		else
2120
-			$templates = array('index');
2232
+		if (isset($settings['theme_templates'])) {
2233
+					$templates = explode(',', $settings['theme_templates']);
2234
+		} else {
2235
+					$templates = array('index');
2236
+		}
2121 2237
 
2122 2238
 		// Load each template...
2123
-		foreach ($templates as $template)
2124
-			loadTemplate($template);
2239
+		foreach ($templates as $template) {
2240
+					loadTemplate($template);
2241
+		}
2125 2242
 
2126 2243
 		// ...and attempt to load their associated language files.
2127 2244
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2128 2245
 		loadLanguage($required_files, '', false);
2129 2246
 
2130 2247
 		// Custom template layers?
2131
-		if (isset($settings['theme_layers']))
2132
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2133
-		else
2134
-			$context['template_layers'] = array('html', 'body');
2248
+		if (isset($settings['theme_layers'])) {
2249
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2250
+		} else {
2251
+					$context['template_layers'] = array('html', 'body');
2252
+		}
2135 2253
 	}
2136 2254
 
2137 2255
 	// Initialize the theme.
2138 2256
 	loadSubTemplate('init', 'ignore');
2139 2257
 
2140 2258
 	// Allow overriding the board wide time/number formats.
2141
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2142
-		$user_info['time_format'] = $txt['time_format'];
2259
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2260
+			$user_info['time_format'] = $txt['time_format'];
2261
+	}
2143 2262
 
2144 2263
 	// Set the character set from the template.
2145 2264
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2147,12 +2266,14 @@  discard block
 block discarded – undo
2147 2266
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2148 2267
 
2149 2268
 	// Guests may still need a name.
2150
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2151
-		$context['user']['name'] = $txt['guest_title'];
2269
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2270
+			$context['user']['name'] = $txt['guest_title'];
2271
+	}
2152 2272
 
2153 2273
 	// Any theme-related strings that need to be loaded?
2154
-	if (!empty($settings['require_theme_strings']))
2155
-		loadLanguage('ThemeStrings', '', false);
2274
+	if (!empty($settings['require_theme_strings'])) {
2275
+			loadLanguage('ThemeStrings', '', false);
2276
+	}
2156 2277
 
2157 2278
 	// Make a special URL for the language.
2158 2279
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2163,8 +2284,9 @@  discard block
 block discarded – undo
2163 2284
 	// Here is my luvly Responsive CSS
2164 2285
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2165 2286
 
2166
-	if ($context['right_to_left'])
2167
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2287
+	if ($context['right_to_left']) {
2288
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2289
+	}
2168 2290
 
2169 2291
 	// We allow theme variants, because we're cool.
2170 2292
 	$context['theme_variant'] = '';
@@ -2172,14 +2294,17 @@  discard block
 block discarded – undo
2172 2294
 	if (!empty($settings['theme_variants']))
2173 2295
 	{
2174 2296
 		// Overriding - for previews and that ilk.
2175
-		if (!empty($_REQUEST['variant']))
2176
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2297
+		if (!empty($_REQUEST['variant'])) {
2298
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2299
+		}
2177 2300
 		// User selection?
2178
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2179
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2301
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2302
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2303
+		}
2180 2304
 		// If not a user variant, select the default.
2181
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2182
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2305
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2306
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2307
+		}
2183 2308
 
2184 2309
 		// Do this to keep things easier in the templates.
2185 2310
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2188,20 +2313,23 @@  discard block
 block discarded – undo
2188 2313
 		if (!empty($context['theme_variant']))
2189 2314
 		{
2190 2315
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2191
-			if ($context['right_to_left'])
2192
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2316
+			if ($context['right_to_left']) {
2317
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2318
+			}
2193 2319
 		}
2194 2320
 	}
2195 2321
 
2196 2322
 	// Let's be compatible with old themes!
2197
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2198
-		$context['template_layers'] = array('main');
2323
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2324
+			$context['template_layers'] = array('main');
2325
+	}
2199 2326
 
2200 2327
 	$context['tabindex'] = 1;
2201 2328
 
2202 2329
 	// Compatibility.
2203
-	if (!isset($settings['theme_version']))
2204
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2330
+	if (!isset($settings['theme_version'])) {
2331
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2332
+	}
2205 2333
 
2206 2334
 	// Default JS variables for use in every theme
2207 2335
 	$context['javascript_vars'] = array(
@@ -2222,18 +2350,18 @@  discard block
 block discarded – undo
2222 2350
 	);
2223 2351
 
2224 2352
 	// Add the JQuery library to the list of files to load.
2225
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2226
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2227
-
2228
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2229
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2230
-
2231
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2232
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2353
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2354
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2355
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2356
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2357
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2358
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2359
+	}
2233 2360
 
2234 2361
 	// Auto loading? template_javascript() will take care of the local half of this.
2235
-	else
2236
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2362
+	else {
2363
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2364
+	}
2237 2365
 
2238 2366
 	// Queue our JQuery plugins!
2239 2367
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2256,12 +2384,12 @@  discard block
 block discarded – undo
2256 2384
 			require_once($sourcedir . '/ScheduledTasks.php');
2257 2385
 
2258 2386
 			// What to do, what to do?!
2259
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2260
-				AutoTask();
2261
-			else
2262
-				ReduceMailQueue();
2263
-		}
2264
-		else
2387
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2388
+							AutoTask();
2389
+			} else {
2390
+							ReduceMailQueue();
2391
+			}
2392
+		} else
2265 2393
 		{
2266 2394
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2267 2395
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2312,8 +2440,9 @@  discard block
 block discarded – undo
2312 2440
 		foreach ($theme_includes as $include)
2313 2441
 		{
2314 2442
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2315
-			if (file_exists($include))
2316
-				require_once($include);
2443
+			if (file_exists($include)) {
2444
+							require_once($include);
2445
+			}
2317 2446
 		}
2318 2447
 	}
2319 2448
 
@@ -2343,16 +2472,19 @@  discard block
 block discarded – undo
2343 2472
 	// Do any style sheets first, cause we're easy with those.
2344 2473
 	if (!empty($style_sheets))
2345 2474
 	{
2346
-		if (!is_array($style_sheets))
2347
-			$style_sheets = array($style_sheets);
2475
+		if (!is_array($style_sheets)) {
2476
+					$style_sheets = array($style_sheets);
2477
+		}
2348 2478
 
2349
-		foreach ($style_sheets as $sheet)
2350
-			loadCSSFile($sheet . '.css', array(), $sheet);
2479
+		foreach ($style_sheets as $sheet) {
2480
+					loadCSSFile($sheet . '.css', array(), $sheet);
2481
+		}
2351 2482
 	}
2352 2483
 
2353 2484
 	// No template to load?
2354
-	if ($template_name === false)
2355
-		return true;
2485
+	if ($template_name === false) {
2486
+			return true;
2487
+	}
2356 2488
 
2357 2489
 	$loaded = false;
2358 2490
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2367,12 +2499,14 @@  discard block
 block discarded – undo
2367 2499
 
2368 2500
 	if ($loaded)
2369 2501
 	{
2370
-		if ($db_show_debug === true)
2371
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2502
+		if ($db_show_debug === true) {
2503
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2504
+		}
2372 2505
 
2373 2506
 		// If they have specified an initialization function for this template, go ahead and call it now.
2374
-		if (function_exists('template_' . $template_name . '_init'))
2375
-			call_user_func('template_' . $template_name . '_init');
2507
+		if (function_exists('template_' . $template_name . '_init')) {
2508
+					call_user_func('template_' . $template_name . '_init');
2509
+		}
2376 2510
 	}
2377 2511
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2378 2512
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2392,13 +2526,14 @@  discard block
 block discarded – undo
2392 2526
 		loadTemplate($template_name);
2393 2527
 	}
2394 2528
 	// Cause an error otherwise.
2395
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2396
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2397
-	elseif ($fatal)
2398
-		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'));
2399
-	else
2400
-		return false;
2401
-}
2529
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2530
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2531
+	} elseif ($fatal) {
2532
+			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'));
2533
+	} else {
2534
+			return false;
2535
+	}
2536
+	}
2402 2537
 
2403 2538
 /**
2404 2539
  * Load a sub-template.
@@ -2416,17 +2551,19 @@  discard block
 block discarded – undo
2416 2551
 {
2417 2552
 	global $context, $txt, $db_show_debug;
2418 2553
 
2419
-	if ($db_show_debug === true)
2420
-		$context['debug']['sub_templates'][] = $sub_template_name;
2554
+	if ($db_show_debug === true) {
2555
+			$context['debug']['sub_templates'][] = $sub_template_name;
2556
+	}
2421 2557
 
2422 2558
 	// Figure out what the template function is named.
2423 2559
 	$theme_function = 'template_' . $sub_template_name;
2424
-	if (function_exists($theme_function))
2425
-		$theme_function();
2426
-	elseif ($fatal === false)
2427
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2428
-	elseif ($fatal !== 'ignore')
2429
-		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'));
2560
+	if (function_exists($theme_function)) {
2561
+			$theme_function();
2562
+	} elseif ($fatal === false) {
2563
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2564
+	} elseif ($fatal !== 'ignore') {
2565
+			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'));
2566
+	}
2430 2567
 
2431 2568
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2432 2569
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2456,8 +2593,9 @@  discard block
 block discarded – undo
2456 2593
 {
2457 2594
 	global $settings, $context, $modSettings;
2458 2595
 
2459
-	if (empty($context['css_files_order']))
2460
-		$context['css_files_order'] = array();
2596
+	if (empty($context['css_files_order'])) {
2597
+			$context['css_files_order'] = array();
2598
+	}
2461 2599
 
2462 2600
 	$params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
2463 2601
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2468,8 +2606,9 @@  discard block
 block discarded – undo
2468 2606
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2469 2607
 
2470 2608
 	// If this is an external file, automatically set this to false.
2471
-	if (!empty($params['external']))
2472
-		$params['minimize'] = false;
2609
+	if (!empty($params['external'])) {
2610
+			$params['minimize'] = false;
2611
+	}
2473 2612
 
2474 2613
 	// Account for shorthand like admin.css?alp21 filenames
2475 2614
 	$has_seed = strpos($fileName, '.css?');
@@ -2486,16 +2625,12 @@  discard block
 block discarded – undo
2486 2625
 			{
2487 2626
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2488 2627
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2489
-			}
2490
-
2491
-			else
2628
+			} else
2492 2629
 			{
2493 2630
 				$fileUrl = false;
2494 2631
 				$filePath = false;
2495 2632
 			}
2496
-		}
2497
-
2498
-		else
2633
+		} else
2499 2634
 		{
2500 2635
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2501 2636
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2513,16 +2648,18 @@  discard block
 block discarded – undo
2513 2648
 	if (!empty($fileName))
2514 2649
 	{
2515 2650
 		// find a free number/position
2516
-		while (isset($context['css_files_order'][$params['order_pos']]))
2517
-			$params['order_pos']++;
2651
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2652
+					$params['order_pos']++;
2653
+		}
2518 2654
 		$context['css_files_order'][$params['order_pos']] = $id;
2519 2655
 
2520 2656
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2521 2657
 	}
2522 2658
 
2523
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2524
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2525
-}
2659
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2660
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2661
+	}
2662
+	}
2526 2663
 
2527 2664
 /**
2528 2665
  * Add a block of inline css code to be executed later
@@ -2539,8 +2676,9 @@  discard block
 block discarded – undo
2539 2676
 	global $context;
2540 2677
 
2541 2678
 	// Gotta add something...
2542
-	if (empty($css))
2543
-		return false;
2679
+	if (empty($css)) {
2680
+			return false;
2681
+	}
2544 2682
 
2545 2683
 	$context['css_header'][] = $css;
2546 2684
 }
@@ -2576,8 +2714,9 @@  discard block
 block discarded – undo
2576 2714
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2577 2715
 
2578 2716
 	// If this is an external file, automatically set this to false.
2579
-	if (!empty($params['external']))
2580
-		$params['minimize'] = false;
2717
+	if (!empty($params['external'])) {
2718
+			$params['minimize'] = false;
2719
+	}
2581 2720
 
2582 2721
 	// Account for shorthand like admin.js?alp21 filenames
2583 2722
 	$has_seed = strpos($fileName, '.js?');
@@ -2594,16 +2733,12 @@  discard block
 block discarded – undo
2594 2733
 			{
2595 2734
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2596 2735
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2597
-			}
2598
-
2599
-			else
2736
+			} else
2600 2737
 			{
2601 2738
 				$fileUrl = false;
2602 2739
 				$filePath = false;
2603 2740
 			}
2604
-		}
2605
-
2606
-		else
2741
+		} else
2607 2742
 		{
2608 2743
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2609 2744
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2618,9 +2753,10 @@  discard block
 block discarded – undo
2618 2753
 	}
2619 2754
 
2620 2755
 	// Add it to the array for use in the template
2621
-	if (!empty($fileName))
2622
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2623
-}
2756
+	if (!empty($fileName)) {
2757
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2758
+	}
2759
+	}
2624 2760
 
2625 2761
 /**
2626 2762
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2634,9 +2770,10 @@  discard block
 block discarded – undo
2634 2770
 {
2635 2771
 	global $context;
2636 2772
 
2637
-	if (!empty($key) && (!empty($value) || $value === '0'))
2638
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2639
-}
2773
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2774
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2775
+	}
2776
+	}
2640 2777
 
2641 2778
 /**
2642 2779
  * Add a block of inline Javascript code to be executed later
@@ -2653,8 +2790,9 @@  discard block
 block discarded – undo
2653 2790
 {
2654 2791
 	global $context;
2655 2792
 
2656
-	if (empty($javascript))
2657
-		return false;
2793
+	if (empty($javascript)) {
2794
+			return false;
2795
+	}
2658 2796
 
2659 2797
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2660 2798
 }
@@ -2675,15 +2813,18 @@  discard block
 block discarded – undo
2675 2813
 	static $already_loaded = array();
2676 2814
 
2677 2815
 	// Default to the user's language.
2678
-	if ($lang == '')
2679
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2816
+	if ($lang == '') {
2817
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2818
+	}
2680 2819
 
2681 2820
 	// Do we want the English version of language file as fallback?
2682
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2683
-		loadLanguage($template_name, 'english', false);
2821
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2822
+			loadLanguage($template_name, 'english', false);
2823
+	}
2684 2824
 
2685
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2686
-		return $lang;
2825
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2826
+			return $lang;
2827
+	}
2687 2828
 
2688 2829
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2689 2830
 	if (empty($settings['default_theme_dir']))
@@ -2694,8 +2835,9 @@  discard block
 block discarded – undo
2694 2835
 
2695 2836
 	// What theme are we in?
2696 2837
 	$theme_name = basename($settings['theme_url']);
2697
-	if (empty($theme_name))
2698
-		$theme_name = 'unknown';
2838
+	if (empty($theme_name)) {
2839
+			$theme_name = 'unknown';
2840
+	}
2699 2841
 
2700 2842
 	// For each file open it up and write it out!
2701 2843
 	foreach (explode('+', $template_name) as $template)
@@ -2737,8 +2879,9 @@  discard block
 block discarded – undo
2737 2879
 				$found = true;
2738 2880
 
2739 2881
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2740
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2741
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2882
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2883
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2884
+				}
2742 2885
 
2743 2886
 				break;
2744 2887
 			}
@@ -2778,8 +2921,9 @@  discard block
 block discarded – undo
2778 2921
 	}
2779 2922
 
2780 2923
 	// Keep track of what we're up to soldier.
2781
-	if ($db_show_debug === true)
2782
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2924
+	if ($db_show_debug === true) {
2925
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2926
+	}
2783 2927
 
2784 2928
 	// Remember what we have loaded, and in which language.
2785 2929
 	$already_loaded[$template_name] = $lang;
@@ -2825,8 +2969,9 @@  discard block
 block discarded – undo
2825 2969
 				)
2826 2970
 			);
2827 2971
 			// In the EXTREMELY unlikely event this happens, give an error message.
2828
-			if ($smcFunc['db_num_rows']($result) == 0)
2829
-				fatal_lang_error('parent_not_found', 'critical');
2972
+			if ($smcFunc['db_num_rows']($result) == 0) {
2973
+							fatal_lang_error('parent_not_found', 'critical');
2974
+			}
2830 2975
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2831 2976
 			{
2832 2977
 				if (!isset($boards[$row['id_board']]))
@@ -2843,8 +2988,8 @@  discard block
 block discarded – undo
2843 2988
 					);
2844 2989
 				}
2845 2990
 				// If a moderator exists for this board, add that moderator for all children too.
2846
-				if (!empty($row['id_moderator']))
2847
-					foreach ($boards as $id => $dummy)
2991
+				if (!empty($row['id_moderator'])) {
2992
+									foreach ($boards as $id => $dummy)
2848 2993
 					{
2849 2994
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2850 2995
 							'id' => $row['id_moderator'],
@@ -2852,11 +2997,12 @@  discard block
 block discarded – undo
2852 2997
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2853 2998
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2854 2999
 						);
3000
+				}
2855 3001
 					}
2856 3002
 
2857 3003
 				// If a moderator group exists for this board, add that moderator group for all children too
2858
-				if (!empty($row['id_moderator_group']))
2859
-					foreach ($boards as $id => $dummy)
3004
+				if (!empty($row['id_moderator_group'])) {
3005
+									foreach ($boards as $id => $dummy)
2860 3006
 					{
2861 3007
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2862 3008
 							'id' => $row['id_moderator_group'],
@@ -2864,6 +3010,7 @@  discard block
 block discarded – undo
2864 3010
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2865 3011
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2866 3012
 						);
3013
+				}
2867 3014
 					}
2868 3015
 			}
2869 3016
 			$smcFunc['db_free_result']($result);
@@ -2890,23 +3037,27 @@  discard block
 block discarded – undo
2890 3037
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2891 3038
 	{
2892 3039
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2893
-		if (empty($smcFunc['ucwords']))
2894
-			reloadSettings();
3040
+		if (empty($smcFunc['ucwords'])) {
3041
+					reloadSettings();
3042
+		}
2895 3043
 
2896 3044
 		// If we don't have our theme information yet, let's get it.
2897
-		if (empty($settings['default_theme_dir']))
2898
-			loadTheme(0, false);
3045
+		if (empty($settings['default_theme_dir'])) {
3046
+					loadTheme(0, false);
3047
+		}
2899 3048
 
2900 3049
 		// Default language directories to try.
2901 3050
 		$language_directories = array(
2902 3051
 			$settings['default_theme_dir'] . '/languages',
2903 3052
 		);
2904
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2905
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3053
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3054
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3055
+		}
2906 3056
 
2907 3057
 		// We possibly have a base theme directory.
2908
-		if (!empty($settings['base_theme_dir']))
2909
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3058
+		if (!empty($settings['base_theme_dir'])) {
3059
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3060
+		}
2910 3061
 
2911 3062
 		// Remove any duplicates.
2912 3063
 		$language_directories = array_unique($language_directories);
@@ -2920,20 +3071,21 @@  discard block
 block discarded – undo
2920 3071
 		foreach ($language_directories as $language_dir)
2921 3072
 		{
2922 3073
 			// Can't look in here... doesn't exist!
2923
-			if (!file_exists($language_dir))
2924
-				continue;
3074
+			if (!file_exists($language_dir)) {
3075
+							continue;
3076
+			}
2925 3077
 
2926 3078
 			$dir = dir($language_dir);
2927 3079
 			while ($entry = $dir->read())
2928 3080
 			{
2929 3081
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2930
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2931
-					continue;
2932
-
2933
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2934
-					$langName = $langList[$matches[1]];
3082
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3083
+									continue;
3084
+				}
2935 3085
 
2936
-				else
3086
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3087
+									$langName = $langList[$matches[1]];
3088
+				} else
2937 3089
 				{
2938 3090
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2939 3091
 
@@ -2974,12 +3126,14 @@  discard block
 block discarded – undo
2974 3126
 		}
2975 3127
 
2976 3128
 		// Do we need to store the lang list?
2977
-		if (empty($langList))
2978
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3129
+		if (empty($langList)) {
3130
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3131
+		}
2979 3132
 
2980 3133
 		// Let's cash in on this deal.
2981
-		if (!empty($modSettings['cache_enable']))
2982
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3134
+		if (!empty($modSettings['cache_enable'])) {
3135
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3136
+		}
2983 3137
 	}
2984 3138
 
2985 3139
 	return $context['languages'];
@@ -3002,8 +3156,9 @@  discard block
 block discarded – undo
3002 3156
 	global $modSettings, $options, $txt;
3003 3157
 	static $censor_vulgar = null, $censor_proper;
3004 3158
 
3005
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
3006
-		return $text;
3159
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3160
+			return $text;
3161
+	}
3007 3162
 
3008 3163
 	// If they haven't yet been loaded, load them.
3009 3164
 	if ($censor_vulgar == null)
@@ -3034,9 +3189,9 @@  discard block
 block discarded – undo
3034 3189
 	{
3035 3190
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3036 3191
 		$text = $func($censor_vulgar, $censor_proper, $text);
3192
+	} else {
3193
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3037 3194
 	}
3038
-	else
3039
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3040 3195
 
3041 3196
 	return $text;
3042 3197
 }
@@ -3062,30 +3217,35 @@  discard block
 block discarded – undo
3062 3217
 	@ini_set('track_errors', '1');
3063 3218
 
3064 3219
 	// Don't include the file more than once, if $once is true.
3065
-	if ($once && in_array($filename, $templates))
3066
-		return;
3220
+	if ($once && in_array($filename, $templates)) {
3221
+			return;
3222
+	}
3067 3223
 	// Add this file to the include list, whether $once is true or not.
3068
-	else
3069
-		$templates[] = $filename;
3224
+	else {
3225
+			$templates[] = $filename;
3226
+	}
3070 3227
 
3071 3228
 
3072 3229
 	$file_found = file_exists($filename);
3073 3230
 
3074
-	if ($once && $file_found)
3075
-		require_once($filename);
3076
-	elseif ($file_found)
3077
-		require($filename);
3231
+	if ($once && $file_found) {
3232
+			require_once($filename);
3233
+	} elseif ($file_found) {
3234
+			require($filename);
3235
+	}
3078 3236
 
3079 3237
 	if ($file_found !== true)
3080 3238
 	{
3081 3239
 		ob_end_clean();
3082
-		if (!empty($modSettings['enableCompressedOutput']))
3083
-			@ob_start('ob_gzhandler');
3084
-		else
3085
-			ob_start();
3240
+		if (!empty($modSettings['enableCompressedOutput'])) {
3241
+					@ob_start('ob_gzhandler');
3242
+		} else {
3243
+					ob_start();
3244
+		}
3086 3245
 
3087
-		if (isset($_GET['debug']))
3088
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3246
+		if (isset($_GET['debug'])) {
3247
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3248
+		}
3089 3249
 
3090 3250
 		// Don't cache error pages!!
3091 3251
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3104,12 +3264,13 @@  discard block
 block discarded – undo
3104 3264
 		echo '<!DOCTYPE html>
3105 3265
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3106 3266
 	<head>';
3107
-		if (isset($context['character_set']))
3108
-			echo '
3267
+		if (isset($context['character_set'])) {
3268
+					echo '
3109 3269
 		<meta charset="', $context['character_set'], '">';
3270
+		}
3110 3271
 
3111
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3112
-			echo '
3272
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3273
+					echo '
3113 3274
 		<title>', $mtitle, '</title>
3114 3275
 	</head>
3115 3276
 	<body>
@@ -3117,8 +3278,8 @@  discard block
 block discarded – undo
3117 3278
 		', $mmessage, '
3118 3279
 	</body>
3119 3280
 </html>';
3120
-		elseif (!allowedTo('admin_forum'))
3121
-			echo '
3281
+		} elseif (!allowedTo('admin_forum')) {
3282
+					echo '
3122 3283
 		<title>', $txt['template_parse_error'], '</title>
3123 3284
 	</head>
3124 3285
 	<body>
@@ -3126,14 +3287,16 @@  discard block
 block discarded – undo
3126 3287
 		', $txt['template_parse_error_message'], '
3127 3288
 	</body>
3128 3289
 </html>';
3129
-		else
3290
+		} else
3130 3291
 		{
3131 3292
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3132 3293
 			$error_array = error_get_last();
3133
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3134
-				$error = $error_array['message'];
3135
-			if (empty($error))
3136
-				$error = $txt['template_parse_errmsg'];
3294
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3295
+							$error = $error_array['message'];
3296
+			}
3297
+			if (empty($error)) {
3298
+							$error = $txt['template_parse_errmsg'];
3299
+			}
3137 3300
 
3138 3301
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3139 3302
 
@@ -3144,11 +3307,12 @@  discard block
 block discarded – undo
3144 3307
 		<h3>', $txt['template_parse_error'], '</h3>
3145 3308
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3146 3309
 
3147
-			if (!empty($error))
3148
-				echo '
3310
+			if (!empty($error)) {
3311
+							echo '
3149 3312
 		<hr>
3150 3313
 
3151 3314
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3315
+			}
3152 3316
 
3153 3317
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3154 3318
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3158,10 +3322,11 @@  discard block
 block discarded – undo
3158 3322
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3159 3323
 
3160 3324
 				// Fix the PHP code stuff...
3161
-				if (!isBrowser('gecko'))
3162
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3163
-				else
3164
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3325
+				if (!isBrowser('gecko')) {
3326
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3327
+				} else {
3328
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3329
+				}
3165 3330
 
3166 3331
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3167 3332
 				$j = -1;
@@ -3169,8 +3334,9 @@  discard block
 block discarded – undo
3169 3334
 				{
3170 3335
 					$j++;
3171 3336
 
3172
-					if (substr_count($line, '<br>') == 0)
3173
-						continue;
3337
+					if (substr_count($line, '<br>') == 0) {
3338
+											continue;
3339
+					}
3174 3340
 
3175 3341
 					$n = substr_count($line, '<br>');
3176 3342
 					for ($i = 0; $i < $n; $i++)
@@ -3189,38 +3355,42 @@  discard block
 block discarded – undo
3189 3355
 				// Figure out what the color coding was before...
3190 3356
 				$line = max($match[1] - 9, 1);
3191 3357
 				$last_line = '';
3192
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3193
-					if (strpos($data2[$line2], '<') !== false)
3358
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3359
+									if (strpos($data2[$line2], '<') !== false)
3194 3360
 					{
3195 3361
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3196 3362
 							$last_line = $color_match[1];
3363
+				}
3197 3364
 						break;
3198 3365
 					}
3199 3366
 
3200 3367
 				// Show the relevant lines...
3201 3368
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3202 3369
 				{
3203
-					if ($line == $match[1])
3204
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3370
+					if ($line == $match[1]) {
3371
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3372
+					}
3205 3373
 
3206 3374
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3207
-					if (isset($data2[$line]) && $data2[$line] != '')
3208
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3375
+					if (isset($data2[$line]) && $data2[$line] != '') {
3376
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3377
+					}
3209 3378
 
3210 3379
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3211 3380
 					{
3212 3381
 						$last_line = $color_match[1];
3213 3382
 						echo '</', substr($last_line, 1, 4), '>';
3383
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3384
+											$last_line = '';
3385
+					} elseif ($last_line != '' && $data2[$line] != '') {
3386
+											echo '</', substr($last_line, 1, 4), '>';
3214 3387
 					}
3215
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3216
-						$last_line = '';
3217
-					elseif ($last_line != '' && $data2[$line] != '')
3218
-						echo '</', substr($last_line, 1, 4), '>';
3219 3388
 
3220
-					if ($line == $match[1])
3221
-						echo '</pre></div><pre style="margin: 0;">';
3222
-					else
3223
-						echo "\n";
3389
+					if ($line == $match[1]) {
3390
+											echo '</pre></div><pre style="margin: 0;">';
3391
+					} else {
3392
+											echo "\n";
3393
+					}
3224 3394
 				}
3225 3395
 
3226 3396
 				echo '</pre></div>';
@@ -3244,8 +3414,9 @@  discard block
 block discarded – undo
3244 3414
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4;
3245 3415
 
3246 3416
 	// Figure out what type of database we are using.
3247
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3248
-		$db_type = 'mysql';
3417
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3418
+			$db_type = 'mysql';
3419
+	}
3249 3420
 
3250 3421
 	// Load the file for the database.
3251 3422
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3253,11 +3424,13 @@  discard block
 block discarded – undo
3253 3424
 	$db_options = array();
3254 3425
 
3255 3426
 	// Add in the port if needed
3256
-	if (!empty($db_port))
3257
-		$db_options['port'] = $db_port;
3427
+	if (!empty($db_port)) {
3428
+			$db_options['port'] = $db_port;
3429
+	}
3258 3430
 
3259
-	if (!empty($db_mb4))
3260
-		$db_options['db_mb4'] = $db_mb4;
3431
+	if (!empty($db_mb4)) {
3432
+			$db_options['db_mb4'] = $db_mb4;
3433
+	}
3261 3434
 
3262 3435
 	// 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.
3263 3436
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3276,13 +3449,15 @@  discard block
 block discarded – undo
3276 3449
 	}
3277 3450
 
3278 3451
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3279
-	if (!$db_connection)
3280
-		display_db_error();
3452
+	if (!$db_connection) {
3453
+			display_db_error();
3454
+	}
3281 3455
 
3282 3456
 	// If in SSI mode fix up the prefix.
3283
-	if (SMF == 'SSI')
3284
-		db_fix_prefix($db_prefix, $db_name);
3285
-}
3457
+	if (SMF == 'SSI') {
3458
+			db_fix_prefix($db_prefix, $db_name);
3459
+	}
3460
+	}
3286 3461
 
3287 3462
 /**
3288 3463
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3296,10 +3471,11 @@  discard block
 block discarded – undo
3296 3471
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3297 3472
 
3298 3473
 	// Not overriding this and we have a cacheAPI, send it back.
3299
-	if (empty($overrideCache) && is_object($cacheAPI))
3300
-		return $cacheAPI;
3301
-	elseif (is_null($cacheAPI))
3302
-		$cacheAPI = false;
3474
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3475
+			return $cacheAPI;
3476
+	} elseif (is_null($cacheAPI)) {
3477
+			$cacheAPI = false;
3478
+	}
3303 3479
 
3304 3480
 	// Make sure our class is in session.
3305 3481
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3320,8 +3496,9 @@  discard block
 block discarded – undo
3320 3496
 		if (!$testAPI->isSupported())
3321 3497
 		{
3322 3498
 			// Can we save ourselves?
3323
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3324
-				return loadCacheAccelerator(null, false);
3499
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3500
+							return loadCacheAccelerator(null, false);
3501
+			}
3325 3502
 			return false;
3326 3503
 		}
3327 3504
 
@@ -3333,9 +3510,9 @@  discard block
 block discarded – undo
3333 3510
 		{
3334 3511
 			$cacheAPI = $testAPI;
3335 3512
 			return $cacheAPI;
3513
+		} else {
3514
+					return $testAPI;
3336 3515
 		}
3337
-		else
3338
-			return $testAPI;
3339 3516
 	}
3340 3517
 }
3341 3518
 
@@ -3355,8 +3532,9 @@  discard block
 block discarded – undo
3355 3532
 
3356 3533
 	// @todo Why are we doing this if caching is disabled?
3357 3534
 
3358
-	if (function_exists('call_integration_hook'))
3359
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3535
+	if (function_exists('call_integration_hook')) {
3536
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3537
+	}
3360 3538
 
3361 3539
 	/* Refresh the cache if either:
3362 3540
 		1. Caching is disabled.
@@ -3370,16 +3548,19 @@  discard block
 block discarded – undo
3370 3548
 		require_once($sourcedir . '/' . $file);
3371 3549
 		$cache_block = call_user_func_array($function, $params);
3372 3550
 
3373
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3374
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3551
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3552
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3553
+		}
3375 3554
 	}
3376 3555
 
3377 3556
 	// Some cached data may need a freshening up after retrieval.
3378
-	if (!empty($cache_block['post_retri_eval']))
3379
-		eval($cache_block['post_retri_eval']);
3557
+	if (!empty($cache_block['post_retri_eval'])) {
3558
+			eval($cache_block['post_retri_eval']);
3559
+	}
3380 3560
 
3381
-	if (function_exists('call_integration_hook'))
3382
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3561
+	if (function_exists('call_integration_hook')) {
3562
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3563
+	}
3383 3564
 
3384 3565
 	return $cache_block['data'];
3385 3566
 }
@@ -3406,8 +3587,9 @@  discard block
 block discarded – undo
3406 3587
 	global $smcFunc, $cache_enable, $cacheAPI;
3407 3588
 	global $cache_hits, $cache_count, $db_show_debug;
3408 3589
 
3409
-	if (empty($cache_enable) || empty($cacheAPI))
3410
-		return;
3590
+	if (empty($cache_enable) || empty($cacheAPI)) {
3591
+			return;
3592
+	}
3411 3593
 
3412 3594
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3413 3595
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3420,12 +3602,14 @@  discard block
 block discarded – undo
3420 3602
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3421 3603
 	$cacheAPI->putData($key, $value, $ttl);
3422 3604
 
3423
-	if (function_exists('call_integration_hook'))
3424
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3605
+	if (function_exists('call_integration_hook')) {
3606
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3607
+	}
3425 3608
 
3426
-	if (isset($db_show_debug) && $db_show_debug === true)
3427
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3428
-}
3609
+	if (isset($db_show_debug) && $db_show_debug === true) {
3610
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3611
+	}
3612
+	}
3429 3613
 
3430 3614
 /**
3431 3615
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3441,8 +3625,9 @@  discard block
 block discarded – undo
3441 3625
 	global $smcFunc, $cache_enable, $cacheAPI;
3442 3626
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3443 3627
 
3444
-	if (empty($cache_enable) || empty($cacheAPI))
3445
-		return;
3628
+	if (empty($cache_enable) || empty($cacheAPI)) {
3629
+			return;
3630
+	}
3446 3631
 
3447 3632
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3448 3633
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3462,16 +3647,18 @@  discard block
 block discarded – undo
3462 3647
 
3463 3648
 		if (empty($value))
3464 3649
 		{
3465
-			if (!is_array($cache_misses))
3466
-				$cache_misses = array();
3650
+			if (!is_array($cache_misses)) {
3651
+							$cache_misses = array();
3652
+			}
3467 3653
 
3468 3654
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3469 3655
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3470 3656
 		}
3471 3657
 	}
3472 3658
 
3473
-	if (function_exists('call_integration_hook') && isset($value))
3474
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3659
+	if (function_exists('call_integration_hook') && isset($value)) {
3660
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3661
+	}
3475 3662
 
3476 3663
 	return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3477 3664
 }
@@ -3493,8 +3680,9 @@  discard block
 block discarded – undo
3493 3680
 	global $cacheAPI;
3494 3681
 
3495 3682
 	// If we can't get to the API, can't do this.
3496
-	if (empty($cacheAPI))
3497
-		return;
3683
+	if (empty($cacheAPI)) {
3684
+			return;
3685
+	}
3498 3686
 
3499 3687
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3500 3688
 	$cacheAPI->cleanCache($type);
@@ -3519,8 +3707,9 @@  discard block
 block discarded – undo
3519 3707
 	global $modSettings, $smcFunc, $image_proxy_enabled, $user_info;
3520 3708
 
3521 3709
 	// Come on!
3522
-	if (empty($data))
3523
-		return array();
3710
+	if (empty($data)) {
3711
+			return array();
3712
+	}
3524 3713
 
3525 3714
 	// Set a nice default var.
3526 3715
 	$image = '';
@@ -3528,11 +3717,11 @@  discard block
 block discarded – undo
3528 3717
 	// Gravatar has been set as mandatory!
3529 3718
 	if (!empty($modSettings['gravatarOverride']))
3530 3719
 	{
3531
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3532
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3533
-
3534
-		else if (!empty($data['email']))
3535
-			$image = get_gravatar_url($data['email']);
3720
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3721
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3722
+		} else if (!empty($data['email'])) {
3723
+					$image = get_gravatar_url($data['email']);
3724
+		}
3536 3725
 	}
3537 3726
 
3538 3727
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3544,54 +3733,60 @@  discard block
 block discarded – undo
3544 3733
 			// Gravatar.
3545 3734
 			if (stristr($data['avatar'], 'gravatar://'))
3546 3735
 			{
3547
-				if ($data['avatar'] == 'gravatar://')
3548
-					$image = get_gravatar_url($data['email']);
3549
-
3550
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3551
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3736
+				if ($data['avatar'] == 'gravatar://') {
3737
+									$image = get_gravatar_url($data['email']);
3738
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3739
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3740
+				}
3552 3741
 			}
3553 3742
 
3554 3743
 			// External url.
3555 3744
 			else
3556 3745
 			{
3557 3746
 				// Using ssl?
3558
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3559
-					$image = get_proxied_url($data['avatar']);
3747
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3748
+									$image = get_proxied_url($data['avatar']);
3749
+				}
3560 3750
 
3561 3751
 				// Just a plain external url.
3562
-				else
3563
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3752
+				else {
3753
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3754
+				}
3564 3755
 			}
3565 3756
 		}
3566 3757
 
3567 3758
 		// Perhaps this user has an attachment as avatar...
3568
-		else if (!empty($data['filename']))
3569
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3759
+		else if (!empty($data['filename'])) {
3760
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3761
+		}
3570 3762
 
3571 3763
 		// Right... no avatar... use our default image.
3572
-		else
3573
-			$image = $modSettings['avatar_url'] . '/default.png';
3764
+		else {
3765
+					$image = $modSettings['avatar_url'] . '/default.png';
3766
+		}
3574 3767
 	}
3575 3768
 
3576 3769
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3577 3770
 
3578 3771
 	// 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.
3579
-	if (!empty($image))
3580
-		return array(
3772
+	if (!empty($image)) {
3773
+			return array(
3581 3774
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3582 3775
 			'image' => '<img class="avatar" src="' . $image . '" />',
3583 3776
 			'href' => $image,
3584 3777
 			'url' => $image,
3585 3778
 		);
3779
+	}
3586 3780
 
3587 3781
 	// Fallback to make life easier for everyone...
3588
-	else
3589
-		return array(
3782
+	else {
3783
+			return array(
3590 3784
 			'name' => '',
3591 3785
 			'image' => '',
3592 3786
 			'href' => '',
3593 3787
 			'url' => '',
3594 3788
 		);
3595
-}
3789
+	}
3790
+	}
3596 3791
 
3597 3792
 ?>
3598 3793
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/ManageSmileys.template.php 1 patch
Braces   +58 added lines, -44 removed lines patch added patch discarded remove patch
@@ -34,11 +34,12 @@  discard block
 block discarded – undo
34 34
 		</div>';
35 35
 
36 36
 	// If this is an existing set, and there are still un-added smileys - offer an import opportunity.
37
-	if (!empty($context['current_set']['can_import']))
38
-		echo '
37
+	if (!empty($context['current_set']['can_import'])) {
38
+			echo '
39 39
 		<div class="information noup">
40 40
 			', $context['current_set']['can_import'] == 1 ? sprintf($txt['smiley_set_import_single'], $context['current_set']['import_url']) : sprintf($txt['smiley_set_import_multiple'], $context['current_set']['can_import'], $context['current_set']['import_url']), '
41 41
 		</div>';
42
+	}
42 43
 
43 44
 	echo '
44 45
 		<div class="windowbg noup">
@@ -54,20 +55,20 @@  discard block
 block discarded – undo
54 55
 				</dt>
55 56
 				<dd>
56 57
 					', $modSettings['smileys_url'], '/';
57
-	if ($context['current_set']['id'] == 'default')
58
-		echo '<strong>default</strong><input type="hidden" name="smiley_sets_path" id="smiley_sets_path" value="default">';
59
-
60
-	elseif (empty($context['smiley_set_dirs']))
61
-		echo '
58
+	if ($context['current_set']['id'] == 'default') {
59
+			echo '<strong>default</strong><input type="hidden" name="smiley_sets_path" id="smiley_sets_path" value="default">';
60
+	} elseif (empty($context['smiley_set_dirs'])) {
61
+			echo '
62 62
 					<input type="text" name="smiley_sets_path" id="smiley_sets_path" value="', $context['current_set']['path'], '"> ';
63
-	else
63
+	} else
64 64
 	{
65 65
 		echo '
66 66
 					<select name="smiley_sets_path" id="smiley_sets_path">';
67 67
 
68
-		foreach ($context['smiley_set_dirs'] as $smiley_set_dir)
69
-			echo '
68
+		foreach ($context['smiley_set_dirs'] as $smiley_set_dir) {
69
+					echo '
70 70
 						<option value="', $smiley_set_dir['id'], '"', $smiley_set_dir['current'] ? ' selected' : '', $smiley_set_dir['selectable'] ? '' : ' disabled', '>', $smiley_set_dir['id'], '</option>';
71
+		}
71 72
 		echo '
72 73
 					</select> ';
73 74
 	}
@@ -82,14 +83,15 @@  discard block
 block discarded – undo
82 83
 				</dd>';
83 84
 
84 85
 	// If this is a new smiley set they have the option to import smileys already in the directory.
85
-	if ($context['current_set']['is_new'] && !empty($modSettings['smiley_enable']))
86
-		echo '
86
+	if ($context['current_set']['is_new'] && !empty($modSettings['smiley_enable'])) {
87
+			echo '
87 88
 				<dt>
88 89
 					<strong><label for="smiley_sets_import">', $txt['smiley_set_import_directory'], '</label>: </strong>
89 90
 				</dt>
90 91
 				<dd>
91 92
 					<input type="checkbox" name="smiley_sets_import" id="smiley_sets_import" value="1">
92 93
 				</dd>';
94
+	}
93 95
 
94 96
 	echo '
95 97
 			</dl>
@@ -121,9 +123,10 @@  discard block
 block discarded – undo
121 123
 				<dd>
122 124
 					<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $context['current_smiley']['filename'], '" id="preview" alt=""> ', $txt['smiley_preview_using'], ': <select name="set" onchange="updatePreview();">';
123 125
 
124
-	foreach ($context['smiley_sets'] as $smiley_set)
125
-		echo '
126
+	foreach ($context['smiley_sets'] as $smiley_set) {
127
+			echo '
126 128
 					<option value="', $smiley_set['path'], '"', $context['selected_set'] == $smiley_set['path'] ? ' selected' : '', '>', $smiley_set['name'], '</option>';
129
+	}
127 130
 
128 131
 	echo '
129 132
 					</select>
@@ -139,17 +142,18 @@  discard block
 block discarded – undo
139 142
 				</dt>
140 143
 				<dd>';
141 144
 
142
-	if (empty($context['filenames']))
143
-		echo '
145
+	if (empty($context['filenames'])) {
146
+			echo '
144 147
 					<input type="text" name="smiley_filename" id="smiley_filename" value="', $context['current_smiley']['filename'], '">';
145
-	else
148
+	} else
146 149
 	{
147 150
 		echo '
148 151
 					<select name="smiley_filename" id="smiley_filename" onchange="updatePreview();">';
149 152
 
150
-		foreach ($context['filenames'] as $filename)
151
-			echo '
153
+		foreach ($context['filenames'] as $filename) {
154
+					echo '
152 155
 						<option value="', $filename['id'], '"', $filename['selected'] ? ' selected' : '', '>', $filename['id'], '</option>';
156
+		}
153 157
 		echo '
154 158
 					</select>';
155 159
 	}
@@ -216,9 +220,10 @@  discard block
 block discarded – undo
216 220
 					<dd>
217 221
 						', $txt['smiley_preview_using'], ': <select name="set" onchange="updatePreview();selectMethod(\'existing\');">';
218 222
 
219
-	foreach ($context['smiley_sets'] as $smiley_set)
220
-		echo '
223
+	foreach ($context['smiley_sets'] as $smiley_set) {
224
+			echo '
221 225
 							<option value="', $smiley_set['path'], '"', $context['selected_set'] == $smiley_set['path'] ? ' selected' : '', '>', $smiley_set['name'], '</option>';
226
+	}
222 227
 
223 228
 	echo '
224 229
 						</select>
@@ -228,17 +233,18 @@  discard block
 block discarded – undo
228 233
 					</dt>
229 234
 					<dd>';
230 235
 
231
-	if (empty($context['filenames']))
232
-		echo '
236
+	if (empty($context['filenames'])) {
237
+			echo '
233 238
 						<input type="text" name="smiley_filename" id="smiley_filename" value="', $context['current_smiley']['filename'], '" onchange="selectMethod(\'existing\');">';
234
-	else
239
+	} else
235 240
 	{
236 241
 		echo '
237 242
 						<select name="smiley_filename" id="smiley_filename" onchange="updatePreview();selectMethod(\'existing\');">';
238 243
 
239
-		foreach ($context['filenames'] as $filename)
240
-			echo '
244
+		foreach ($context['filenames'] as $filename) {
245
+					echo '
241 246
 							<option value="', $filename['id'], '"', $filename['selected'] ? ' selected' : '', '>', $filename['id'], '</option>';
247
+		}
242 248
 		echo '
243 249
 						</select>';
244 250
 	}
@@ -267,14 +273,15 @@  discard block
 block discarded – undo
267 273
 
268 274
 			<dl id="uploadMore" style="display: none;" class="settings">';
269 275
 
270
-	foreach ($context['smiley_sets'] as $smiley_set)
271
-		echo '
276
+	foreach ($context['smiley_sets'] as $smiley_set) {
277
+			echo '
272 278
 				<dt>
273 279
 					', sprintf($txt['smileys_add_upload_for'], '<strong>' . $smiley_set['name'] . '</strong>'), ':
274 280
 				</dt>
275 281
 				<dd>
276 282
 					<input type="file" name="individual_', $smiley_set['name'], '" onchange="selectMethod(\'upload\');">
277 283
 				</dd>';
284
+	}
278 285
 
279 286
 	echo '
280 287
 			</dl>
@@ -341,27 +348,30 @@  discard block
 block discarded – undo
341 348
 
342 349
 		foreach ($location['rows'] as $row)
343 350
 		{
344
-			if (!empty($context['move_smiley']))
345
-				echo '
351
+			if (!empty($context['move_smiley'])) {
352
+							echo '
346 353
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';row=', $row[0]['row'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons select_below" title="', $txt['smileys_move_here'], '"></span></a>';
354
+			}
347 355
 
348 356
 			foreach ($row as $smiley)
349 357
 			{
350
-				if (empty($context['move_smiley']))
351
-					echo '
358
+				if (empty($context['move_smiley'])) {
359
+									echo '
352 360
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;move=', $smiley['id'], '"><img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $smiley['filename'], '" alt="', $smiley['description'], '"></a>';
353
-				else
354
-					echo '
361
+				} else {
362
+									echo '
355 363
 			<img src="', $modSettings['smileys_url'], '/', $modSettings['smiley_sets_default'], '/', $smiley['filename'], '" alt="', $smiley['description'], '" ', $smiley['selected'] ? 'class="selected_item"' : '', '>
356 364
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';after=', $smiley['id'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '" title="', $txt['smileys_move_here'], '"><span class="generic_icons select_below" title="', $txt['smileys_move_here'], '"></span></a>';
365
+				}
357 366
 			}
358 367
 
359 368
 			echo '
360 369
 			<br>';
361 370
 		}
362
-		if (!empty($context['move_smiley']))
363
-			echo '
371
+		if (!empty($context['move_smiley'])) {
372
+					echo '
364 373
 			<a href="', $scripturl, '?action=admin;area=smileys;sa=setorder;location=', $location['id'], ';source=', $context['move_smiley'], ';row=', $location['last_row'], ';reorder=1;', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons select_below" title="', $txt['smileys_move_here'], '"></span></a>';
374
+		}
365 375
 		echo '
366 376
 		</div><!-- .windowbg -->
367 377
 		<input type="hidden" name="reorder" value="1">
@@ -394,14 +404,15 @@  discard block
 block discarded – undo
394 404
 		<div class="windowbg">
395 405
 			<dl class="settings">';
396 406
 
397
-	if (!$context['new_icon'])
398
-		echo '
407
+	if (!$context['new_icon']) {
408
+			echo '
399 409
 				<dt>
400 410
 					<strong>', $txt['smiley_preview'], ': </strong>
401 411
 				</dt>
402 412
 				<dd>
403 413
 					<img src="', $context['icon']['image_url'], '" alt="', $context['icon']['title'], '">
404 414
 				</dd>';
415
+	}
405 416
 
406 417
 	echo '
407 418
 				<dt>
@@ -428,9 +439,10 @@  discard block
 block discarded – undo
428 439
 		echo '
429 440
 						<optgroup label="', $category['name'], '">';
430 441
 
431
-		foreach ($category['boards'] as $board)
432
-			echo '
442
+		foreach ($category['boards'] as $board) {
443
+					echo '
433 444
 							<option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=&gt;' : '', ' ', $board['name'], '</option>';
445
+		}
434 446
 
435 447
 		echo '
436 448
 						</optgroup>';
@@ -447,19 +459,21 @@  discard block
 block discarded – undo
447 459
 						<option value="0"', empty($context['icon']['after']) ? ' selected' : '', '>', $txt['icons_location_first_icon'], '</option>';
448 460
 
449 461
 	// Print the list of all the icons it can be put after...
450
-	foreach ($context['icons'] as $id => $data)
451
-		if (empty($context['icon']['id']) || $id != $context['icon']['id'])
462
+	foreach ($context['icons'] as $id => $data) {
463
+			if (empty($context['icon']['id']) || $id != $context['icon']['id'])
452 464
 			echo '
453 465
 						<option value="', $id, '"', !empty($context['icon']['after']) && $id == $context['icon']['after'] ? ' selected' : '', '>', $txt['icons_location_after'], ': ', $data['title'], '</option>';
466
+	}
454 467
 
455 468
 	echo '
456 469
 					</select>
457 470
 				</dd>
458 471
 			</dl>';
459 472
 
460
-	if (!$context['new_icon'])
461
-		echo '
473
+	if (!$context['new_icon']) {
474
+			echo '
462 475
 			<input type="hidden" name="icon" value="', $context['icon']['id'], '">';
476
+	}
463 477
 
464 478
 	echo '
465 479
 			<input type="submit" name="icons_save" value="', $txt['smileys_save'], '" class="button">
Please login to merge, or discard this patch.
Sources/Post.php 1 patch
Braces   +677 added lines, -523 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -60,12 +63,14 @@  discard block
 block discarded – undo
60 63
 	{
61 64
 		// Get ids of all the boards they can post in.
62 65
 		$post_permissions = array('post_new');
63
-		if ($modSettings['postmod_active'])
64
-			$post_permissions[] = 'post_unapproved_topics';
66
+		if ($modSettings['postmod_active']) {
67
+					$post_permissions[] = 'post_unapproved_topics';
68
+		}
65 69
 
66 70
 		$boards = boardsAllowedTo($post_permissions);
67
-		if (empty($boards))
68
-			fatal_lang_error('cannot_post_new', false);
71
+		if (empty($boards)) {
72
+					fatal_lang_error('cannot_post_new', false);
73
+		}
69 74
 
70 75
 		// Get a list of boards for the select menu
71 76
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -78,8 +83,9 @@  discard block
 block discarded – undo
78 83
 		$board_list = getBoardList($boardListOptions);
79 84
 	}
80 85
 	// Let's keep things simple for ourselves below
81
-	else
82
-		$boards = array($board);
86
+	else {
87
+			$boards = array($board);
88
+	}
83 89
 
84 90
 	require_once($sourcedir . '/Subs-Post.php');
85 91
 
@@ -102,10 +108,11 @@  discard block
 block discarded – undo
102 108
 			array(
103 109
 				'msg' => (int) $_REQUEST['msg'],
104 110
 		));
105
-		if ($smcFunc['db_num_rows']($request) != 1)
106
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
107
-		else
108
-			list ($topic) = $smcFunc['db_fetch_row']($request);
111
+		if ($smcFunc['db_num_rows']($request) != 1) {
112
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
113
+		} else {
114
+					list ($topic) = $smcFunc['db_fetch_row']($request);
115
+		}
109 116
 		$smcFunc['db_free_result']($request);
110 117
 	}
111 118
 
@@ -132,33 +139,36 @@  discard block
 block discarded – undo
132 139
 		$smcFunc['db_free_result']($request);
133 140
 
134 141
 		// If this topic already has a poll, they sure can't add another.
135
-		if (isset($_REQUEST['poll']) && $pollID > 0)
136
-			unset($_REQUEST['poll']);
142
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
143
+					unset($_REQUEST['poll']);
144
+		}
137 145
 
138 146
 		if (empty($_REQUEST['msg']))
139 147
 		{
140
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
141
-				is_not_guest();
148
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
149
+							is_not_guest();
150
+			}
142 151
 
143 152
 			// By default the reply will be approved...
144 153
 			$context['becomes_approved'] = true;
145 154
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
146 155
 			{
147
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
148
-					$context['becomes_approved'] = false;
149
-				else
150
-					isAllowedTo('post_reply_any');
151
-			}
152
-			elseif (!allowedTo('post_reply_any'))
156
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
157
+									$context['becomes_approved'] = false;
158
+				} else {
159
+									isAllowedTo('post_reply_any');
160
+				}
161
+			} elseif (!allowedTo('post_reply_any'))
153 162
 			{
154
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
155
-					$context['becomes_approved'] = false;
156
-				else
157
-					isAllowedTo('post_reply_own');
163
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
164
+									$context['becomes_approved'] = false;
165
+				} else {
166
+									isAllowedTo('post_reply_own');
167
+				}
158 168
 			}
169
+		} else {
170
+					$context['becomes_approved'] = true;
159 171
 		}
160
-		else
161
-			$context['becomes_approved'] = true;
162 172
 
163 173
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
164 174
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -173,17 +183,18 @@  discard block
 block discarded – undo
173 183
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
174 184
 
175 185
 		// Check whether this is a really old post being bumped...
176
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
177
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
178
-	}
179
-	else
186
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
187
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
188
+		}
189
+	} else
180 190
 	{
181 191
 		// @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu
182 192
 		$context['becomes_approved'] = true;
183
-		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true))
184
-			$context['becomes_approved'] = false;
185
-		else
186
-			isAllowedTo('post_new', $boards, true);
193
+		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) {
194
+					$context['becomes_approved'] = false;
195
+		} else {
196
+					isAllowedTo('post_new', $boards, true);
197
+		}
187 198
 
188 199
 		$locked = 0;
189 200
 		$context['already_locked'] = 0;
@@ -213,27 +224,32 @@  discard block
 block discarded – undo
213 224
 	if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached']))
214 225
 	{
215 226
 		require_once($sourcedir . '/ManageAttachments.php');
216
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
217
-			removeAttachments(array('id_attach' => $attachID));
227
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
228
+					removeAttachments(array('id_attach' => $attachID));
229
+		}
218 230
 
219 231
 		unset($_SESSION['already_attached']);
220 232
 	}
221 233
 
222 234
 	// Don't allow a post if it's locked and you aren't all powerful.
223
-	if ($locked && !allowedTo('moderate_board'))
224
-		fatal_lang_error('topic_locked', false);
235
+	if ($locked && !allowedTo('moderate_board')) {
236
+			fatal_lang_error('topic_locked', false);
237
+	}
225 238
 	// Check the users permissions - is the user allowed to add or post a poll?
226 239
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
227 240
 	{
228 241
 		// New topic, new poll.
229
-		if (empty($topic))
230
-			isAllowedTo('poll_post');
242
+		if (empty($topic)) {
243
+					isAllowedTo('poll_post');
244
+		}
231 245
 		// This is an old topic - but it is yours!  Can you add to it?
232
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
233
-			isAllowedTo('poll_add_own');
246
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
247
+					isAllowedTo('poll_add_own');
248
+		}
234 249
 		// If you're not the owner, can you add to any poll?
235
-		else
236
-			isAllowedTo('poll_add_any');
250
+		else {
251
+					isAllowedTo('poll_add_any');
252
+		}
237 253
 
238 254
 		if (!empty($board))
239 255
 		{
@@ -242,8 +258,9 @@  discard block
 block discarded – undo
242 258
 			$guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']);
243 259
 		}
244 260
 		// No board, so we'll have to check this again in Post2
245
-		else
246
-			$guest_vote_enabled = true;
261
+		else {
262
+					$guest_vote_enabled = true;
263
+		}
247 264
 
248 265
 		// Set up the poll options.
249 266
 		$context['poll_options'] = array(
@@ -269,8 +286,9 @@  discard block
 block discarded – undo
269 286
 	if ($context['make_event'])
270 287
 	{
271 288
 		// They might want to pick a board.
272
-		if (!isset($context['current_board']))
273
-			$context['current_board'] = 0;
289
+		if (!isset($context['current_board'])) {
290
+					$context['current_board'] = 0;
291
+		}
274 292
 
275 293
 		// Start loading up the event info.
276 294
 		$context['event'] = array();
@@ -284,10 +302,11 @@  discard block
 block discarded – undo
284 302
 		isAllowedTo('calendar_post');
285 303
 
286 304
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
287
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
288
-			$time_string = '%k:%M';
289
-		else
290
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
305
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
306
+					$time_string = '%k:%M';
307
+		} else {
308
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
309
+		}
291 310
 
292 311
 		$js_time_string = str_replace(
293 312
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -309,8 +328,7 @@  discard block
 block discarded – undo
309 328
 			require_once($sourcedir . '/Subs-Calendar.php');
310 329
 			$eventProperties = getEventProperties($context['event']['id']);
311 330
 			$context['event'] = array_merge($context['event'], $eventProperties);
312
-		}
313
-		else
331
+		} else
314 332
 		{
315 333
 			// Get the current event information.
316 334
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -318,10 +336,12 @@  discard block
 block discarded – undo
318 336
 			$context['event'] = array_merge($context['event'], $eventProperties);
319 337
 
320 338
 			// Make sure the year and month are in the valid range.
321
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
322
-				fatal_lang_error('invalid_month', false);
323
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
324
-				fatal_lang_error('invalid_year', false);
339
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
340
+							fatal_lang_error('invalid_month', false);
341
+			}
342
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
343
+							fatal_lang_error('invalid_year', false);
344
+			}
325 345
 
326 346
 			$context['event']['categories'] = $board_list;
327 347
 		}
@@ -432,10 +452,11 @@  discard block
 block discarded – undo
432 452
 
433 453
 			if (!empty($context['new_replies']))
434 454
 			{
435
-				if ($context['new_replies'] == 1)
436
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
437
-				else
438
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
455
+				if ($context['new_replies'] == 1) {
456
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
457
+				} else {
458
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
459
+				}
439 460
 
440 461
 				$post_errors[] = 'new_replies';
441 462
 
@@ -447,9 +468,9 @@  discard block
 block discarded – undo
447 468
 	// Get a response prefix (like 'Re:') in the default forum language.
448 469
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
449 470
 	{
450
-		if ($language === $user_info['language'])
451
-			$context['response_prefix'] = $txt['response_prefix'];
452
-		else
471
+		if ($language === $user_info['language']) {
472
+					$context['response_prefix'] = $txt['response_prefix'];
473
+		} else
453 474
 		{
454 475
 			loadLanguage('index', $language, false);
455 476
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -462,23 +483,26 @@  discard block
 block discarded – undo
462 483
 	// Do we have a body, but an error happened.
463 484
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
464 485
 	{
465
-		if (isset($_REQUEST['quickReply']))
466
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
486
+		if (isset($_REQUEST['quickReply'])) {
487
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
488
+		}
467 489
 
468 490
 		// Validate inputs.
469 491
 		if (empty($context['post_error']))
470 492
 		{
471 493
 			// This means they didn't click Post and get an error.
472 494
 			$really_previewing = true;
473
-		}
474
-		else
495
+		} else
475 496
 		{
476
-			if (!isset($_REQUEST['subject']))
477
-				$_REQUEST['subject'] = '';
478
-			if (!isset($_REQUEST['message']))
479
-				$_REQUEST['message'] = '';
480
-			if (!isset($_REQUEST['icon']))
481
-				$_REQUEST['icon'] = 'xx';
497
+			if (!isset($_REQUEST['subject'])) {
498
+							$_REQUEST['subject'] = '';
499
+			}
500
+			if (!isset($_REQUEST['message'])) {
501
+							$_REQUEST['message'] = '';
502
+			}
503
+			if (!isset($_REQUEST['icon'])) {
504
+							$_REQUEST['icon'] = 'xx';
505
+			}
482 506
 
483 507
 			// They are previewing if they asked to preview (i.e. came from quick reply).
484 508
 			$really_previewing = !empty($_POST['preview']);
@@ -494,8 +518,9 @@  discard block
 block discarded – undo
494 518
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
495 519
 
496 520
 		// Make sure the subject isn't too long - taking into account special characters.
497
-		if ($smcFunc['strlen']($form_subject) > 100)
498
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
521
+		if ($smcFunc['strlen']($form_subject) > 100) {
522
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
523
+		}
499 524
 
500 525
 		if (isset($_REQUEST['poll']))
501 526
 		{
@@ -507,8 +532,9 @@  discard block
 block discarded – undo
507 532
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
508 533
 			foreach ($_POST['options'] as $option)
509 534
 			{
510
-				if (trim($option) == '')
511
-					continue;
535
+				if (trim($option) == '') {
536
+									continue;
537
+				}
512 538
 
513 539
 				$context['choices'][] = array(
514 540
 					'id' => $choice_id++,
@@ -570,13 +596,14 @@  discard block
 block discarded – undo
570 596
 				$context['preview_subject'] = $form_subject;
571 597
 
572 598
 				censorText($context['preview_subject']);
599
+			} else {
600
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
573 601
 			}
574
-			else
575
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
576 602
 
577 603
 			// Protect any CDATA blocks.
578
-			if (isset($_REQUEST['xml']))
579
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
604
+			if (isset($_REQUEST['xml'])) {
605
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
606
+			}
580 607
 		}
581 608
 
582 609
 		// Set up the checkboxes.
@@ -615,29 +642,32 @@  discard block
 block discarded – undo
615 642
 			);
616 643
 			// The message they were trying to edit was most likely deleted.
617 644
 			// @todo Change this error message?
618
-			if ($smcFunc['db_num_rows']($request) == 0)
619
-				fatal_lang_error('no_board', false);
645
+			if ($smcFunc['db_num_rows']($request) == 0) {
646
+							fatal_lang_error('no_board', false);
647
+			}
620 648
 			$row = $smcFunc['db_fetch_assoc']($request);
621 649
 
622 650
 			$attachment_stuff = array($row);
623
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
624
-				$attachment_stuff[] = $row2;
651
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
652
+							$attachment_stuff[] = $row2;
653
+			}
625 654
 			$smcFunc['db_free_result']($request);
626 655
 
627 656
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
628 657
 			{
629 658
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
630
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
631
-					fatal_lang_error('modify_post_time_passed', false);
632
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
633
-					isAllowedTo('modify_replies');
634
-				else
635
-					isAllowedTo('modify_own');
659
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
660
+									fatal_lang_error('modify_post_time_passed', false);
661
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
662
+									isAllowedTo('modify_replies');
663
+				} else {
664
+									isAllowedTo('modify_own');
665
+				}
666
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
667
+							isAllowedTo('modify_replies');
668
+			} else {
669
+							isAllowedTo('modify_any');
636 670
 			}
637
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
638
-				isAllowedTo('modify_replies');
639
-			else
640
-				isAllowedTo('modify_any');
641 671
 
642 672
 			if ($context['can_announce'] && !empty($row['id_action']))
643 673
 			{
@@ -661,8 +691,9 @@  discard block
 block discarded – undo
661 691
 
662 692
 				while ($row = $smcFunc['db_fetch_assoc']($request))
663 693
 				{
664
-					if ($row['filesize'] <= 0)
665
-						continue;
694
+					if ($row['filesize'] <= 0) {
695
+											continue;
696
+					}
666 697
 					$context['current_attachments'][$row['id_attach']] = array(
667 698
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
668 699
 						'size' => $row['filesize'],
@@ -732,29 +763,32 @@  discard block
 block discarded – undo
732 763
 			)
733 764
 		);
734 765
 		// The message they were trying to edit was most likely deleted.
735
-		if ($smcFunc['db_num_rows']($request) == 0)
736
-			fatal_lang_error('no_message', false);
766
+		if ($smcFunc['db_num_rows']($request) == 0) {
767
+					fatal_lang_error('no_message', false);
768
+		}
737 769
 		$row = $smcFunc['db_fetch_assoc']($request);
738 770
 
739 771
 		$attachment_stuff = array($row);
740
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
741
-			$attachment_stuff[] = $row2;
772
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
773
+					$attachment_stuff[] = $row2;
774
+		}
742 775
 		$smcFunc['db_free_result']($request);
743 776
 
744 777
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
745 778
 		{
746 779
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
747
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
748
-				fatal_lang_error('modify_post_time_passed', false);
749
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
750
-				isAllowedTo('modify_replies');
751
-			else
752
-				isAllowedTo('modify_own');
780
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
781
+							fatal_lang_error('modify_post_time_passed', false);
782
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
783
+							isAllowedTo('modify_replies');
784
+			} else {
785
+							isAllowedTo('modify_own');
786
+			}
787
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
788
+					isAllowedTo('modify_replies');
789
+		} else {
790
+					isAllowedTo('modify_any');
753 791
 		}
754
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
755
-			isAllowedTo('modify_replies');
756
-		else
757
-			isAllowedTo('modify_any');
758 792
 
759 793
 		if ($context['can_announce'] && !empty($row['id_action']))
760 794
 		{
@@ -781,15 +815,17 @@  discard block
 block discarded – undo
781 815
 		$context['icon'] = $row['icon'];
782 816
 
783 817
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
784
-		if (!$row['approved'] && !$context['show_approval'])
785
-			$context['show_approval'] = allowedTo('approve_posts');
818
+		if (!$row['approved'] && !$context['show_approval']) {
819
+					$context['show_approval'] = allowedTo('approve_posts');
820
+		}
786 821
 
787 822
 		// Sort the attachments so they are in the order saved
788 823
 		$temp = array();
789 824
 		foreach ($attachment_stuff as $attachment)
790 825
 		{
791
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
792
-				$temp[$attachment['id_attach']] = $attachment;
826
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
827
+							$temp[$attachment['id_attach']] = $attachment;
828
+			}
793 829
 		}
794 830
 		ksort($temp);
795 831
 
@@ -850,14 +886,16 @@  discard block
 block discarded – undo
850 886
 					'is_approved' => 1,
851 887
 				)
852 888
 			);
853
-			if ($smcFunc['db_num_rows']($request) == 0)
854
-				fatal_lang_error('quoted_post_deleted', false);
889
+			if ($smcFunc['db_num_rows']($request) == 0) {
890
+							fatal_lang_error('quoted_post_deleted', false);
891
+			}
855 892
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
856 893
 			$smcFunc['db_free_result']($request);
857 894
 
858 895
 			// Add 'Re: ' to the front of the quoted subject.
859
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
860
-				$form_subject = $context['response_prefix'] . $form_subject;
896
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
897
+							$form_subject = $context['response_prefix'] . $form_subject;
898
+			}
861 899
 
862 900
 			// Censor the message and subject.
863 901
 			censorText($form_message);
@@ -870,10 +908,11 @@  discard block
 block discarded – undo
870 908
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
871 909
 				{
872 910
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
873
-					if ($i % 4 == 0)
874
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
911
+					if ($i % 4 == 0) {
912
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
875 913
 						{
876 914
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
915
+					}
877 916
 						}, $parts[$i]);
878 917
 				}
879 918
 				$form_message = implode('', $parts);
@@ -882,8 +921,9 @@  discard block
 block discarded – undo
882 921
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
883 922
 
884 923
 			// Remove any nested quotes, if necessary.
885
-			if (!empty($modSettings['removeNestedQuotes']))
886
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
924
+			if (!empty($modSettings['removeNestedQuotes'])) {
925
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
926
+			}
887 927
 
888 928
 			// Add a quote string on the front and end.
889 929
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -895,15 +935,15 @@  discard block
 block discarded – undo
895 935
 			$form_subject = $first_subject;
896 936
 
897 937
 			// Add 'Re: ' to the front of the subject.
898
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
899
-				$form_subject = $context['response_prefix'] . $form_subject;
938
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
939
+							$form_subject = $context['response_prefix'] . $form_subject;
940
+			}
900 941
 
901 942
 			// Censor the subject.
902 943
 			censorText($form_subject);
903 944
 
904 945
 			$form_message = '';
905
-		}
906
-		else
946
+		} else
907 947
 		{
908 948
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
909 949
 			$form_message = '';
@@ -922,13 +962,15 @@  discard block
 block discarded – undo
922 962
 		if (isset($_REQUEST['msg']))
923 963
 		{
924 964
 			$context['attachments']['quantity'] = count($context['current_attachments']);
925
-			foreach ($context['current_attachments'] as $attachment)
926
-				$context['attachments']['total_size'] += $attachment['size'];
965
+			foreach ($context['current_attachments'] as $attachment) {
966
+							$context['attachments']['total_size'] += $attachment['size'];
967
+			}
927 968
 		}
928 969
 
929 970
 		// A bit of house keeping first.
930
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
931
-			unset($_SESSION['temp_attachments']);
971
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
972
+					unset($_SESSION['temp_attachments']);
973
+		}
932 974
 
933 975
 		if (!empty($_SESSION['temp_attachments']))
934 976
 		{
@@ -937,9 +979,10 @@  discard block
 block discarded – undo
937 979
 			{
938 980
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
939 981
 				{
940
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
941
-						if (file_exists($attachment['tmp_name']))
982
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
983
+											if (file_exists($attachment['tmp_name']))
942 984
 							unlink($attachment['tmp_name']);
985
+					}
943 986
 				}
944 987
 				$post_errors[] = 'temp_attachments_gone';
945 988
 				$_SESSION['temp_attachments'] = array();
@@ -953,8 +996,9 @@  discard block
 block discarded – undo
953 996
 					// See if any files still exist before showing the warning message and the files attached.
954 997
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
955 998
 					{
956
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
957
-							continue;
999
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1000
+													continue;
1001
+						}
958 1002
 
959 1003
 						if (file_exists($attachment['tmp_name']))
960 1004
 						{
@@ -964,20 +1008,21 @@  discard block
 block discarded – undo
964 1008
 							break;
965 1009
 						}
966 1010
 					}
967
-				}
968
-				else
1011
+				} else
969 1012
 				{
970 1013
 					// Since, they don't belong here. Let's inform the user that they exist..
971
-					if (!empty($topic))
972
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
973
-					else
974
-						$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1014
+					if (!empty($topic)) {
1015
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
1016
+					} else {
1017
+											$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1018
+					}
975 1019
 
976 1020
 					// Compile a list of the files to show the user.
977 1021
 					$file_list = array();
978
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
979
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1022
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1023
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
980 1024
 							$file_list[] = $attachment['name'];
1025
+					}
981 1026
 
982 1027
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
983 1028
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -989,8 +1034,7 @@  discard block
 block discarded – undo
989 1034
 
990 1035
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
991 1036
 						$context['ignore_temp_attachments'] = true;
992
-					}
993
-					else
1037
+					} else
994 1038
 					{
995 1039
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
996 1040
 						$context['ignore_temp_attachments'] = true;
@@ -998,16 +1042,19 @@  discard block
 block discarded – undo
998 1042
 				}
999 1043
 			}
1000 1044
 
1001
-			if (!empty($context['we_are_history']))
1002
-				$post_errors[] = $context['we_are_history'];
1045
+			if (!empty($context['we_are_history'])) {
1046
+							$post_errors[] = $context['we_are_history'];
1047
+			}
1003 1048
 
1004 1049
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1005 1050
 			{
1006
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
1007
-					break;
1051
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1052
+									break;
1053
+				}
1008 1054
 
1009
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1010
-					continue;
1055
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1056
+									continue;
1057
+				}
1011 1058
 
1012 1059
 				if ($attachID == 'initial_error')
1013 1060
 				{
@@ -1022,15 +1069,17 @@  discard block
 block discarded – undo
1022 1069
 				{
1023 1070
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1024 1071
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1025
-					foreach ($attachment['errors'] as $error)
1026
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1072
+					foreach ($attachment['errors'] as $error) {
1073
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1074
+					}
1027 1075
 					$txt['error_attach_errors'] .= '</div>';
1028 1076
 					$post_errors[] = 'attach_errors';
1029 1077
 
1030 1078
 					// Take out the trash.
1031 1079
 					unset($_SESSION['temp_attachments'][$attachID]);
1032
-					if (file_exists($attachment['tmp_name']))
1033
-						unlink($attachment['tmp_name']);
1080
+					if (file_exists($attachment['tmp_name'])) {
1081
+											unlink($attachment['tmp_name']);
1082
+					}
1034 1083
 					continue;
1035 1084
 				}
1036 1085
 
@@ -1043,8 +1092,9 @@  discard block
 block discarded – undo
1043 1092
 
1044 1093
 				$context['attachments']['quantity']++;
1045 1094
 				$context['attachments']['total_size'] += $attachment['size'];
1046
-				if (!isset($context['files_in_session_warning']))
1047
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1095
+				if (!isset($context['files_in_session_warning'])) {
1096
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1097
+				}
1048 1098
 
1049 1099
 				$context['current_attachments'][$attachID] = array(
1050 1100
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1072,8 +1122,9 @@  discard block
 block discarded – undo
1072 1122
 	}
1073 1123
 
1074 1124
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1075
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1076
-		$post_errors[] = 'need_qr_verification';
1125
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1126
+			$post_errors[] = 'need_qr_verification';
1127
+	}
1077 1128
 
1078 1129
 	/*
1079 1130
 	 * There are two error types: serious and minor. Serious errors
@@ -1090,52 +1141,56 @@  discard block
 block discarded – undo
1090 1141
 	{
1091 1142
 		loadLanguage('Errors');
1092 1143
 		$context['error_type'] = 'minor';
1093
-		foreach ($post_errors as $post_error)
1094
-			if (is_array($post_error))
1144
+		foreach ($post_errors as $post_error) {
1145
+					if (is_array($post_error))
1095 1146
 			{
1096 1147
 				$post_error_id = $post_error[0];
1148
+		}
1097 1149
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1098 1150
 
1099 1151
 				// If it's not a minor error flag it as such.
1100
-				if (!in_array($post_error_id, $minor_errors))
1101
-					$context['error_type'] = 'serious';
1102
-			}
1103
-			else
1152
+				if (!in_array($post_error_id, $minor_errors)) {
1153
+									$context['error_type'] = 'serious';
1154
+				}
1155
+			} else
1104 1156
 			{
1105 1157
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1106 1158
 
1107 1159
 				// If it's not a minor error flag it as such.
1108
-				if (!in_array($post_error, $minor_errors))
1109
-					$context['error_type'] = 'serious';
1160
+				if (!in_array($post_error, $minor_errors)) {
1161
+									$context['error_type'] = 'serious';
1162
+				}
1110 1163
 			}
1111 1164
 	}
1112 1165
 
1113 1166
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1114
-	if (isset($_REQUEST['poll']))
1115
-		$context['page_title'] = $txt['new_poll'];
1116
-	elseif ($context['make_event'])
1117
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1118
-	elseif (isset($_REQUEST['msg']))
1119
-		$context['page_title'] = $txt['modify_msg'];
1120
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1121
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1122
-	elseif (empty($topic))
1123
-		$context['page_title'] = $txt['start_new_topic'];
1124
-	else
1125
-		$context['page_title'] = $txt['post_reply'];
1167
+	if (isset($_REQUEST['poll'])) {
1168
+			$context['page_title'] = $txt['new_poll'];
1169
+	} elseif ($context['make_event']) {
1170
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1171
+	} elseif (isset($_REQUEST['msg'])) {
1172
+			$context['page_title'] = $txt['modify_msg'];
1173
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1174
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1175
+	} elseif (empty($topic)) {
1176
+			$context['page_title'] = $txt['start_new_topic'];
1177
+	} else {
1178
+			$context['page_title'] = $txt['post_reply'];
1179
+	}
1126 1180
 
1127 1181
 	// Build the link tree.
1128
-	if (empty($topic))
1129
-		$context['linktree'][] = array(
1182
+	if (empty($topic)) {
1183
+			$context['linktree'][] = array(
1130 1184
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1131 1185
 		);
1132
-	else
1133
-		$context['linktree'][] = array(
1186
+	} else {
1187
+			$context['linktree'][] = array(
1134 1188
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1135 1189
 			'name' => $form_subject,
1136 1190
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1137 1191
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1138 1192
 		);
1193
+	}
1139 1194
 
1140 1195
 	$context['subject'] = addcslashes($form_subject, '"');
1141 1196
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1179,8 +1234,9 @@  discard block
 block discarded – undo
1179 1234
 	// Message icons - customized icons are off?
1180 1235
 	$context['icons'] = getMessageIcons(!empty($board) ? $board : 0);
1181 1236
 
1182
-	if (!empty($context['icons']))
1183
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1237
+	if (!empty($context['icons'])) {
1238
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1239
+	}
1184 1240
 
1185 1241
 	// Are we starting a poll? if set the poll icon as selected if its available
1186 1242
 	if (isset($_REQUEST['poll']))
@@ -1200,8 +1256,9 @@  discard block
 block discarded – undo
1200 1256
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1201 1257
 	{
1202 1258
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1203
-		if ($context['icons'][$i]['selected'])
1204
-			$context['icon_url'] = $context['icons'][$i]['url'];
1259
+		if ($context['icons'][$i]['selected']) {
1260
+					$context['icon_url'] = $context['icons'][$i]['url'];
1261
+		}
1205 1262
 	}
1206 1263
 	if (empty($context['icon_url']))
1207 1264
 	{
@@ -1215,8 +1272,9 @@  discard block
 block discarded – undo
1215 1272
 		));
1216 1273
 	}
1217 1274
 
1218
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1219
-		getTopic();
1275
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1276
+			getTopic();
1277
+	}
1220 1278
 
1221 1279
 	// If the user can post attachments prepare the warning labels.
1222 1280
 	if ($context['can_post_attachment'])
@@ -1227,12 +1285,13 @@  discard block
 block discarded – undo
1227 1285
 		$context['attachment_restrictions'] = array();
1228 1286
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1229 1287
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1230
-		foreach ($attachmentRestrictionTypes as $type)
1231
-			if (!empty($modSettings[$type]))
1288
+		foreach ($attachmentRestrictionTypes as $type) {
1289
+					if (!empty($modSettings[$type]))
1232 1290
 			{
1233 1291
 				// Show the max number of attachments if not 0.
1234 1292
 				if ($type == 'attachmentNumPerPostLimit')
1235 1293
 					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1294
+		}
1236 1295
 			}
1237 1296
 	}
1238 1297
 
@@ -1266,8 +1325,8 @@  discard block
 block discarded – undo
1266 1325
 
1267 1326
 	if (!empty($context['current_attachments']))
1268 1327
 	{
1269
-		foreach ($context['current_attachments'] as $key => $mock)
1270
-			addInlineJavaScript('
1328
+		foreach ($context['current_attachments'] as $key => $mock) {
1329
+					addInlineJavaScript('
1271 1330
 	current_attachments.push({
1272 1331
 		name: '. JavaScriptEscape($mock['name']) . ',
1273 1332
 		size: '. $mock['size'] . ',
@@ -1276,6 +1335,7 @@  discard block
 block discarded – undo
1276 1335
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1277 1336
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1278 1337
 	});');
1338
+		}
1279 1339
 	}
1280 1340
 
1281 1341
 	// File Upload.
@@ -1374,12 +1434,13 @@  discard block
 block discarded – undo
1374 1434
 		{
1375 1435
 			$context['posting_fields']['board']['input']['options'][$category['name']] = array('options' => array());
1376 1436
 
1377
-			foreach ($category['boards'] as $brd)
1378
-				$context['posting_fields']['board']['input']['options'][$category['name']]['options'][$brd['name']]['attributes'] = array(
1437
+			foreach ($category['boards'] as $brd) {
1438
+							$context['posting_fields']['board']['input']['options'][$category['name']]['options'][$brd['name']]['attributes'] = array(
1379 1439
 					'value' => $brd['id'],
1380 1440
 					'selected' => (bool) $brd['selected'],
1381 1441
 					'label' => ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=&gt;' : '') . ' ' . $brd['name'],
1382 1442
 				);
1443
+			}
1383 1444
 		}
1384 1445
 	}
1385 1446
 
@@ -1425,8 +1486,9 @@  discard block
 block discarded – undo
1425 1486
 
1426 1487
 
1427 1488
 	// Finally, load the template.
1428
-	if (!isset($_REQUEST['xml']))
1429
-		loadTemplate('Post');
1489
+	if (!isset($_REQUEST['xml'])) {
1490
+			loadTemplate('Post');
1491
+	}
1430 1492
 
1431 1493
 	call_integration_hook('integrate_post_end');
1432 1494
 }
@@ -1447,13 +1509,14 @@  discard block
 block discarded – undo
1447 1509
 	// Sneaking off, are we?
1448 1510
 	if (empty($_POST) && empty($topic))
1449 1511
 	{
1450
-		if (empty($_SERVER['CONTENT_LENGTH']))
1451
-			redirectexit('action=post;board=' . $board . '.0');
1452
-		else
1453
-			fatal_lang_error('post_upload_error', false);
1512
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1513
+					redirectexit('action=post;board=' . $board . '.0');
1514
+		} else {
1515
+					fatal_lang_error('post_upload_error', false);
1516
+		}
1517
+	} elseif (empty($_POST) && !empty($topic)) {
1518
+			redirectexit('action=post;topic=' . $topic . '.0');
1454 1519
 	}
1455
-	elseif (empty($_POST) && !empty($topic))
1456
-		redirectexit('action=post;topic=' . $topic . '.0');
1457 1520
 
1458 1521
 	// No need!
1459 1522
 	$context['robot_no_index'] = true;
@@ -1465,8 +1528,9 @@  discard block
 block discarded – undo
1465 1528
 	$post_errors = array();
1466 1529
 
1467 1530
 	// If the session has timed out, let the user re-submit their form.
1468
-	if (checkSession('post', '', false) != '')
1469
-		$post_errors[] = 'session_timeout';
1531
+	if (checkSession('post', '', false) != '') {
1532
+			$post_errors[] = 'session_timeout';
1533
+	}
1470 1534
 
1471 1535
 	// Wrong verification code?
1472 1536
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1476,8 +1540,9 @@  discard block
 block discarded – undo
1476 1540
 			'id' => 'post',
1477 1541
 		);
1478 1542
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1479
-		if (is_array($context['require_verification']))
1480
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1543
+		if (is_array($context['require_verification'])) {
1544
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1545
+		}
1481 1546
 	}
1482 1547
 
1483 1548
 	require_once($sourcedir . '/Subs-Post.php');
@@ -1486,25 +1551,29 @@  discard block
 block discarded – undo
1486 1551
 	call_integration_hook('integrate_post2_start');
1487 1552
 
1488 1553
 	// Drafts enabled and needed?
1489
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1490
-		require_once($sourcedir . '/Drafts.php');
1554
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1555
+			require_once($sourcedir . '/Drafts.php');
1556
+	}
1491 1557
 
1492 1558
 	// First check to see if they are trying to delete any current attachments.
1493 1559
 	if (isset($_POST['attach_del']))
1494 1560
 	{
1495 1561
 		$keep_temp = array();
1496 1562
 		$keep_ids = array();
1497
-		foreach ($_POST['attach_del'] as $dummy)
1498
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1563
+		foreach ($_POST['attach_del'] as $dummy) {
1564
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1499 1565
 				$keep_temp[] = $dummy;
1500
-			else
1501
-				$keep_ids[] = (int) $dummy;
1566
+		}
1567
+			else {
1568
+							$keep_ids[] = (int) $dummy;
1569
+			}
1502 1570
 
1503
-		if (isset($_SESSION['temp_attachments']))
1504
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1571
+		if (isset($_SESSION['temp_attachments'])) {
1572
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1505 1573
 			{
1506 1574
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1507 1575
 					continue;
1576
+		}
1508 1577
 
1509 1578
 				unset($_SESSION['temp_attachments'][$attachID]);
1510 1579
 				unlink($attachment['tmp_name']);
@@ -1536,8 +1605,9 @@  discard block
 block discarded – undo
1536 1605
 	{
1537 1606
 		require_once($sourcedir . '/ManageAttachments.php');
1538 1607
 
1539
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
1540
-			removeAttachments(array('id_attach' => $attachID));
1608
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
1609
+					removeAttachments(array('id_attach' => $attachID));
1610
+		}
1541 1611
 
1542 1612
 		unset($_SESSION['already_attached']);
1543 1613
 
@@ -1560,12 +1630,14 @@  discard block
 block discarded – undo
1560 1630
 		$smcFunc['db_free_result']($request);
1561 1631
 
1562 1632
 		// Though the topic should be there, it might have vanished.
1563
-		if (!is_array($topic_info))
1564
-			fatal_lang_error('topic_doesnt_exist', 404);
1633
+		if (!is_array($topic_info)) {
1634
+					fatal_lang_error('topic_doesnt_exist', 404);
1635
+		}
1565 1636
 
1566 1637
 		// Did this topic suddenly move? Just checking...
1567
-		if ($topic_info['id_board'] != $board)
1568
-			fatal_lang_error('not_a_topic');
1638
+		if ($topic_info['id_board'] != $board) {
1639
+					fatal_lang_error('not_a_topic');
1640
+		}
1569 1641
 
1570 1642
 		// Do the permissions and approval stuff...
1571 1643
 		$becomesApproved = true;
@@ -1588,49 +1660,50 @@  discard block
 block discarded – undo
1588 1660
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1589 1661
 	{
1590 1662
 		// Don't allow a post if it's locked.
1591
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1592
-			fatal_lang_error('topic_locked', false);
1663
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1664
+					fatal_lang_error('topic_locked', false);
1665
+		}
1593 1666
 
1594 1667
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1595
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1596
-			unset($_REQUEST['poll']);
1597
-
1598
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1599
-		{
1600
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1601
-				$becomesApproved = false;
1602
-
1603
-			else
1604
-				isAllowedTo('post_reply_any');
1605
-		}
1606
-		elseif (!allowedTo('post_reply_any'))
1668
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1669
+					unset($_REQUEST['poll']);
1670
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1671
+		{
1672
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1673
+							$becomesApproved = false;
1674
+			} else {
1675
+							isAllowedTo('post_reply_any');
1676
+			}
1677
+		} elseif (!allowedTo('post_reply_any'))
1607 1678
 		{
1608
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1609
-				$becomesApproved = false;
1610
-
1611
-			else
1612
-				isAllowedTo('post_reply_own');
1679
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1680
+							$becomesApproved = false;
1681
+			} else {
1682
+							isAllowedTo('post_reply_own');
1683
+			}
1613 1684
 		}
1614 1685
 
1615 1686
 		if (isset($_POST['lock']))
1616 1687
 		{
1617 1688
 			// Nothing is changed to the lock.
1618
-			if (empty($topic_info['locked']) == empty($_POST['lock']))
1619
-				unset($_POST['lock']);
1689
+			if (empty($topic_info['locked']) == empty($_POST['lock'])) {
1690
+							unset($_POST['lock']);
1691
+			}
1620 1692
 
1621 1693
 			// You're have no permission to lock this topic.
1622
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1623
-				unset($_POST['lock']);
1694
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1695
+							unset($_POST['lock']);
1696
+			}
1624 1697
 
1625 1698
 			// You are allowed to (un)lock your own topic only.
1626 1699
 			elseif (!allowedTo('lock_any'))
1627 1700
 			{
1628 1701
 				// You cannot override a moderator lock.
1629
-				if ($topic_info['locked'] == 1)
1630
-					unset($_POST['lock']);
1631
-
1632
-				else
1633
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1702
+				if ($topic_info['locked'] == 1) {
1703
+									unset($_POST['lock']);
1704
+				} else {
1705
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1706
+				}
1634 1707
 			}
1635 1708
 			// Hail mighty moderator, (un)lock this topic immediately.
1636 1709
 			else
@@ -1638,19 +1711,21 @@  discard block
 block discarded – undo
1638 1711
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1639 1712
 
1640 1713
 				// Did someone (un)lock this while you were posting?
1641
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1642
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1714
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1715
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1716
+				}
1643 1717
 			}
1644 1718
 		}
1645 1719
 
1646 1720
 		// So you wanna (un)sticky this...let's see.
1647
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1648
-			unset($_POST['sticky']);
1649
-		elseif (isset($_POST['sticky']))
1721
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1722
+					unset($_POST['sticky']);
1723
+		} elseif (isset($_POST['sticky']))
1650 1724
 		{
1651 1725
 			// Did someone (un)sticky this while you were posting?
1652
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1653
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1726
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1727
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1728
+			}
1654 1729
 		}
1655 1730
 
1656 1731
 		// If drafts are enabled, then pass this off
@@ -1677,26 +1752,31 @@  discard block
 block discarded – undo
1677 1752
 
1678 1753
 		// Do like, the permissions, for safety and stuff...
1679 1754
 		$becomesApproved = true;
1680
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1681
-			$becomesApproved = false;
1682
-		else
1683
-			isAllowedTo('post_new');
1755
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1756
+					$becomesApproved = false;
1757
+		} else {
1758
+					isAllowedTo('post_new');
1759
+		}
1684 1760
 
1685 1761
 		if (isset($_POST['lock']))
1686 1762
 		{
1687 1763
 			// New topics are by default not locked.
1688
-			if (empty($_POST['lock']))
1689
-				unset($_POST['lock']);
1764
+			if (empty($_POST['lock'])) {
1765
+							unset($_POST['lock']);
1766
+			}
1690 1767
 			// Besides, you need permission.
1691
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1692
-				unset($_POST['lock']);
1768
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1769
+							unset($_POST['lock']);
1770
+			}
1693 1771
 			// A moderator-lock (1) can override a user-lock (2).
1694
-			else
1695
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1772
+			else {
1773
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1774
+			}
1696 1775
 		}
1697 1776
 
1698
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1699
-			unset($_POST['sticky']);
1777
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1778
+					unset($_POST['sticky']);
1779
+		}
1700 1780
 
1701 1781
 		// Saving your new topic as a draft first?
1702 1782
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1721,31 +1801,37 @@  discard block
 block discarded – undo
1721 1801
 				'id_msg' => $_REQUEST['msg'],
1722 1802
 			)
1723 1803
 		);
1724
-		if ($smcFunc['db_num_rows']($request) == 0)
1725
-			fatal_lang_error('cant_find_messages', false);
1804
+		if ($smcFunc['db_num_rows']($request) == 0) {
1805
+					fatal_lang_error('cant_find_messages', false);
1806
+		}
1726 1807
 		$row = $smcFunc['db_fetch_assoc']($request);
1727 1808
 		$smcFunc['db_free_result']($request);
1728 1809
 
1729
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1730
-			fatal_lang_error('topic_locked', false);
1810
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1811
+					fatal_lang_error('topic_locked', false);
1812
+		}
1731 1813
 
1732 1814
 		if (isset($_POST['lock']))
1733 1815
 		{
1734 1816
 			// Nothing changes to the lock status.
1735
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1736
-				unset($_POST['lock']);
1817
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1818
+							unset($_POST['lock']);
1819
+			}
1737 1820
 			// You're simply not allowed to (un)lock this.
1738
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1739
-				unset($_POST['lock']);
1821
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1822
+							unset($_POST['lock']);
1823
+			}
1740 1824
 			// You're only allowed to lock your own topics.
1741 1825
 			elseif (!allowedTo('lock_any'))
1742 1826
 			{
1743 1827
 				// You're not allowed to break a moderator's lock.
1744
-				if ($topic_info['locked'] == 1)
1745
-					unset($_POST['lock']);
1828
+				if ($topic_info['locked'] == 1) {
1829
+									unset($_POST['lock']);
1830
+				}
1746 1831
 				// Lock it with a soft lock or unlock it.
1747
-				else
1748
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1832
+				else {
1833
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1834
+				}
1749 1835
 			}
1750 1836
 			// You must be the moderator.
1751 1837
 			else
@@ -1753,44 +1839,46 @@  discard block
 block discarded – undo
1753 1839
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1754 1840
 
1755 1841
 				// Did someone (un)lock this while you were posting?
1756
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1757
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1842
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1843
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1844
+				}
1758 1845
 			}
1759 1846
 		}
1760 1847
 
1761 1848
 		// Change the sticky status of this topic?
1762
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1763
-			unset($_POST['sticky']);
1764
-		elseif (isset($_POST['sticky']))
1849
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1850
+					unset($_POST['sticky']);
1851
+		} elseif (isset($_POST['sticky']))
1765 1852
 		{
1766 1853
 			// Did someone (un)sticky this while you were posting?
1767
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1768
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1854
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1855
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1856
+			}
1769 1857
 		}
1770 1858
 
1771 1859
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1772 1860
 		{
1773
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1774
-				fatal_lang_error('modify_post_time_passed', false);
1775
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1776
-				isAllowedTo('modify_replies');
1777
-			else
1778
-				isAllowedTo('modify_own');
1779
-		}
1780
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1861
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1862
+							fatal_lang_error('modify_post_time_passed', false);
1863
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1864
+							isAllowedTo('modify_replies');
1865
+			} else {
1866
+							isAllowedTo('modify_own');
1867
+			}
1868
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1781 1869
 		{
1782 1870
 			isAllowedTo('modify_replies');
1783 1871
 
1784 1872
 			// If you're modifying a reply, I say it better be logged...
1785 1873
 			$moderationAction = true;
1786
-		}
1787
-		else
1874
+		} else
1788 1875
 		{
1789 1876
 			isAllowedTo('modify_any');
1790 1877
 
1791 1878
 			// Log it, assuming you're not modifying your own post.
1792
-			if ($row['id_member'] != $user_info['id'])
1793
-				$moderationAction = true;
1879
+			if ($row['id_member'] != $user_info['id']) {
1880
+							$moderationAction = true;
1881
+			}
1794 1882
 		}
1795 1883
 
1796 1884
 		// If drafts are enabled, then lets send this off to save
@@ -1817,8 +1905,9 @@  discard block
 block discarded – undo
1817 1905
 		// Update search api
1818 1906
 		require_once($sourcedir . '/Search.php');
1819 1907
 		$searchAPI = findSearchAPI();
1820
-		if ($searchAPI->supportsMethod('postRemoved'))
1821
-			$searchAPI->postRemoved($_REQUEST['msg']);
1908
+		if ($searchAPI->supportsMethod('postRemoved')) {
1909
+					$searchAPI->postRemoved($_REQUEST['msg']);
1910
+		}
1822 1911
 
1823 1912
 	}
1824 1913
 
@@ -1836,20 +1925,24 @@  discard block
 block discarded – undo
1836 1925
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1837 1926
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1838 1927
 
1839
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1840
-			$post_errors[] = 'no_name';
1841
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1842
-			$post_errors[] = 'long_name';
1928
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1929
+					$post_errors[] = 'no_name';
1930
+		}
1931
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1932
+					$post_errors[] = 'long_name';
1933
+		}
1843 1934
 
1844 1935
 		if (empty($modSettings['guest_post_no_email']))
1845 1936
 		{
1846 1937
 			// Only check if they changed it!
1847 1938
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1848 1939
 			{
1849
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1850
-					$post_errors[] = 'no_email';
1851
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1852
-					$post_errors[] = 'bad_email';
1940
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1941
+									$post_errors[] = 'no_email';
1942
+				}
1943
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1944
+									$post_errors[] = 'bad_email';
1945
+				}
1853 1946
 			}
1854 1947
 
1855 1948
 			// Now make sure this email address is not banned from posting.
@@ -1865,76 +1958,90 @@  discard block
 block discarded – undo
1865 1958
 	}
1866 1959
 
1867 1960
 	// Coming from the quickReply?
1868
-	if (isset($_POST['quickReply']))
1869
-		$_POST['message'] = $_POST['quickReply'];
1961
+	if (isset($_POST['quickReply'])) {
1962
+			$_POST['message'] = $_POST['quickReply'];
1963
+	}
1870 1964
 
1871 1965
 	// Check the subject and message.
1872
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1873
-		$post_errors[] = 'no_subject';
1874
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1875
-		$post_errors[] = 'no_message';
1876
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1877
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1878
-	else
1966
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1967
+			$post_errors[] = 'no_subject';
1968
+	}
1969
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1970
+			$post_errors[] = 'no_message';
1971
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1972
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1973
+	} else
1879 1974
 	{
1880 1975
 		// Prepare the message a bit for some additional testing.
1881 1976
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1882 1977
 
1883 1978
 		// Preparse code. (Zef)
1884
-		if ($user_info['is_guest'])
1885
-			$user_info['name'] = $_POST['guestname'];
1979
+		if ($user_info['is_guest']) {
1980
+					$user_info['name'] = $_POST['guestname'];
1981
+		}
1886 1982
 		preparsecode($_POST['message']);
1887 1983
 
1888 1984
 		// Let's see if there's still some content left without the tags.
1889
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1890
-			$post_errors[] = 'no_message';
1985
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1986
+					$post_errors[] = 'no_message';
1987
+		}
1891 1988
 
1892 1989
 	}
1893
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1894
-		$post_errors[] = 'no_event';
1990
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1991
+			$post_errors[] = 'no_event';
1992
+	}
1895 1993
 	// You are not!
1896
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1897
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1994
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1995
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1996
+	}
1898 1997
 
1899 1998
 	// Validate the poll...
1900 1999
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1901 2000
 	{
1902
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1903
-			fatal_lang_error('no_access', false);
2001
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
2002
+					fatal_lang_error('no_access', false);
2003
+		}
1904 2004
 
1905 2005
 		// This is a new topic... so it's a new poll.
1906
-		if (empty($topic))
1907
-			isAllowedTo('poll_post');
2006
+		if (empty($topic)) {
2007
+					isAllowedTo('poll_post');
2008
+		}
1908 2009
 		// Can you add to your own topics?
1909
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1910
-			isAllowedTo('poll_add_own');
2010
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
2011
+					isAllowedTo('poll_add_own');
2012
+		}
1911 2013
 		// Can you add polls to any topic, then?
1912
-		else
1913
-			isAllowedTo('poll_add_any');
2014
+		else {
2015
+					isAllowedTo('poll_add_any');
2016
+		}
1914 2017
 
1915
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1916
-			$post_errors[] = 'no_question';
2018
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
2019
+					$post_errors[] = 'no_question';
2020
+		}
1917 2021
 
1918 2022
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1919 2023
 
1920 2024
 		// Get rid of empty ones.
1921
-		foreach ($_POST['options'] as $k => $option)
1922
-			if ($option == '')
2025
+		foreach ($_POST['options'] as $k => $option) {
2026
+					if ($option == '')
1923 2027
 				unset($_POST['options'][$k], $_POST['options'][$k]);
2028
+		}
1924 2029
 
1925 2030
 		// What are you going to vote between with one choice?!?
1926
-		if (count($_POST['options']) < 2)
1927
-			$post_errors[] = 'poll_few';
1928
-		elseif (count($_POST['options']) > 256)
1929
-			$post_errors[] = 'poll_many';
2031
+		if (count($_POST['options']) < 2) {
2032
+					$post_errors[] = 'poll_few';
2033
+		} elseif (count($_POST['options']) > 256) {
2034
+					$post_errors[] = 'poll_many';
2035
+		}
1930 2036
 	}
1931 2037
 
1932 2038
 	if ($posterIsGuest)
1933 2039
 	{
1934 2040
 		// If user is a guest, make sure the chosen name isn't taken.
1935 2041
 		require_once($sourcedir . '/Subs-Members.php');
1936
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1937
-			$post_errors[] = 'bad_name';
2042
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
2043
+					$post_errors[] = 'bad_name';
2044
+		}
1938 2045
 	}
1939 2046
 	// If the user isn't a guest, get his or her name and email.
1940 2047
 	elseif (!isset($_REQUEST['msg']))
@@ -1965,8 +2072,9 @@  discard block
 block discarded – undo
1965 2072
 	}
1966 2073
 
1967 2074
 	// Make sure the user isn't spamming the board.
1968
-	if (!isset($_REQUEST['msg']))
1969
-		spamProtection('post');
2075
+	if (!isset($_REQUEST['msg'])) {
2076
+			spamProtection('post');
2077
+	}
1970 2078
 
1971 2079
 	// At about this point, we're posting and that's that.
1972 2080
 	ignore_user_abort(true);
@@ -1979,32 +2087,36 @@  discard block
 block discarded – undo
1979 2087
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1980 2088
 
1981 2089
 	// At this point, we want to make sure the subject isn't too long.
1982
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1983
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2090
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
2091
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2092
+	}
1984 2093
 
1985 2094
 	// Same with the "why did you edit this" text.
1986
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1987
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2095
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2096
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2097
+	}
1988 2098
 
1989 2099
 	// Make the poll...
1990 2100
 	if (isset($_REQUEST['poll']))
1991 2101
 	{
1992 2102
 		// Make sure that the user has not entered a ridiculous number of options..
1993
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1994
-			$_POST['poll_max_votes'] = 1;
1995
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1996
-			$_POST['poll_max_votes'] = count($_POST['options']);
1997
-		else
1998
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2103
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
2104
+					$_POST['poll_max_votes'] = 1;
2105
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
2106
+					$_POST['poll_max_votes'] = count($_POST['options']);
2107
+		} else {
2108
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2109
+		}
1999 2110
 
2000 2111
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
2001 2112
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
2002 2113
 
2003 2114
 		// Just set it to zero if it's not there..
2004
-		if (!isset($_POST['poll_hide']))
2005
-			$_POST['poll_hide'] = 0;
2006
-		else
2007
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2115
+		if (!isset($_POST['poll_hide'])) {
2116
+					$_POST['poll_hide'] = 0;
2117
+		} else {
2118
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2119
+		}
2008 2120
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
2009 2121
 
2010 2122
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -2013,16 +2125,19 @@  discard block
 block discarded – undo
2013 2125
 		{
2014 2126
 			require_once($sourcedir . '/Subs-Members.php');
2015 2127
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
2016
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
2017
-				$_POST['poll_guest_vote'] = 0;
2128
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2129
+							$_POST['poll_guest_vote'] = 0;
2130
+			}
2018 2131
 		}
2019 2132
 
2020 2133
 		// If the user tries to set the poll too far in advance, don't let them.
2021
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
2022
-			fatal_lang_error('poll_range_error', false);
2134
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2135
+					fatal_lang_error('poll_range_error', false);
2136
+		}
2023 2137
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
2024
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
2025
-			$_POST['poll_hide'] = 1;
2138
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2139
+					$_POST['poll_hide'] = 1;
2140
+		}
2026 2141
 
2027 2142
 		// Clean up the question and answers.
2028 2143
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -2036,13 +2151,15 @@  discard block
 block discarded – undo
2036 2151
 	{
2037 2152
 		$attachIDs = array();
2038 2153
 		$attach_errors = array();
2039
-		if (!empty($context['we_are_history']))
2040
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2154
+		if (!empty($context['we_are_history'])) {
2155
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2156
+		}
2041 2157
 
2042 2158
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
2043 2159
 		{
2044
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
2045
-				continue;
2160
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2161
+							continue;
2162
+			}
2046 2163
 
2047 2164
 			// If there was an initial error just show that message.
2048 2165
 			if ($attachID == 'initial_error')
@@ -2071,12 +2188,13 @@  discard block
 block discarded – undo
2071 2188
 				if (createAttachment($attachmentOptions))
2072 2189
 				{
2073 2190
 					$attachIDs[] = $attachmentOptions['id'];
2074
-					if (!empty($attachmentOptions['thumb']))
2075
-						$attachIDs[] = $attachmentOptions['thumb'];
2191
+					if (!empty($attachmentOptions['thumb'])) {
2192
+											$attachIDs[] = $attachmentOptions['thumb'];
2193
+					}
2076 2194
 				}
2195
+			} else {
2196
+							$attach_errors[] = '<dt>&nbsp;</dt>';
2077 2197
 			}
2078
-			else
2079
-				$attach_errors[] = '<dt>&nbsp;</dt>';
2080 2198
 
2081 2199
 			if (!empty($attachmentOptions['errors']))
2082 2200
 			{
@@ -2088,14 +2206,16 @@  discard block
 block discarded – undo
2088 2206
 					if (!is_array($error))
2089 2207
 					{
2090 2208
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
2091
-						if (in_array($error, $log_these))
2092
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2209
+						if (in_array($error, $log_these)) {
2210
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2211
+						}
2212
+					} else {
2213
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2093 2214
 					}
2094
-					else
2095
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2096 2215
 				}
2097
-				if (file_exists($attachment['tmp_name']))
2098
-					unlink($attachment['tmp_name']);
2216
+				if (file_exists($attachment['tmp_name'])) {
2217
+									unlink($attachment['tmp_name']);
2218
+				}
2099 2219
 			}
2100 2220
 		}
2101 2221
 		unset($_SESSION['temp_attachments']);
@@ -2136,24 +2256,24 @@  discard block
 block discarded – undo
2136 2256
 		);
2137 2257
 
2138 2258
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2259
+	} else {
2260
+			$id_poll = 0;
2139 2261
 	}
2140
-	else
2141
-		$id_poll = 0;
2142 2262
 
2143 2263
 	// Creating a new topic?
2144 2264
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2145 2265
 
2146 2266
 	// Check the icon.
2147
-	if (!isset($_POST['icon']))
2148
-		$_POST['icon'] = 'xx';
2149
-
2150
-	else
2267
+	if (!isset($_POST['icon'])) {
2268
+			$_POST['icon'] = 'xx';
2269
+	} else
2151 2270
 	{
2152 2271
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2153 2272
 
2154 2273
 		// Need to figure it out if this is a valid icon name.
2155
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2156
-			$_POST['icon'] = 'xx';
2274
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2275
+					$_POST['icon'] = 'xx';
2276
+		}
2157 2277
 	}
2158 2278
 
2159 2279
 	// Collect all parameters for the creation or modification of a post.
@@ -2194,8 +2314,9 @@  discard block
 block discarded – undo
2194 2314
 		}
2195 2315
 
2196 2316
 		// This will save some time...
2197
-		if (empty($approve_has_changed))
2198
-			unset($msgOptions['approved']);
2317
+		if (empty($approve_has_changed)) {
2318
+					unset($msgOptions['approved']);
2319
+		}
2199 2320
 
2200 2321
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2201 2322
 	}
@@ -2204,8 +2325,9 @@  discard block
 block discarded – undo
2204 2325
 	{
2205 2326
 		createPost($msgOptions, $topicOptions, $posterOptions);
2206 2327
 
2207
-		if (isset($topicOptions['id']))
2208
-			$topic = $topicOptions['id'];
2328
+		if (isset($topicOptions['id'])) {
2329
+					$topic = $topicOptions['id'];
2330
+		}
2209 2331
 	}
2210 2332
 
2211 2333
 	// Are there attachments already uploaded and waiting to be assigned?
@@ -2217,8 +2339,9 @@  discard block
 block discarded – undo
2217 2339
 	}
2218 2340
 
2219 2341
 	// If we had a draft for this, its time to remove it since it was just posted
2220
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2221
-		DeleteDraft($_POST['id_draft']);
2342
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2343
+			DeleteDraft($_POST['id_draft']);
2344
+	}
2222 2345
 
2223 2346
 	// Editing or posting an event?
2224 2347
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2237,8 +2360,7 @@  discard block
 block discarded – undo
2237 2360
 			'member' => $user_info['id'],
2238 2361
 		);
2239 2362
 		insertEvent($eventOptions);
2240
-	}
2241
-	elseif (isset($_POST['calendar']))
2363
+	} elseif (isset($_POST['calendar']))
2242 2364
 	{
2243 2365
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2244 2366
 
@@ -2266,14 +2388,15 @@  discard block
 block discarded – undo
2266 2388
 		}
2267 2389
 
2268 2390
 		// Delete it?
2269
-		if (isset($_REQUEST['deleteevent']))
2270
-			$smcFunc['db_query']('', '
2391
+		if (isset($_REQUEST['deleteevent'])) {
2392
+					$smcFunc['db_query']('', '
2271 2393
 				DELETE FROM {db_prefix}calendar
2272 2394
 				WHERE id_event = {int:id_event}',
2273 2395
 				array(
2274 2396
 					'id_event' => $_REQUEST['eventid'],
2275 2397
 				)
2276 2398
 			);
2399
+		}
2277 2400
 		// ... or just update it?
2278 2401
 		else
2279 2402
 		{
@@ -2315,9 +2438,8 @@  discard block
 block discarded – undo
2315 2438
 			array($user_info['id'], $topic, 0),
2316 2439
 			array('id_member', 'id_topic', 'id_board')
2317 2440
 		);
2318
-	}
2319
-	elseif (!$newTopic)
2320
-		$smcFunc['db_query']('', '
2441
+	} elseif (!$newTopic) {
2442
+			$smcFunc['db_query']('', '
2321 2443
 			DELETE FROM {db_prefix}log_notify
2322 2444
 			WHERE id_member = {int:current_member}
2323 2445
 				AND id_topic = {int:current_topic}',
@@ -2326,16 +2448,20 @@  discard block
 block discarded – undo
2326 2448
 				'current_topic' => $topic,
2327 2449
 			)
2328 2450
 		);
2451
+	}
2329 2452
 
2330 2453
 	// Log an act of moderation - modifying.
2331
-	if (!empty($moderationAction))
2332
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2454
+	if (!empty($moderationAction)) {
2455
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2456
+	}
2333 2457
 
2334
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2335
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2458
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2459
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2460
+	}
2336 2461
 
2337
-	if (isset($_POST['sticky']))
2338
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2462
+	if (isset($_POST['sticky'])) {
2463
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2464
+	}
2339 2465
 
2340 2466
 	// Returning to the topic?
2341 2467
 	if (!empty($_REQUEST['goback']))
@@ -2354,26 +2480,31 @@  discard block
 block discarded – undo
2354 2480
 		);
2355 2481
 	}
2356 2482
 
2357
-	if ($board_info['num_topics'] == 0)
2358
-		cache_put_data('board-' . $board, null, 120);
2483
+	if ($board_info['num_topics'] == 0) {
2484
+			cache_put_data('board-' . $board, null, 120);
2485
+	}
2359 2486
 
2360 2487
 	call_integration_hook('integrate_post2_end');
2361 2488
 
2362
-	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic'))
2363
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2489
+	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) {
2490
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2491
+	}
2364 2492
 
2365
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2366
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2493
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2494
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2495
+	}
2367 2496
 
2368 2497
 	// Return to post if the mod is on.
2369
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2370
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2371
-	elseif (!empty($_REQUEST['goback']))
2372
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2498
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2499
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2500
+	} elseif (!empty($_REQUEST['goback'])) {
2501
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2502
+	}
2373 2503
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2374
-	else
2375
-		redirectexit('board=' . $board . '.0');
2376
-}
2504
+	else {
2505
+			redirectexit('board=' . $board . '.0');
2506
+	}
2507
+	}
2377 2508
 
2378 2509
 /**
2379 2510
  * Handle the announce topic function (action=announce).
@@ -2391,8 +2522,9 @@  discard block
 block discarded – undo
2391 2522
 
2392 2523
 	validateSession();
2393 2524
 
2394
-	if (empty($topic))
2395
-		fatal_lang_error('topic_gone', false);
2525
+	if (empty($topic)) {
2526
+			fatal_lang_error('topic_gone', false);
2527
+	}
2396 2528
 
2397 2529
 	loadLanguage('Post');
2398 2530
 	loadTemplate('Post');
@@ -2419,8 +2551,9 @@  discard block
 block discarded – undo
2419 2551
 	global $txt, $context, $topic, $board_info, $smcFunc;
2420 2552
 
2421 2553
 	$groups = array_merge($board_info['groups'], array(1));
2422
-	foreach ($groups as $id => $group)
2423
-		$groups[$id] = (int) $group;
2554
+	foreach ($groups as $id => $group) {
2555
+			$groups[$id] = (int) $group;
2556
+	}
2424 2557
 
2425 2558
 	$context['groups'] = array();
2426 2559
 	if (in_array(0, $groups))
@@ -2463,8 +2596,9 @@  discard block
 block discarded – undo
2463 2596
 			'group_list' => $groups,
2464 2597
 		)
2465 2598
 	);
2466
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2467
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2599
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2600
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2601
+	}
2468 2602
 	$smcFunc['db_free_result']($request);
2469 2603
 
2470 2604
 	// Get the subject of the topic we're about to announce.
@@ -2506,16 +2640,19 @@  discard block
 block discarded – undo
2506 2640
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2507 2641
 	$groups = array_merge($board_info['groups'], array(1));
2508 2642
 
2509
-	if (isset($_POST['membergroups']))
2510
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2643
+	if (isset($_POST['membergroups'])) {
2644
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2645
+	}
2511 2646
 
2512 2647
 	// Check whether at least one membergroup was selected.
2513
-	if (empty($_POST['who']))
2514
-		fatal_lang_error('no_membergroup_selected');
2648
+	if (empty($_POST['who'])) {
2649
+			fatal_lang_error('no_membergroup_selected');
2650
+	}
2515 2651
 
2516 2652
 	// Make sure all membergroups are integers and can access the board of the announcement.
2517
-	foreach ($_POST['who'] as $id => $mg)
2518
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2653
+	foreach ($_POST['who'] as $id => $mg) {
2654
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2655
+	}
2519 2656
 
2520 2657
 	// Get the topic subject and censor it.
2521 2658
 	$request = $smcFunc['db_query']('', '
@@ -2561,12 +2698,13 @@  discard block
 block discarded – undo
2561 2698
 	if ($smcFunc['db_num_rows']($request) == 0)
2562 2699
 	{
2563 2700
 		logAction('announce_topic', array('topic' => $topic), 'user');
2564
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2565
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2566
-		elseif (!empty($_REQUEST['goback']))
2567
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2568
-		else
2569
-			redirectexit('board=' . $board . '.0');
2701
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2702
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2703
+		} elseif (!empty($_REQUEST['goback'])) {
2704
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2705
+		} else {
2706
+					redirectexit('board=' . $board . '.0');
2707
+		}
2570 2708
 	}
2571 2709
 
2572 2710
 	$announcements = array();
@@ -2585,8 +2723,9 @@  discard block
 block discarded – undo
2585 2723
 	foreach ($rows as $row)
2586 2724
 	{
2587 2725
 		// Force them to have it?
2588
-		if (empty($prefs[$row['id_member']]['announcements']))
2589
-			continue;
2726
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2727
+					continue;
2728
+		}
2590 2729
 
2591 2730
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2592 2731
 
@@ -2614,8 +2753,9 @@  discard block
 block discarded – undo
2614 2753
 	}
2615 2754
 
2616 2755
 	// For each language send a different mail - low priority...
2617
-	foreach ($announcements as $lang => $mail)
2618
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2756
+	foreach ($announcements as $lang => $mail) {
2757
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2758
+	}
2619 2759
 
2620 2760
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2621 2761
 
@@ -2625,9 +2765,10 @@  discard block
 block discarded – undo
2625 2765
 	$context['sub_template'] = 'announcement_send';
2626 2766
 
2627 2767
 	// Go back to the correct language for the user ;).
2628
-	if (!empty($modSettings['userLanguage']))
2629
-		loadLanguage('Post');
2630
-}
2768
+	if (!empty($modSettings['userLanguage'])) {
2769
+			loadLanguage('Post');
2770
+	}
2771
+	}
2631 2772
 
2632 2773
 /**
2633 2774
  * Get the topic for display purposes.
@@ -2640,12 +2781,13 @@  discard block
 block discarded – undo
2640 2781
 {
2641 2782
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2642 2783
 
2643
-	if (isset($_REQUEST['xml']))
2644
-		$limit = '
2784
+	if (isset($_REQUEST['xml'])) {
2785
+			$limit = '
2645 2786
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2646
-	else
2647
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2787
+	} else {
2788
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2648 2789
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2790
+	}
2649 2791
 
2650 2792
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2651 2793
 	$request = $smcFunc['db_query']('', '
@@ -2683,8 +2825,9 @@  discard block
 block discarded – undo
2683 2825
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2684 2826
 		);
2685 2827
 
2686
-		if (!empty($context['new_replies']))
2687
-			$context['new_replies']--;
2828
+		if (!empty($context['new_replies'])) {
2829
+					$context['new_replies']--;
2830
+		}
2688 2831
 	}
2689 2832
 	$smcFunc['db_free_result']($request);
2690 2833
 }
@@ -2701,8 +2844,9 @@  discard block
 block discarded – undo
2701 2844
 	global $sourcedir, $smcFunc;
2702 2845
 
2703 2846
 	loadLanguage('Post');
2704
-	if (!isset($_REQUEST['xml']))
2705
-		loadTemplate('Post');
2847
+	if (!isset($_REQUEST['xml'])) {
2848
+			loadTemplate('Post');
2849
+	}
2706 2850
 
2707 2851
 	include_once($sourcedir . '/Subs-Post.php');
2708 2852
 
@@ -2733,8 +2877,9 @@  discard block
 block discarded – undo
2733 2877
 	$smcFunc['db_free_result']($request);
2734 2878
 
2735 2879
 	$context['sub_template'] = 'quotefast';
2736
-	if (!empty($row))
2737
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2880
+	if (!empty($row)) {
2881
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2882
+	}
2738 2883
 
2739 2884
 	if (!empty($can_view_post))
2740 2885
 	{
@@ -2767,8 +2912,9 @@  discard block
 block discarded – undo
2767 2912
 		}
2768 2913
 
2769 2914
 		// Remove any nested quotes.
2770
-		if (!empty($modSettings['removeNestedQuotes']))
2771
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2915
+		if (!empty($modSettings['removeNestedQuotes'])) {
2916
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2917
+		}
2772 2918
 
2773 2919
 		$lb = "\n";
2774 2920
 
@@ -2794,14 +2940,14 @@  discard block
 block discarded – undo
2794 2940
 				'time' => '',
2795 2941
 			),
2796 2942
 		);
2797
-	}
2798
-	else
2799
-		$context['quote'] = array(
2943
+	} else {
2944
+			$context['quote'] = array(
2800 2945
 			'xml' => '',
2801 2946
 			'mozilla' => '',
2802 2947
 			'text' => '',
2803 2948
 		);
2804
-}
2949
+	}
2950
+	}
2805 2951
 
2806 2952
 /**
2807 2953
  * Used to edit the body or subject of a message inline
@@ -2813,8 +2959,9 @@  discard block
 block discarded – undo
2813 2959
 	global $user_info, $context, $smcFunc, $language, $board_info;
2814 2960
 
2815 2961
 	// We have to have a topic!
2816
-	if (empty($topic))
2817
-		obExit(false);
2962
+	if (empty($topic)) {
2963
+			obExit(false);
2964
+	}
2818 2965
 
2819 2966
 	checkSession('get');
2820 2967
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2840,31 +2987,35 @@  discard block
 block discarded – undo
2840 2987
 			'guest_id' => 0,
2841 2988
 		)
2842 2989
 	);
2843
-	if ($smcFunc['db_num_rows']($request) == 0)
2844
-		fatal_lang_error('no_board', false);
2990
+	if ($smcFunc['db_num_rows']($request) == 0) {
2991
+			fatal_lang_error('no_board', false);
2992
+	}
2845 2993
 	$row = $smcFunc['db_fetch_assoc']($request);
2846 2994
 	$smcFunc['db_free_result']($request);
2847 2995
 
2848 2996
 	// Change either body or subject requires permissions to modify messages.
2849 2997
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2850 2998
 	{
2851
-		if (!empty($row['locked']))
2852
-			isAllowedTo('moderate_board');
2999
+		if (!empty($row['locked'])) {
3000
+					isAllowedTo('moderate_board');
3001
+		}
2853 3002
 
2854 3003
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2855 3004
 		{
2856
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2857
-				fatal_lang_error('modify_post_time_passed', false);
2858
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2859
-				isAllowedTo('modify_replies');
2860
-			else
2861
-				isAllowedTo('modify_own');
3005
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
3006
+							fatal_lang_error('modify_post_time_passed', false);
3007
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
3008
+							isAllowedTo('modify_replies');
3009
+			} else {
3010
+							isAllowedTo('modify_own');
3011
+			}
2862 3012
 		}
2863 3013
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2864
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2865
-			isAllowedTo('modify_replies');
2866
-		else
2867
-			isAllowedTo('modify_any');
3014
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
3015
+					isAllowedTo('modify_replies');
3016
+		} else {
3017
+					isAllowedTo('modify_any');
3018
+		}
2868 3019
 
2869 3020
 		// Only log this action if it wasn't your message.
2870 3021
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2876,10 +3027,10 @@  discard block
 block discarded – undo
2876 3027
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2877 3028
 
2878 3029
 		// Maximum number of characters.
2879
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2880
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2881
-	}
2882
-	elseif (isset($_POST['subject']))
3030
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
3031
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
3032
+		}
3033
+	} elseif (isset($_POST['subject']))
2883 3034
 	{
2884 3035
 		$post_errors[] = 'no_subject';
2885 3036
 		unset($_POST['subject']);
@@ -2891,13 +3042,11 @@  discard block
 block discarded – undo
2891 3042
 		{
2892 3043
 			$post_errors[] = 'no_message';
2893 3044
 			unset($_POST['message']);
2894
-		}
2895
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
3045
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2896 3046
 		{
2897 3047
 			$post_errors[] = 'long_message';
2898 3048
 			unset($_POST['message']);
2899
-		}
2900
-		else
3049
+		} else
2901 3050
 		{
2902 3051
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2903 3052
 
@@ -2913,31 +3062,34 @@  discard block
 block discarded – undo
2913 3062
 
2914 3063
 	if (isset($_POST['lock']))
2915 3064
 	{
2916
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2917
-			unset($_POST['lock']);
2918
-		elseif (!allowedTo('lock_any'))
3065
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
3066
+					unset($_POST['lock']);
3067
+		} elseif (!allowedTo('lock_any'))
2919 3068
 		{
2920
-			if ($row['locked'] == 1)
2921
-				unset($_POST['lock']);
2922
-			else
2923
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3069
+			if ($row['locked'] == 1) {
3070
+							unset($_POST['lock']);
3071
+			} else {
3072
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3073
+			}
3074
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
3075
+					unset($_POST['lock']);
3076
+		} else {
3077
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2924 3078
 		}
2925
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2926
-			unset($_POST['lock']);
2927
-		else
2928
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2929 3079
 	}
2930 3080
 
2931
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2932
-		unset($_POST['sticky']);
3081
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
3082
+			unset($_POST['sticky']);
3083
+	}
2933 3084
 
2934 3085
 	if (isset($_POST['modify_reason']))
2935 3086
 	{
2936 3087
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2937 3088
 
2938 3089
 		// Maximum number of characters.
2939
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2940
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3090
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
3091
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3092
+		}
2941 3093
 	}
2942 3094
 
2943 3095
 	if (empty($post_errors))
@@ -2974,8 +3126,9 @@  discard block
 block discarded – undo
2974 3126
 			}
2975 3127
 		}
2976 3128
 		// If nothing was changed there's no need to add an entry to the moderation log.
2977
-		else
2978
-			$moderationAction = false;
3129
+		else {
3130
+					$moderationAction = false;
3131
+		}
2979 3132
 
2980 3133
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2981 3134
 
@@ -2993,9 +3146,9 @@  discard block
 block discarded – undo
2993 3146
 			// Get the proper (default language) response prefix first.
2994 3147
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2995 3148
 			{
2996
-				if ($language === $user_info['language'])
2997
-					$context['response_prefix'] = $txt['response_prefix'];
2998
-				else
3149
+				if ($language === $user_info['language']) {
3150
+									$context['response_prefix'] = $txt['response_prefix'];
3151
+				} else
2999 3152
 				{
3000 3153
 					loadLanguage('index', $language, false);
3001 3154
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -3017,8 +3170,9 @@  discard block
 block discarded – undo
3017 3170
 			);
3018 3171
 		}
3019 3172
 
3020
-		if (!empty($moderationAction))
3021
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3173
+		if (!empty($moderationAction)) {
3174
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3175
+		}
3022 3176
 	}
3023 3177
 
3024 3178
 	if (isset($_REQUEST['xml']))
@@ -3059,8 +3213,7 @@  discard block
 block discarded – undo
3059 3213
 			);
3060 3214
 
3061 3215
 			censorText($context['message']['subject']);
3062
-		}
3063
-		else
3216
+		} else
3064 3217
 		{
3065 3218
 			$context['message'] = array(
3066 3219
 				'id' => $row['id_msg'],
@@ -3072,15 +3225,16 @@  discard block
 block discarded – undo
3072 3225
 			loadLanguage('Errors');
3073 3226
 			foreach ($post_errors as $post_error)
3074 3227
 			{
3075
-				if ($post_error == 'long_message')
3076
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3077
-				else
3078
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3228
+				if ($post_error == 'long_message') {
3229
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3230
+				} else {
3231
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3232
+				}
3079 3233
 			}
3080 3234
 		}
3235
+	} else {
3236
+			obExit(false);
3237
+	}
3081 3238
 	}
3082
-	else
3083
-		obExit(false);
3084
-}
3085 3239
 
3086 3240
 ?>
3087 3241
\ No newline at end of file
Please login to merge, or discard this patch.