Completed
Push — release-2.1 ( 26e7ba...473bd5 )
by Jeremy
10:28 queued 04:21
created
Sources/Load.php 1 patch
Braces   +792 added lines, -597 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We explicitly do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -410,9 +427,9 @@  discard block
 block discarded – undo
410 427
 				break;
411 428
 			}
412 429
 		}
430
+	} else {
431
+			$id_member = 0;
413 432
 	}
414
-	else
415
-		$id_member = 0;
416 433
 
417 434
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
418 435
 	{
@@ -420,8 +437,9 @@  discard block
 block discarded – undo
420 437
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
421 438
 
422 439
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
423
-		if (empty($cookie_data))
424
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
440
+		if (empty($cookie_data)) {
441
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
442
+		}
425 443
 
426 444
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
427 445
 
@@ -429,16 +447,17 @@  discard block
 block discarded – undo
429 447
 
430 448
 		// Make sure the cookie is set to the correct domain and path
431 449
 		require_once($sourcedir . '/Subs-Auth.php');
432
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
433
-			setLoginCookie((int) $login_span - time(), $id_member);
434
-	}
435
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
450
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
451
+					setLoginCookie((int) $login_span - time(), $id_member);
452
+		}
453
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
436 454
 	{
437 455
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
438 456
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
439 457
 
440
-		if (empty($cookie_data))
441
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
458
+		if (empty($cookie_data)) {
459
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
460
+		}
442 461
 
443 462
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
444 463
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -463,30 +482,34 @@  discard block
 block discarded – undo
463 482
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
464 483
 			$smcFunc['db_free_result']($request);
465 484
 
466
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
467
-				$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
485
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
486
+							$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
487
+			}
468 488
 
469
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
470
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
489
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
490
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
491
+			}
471 492
 		}
472 493
 
473 494
 		// Did we find 'im?  If not, junk it.
474 495
 		if (!empty($user_settings))
475 496
 		{
476 497
 			// As much as the password should be right, we can assume the integration set things up.
477
-			if (!empty($already_verified) && $already_verified === true)
478
-				$check = true;
498
+			if (!empty($already_verified) && $already_verified === true) {
499
+							$check = true;
500
+			}
479 501
 			// SHA-512 hash should be 128 characters long.
480
-			elseif (strlen($password) == 128)
481
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
482
-			else
483
-				$check = false;
502
+			elseif (strlen($password) == 128) {
503
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
504
+			} else {
505
+							$check = false;
506
+			}
484 507
 
485 508
 			// Wrong password or not activated - either way, you're going nowhere.
486 509
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
510
+		} else {
511
+					$id_member = 0;
487 512
 		}
488
-		else
489
-			$id_member = 0;
490 513
 
491 514
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
492 515
 		if (!$id_member)
@@ -515,8 +538,9 @@  discard block
 block discarded – undo
515 538
 
516 539
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
517 540
 
518
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
519
-						$tfasecret = null;
541
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
542
+											$tfasecret = null;
543
+					}
520 544
 				}
521 545
 
522 546
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -538,10 +562,12 @@  discard block
 block discarded – undo
538 562
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
539 563
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
540 564
 		{
541
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
565
+			if ($modSettings['tfa_mode'] == 2) {
566
+				//only do this if we are just forcing SOME membergroups
542 567
 			{
543 568
 				//Build an array of ALL user membergroups.
544 569
 				$full_groups = array($user_settings['id_group']);
570
+			}
545 571
 				if (!empty($user_settings['additional_groups']))
546 572
 				{
547 573
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -561,15 +587,17 @@  discard block
 block discarded – undo
561 587
 				);
562 588
 				$row = $smcFunc['db_fetch_assoc']($request);
563 589
 				$smcFunc['db_free_result']($request);
590
+			} else {
591
+							$row['total'] = 1;
564 592
 			}
565
-			else
566
-				$row['total'] = 1; //simplifies logics in the next "if"
593
+			//simplifies logics in the next "if"
567 594
 
568 595
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
569 596
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
570 597
 
571
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
572
-				redirectexit('action=profile;area=tfasetup;forced');
598
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
599
+							redirectexit('action=profile;area=tfasetup;forced');
600
+			}
573 601
 		}
574 602
 	}
575 603
 
@@ -606,29 +634,32 @@  discard block
 block discarded – undo
606 634
 				updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']));
607 635
 				$user_settings['last_login'] = time();
608 636
 
609
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
610
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
637
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
638
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
639
+				}
611 640
 
612
-				if (!empty($modSettings['cache_enable']))
613
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
641
+				if (!empty($modSettings['cache_enable'])) {
642
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
643
+				}
614 644
 			}
645
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
646
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
615 647
 		}
616
-		elseif (empty($_SESSION['id_msg_last_visit']))
617
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
618 648
 
619 649
 		$username = $user_settings['member_name'];
620 650
 
621
-		if (empty($user_settings['additional_groups']))
622
-			$user_info = array(
651
+		if (empty($user_settings['additional_groups'])) {
652
+					$user_info = array(
623 653
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
624 654
 			);
625
-		else
626
-			$user_info = array(
655
+		} else {
656
+					$user_info = array(
627 657
 				'groups' => array_merge(
628 658
 					array($user_settings['id_group'], $user_settings['id_post_group']),
629 659
 					explode(',', $user_settings['additional_groups'])
630 660
 				)
631 661
 			);
662
+		}
632 663
 
633 664
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
634 665
 		$user_info['groups'] = array_map('intval', $user_info['groups']);
@@ -645,8 +676,7 @@  discard block
 block discarded – undo
645 676
 			$time_system = new DateTime('now', $tz_system);
646 677
 			$time_user = new DateTime('now', $tz_user);
647 678
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
648
-		}
649
-		else
679
+		} else
650 680
 		{
651 681
 			// !!! Compatibility.
652 682
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -660,8 +690,9 @@  discard block
 block discarded – undo
660 690
 		$user_info = array('groups' => array(-1));
661 691
 		$user_settings = array();
662 692
 
663
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
664
-			$_COOKIE[$cookiename] = '';
693
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
694
+					$_COOKIE[$cookiename] = '';
695
+		}
665 696
 
666 697
 		// Expire the 2FA cookie
667 698
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -678,19 +709,20 @@  discard block
 block discarded – undo
678 709
 		}
679 710
 
680 711
 		// Create a login token if it doesn't exist yet.
681
-		if (!isset($_SESSION['token']['post-login']))
682
-			createToken('login');
683
-		else
684
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
712
+		if (!isset($_SESSION['token']['post-login'])) {
713
+					createToken('login');
714
+		} else {
715
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
716
+		}
685 717
 
686 718
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
687 719
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
688 720
 		{
689 721
 			require_once($sourcedir . '/ManageSearchEngines.php');
690 722
 			$user_info['possibly_robot'] = SpiderCheck();
723
+		} elseif (!empty($modSettings['spider_mode'])) {
724
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
691 725
 		}
692
-		elseif (!empty($modSettings['spider_mode']))
693
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
694 726
 		// If we haven't turned on proper spider hunts then have a guess!
695 727
 		else
696 728
 		{
@@ -738,8 +770,9 @@  discard block
 block discarded – undo
738 770
 	$user_info['groups'] = array_unique($user_info['groups']);
739 771
 
740 772
 	// Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems.
741
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
742
-		unset($user_info['ignoreboards'][$tmp]);
773
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
774
+			unset($user_info['ignoreboards'][$tmp]);
775
+	}
743 776
 
744 777
 	// Allow the user to change their language.
745 778
 	if (!empty($modSettings['userLanguage']))
@@ -752,13 +785,14 @@  discard block
 block discarded – undo
752 785
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
753 786
 
754 787
 			// Make it permanent for members.
755
-			if (!empty($user_info['id']))
756
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
757
-			else
758
-				$_SESSION['language'] = $user_info['language'];
788
+			if (!empty($user_info['id'])) {
789
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
790
+			} else {
791
+							$_SESSION['language'] = $user_info['language'];
792
+			}
793
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
794
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
759 795
 		}
760
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
761
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
762 796
 	}
763 797
 
764 798
 	$temp = build_query_board($user_info['id']);
@@ -821,9 +855,9 @@  discard block
 block discarded – undo
821 855
 		}
822 856
 
823 857
 		// Remember redirection is the key to avoiding fallout from your bosses.
