Completed
Push — release-2.1 ( eb007a...868556 )
by Michael
18:53 queued 10:36
created
Sources/Load.php 1 patch
Braces   +792 added lines, -598 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -403,27 +420,28 @@  discard block
 block discarded – undo
403 420
 				break;
404 421
 			}
405 422
 		}
423
+	} else {
424
+			$id_member = 0;
406 425
 	}
407
-	else
408
-		$id_member = 0;
409 426
 
410 427
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
411 428
 	{
412 429
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
413 430
 
414
-		if (empty($cookie_data))
415
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
431
+		if (empty($cookie_data)) {
432
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
433
+		}
416 434
 
417 435
 		list ($id_member, $password) = $cookie_data;
418 436
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
419
-	}
420
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
437
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
421 438
 	{
422 439
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
423 440
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
424 441
 
425
-		if (empty($cookie_data))
426
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		if (empty($cookie_data)) {
443
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
444
+		}
427 445
 
428 446
 		list ($id_member, $password, $login_span) = $cookie_data;
429 447
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -448,30 +466,34 @@  discard block
 block discarded – undo
448 466
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
449 467
 			$smcFunc['db_free_result']($request);
450 468
 
451
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
452
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
469
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
470
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
471
+			}
453 472
 
454
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
455
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
474
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
475
+			}
456 476
 		}
457 477
 
458 478
 		// Did we find 'im?  If not, junk it.
459 479
 		if (!empty($user_settings))
460 480
 		{
461 481
 			// As much as the password should be right, we can assume the integration set things up.
462
-			if (!empty($already_verified) && $already_verified === true)
463
-				$check = true;
482
+			if (!empty($already_verified) && $already_verified === true) {
483
+							$check = true;
484
+			}
464 485
 			// SHA-512 hash should be 128 characters long.
465
-			elseif (strlen($password) == 128)
466
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
467
-			else
468
-				$check = false;
486
+			elseif (strlen($password) == 128) {
487
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
488
+			} else {
489
+							$check = false;
490
+			}
469 491
 
470 492
 			// Wrong password or not activated - either way, you're going nowhere.
471 493
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
494
+		} else {
495
+					$id_member = 0;
472 496
 		}
473
-		else
474
-			$id_member = 0;
475 497
 
476 498
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
477 499
 		if (!$id_member)
@@ -500,8 +522,9 @@  discard block
 block discarded – undo
500 522
 
501 523
 					list ($tfamember, $tfasecret) = $tfa_data;
502 524
 
503
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
504
-						$tfasecret = null;
525
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
526
+											$tfasecret = null;
527
+					}
505 528
 				}
506 529
 
507 530
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -521,10 +544,12 @@  discard block
 block discarded – undo
521 544
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
522 545
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
523 546
 		{
524
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
547
+			if ($modSettings['tfa_mode'] == 2) {
548
+				//only do this if we are just forcing SOME membergroups
525 549
 			{
526 550
 				//Build an array of ALL user membergroups.
527 551
 				$full_groups = array($user_settings['id_group']);
552
+			}
528 553
 				if (!empty($user_settings['additional_groups']))
529 554
 				{
530 555
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -544,15 +569,17 @@  discard block
 block discarded – undo
544 569
 				);
545 570
 				$row = $smcFunc['db_fetch_assoc']($request);
546 571
 				$smcFunc['db_free_result']($request);
572
+			} else {
573
+							$row['total'] = 1;
547 574
 			}
548
-			else
549
-				$row['total'] = 1; //simplifies logics in the next "if"
575
+			//simplifies logics in the next "if"
550 576
 
551 577
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
552 578
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
553 579
 
554
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
555
-				redirectexit('action=profile;area=tfasetup;forced');
580
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
581
+							redirectexit('action=profile;area=tfasetup;forced');
582
+			}
556 583
 		}
557 584
 	}
558 585
 
@@ -589,33 +616,37 @@  discard block
 block discarded – undo
589 616
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
590 617
 				$user_settings['last_login'] = time();
591 618
 
592
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
593
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
619
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
620
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
621
+				}
594 622
 
595
-				if (!empty($modSettings['cache_enable']))
596
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
623
+				if (!empty($modSettings['cache_enable'])) {
624
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
625
+				}
597 626
 			}
627
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
628
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
598 629
 		}
599
-		elseif (empty($_SESSION['id_msg_last_visit']))
600
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
601 630
 
602 631
 		$username = $user_settings['member_name'];
603 632
 
604
-		if (empty($user_settings['additional_groups']))
605
-			$user_info = array(
633
+		if (empty($user_settings['additional_groups'])) {
634
+					$user_info = array(
606 635
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
607 636
 			);
608
-		else
609
-			$user_info = array(
637
+		} else {
638
+					$user_info = array(
610 639
 				'groups' => array_merge(
611 640
 					array($user_settings['id_group'], $user_settings['id_post_group']),
612 641
 					explode(',', $user_settings['additional_groups'])
613 642
 				)
614 643
 			);
644
+		}
615 645
 
616 646
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
617
-		foreach ($user_info['groups'] as $k => $v)
618
-			$user_info['groups'][$k] = (int) $v;
647
+		foreach ($user_info['groups'] as $k => $v) {
648
+					$user_info['groups'][$k] = (int) $v;
649
+		}
619 650
 
620 651
 		// This is a logged in user, so definitely not a spider.
621 652
 		$user_info['possibly_robot'] = false;
@@ -629,8 +660,7 @@  discard block
 block discarded – undo
629 660
 			$time_system = new DateTime('now', $tz_system);
630 661
 			$time_user = new DateTime('now', $tz_user);
631 662
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
632
-		}
633
-		else
663
+		} else
634 664
 		{
635 665
 			// !!! Compatibility.
636 666
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -644,8 +674,9 @@  discard block
 block discarded – undo
644 674
 		$user_info = array('groups' => array(-1));
645 675
 		$user_settings = array();
646 676
 
647
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
648
-			$_COOKIE[$cookiename] = '';
677
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
678
+					$_COOKIE[$cookiename] = '';
679
+		}
649 680
 
650 681
 		// Expire the 2FA cookie
651 682
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -662,19 +693,20 @@  discard block
 block discarded – undo
662 693
 		}
663 694
 
664 695
 		// Create a login token if it doesn't exist yet.
665
-		if (!isset($_SESSION['token']['post-login']))
666
-			createToken('login');
667
-		else
668
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
696
+		if (!isset($_SESSION['token']['post-login'])) {
697
+					createToken('login');
698
+		} else {
699
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
700
+		}
669 701
 
670 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
671 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
672 704
 		{
673 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
674 706
 			$user_info['possibly_robot'] = SpiderCheck();
707
+		} elseif (!empty($modSettings['spider_mode'])) {
708
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
675 709
 		}
676
-		elseif (!empty($modSettings['spider_mode']))
677
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
678 710
 		// If we haven't turned on proper spider hunts then have a guess!
679 711
 		else
680 712
 		{
@@ -722,8 +754,9 @@  discard block
 block discarded – undo
722 754
 	$user_info['groups'] = array_unique($user_info['groups']);
723 755
 
724 756
 	// 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.
725
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
726
-		unset($user_info['ignoreboards'][$tmp]);
757
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
758
+			unset($user_info['ignoreboards'][$tmp]);
759
+	}
727 760
 
728 761
 	// Allow the user to change their language.
729 762
 	if (!empty($modSettings['userLanguage']))
@@ -736,31 +769,36 @@  discard block
 block discarded – undo
736 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
737 770
 
738 771
 			// Make it permanent for members.
739
-			if (!empty($user_info['id']))
740
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
741
-			else
742
-				$_SESSION['language'] = $user_info['language'];
772
+			if (!empty($user_info['id'])) {
773
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
774
+			} else {
775
+							$_SESSION['language'] = $user_info['language'];
776
+			}
777
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
778
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
743 779
 		}
744
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
745
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
746 780
 	}
747 781
 
748 782
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
749
-	if ($user_info['is_admin'])
750
-		$user_info['query_see_board'] = '1=1';
783
+	if ($user_info['is_admin']) {
784
+			$user_info['query_see_board'] = '1=1';
785
+	}
751 786
 	// Otherwise just the groups in $user_info['groups'].
752
-	else
753
-		$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
787
+	else {
788
+			$user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')';
789
+	}
754 790
 
755 791
 	// Build the list of boards they WANT to see.
756 792
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
757 793
 
758 794
 	// If they aren't ignoring any boards then they want to see all the boards they can see
759
-	if (empty($user_info['ignoreboards']))
760
-		$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
795
+	if (empty($user_info['ignoreboards'])) {
796
+			$user_info['query_wanna_see_board'] = $user_info['query_see_board'];
797
+	}
761 798
 	// Ok I guess they don't want to see all the boards
762
-	else
763
-		$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
799
+	else {
800
+			$user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))';
801
+	}
764 802
 
765 803
 	call_integration_hook('integrate_user_info');
766 804
 }
@@ -818,9 +856,9 @@  discard block
 block discarded – undo
818 856
 		}
819 857
 
820 858
 		// Remember redirection is the key to avoiding fallout from your bosses.