824
-		if (!empty($topic))
825
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
826
-		else
858
+		if (!empty($topic)) {
859
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
860
+		} else
827 861
 		{
828 862
 			loadPermissions();
829 863
 			loadTheme();
@@ -841,10 +875,11 @@  discard block
 block discarded – undo
841 875
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
842 876
 	{
843 877
 		// @todo SLOW?
844
-		if (!empty($topic))
845
-			$temp = cache_get_data('topic_board-' . $topic, 120);
846
-		else
847
-			$temp = cache_get_data('board-' . $board, 120);
878
+		if (!empty($topic)) {
879
+					$temp = cache_get_data('topic_board-' . $topic, 120);
880
+		} else {
881
+					$temp = cache_get_data('board-' . $board, 120);
882
+		}
848 883
 
849 884
 		if (!empty($temp))
850 885
 		{
@@ -882,8 +917,9 @@  discard block
 block discarded – undo
882 917
 			$row = $smcFunc['db_fetch_assoc']($request);
883 918
 
884 919
 			// Set the current board.
885
-			if (!empty($row['id_board']))
886
-				$board = $row['id_board'];
920
+			if (!empty($row['id_board'])) {
921
+							$board = $row['id_board'];
922
+			}
887 923
 
888 924
 			// Basic operating information. (globals... :/)
889 925
 			$board_info = array(
@@ -919,21 +955,23 @@  discard block
 block discarded – undo
919 955
 
920 956
 			do
921 957
 			{
922
-				if (!empty($row['id_moderator']))
923
-					$board_info['moderators'][$row['id_moderator']] = array(
958
+				if (!empty($row['id_moderator'])) {
959
+									$board_info['moderators'][$row['id_moderator']] = array(
924 960
 						'id' => $row['id_moderator'],
925 961
 						'name' => $row['real_name'],
926 962
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
927 963
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
928 964
 					);
965
+				}
929 966
 
930
-				if (!empty($row['id_moderator_group']))
931
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
967
+				if (!empty($row['id_moderator_group'])) {
968
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
932 969
 						'id' => $row['id_moderator_group'],
933 970
 						'name' => $row['group_name'],
934 971
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
935 972
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
936 973
 					);
974
+				}
937 975
 			}
938 976
 			while ($row = $smcFunc['db_fetch_assoc']($request));
939 977
 
@@ -965,12 +1003,12 @@  discard block
 block discarded – undo
965 1003
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
966 1004
 			{
967 1005
 				// @todo SLOW?
968
-				if (!empty($topic))
969
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1006
+				if (!empty($topic)) {
1007
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1008
+				}
970 1009
 				cache_put_data('board-' . $board, $board_info, 120);
971 1010
 			}
972
-		}
973
-		else
1011
+		} else
974 1012
 		{
975 1013
 			// Otherwise the topic is invalid, there are no moderators, etc.
976 1014
 			$board_info = array(
@@ -984,8 +1022,9 @@  discard block
 block discarded – undo
984 1022
 		$smcFunc['db_free_result']($request);
985 1023
 	}
986 1024
 
987
-	if (!empty($topic))
988
-		$_GET['board'] = (int) $board;
1025
+	if (!empty($topic)) {
1026
+			$_GET['board'] = (int) $board;
1027
+	}
989 1028
 
990 1029
 	if (!empty($board))
991 1030
 	{
@@ -995,10 +1034,12 @@  discard block
 block discarded – undo
995 1034
 		// Now check if the user is a moderator.
996 1035
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
997 1036
 
998
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
999
-			$board_info['error'] = 'access';
1000
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
1001
-			$board_info['error'] = 'access';
1037
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1038
+					$board_info['error'] = 'access';
1039
+		}
1040
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1041
+					$board_info['error'] = 'access';
1042
+		}
1002 1043
 
1003 1044
 		// Build up the linktree.
1004 1045
 		$context['linktree'] = array_merge(
@@ -1021,8 +1062,9 @@  discard block
 block discarded – undo
1021 1062
 	$context['current_board'] = $board;
1022 1063
 
1023 1064
 	// No posting in redirection boards!
1024
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1025
-		$board_info['error'] == 'post_in_redirect';
1065
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1066
+			$board_info['error'] == 'post_in_redirect';
1067
+	}
1026 1068
 
1027 1069
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1028 1070
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1048,24 +1090,23 @@  discard block
 block discarded – undo
1048 1090
 			ob_end_clean();
1049 1091
 			send_http_status(403);
1050 1092
 			die;
1051
-		}
1052
-		elseif ($board_info['error'] == 'post_in_redirect')
1093
+		} elseif ($board_info['error'] == 'post_in_redirect')
1053 1094
 		{
1054 1095
 			// Slightly different error message here...
1055 1096
 			fatal_lang_error('cannot_post_redirect', false);
1056
-		}
1057
-		elseif ($user_info['is_guest'])
1097
+		} elseif ($user_info['is_guest'])
1058 1098
 		{
1059 1099
 			loadLanguage('Errors');
1060 1100
 			is_not_guest($txt['topic_gone']);
1101
+		} else {
1102
+					fatal_lang_error('topic_gone', false);
1061 1103
 		}
1062
-		else
1063
-			fatal_lang_error('topic_gone', false);
1064 1104
 	}
1065 1105
 
1066
-	if ($user_info['is_mod'])
1067
-		$user_info['groups'][] = 3;
1068
-}
1106
+	if ($user_info['is_mod']) {
1107
+			$user_info['groups'][] = 3;
1108
+	}
1109
+	}
1069 1110
 