821
-		if (!empty($topic))
822
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
823
-		else
859
+		if (!empty($topic)) {
860
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
861
+		} else
824 862
 		{
825 863
 			loadPermissions();
826 864
 			loadTheme();
@@ -838,10 +876,11 @@  discard block
 block discarded – undo
838 876
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
839 877
 	{
840 878
 		// @todo SLOW?
841
-		if (!empty($topic))
842
-			$temp = cache_get_data('topic_board-' . $topic, 120);
843
-		else
844
-			$temp = cache_get_data('board-' . $board, 120);
879
+		if (!empty($topic)) {
880
+					$temp = cache_get_data('topic_board-' . $topic, 120);
881
+		} else {
882
+					$temp = cache_get_data('board-' . $board, 120);
883
+		}
845 884
 
846 885
 		if (!empty($temp))
847 886
 		{
@@ -879,8 +918,9 @@  discard block
 block discarded – undo
879 918
 			$row = $smcFunc['db_fetch_assoc']($request);
880 919
 
881 920
 			// Set the current board.
882
-			if (!empty($row['id_board']))
883
-				$board = $row['id_board'];
921
+			if (!empty($row['id_board'])) {
922
+							$board = $row['id_board'];
923
+			}
884 924
 
885 925
 			// Basic operating information. (globals... :/)
886 926
 			$board_info = array(
@@ -916,21 +956,23 @@  discard block
 block discarded – undo
916 956
 
917 957
 			do
918 958
 			{
919
-				if (!empty($row['id_moderator']))
920
-					$board_info['moderators'][$row['id_moderator']] = array(
959
+				if (!empty($row['id_moderator'])) {
960
+									$board_info['moderators'][$row['id_moderator']] = array(
921 961
 						'id' => $row['id_moderator'],
922 962
 						'name' => $row['real_name'],
923 963
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
924 964
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
925 965
 					);
966
+				}
926 967
 
927
-				if (!empty($row['id_moderator_group']))
928
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
968
+				if (!empty($row['id_moderator_group'])) {
969
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
929 970
 						'id' => $row['id_moderator_group'],
930 971
 						'name' => $row['group_name'],
931 972
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
932 973
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
933 974
 					);
975
+				}
934 976
 			}
935 977
 			while ($row = $smcFunc['db_fetch_assoc']($request));
936 978
 
@@ -962,12 +1004,12 @@  discard block
 block discarded – undo
962 1004
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
963 1005
 			{
964 1006
 				// @todo SLOW?
965
-				if (!empty($topic))
966
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1007
+				if (!empty($topic)) {
1008
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1009
+				}
967 1010
 				cache_put_data('board-' . $board, $board_info, 120);
968 1011
 			}
969
-		}
970
-		else
1012
+		} else
971 1013
 		{
972 1014
 			// Otherwise the topic is invalid, there are no moderators, etc.
973 1015
 			$board_info = array(
@@ -981,8 +1023,9 @@  discard block
 block discarded – undo
981 1023
 		$smcFunc['db_free_result']($request);
982 1024
 	}
983 1025
 
984
-	if (!empty($topic))
985
-		$_GET['board'] = (int) $board;
1026
+	if (!empty($topic)) {
1027
+			$_GET['board'] = (int) $board;
1028
+	}
986 1029
 
987 1030
 	if (!empty($board))
988 1031
 	{
@@ -992,10 +1035,12 @@  discard block
 block discarded – undo
992 1035
 		// Now check if the user is a moderator.
993 1036
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
994 1037
 
995
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
996
-			$board_info['error'] = 'access';
997
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
998
-			$board_info['error'] = 'access';
1038
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1039
+					$board_info['error'] = 'access';
1040
+		}
1041
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1042
+					$board_info['error'] = 'access';
1043
+		}
999 1044
 
1000 1045
 		// Build up the linktree.
1001 1046
 		$context['linktree'] = array_merge(
@@ -1018,8 +1063,9 @@  discard block
 block discarded – undo
1018 1063
 	$context['current_board'] = $board;
1019 1064
 
1020 1065
 	// No posting in redirection boards!
1021
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1022
-		$board_info['error'] == 'post_in_redirect';
1066
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1067
+			$board_info['error'] == 'post_in_redirect';
1068
+	}
1023 1069
 
1024 1070
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1025 1071
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1045,24 +1091,23 @@  discard block
 block discarded – undo
1045 1091
 			ob_end_clean();
1046 1092
 			header('HTTP/1.1 403 Forbidden');
1047 1093
 			die;
1048
-		}
1049
-		elseif ($board_info['error'] == 'post_in_redirect')
1094
+		} elseif ($board_info['error'] == 'post_in_redirect')
1050 1095
 		{
1051 1096
 			// Slightly different error message here...
1052 1097
 			fatal_lang_error('cannot_post_redirect', false);
1053
-		}
1054
-		elseif ($user_info['is_guest'])
1098
+		} elseif ($user_info['is_guest'])
1055 1099
 		{
1056 1100
 			loadLanguage('Errors');
1057 1101
 			is_not_guest($txt['topic_gone']);
1102
+		} else {
1103
+					fatal_lang_error('topic_gone', false);
1058 1104
 		}
1059
-		else
1060
-			fatal_lang_error('topic_gone', false);
1061 1105
 	}
1062 1106
 
1063
-	if ($user_info['is_mod'])
1064
-		$user_info['groups'][] = 3;
1065
-}
1107
+	if ($user_info['is_mod']) {
1108
+			$user_info['groups'][] = 3;
1109
+	}
1110
+	}
1066 1111
 