1070 1111
 /**
1071 1112
  * Load this user's permissions.
@@ -1086,8 +1127,9 @@  discard block
 block discarded – undo
1086 1127
 		asort($cache_groups);
1087 1128
 		$cache_groups = implode(',', $cache_groups);
1088 1129
 		// If it's a spider then cache it different.
1089
-		if ($user_info['possibly_robot'])
1090
-			$cache_groups .= '-spider';
1130
+		if ($user_info['possibly_robot']) {
1131
+					$cache_groups .= '-spider';
1132
+		}
1091 1133
 
1092 1134
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1093 1135
 		{
@@ -1095,9 +1137,9 @@  discard block
 block discarded – undo
1095 1137
 			banPermissions();
1096 1138
 
1097 1139
 			return;
1140
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1141
+					list ($user_info['permissions'], $removals) = $temp;
1098 1142
 		}
1099
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1100
-			list ($user_info['permissions'], $removals) = $temp;
1101 1143
 	}
1102 1144
 
1103 1145
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1119,23 +1161,26 @@  discard block
 block discarded – undo
1119 1161
 		$removals = array();
1120 1162
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1121 1163
 		{
1122
-			if (empty($row['add_deny']))
1123
-				$removals[] = $row['permission'];
1124
-			else
1125
-				$user_info['permissions'][] = $row['permission'];
1164
+			if (empty($row['add_deny'])) {
1165
+							$removals[] = $row['permission'];
1166
+			} else {
1167
+							$user_info['permissions'][] = $row['permission'];
1168
+			}
1126 1169
 		}
1127 1170
 		$smcFunc['db_free_result']($request);
1128 1171
 
1129
-		if (isset($cache_groups))
1130
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1172
+		if (isset($cache_groups)) {
1173
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1174
+		}
1131 1175
 	}
1132 1176
 
1133 1177
 	// Get the board permissions.
1134 1178
 	if (!empty($board))
1135 1179
 	{
1136 1180
 		// Make sure the board (if any) has been loaded by loadBoard().
1137
-		if (!isset($board_info['profile']))
1138
-			fatal_lang_error('no_board');
1181
+		if (!isset($board_info['profile'])) {
1182
+					fatal_lang_error('no_board');
1183
+		}
1139 1184
 
1140 1185
 		$request = $smcFunc['db_query']('', '
1141 1186
 			SELECT permission, add_deny
@@ -1151,20 +1196,23 @@  discard block
 block discarded – undo
1151 1196
 		);
1152 1197
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1153 1198
 		{
1154
-			if (empty($row['add_deny']))
1155
-				$removals[] = $row['permission'];
1156
-			else
1157
-				$user_info['permissions'][] = $row['permission'];
1199
+			if (empty($row['add_deny'])) {
1200
+							$removals[] = $row['permission'];
1201
+			} else {
1202
+							$user_info['permissions'][] = $row['permission'];
1203
+			}
1158 1204
 		}
1159 1205
 		$smcFunc['db_free_result']($request);
1160 1206
 	}
1161 1207
 
1162 1208
 	// Remove all the permissions they shouldn't have ;).
1163
-	if (!empty($modSettings['permission_enable_deny']))
1164
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1209
+	if (!empty($modSettings['permission_enable_deny'])) {
1210
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1211
+	}
1165 1212
 
1166
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1167
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1213
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1214
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1215
+	}
1168 1216
 
1169 1217
 	// Banned?  Watch, don't touch..
1170 1218
 	banPermissions();
@@ -1176,17 +1224,18 @@  discard block
 block discarded – undo
1176 1224
 		{
1177 1225
 			require_once($sourcedir . '/Subs-Auth.php');
1178 1226
 			rebuildModCache();
1227
+		} else {
1228
+					$user_info['mod_cache'] = $_SESSION['mc'];
1179 1229
 		}
1180
-		else
1181
-			$user_info['mod_cache'] = $_SESSION['mc'];
1182 1230
 
1183 1231
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1184 1232
 		// For example this drastically simplifies certain changes to the profile area.
1185 1233
 		$user_info['permissions'][] = 'is_not_guest';
1186 1234
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1187 1235
 		$user_info['permissions'][] = 'profile_view_own';
1188
-		if (in_array('profile_view', $user_info['permissions']))
1189
-			$user_info['permissions'][] = 'profile_view_any';
1236
+		if (in_array('profile_view', $user_info['permissions'])) {
1237
+					$user_info['permissions'][] = 'profile_view_any';
1238
+		}
1190 1239
 	}
1191 1240
 }
1192 1241
 
@@ -1204,8 +1253,9 @@  discard block
 block discarded – undo
1204 1253
 	global $image_proxy_enabled, $user_info;
1205 1254
 
1206 1255
 	// Can't just look for no users :P.
1207
-	if (empty($users))
1208
-		return array();
1256
+	if (empty($users)) {
1257
+			return array();
1258
+	}
1209 1259
 
1210 1260
 	// Pass the set value
1211 1261
 	$context['loadMemberContext_set'] = $set;
@@ -1220,8 +1270,9 @@  discard block
 block discarded – undo
1220 1270
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1221 1271
 		{
1222 1272
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1223
-			if ($data == null)
1224
-				continue;
1273
+			if ($data == null) {
1274
+							continue;
1275
+			}
1225 1276
 
1226 1277
 			$loaded_ids[] = $data['id_member'];
1227 1278
 			$user_profile[$data['id_member']] = $data;
@@ -1288,16 +1339,19 @@  discard block
 block discarded – undo
1288 1339
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1289 1340
 
1290 1341
 			// Take care of proxying avatar if required, do this here for maximum reach
1291
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1292
-				$row['avatar'] = get_proxied_url($row['avatar']);
1342
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1343
+							$row['avatar'] = get_proxied_url($row['avatar']);
1344
+			}
1293 1345
 
1294 1346
 			// Keep track of the member's normal member group
1295 1347
 			$row['primary_group'] = !empty($row['member_group']) ? $row['member_group'] : '';
1296 1348
 
1297
-			if (isset($row['member_ip']))
1298
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1299
-			if (isset($row['member_ip2']))
1300
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1349
+			if (isset($row['member_ip'])) {
1350
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1351
+			}
1352
+			if (isset($row['member_ip2'])) {
1353
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1354
+			}
1301 1355
 			$row['id_member'] = (int) $row['id_member'];
1302 1356
 			$new_loaded_ids[] = $row['id_member'];
1303 1357
 			$loaded_ids[] = $row['id_member'];
@@ -1317,8 +1371,9 @@  discard block
 block discarded – undo
1317 1371
 				'loaded_ids' => $new_loaded_ids,
1318 1372
 			)
1319 1373
 		);
1320
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1321
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1374
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1375
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1376
+		}
1322 1377
 		$smcFunc['db_free_result']($request);
1323 1378
 	}
1324 1379
 
@@ -1329,10 +1384,11 @@  discard block
 block discarded – undo
1329 1384
 	{
1330 1385
 		foreach ($loaded_ids as $a_member)
1331 1386
 		{
1332
-			if (!empty($user_profile[$a_member]['additional_groups']))
1333
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1334
-			else
1335
-				$groups = array($user_profile[$a_member]['id_group']);
1387
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1388
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1389
+			} else {
1390
+							$groups = array($user_profile[$a_member]['id_group']);
1391
+			}
1336 1392
 
1337 1393
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1338 1394
 
@@ -1345,8 +1401,9 @@  discard block
 block discarded – undo
1345 1401
 
1346 1402
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1347 1403
 	{
1348
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1349
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1404
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1405
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1406
+		}
1350 1407
 	}
1351 1408
 
1352 1409
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1372,14 +1429,17 @@  discard block
 block discarded – undo
1372 1429
 		foreach ($temp_mods as $id)
1373 1430
 		{
1374 1431
 			// By popular demand, don't show admins or global moderators as moderators.
1375
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1376
-				$user_profile[$id]['member_group'] = $row['member_group'];
1432
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1433
+							$user_profile[$id]['member_group'] = $row['member_group'];
1434
+			}
1377 1435
 
1378 1436
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1379
-			if (!empty($row['icons']))
1380
-				$user_profile[$id]['icons'] = $row['icons'];
1381
-			if (!empty($row['member_group_color']))
1382
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1437
+			if (!empty($row['icons'])) {
1438
+							$user_profile[$id]['icons'] = $row['icons'];
1439
+			}
1440
+			if (!empty($row['member_group_color'])) {
1441
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1442
+			}
1383 1443
 		}
1384 1444
 	}
1385 1445
 
@@ -1401,12 +1461,14 @@  discard block
 block discarded – undo
1401 1461
 	static $loadedLanguages = array();
1402 1462
 
1403 1463
 	// If this person's data is already loaded, skip it.
1404
-	if (isset($dataLoaded[$user]))
1405
-		return true;
1464
+	if (isset($dataLoaded[$user])) {
1465
+			return true;
1466
+	}
1406 1467
 
1407 1468
 	// We can't load guests or members not loaded by loadMemberData()!
1408
-	if ($user == 0)
1409
-		return false;
1469
+	if ($user == 0) {
1470
+			return false;
1471
+	}
1410 1472
 	if (!isset($user_profile[$user]))
1411 1473
 	{
1412 1474
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1432,12 +1494,16 @@  discard block
 block discarded – undo
1432 1494
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1433 1495
 
1434 1496
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1435
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1497
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1498
+		//icon is set and exists
1436 1499
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1437
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1500
+	} elseif (isset($profile['icons'][1])) {
1501
+		//icon is set and doesn't exist, fallback to default
1438 1502
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1439
-	else //not set, bye bye
1503
+	} else {
1504
+		//not set, bye bye
1440 1505
 		$group_icon_url = '';
1506
+	}
1441 1507
 
1442 1508
 	// These minimal values are always loaded
1443 1509
 	$memberContext[$user] = array(
@@ -1456,8 +1522,9 @@  discard block
 block discarded – undo
1456 1522
 	if ($context['loadMemberContext_set'] != 'minimal')
1457 1523
 	{
1458 1524
 		// Go the extra mile and load the user's native language name.
1459
-		if (empty($loadedLanguages))
1460
-			$loadedLanguages = getLanguages();
1525
+		if (empty($loadedLanguages)) {
1526
+					$loadedLanguages = getLanguages();
1527
+		}
1461 1528
 
1462 1529
 		$memberContext[$user] += array(
1463 1530
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1512,31 +1579,33 @@  discard block
 block discarded – undo
1512 1579
 	{
1513 1580
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1514 1581
 		{
1515
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1516
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1517
-			else
1518
-				$image = get_gravatar_url($profile['email_address']);
1519
-		}
1520
-		else
1582
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1583
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1584
+			} else {
1585
+							$image = get_gravatar_url($profile['email_address']);
1586
+			}
1587
+		} else
1521 1588
 		{
1522 1589
 			// So it's stored in the member table?
1523 1590
 			if (!empty($profile['avatar']))
1524 1591
 			{
1525 1592
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1593
+			} elseif (!empty($profile['filename'])) {
1594
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1526 1595
 			}
1527
-			elseif (!empty($profile['filename']))
1528
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1529 1596
 			// Right... no avatar...use the default one
1530
-			else
1531
-				$image = $modSettings['avatar_url'] . '/default.png';
1597
+			else {
1598
+							$image = $modSettings['avatar_url'] . '/default.png';
1599
+			}
1532 1600
 		}
1533
-		if (!empty($image))
1534
-			$memberContext[$user]['avatar'] = array(
1601
+		if (!empty($image)) {
1602
+					$memberContext[$user]['avatar'] = array(
1535 1603
 				'name' => $profile['avatar'],
1536 1604
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1537 1605
 				'href' => $image,
1538 1606
 				'url' => $image,
1539 1607
 			);
1608
+		}
1540 1609
 	}
1541 1610
 
1542 1611
 	// Are we also loading the members custom fields into context?
@@ -1544,13 +1613,15 @@  discard block
 block discarded – undo
1544 1613
 	{
1545 1614
 		$memberContext[$user]['custom_fields'] = array();
1546 1615
 
1547
-		if (!isset($context['display_fields']))
1548
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1616
+		if (!isset($context['display_fields'])) {
1617
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1618
+		}
1549 1619
 
1550 1620
 		foreach ($context['display_fields'] as $custom)
1551 1621
 		{
1552
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1553
-				continue;
1622
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1623
+							continue;
1624
+			}
1554 1625
 
1555 1626
 			$value = $profile['options'][$custom['col_name']];
1556 1627
 
@@ -1558,31 +1629,36 @@  discard block
 block discarded – undo
1558 1629
 			$currentKey = 0;
1559 1630
 
1560 1631
 			// Create a key => value array for multiple options fields
1561
-			if (!empty($custom['options']))
1562
-				foreach ($custom['options'] as $k => $v)
1632
+			if (!empty($custom['options'])) {
1633
+							foreach ($custom['options'] as $k => $v)
1563 1634
 				{
1564 1635
 					$fieldOptions[] = $v;
1565
-					if (empty($currentKey))
1566
-						$currentKey = $v == $value ? $k : 0;
1636
+			}
1637
+					if (empty($currentKey)) {
1638
+											$currentKey = $v == $value ? $k : 0;
1639
+					}
1567 1640
 				}
1568 1641
 
1569 1642
 			// BBC?
1570
-			if ($custom['bbc'])
1571
-				$value = parse_bbc($value);
1643
+			if ($custom['bbc']) {
1644
+							$value = parse_bbc($value);
1645
+			}
1572 1646
 
1573 1647
 			// ... or checkbox?
1574
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1575
-				$value = $value ? $txt['yes'] : $txt['no'];
1648
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1649
+							$value = $value ? $txt['yes'] : $txt['no'];
1650
+			}
1576 1651
 
1577 1652
 			// Enclosing the user input within some other text?
1578
-			if (!empty($custom['enclose']))
1579
-				$value = strtr($custom['enclose'], array(
1653
+			if (!empty($custom['enclose'])) {
1654
+							$value = strtr($custom['enclose'], array(
1580 1655
 					'{SCRIPTURL}' => $scripturl,
1581 1656
 					'{IMAGES_URL}' => $settings['images_url'],
1582 1657
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1583 1658
 					'{INPUT}' => $value,
1584 1659
 					'{KEY}' => $currentKey,
1585 1660
 				));
1661
+			}
1586 1662
 
1587 1663
 			$memberContext[$user]['custom_fields'][] = array(
1588 1664
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1609,8 +1685,9 @@  discard block
 block discarded – undo
1609 1685
 	global $smcFunc, $txt, $scripturl, $settings;
1610 1686
 
1611 1687
 	// Do not waste my time...
1612
-	if (empty($users) || empty($params))
1613
-		return false;
1688
+	if (empty($users) || empty($params)) {
1689
+			return false;
1690
+	}
1614 1691
 
1615 1692
 	// Make sure it's an array.
1616 1693
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1637,41 +1714,48 @@  discard block
 block discarded – undo
1637 1714
 		$currentKey = 0;
1638 1715
 
1639 1716
 		// Create a key => value array for multiple options fields
1640
-		if (!empty($row['field_options']))
1641
-			foreach (explode(',', $row['field_options']) as $k => $v)
1717
+		if (!empty($row['field_options'])) {
1718
+					foreach (explode(',', $row['field_options']) as $k => $v)
1642 1719
 			{
1643 1720
 				$fieldOptions[] = $v;
1644
-				if (empty($currentKey))
1645
-					$currentKey = $v == $row['value'] ? $k : 0;
1721
+		}
1722
+				if (empty($currentKey)) {
1723
+									$currentKey = $v == $row['value'] ? $k : 0;
1724
+				}
1646 1725
 			}
1647 1726
 
1648 1727
 		// BBC?
1649
-		if (!empty($row['bbc']))
1650
-			$row['value'] = parse_bbc($row['value']);
1728
+		if (!empty($row['bbc'])) {
1729
+					$row['value'] = parse_bbc($row['value']);
1730
+		}
1651 1731
 
1652 1732
 		// ... or checkbox?
1653
-		elseif (isset($row['type']) && $row['type'] == 'check')
1654
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1733
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1734
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1735
+		}
1655 1736
 
1656 1737
 		// Enclosing the user input within some other text?
1657
-		if (!empty($row['enclose']))
1658
-			$row['value'] = strtr($row['enclose'], array(
1738
+		if (!empty($row['enclose'])) {
1739
+					$row['value'] = strtr($row['enclose'], array(
1659 1740
 				'{SCRIPTURL}' => $scripturl,
1660 1741
 				'{IMAGES_URL}' => $settings['images_url'],
1661 1742
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1662 1743
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1663 1744
 				'{KEY}' => $currentKey,
1664 1745
 			));
1746
+		}
1665 1747
 
1666 1748
 		// Send a simple array if there is just 1 param
1667
-		if (count($params) == 1)
1668
-			$return[$row['id_member']] = $row;
1749
+		if (count($params) == 1) {
1750
+					$return[$row['id_member']] = $row;
1751
+		}
1669 1752
 
1670 1753
 		// More than 1? knock yourself out...
1671 1754
 		else
1672 1755
 		{
1673
-			if (!isset($return[$row['id_member']]))
1674
-				$return[$row['id_member']] = array();
1756
+			if (!isset($return[$row['id_member']])) {
1757
+							$return[$row['id_member']] = array();
1758
+			}
1675 1759
 
1676 1760
 			$return[$row['id_member']][$row['variable']] = $row;
1677 1761
 		}
@@ -1705,8 +1789,9 @@  discard block
 block discarded – undo
1705 1789
 	global $context;
1706 1790
 
1707 1791
 	// Don't know any browser!
1708
-	if (empty($context['browser']))
1709
-		detectBrowser();
1792
+	if (empty($context['browser'])) {
1793
+			detectBrowser();
1794
+	}
1710 1795
 
1711 1796
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1712 1797
 }
@@ -1724,8 +1809,9 @@  discard block
 block discarded – undo
1724 1809
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1725 1810
 
1726 1811
 	// The theme was specified by parameter.
1727
-	if (!empty($id_theme))
1728
-		$id_theme = (int) $id_theme;
1812
+	if (!empty($id_theme)) {
1813
+			$id_theme = (int) $id_theme;
1814
+	}
1729 1815
 	// The theme was specified by REQUEST.
1730 1816
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1731 1817
 	{
@@ -1733,32 +1819,38 @@  discard block
 block discarded – undo
1733 1819
 		$_SESSION['id_theme'] = $id_theme;
1734 1820
 	}
1735 1821
 	// The theme was specified by REQUEST... previously.
1736
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1737
-		$id_theme = (int) $_SESSION['id_theme'];
1822
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1823
+			$id_theme = (int) $_SESSION['id_theme'];
1824
+	}
1738 1825
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1739
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1740
-		$id_theme = $user_info['theme'];
1826
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1827
+			$id_theme = $user_info['theme'];
1828
+	}
1741 1829
 	// The theme was specified by the board.
1742
-	elseif (!empty($board_info['theme']))
1743
-		$id_theme = $board_info['theme'];
1830
+	elseif (!empty($board_info['theme'])) {
1831
+			$id_theme = $board_info['theme'];
1832
+	}
1744 1833
 	// The theme is the forum's default.
1745
-	else
1746
-		$id_theme = $modSettings['theme_guests'];
1834
+	else {
1835
+			$id_theme = $modSettings['theme_guests'];
1836
+	}
1747 1837
 
1748 1838
 	// Verify the id_theme... no foul play.
1749 1839
 	// Always allow the board specific theme, if they are overriding.
1750
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1751
-		$id_theme = $board_info['theme'];
1840
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1841
+			$id_theme = $board_info['theme'];
1842
+	}
1752 1843
 	// If they have specified a particular theme to use with SSI allow it to be used.
1753
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1754
-		$id_theme = (int) $id_theme;
1755
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1844
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1845
+			$id_theme = (int) $id_theme;
1846
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1756 1847
 	{
1757 1848
 		$themes = explode(',', $modSettings['enableThemes']);
1758
-		if (!in_array($id_theme, $themes))
1759
-			$id_theme = $modSettings['theme_guests'];
1760
-		else
1761
-			$id_theme = (int) $id_theme;
1849
+		if (!in_array($id_theme, $themes)) {
1850
+					$id_theme = $modSettings['theme_guests'];
1851
+		} else {
1852
+					$id_theme = (int) $id_theme;
1853
+		}
1762 1854
 	}
1763 1855
 		
1764 1856
 	// We already load the basic stuff?
@@ -1767,18 +1859,19 @@  discard block
 block discarded – undo
1767 1859
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1768 1860
 
1769 1861
 		// Disable image proxy if we don't have SSL enabled
1770
-		if (empty($modSettings['force_ssl']))
1771
-			$image_proxy_enabled = false;
1862
+		if (empty($modSettings['force_ssl'])) {
1863
+					$image_proxy_enabled = false;
1864
+		}
1772 1865
 
1773 1866
 		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated'])
1774 1867
 		{
1775 1868
 			$themeData = $temp;
1776 1869
 			$flag = true;
1870
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1871
+					$themeData = $temp + array($member => array());
1872
+		} else {
1873
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1777 1874
 		}
1778
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1779
-			$themeData = $temp + array($member => array());
1780
-		else
1781
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1782 1875
 
1783 1876
 		if (empty($flag))
1784 1877
 		{
@@ -1798,31 +1891,37 @@  discard block
 block discarded – undo
1798 1891
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1799 1892
 			{
1800 1893
 				// There are just things we shouldn't be able to change as members.
1801
-				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url')))
1802
-					continue;
1894
+				if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) {
1895
+									continue;
1896
+				}
1803 1897
 
1804 1898
 				// If this is the theme_dir of the default theme, store it.
1805
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1806
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1899
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1900
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1901
+				}
1807 1902
 
1808 1903
 				// If this isn't set yet, is a theme option, or is not the default theme..
1809
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1810
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1904
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1905
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1906
+				}
1811 1907
 			}
1812 1908
 			$smcFunc['db_free_result']($result);
1813 1909
 
1814
-			if (!empty($themeData[-1]))
1815
-				foreach ($themeData[-1] as $k => $v)
1910
+			if (!empty($themeData[-1])) {
1911
+							foreach ($themeData[-1] as $k => $v)
1816 1912
 				{
1817 1913
 					if (!isset($themeData[$member][$k]))
1818 1914
 						$themeData[$member][$k] = $v;
1915
+			}
1819 1916
 				}
1820 1917
 
1821
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1822
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1918
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1919
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1920
+			}
1823 1921
 			// Only if we didn't already load that part of the cache...
1824
-			elseif (!isset($temp))
1825
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1922
+			elseif (!isset($temp)) {
1923
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1924
+			}
1826 1925
 		}
1827 1926
 
1828 1927
 		$settings = $themeData[0];
@@ -1839,17 +1938,20 @@  discard block
 block discarded – undo
1839 1938
 		$settings['template_dirs'][] = $settings['theme_dir'];
1840 1939
 
1841 1940
 		// Based on theme (if there is one).
1842
-		if (!empty($settings['base_theme_dir']))
1843
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1941
+		if (!empty($settings['base_theme_dir'])) {
1942
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1943
+		}
1844 1944
 
1845 1945
 		// Lastly the default theme.
1846
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1847
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1946
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1947
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1948
+		}
1848 1949
 	}
1849 1950
 
1850 1951
 
1851
-	if (!$initialize)
1852
-		return;
1952
+	if (!$initialize) {
1953
+			return;
1954
+	}
1853 1955
 
1854 1956
 	// Check to see if we're forcing SSL
1855 1957
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1870,8 +1972,9 @@  discard block
 block discarded – undo
1870 1972
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1871 1973
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1872 1974
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1873
-		if ($temp != '/')
1874
-			$detected_url .= $temp;
1975
+		if ($temp != '/') {
1976
+					$detected_url .= $temp;
1977
+		}
1875 1978
 	}
1876 1979
 	if (isset($detected_url) && $detected_url != $boardurl)
1877 1980
 	{
@@ -1883,8 +1986,9 @@  discard block
 block discarded – undo
1883 1986
 			foreach ($aliases as $alias)
1884 1987
 			{
1885 1988
 				// Rip off all the boring parts, spaces, etc.
1886
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1887
-					$do_fix = true;
1989
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1990
+									$do_fix = true;
1991
+				}
1888 1992
 			}
1889 1993
 		}
1890 1994
 
@@ -1892,21 +1996,23 @@  discard block
 block discarded – undo
1892 1996
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1893 1997
 		{
1894 1998
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1895
-			if (empty($_GET))
1896
-				redirectexit('wwwRedirect');
1897
-			else
1999
+			if (empty($_GET)) {
2000
+							redirectexit('wwwRedirect');
2001
+			} else
1898 2002
 			{
1899 2003
 				$k = key($_GET);
1900 2004
 				$v = current($_GET);
1901 2005
 
1902
-				if ($k != 'wwwRedirect')
1903
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
2006
+				if ($k != 'wwwRedirect') {
2007
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
2008
+				}
1904 2009
 			}
1905 2010
 		}
1906 2011
 
1907 2012
 		// #3 is just a check for SSL...
1908
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1909
-			$do_fix = true;
2013
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
2014
+					$do_fix = true;
2015
+		}
1910 2016
 
1911 2017
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1912 2018
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1941,8 +2047,9 @@  discard block
 block discarded – undo
1941 2047
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1942 2048
 				}
1943 2049
 			}
1944
-			foreach ($context['linktree'] as $k => $dummy)
1945
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2050
+			foreach ($context['linktree'] as $k => $dummy) {
2051
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2052
+			}
1946 2053
 		}
1947 2054
 	}
1948 2055
 	// Set up the contextual user array.
@@ -1961,16 +2068,16 @@  discard block
 block discarded – undo
1961 2068
 			'email' => $user_info['email'],
1962 2069
 			'ignoreusers' => $user_info['ignoreusers'],
1963 2070
 		);
1964
-		if (!$context['user']['is_guest'])
1965
-			$context['user']['name'] = $user_info['name'];
1966
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1967
-			$context['user']['name'] = $txt['guest_title'];
2071
+		if (!$context['user']['is_guest']) {
2072
+					$context['user']['name'] = $user_info['name'];
2073
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2074
+					$context['user']['name'] = $txt['guest_title'];
2075
+		}
1968 2076
 
1969 2077
 		// Determine the current smiley set.
1970 2078
 		$user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set'];
1971 2079
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1972
-	}
1973
-	else
2080
+	} else
1974 2081
 	{
1975 2082
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1976 2083
 		$context['user'] = array(
@@ -2004,18 +2111,24 @@  discard block
 block discarded – undo
2004 2111
 	}
2005 2112
 
2006 2113
 	// Some basic information...
2007
-	if (!isset($context['html_headers']))
2008
-		$context['html_headers'] = '';
2009
-	if (!isset($context['javascript_files']))
2010
-		$context['javascript_files'] = array();
2011
-	if (!isset($context['css_files']))
2012
-		$context['css_files'] = array();
2013
-	if (!isset($context['css_header']))
2014
-		$context['css_header'] = array();
2015
-	if (!isset($context['javascript_inline']))
2016
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2017
-	if (!isset($context['javascript_vars']))
2018
-		$context['javascript_vars'] = array();
2114
+	if (!isset($context['html_headers'])) {
2115
+			$context['html_headers'] = '';
2116
+	}
2117
+	if (!isset($context['javascript_files'])) {
2118
+			$context['javascript_files'] = array();
2119
+	}
2120
+	if (!isset($context['css_files'])) {
2121
+			$context['css_files'] = array();
2122
+	}
2123
+	if (!isset($context['css_header'])) {
2124
+			$context['css_header'] = array();
2125
+	}
2126
+	if (!isset($context['javascript_inline'])) {
2127
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2128
+	}
2129
+	if (!isset($context['javascript_vars'])) {
2130
+			$context['javascript_vars'] = array();
2131
+	}
2019 2132
 
2020 2133
 	$context['login_url'] =  $scripturl . '?action=login2';
2021 2134
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2027,16 +2140,18 @@  discard block
 block discarded – undo
2027 2140
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2028 2141
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2029 2142
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2030
-	if (isset($modSettings['load_average']))
2031
-		$context['load_average'] = $modSettings['load_average'];
2143
+	if (isset($modSettings['load_average'])) {
2144
+			$context['load_average'] = $modSettings['load_average'];
2145
+	}
2032 2146
 
2033 2147
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2034 2148
 	detectBrowser();
2035 2149
 
2036 2150
 	// Set the top level linktree up.
2037 2151
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2038
-	if (empty($context['linktree']))
2039
-		$context['linktree'] = array();
2152
+	if (empty($context['linktree'])) {
2153
+			$context['linktree'] = array();
2154
+	}
2040 2155
 	array_unshift($context['linktree'], array(
2041 2156
 		'url' => $scripturl,
2042 2157
 		'name' => $context['forum_name_html_safe']
@@ -2045,8 +2160,9 @@  discard block
 block discarded – undo
2045 2160
 	// This allows sticking some HTML on the page output - useful for controls.
2046 2161
 	$context['insert_after_template'] = '';
2047 2162
 
2048
-	if (!isset($txt))
2049
-		$txt = array();
2163
+	if (!isset($txt)) {
2164
+			$txt = array();
2165
+	}
2050 2166
 
2051 2167
 	$simpleActions = array(
2052 2168
 		'findmember',
@@ -2092,9 +2208,10 @@  discard block
 block discarded – undo
2092 2208
 
2093 2209
 	// See if theres any extra param to check.
2094 2210
 	$requiresXML = false;
2095
-	foreach ($extraParams as $key => $extra)
2096
-		if (isset($_REQUEST[$extra]))
2211
+	foreach ($extraParams as $key => $extra) {
2212
+			if (isset($_REQUEST[$extra]))
2097 2213
 			$requiresXML = true;
2214
+	}
2098 2215
 
2099 2216
 	// Output is fully XML, so no need for the index template.
2100 2217
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2109,37 +2226,39 @@  discard block
 block discarded – undo
2109 2226
 	{
2110 2227
 		loadLanguage('index+Modifications');
2111 2228
 		$context['template_layers'] = array();
2112
-	}
2113
-
2114
-	else
2229
+	} else
2115 2230
 	{
2116 2231
 		// Custom templates to load, or just default?
2117
-		if (isset($settings['theme_templates']))
2118
-			$templates = explode(',', $settings['theme_templates']);
2119
-		else
2120
-			$templates = array('index');
2232
+		if (isset($settings['theme_templates'])) {
2233
+					$templates = explode(',', $settings['theme_templates']);
2234
+		} else {
2235
+					$templates = array('index');
2236
+		}
2121 2237
 
2122 2238
 		// Load each template...
2123
-		foreach ($templates as $template)
2124
-			loadTemplate($template);
2239
+		foreach ($templates as $template) {
2240
+					loadTemplate($template);
2241
+		}
2125 2242
 
2126 2243
 		// ...and attempt to load their associated language files.
2127 2244
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2128 2245
 		loadLanguage($required_files, '', false);
2129 2246
 
2130 2247
 		// Custom template layers?
2131
-		if (isset($settings['theme_layers']))
2132
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2133
-		else
2134
-			$context['template_layers'] = array('html', 'body');
2248
+		if (isset($settings['theme_layers'])) {
2249
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2250
+		} else {
2251
+					$context['template_layers'] = array('html', 'body');
2252
+		}
2135 2253
 	}
2136 2254
 
2137 2255
 	// Initialize the theme.
2138 2256
 	loadSubTemplate('init', 'ignore');
2139 2257
 
2140 2258
 	// Allow overriding the board wide time/number formats.
2141
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2142
-		$user_info['time_format'] = $txt['time_format'];
2259
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2260
+			$user_info['time_format'] = $txt['time_format'];
2261
+	}
2143 2262
 
2144 2263
 	// Set the character set from the template.
2145 2264
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2147,12 +2266,14 @@  discard block
 block discarded – undo
2147 2266
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2148 2267
 
2149 2268
 	// Guests may still need a name.
2150
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2151
-		$context['user']['name'] = $txt['guest_title'];
2269
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2270
+			$context['user']['name'] = $txt['guest_title'];
2271
+	}
2152 2272
 
2153 2273
 	// Any theme-related strings that need to be loaded?
2154
-	if (!empty($settings['require_theme_strings']))
2155
-		loadLanguage('ThemeStrings', '', false);
2274
+	if (!empty($settings['require_theme_strings'])) {
2275
+			loadLanguage('ThemeStrings', '', false);
2276
+	}
2156 2277
 
2157 2278
 	// Make a special URL for the language.
2158 2279
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2163,8 +2284,9 @@  discard block
 block discarded – undo
2163 2284
 	// Here is my luvly Responsive CSS
2164 2285
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2165 2286
 
2166
-	if ($context['right_to_left'])
2167
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2287
+	if ($context['right_to_left']) {
2288
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2289
+	}
2168 2290
 
2169 2291
 	// We allow theme variants, because we're cool.
2170 2292
 	$context['theme_variant'] = '';
@@ -2172,14 +2294,17 @@  discard block
 block discarded – undo
2172 2294
 	if (!empty($settings['theme_variants']))
2173 2295
 	{
2174 2296
 		// Overriding - for previews and that ilk.
2175
-		if (!empty($_REQUEST['variant']))
2176
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2297
+		if (!empty($_REQUEST['variant'])) {
2298
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2299
+		}
2177 2300
 		// User selection?
2178
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2179
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2301
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2302
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2303
+		}
2180 2304
 		// If not a user variant, select the default.
2181
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2182
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2305
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2306
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2307
+		}
2183 2308
 
2184 2309
 		// Do this to keep things easier in the templates.
2185 2310
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2188,20 +2313,23 @@  discard block
 block discarded – undo
2188 2313
 		if (!empty($context['theme_variant']))
2189 2314
 		{
2190 2315
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2191
-			if ($context['right_to_left'])
2192
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2316
+			if ($context['right_to_left']) {
2317
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2318
+			}
2193 2319
 		}
2194 2320
 	}
2195 2321
 
2196 2322
 	// Let's be compatible with old themes!
2197
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2198
-		$context['template_layers'] = array('main');
2323
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2324
+			$context['template_layers'] = array('main');
2325
+	}
2199 2326
 
2200 2327
 	$context['tabindex'] = 1;
2201 2328
 
2202 2329
 	// Compatibility.
2203
-	if (!isset($settings['theme_version']))
2204
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2330
+	if (!isset($settings['theme_version'])) {
2331
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2332
+	}
2205 2333
 
2206 2334
 	// Default JS variables for use in every theme
2207 2335
 	$context['javascript_vars'] = array(
@@ -2222,18 +2350,18 @@  discard block
 block discarded – undo
2222 2350
 	);
2223 2351
 
2224 2352
 	// Add the JQuery library to the list of files to load.
2225
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2226
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2227
-
2228
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2229
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2230
-
2231
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2232
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2353
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2354
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2355
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2356
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2357
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2358
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2359
+	}
2233 2360
 
2234 2361
 	// Auto loading? template_javascript() will take care of the local half of this.
2235
-	else
2236
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2362
+	else {
2363
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2364
+	}
2237 2365
 
2238 2366
 	// Queue our JQuery plugins!
2239 2367
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2256,12 +2384,12 @@  discard block
 block discarded – undo
2256 2384
 			require_once($sourcedir . '/ScheduledTasks.php');
2257 2385
 
2258 2386
 			// What to do, what to do?!
2259
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2260
-				AutoTask();
2261
-			else
2262
-				ReduceMailQueue();
2263
-		}
2264
-		else
2387
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2388
+							AutoTask();
2389
+			} else {
2390
+							ReduceMailQueue();
2391
+			}
2392
+		} else
2265 2393
 		{
2266 2394
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2267 2395
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2312,8 +2440,9 @@  discard block
 block discarded – undo
2312 2440
 		foreach ($theme_includes as $include)
2313 2441
 		{
2314 2442
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2315
-			if (file_exists($include))
2316
-				require_once($include);
2443
+			if (file_exists($include)) {
2444
+							require_once($include);
2445
+			}
2317 2446
 		}
2318 2447
 	}
2319 2448
 
@@ -2343,16 +2472,19 @@  discard block
 block discarded – undo
2343 2472
 	// Do any style sheets first, cause we're easy with those.
2344 2473
 	if (!empty($style_sheets))
2345 2474
 	{
2346
-		if (!is_array($style_sheets))
2347
-			$style_sheets = array($style_sheets);
2475
+		if (!is_array($style_sheets)) {
2476
+					$style_sheets = array($style_sheets);
2477
+		}
2348 2478
 
2349
-		foreach ($style_sheets as $sheet)
2350
-			loadCSSFile($sheet . '.css', array(), $sheet);
2479
+		foreach ($style_sheets as $sheet) {
2480
+					loadCSSFile($sheet . '.css', array(), $sheet);
2481
+		}
2351 2482
 	}
2352 2483
 
2353 2484
 	// No template to load?
2354
-	if ($template_name === false)
2355
-		return true;
2485
+	if ($template_name === false) {
2486
+			return true;
2487
+	}
2356 2488
 
2357 2489
 	$loaded = false;
2358 2490
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2367,12 +2499,14 @@  discard block
 block discarded – undo
2367 2499
 
2368 2500
 	if ($loaded)
2369 2501
 	{
2370
-		if ($db_show_debug === true)
2371
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2502
+		if ($db_show_debug === true) {
2503
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2504
+		}
2372 2505
 
2373 2506
 		// If they have specified an initialization function for this template, go ahead and call it now.
2374
-		if (function_exists('template_' . $template_name . '_init'))
2375
-			call_user_func('template_' . $template_name . '_init');
2507
+		if (function_exists('template_' . $template_name . '_init')) {
2508
+					call_user_func('template_' . $template_name . '_init');
2509
+		}
2376 2510
 	}
2377 2511
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2378 2512
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2392,13 +2526,14 @@  discard block
 block discarded – undo
2392 2526
 		loadTemplate($template_name);
2393 2527
 	}
2394 2528
 	// Cause an error otherwise.
2395
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2396
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2397
-	elseif ($fatal)
2398
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2399
-	else
2400
-		return false;
2401
-}
2529
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2530
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2531
+	} elseif ($fatal) {
2532
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template'));
2533
+	} else {
2534
+			return false;
2535
+	}
2536
+	}
2402 2537
 
2403 2538
 /**
2404 2539
  * Load a sub-template.
@@ -2416,17 +2551,19 @@  discard block
 block discarded – undo
2416 2551
 {
2417 2552
 	global $context, $txt, $db_show_debug;
2418 2553
 
2419
-	if ($db_show_debug === true)
2420
-		$context['debug']['sub_templates'][] = $sub_template_name;
2554
+	if ($db_show_debug === true) {
2555
+			$context['debug']['sub_templates'][] = $sub_template_name;
2556
+	}
2421 2557
 
2422 2558
 	// Figure out what the template function is named.
2423 2559
 	$theme_function = 'template_' . $sub_template_name;
2424
-	if (function_exists($theme_function))
2425
-		$theme_function();
2426
-	elseif ($fatal === false)
2427
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2428
-	elseif ($fatal !== 'ignore')
2429
-		die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2560
+	if (function_exists($theme_function)) {
2561
+			$theme_function();
2562
+	} elseif ($fatal === false) {
2563
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2564
+	} elseif ($fatal !== 'ignore') {
2565
+			die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template'));
2566
+	}
2430 2567
 
2431 2568
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2432 2569
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2456,8 +2593,9 @@  discard block
 block discarded – undo
2456 2593
 {
2457 2594
 	global $settings, $context, $modSettings;
2458 2595
 
2459
-	if (empty($context['css_files_order']))
2460
-		$context['css_files_order'] = array();
2596
+	if (empty($context['css_files_order'])) {
2597
+			$context['css_files_order'] = array();
2598
+	}
2461 2599
 
2462 2600
 	$params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
2463 2601
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2468,8 +2606,9 @@  discard block
 block discarded – undo
2468 2606
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2469 2607
 
2470 2608
 	// If this is an external file, automatically set this to false.
2471
-	if (!empty($params['external']))
2472
-		$params['minimize'] = false;
2609
+	if (!empty($params['external'])) {
2610
+			$params['minimize'] = false;
2611
+	}
2473 2612
 
2474 2613
 	// Account for shorthand like admin.css?alp21 filenames
2475 2614
 	$has_seed = strpos($fileName, '.css?');
@@ -2486,16 +2625,12 @@  discard block
 block discarded – undo
2486 2625
 			{
2487 2626
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2488 2627
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2489
-			}
2490
-
2491
-			else
2628
+			} else
2492 2629
 			{
2493 2630
 				$fileUrl = false;
2494 2631
 				$filePath = false;
2495 2632
 			}
2496
-		}
2497
-
2498
-		else
2633
+		} else
2499 2634
 		{
2500 2635
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2501 2636
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2513,16 +2648,18 @@  discard block
 block discarded – undo
2513 2648
 	if (!empty($fileName))
2514 2649
 	{
2515 2650
 		// find a free number/position
2516
-		while (isset($context['css_files_order'][$params['order_pos']]))
2517
-			$params['order_pos']++;
2651
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2652
+					$params['order_pos']++;
2653
+		}
2518 2654
 		$context['css_files_order'][$params['order_pos']] = $id;
2519 2655
 
2520 2656
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2521 2657
 	}
2522 2658
 
2523
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2524
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2525
-}
2659
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2660
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2661
+	}
2662
+	}
2526 2663
 
2527 2664
 /**
2528 2665
  * Add a block of inline css code to be executed later
@@ -2539,8 +2676,9 @@  discard block
 block discarded – undo
2539 2676
 	global $context;
2540 2677
 
2541 2678
 	// Gotta add something...
2542
-	if (empty($css))
2543
-		return false;
2679
+	if (empty($css)) {
2680
+			return false;
2681
+	}
2544 2682
 
2545 2683
 	$context['css_header'][] = $css;
2546 2684
 }
@@ -2576,8 +2714,9 @@  discard block
 block discarded – undo
2576 2714
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2577 2715
 
2578 2716
 	// If this is an external file, automatically set this to false.
2579
-	if (!empty($params['external']))
2580
-		$params['minimize'] = false;
2717
+	if (!empty($params['external'])) {
2718
+			$params['minimize'] = false;
2719
+	}
2581 2720
 
2582 2721
 	// Account for shorthand like admin.js?alp21 filenames
2583 2722
 	$has_seed = strpos($fileName, '.js?');
@@ -2594,16 +2733,12 @@  discard block
 block discarded – undo
2594 2733
 			{
2595 2734
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2596 2735
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2597
-			}
2598
-
2599
-			else
2736
+			} else
2600 2737
 			{
2601 2738
 				$fileUrl = false;
2602 2739
 				$filePath = false;
2603 2740
 			}
2604
-		}
2605
-
2606
-		else
2741
+		} else
2607 2742
 		{
2608 2743
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2609 2744
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2618,9 +2753,10 @@  discard block
 block discarded – undo
2618 2753
 	}
2619 2754
 
2620 2755
 	// Add it to the array for use in the template
2621
-	if (!empty($fileName))
2622
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2623
-}
2756
+	if (!empty($fileName)) {
2757
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2758
+	}
2759
+	}
2624 2760
 
2625 2761
 /**
2626 2762
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2634,9 +2770,10 @@  discard block
 block discarded – undo
2634 2770
 {
2635 2771
 	global $context;
2636 2772
 
2637
-	if (!empty($key) && (!empty($value) || $value === '0'))
2638
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2639
-}
2773
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2774
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2775
+	}
2776
+	}
2640 2777
 
2641 2778
 /**
2642 2779
  * Add a block of inline Javascript code to be executed later
@@ -2653,8 +2790,9 @@  discard block
 block discarded – undo
2653 2790
 {
2654 2791
 	global $context;
2655 2792
 
2656
-	if (empty($javascript))
2657
-		return false;
2793
+	if (empty($javascript)) {
2794
+			return false;
2795
+	}
2658 2796
 
2659 2797
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2660 2798
 }
@@ -2675,15 +2813,18 @@  discard block
 block discarded – undo
2675 2813
 	static $already_loaded = array();
2676 2814
 
2677 2815
 	// Default to the user's language.
2678
-	if ($lang == '')
2679
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2816
+	if ($lang == '') {
2817
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2818
+	}
2680 2819
 
2681 2820
 	// Do we want the English version of language file as fallback?
2682
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2683
-		loadLanguage($template_name, 'english', false);
2821
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2822
+			loadLanguage($template_name, 'english', false);
2823
+	}
2684 2824
 
2685
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2686
-		return $lang;
2825
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2826
+			return $lang;
2827
+	}
2687 2828
 
2688 2829
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2689 2830
 	if (empty($settings['default_theme_dir']))
@@ -2694,8 +2835,9 @@  discard block
 block discarded – undo
2694 2835
 
2695 2836
 	// What theme are we in?
2696 2837
 	$theme_name = basename($settings['theme_url']);
2697
-	if (empty($theme_name))
2698
-		$theme_name = 'unknown';
2838
+	if (empty($theme_name)) {
2839
+			$theme_name = 'unknown';
2840
+	}
2699 2841
 
2700 2842
 	// For each file open it up and write it out!
2701 2843
 	foreach (explode('+', $template_name) as $template)
@@ -2737,8 +2879,9 @@  discard block
 block discarded – undo
2737 2879
 				$found = true;
2738 2880
 
2739 2881
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2740
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2741
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2882
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2883
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2884
+				}
2742 2885
 
2743 2886
 				break;
2744 2887
 			}
@@ -2778,8 +2921,9 @@  discard block
 block discarded – undo
2778 2921
 	}
2779 2922
 
2780 2923
 	// Keep track of what we're up to soldier.
2781
-	if ($db_show_debug === true)
2782
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2924
+	if ($db_show_debug === true) {
2925
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2926
+	}
2783 2927
 
2784 2928
 	// Remember what we have loaded, and in which language.
2785 2929
 	$already_loaded[$template_name] = $lang;
@@ -2825,8 +2969,9 @@  discard block
 block discarded – undo
2825 2969
 				)
2826 2970
 			);
2827 2971
 			// In the EXTREMELY unlikely event this happens, give an error message.
2828
-			if ($smcFunc['db_num_rows']($result) == 0)
2829
-				fatal_lang_error('parent_not_found', 'critical');
2972
+			if ($smcFunc['db_num_rows']($result) == 0) {
2973
+							fatal_lang_error('parent_not_found', 'critical');
2974
+			}
2830 2975
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2831 2976
 			{
2832 2977
 				if (!isset($boards[$row['id_board']]))
@@ -2843,8 +2988,8 @@  discard block
 block discarded – undo
2843 2988
 					);
2844 2989
 				}
2845 2990
 				// If a moderator exists for this board, add that moderator for all children too.
2846
-				if (!empty($row['id_moderator']))
2847
-					foreach ($boards as $id => $dummy)
2991
+				if (!empty($row['id_moderator'])) {
2992
+									foreach ($boards as $id => $dummy)
2848 2993
 					{
2849 2994
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2850 2995
 							'id' => $row['id_moderator'],
@@ -2852,11 +2997,12 @@  discard block
 block discarded – undo
2852 2997
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2853 2998
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2854 2999
 						);
3000
+				}
2855 3001
 					}
2856 3002
 
2857 3003
 				// If a moderator group exists for this board, add that moderator group for all children too
2858
-				if (!empty($row['id_moderator_group']))
2859
-					foreach ($boards as $id => $dummy)
3004
+				if (!empty($row['id_moderator_group'])) {
3005
+									foreach ($boards as $id => $dummy)
2860 3006
 					{
2861 3007
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2862 3008
 							'id' => $row['id_moderator_group'],
@@ -2864,6 +3010,7 @@  discard block
 block discarded – undo
2864 3010
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2865 3011
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2866 3012
 						);
3013
+				}
2867 3014
 					}
2868 3015
 			}
2869 3016
 			$smcFunc['db_free_result']($result);
@@ -2890,23 +3037,27 @@  discard block
 block discarded – undo
2890 3037
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2891 3038
 	{
2892 3039
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2893
-		if (empty($smcFunc['ucwords']))
2894
-			reloadSettings();
3040
+		if (empty($smcFunc['ucwords'])) {
3041
+					reloadSettings();
3042
+		}
2895 3043
 
2896 3044
 		// If we don't have our theme information yet, let's get it.
2897
-		if (empty($settings['default_theme_dir']))
2898
-			loadTheme(0, false);
3045
+		if (empty($settings['default_theme_dir'])) {
3046
+					loadTheme(0, false);
3047
+		}
2899 3048
 
2900 3049
 		// Default language directories to try.
2901 3050
 		$language_directories = array(
2902 3051
 			$settings['default_theme_dir'] . '/languages',
2903 3052
 		);
2904
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2905
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3053
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3054
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3055
+		}
2906 3056
 
2907 3057
 		// We possibly have a base theme directory.
2908
-		if (!empty($settings['base_theme_dir']))
2909
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3058
+		if (!empty($settings['base_theme_dir'])) {
3059
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3060
+		}
2910 3061
 
2911 3062
 		// Remove any duplicates.
2912 3063
 		$language_directories = array_unique($language_directories);
@@ -2920,20 +3071,21 @@  discard block
 block discarded – undo
2920 3071
 		foreach ($language_directories as $language_dir)
2921 3072
 		{
2922 3073
 			// Can't look in here... doesn't exist!
2923
-			if (!file_exists($language_dir))
2924
-				continue;
3074
+			if (!file_exists($language_dir)) {
3075
+							continue;
3076
+			}
2925 3077
 
2926 3078
 			$dir = dir($language_dir);
2927 3079
 			while ($entry = $dir->read())
2928 3080
 			{
2929 3081
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2930
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2931
-					continue;
2932
-
2933
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2934
-					$langName = $langList[$matches[1]];
3082
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3083
+									continue;
3084
+				}
2935 3085
 
2936
-				else
3086
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3087
+									$langName = $langList[$matches[1]];
3088
+				} else
2937 3089
 				{
2938 3090
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2939 3091
 
@@ -2974,12 +3126,14 @@  discard block
 block discarded – undo
2974 3126
 		}
2975 3127
 
2976 3128
 		// Do we need to store the lang list?
2977
-		if (empty($langList))
2978
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3129
+		if (empty($langList)) {
3130
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3131
+		}
2979 3132
 
2980 3133
 		// Let's cash in on this deal.
2981
-		if (!empty($modSettings['cache_enable']))
2982
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3134
+		if (!empty($modSettings['cache_enable'])) {
3135
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3136
+		}
2983 3137
 	}
2984 3138
 
2985 3139
 	return $context['languages'];
@@ -3002,8 +3156,9 @@  discard block
 block discarded – undo
3002 3156
 	global $modSettings, $options, $txt;
3003 3157
 	static $censor_vulgar = null, $censor_proper;
3004 3158
 
3005
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
3006
-		return $text;
3159
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3160
+			return $text;
3161
+	}
3007 3162
 
3008 3163
 	// If they haven't yet been loaded, load them.
3009 3164
 	if ($censor_vulgar == null)
@@ -3034,9 +3189,9 @@  discard block
 block discarded – undo
3034 3189
 	{
3035 3190
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3036 3191
 		$text = $func($censor_vulgar, $censor_proper, $text);
3192
+	} else {
3193
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3037 3194
 	}
3038
-	else
3039
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3040 3195
 
3041 3196
 	return $text;
3042 3197
 }
@@ -3062,30 +3217,35 @@  discard block
 block discarded – undo
3062 3217
 	@ini_set('track_errors', '1');
3063 3218
 
3064 3219
 	// Don't include the file more than once, if $once is true.
3065
-	if ($once && in_array($filename, $templates))
3066
-		return;
3220
+	if ($once && in_array($filename, $templates)) {
3221
+			return;
3222
+	}
3067 3223
 	// Add this file to the include list, whether $once is true or not.
3068
-	else
3069
-		$templates[] = $filename;
3224
+	else {
3225
+			$templates[] = $filename;
3226
+	}
3070 3227
 
3071 3228
 
3072 3229
 	$file_found = file_exists($filename);
3073 3230
 
3074
-	if ($once && $file_found)
3075
-		require_once($filename);
3076
-	elseif ($file_found)
3077
-		require($filename);
3231
+	if ($once && $file_found) {
3232
+			require_once($filename);
3233
+	} elseif ($file_found) {
3234
+			require($filename);
3235
+	}
3078 3236
 
3079 3237
 	if ($file_found !== true)
3080 3238
 	{
3081 3239
 		ob_end_clean();
3082
-		if (!empty($modSettings['enableCompressedOutput']))
3083
-			@ob_start('ob_gzhandler');
3084
-		else
3085
-			ob_start();
3240
+		if (!empty($modSettings['enableCompressedOutput'])) {
3241
+					@ob_start('ob_gzhandler');
3242
+		} else {
3243
+					ob_start();
3244
+		}
3086 3245
 
3087
-		if (isset($_GET['debug']))
3088
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3246
+		if (isset($_GET['debug'])) {
3247
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3248
+		}
3089 3249
 
3090 3250
 		// Don't cache error pages!!
3091 3251
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3104,12 +3264,13 @@  discard block
 block discarded – undo
3104 3264
 		echo '<!DOCTYPE html>
3105 3265
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3106 3266
 	<head>';
3107
-		if (isset($context['character_set']))
3108
-			echo '
3267
+		if (isset($context['character_set'])) {
3268
+					echo '
3109 3269
 		<meta charset="', $context['character_set'], '">';
3270
+		}
3110 3271
 
3111
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3112
-			echo '
3272
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3273
+					echo '
3113 3274
 		<title>', $mtitle, '</title>
3114 3275
 	</head>
3115 3276
 	<body>
@@ -3117,8 +3278,8 @@  discard block
 block discarded – undo
3117 3278
 		', $mmessage, '
3118 3279
 	</body>
3119 3280
 </html>';
3120
-		elseif (!allowedTo('admin_forum'))
3121
-			echo '
3281
+		} elseif (!allowedTo('admin_forum')) {
3282
+					echo '
3122 3283
 		<title>', $txt['template_parse_error'], '</title>
3123 3284
 	</head>
3124 3285
 	<body>
@@ -3126,14 +3287,16 @@  discard block
 block discarded – undo
3126 3287
 		', $txt['template_parse_error_message'], '
3127 3288
 	</body>
3128 3289
 </html>';
3129
-		else
3290
+		} else
3130 3291
 		{
3131 3292
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3132 3293
 			$error_array = error_get_last();
3133
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3134
-				$error = $error_array['message'];
3135
-			if (empty($error))
3136
-				$error = $txt['template_parse_errmsg'];
3294
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3295
+							$error = $error_array['message'];
3296
+			}
3297
+			if (empty($error)) {
3298
+							$error = $txt['template_parse_errmsg'];
3299
+			}
3137 3300
 
3138 3301
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3139 3302
 
@@ -3144,11 +3307,12 @@  discard block
 block discarded – undo
3144 3307
 		<h3>', $txt['template_parse_error'], '</h3>
3145 3308
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3146 3309
 
3147
-			if (!empty($error))
3148
-				echo '
3310
+			if (!empty($error)) {
3311
+							echo '
3149 3312
 		<hr>
3150 3313
 
3151 3314
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3315
+			}
3152 3316
 
3153 3317
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3154 3318
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3158,10 +3322,11 @@  discard block
 block discarded – undo
3158 3322
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3159 3323
 
3160 3324
 				// Fix the PHP code stuff...
3161
-				if (!isBrowser('gecko'))
3162
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3163
-				else
3164
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3325
+				if (!isBrowser('gecko')) {
3326
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3327
+				} else {
3328
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3329
+				}
3165 3330
 
3166 3331
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3167 3332
 				$j = -1;
@@ -3169,8 +3334,9 @@  discard block
 block discarded – undo
3169 3334
 				{
3170 3335
 					$j++;
3171 3336
 
3172
-					if (substr_count($line, '<br>') == 0)
3173
-						continue;
3337
+					if (substr_count($line, '<br>') == 0) {
3338
+											continue;
3339
+					}
3174 3340
 
3175 3341
 					$n = substr_count($line, '<br>');
3176 3342
 					for ($i = 0; $i < $n; $i++)
@@ -3189,38 +3355,42 @@  discard block
 block discarded – undo
3189 3355
 				// Figure out what the color coding was before...
3190 3356
 				$line = max($match[1] - 9, 1);
3191 3357
 				$last_line = '';
3192
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3193
-					if (strpos($data2[$line2], '<') !== false)
3358
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3359
+									if (strpos($data2[$line2], '<') !== false)
3194 3360
 					{
3195 3361
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3196 3362
 							$last_line = $color_match[1];
3363
+				}
3197 3364
 						break;
3198 3365
 					}
3199 3366
 
3200 3367
 				// Show the relevant lines...
3201 3368
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3202 3369
 				{
3203
-					if ($line == $match[1])
3204
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3370
+					if ($line == $match[1]) {
3371
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3372
+					}
3205 3373
 
3206 3374
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3207
-					if (isset($data2[$line]) && $data2[$line] != '')
3208
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3375
+					if (isset($data2[$line]) && $data2[$line] != '') {
3376
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3377
+					}
3209 3378
 
3210 3379
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3211 3380
 					{
3212 3381
 						$last_line = $color_match[1];
3213 3382
 						echo '</', substr($last_line, 1, 4), '>';
3383
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3384
+											$last_line = '';
3385
+					} elseif ($last_line != '' && $data2[$line] != '') {
3386
+											echo '</', substr($last_line, 1, 4), '>';
3214 3387
 					}
3215
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3216
-						$last_line = '';
3217
-					elseif ($last_line != '' && $data2[$line] != '')
3218
-						echo '</', substr($last_line, 1, 4), '>';
3219 3388
 
3220
-					if ($line == $match[1])
3221
-						echo '</pre></div><pre style="margin: 0;">';
3222
-					else
3223
-						echo "\n";
3389
+					if ($line == $match[1]) {
3390
+											echo '</pre></div><pre style="margin: 0;">';
3391
+					} else {
3392
+											echo "\n";
3393
+					}
3224 3394
 				}
3225 3395
 
3226 3396
 				echo '</pre></div>';
@@ -3244,8 +3414,9 @@  discard block
 block discarded – undo
3244 3414
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4;
3245 3415
 
3246 3416
 	// Figure out what type of database we are using.
3247
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3248
-		$db_type = 'mysql';
3417
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3418
+			$db_type = 'mysql';
3419
+	}
3249 3420
 
3250 3421
 	// Load the file for the database.
3251 3422
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3253,11 +3424,13 @@  discard block
 block discarded – undo
3253 3424
 	$db_options = array();
3254 3425
 
3255 3426
 	// Add in the port if needed
3256
-	if (!empty($db_port))
3257
-		$db_options['port'] = $db_port;
3427
+	if (!empty($db_port)) {
3428
+			$db_options['port'] = $db_port;
3429
+	}
3258 3430
 
3259
-	if (!empty($db_mb4))
3260
-		$db_options['db_mb4'] = $db_mb4;
3431
+	if (!empty($db_mb4)) {
3432
+			$db_options['db_mb4'] = $db_mb4;
3433
+	}
3261 3434
 
3262 3435
 	// If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use.
3263 3436
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3276,13 +3449,15 @@  discard block
 block discarded – undo
3276 3449
 	}
3277 3450
 
3278 3451
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3279
-	if (!$db_connection)
3280
-		display_db_error();
3452
+	if (!$db_connection) {
3453
+			display_db_error();
3454
+	}
3281 3455
 
3282 3456
 	// If in SSI mode fix up the prefix.
3283
-	if (SMF == 'SSI')
3284
-		db_fix_prefix($db_prefix, $db_name);
3285
-}
3457
+	if (SMF == 'SSI') {
3458
+			db_fix_prefix($db_prefix, $db_name);
3459
+	}
3460
+	}
3286 3461
 
3287 3462
 /**
3288 3463
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3296,10 +3471,11 @@  discard block
 block discarded – undo
3296 3471
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3297 3472
 
3298 3473
 	// Not overriding this and we have a cacheAPI, send it back.
3299
-	if (empty($overrideCache) && is_object($cacheAPI))
3300
-		return $cacheAPI;
3301
-	elseif (is_null($cacheAPI))
3302
-		$cacheAPI = false;
3474
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3475
+			return $cacheAPI;
3476
+	} elseif (is_null($cacheAPI)) {
3477
+			$cacheAPI = false;
3478
+	}
3303 3479
 
3304 3480
 	// Make sure our class is in session.
3305 3481
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3320,8 +3496,9 @@  discard block
 block discarded – undo
3320 3496
 		if (!$testAPI->isSupported())
3321 3497
 		{
3322 3498
 			// Can we save ourselves?
3323
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3324
-				return loadCacheAccelerator(null, false);
3499
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3500
+							return loadCacheAccelerator(null, false);
3501
+			}
3325 3502
 			return false;
3326 3503
 		}
3327 3504
 
@@ -3333,9 +3510,9 @@  discard block
 block discarded – undo
3333 3510
 		{
3334 3511
 			$cacheAPI = $testAPI;
3335 3512
 			return $cacheAPI;
3513
+		} else {
3514
+					return $testAPI;
3336 3515
 		}
3337
-		else
3338
-			return $testAPI;
3339 3516
 	}
3340 3517
 }
3341 3518
 
@@ -3355,8 +3532,9 @@  discard block
 block discarded – undo
3355 3532
 
3356 3533
 	// @todo Why are we doing this if caching is disabled?
3357 3534
 
3358
-	if (function_exists('call_integration_hook'))
3359
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3535
+	if (function_exists('call_integration_hook')) {
3536
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3537
+	}
3360 3538
 
3361 3539
 	/* Refresh the cache if either:
3362 3540
 		1. Caching is disabled.
@@ -3370,16 +3548,19 @@  discard block
 block discarded – undo
3370 3548
 		require_once($sourcedir . '/' . $file);
3371 3549
 		$cache_block = call_user_func_array($function, $params);
3372 3550
 
3373
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3374
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3551
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3552
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3553
+		}
3375 3554
 	}
3376 3555
 
3377 3556
 	// Some cached data may need a freshening up after retrieval.
3378
-	if (!empty($cache_block['post_retri_eval']))
3379
-		eval($cache_block['post_retri_eval']);
3557
+	if (!empty($cache_block['post_retri_eval'])) {
3558
+			eval($cache_block['post_retri_eval']);
3559
+	}
3380 3560
 
3381
-	if (function_exists('call_integration_hook'))
3382
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3561
+	if (function_exists('call_integration_hook')) {
3562
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3563
+	}
3383 3564
 
3384 3565
 	return $cache_block['data'];
3385 3566
 }
@@ -3406,8 +3587,9 @@  discard block
 block discarded – undo
3406 3587
 	global $smcFunc, $cache_enable, $cacheAPI;
3407 3588
 	global $cache_hits, $cache_count, $db_show_debug;
3408 3589
 
3409
-	if (empty($cache_enable) || empty($cacheAPI))
3410
-		return;
3590
+	if (empty($cache_enable) || empty($cacheAPI)) {
3591
+			return;
3592
+	}
3411 3593
 
3412 3594
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3413 3595
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3420,12 +3602,14 @@  discard block
 block discarded – undo
3420 3602
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3421 3603
 	$cacheAPI->putData($key, $value, $ttl);
3422 3604
 
3423
-	if (function_exists('call_integration_hook'))
3424
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3605
+	if (function_exists('call_integration_hook')) {
3606
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3607
+	}
3425 3608
 
3426
-	if (isset($db_show_debug) && $db_show_debug === true)
3427
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3428
-}
3609
+	if (isset($db_show_debug) && $db_show_debug === true) {
3610
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3611
+	}
3612
+	}
3429 3613
 
3430 3614
 /**
3431 3615
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3441,8 +3625,9 @@  discard block
 block discarded – undo
3441 3625
 	global $smcFunc, $cache_enable, $cacheAPI;
3442 3626
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3443 3627
 
3444
-	if (empty($cache_enable) || empty($cacheAPI))
3445
-		return;
3628
+	if (empty($cache_enable) || empty($cacheAPI)) {
3629
+			return;
3630
+	}
3446 3631
 
3447 3632
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3448 3633
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3462,16 +3647,18 @@  discard block
 block discarded – undo
3462 3647
 
3463 3648
 		if (empty($value))
3464 3649
 		{
3465
-			if (!is_array($cache_misses))
3466
-				$cache_misses = array();
3650
+			if (!is_array($cache_misses)) {
3651
+							$cache_misses = array();
3652
+			}
3467 3653
 
3468 3654
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3469 3655
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3470 3656
 		}
3471 3657
 	}
3472 3658
 
3473
-	if (function_exists('call_integration_hook') && isset($value))
3474
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3659
+	if (function_exists('call_integration_hook') && isset($value)) {
3660
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3661
+	}
3475 3662
 
3476 3663
 	return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3477 3664
 }
@@ -3493,8 +3680,9 @@  discard block
 block discarded – undo
3493 3680
 	global $cacheAPI;
3494 3681
 
3495 3682
 	// If we can't get to the API, can't do this.
3496
-	if (empty($cacheAPI))
3497
-		return;
3683
+	if (empty($cacheAPI)) {
3684
+			return;
3685
+	}
3498 3686
 
3499 3687
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3500 3688
 	$cacheAPI->cleanCache($type);
@@ -3519,8 +3707,9 @@  discard block
 block discarded – undo
3519 3707
 	global $modSettings, $smcFunc, $image_proxy_enabled, $user_info;
3520 3708
 
3521 3709
 	// Come on!
3522
-	if (empty($data))
3523
-		return array();
3710
+	if (empty($data)) {
3711
+			return array();
3712
+	}
3524 3713
 
3525 3714
 	// Set a nice default var.
3526 3715
 	$image = '';
@@ -3528,11 +3717,11 @@  discard block
 block discarded – undo
3528 3717
 	// Gravatar has been set as mandatory!
3529 3718
 	if (!empty($modSettings['gravatarOverride']))
3530 3719
 	{
3531
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3532
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3533
-
3534
-		else if (!empty($data['email']))
3535
-			$image = get_gravatar_url($data['email']);
3720
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3721
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3722
+		} else if (!empty($data['email'])) {
3723
+					$image = get_gravatar_url($data['email']);
3724
+		}
3536 3725
 	}
3537 3726
 
3538 3727
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3544,54 +3733,60 @@  discard block
 block discarded – undo
3544 3733
 			// Gravatar.
3545 3734
 			if (stristr($data['avatar'], 'gravatar://'))
3546 3735
 			{
3547
-				if ($data['avatar'] == 'gravatar://')
3548
-					$image = get_gravatar_url($data['email']);
3549
-
3550
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3551
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3736
+				if ($data['avatar'] == 'gravatar://') {
3737
+									$image = get_gravatar_url($data['email']);
3738
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3739
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3740
+				}
3552 3741
 			}
3553 3742
 
3554 3743
 			// External url.
3555 3744
 			else
3556 3745
 			{
3557 3746
 				// Using ssl?
3558
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3559
-					$image = get_proxied_url($data['avatar']);
3747
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3748
+									$image = get_proxied_url($data['avatar']);
3749
+				}
3560 3750
 
3561 3751
 				// Just a plain external url.
3562
-				else
3563
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3752
+				else {
3753
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3754
+				}
3564 3755
 			}
3565 3756
 		}
3566 3757
 
3567 3758
 		// Perhaps this user has an attachment as avatar...
3568
-		else if (!empty($data['filename']))
3569
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3759
+		else if (!empty($data['filename'])) {
3760
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3761
+		}
3570 3762
 
3571 3763
 		// Right... no avatar... use our default image.
3572
-		else
3573
-			$image = $modSettings['avatar_url'] . '/default.png';
3764
+		else {
3765
+					$image = $modSettings['avatar_url'] . '/default.png';
3766
+		}
3574 3767
 	}
3575 3768
 
3576 3769
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3577 3770
 
3578 3771
 	// At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed.
3579
-	if (!empty($image))
3580
-		return array(
3772
+	if (!empty($image)) {
3773
+			return array(
3581 3774
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3582 3775
 			'image' => '<img class="avatar" src="' . $image . '" />',
3583 3776
 			'href' => $image,
3584 3777
 			'url' => $image,
3585 3778
 		);
3779
+	}
3586 3780
 
3587 3781
 	// Fallback to make life easier for everyone...
3588
-	else
3589
-		return array(
3782
+	else {
3783
+			return array(
3590 3784
 			'name' => '',
3591 3785
 			'image' => '',
3592 3786
 			'href' => '',
3593 3787
 			'url' => '',
3594 3788
 		);
3595
-}
3789
+	}
3790
+	}
3596 3791
 
3597 3792
 ?>
3598 3793
\ No newline at end of file
Please login to merge, or discard this patch.