1067 1112
 /**
1068 1113
  * Load this user's permissions.
@@ -1083,8 +1128,9 @@  discard block
 block discarded – undo
1083 1128
 		asort($cache_groups);
1084 1129
 		$cache_groups = implode(',', $cache_groups);
1085 1130
 		// If it's a spider then cache it different.
1086
-		if ($user_info['possibly_robot'])
1087
-			$cache_groups .= '-spider';
1131
+		if ($user_info['possibly_robot']) {
1132
+					$cache_groups .= '-spider';
1133
+		}
1088 1134
 
1089 1135
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1090 1136
 		{
@@ -1092,9 +1138,9 @@  discard block
 block discarded – undo
1092 1138
 			banPermissions();
1093 1139
 
1094 1140
 			return;
1141
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1142
+					list ($user_info['permissions'], $removals) = $temp;
1095 1143
 		}
1096
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1097
-			list ($user_info['permissions'], $removals) = $temp;
1098 1144
 	}
1099 1145
 
1100 1146
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1116,23 +1162,26 @@  discard block
 block discarded – undo
1116 1162
 		$removals = array();
1117 1163
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1118 1164
 		{
1119
-			if (empty($row['add_deny']))
1120
-				$removals[] = $row['permission'];
1121
-			else
1122
-				$user_info['permissions'][] = $row['permission'];
1165
+			if (empty($row['add_deny'])) {
1166
+							$removals[] = $row['permission'];
1167
+			} else {
1168
+							$user_info['permissions'][] = $row['permission'];
1169
+			}
1123 1170
 		}
1124 1171
 		$smcFunc['db_free_result']($request);
1125 1172
 
1126
-		if (isset($cache_groups))
1127
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1173
+		if (isset($cache_groups)) {
1174
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1175
+		}
1128 1176
 	}
1129 1177
 
1130 1178
 	// Get the board permissions.
1131 1179
 	if (!empty($board))
1132 1180
 	{
1133 1181
 		// Make sure the board (if any) has been loaded by loadBoard().
1134
-		if (!isset($board_info['profile']))
1135
-			fatal_lang_error('no_board');
1182
+		if (!isset($board_info['profile'])) {
1183
+					fatal_lang_error('no_board');
1184
+		}
1136 1185
 
1137 1186
 		$request = $smcFunc['db_query']('', '
1138 1187
 			SELECT permission, add_deny
@@ -1148,20 +1197,23 @@  discard block
 block discarded – undo
1148 1197
 		);
1149 1198
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1150 1199
 		{
1151
-			if (empty($row['add_deny']))
1152
-				$removals[] = $row['permission'];
1153
-			else
1154
-				$user_info['permissions'][] = $row['permission'];
1200
+			if (empty($row['add_deny'])) {
1201
+							$removals[] = $row['permission'];
1202
+			} else {
1203
+							$user_info['permissions'][] = $row['permission'];
1204
+			}
1155 1205
 		}
1156 1206
 		$smcFunc['db_free_result']($request);
1157 1207
 	}
1158 1208
 
1159 1209
 	// Remove all the permissions they shouldn't have ;).
1160
-	if (!empty($modSettings['permission_enable_deny']))
1161
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1210
+	if (!empty($modSettings['permission_enable_deny'])) {
1211
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1212
+	}
1162 1213
 
1163
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1164
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1214
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1215
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1216
+	}
1165 1217
 
1166 1218
 	// Banned?  Watch, don't touch..
1167 1219
 	banPermissions();
@@ -1173,17 +1225,18 @@  discard block
 block discarded – undo
1173 1225
 		{
1174 1226
 			require_once($sourcedir . '/Subs-Auth.php');
1175 1227
 			rebuildModCache();
1228
+		} else {
1229
+					$user_info['mod_cache'] = $_SESSION['mc'];
1176 1230
 		}
1177
-		else
1178
-			$user_info['mod_cache'] = $_SESSION['mc'];
1179 1231
 
1180 1232
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1181 1233
 		// For example this drastically simplifies certain changes to the profile area.
1182 1234
 		$user_info['permissions'][] = 'is_not_guest';
1183 1235
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1184 1236
 		$user_info['permissions'][] = 'profile_view_own';
1185
-		if (in_array('profile_view', $user_info['permissions']))
1186
-			$user_info['permissions'][] = 'profile_view_any';
1237
+		if (in_array('profile_view', $user_info['permissions'])) {
1238
+					$user_info['permissions'][] = 'profile_view_any';
1239
+		}
1187 1240
 	}
1188 1241
 }
1189 1242
 
@@ -1201,8 +1254,9 @@  discard block
 block discarded – undo
1201 1254
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1202 1255
 
1203 1256
 	// Can't just look for no users :P.
1204
-	if (empty($users))
1205
-		return array();
1257
+	if (empty($users)) {
1258
+			return array();
1259
+	}
1206 1260
 
1207 1261
 	// Pass the set value
1208 1262
 	$context['loadMemberContext_set'] = $set;
@@ -1217,8 +1271,9 @@  discard block
 block discarded – undo
1217 1271
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1218 1272
 		{
1219 1273
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1220
-			if ($data == null)
1221
-				continue;
1274
+			if ($data == null) {
1275
+							continue;
1276
+			}
1222 1277
 
1223 1278
 			$loaded_ids[] = $data['id_member'];
1224 1279
 			$user_profile[$data['id_member']] = $data;
@@ -1285,13 +1340,16 @@  discard block
 block discarded – undo
1285 1340
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1286 1341
 
1287 1342
 			// Take care of proxying avatar if required, do this here for maximum reach
1288
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1289
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1343
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1344
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1345
+			}
1290 1346
 
1291
-			if (isset($row['member_ip']))
1292
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1293
-			if (isset($row['member_ip2']))
1294
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1347
+			if (isset($row['member_ip'])) {
1348
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1349
+			}
1350
+			if (isset($row['member_ip2'])) {
1351
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1352
+			}
1295 1353
 			$new_loaded_ids[] = $row['id_member'];
1296 1354
 			$loaded_ids[] = $row['id_member'];
1297 1355
 			$row['options'] = array();
@@ -1310,8 +1368,9 @@  discard block
 block discarded – undo
1310 1368
 				'loaded_ids' => $new_loaded_ids,
1311 1369
 			)
1312 1370
 		);
1313
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1314
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1371
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1372
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1373
+		}
1315 1374
 		$smcFunc['db_free_result']($request);
1316 1375
 	}
1317 1376
 
@@ -1322,10 +1381,11 @@  discard block
 block discarded – undo
1322 1381
 	{
1323 1382
 		foreach ($loaded_ids as $a_member)
1324 1383
 		{
1325
-			if (!empty($user_profile[$a_member]['additional_groups']))
1326
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1327
-			else
1328
-				$groups = array($user_profile[$a_member]['id_group']);
1384
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1385
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1386
+			} else {
1387
+							$groups = array($user_profile[$a_member]['id_group']);
1388
+			}
1329 1389
 
1330 1390
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1331 1391
 
@@ -1338,8 +1398,9 @@  discard block
 block discarded – undo
1338 1398
 
1339 1399
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1340 1400
 	{
1341
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1342
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1401
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1402
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1403
+		}
1343 1404
 	}
1344 1405
 
1345 1406
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1365,14 +1426,17 @@  discard block
 block discarded – undo
1365 1426
 		foreach ($temp_mods as $id)
1366 1427
 		{
1367 1428
 			// By popular demand, don't show admins or global moderators as moderators.
1368
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1369
-				$user_profile[$id]['member_group'] = $row['member_group'];
1429
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1430
+							$user_profile[$id]['member_group'] = $row['member_group'];
1431
+			}
1370 1432
 
1371 1433
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1372
-			if (!empty($row['icons']))
1373
-				$user_profile[$id]['icons'] = $row['icons'];
1374
-			if (!empty($row['member_group_color']))
1375
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1434
+			if (!empty($row['icons'])) {
1435
+							$user_profile[$id]['icons'] = $row['icons'];
1436
+			}
1437
+			if (!empty($row['member_group_color'])) {
1438
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1439
+			}
1376 1440
 		}
1377 1441
 	}
1378 1442
 
@@ -1394,12 +1458,14 @@  discard block
 block discarded – undo
1394 1458
 	static $loadedLanguages = array();
1395 1459
 
1396 1460
 	// If this person's data is already loaded, skip it.
1397
-	if (isset($dataLoaded[$user]))
1398
-		return true;
1461
+	if (isset($dataLoaded[$user])) {
1462
+			return true;
1463
+	}
1399 1464
 
1400 1465
 	// We can't load guests or members not loaded by loadMemberData()!
1401
-	if ($user == 0)
1402
-		return false;
1466
+	if ($user == 0) {
1467
+			return false;
1468
+	}
1403 1469
 	if (!isset($user_profile[$user]))
1404 1470
 	{
1405 1471
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1425,12 +1491,16 @@  discard block
 block discarded – undo
1425 1491
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1426 1492
 
1427 1493
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1428
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1494
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1495
+		//icon is set and exists
1429 1496
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1430
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1497
+	} elseif (isset($profile['icons'][1])) {
1498
+		//icon is set and doesn't exist, fallback to default
1431 1499
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1432
-	else //not set, bye bye
1500
+	} else {
1501
+		//not set, bye bye
1433 1502
 		$group_icon_url = '';
1503
+	}
1434 1504
 
1435 1505
 	// These minimal values are always loaded
1436 1506
 	$memberContext[$user] = array(
@@ -1449,8 +1519,9 @@  discard block
 block discarded – undo
1449 1519
 	if ($context['loadMemberContext_set'] != 'minimal')
1450 1520
 	{
1451 1521
 		// Go the extra mile and load the user's native language name.
1452
-		if (empty($loadedLanguages))
1453
-			$loadedLanguages = getLanguages();
1522
+		if (empty($loadedLanguages)) {
1523
+					$loadedLanguages = getLanguages();
1524
+		}
1454 1525
 
1455 1526
 		$memberContext[$user] += array(
1456 1527
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1504,31 +1575,33 @@  discard block
 block discarded – undo
1504 1575
 	{
1505 1576
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1506 1577
 		{
1507
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1508
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1509
-			else
1510
-				$image = get_gravatar_url($profile['email_address']);
1511
-		}
1512
-		else
1578
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1579
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1580
+			} else {
1581
+							$image = get_gravatar_url($profile['email_address']);
1582
+			}
1583
+		} else
1513 1584
 		{
1514 1585
 			// So it's stored in the member table?
1515 1586
 			if (!empty($profile['avatar']))
1516 1587
 			{
1517 1588
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1589
+			} elseif (!empty($profile['filename'])) {
1590
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1518 1591
 			}
1519
-			elseif (!empty($profile['filename']))
1520
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1521 1592
 			// Right... no avatar...use the default one
1522
-			else
1523
-				$image = $modSettings['avatar_url'] . '/default.png';
1593
+			else {
1594
+							$image = $modSettings['avatar_url'] . '/default.png';
1595
+			}
1524 1596
 		}
1525
-		if (!empty($image))
1526
-			$memberContext[$user]['avatar'] = array(
1597
+		if (!empty($image)) {
1598
+					$memberContext[$user]['avatar'] = array(
1527 1599
 				'name' => $profile['avatar'],
1528 1600
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1529 1601
 				'href' => $image,
1530 1602
 				'url' => $image,
1531 1603
 			);
1604
+		}
1532 1605
 	}
1533 1606
 
1534 1607
 	// Are we also loading the members custom fields into context?
@@ -1536,35 +1609,41 @@  discard block
 block discarded – undo
1536 1609
 	{
1537 1610
 		$memberContext[$user]['custom_fields'] = array();
1538 1611
 
1539
-		if (!isset($context['display_fields']))
1540
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1612
+		if (!isset($context['display_fields'])) {
1613
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1614
+		}
1541 1615
 
1542 1616
 		foreach ($context['display_fields'] as $custom)
1543 1617
 		{
1544
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1545
-				continue;
1618
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1619
+							continue;
1620
+			}
1546 1621
 
1547 1622
 			$value = $profile['options'][$custom['col_name']];
1548 1623
 
1549 1624
 			// Don't show the "disabled" option for the "gender" field.
1550
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1551
-				continue;
1625
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1626
+							continue;
1627
+			}
1552 1628
 
1553 1629
 			// BBC?
1554
-			if ($custom['bbc'])
1555
-				$value = parse_bbc($value);
1630
+			if ($custom['bbc']) {
1631
+							$value = parse_bbc($value);
1632
+			}
1556 1633
 			// ... or checkbox?
1557
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1558
-				$value = $value ? $txt['yes'] : $txt['no'];
1634
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1635
+							$value = $value ? $txt['yes'] : $txt['no'];
1636
+			}
1559 1637
 
1560 1638
 			// Enclosing the user input within some other text?
1561
-			if (!empty($custom['enclose']))
1562
-				$value = strtr($custom['enclose'], array(
1639
+			if (!empty($custom['enclose'])) {
1640
+							$value = strtr($custom['enclose'], array(
1563 1641
 					'{SCRIPTURL}' => $scripturl,
1564 1642
 					'{IMAGES_URL}' => $settings['images_url'],
1565 1643
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1566 1644
 					'{INPUT}' => $value,
1567 1645
 				));
1646
+			}
1568 1647
 
1569 1648
 			$memberContext[$user]['custom_fields'][] = array(
1570 1649
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1591,8 +1670,9 @@  discard block
 block discarded – undo
1591 1670
 	global $smcFunc, $txt, $scripturl, $settings;
1592 1671
 
1593 1672
 	// Do not waste my time...
1594
-	if (empty($users) || empty($params))
1595
-		return false;
1673
+	if (empty($users) || empty($params)) {
1674
+			return false;
1675
+	}
1596 1676
 
1597 1677
 	// Make sure it's an array.
1598 1678
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1616,31 +1696,36 @@  discard block
 block discarded – undo
1616 1696
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1617 1697
 	{
1618 1698
 		// BBC?
1619
-		if (!empty($row['bbc']))
1620
-			$row['value'] = parse_bbc($row['value']);
1699
+		if (!empty($row['bbc'])) {
1700
+					$row['value'] = parse_bbc($row['value']);
1701
+		}
1621 1702
 
1622 1703
 		// ... or checkbox?
1623
-		elseif (isset($row['type']) && $row['type'] == 'check')
1624
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1704
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1705
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1706
+		}
1625 1707
 
1626 1708
 		// Enclosing the user input within some other text?
1627
-		if (!empty($row['enclose']))
1628
-			$row['value'] = strtr($row['enclose'], array(
1709
+		if (!empty($row['enclose'])) {
1710
+					$row['value'] = strtr($row['enclose'], array(
1629 1711
 				'{SCRIPTURL}' => $scripturl,
1630 1712
 				'{IMAGES_URL}' => $settings['images_url'],
1631 1713
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1632 1714
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1633 1715
 			));
1716
+		}
1634 1717
 
1635 1718
 		// Send a simple array if there is just 1 param
1636
-		if (count($params) == 1)
1637
-			$return[$row['id_member']] = $row;
1719
+		if (count($params) == 1) {
1720
+					$return[$row['id_member']] = $row;
1721
+		}
1638 1722
 
1639 1723
 		// More than 1? knock yourself out...
1640 1724
 		else
1641 1725
 		{
1642
-			if (!isset($return[$row['id_member']]))
1643
-				$return[$row['id_member']] = array();
1726
+			if (!isset($return[$row['id_member']])) {
1727
+							$return[$row['id_member']] = array();
1728
+			}
1644 1729
 
1645 1730
 			$return[$row['id_member']][$row['variable']] = $row;
1646 1731
 		}
@@ -1674,8 +1759,9 @@  discard block
 block discarded – undo
1674 1759
 	global $context;
1675 1760
 
1676 1761
 	// Don't know any browser!
1677
-	if (empty($context['browser']))
1678
-		detectBrowser();
1762
+	if (empty($context['browser'])) {
1763
+			detectBrowser();
1764
+	}
1679 1765
 
1680 1766
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1681 1767
 }
@@ -1693,8 +1779,9 @@  discard block
 block discarded – undo
1693 1779
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1694 1780
 
1695 1781
 	// The theme was specified by parameter.
1696
-	if (!empty($id_theme))
1697
-		$id_theme = (int) $id_theme;
1782
+	if (!empty($id_theme)) {
1783
+			$id_theme = (int) $id_theme;
1784
+	}
1698 1785
 	// The theme was specified by REQUEST.
1699 1786
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1700 1787
 	{
@@ -1702,51 +1789,58 @@  discard block
 block discarded – undo
1702 1789
 		$_SESSION['id_theme'] = $id_theme;
1703 1790
 	}
1704 1791
 	// The theme was specified by REQUEST... previously.
1705
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1706
-		$id_theme = (int) $_SESSION['id_theme'];
1792
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1793
+			$id_theme = (int) $_SESSION['id_theme'];
1794
+	}
1707 1795
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1708
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1709
-		$id_theme = $user_info['theme'];
1796
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1797
+			$id_theme = $user_info['theme'];
1798
+	}
1710 1799
 	// The theme was specified by the board.
1711
-	elseif (!empty($board_info['theme']))
1712
-		$id_theme = $board_info['theme'];
1800
+	elseif (!empty($board_info['theme'])) {
1801
+			$id_theme = $board_info['theme'];
1802
+	}
1713 1803
 	// The theme is the forum's default.
1714
-	else
1715
-		$id_theme = $modSettings['theme_guests'];
1804
+	else {
1805
+			$id_theme = $modSettings['theme_guests'];
1806
+	}
1716 1807
 
1717 1808
 	// Verify the id_theme... no foul play.
1718 1809
 	// Always allow the board specific theme, if they are overriding.
1719
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1720
-		$id_theme = $board_info['theme'];
1810
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1811
+			$id_theme = $board_info['theme'];
1812
+	}
1721 1813
 	// If they have specified a particular theme to use with SSI allow it to be used.
1722
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1723
-		$id_theme = (int) $id_theme;
1724
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1814
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1815
+			$id_theme = (int) $id_theme;
1816
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1725 1817
 	{
1726 1818
 		$themes = explode(',', $modSettings['enableThemes']);
1727
-		if (!in_array($id_theme, $themes))
1728
-			$id_theme = $modSettings['theme_guests'];
1729
-		else
1819
+		if (!in_array($id_theme, $themes)) {
1820
+					$id_theme = $modSettings['theme_guests'];
1821
+		} else {
1822
+					$id_theme = (int) $id_theme;
1823
+		}
1824
+	} else {
1730 1825
 			$id_theme = (int) $id_theme;
1731 1826
 	}
1732
-	else
1733
-		$id_theme = (int) $id_theme;
1734 1827
 
1735 1828
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1736 1829
 
1737 1830
 	// Disable image proxy if we don't have SSL enabled
1738
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1739
-		$image_proxy_enabled = false;
1831
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1832
+			$image_proxy_enabled = false;
1833
+	}
1740 1834
 
1741 1835
 	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'])
1742 1836
 	{
1743 1837
 		$themeData = $temp;
1744 1838
 		$flag = true;
1839
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1840
+			$themeData = $temp + array($member => array());
1841
+	} else {
1842
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1745 1843
 	}
1746
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1747
-		$themeData = $temp + array($member => array());
1748
-	else
1749
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1750 1844
 
1751 1845
 	if (empty($flag))
1752 1846
 	{
@@ -1765,31 +1859,37 @@  discard block
 block discarded – undo
1765 1859
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1766 1860
 		{
1767 1861
 			// There are just things we shouldn't be able to change as members.
1768
-			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')))
1769
-				continue;
1862
+			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'))) {
1863
+							continue;
1864
+			}
1770 1865
 
1771 1866
 			// If this is the theme_dir of the default theme, store it.
1772
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1773
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1867
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1868
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1869
+			}
1774 1870
 
1775 1871
 			// If this isn't set yet, is a theme option, or is not the default theme..
1776
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1777
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1872
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1873
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1874
+			}
1778 1875
 		}
1779 1876
 		$smcFunc['db_free_result']($result);
1780 1877
 
1781
-		if (!empty($themeData[-1]))
1782
-			foreach ($themeData[-1] as $k => $v)
1878
+		if (!empty($themeData[-1])) {
1879
+					foreach ($themeData[-1] as $k => $v)
1783 1880
 			{
1784 1881
 				if (!isset($themeData[$member][$k]))
1785 1882
 					$themeData[$member][$k] = $v;
1883
+		}
1786 1884
 			}
1787 1885
 
1788
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1789
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1886
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1887
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1888
+		}
1790 1889
 		// Only if we didn't already load that part of the cache...
1791
-		elseif (!isset($temp))
1792
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1890
+		elseif (!isset($temp)) {
1891
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1892
+		}
1793 1893
 	}
1794 1894
 
1795 1895
 	$settings = $themeData[0];
@@ -1806,20 +1906,24 @@  discard block
 block discarded – undo
1806 1906
 	$settings['template_dirs'][] = $settings['theme_dir'];
1807 1907
 
1808 1908
 	// Based on theme (if there is one).
1809
-	if (!empty($settings['base_theme_dir']))
1810
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1909
+	if (!empty($settings['base_theme_dir'])) {
1910
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1911
+	}
1811 1912
 
1812 1913
 	// Lastly the default theme.
1813
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1814
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1914
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1915
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1916
+	}
1815 1917
 
1816
-	if (!$initialize)
1817
-		return;
1918
+	if (!$initialize) {
1919
+			return;
1920
+	}
1818 1921
 
1819 1922
 	// Check to see if we're forcing SSL
1820 1923
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1821
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1822
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1924
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1925
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1926
+	}
1823 1927
 
1824 1928
 	// Check to see if they're accessing it from the wrong place.
1825 1929
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1827,8 +1931,9 @@  discard block
 block discarded – undo
1827 1931
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1828 1932
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1829 1933
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1830
-		if ($temp != '/')
1831
-			$detected_url .= $temp;
1934
+		if ($temp != '/') {
1935
+					$detected_url .= $temp;
1936
+		}
1832 1937
 	}
1833 1938
 	if (isset($detected_url) && $detected_url != $boardurl)
1834 1939
 	{
@@ -1840,8 +1945,9 @@  discard block
 block discarded – undo
1840 1945
 			foreach ($aliases as $alias)
1841 1946
 			{
1842 1947
 				// Rip off all the boring parts, spaces, etc.
1843
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1844
-					$do_fix = true;
1948
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1949
+									$do_fix = true;
1950
+				}
1845 1951
 			}
1846 1952
 		}
1847 1953
 
@@ -1849,20 +1955,22 @@  discard block
 block discarded – undo
1849 1955
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1850 1956
 		{
1851 1957
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1852
-			if (empty($_GET))
1853
-				redirectexit('wwwRedirect');
1854
-			else
1958
+			if (empty($_GET)) {
1959
+							redirectexit('wwwRedirect');
1960
+			} else
1855 1961
 			{
1856 1962
 				list ($k, $v) = each($_GET);
1857 1963
 
1858
-				if ($k != 'wwwRedirect')
1859
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1964
+				if ($k != 'wwwRedirect') {
1965
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1966
+				}
1860 1967
 			}
1861 1968
 		}
1862 1969
 
1863 1970
 		// #3 is just a check for SSL...
1864
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1865
-			$do_fix = true;
1971
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1972
+					$do_fix = true;
1973
+		}
1866 1974
 
1867 1975
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1868 1976
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1896,8 +2004,9 @@  discard block
 block discarded – undo
1896 2004
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1897 2005
 				}
1898 2006
 			}
1899
-			foreach ($context['linktree'] as $k => $dummy)
1900
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2007
+			foreach ($context['linktree'] as $k => $dummy) {
2008
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2009
+			}
1901 2010
 		}
1902 2011
 	}
1903 2012
 	// Set up the contextual user array.
@@ -1916,16 +2025,16 @@  discard block
 block discarded – undo
1916 2025
 			'email' => $user_info['email'],
1917 2026
 			'ignoreusers' => $user_info['ignoreusers'],
1918 2027
 		);
1919
-		if (!$context['user']['is_guest'])
1920
-			$context['user']['name'] = $user_info['name'];
1921
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1922
-			$context['user']['name'] = $txt['guest_title'];
2028
+		if (!$context['user']['is_guest']) {
2029
+					$context['user']['name'] = $user_info['name'];
2030
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2031
+					$context['user']['name'] = $txt['guest_title'];
2032
+		}
1923 2033
 
1924 2034
 		// Determine the current smiley set.
1925 2035
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1926 2036
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1927
-	}
1928
-	else
2037
+	} else
1929 2038
 	{
1930 2039
 		$context['user'] = array(
1931 2040
 			'id' => -1,
@@ -1941,18 +2050,24 @@  discard block
 block discarded – undo
1941 2050
 	}
1942 2051
 
1943 2052
 	// Some basic information...
1944
-	if (!isset($context['html_headers']))
1945
-		$context['html_headers'] = '';
1946
-	if (!isset($context['javascript_files']))
1947
-		$context['javascript_files'] = array();
1948
-	if (!isset($context['css_files']))
1949
-		$context['css_files'] = array();
1950
-	if (!isset($context['css_header']))
1951
-		$context['css_header'] = array();
1952
-	if (!isset($context['javascript_inline']))
1953
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1954
-	if (!isset($context['javascript_vars']))
1955
-		$context['javascript_vars'] = array();
2053
+	if (!isset($context['html_headers'])) {
2054
+			$context['html_headers'] = '';
2055
+	}
2056
+	if (!isset($context['javascript_files'])) {
2057
+			$context['javascript_files'] = array();
2058
+	}
2059
+	if (!isset($context['css_files'])) {
2060
+			$context['css_files'] = array();
2061
+	}
2062
+	if (!isset($context['css_header'])) {
2063
+			$context['css_header'] = array();
2064
+	}
2065
+	if (!isset($context['javascript_inline'])) {
2066
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2067
+	}
2068
+	if (!isset($context['javascript_vars'])) {
2069
+			$context['javascript_vars'] = array();
2070
+	}
1956 2071
 
1957 2072
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1958 2073
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1964,8 +2079,9 @@  discard block
 block discarded – undo
1964 2079
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1965 2080
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1966 2081
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1967
-	if (isset($modSettings['load_average']))
1968
-		$context['load_average'] = $modSettings['load_average'];
2082
+	if (isset($modSettings['load_average'])) {
2083
+			$context['load_average'] = $modSettings['load_average'];
2084
+	}
1969 2085
 
1970 2086
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1971 2087
 	detectBrowser();
@@ -1979,8 +2095,9 @@  discard block
 block discarded – undo
1979 2095
 	// This allows sticking some HTML on the page output - useful for controls.
1980 2096
 	$context['insert_after_template'] = '';
1981 2097
 
1982
-	if (!isset($txt))
1983
-		$txt = array();
2098
+	if (!isset($txt)) {
2099
+			$txt = array();
2100
+	}
1984 2101
 
1985 2102
 	$simpleActions = array(
1986 2103
 		'findmember',
@@ -2026,9 +2143,10 @@  discard block
 block discarded – undo
2026 2143
 
2027 2144
 	// See if theres any extra param to check.
2028 2145
 	$requiresXML = false;
2029
-	foreach ($extraParams as $key => $extra)
2030
-		if (isset($_REQUEST[$extra]))
2146
+	foreach ($extraParams as $key => $extra) {
2147
+			if (isset($_REQUEST[$extra]))
2031 2148
 			$requiresXML = true;
2149
+	}
2032 2150
 
2033 2151
 	// Output is fully XML, so no need for the index template.
2034 2152
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2043,37 +2161,39 @@  discard block
 block discarded – undo
2043 2161
 	{
2044 2162
 		loadLanguage('index+Modifications');
2045 2163
 		$context['template_layers'] = array();
2046
-	}
2047
-
2048
-	else
2164
+	} else
2049 2165
 	{
2050 2166
 		// Custom templates to load, or just default?
2051
-		if (isset($settings['theme_templates']))
2052
-			$templates = explode(',', $settings['theme_templates']);
2053
-		else
2054
-			$templates = array('index');
2167
+		if (isset($settings['theme_templates'])) {
2168
+					$templates = explode(',', $settings['theme_templates']);
2169
+		} else {
2170
+					$templates = array('index');
2171
+		}
2055 2172
 
2056 2173
 		// Load each template...
2057
-		foreach ($templates as $template)
2058
-			loadTemplate($template);
2174
+		foreach ($templates as $template) {
2175
+					loadTemplate($template);
2176
+		}
2059 2177
 
2060 2178
 		// ...and attempt to load their associated language files.
2061 2179
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2062 2180
 		loadLanguage($required_files, '', false);
2063 2181
 
2064 2182
 		// Custom template layers?
2065
-		if (isset($settings['theme_layers']))
2066
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2067
-		else
2068
-			$context['template_layers'] = array('html', 'body');
2183
+		if (isset($settings['theme_layers'])) {
2184
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2185
+		} else {
2186
+					$context['template_layers'] = array('html', 'body');
2187
+		}
2069 2188
 	}
2070 2189
 
2071 2190
 	// Initialize the theme.
2072 2191
 	loadSubTemplate('init', 'ignore');
2073 2192
 
2074 2193
 	// Allow overriding the board wide time/number formats.
2075
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2076
-		$user_info['time_format'] = $txt['time_format'];
2194
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2195
+			$user_info['time_format'] = $txt['time_format'];
2196
+	}
2077 2197
 
2078 2198
 	// Set the character set from the template.
2079 2199
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2081,12 +2201,14 @@  discard block
 block discarded – undo
2081 2201
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2082 2202
 
2083 2203
 	// Guests may still need a name.
2084
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2085
-		$context['user']['name'] = $txt['guest_title'];
2204
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2205
+			$context['user']['name'] = $txt['guest_title'];
2206
+	}
2086 2207
 
2087 2208
 	// Any theme-related strings that need to be loaded?
2088
-	if (!empty($settings['require_theme_strings']))
2089
-		loadLanguage('ThemeStrings', '', false);
2209
+	if (!empty($settings['require_theme_strings'])) {
2210
+			loadLanguage('ThemeStrings', '', false);
2211
+	}
2090 2212
 
2091 2213
 	// Make a special URL for the language.
2092 2214
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2097,8 +2219,9 @@  discard block
 block discarded – undo
2097 2219
 	// Here is my luvly Responsive CSS
2098 2220
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2099 2221
 
2100
-	if ($context['right_to_left'])
2101
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2222
+	if ($context['right_to_left']) {
2223
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2224
+	}
2102 2225
 
2103 2226
 	// We allow theme variants, because we're cool.
2104 2227
 	$context['theme_variant'] = '';
@@ -2106,14 +2229,17 @@  discard block
 block discarded – undo
2106 2229
 	if (!empty($settings['theme_variants']))
2107 2230
 	{
2108 2231
 		// Overriding - for previews and that ilk.
2109
-		if (!empty($_REQUEST['variant']))
2110
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2232
+		if (!empty($_REQUEST['variant'])) {
2233
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2234
+		}
2111 2235
 		// User selection?
2112
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2113
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2236
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2237
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2238
+		}
2114 2239
 		// If not a user variant, select the default.
2115
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2116
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2240
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2241
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2242
+		}
2117 2243
 
2118 2244
 		// Do this to keep things easier in the templates.
2119 2245
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2122,20 +2248,23 @@  discard block
 block discarded – undo
2122 2248
 		if (!empty($context['theme_variant']))
2123 2249
 		{
2124 2250
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2125
-			if ($context['right_to_left'])
2126
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2251
+			if ($context['right_to_left']) {
2252
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2253
+			}
2127 2254
 		}
2128 2255
 	}
2129 2256
 
2130 2257
 	// Let's be compatible with old themes!
2131
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2132
-		$context['template_layers'] = array('main');
2258
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2259
+			$context['template_layers'] = array('main');
2260
+	}
2133 2261
 
2134 2262
 	$context['tabindex'] = 1;
2135 2263
 
2136 2264
 	// Compatibility.
2137
-	if (!isset($settings['theme_version']))
2138
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2265
+	if (!isset($settings['theme_version'])) {
2266
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2267
+	}
2139 2268
 
2140 2269
 	// Default JS variables for use in every theme
2141 2270
 	$context['javascript_vars'] = array(
@@ -2154,18 +2283,18 @@  discard block
 block discarded – undo
2154 2283
 	);
2155 2284
 
2156 2285
 	// Add the JQuery library to the list of files to load.
2157
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2158
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2159
-
2160
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2161
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2162
-
2163
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2164
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2286
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2287
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2288
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2289
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2290
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2291
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2292
+	}
2165 2293
 
2166 2294
 	// Auto loading? template_javascript() will take care of the local half of this.
2167
-	else
2168
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2295
+	else {
2296
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2297
+	}
2169 2298
 
2170 2299
 	// Queue our JQuery plugins!
2171 2300
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2188,12 +2317,12 @@  discard block
 block discarded – undo
2188 2317
 			require_once($sourcedir . '/ScheduledTasks.php');
2189 2318
 
2190 2319
 			// What to do, what to do?!
2191
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2192
-				AutoTask();
2193
-			else
2194
-				ReduceMailQueue();
2195
-		}
2196
-		else
2320
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2321
+							AutoTask();
2322
+			} else {
2323
+							ReduceMailQueue();
2324
+			}
2325
+		} else
2197 2326
 		{
2198 2327
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2199 2328
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2244,8 +2373,9 @@  discard block
 block discarded – undo
2244 2373
 		foreach ($theme_includes as $include)
2245 2374
 		{
2246 2375
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2247
-			if (file_exists($include))
2248
-				require_once($include);
2376
+			if (file_exists($include)) {
2377
+							require_once($include);
2378
+			}
2249 2379
 		}
2250 2380
 	}
2251 2381
 
@@ -2275,16 +2405,19 @@  discard block
 block discarded – undo
2275 2405
 	// Do any style sheets first, cause we're easy with those.
2276 2406
 	if (!empty($style_sheets))
2277 2407
 	{
2278
-		if (!is_array($style_sheets))
2279
-			$style_sheets = array($style_sheets);
2408
+		if (!is_array($style_sheets)) {
2409
+					$style_sheets = array($style_sheets);
2410
+		}
2280 2411
 
2281
-		foreach ($style_sheets as $sheet)
2282
-			loadCSSFile($sheet . '.css', array(), $sheet);
2412
+		foreach ($style_sheets as $sheet) {
2413
+					loadCSSFile($sheet . '.css', array(), $sheet);
2414
+		}
2283 2415
 	}
2284 2416
 
2285 2417
 	// No template to load?
2286
-	if ($template_name === false)
2287
-		return true;
2418
+	if ($template_name === false) {
2419
+			return true;
2420
+	}
2288 2421
 
2289 2422
 	$loaded = false;
2290 2423
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2299,12 +2432,14 @@  discard block
 block discarded – undo
2299 2432
 
2300 2433
 	if ($loaded)
2301 2434
 	{
2302
-		if ($db_show_debug === true)
2303
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2435
+		if ($db_show_debug === true) {
2436
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2437
+		}
2304 2438
 
2305 2439
 		// If they have specified an initialization function for this template, go ahead and call it now.
2306
-		if (function_exists('template_' . $template_name . '_init'))
2307
-			call_user_func('template_' . $template_name . '_init');
2440
+		if (function_exists('template_' . $template_name . '_init')) {
2441
+					call_user_func('template_' . $template_name . '_init');
2442
+		}
2308 2443
 	}
2309 2444
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2310 2445
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2324,13 +2459,14 @@  discard block
 block discarded – undo
2324 2459
 		loadTemplate($template_name);
2325 2460
 	}
2326 2461
 	// Cause an error otherwise.
2327
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2328
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2329
-	elseif ($fatal)
2330
-		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'));
2331
-	else
2332
-		return false;
2333
-}
2462
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2463
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2464
+	} elseif ($fatal) {
2465
+			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'));
2466
+	} else {
2467
+			return false;
2468
+	}
2469
+	}
2334 2470
 
2335 2471
 /**
2336 2472
  * Load a sub-template.
@@ -2348,17 +2484,19 @@  discard block
 block discarded – undo
2348 2484
 {
2349 2485
 	global $context, $txt, $db_show_debug;
2350 2486
 
2351
-	if ($db_show_debug === true)
2352
-		$context['debug']['sub_templates'][] = $sub_template_name;
2487
+	if ($db_show_debug === true) {
2488
+			$context['debug']['sub_templates'][] = $sub_template_name;
2489
+	}
2353 2490
 
2354 2491
 	// Figure out what the template function is named.
2355 2492
 	$theme_function = 'template_' . $sub_template_name;
2356
-	if (function_exists($theme_function))
2357
-		$theme_function();
2358
-	elseif ($fatal === false)
2359
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2360
-	elseif ($fatal !== 'ignore')
2361
-		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'));
2493
+	if (function_exists($theme_function)) {
2494
+			$theme_function();
2495
+	} elseif ($fatal === false) {
2496
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2497
+	} elseif ($fatal !== 'ignore') {
2498
+			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'));
2499
+	}
2362 2500
 
2363 2501
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2364 2502
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2395,8 +2533,9 @@  discard block
 block discarded – undo
2395 2533
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2396 2534
 
2397 2535
 	// If this is an external file, automatically set this to false.
2398
-	if (!empty($params['external']))
2399
-		$params['minimize'] = false;
2536
+	if (!empty($params['external'])) {
2537
+			$params['minimize'] = false;
2538
+	}
2400 2539
 
2401 2540
 	// Account for shorthand like admin.css?alp21 filenames
2402 2541
 	$has_seed = strpos($fileName, '.css?');
@@ -2413,13 +2552,10 @@  discard block
 block discarded – undo
2413 2552
 			{
2414 2553
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2415 2554
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2555
+			} else {
2556
+							$fileUrl = false;
2416 2557
 			}
2417
-
2418
-			else
2419
-				$fileUrl = false;
2420
-		}
2421
-
2422
-		else
2558
+		} else
2423 2559
 		{
2424 2560
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2425 2561
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2434,12 +2570,14 @@  discard block
 block discarded – undo
2434 2570
 	}
2435 2571
 
2436 2572
 	// Add it to the array for use in the template
2437
-	if (!empty($fileName))
2438
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2573
+	if (!empty($fileName)) {
2574
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2575
+	}
2439 2576
 
2440
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2441
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2442
-}
2577
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2578
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2579
+	}
2580
+	}
2443 2581
 
2444 2582
 /**
2445 2583
  * Add a block of inline css code to be executed later
@@ -2456,8 +2594,9 @@  discard block
 block discarded – undo
2456 2594
 	global $context;
2457 2595
 
2458 2596
 	// Gotta add something...
2459
-	if (empty($css))
2460
-		return false;
2597
+	if (empty($css)) {
2598
+			return false;
2599
+	}
2461 2600
 
2462 2601
 	$context['css_header'][] = $css;
2463 2602
 }
@@ -2492,8 +2631,9 @@  discard block
 block discarded – undo
2492 2631
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2493 2632
 
2494 2633
 	// If this is an external file, automatically set this to false.
2495
-	if (!empty($params['external']))
2496
-		$params['minimize'] = false;
2634
+	if (!empty($params['external'])) {
2635
+			$params['minimize'] = false;
2636
+	}
2497 2637
 
2498 2638
 	// Account for shorthand like admin.js?alp21 filenames
2499 2639
 	$has_seed = strpos($fileName, '.js?');
@@ -2510,16 +2650,12 @@  discard block
 block discarded – undo
2510 2650
 			{
2511 2651
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2512 2652
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2513
-			}
2514
-
2515
-			else
2653
+			} else
2516 2654
 			{
2517 2655
 				$fileUrl = false;
2518 2656
 				$filePath = false;
2519 2657
 			}
2520
-		}
2521
-
2522
-		else
2658
+		} else
2523 2659
 		{
2524 2660
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2525 2661
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2534,9 +2670,10 @@  discard block
 block discarded – undo
2534 2670
 	}
2535 2671
 
2536 2672
 	// Add it to the array for use in the template
2537
-	if (!empty($fileName))
2538
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2539
-}
2673
+	if (!empty($fileName)) {
2674
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2675
+	}
2676
+	}
2540 2677
 
2541 2678
 /**
2542 2679
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2550,9 +2687,10 @@  discard block
 block discarded – undo
2550 2687
 {
2551 2688
 	global $context;
2552 2689
 
2553
-	if (!empty($key) && (!empty($value) || $value === '0'))
2554
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2555
-}
2690
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2691
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2692
+	}
2693
+	}
2556 2694
 
2557 2695
 /**
2558 2696
  * Add a block of inline Javascript code to be executed later
@@ -2569,8 +2707,9 @@  discard block
 block discarded – undo
2569 2707
 {
2570 2708
 	global $context;
2571 2709
 
2572
-	if (empty($javascript))
2573
-		return false;
2710
+	if (empty($javascript)) {
2711
+			return false;
2712
+	}
2574 2713
 
2575 2714
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2576 2715
 }
@@ -2591,15 +2730,18 @@  discard block
 block discarded – undo
2591 2730
 	static $already_loaded = array();
2592 2731
 
2593 2732
 	// Default to the user's language.
2594
-	if ($lang == '')
2595
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2733
+	if ($lang == '') {
2734
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2735
+	}
2596 2736
 
2597 2737
 	// Do we want the English version of language file as fallback?
2598
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2599
-		loadLanguage($template_name, 'english', false);
2738
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2739
+			loadLanguage($template_name, 'english', false);
2740
+	}
2600 2741
 
2601
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2602
-		return $lang;
2742
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2743
+			return $lang;
2744
+	}
2603 2745
 
2604 2746
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2605 2747
 	if (empty($settings['default_theme_dir']))
@@ -2610,8 +2752,9 @@  discard block
 block discarded – undo
2610 2752
 
2611 2753
 	// What theme are we in?
2612 2754
 	$theme_name = basename($settings['theme_url']);
2613
-	if (empty($theme_name))
2614
-		$theme_name = 'unknown';
2755
+	if (empty($theme_name)) {
2756
+			$theme_name = 'unknown';
2757
+	}
2615 2758
 
2616 2759
 	// For each file open it up and write it out!
2617 2760
 	foreach (explode('+', $template_name) as $template)
@@ -2653,8 +2796,9 @@  discard block
 block discarded – undo
2653 2796
 				$found = true;
2654 2797
 
2655 2798
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2656
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2657
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2799
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2800
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2801
+				}
2658 2802
 
2659 2803
 				break;
2660 2804
 			}
@@ -2694,8 +2838,9 @@  discard block
 block discarded – undo
2694 2838
 	}
2695 2839
 
2696 2840
 	// Keep track of what we're up to soldier.
2697
-	if ($db_show_debug === true)
2698
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2841
+	if ($db_show_debug === true) {
2842
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2843
+	}
2699 2844
 
2700 2845
 	// Remember what we have loaded, and in which language.
2701 2846
 	$already_loaded[$template_name] = $lang;
@@ -2741,8 +2886,9 @@  discard block
 block discarded – undo
2741 2886
 				)
2742 2887
 			);
2743 2888
 			// In the EXTREMELY unlikely event this happens, give an error message.
2744
-			if ($smcFunc['db_num_rows']($result) == 0)
2745
-				fatal_lang_error('parent_not_found', 'critical');
2889
+			if ($smcFunc['db_num_rows']($result) == 0) {
2890
+							fatal_lang_error('parent_not_found', 'critical');
2891
+			}
2746 2892
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2747 2893
 			{
2748 2894
 				if (!isset($boards[$row['id_board']]))
@@ -2759,8 +2905,8 @@  discard block
 block discarded – undo
2759 2905
 					);
2760 2906
 				}
2761 2907
 				// If a moderator exists for this board, add that moderator for all children too.
2762
-				if (!empty($row['id_moderator']))
2763
-					foreach ($boards as $id => $dummy)
2908
+				if (!empty($row['id_moderator'])) {
2909
+									foreach ($boards as $id => $dummy)
2764 2910
 					{
2765 2911
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2766 2912
 							'id' => $row['id_moderator'],
@@ -2768,11 +2914,12 @@  discard block
 block discarded – undo
2768 2914
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2769 2915
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2770 2916
 						);
2917
+				}
2771 2918
 					}
2772 2919
 
2773 2920
 				// If a moderator group exists for this board, add that moderator group for all children too
2774
-				if (!empty($row['id_moderator_group']))
2775
-					foreach ($boards as $id => $dummy)
2921
+				if (!empty($row['id_moderator_group'])) {
2922
+									foreach ($boards as $id => $dummy)
2776 2923
 					{
2777 2924
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2778 2925
 							'id' => $row['id_moderator_group'],
@@ -2780,6 +2927,7 @@  discard block
 block discarded – undo
2780 2927
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2781 2928
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2782 2929
 						);
2930
+				}
2783 2931
 					}
2784 2932
 			}
2785 2933
 			$smcFunc['db_free_result']($result);
@@ -2806,23 +2954,27 @@  discard block
 block discarded – undo
2806 2954
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2807 2955
 	{
2808 2956
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2809
-		if (empty($smcFunc['ucwords']))
2810
-			reloadSettings();
2957
+		if (empty($smcFunc['ucwords'])) {
2958
+					reloadSettings();
2959
+		}
2811 2960
 
2812 2961
 		// If we don't have our theme information yet, let's get it.
2813
-		if (empty($settings['default_theme_dir']))
2814
-			loadTheme(0, false);
2962
+		if (empty($settings['default_theme_dir'])) {
2963
+					loadTheme(0, false);
2964
+		}
2815 2965
 
2816 2966
 		// Default language directories to try.
2817 2967
 		$language_directories = array(
2818 2968
 			$settings['default_theme_dir'] . '/languages',
2819 2969
 		);
2820
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2821
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2970
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2971
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2972
+		}
2822 2973
 
2823 2974
 		// We possibly have a base theme directory.
2824
-		if (!empty($settings['base_theme_dir']))
2825
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2975
+		if (!empty($settings['base_theme_dir'])) {
2976
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2977
+		}
2826 2978
 
2827 2979
 		// Remove any duplicates.
2828 2980
 		$language_directories = array_unique($language_directories);
@@ -2836,20 +2988,21 @@  discard block
 block discarded – undo
2836 2988
 		foreach ($language_directories as $language_dir)
2837 2989
 		{
2838 2990
 			// Can't look in here... doesn't exist!
2839
-			if (!file_exists($language_dir))
2840
-				continue;
2991
+			if (!file_exists($language_dir)) {
2992
+							continue;
2993
+			}
2841 2994
 
2842 2995
 			$dir = dir($language_dir);
2843 2996
 			while ($entry = $dir->read())
2844 2997
 			{
2845 2998
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2846
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2847
-					continue;
2848
-
2849
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2850
-					$langName = $langList[$matches[1]];
2999
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3000
+									continue;
3001
+				}
2851 3002
 
2852
-				else
3003
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3004
+									$langName = $langList[$matches[1]];
3005
+				} else
2853 3006
 				{
2854 3007
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2855 3008
 
@@ -2890,12 +3043,14 @@  discard block
 block discarded – undo
2890 3043
 		}
2891 3044
 
2892 3045
 		// Do we need to store the lang list?
2893
-		if (empty($langList))
2894
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3046
+		if (empty($langList)) {
3047
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3048
+		}
2895 3049
 
2896 3050
 		// Let's cash in on this deal.
2897
-		if (!empty($modSettings['cache_enable']))
2898
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3051
+		if (!empty($modSettings['cache_enable'])) {
3052
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3053
+		}
2899 3054
 	}
2900 3055
 
2901 3056
 	return $context['languages'];
@@ -2918,8 +3073,9 @@  discard block
 block discarded – undo
2918 3073
 	global $modSettings, $options, $txt;
2919 3074
 	static $censor_vulgar = null, $censor_proper;
2920 3075
 
2921
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2922
-		return $text;
3076
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3077
+			return $text;
3078
+	}
2923 3079
 
2924 3080
 	// If they haven't yet been loaded, load them.
2925 3081
 	if ($censor_vulgar == null)
@@ -2947,9 +3103,9 @@  discard block
 block discarded – undo
2947 3103
 	{
2948 3104
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2949 3105
 		$text = $func($censor_vulgar, $censor_proper, $text);
3106
+	} else {
3107
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2950 3108
 	}
2951
-	else
2952
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2953 3109
 
2954 3110
 	return $text;
2955 3111
 }
@@ -2975,38 +3131,42 @@  discard block
 block discarded – undo
2975 3131
 	@ini_set('track_errors', '1');
2976 3132
 
2977 3133
 	// Don't include the file more than once, if $once is true.
2978
-	if ($once && in_array($filename, $templates))
2979
-		return;
3134
+	if ($once && in_array($filename, $templates)) {
3135
+			return;
3136
+	}
2980 3137
 	// Add this file to the include list, whether $once is true or not.
2981
-	else
2982
-		$templates[] = $filename;
3138
+	else {
3139
+			$templates[] = $filename;
3140
+	}
2983 3141
 
2984 3142
 	// Are we going to use eval?
2985 3143
 	if (empty($modSettings['disableTemplateEval']))
2986 3144
 	{
2987 3145
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2988 3146
 		$settings['current_include_filename'] = $filename;
2989
-	}
2990
-	else
3147
+	} else
2991 3148
 	{
2992 3149
 		$file_found = file_exists($filename);
2993 3150
 
2994
-		if ($once && $file_found)
2995
-			require_once($filename);
2996
-		elseif ($file_found)
2997
-			require($filename);
3151
+		if ($once && $file_found) {
3152
+					require_once($filename);
3153
+		} elseif ($file_found) {
3154
+					require($filename);
3155
+		}
2998 3156
 	}
2999 3157
 
3000 3158
 	if ($file_found !== true)
3001 3159
 	{
3002 3160
 		ob_end_clean();
3003
-		if (!empty($modSettings['enableCompressedOutput']))
3004
-			@ob_start('ob_gzhandler');
3005
-		else
3006
-			ob_start();
3161
+		if (!empty($modSettings['enableCompressedOutput'])) {
3162
+					@ob_start('ob_gzhandler');
3163
+		} else {
3164
+					ob_start();
3165
+		}
3007 3166
 
3008
-		if (isset($_GET['debug']))
3009
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3167
+		if (isset($_GET['debug'])) {
3168
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3169
+		}
3010 3170
 
3011 3171
 		// Don't cache error pages!!
3012 3172
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3025,12 +3185,13 @@  discard block
 block discarded – undo
3025 3185
 		echo '<!DOCTYPE html>
3026 3186
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3027 3187
 	<head>';
3028
-		if (isset($context['character_set']))
3029
-			echo '
3188
+		if (isset($context['character_set'])) {
3189
+					echo '
3030 3190
 		<meta charset="', $context['character_set'], '">';
3191
+		}
3031 3192
 
3032
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3033
-			echo '
3193
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3194
+					echo '
3034 3195
 		<title>', $mtitle, '</title>
3035 3196
 	</head>
3036 3197
 	<body>
@@ -3038,8 +3199,8 @@  discard block
 block discarded – undo
3038 3199
 		', $mmessage, '
3039 3200
 	</body>
3040 3201
 </html>';
3041
-		elseif (!allowedTo('admin_forum'))
3042
-			echo '
3202
+		} elseif (!allowedTo('admin_forum')) {
3203
+					echo '
3043 3204
 		<title>', $txt['template_parse_error'], '</title>
3044 3205
 	</head>
3045 3206
 	<body>
@@ -3047,16 +3208,18 @@  discard block
 block discarded – undo
3047 3208
 		', $txt['template_parse_error_message'], '
3048 3209
 	</body>
3049 3210
 </html>';
3050
-		else
3211
+		} else
3051 3212
 		{
3052 3213
 			require_once($sourcedir . '/Subs-Package.php');
3053 3214
 
3054 3215
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3055 3216
 			$error_array = error_get_last();
3056
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3057
-				$error = $error_array['message'];
3058
-			if (empty($error))
3059
-				$error = $txt['template_parse_errmsg'];
3217
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3218
+							$error = $error_array['message'];
3219
+			}
3220
+			if (empty($error)) {
3221
+							$error = $txt['template_parse_errmsg'];
3222
+			}
3060 3223
 
3061 3224
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3062 3225
 
@@ -3067,11 +3230,12 @@  discard block
 block discarded – undo
3067 3230
 		<h3>', $txt['template_parse_error'], '</h3>
3068 3231
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3069 3232
 
3070
-			if (!empty($error))
3071
-				echo '
3233
+			if (!empty($error)) {
3234
+							echo '
3072 3235
 		<hr>
3073 3236
 
3074 3237
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3238
+			}
3075 3239
 
3076 3240
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3077 3241
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3081,10 +3245,11 @@  discard block
 block discarded – undo
3081 3245
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3082 3246
 
3083 3247
 				// Fix the PHP code stuff...
3084
-				if (!isBrowser('gecko'))
3085
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3086
-				else
3087
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3248
+				if (!isBrowser('gecko')) {
3249
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3250
+				} else {
3251
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3252
+				}
3088 3253
 
3089 3254
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3090 3255
 				$j = -1;
@@ -3092,8 +3257,9 @@  discard block
 block discarded – undo
3092 3257
 				{
3093 3258
 					$j++;
3094 3259
 
3095
-					if (substr_count($line, '<br>') == 0)
3096
-						continue;
3260
+					if (substr_count($line, '<br>') == 0) {
3261
+											continue;
3262
+					}
3097 3263
 
3098 3264
 					$n = substr_count($line, '<br>');
3099 3265
 					for ($i = 0; $i < $n; $i++)
@@ -3112,38 +3278,42 @@  discard block
 block discarded – undo
3112 3278
 				// Figure out what the color coding was before...
3113 3279
 				$line = max($match[1] - 9, 1);
3114 3280
 				$last_line = '';
3115
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3116
-					if (strpos($data2[$line2], '<') !== false)
3281
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3282
+									if (strpos($data2[$line2], '<') !== false)
3117 3283
 					{
3118 3284
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3119 3285
 							$last_line = $color_match[1];
3286
+				}
3120 3287
 						break;
3121 3288
 					}
3122 3289
 
3123 3290
 				// Show the relevant lines...
3124 3291
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3125 3292
 				{
3126
-					if ($line == $match[1])
3127
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3293
+					if ($line == $match[1]) {
3294
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3295
+					}
3128 3296
 
3129 3297
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3130
-					if (isset($data2[$line]) && $data2[$line] != '')
3131
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3298
+					if (isset($data2[$line]) && $data2[$line] != '') {
3299
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3300
+					}
3132 3301
 
3133 3302
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3134 3303
 					{
3135 3304
 						$last_line = $color_match[1];
3136 3305
 						echo '</', substr($last_line, 1, 4), '>';
3306
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3307
+											$last_line = '';
3308
+					} elseif ($last_line != '' && $data2[$line] != '') {
3309
+											echo '</', substr($last_line, 1, 4), '>';
3137 3310
 					}
3138
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3139
-						$last_line = '';
3140
-					elseif ($last_line != '' && $data2[$line] != '')
3141
-						echo '</', substr($last_line, 1, 4), '>';
3142 3311
 
3143
-					if ($line == $match[1])
3144
-						echo '</pre></div><pre style="margin: 0;">';
3145
-					else
3146
-						echo "\n";
3312
+					if ($line == $match[1]) {
3313
+											echo '</pre></div><pre style="margin: 0;">';
3314
+					} else {
3315
+											echo "\n";
3316
+					}
3147 3317
 				}
3148 3318
 
3149 3319
 				echo '</pre></div>';
@@ -3167,8 +3337,9 @@  discard block
 block discarded – undo
3167 3337
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3168 3338
 
3169 3339
 	// Figure out what type of database we are using.
3170
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3171
-		$db_type = 'mysql';
3340
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3341
+			$db_type = 'mysql';
3342
+	}
3172 3343
 
3173 3344
 	// Load the file for the database.
3174 3345
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3176,8 +3347,9 @@  discard block
 block discarded – undo
3176 3347
 	$db_options = array();
3177 3348
 
3178 3349
 	// Add in the port if needed
3179
-	if (!empty($db_port))
3180
-		$db_options['port'] = $db_port;
3350
+	if (!empty($db_port)) {
3351
+			$db_options['port'] = $db_port;
3352
+	}
3181 3353
 
3182 3354
 	// 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.
3183 3355
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3196,13 +3368,15 @@  discard block
 block discarded – undo
3196 3368
 	}
3197 3369
 
3198 3370
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3199
-	if (!$db_connection)
3200
-		display_db_error();
3371
+	if (!$db_connection) {
3372
+			display_db_error();
3373
+	}
3201 3374
 
3202 3375
 	// If in SSI mode fix up the prefix.
3203
-	if (SMF == 'SSI')
3204
-		db_fix_prefix($db_prefix, $db_name);
3205
-}
3376
+	if (SMF == 'SSI') {
3377
+			db_fix_prefix($db_prefix, $db_name);
3378
+	}
3379
+	}
3206 3380
 
3207 3381
 /**
3208 3382
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3216,10 +3390,11 @@  discard block
 block discarded – undo
3216 3390
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3217 3391
 
3218 3392
 	// Not overriding this and we have a cacheAPI, send it back.
3219
-	if (empty($overrideCache) && is_object($cacheAPI))
3220
-		return $cacheAPI;
3221
-	elseif (is_null($cacheAPI))
3222
-		$cacheAPI = false;
3393
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3394
+			return $cacheAPI;
3395
+	} elseif (is_null($cacheAPI)) {
3396
+			$cacheAPI = false;
3397
+	}
3223 3398
 
3224 3399
 	// Make sure our class is in session.
3225 3400
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3240,8 +3415,9 @@  discard block
 block discarded – undo
3240 3415
 		if (!$testAPI->isSupported())
3241 3416
 		{
3242 3417
 			// Can we save ourselves?
3243
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3244
-				return loadCacheAccelerator(null, false);
3418
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3419
+							return loadCacheAccelerator(null, false);
3420
+			}
3245 3421
 			return false;
3246 3422
 		}
3247 3423
 
@@ -3253,9 +3429,9 @@  discard block
 block discarded – undo
3253 3429
 		{
3254 3430
 			$cacheAPI = $testAPI;
3255 3431
 			return $cacheAPI;
3432
+		} else {
3433
+					return $testAPI;
3256 3434
 		}
3257
-		else
3258
-			return $testAPI;
3259 3435
 	}
3260 3436
 }
3261 3437
 
@@ -3275,8 +3451,9 @@  discard block
 block discarded – undo
3275 3451
 
3276 3452
 	// @todo Why are we doing this if caching is disabled?
3277 3453
 
3278
-	if (function_exists('call_integration_hook'))
3279
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3454
+	if (function_exists('call_integration_hook')) {
3455
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3456
+	}
3280 3457
 
3281 3458
 	/* Refresh the cache if either:
3282 3459
 		1. Caching is disabled.
@@ -3290,16 +3467,19 @@  discard block
 block discarded – undo
3290 3467
 		require_once($sourcedir . '/' . $file);
3291 3468
 		$cache_block = call_user_func_array($function, $params);
3292 3469
 
3293
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3294
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3470
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3471
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3472
+		}
3295 3473
 	}
3296 3474
 
3297 3475
 	// Some cached data may need a freshening up after retrieval.
3298
-	if (!empty($cache_block['post_retri_eval']))
3299
-		eval($cache_block['post_retri_eval']);
3476
+	if (!empty($cache_block['post_retri_eval'])) {
3477
+			eval($cache_block['post_retri_eval']);
3478
+	}
3300 3479
 
3301
-	if (function_exists('call_integration_hook'))
3302
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3480
+	if (function_exists('call_integration_hook')) {
3481
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3482
+	}
3303 3483
 
3304 3484
 	return $cache_block['data'];
3305 3485
 }
@@ -3326,8 +3506,9 @@  discard block
 block discarded – undo
3326 3506
 	global $smcFunc, $cache_enable, $cacheAPI;
3327 3507
 	global $cache_hits, $cache_count, $db_show_debug;
3328 3508
 
3329
-	if (empty($cache_enable) || empty($cacheAPI))
3330
-		return;
3509
+	if (empty($cache_enable) || empty($cacheAPI)) {
3510
+			return;
3511
+	}
3331 3512
 
3332 3513
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3333 3514
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3340,12 +3521,14 @@  discard block
 block discarded – undo
3340 3521
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3341 3522
 	$cacheAPI->putData($key, $value, $ttl);
3342 3523
 
3343
-	if (function_exists('call_integration_hook'))
3344
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3524
+	if (function_exists('call_integration_hook')) {
3525
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3526
+	}
3345 3527
 
3346
-	if (isset($db_show_debug) && $db_show_debug === true)
3347
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3348
-}
3528
+	if (isset($db_show_debug) && $db_show_debug === true) {
3529
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3530
+	}
3531
+	}
3349 3532
 
3350 3533
 /**
3351 3534
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3361,8 +3544,9 @@  discard block
 block discarded – undo
3361 3544
 	global $smcFunc, $cache_enable, $cacheAPI;
3362 3545
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3363 3546
 
3364
-	if (empty($cache_enable) || empty($cacheAPI))
3365
-		return;
3547
+	if (empty($cache_enable) || empty($cacheAPI)) {
3548
+			return;
3549
+	}
3366 3550
 
3367 3551
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3368 3552
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3382,16 +3566,18 @@  discard block
 block discarded – undo
3382 3566
 
3383 3567
 		if (empty($value))
3384 3568
 		{
3385
-			if (!is_array($cache_misses))
3386
-				$cache_misses = array();
3569
+			if (!is_array($cache_misses)) {
3570
+							$cache_misses = array();
3571
+			}
3387 3572
 
3388 3573
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3389 3574
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3390 3575
 		}
3391 3576
 	}
3392 3577
 
3393
-	if (function_exists('call_integration_hook') && isset($value))
3394
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3578
+	if (function_exists('call_integration_hook') && isset($value)) {
3579
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3580
+	}
3395 3581
 
3396 3582
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3397 3583
 }
@@ -3413,8 +3599,9 @@  discard block
 block discarded – undo
3413 3599
 	global $cacheAPI;
3414 3600
 
3415 3601
 	// If we can't get to the API, can't do this.
3416
-	if (empty($cacheAPI))
3417
-		return;
3602
+	if (empty($cacheAPI)) {
3603
+			return;
3604
+	}
3418 3605
 
3419 3606
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3420 3607
 	$cacheAPI->cleanCache($type);
@@ -3439,8 +3626,9 @@  discard block
 block discarded – undo
3439 3626
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3440 3627
 
3441 3628
 	// Come on!
3442
-	if (empty($data))
3443
-		return array();
3629
+	if (empty($data)) {
3630
+			return array();
3631
+	}
3444 3632
 
3445 3633
 	// Set a nice default var.
3446 3634
 	$image = '';
@@ -3448,11 +3636,11 @@  discard block
 block discarded – undo
3448 3636
 	// Gravatar has been set as mandatory!
3449 3637
 	if (!empty($modSettings['gravatarOverride']))
3450 3638
 	{
3451
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3452
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3453
-
3454
-		else if (!empty($data['email']))
3455
-			$image = get_gravatar_url($data['email']);
3639
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3640
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3641
+		} else if (!empty($data['email'])) {
3642
+					$image = get_gravatar_url($data['email']);
3643
+		}
3456 3644
 	}
3457 3645
 
3458 3646
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3464,54 +3652,60 @@  discard block
 block discarded – undo
3464 3652
 			// Gravatar.
3465 3653
 			if (stristr($data['avatar'], 'gravatar://'))
3466 3654
 			{
3467
-				if ($data['avatar'] == 'gravatar://')
3468
-					$image = get_gravatar_url($data['email']);
3469
-
3470
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3471
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3655
+				if ($data['avatar'] == 'gravatar://') {
3656
+									$image = get_gravatar_url($data['email']);
3657
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3658
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3659
+				}
3472 3660
 			}
3473 3661
 
3474 3662
 			// External url.
3475 3663
 			else
3476 3664
 			{
3477 3665
 				// Using ssl?
3478
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3479
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3666
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3667
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3668
+				}
3480 3669
 
3481 3670
 				// Just a plain external url.
3482
-				else
3483
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3671
+				else {
3672
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3673
+				}
3484 3674
 			}
3485 3675
 		}
3486 3676
 
3487 3677
 		// Perhaps this user has an attachment as avatar...
3488
-		else if (!empty($data['filename']))
3489
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3678
+		else if (!empty($data['filename'])) {
3679
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3680
+		}
3490 3681
 
3491 3682
 		// Right... no avatar... use our default image.
3492
-		else
3493
-			$image = $modSettings['avatar_url'] . '/default.png';
3683
+		else {
3684
+					$image = $modSettings['avatar_url'] . '/default.png';
3685
+		}
3494 3686
 	}
3495 3687
 
3496 3688
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3497 3689
 
3498 3690
 	// 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.
3499
-	if (!empty($image))
3500
-		return array(
3691
+	if (!empty($image)) {
3692
+			return array(
3501 3693
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3502 3694
 			'image' => '<img class="avatar" src="' . $image . '" />',
3503 3695
 			'href' => $image,
3504 3696
 			'url' => $image,
3505 3697
 		);
3698
+	}
3506 3699
 
3507 3700
 	// Fallback to make life easier for everyone...
3508
-	else
3509
-		return array(
3701
+	else {
3702
+			return array(
3510 3703
 			'name' => '',
3511 3704
 			'image' => '',
3512 3705
 			'href' => '',
3513 3706
 			'url' => '',
3514 3707
 		);
3515
-}
3708
+	}
3709
+	}
3516 3710
 
3517 3711
 ?>
3518 3712
\ No newline at end of file
Please login to merge, or discard this patch.