Completed
Pull Request — release-2.1 (#5005)
by Martyn
09:25 queued 03:14
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
 		{
@@ -747,8 +779,9 @@  discard block
 block discarded – undo
747 779
 	$user_info['groups'] = array_unique($user_info['groups']);
748 780
 
749 781
 	// 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.
750
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
751
-		unset($user_info['ignoreboards'][$tmp]);
782
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
783
+			unset($user_info['ignoreboards'][$tmp]);
784
+	}
752 785
 
753 786
 	// Allow the user to change their language.
754 787
 	if (!empty($modSettings['userLanguage']))
@@ -761,13 +794,14 @@  discard block
 block discarded – undo
761 794
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
762 795
 
763 796
 			// Make it permanent for members.
764
-			if (!empty($user_info['id']))
765
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
766
-			else
767
-				$_SESSION['language'] = $user_info['language'];
797
+			if (!empty($user_info['id'])) {
798
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
799
+			} else {
800
+							$_SESSION['language'] = $user_info['language'];
801
+			}
802
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
803
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
768 804
 		}
769
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
770
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
771 805
 	}
772 806
 
773 807
 	$temp = build_query_board($user_info['id']);
@@ -830,9 +864,9 @@  discard block
 block discarded – undo
830 864
 		}
831 865
 
832 866
 		// Remember redirection is the key to avoiding fallout from your bosses.
833
-		if (!empty($topic))
834
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
835
-		else
867
+		if (!empty($topic)) {
868
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
869
+		} else
836 870
 		{
837 871
 			loadPermissions();
838 872
 			loadTheme();
@@ -850,10 +884,11 @@  discard block
 block discarded – undo
850 884
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
851 885
 	{
852 886
 		// @todo SLOW?
853
-		if (!empty($topic))
854
-			$temp = cache_get_data('topic_board-' . $topic, 120);
855
-		else
856
-			$temp = cache_get_data('board-' . $board, 120);
887
+		if (!empty($topic)) {
888
+					$temp = cache_get_data('topic_board-' . $topic, 120);
889
+		} else {
890
+					$temp = cache_get_data('board-' . $board, 120);
891
+		}
857 892
 
858 893
 		if (!empty($temp))
859 894
 		{
@@ -891,8 +926,9 @@  discard block
 block discarded – undo
891 926
 			$row = $smcFunc['db_fetch_assoc']($request);
892 927
 
893 928
 			// Set the current board.
894
-			if (!empty($row['id_board']))
895
-				$board = $row['id_board'];
929
+			if (!empty($row['id_board'])) {
930
+							$board = $row['id_board'];
931
+			}
896 932
 
897 933
 			// Basic operating information. (globals... :/)
898 934
 			$board_info = array(
@@ -928,21 +964,23 @@  discard block
 block discarded – undo
928 964
 
929 965
 			do
930 966
 			{
931
-				if (!empty($row['id_moderator']))
932
-					$board_info['moderators'][$row['id_moderator']] = array(
967
+				if (!empty($row['id_moderator'])) {
968
+									$board_info['moderators'][$row['id_moderator']] = array(
933 969
 						'id' => $row['id_moderator'],
934 970
 						'name' => $row['real_name'],
935 971
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
936 972
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
937 973
 					);
974
+				}
938 975
 
939
-				if (!empty($row['id_moderator_group']))
940
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
976
+				if (!empty($row['id_moderator_group'])) {
977
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
941 978
 						'id' => $row['id_moderator_group'],
942 979
 						'name' => $row['group_name'],
943 980
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
944 981
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
945 982
 					);
983
+				}
946 984
 			}
947 985
 			while ($row = $smcFunc['db_fetch_assoc']($request));
948 986
 
@@ -974,12 +1012,12 @@  discard block
 block discarded – undo
974 1012
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
975 1013
 			{
976 1014
 				// @todo SLOW?
977
-				if (!empty($topic))
978
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
1015
+				if (!empty($topic)) {
1016
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
1017
+				}
979 1018
 				cache_put_data('board-' . $board, $board_info, 120);
980 1019
 			}
981
-		}
982
-		else
1020
+		} else
983 1021
 		{
984 1022
 			// Otherwise the topic is invalid, there are no moderators, etc.
985 1023
 			$board_info = array(
@@ -993,8 +1031,9 @@  discard block
 block discarded – undo
993 1031
 		$smcFunc['db_free_result']($request);
994 1032
 	}
995 1033
 
996
-	if (!empty($topic))
997
-		$_GET['board'] = (int) $board;
1034
+	if (!empty($topic)) {
1035
+			$_GET['board'] = (int) $board;
1036
+	}
998 1037
 
999 1038
 	if (!empty($board))
1000 1039
 	{
@@ -1004,10 +1043,12 @@  discard block
 block discarded – undo
1004 1043
 		// Now check if the user is a moderator.
1005 1044
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
1006 1045
 
1007
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
1008
-			$board_info['error'] = 'access';
1009
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
1010
-			$board_info['error'] = 'access';
1046
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1047
+					$board_info['error'] = 'access';
1048
+		}
1049
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1050
+					$board_info['error'] = 'access';
1051
+		}
1011 1052
 
1012 1053
 		// Build up the linktree.
1013 1054
 		$context['linktree'] = array_merge(
@@ -1030,8 +1071,9 @@  discard block
 block discarded – undo
1030 1071
 	$context['current_board'] = $board;
1031 1072
 
1032 1073
 	// No posting in redirection boards!
1033
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1034
-		$board_info['error'] == 'post_in_redirect';
1074
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1075
+			$board_info['error'] == 'post_in_redirect';
1076
+	}
1035 1077
 
1036 1078
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1037 1079
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1057,24 +1099,23 @@  discard block
 block discarded – undo
1057 1099
 			ob_end_clean();
1058 1100
 			send_http_status(403);
1059 1101
 			die;
1060
-		}
1061
-		elseif ($board_info['error'] == 'post_in_redirect')
1102
+		} elseif ($board_info['error'] == 'post_in_redirect')
1062 1103
 		{
1063 1104
 			// Slightly different error message here...
1064 1105
 			fatal_lang_error('cannot_post_redirect', false);
1065
-		}
1066
-		elseif ($user_info['is_guest'])
1106
+		} elseif ($user_info['is_guest'])
1067 1107
 		{
1068 1108
 			loadLanguage('Errors');
1069 1109
 			is_not_guest($txt['topic_gone']);
1110
+		} else {
1111
+					fatal_lang_error('topic_gone', false);
1070 1112
 		}
1071
-		else
1072
-			fatal_lang_error('topic_gone', false);
1073 1113
 	}
1074 1114
 
1075
-	if ($user_info['is_mod'])
1076
-		$user_info['groups'][] = 3;
1077
-}
1115
+	if ($user_info['is_mod']) {
1116
+			$user_info['groups'][] = 3;
1117
+	}
1118
+	}
1078 1119
 
1079 1120
 /**
1080 1121
  * Load this user's permissions.
@@ -1095,8 +1136,9 @@  discard block
 block discarded – undo
1095 1136
 		asort($cache_groups);
1096 1137
 		$cache_groups = implode(',', $cache_groups);
1097 1138
 		// If it's a spider then cache it different.
1098
-		if ($user_info['possibly_robot'])
1099
-			$cache_groups .= '-spider';
1139
+		if ($user_info['possibly_robot']) {
1140
+					$cache_groups .= '-spider';
1141
+		}
1100 1142
 
1101 1143
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1102 1144
 		{
@@ -1104,9 +1146,9 @@  discard block
 block discarded – undo
1104 1146
 			banPermissions();
1105 1147
 
1106 1148
 			return;
1149
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1150
+					list ($user_info['permissions'], $removals) = $temp;
1107 1151
 		}
1108
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1109
-			list ($user_info['permissions'], $removals) = $temp;
1110 1152
 	}
1111 1153
 
1112 1154
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1128,23 +1170,26 @@  discard block
 block discarded – undo
1128 1170
 		$removals = array();
1129 1171
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1130 1172
 		{
1131
-			if (empty($row['add_deny']))
1132
-				$removals[] = $row['permission'];
1133
-			else
1134
-				$user_info['permissions'][] = $row['permission'];
1173
+			if (empty($row['add_deny'])) {
1174
+							$removals[] = $row['permission'];
1175
+			} else {
1176
+							$user_info['permissions'][] = $row['permission'];
1177
+			}
1135 1178
 		}
1136 1179
 		$smcFunc['db_free_result']($request);
1137 1180
 
1138
-		if (isset($cache_groups))
1139
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1181
+		if (isset($cache_groups)) {
1182
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1183
+		}
1140 1184
 	}
1141 1185
 
1142 1186
 	// Get the board permissions.
1143 1187
 	if (!empty($board))
1144 1188
 	{
1145 1189
 		// Make sure the board (if any) has been loaded by loadBoard().
1146
-		if (!isset($board_info['profile']))
1147
-			fatal_lang_error('no_board');
1190
+		if (!isset($board_info['profile'])) {
1191
+					fatal_lang_error('no_board');
1192
+		}
1148 1193
 
1149 1194
 		$request = $smcFunc['db_query']('', '
1150 1195
 			SELECT permission, add_deny
@@ -1160,20 +1205,23 @@  discard block
 block discarded – undo
1160 1205
 		);
1161 1206
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1162 1207
 		{
1163
-			if (empty($row['add_deny']))
1164
-				$removals[] = $row['permission'];
1165
-			else
1166
-				$user_info['permissions'][] = $row['permission'];
1208
+			if (empty($row['add_deny'])) {
1209
+							$removals[] = $row['permission'];
1210
+			} else {
1211
+							$user_info['permissions'][] = $row['permission'];
1212
+			}
1167 1213
 		}
1168 1214
 		$smcFunc['db_free_result']($request);
1169 1215
 	}
1170 1216
 
1171 1217
 	// Remove all the permissions they shouldn't have ;).
1172
-	if (!empty($modSettings['permission_enable_deny']))
1173
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1218
+	if (!empty($modSettings['permission_enable_deny'])) {
1219
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1220
+	}
1174 1221
 
1175
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1176
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1222
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1223
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1224
+	}
1177 1225
 
1178 1226
 	// Banned?  Watch, don't touch..
1179 1227
 	banPermissions();
@@ -1185,17 +1233,18 @@  discard block
 block discarded – undo
1185 1233
 		{
1186 1234
 			require_once($sourcedir . '/Subs-Auth.php');
1187 1235
 			rebuildModCache();
1236
+		} else {
1237
+					$user_info['mod_cache'] = $_SESSION['mc'];
1188 1238
 		}
1189
-		else
1190
-			$user_info['mod_cache'] = $_SESSION['mc'];
1191 1239
 
1192 1240
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1193 1241
 		// For example this drastically simplifies certain changes to the profile area.
1194 1242
 		$user_info['permissions'][] = 'is_not_guest';
1195 1243
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1196 1244
 		$user_info['permissions'][] = 'profile_view_own';
1197
-		if (in_array('profile_view', $user_info['permissions']))
1198
-			$user_info['permissions'][] = 'profile_view_any';
1245
+		if (in_array('profile_view', $user_info['permissions'])) {
1246
+					$user_info['permissions'][] = 'profile_view_any';
1247
+		}
1199 1248
 	}
1200 1249
 }
1201 1250
 
@@ -1213,8 +1262,9 @@  discard block
 block discarded – undo
1213 1262
 	global $image_proxy_enabled, $user_info;
1214 1263
 
1215 1264
 	// Can't just look for no users :P.
1216
-	if (empty($users))
1217
-		return array();
1265
+	if (empty($users)) {
1266
+			return array();
1267
+	}
1218 1268
 
1219 1269
 	// Pass the set value
1220 1270
 	$context['loadMemberContext_set'] = $set;
@@ -1229,8 +1279,9 @@  discard block
 block discarded – undo
1229 1279
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1230 1280
 		{
1231 1281
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1232
-			if ($data == null)
1233
-				continue;
1282
+			if ($data == null) {
1283
+							continue;
1284
+			}
1234 1285
 
1235 1286
 			$loaded_ids[] = $data['id_member'];
1236 1287
 			$user_profile[$data['id_member']] = $data;
@@ -1297,16 +1348,19 @@  discard block
 block discarded – undo
1297 1348
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1298 1349
 
1299 1350
 			// Take care of proxying avatar if required, do this here for maximum reach
1300
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1301
-				$row['avatar'] = get_proxied_url($row['avatar']);
1351
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1352
+							$row['avatar'] = get_proxied_url($row['avatar']);
1353
+			}
1302 1354
 
1303 1355
 			// Keep track of the member's normal member group
1304 1356
 			$row['primary_group'] = !empty($row['member_group']) ? $row['member_group'] : '';
1305 1357
 
1306
-			if (isset($row['member_ip']))
1307
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1308
-			if (isset($row['member_ip2']))
1309
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1358
+			if (isset($row['member_ip'])) {
1359
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1360
+			}
1361
+			if (isset($row['member_ip2'])) {
1362
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1363
+			}
1310 1364
 			$row['id_member'] = (int) $row['id_member'];
1311 1365
 			$new_loaded_ids[] = $row['id_member'];
1312 1366
 			$loaded_ids[] = $row['id_member'];
@@ -1326,8 +1380,9 @@  discard block
 block discarded – undo
1326 1380
 				'loaded_ids' => $new_loaded_ids,
1327 1381
 			)
1328 1382
 		);
1329
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1330
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1383
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1384
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1385
+		}
1331 1386
 		$smcFunc['db_free_result']($request);
1332 1387
 	}
1333 1388
 
@@ -1338,10 +1393,11 @@  discard block
 block discarded – undo
1338 1393
 	{
1339 1394
 		foreach ($loaded_ids as $a_member)
1340 1395
 		{
1341
-			if (!empty($user_profile[$a_member]['additional_groups']))
1342
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1343
-			else
1344
-				$groups = array($user_profile[$a_member]['id_group']);
1396
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1397
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1398
+			} else {
1399
+							$groups = array($user_profile[$a_member]['id_group']);
1400
+			}
1345 1401
 
1346 1402
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1347 1403
 
@@ -1354,8 +1410,9 @@  discard block
 block discarded – undo
1354 1410
 
1355 1411
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1356 1412
 	{
1357
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1358
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1413
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1414
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1415
+		}
1359 1416
 	}
1360 1417
 
1361 1418
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1381,14 +1438,17 @@  discard block
 block discarded – undo
1381 1438
 		foreach ($temp_mods as $id)
1382 1439
 		{
1383 1440
 			// By popular demand, don't show admins or global moderators as moderators.
1384
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1385
-				$user_profile[$id]['member_group'] = $row['member_group'];
1441
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1442
+							$user_profile[$id]['member_group'] = $row['member_group'];
1443
+			}
1386 1444
 
1387 1445
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1388
-			if (!empty($row['icons']))
1389
-				$user_profile[$id]['icons'] = $row['icons'];
1390
-			if (!empty($row['member_group_color']))
1391
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1446
+			if (!empty($row['icons'])) {
1447
+							$user_profile[$id]['icons'] = $row['icons'];
1448
+			}
1449
+			if (!empty($row['member_group_color'])) {
1450
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1451
+			}
1392 1452
 		}
1393 1453
 	}
1394 1454
 
@@ -1410,12 +1470,14 @@  discard block
 block discarded – undo
1410 1470
 	static $loadedLanguages = array();
1411 1471
 
1412 1472
 	// If this person's data is already loaded, skip it.
1413
-	if (isset($dataLoaded[$user]))
1414
-		return true;
1473
+	if (isset($dataLoaded[$user])) {
1474
+			return true;
1475
+	}
1415 1476
 
1416 1477
 	// We can't load guests or members not loaded by loadMemberData()!
1417
-	if ($user == 0)
1418
-		return false;
1478
+	if ($user == 0) {
1479
+			return false;
1480
+	}
1419 1481
 	if (!isset($user_profile[$user]))
1420 1482
 	{
1421 1483
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1441,12 +1503,16 @@  discard block
 block discarded – undo
1441 1503
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1442 1504
 
1443 1505
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1444
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1506
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1507
+		//icon is set and exists
1445 1508
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1446
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1509
+	} elseif (isset($profile['icons'][1])) {
1510
+		//icon is set and doesn't exist, fallback to default
1447 1511
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1448
-	else //not set, bye bye
1512
+	} else {
1513
+		//not set, bye bye
1449 1514
 		$group_icon_url = '';
1515
+	}
1450 1516
 
1451 1517
 	// These minimal values are always loaded
1452 1518
 	$memberContext[$user] = array(
@@ -1465,8 +1531,9 @@  discard block
 block discarded – undo
1465 1531
 	if ($context['loadMemberContext_set'] != 'minimal')
1466 1532
 	{
1467 1533
 		// Go the extra mile and load the user's native language name.
1468
-		if (empty($loadedLanguages))
1469
-			$loadedLanguages = getLanguages();
1534
+		if (empty($loadedLanguages)) {
1535
+					$loadedLanguages = getLanguages();
1536
+		}
1470 1537
 
1471 1538
 		$memberContext[$user] += array(
1472 1539
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1521,31 +1588,33 @@  discard block
 block discarded – undo
1521 1588
 	{
1522 1589
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1523 1590
 		{
1524
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1525
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1526
-			else
1527
-				$image = get_gravatar_url($profile['email_address']);
1528
-		}
1529
-		else
1591
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1592
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1593
+			} else {
1594
+							$image = get_gravatar_url($profile['email_address']);
1595
+			}
1596
+		} else
1530 1597
 		{
1531 1598
 			// So it's stored in the member table?
1532 1599
 			if (!empty($profile['avatar']))
1533 1600
 			{
1534 1601
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1602
+			} elseif (!empty($profile['filename'])) {
1603
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1535 1604
 			}
1536
-			elseif (!empty($profile['filename']))
1537
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1538 1605
 			// Right... no avatar...use the default one
1539
-			else
1540
-				$image = $modSettings['avatar_url'] . '/default.png';
1606
+			else {
1607
+							$image = $modSettings['avatar_url'] . '/default.png';
1608
+			}
1541 1609
 		}
1542
-		if (!empty($image))
1543
-			$memberContext[$user]['avatar'] = array(
1610
+		if (!empty($image)) {
1611
+					$memberContext[$user]['avatar'] = array(
1544 1612
 				'name' => $profile['avatar'],
1545 1613
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1546 1614
 				'href' => $image,
1547 1615
 				'url' => $image,
1548 1616
 			);
1617
+		}
1549 1618
 	}
1550 1619
 
1551 1620
 	// Are we also loading the members custom fields into context?
@@ -1553,13 +1622,15 @@  discard block
 block discarded – undo
1553 1622
 	{
1554 1623
 		$memberContext[$user]['custom_fields'] = array();
1555 1624
 
1556
-		if (!isset($context['display_fields']))
1557
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1625
+		if (!isset($context['display_fields'])) {
1626
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1627
+		}
1558 1628
 
1559 1629
 		foreach ($context['display_fields'] as $custom)
1560 1630
 		{
1561
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1562
-				continue;
1631
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1632
+							continue;
1633
+			}
1563 1634
 
1564 1635
 			$value = $profile['options'][$custom['col_name']];
1565 1636
 
@@ -1567,31 +1638,36 @@  discard block
 block discarded – undo
1567 1638
 			$currentKey = 0;
1568 1639
 
1569 1640
 			// Create a key => value array for multiple options fields
1570
-			if (!empty($custom['options']))
1571
-				foreach ($custom['options'] as $k => $v)
1641
+			if (!empty($custom['options'])) {
1642
+							foreach ($custom['options'] as $k => $v)
1572 1643
 				{
1573 1644
 					$fieldOptions[] = $v;
1574
-					if (empty($currentKey))
1575
-						$currentKey = $v == $value ? $k : 0;
1645
+			}
1646
+					if (empty($currentKey)) {
1647
+											$currentKey = $v == $value ? $k : 0;
1648
+					}
1576 1649
 				}
1577 1650
 
1578 1651
 			// BBC?
1579
-			if ($custom['bbc'])
1580
-				$value = parse_bbc($value);
1652
+			if ($custom['bbc']) {
1653
+							$value = parse_bbc($value);
1654
+			}
1581 1655
 
1582 1656
 			// ... or checkbox?
1583
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1584
-				$value = $value ? $txt['yes'] : $txt['no'];
1657
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1658
+							$value = $value ? $txt['yes'] : $txt['no'];
1659
+			}
1585 1660
 
1586 1661
 			// Enclosing the user input within some other text?
1587
-			if (!empty($custom['enclose']))
1588
-				$value = strtr($custom['enclose'], array(
1662
+			if (!empty($custom['enclose'])) {
1663
+							$value = strtr($custom['enclose'], array(
1589 1664
 					'{SCRIPTURL}' => $scripturl,
1590 1665
 					'{IMAGES_URL}' => $settings['images_url'],
1591 1666
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1592 1667
 					'{INPUT}' => $value,
1593 1668
 					'{KEY}' => $currentKey,
1594 1669
 				));
1670
+			}
1595 1671
 
1596 1672
 			$memberContext[$user]['custom_fields'][] = array(
1597 1673
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1618,8 +1694,9 @@  discard block
 block discarded – undo
1618 1694
 	global $smcFunc, $txt, $scripturl, $settings;
1619 1695
 
1620 1696
 	// Do not waste my time...
1621
-	if (empty($users) || empty($params))
1622
-		return false;
1697
+	if (empty($users) || empty($params)) {
1698
+			return false;
1699
+	}
1623 1700
 
1624 1701
 	// Make sure it's an array.
1625 1702
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1646,41 +1723,48 @@  discard block
 block discarded – undo
1646 1723
 		$currentKey = 0;
1647 1724
 
1648 1725
 		// Create a key => value array for multiple options fields
1649
-		if (!empty($row['field_options']))
1650
-			foreach (explode(',', $row['field_options']) as $k => $v)
1726
+		if (!empty($row['field_options'])) {
1727
+					foreach (explode(',', $row['field_options']) as $k => $v)
1651 1728
 			{
1652 1729
 				$fieldOptions[] = $v;
1653
-				if (empty($currentKey))
1654
-					$currentKey = $v == $row['value'] ? $k : 0;
1730
+		}
1731
+				if (empty($currentKey)) {
1732
+									$currentKey = $v == $row['value'] ? $k : 0;
1733
+				}
1655 1734
 			}
1656 1735
 
1657 1736
 		// BBC?
1658
-		if (!empty($row['bbc']))
1659
-			$row['value'] = parse_bbc($row['value']);
1737
+		if (!empty($row['bbc'])) {
1738
+					$row['value'] = parse_bbc($row['value']);
1739
+		}
1660 1740
 
1661 1741
 		// ... or checkbox?
1662
-		elseif (isset($row['type']) && $row['type'] == 'check')
1663
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1742
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1743
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1744
+		}
1664 1745
 
1665 1746
 		// Enclosing the user input within some other text?
1666
-		if (!empty($row['enclose']))
1667
-			$row['value'] = strtr($row['enclose'], array(
1747
+		if (!empty($row['enclose'])) {
1748
+					$row['value'] = strtr($row['enclose'], array(
1668 1749
 				'{SCRIPTURL}' => $scripturl,
1669 1750
 				'{IMAGES_URL}' => $settings['images_url'],
1670 1751
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1671 1752
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1672 1753
 				'{KEY}' => $currentKey,
1673 1754
 			));
1755
+		}
1674 1756
 
1675 1757
 		// Send a simple array if there is just 1 param
1676
-		if (count($params) == 1)
1677
-			$return[$row['id_member']] = $row;
1758
+		if (count($params) == 1) {
1759
+					$return[$row['id_member']] = $row;
1760
+		}
1678 1761
 
1679 1762
 		// More than 1? knock yourself out...
1680 1763
 		else
1681 1764
 		{
1682
-			if (!isset($return[$row['id_member']]))
1683
-				$return[$row['id_member']] = array();
1765
+			if (!isset($return[$row['id_member']])) {
1766
+							$return[$row['id_member']] = array();
1767
+			}
1684 1768
 
1685 1769
 			$return[$row['id_member']][$row['variable']] = $row;
1686 1770
 		}
@@ -1714,8 +1798,9 @@  discard block
 block discarded – undo
1714 1798
 	global $context;
1715 1799
 
1716 1800
 	// Don't know any browser!
1717
-	if (empty($context['browser']))
1718
-		detectBrowser();
1801
+	if (empty($context['browser'])) {
1802
+			detectBrowser();
1803
+	}
1719 1804
 
1720 1805
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1721 1806
 }
@@ -1733,8 +1818,9 @@  discard block
 block discarded – undo
1733 1818
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1734 1819
 
1735 1820
 	// The theme was specified by parameter.
1736
-	if (!empty($id_theme))
1737
-		$id_theme = (int) $id_theme;
1821
+	if (!empty($id_theme)) {
1822
+			$id_theme = (int) $id_theme;
1823
+	}
1738 1824
 	// The theme was specified by REQUEST.
1739 1825
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1740 1826
 	{
@@ -1742,35 +1828,41 @@  discard block
 block discarded – undo
1742 1828
 		$_SESSION['id_theme'] = $id_theme;
1743 1829
 	}
1744 1830
 	// The theme was specified by REQUEST... previously.
1745
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1746
-		$id_theme = (int) $_SESSION['id_theme'];
1831
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1832
+			$id_theme = (int) $_SESSION['id_theme'];
1833
+	}
1747 1834
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1748
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1749
-		$id_theme = $user_info['theme'];
1835
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1836
+			$id_theme = $user_info['theme'];
1837
+	}
1750 1838
 	// The theme was specified by the board.
1751
-	elseif (!empty($board_info['theme']))
1752
-		$id_theme = $board_info['theme'];
1839
+	elseif (!empty($board_info['theme'])) {
1840
+			$id_theme = $board_info['theme'];
1841
+	}
1753 1842
 	// The theme is the forum's default.
1754
-	else
1755
-		$id_theme = $modSettings['theme_guests'];
1843
+	else {
1844
+			$id_theme = $modSettings['theme_guests'];
1845
+	}
1756 1846
 
1757 1847
 	// Allow mod authors the option to override the theme id for custom page themes
1758 1848
 	call_integration_hook('integrate_pre_load_theme', array(&$id_theme));
1759 1849
 
1760 1850
 	// Verify the id_theme... no foul play.
1761 1851
 	// Always allow the board specific theme, if they are overriding.
1762
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1763
-		$id_theme = $board_info['theme'];
1852
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1853
+			$id_theme = $board_info['theme'];
1854
+	}
1764 1855
 	// If they have specified a particular theme to use with SSI allow it to be used.
1765
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1766
-		$id_theme = (int) $id_theme;
1767
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1856
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1857
+			$id_theme = (int) $id_theme;
1858
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1768 1859
 	{
1769 1860
 		$themes = explode(',', $modSettings['enableThemes']);
1770
-		if (!in_array($id_theme, $themes))
1771
-			$id_theme = $modSettings['theme_guests'];
1772
-		else
1773
-			$id_theme = (int) $id_theme;
1861
+		if (!in_array($id_theme, $themes)) {
1862
+					$id_theme = $modSettings['theme_guests'];
1863
+		} else {
1864
+					$id_theme = (int) $id_theme;
1865
+		}
1774 1866
 	}
1775 1867
 		
1776 1868
 	// We already load the basic stuff?
@@ -1779,18 +1871,19 @@  discard block
 block discarded – undo
1779 1871
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1780 1872
 
1781 1873
 		// Disable image proxy if we don't have SSL enabled
1782
-		if (empty($modSettings['force_ssl']))
1783
-			$image_proxy_enabled = false;
1874
+		if (empty($modSettings['force_ssl'])) {
1875
+					$image_proxy_enabled = false;
1876
+		}
1784 1877
 
1785 1878
 		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'])
1786 1879
 		{
1787 1880
 			$themeData = $temp;
1788 1881
 			$flag = true;
1882
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1883
+					$themeData = $temp + array($member => array());
1884
+		} else {
1885
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1789 1886
 		}
1790
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1791
-			$themeData = $temp + array($member => array());
1792
-		else
1793
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1794 1887
 
1795 1888
 		if (empty($flag))
1796 1889
 		{
@@ -1810,31 +1903,37 @@  discard block
 block discarded – undo
1810 1903
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1811 1904
 			{
1812 1905
 				// There are just things we shouldn't be able to change as members.
1813
-				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')))
1814
-					continue;
1906
+				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'))) {
1907
+									continue;
1908
+				}
1815 1909
 
1816 1910
 				// If this is the theme_dir of the default theme, store it.
1817
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1818
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1911
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1912
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1913
+				}
1819 1914
 
1820 1915
 				// If this isn't set yet, is a theme option, or is not the default theme..
1821
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1822
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1916
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1917
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1918
+				}
1823 1919
 			}
1824 1920
 			$smcFunc['db_free_result']($result);
1825 1921
 
1826
-			if (!empty($themeData[-1]))
1827
-				foreach ($themeData[-1] as $k => $v)
1922
+			if (!empty($themeData[-1])) {
1923
+							foreach ($themeData[-1] as $k => $v)
1828 1924
 				{
1829 1925
 					if (!isset($themeData[$member][$k]))
1830 1926
 						$themeData[$member][$k] = $v;
1927
+			}
1831 1928
 				}
1832 1929
 
1833
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1834
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1930
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1931
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1932
+			}
1835 1933
 			// Only if we didn't already load that part of the cache...
1836
-			elseif (!isset($temp))
1837
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1934
+			elseif (!isset($temp)) {
1935
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1936
+			}
1838 1937
 		}
1839 1938
 
1840 1939
 		$settings = $themeData[0];
@@ -1851,17 +1950,20 @@  discard block
 block discarded – undo
1851 1950
 		$settings['template_dirs'][] = $settings['theme_dir'];
1852 1951
 
1853 1952
 		// Based on theme (if there is one).
1854
-		if (!empty($settings['base_theme_dir']))
1855
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1953
+		if (!empty($settings['base_theme_dir'])) {
1954
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1955
+		}
1856 1956
 
1857 1957
 		// Lastly the default theme.
1858
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1859
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1958
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1959
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1960
+		}
1860 1961
 	}
1861 1962
 
1862 1963
 
1863
-	if (!$initialize)
1864
-		return;
1964
+	if (!$initialize) {
1965
+			return;
1966
+	}
1865 1967
 
1866 1968
 	// Check to see if we're forcing SSL
1867 1969
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1882,8 +1984,9 @@  discard block
 block discarded – undo
1882 1984
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1883 1985
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1884 1986
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1885
-		if ($temp != '/')
1886
-			$detected_url .= $temp;
1987
+		if ($temp != '/') {
1988
+					$detected_url .= $temp;
1989
+		}
1887 1990
 	}
1888 1991
 	if (isset($detected_url) && $detected_url != $boardurl)
1889 1992
 	{
@@ -1895,8 +1998,9 @@  discard block
 block discarded – undo
1895 1998
 			foreach ($aliases as $alias)
1896 1999
 			{
1897 2000
 				// Rip off all the boring parts, spaces, etc.
1898
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1899
-					$do_fix = true;
2001
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
2002
+									$do_fix = true;
2003
+				}
1900 2004
 			}
1901 2005
 		}
1902 2006
 
@@ -1904,21 +2008,23 @@  discard block
 block discarded – undo
1904 2008
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1905 2009
 		{
1906 2010
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1907
-			if (empty($_GET))
1908
-				redirectexit('wwwRedirect');
1909
-			else
2011
+			if (empty($_GET)) {
2012
+							redirectexit('wwwRedirect');
2013
+			} else
1910 2014
 			{
1911 2015
 				$k = key($_GET);
1912 2016
 				$v = current($_GET);
1913 2017
 
1914
-				if ($k != 'wwwRedirect')
1915
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
2018
+				if ($k != 'wwwRedirect') {
2019
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
2020
+				}
1916 2021
 			}
1917 2022
 		}
1918 2023
 
1919 2024
 		// #3 is just a check for SSL...
1920
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1921
-			$do_fix = true;
2025
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
2026
+					$do_fix = true;
2027
+		}
1922 2028
 
1923 2029
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1924 2030
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1953,8 +2059,9 @@  discard block
 block discarded – undo
1953 2059
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1954 2060
 				}
1955 2061
 			}
1956
-			foreach ($context['linktree'] as $k => $dummy)
1957
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2062
+			foreach ($context['linktree'] as $k => $dummy) {
2063
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2064
+			}
1958 2065
 		}
1959 2066
 	}
1960 2067
 	// Set up the contextual user array.
@@ -1973,16 +2080,16 @@  discard block
 block discarded – undo
1973 2080
 			'email' => $user_info['email'],
1974 2081
 			'ignoreusers' => $user_info['ignoreusers'],
1975 2082
 		);
1976
-		if (!$context['user']['is_guest'])
1977
-			$context['user']['name'] = $user_info['name'];
1978
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1979
-			$context['user']['name'] = $txt['guest_title'];
2083
+		if (!$context['user']['is_guest']) {
2084
+					$context['user']['name'] = $user_info['name'];
2085
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2086
+					$context['user']['name'] = $txt['guest_title'];
2087
+		}
1980 2088
 
1981 2089
 		// Determine the current smiley set.
1982 2090
 		$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'];
1983 2091
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1984
-	}
1985
-	else
2092
+	} else
1986 2093
 	{
1987 2094
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1988 2095
 		$context['user'] = array(
@@ -2016,18 +2123,24 @@  discard block
 block discarded – undo
2016 2123
 	}
2017 2124
 
2018 2125
 	// Some basic information...
2019
-	if (!isset($context['html_headers']))
2020
-		$context['html_headers'] = '';
2021
-	if (!isset($context['javascript_files']))
2022
-		$context['javascript_files'] = array();
2023
-	if (!isset($context['css_files']))
2024
-		$context['css_files'] = array();
2025
-	if (!isset($context['css_header']))
2026
-		$context['css_header'] = array();
2027
-	if (!isset($context['javascript_inline']))
2028
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2029
-	if (!isset($context['javascript_vars']))
2030
-		$context['javascript_vars'] = array();
2126
+	if (!isset($context['html_headers'])) {
2127
+			$context['html_headers'] = '';
2128
+	}
2129
+	if (!isset($context['javascript_files'])) {
2130
+			$context['javascript_files'] = array();
2131
+	}
2132
+	if (!isset($context['css_files'])) {
2133
+			$context['css_files'] = array();
2134
+	}
2135
+	if (!isset($context['css_header'])) {
2136
+			$context['css_header'] = array();
2137
+	}
2138
+	if (!isset($context['javascript_inline'])) {
2139
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2140
+	}
2141
+	if (!isset($context['javascript_vars'])) {
2142
+			$context['javascript_vars'] = array();
2143
+	}
2031 2144
 
2032 2145
 	$context['login_url'] =  $scripturl . '?action=login2';
2033 2146
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2039,16 +2152,18 @@  discard block
 block discarded – undo
2039 2152
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2040 2153
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2041 2154
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2042
-	if (isset($modSettings['load_average']))
2043
-		$context['load_average'] = $modSettings['load_average'];
2155
+	if (isset($modSettings['load_average'])) {
2156
+			$context['load_average'] = $modSettings['load_average'];
2157
+	}
2044 2158
 
2045 2159
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2046 2160
 	detectBrowser();
2047 2161
 
2048 2162
 	// Set the top level linktree up.
2049 2163
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2050
-	if (empty($context['linktree']))
2051
-		$context['linktree'] = array();
2164
+	if (empty($context['linktree'])) {
2165
+			$context['linktree'] = array();
2166
+	}
2052 2167
 	array_unshift($context['linktree'], array(
2053 2168
 		'url' => $scripturl,
2054 2169
 		'name' => $context['forum_name_html_safe']
@@ -2057,8 +2172,9 @@  discard block
 block discarded – undo
2057 2172
 	// This allows sticking some HTML on the page output - useful for controls.
2058 2173
 	$context['insert_after_template'] = '';
2059 2174
 
2060
-	if (!isset($txt))
2061
-		$txt = array();
2175
+	if (!isset($txt)) {
2176
+			$txt = array();
2177
+	}
2062 2178
 
2063 2179
 	$simpleActions = array(
2064 2180
 		'findmember',
@@ -2104,9 +2220,10 @@  discard block
 block discarded – undo
2104 2220
 
2105 2221
 	// See if theres any extra param to check.
2106 2222
 	$requiresXML = false;
2107
-	foreach ($extraParams as $key => $extra)
2108
-		if (isset($_REQUEST[$extra]))
2223
+	foreach ($extraParams as $key => $extra) {
2224
+			if (isset($_REQUEST[$extra]))
2109 2225
 			$requiresXML = true;
2226
+	}
2110 2227
 
2111 2228
 	// Output is fully XML, so no need for the index template.
2112 2229
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2121,37 +2238,39 @@  discard block
 block discarded – undo
2121 2238
 	{
2122 2239
 		loadLanguage('index+Modifications');
2123 2240
 		$context['template_layers'] = array();
2124
-	}
2125
-
2126
-	else
2241
+	} else
2127 2242
 	{
2128 2243
 		// Custom templates to load, or just default?
2129
-		if (isset($settings['theme_templates']))
2130
-			$templates = explode(',', $settings['theme_templates']);
2131
-		else
2132
-			$templates = array('index');
2244
+		if (isset($settings['theme_templates'])) {
2245
+					$templates = explode(',', $settings['theme_templates']);
2246
+		} else {
2247
+					$templates = array('index');
2248
+		}
2133 2249
 
2134 2250
 		// Load each template...
2135
-		foreach ($templates as $template)
2136
-			loadTemplate($template);
2251
+		foreach ($templates as $template) {
2252
+					loadTemplate($template);
2253
+		}
2137 2254
 
2138 2255
 		// ...and attempt to load their associated language files.
2139 2256
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2140 2257
 		loadLanguage($required_files, '', false);
2141 2258
 
2142 2259
 		// Custom template layers?
2143
-		if (isset($settings['theme_layers']))
2144
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2145
-		else
2146
-			$context['template_layers'] = array('html', 'body');
2260
+		if (isset($settings['theme_layers'])) {
2261
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2262
+		} else {
2263
+					$context['template_layers'] = array('html', 'body');
2264
+		}
2147 2265
 	}
2148 2266
 
2149 2267
 	// Initialize the theme.
2150 2268
 	loadSubTemplate('init', 'ignore');
2151 2269
 
2152 2270
 	// Allow overriding the board wide time/number formats.
2153
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2154
-		$user_info['time_format'] = $txt['time_format'];
2271
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2272
+			$user_info['time_format'] = $txt['time_format'];
2273
+	}
2155 2274
 
2156 2275
 	// Set the character set from the template.
2157 2276
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2159,12 +2278,14 @@  discard block
 block discarded – undo
2159 2278
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2160 2279
 
2161 2280
 	// Guests may still need a name.
2162
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2163
-		$context['user']['name'] = $txt['guest_title'];
2281
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2282
+			$context['user']['name'] = $txt['guest_title'];
2283
+	}
2164 2284
 
2165 2285
 	// Any theme-related strings that need to be loaded?
2166
-	if (!empty($settings['require_theme_strings']))
2167
-		loadLanguage('ThemeStrings', '', false);
2286
+	if (!empty($settings['require_theme_strings'])) {
2287
+			loadLanguage('ThemeStrings', '', false);
2288
+	}
2168 2289
 
2169 2290
 	// Make a special URL for the language.
2170 2291
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2175,8 +2296,9 @@  discard block
 block discarded – undo
2175 2296
 	// Here is my luvly Responsive CSS
2176 2297
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2177 2298
 
2178
-	if ($context['right_to_left'])
2179
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2299
+	if ($context['right_to_left']) {
2300
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2301
+	}
2180 2302
 
2181 2303
 	// We allow theme variants, because we're cool.
2182 2304
 	$context['theme_variant'] = '';
@@ -2184,14 +2306,17 @@  discard block
 block discarded – undo
2184 2306
 	if (!empty($settings['theme_variants']))
2185 2307
 	{
2186 2308
 		// Overriding - for previews and that ilk.
2187
-		if (!empty($_REQUEST['variant']))
2188
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2309
+		if (!empty($_REQUEST['variant'])) {
2310
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2311
+		}
2189 2312
 		// User selection?
2190
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2191
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2313
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2314
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2315
+		}
2192 2316
 		// If not a user variant, select the default.
2193
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2194
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2317
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2318
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2319
+		}
2195 2320
 
2196 2321
 		// Do this to keep things easier in the templates.
2197 2322
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2200,20 +2325,23 @@  discard block
 block discarded – undo
2200 2325
 		if (!empty($context['theme_variant']))
2201 2326
 		{
2202 2327
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2203
-			if ($context['right_to_left'])
2204
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2328
+			if ($context['right_to_left']) {
2329
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2330
+			}
2205 2331
 		}
2206 2332
 	}
2207 2333
 
2208 2334
 	// Let's be compatible with old themes!
2209
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2210
-		$context['template_layers'] = array('main');
2335
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2336
+			$context['template_layers'] = array('main');
2337
+	}
2211 2338
 
2212 2339
 	$context['tabindex'] = 1;
2213 2340
 
2214 2341
 	// Compatibility.
2215
-	if (!isset($settings['theme_version']))
2216
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2342
+	if (!isset($settings['theme_version'])) {
2343
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2344
+	}
2217 2345
 
2218 2346
 	// Default JS variables for use in every theme
2219 2347
 	$context['javascript_vars'] = array(
@@ -2234,18 +2362,18 @@  discard block
 block discarded – undo
2234 2362
 	);
2235 2363
 
2236 2364
 	// Add the JQuery library to the list of files to load.
2237
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2238
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2239
-
2240
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2241
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2242
-
2243
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2244
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2365
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2366
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2367
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2368
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2369
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2370
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2371
+	}
2245 2372
 
2246 2373
 	// Auto loading? template_javascript() will take care of the local half of this.
2247
-	else
2248
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2374
+	else {
2375
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2376
+	}
2249 2377
 
2250 2378
 	// Queue our JQuery plugins!
2251 2379
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2268,12 +2396,12 @@  discard block
 block discarded – undo
2268 2396
 			require_once($sourcedir . '/ScheduledTasks.php');
2269 2397
 
2270 2398
 			// What to do, what to do?!
2271
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2272
-				AutoTask();
2273
-			else
2274
-				ReduceMailQueue();
2275
-		}
2276
-		else
2399
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2400
+							AutoTask();
2401
+			} else {
2402
+							ReduceMailQueue();
2403
+			}
2404
+		} else
2277 2405
 		{
2278 2406
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2279 2407
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2324,8 +2452,9 @@  discard block
 block discarded – undo
2324 2452
 		foreach ($theme_includes as $include)
2325 2453
 		{
2326 2454
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2327
-			if (file_exists($include))
2328
-				require_once($include);
2455
+			if (file_exists($include)) {
2456
+							require_once($include);
2457
+			}
2329 2458
 		}
2330 2459
 	}
2331 2460
 
@@ -2355,16 +2484,19 @@  discard block
 block discarded – undo
2355 2484
 	// Do any style sheets first, cause we're easy with those.
2356 2485
 	if (!empty($style_sheets))
2357 2486
 	{
2358
-		if (!is_array($style_sheets))
2359
-			$style_sheets = array($style_sheets);
2487
+		if (!is_array($style_sheets)) {
2488
+					$style_sheets = array($style_sheets);
2489
+		}
2360 2490
 
2361
-		foreach ($style_sheets as $sheet)
2362
-			loadCSSFile($sheet . '.css', array(), $sheet);
2491
+		foreach ($style_sheets as $sheet) {
2492
+					loadCSSFile($sheet . '.css', array(), $sheet);
2493
+		}
2363 2494
 	}
2364 2495
 
2365 2496
 	// No template to load?
2366
-	if ($template_name === false)
2367
-		return true;
2497
+	if ($template_name === false) {
2498
+			return true;
2499
+	}
2368 2500
 
2369 2501
 	$loaded = false;
2370 2502
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2379,12 +2511,14 @@  discard block
 block discarded – undo
2379 2511
 
2380 2512
 	if ($loaded)
2381 2513
 	{
2382
-		if ($db_show_debug === true)
2383
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2514
+		if ($db_show_debug === true) {
2515
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2516
+		}
2384 2517
 
2385 2518
 		// If they have specified an initialization function for this template, go ahead and call it now.
2386
-		if (function_exists('template_' . $template_name . '_init'))
2387
-			call_user_func('template_' . $template_name . '_init');
2519
+		if (function_exists('template_' . $template_name . '_init')) {
2520
+					call_user_func('template_' . $template_name . '_init');
2521
+		}
2388 2522
 	}
2389 2523
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2390 2524
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2404,13 +2538,14 @@  discard block
 block discarded – undo
2404 2538
 		loadTemplate($template_name);
2405 2539
 	}
2406 2540
 	// Cause an error otherwise.
2407
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2408
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2409
-	elseif ($fatal)
2410
-		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'));
2411
-	else
2412
-		return false;
2413
-}
2541
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2542
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2543
+	} elseif ($fatal) {
2544
+			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'));
2545
+	} else {
2546
+			return false;
2547
+	}
2548
+	}
2414 2549
 
2415 2550
 /**
2416 2551
  * Load a sub-template.
@@ -2428,17 +2563,19 @@  discard block
 block discarded – undo
2428 2563
 {
2429 2564
 	global $context, $txt, $db_show_debug;
2430 2565
 
2431
-	if ($db_show_debug === true)
2432
-		$context['debug']['sub_templates'][] = $sub_template_name;
2566
+	if ($db_show_debug === true) {
2567
+			$context['debug']['sub_templates'][] = $sub_template_name;
2568
+	}
2433 2569
 
2434 2570
 	// Figure out what the template function is named.
2435 2571
 	$theme_function = 'template_' . $sub_template_name;
2436
-	if (function_exists($theme_function))
2437
-		$theme_function();
2438
-	elseif ($fatal === false)
2439
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2440
-	elseif ($fatal !== 'ignore')
2441
-		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'));
2572
+	if (function_exists($theme_function)) {
2573
+			$theme_function();
2574
+	} elseif ($fatal === false) {
2575
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2576
+	} elseif ($fatal !== 'ignore') {
2577
+			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'));
2578
+	}
2442 2579
 
2443 2580
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2444 2581
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2468,8 +2605,9 @@  discard block
 block discarded – undo
2468 2605
 {
2469 2606
 	global $settings, $context, $modSettings;
2470 2607
 
2471
-	if (empty($context['css_files_order']))
2472
-		$context['css_files_order'] = array();
2608
+	if (empty($context['css_files_order'])) {
2609
+			$context['css_files_order'] = array();
2610
+	}
2473 2611
 
2474 2612
 	$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']) : '');
2475 2613
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2480,8 +2618,9 @@  discard block
 block discarded – undo
2480 2618
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2481 2619
 
2482 2620
 	// If this is an external file, automatically set this to false.
2483
-	if (!empty($params['external']))
2484
-		$params['minimize'] = false;
2621
+	if (!empty($params['external'])) {
2622
+			$params['minimize'] = false;
2623
+	}
2485 2624
 
2486 2625
 	// Account for shorthand like admin.css?alp21 filenames
2487 2626
 	$has_seed = strpos($fileName, '.css?');
@@ -2498,16 +2637,12 @@  discard block
 block discarded – undo
2498 2637
 			{
2499 2638
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2500 2639
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2501
-			}
2502
-
2503
-			else
2640
+			} else
2504 2641
 			{
2505 2642
 				$fileUrl = false;
2506 2643
 				$filePath = false;
2507 2644
 			}
2508
-		}
2509
-
2510
-		else
2645
+		} else
2511 2646
 		{
2512 2647
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2513 2648
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2525,16 +2660,18 @@  discard block
 block discarded – undo
2525 2660
 	if (!empty($fileName))
2526 2661
 	{
2527 2662
 		// find a free number/position
2528
-		while (isset($context['css_files_order'][$params['order_pos']]))
2529
-			$params['order_pos']++;
2663
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2664
+					$params['order_pos']++;
2665
+		}
2530 2666
 		$context['css_files_order'][$params['order_pos']] = $id;
2531 2667
 
2532 2668
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2533 2669
 	}
2534 2670
 
2535
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2536
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2537
-}
2671
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2672
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2673
+	}
2674
+	}
2538 2675
 
2539 2676
 /**
2540 2677
  * Add a block of inline css code to be executed later
@@ -2551,8 +2688,9 @@  discard block
 block discarded – undo
2551 2688
 	global $context;
2552 2689
 
2553 2690
 	// Gotta add something...
2554
-	if (empty($css))
2555
-		return false;
2691
+	if (empty($css)) {
2692
+			return false;
2693
+	}
2556 2694
 
2557 2695
 	$context['css_header'][] = $css;
2558 2696
 }
@@ -2588,8 +2726,9 @@  discard block
 block discarded – undo
2588 2726
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2589 2727
 
2590 2728
 	// If this is an external file, automatically set this to false.
2591
-	if (!empty($params['external']))
2592
-		$params['minimize'] = false;
2729
+	if (!empty($params['external'])) {
2730
+			$params['minimize'] = false;
2731
+	}
2593 2732
 
2594 2733
 	// Account for shorthand like admin.js?alp21 filenames
2595 2734
 	$has_seed = strpos($fileName, '.js?');
@@ -2606,16 +2745,12 @@  discard block
 block discarded – undo
2606 2745
 			{
2607 2746
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2608 2747
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2609
-			}
2610
-
2611
-			else
2748
+			} else
2612 2749
 			{
2613 2750
 				$fileUrl = false;
2614 2751
 				$filePath = false;
2615 2752
 			}
2616
-		}
2617
-
2618
-		else
2753
+		} else
2619 2754
 		{
2620 2755
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2621 2756
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2630,9 +2765,10 @@  discard block
 block discarded – undo
2630 2765
 	}
2631 2766
 
2632 2767
 	// Add it to the array for use in the template
2633
-	if (!empty($fileName))
2634
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2635
-}
2768
+	if (!empty($fileName)) {
2769
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2770
+	}
2771
+	}
2636 2772
 
2637 2773
 /**
2638 2774
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2646,9 +2782,10 @@  discard block
 block discarded – undo
2646 2782
 {
2647 2783
 	global $context;
2648 2784
 
2649
-	if (!empty($key) && (!empty($value) || $value === '0'))
2650
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2651
-}
2785
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2786
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2787
+	}
2788
+	}
2652 2789
 
2653 2790
 /**
2654 2791
  * Add a block of inline Javascript code to be executed later
@@ -2665,8 +2802,9 @@  discard block
 block discarded – undo
2665 2802
 {
2666 2803
 	global $context;
2667 2804
 
2668
-	if (empty($javascript))
2669
-		return false;
2805
+	if (empty($javascript)) {
2806
+			return false;
2807
+	}
2670 2808
 
2671 2809
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2672 2810
 }
@@ -2687,15 +2825,18 @@  discard block
 block discarded – undo
2687 2825
 	static $already_loaded = array();
2688 2826
 
2689 2827
 	// Default to the user's language.
2690
-	if ($lang == '')
2691
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2828
+	if ($lang == '') {
2829
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2830
+	}
2692 2831
 
2693 2832
 	// Do we want the English version of language file as fallback?
2694
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2695
-		loadLanguage($template_name, 'english', false);
2833
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2834
+			loadLanguage($template_name, 'english', false);
2835
+	}
2696 2836
 
2697
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2698
-		return $lang;
2837
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2838
+			return $lang;
2839
+	}
2699 2840
 
2700 2841
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2701 2842
 	if (empty($settings['default_theme_dir']))
@@ -2706,8 +2847,9 @@  discard block
 block discarded – undo
2706 2847
 
2707 2848
 	// What theme are we in?
2708 2849
 	$theme_name = basename($settings['theme_url']);
2709
-	if (empty($theme_name))
2710
-		$theme_name = 'unknown';
2850
+	if (empty($theme_name)) {
2851
+			$theme_name = 'unknown';
2852
+	}
2711 2853
 
2712 2854
 	// For each file open it up and write it out!
2713 2855
 	foreach (explode('+', $template_name) as $template)
@@ -2749,8 +2891,9 @@  discard block
 block discarded – undo
2749 2891
 				$found = true;
2750 2892
 
2751 2893
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2752
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2753
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2894
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2895
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2896
+				}
2754 2897
 
2755 2898
 				break;
2756 2899
 			}
@@ -2790,8 +2933,9 @@  discard block
 block discarded – undo
2790 2933
 	}
2791 2934
 
2792 2935
 	// Keep track of what we're up to soldier.
2793
-	if ($db_show_debug === true)
2794
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2936
+	if ($db_show_debug === true) {
2937
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2938
+	}
2795 2939
 
2796 2940
 	// Remember what we have loaded, and in which language.
2797 2941
 	$already_loaded[$template_name] = $lang;
@@ -2837,8 +2981,9 @@  discard block
 block discarded – undo
2837 2981
 				)
2838 2982
 			);
2839 2983
 			// In the EXTREMELY unlikely event this happens, give an error message.
2840
-			if ($smcFunc['db_num_rows']($result) == 0)
2841
-				fatal_lang_error('parent_not_found', 'critical');
2984
+			if ($smcFunc['db_num_rows']($result) == 0) {
2985
+							fatal_lang_error('parent_not_found', 'critical');
2986
+			}
2842 2987
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2843 2988
 			{
2844 2989
 				if (!isset($boards[$row['id_board']]))
@@ -2855,8 +3000,8 @@  discard block
 block discarded – undo
2855 3000
 					);
2856 3001
 				}
2857 3002
 				// If a moderator exists for this board, add that moderator for all children too.
2858
-				if (!empty($row['id_moderator']))
2859
-					foreach ($boards as $id => $dummy)
3003
+				if (!empty($row['id_moderator'])) {
3004
+									foreach ($boards as $id => $dummy)
2860 3005
 					{
2861 3006
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2862 3007
 							'id' => $row['id_moderator'],
@@ -2864,11 +3009,12 @@  discard block
 block discarded – undo
2864 3009
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2865 3010
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2866 3011
 						);
3012
+				}
2867 3013
 					}
2868 3014
 
2869 3015
 				// If a moderator group exists for this board, add that moderator group for all children too
2870
-				if (!empty($row['id_moderator_group']))
2871
-					foreach ($boards as $id => $dummy)
3016
+				if (!empty($row['id_moderator_group'])) {
3017
+									foreach ($boards as $id => $dummy)
2872 3018
 					{
2873 3019
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2874 3020
 							'id' => $row['id_moderator_group'],
@@ -2876,6 +3022,7 @@  discard block
 block discarded – undo
2876 3022
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2877 3023
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2878 3024
 						);
3025
+				}
2879 3026
 					}
2880 3027
 			}
2881 3028
 			$smcFunc['db_free_result']($result);
@@ -2902,23 +3049,27 @@  discard block
 block discarded – undo
2902 3049
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2903 3050
 	{
2904 3051
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2905
-		if (empty($smcFunc['ucwords']))
2906
-			reloadSettings();
3052
+		if (empty($smcFunc['ucwords'])) {
3053
+					reloadSettings();
3054
+		}
2907 3055
 
2908 3056
 		// If we don't have our theme information yet, let's get it.
2909
-		if (empty($settings['default_theme_dir']))
2910
-			loadTheme(0, false);
3057
+		if (empty($settings['default_theme_dir'])) {
3058
+					loadTheme(0, false);
3059
+		}
2911 3060
 
2912 3061
 		// Default language directories to try.
2913 3062
 		$language_directories = array(
2914 3063
 			$settings['default_theme_dir'] . '/languages',
2915 3064
 		);
2916
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2917
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3065
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3066
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3067
+		}
2918 3068
 
2919 3069
 		// We possibly have a base theme directory.
2920
-		if (!empty($settings['base_theme_dir']))
2921
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3070
+		if (!empty($settings['base_theme_dir'])) {
3071
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3072
+		}
2922 3073
 
2923 3074
 		// Remove any duplicates.
2924 3075
 		$language_directories = array_unique($language_directories);
@@ -2932,20 +3083,21 @@  discard block
 block discarded – undo
2932 3083
 		foreach ($language_directories as $language_dir)
2933 3084
 		{
2934 3085
 			// Can't look in here... doesn't exist!
2935
-			if (!file_exists($language_dir))
2936
-				continue;
3086
+			if (!file_exists($language_dir)) {
3087
+							continue;
3088
+			}
2937 3089
 
2938 3090
 			$dir = dir($language_dir);
2939 3091
 			while ($entry = $dir->read())
2940 3092
 			{
2941 3093
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2942
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2943
-					continue;
2944
-
2945
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2946
-					$langName = $langList[$matches[1]];
3094
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3095
+									continue;
3096
+				}
2947 3097
 
2948
-				else
3098
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3099
+									$langName = $langList[$matches[1]];
3100
+				} else
2949 3101
 				{
2950 3102
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2951 3103
 
@@ -2986,12 +3138,14 @@  discard block
 block discarded – undo
2986 3138
 		}
2987 3139
 
2988 3140
 		// Do we need to store the lang list?
2989
-		if (empty($langList))
2990
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3141
+		if (empty($langList)) {
3142
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3143
+		}
2991 3144
 
2992 3145
 		// Let's cash in on this deal.
2993
-		if (!empty($modSettings['cache_enable']))
2994
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3146
+		if (!empty($modSettings['cache_enable'])) {
3147
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3148
+		}
2995 3149
 	}
2996 3150
 
2997 3151
 	return $context['languages'];
@@ -3014,8 +3168,9 @@  discard block
 block discarded – undo
3014 3168
 	global $modSettings, $options, $txt;
3015 3169
 	static $censor_vulgar = null, $censor_proper;
3016 3170
 
3017
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
3018
-		return $text;
3171
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3172
+			return $text;
3173
+	}
3019 3174
 
3020 3175
 	// If they haven't yet been loaded, load them.
3021 3176
 	if ($censor_vulgar == null)
@@ -3046,9 +3201,9 @@  discard block
 block discarded – undo
3046 3201
 	{
3047 3202
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3048 3203
 		$text = $func($censor_vulgar, $censor_proper, $text);
3204
+	} else {
3205
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3049 3206
 	}
3050
-	else
3051
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3052 3207
 
3053 3208
 	return $text;
3054 3209
 }
@@ -3074,30 +3229,35 @@  discard block
 block discarded – undo
3074 3229
 	@ini_set('track_errors', '1');
3075 3230
 
3076 3231
 	// Don't include the file more than once, if $once is true.
3077
-	if ($once && in_array($filename, $templates))
3078
-		return;
3232
+	if ($once && in_array($filename, $templates)) {
3233
+			return;
3234
+	}
3079 3235
 	// Add this file to the include list, whether $once is true or not.
3080
-	else
3081
-		$templates[] = $filename;
3236
+	else {
3237
+			$templates[] = $filename;
3238
+	}
3082 3239
 
3083 3240
 
3084 3241
 	$file_found = file_exists($filename);
3085 3242
 
3086
-	if ($once && $file_found)
3087
-		require_once($filename);
3088
-	elseif ($file_found)
3089
-		require($filename);
3243
+	if ($once && $file_found) {
3244
+			require_once($filename);
3245
+	} elseif ($file_found) {
3246
+			require($filename);
3247
+	}
3090 3248
 
3091 3249
 	if ($file_found !== true)
3092 3250
 	{
3093 3251
 		ob_end_clean();
3094
-		if (!empty($modSettings['enableCompressedOutput']))
3095
-			@ob_start('ob_gzhandler');
3096
-		else
3097
-			ob_start();
3252
+		if (!empty($modSettings['enableCompressedOutput'])) {
3253
+					@ob_start('ob_gzhandler');
3254
+		} else {
3255
+					ob_start();
3256
+		}
3098 3257
 
3099
-		if (isset($_GET['debug']))
3100
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3258
+		if (isset($_GET['debug'])) {
3259
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3260
+		}
3101 3261
 
3102 3262
 		// Don't cache error pages!!
3103 3263
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3116,12 +3276,13 @@  discard block
 block discarded – undo
3116 3276
 		echo '<!DOCTYPE html>
3117 3277
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3118 3278
 	<head>';
3119
-		if (isset($context['character_set']))
3120
-			echo '
3279
+		if (isset($context['character_set'])) {
3280
+					echo '
3121 3281
 		<meta charset="', $context['character_set'], '">';
3282
+		}
3122 3283
 
3123
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3124
-			echo '
3284
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3285
+					echo '
3125 3286
 		<title>', $mtitle, '</title>
3126 3287
 	</head>
3127 3288
 	<body>
@@ -3129,8 +3290,8 @@  discard block
 block discarded – undo
3129 3290
 		', $mmessage, '
3130 3291
 	</body>
3131 3292
 </html>';
3132
-		elseif (!allowedTo('admin_forum'))
3133
-			echo '
3293
+		} elseif (!allowedTo('admin_forum')) {
3294
+					echo '
3134 3295
 		<title>', $txt['template_parse_error'], '</title>
3135 3296
 	</head>
3136 3297
 	<body>
@@ -3138,14 +3299,16 @@  discard block
 block discarded – undo
3138 3299
 		', $txt['template_parse_error_message'], '
3139 3300
 	</body>
3140 3301
 </html>';
3141
-		else
3302
+		} else
3142 3303
 		{
3143 3304
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3144 3305
 			$error_array = error_get_last();
3145
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3146
-				$error = $error_array['message'];
3147
-			if (empty($error))
3148
-				$error = $txt['template_parse_errmsg'];
3306
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3307
+							$error = $error_array['message'];
3308
+			}
3309
+			if (empty($error)) {
3310
+							$error = $txt['template_parse_errmsg'];
3311
+			}
3149 3312
 
3150 3313
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3151 3314
 
@@ -3156,11 +3319,12 @@  discard block
 block discarded – undo
3156 3319
 		<h3>', $txt['template_parse_error'], '</h3>
3157 3320
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3158 3321
 
3159
-			if (!empty($error))
3160
-				echo '
3322
+			if (!empty($error)) {
3323
+							echo '
3161 3324
 		<hr>
3162 3325
 
3163 3326
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3327
+			}
3164 3328
 
3165 3329
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3166 3330
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3170,10 +3334,11 @@  discard block
 block discarded – undo
3170 3334
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3171 3335
 
3172 3336
 				// Fix the PHP code stuff...
3173
-				if (!isBrowser('gecko'))
3174
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3175
-				else
3176
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3337
+				if (!isBrowser('gecko')) {
3338
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3339
+				} else {
3340
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3341
+				}
3177 3342
 
3178 3343
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3179 3344
 				$j = -1;
@@ -3181,8 +3346,9 @@  discard block
 block discarded – undo
3181 3346
 				{
3182 3347
 					$j++;
3183 3348
 
3184
-					if (substr_count($line, '<br>') == 0)
3185
-						continue;
3349
+					if (substr_count($line, '<br>') == 0) {
3350
+											continue;
3351
+					}
3186 3352
 
3187 3353
 					$n = substr_count($line, '<br>');
3188 3354
 					for ($i = 0; $i < $n; $i++)
@@ -3201,38 +3367,42 @@  discard block
 block discarded – undo
3201 3367
 				// Figure out what the color coding was before...
3202 3368
 				$line = max($match[1] - 9, 1);
3203 3369
 				$last_line = '';
3204
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3205
-					if (strpos($data2[$line2], '<') !== false)
3370
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3371
+									if (strpos($data2[$line2], '<') !== false)
3206 3372
 					{
3207 3373
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3208 3374
 							$last_line = $color_match[1];
3375
+				}
3209 3376
 						break;
3210 3377
 					}
3211 3378
 
3212 3379
 				// Show the relevant lines...
3213 3380
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3214 3381
 				{
3215
-					if ($line == $match[1])
3216
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3382
+					if ($line == $match[1]) {
3383
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3384
+					}
3217 3385
 
3218 3386
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3219
-					if (isset($data2[$line]) && $data2[$line] != '')
3220
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3387
+					if (isset($data2[$line]) && $data2[$line] != '') {
3388
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3389
+					}
3221 3390
 
3222 3391
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3223 3392
 					{
3224 3393
 						$last_line = $color_match[1];
3225 3394
 						echo '</', substr($last_line, 1, 4), '>';
3395
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3396
+											$last_line = '';
3397
+					} elseif ($last_line != '' && $data2[$line] != '') {
3398
+											echo '</', substr($last_line, 1, 4), '>';
3226 3399
 					}
3227
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3228
-						$last_line = '';
3229
-					elseif ($last_line != '' && $data2[$line] != '')
3230
-						echo '</', substr($last_line, 1, 4), '>';
3231 3400
 
3232
-					if ($line == $match[1])
3233
-						echo '</pre></div><pre style="margin: 0;">';
3234
-					else
3235
-						echo "\n";
3401
+					if ($line == $match[1]) {
3402
+											echo '</pre></div><pre style="margin: 0;">';
3403
+					} else {
3404
+											echo "\n";
3405
+					}
3236 3406
 				}
3237 3407
 
3238 3408
 				echo '</pre></div>';
@@ -3256,8 +3426,9 @@  discard block
 block discarded – undo
3256 3426
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port, $db_mb4;
3257 3427
 
3258 3428
 	// Figure out what type of database we are using.
3259
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3260
-		$db_type = 'mysql';
3429
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3430
+			$db_type = 'mysql';
3431
+	}
3261 3432
 
3262 3433
 	// Load the file for the database.
3263 3434
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3265,11 +3436,13 @@  discard block
 block discarded – undo
3265 3436
 	$db_options = array();
3266 3437
 
3267 3438
 	// Add in the port if needed
3268
-	if (!empty($db_port))
3269
-		$db_options['port'] = $db_port;
3439
+	if (!empty($db_port)) {
3440
+			$db_options['port'] = $db_port;
3441
+	}
3270 3442
 
3271
-	if (!empty($db_mb4))
3272
-		$db_options['db_mb4'] = $db_mb4;
3443
+	if (!empty($db_mb4)) {
3444
+			$db_options['db_mb4'] = $db_mb4;
3445
+	}
3273 3446
 
3274 3447
 	// 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.
3275 3448
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3288,13 +3461,15 @@  discard block
 block discarded – undo
3288 3461
 	}
3289 3462
 
3290 3463
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3291
-	if (!$db_connection)
3292
-		display_db_error();
3464
+	if (!$db_connection) {
3465
+			display_db_error();
3466
+	}
3293 3467
 
3294 3468
 	// If in SSI mode fix up the prefix.
3295
-	if (SMF == 'SSI')
3296
-		db_fix_prefix($db_prefix, $db_name);
3297
-}
3469
+	if (SMF == 'SSI') {
3470
+			db_fix_prefix($db_prefix, $db_name);
3471
+	}
3472
+	}
3298 3473
 
3299 3474
 /**
3300 3475
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3308,10 +3483,11 @@  discard block
 block discarded – undo
3308 3483
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3309 3484
 
3310 3485
 	// Not overriding this and we have a cacheAPI, send it back.
3311
-	if (empty($overrideCache) && is_object($cacheAPI))
3312
-		return $cacheAPI;
3313
-	elseif (is_null($cacheAPI))
3314
-		$cacheAPI = false;
3486
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3487
+			return $cacheAPI;
3488
+	} elseif (is_null($cacheAPI)) {
3489
+			$cacheAPI = false;
3490
+	}
3315 3491
 
3316 3492
 	// Make sure our class is in session.
3317 3493
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3332,8 +3508,9 @@  discard block
 block discarded – undo
3332 3508
 		if (!$testAPI->isSupported())
3333 3509
 		{
3334 3510
 			// Can we save ourselves?
3335
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3336
-				return loadCacheAccelerator(null, false);
3511
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3512
+							return loadCacheAccelerator(null, false);
3513
+			}
3337 3514
 			return false;
3338 3515
 		}
3339 3516
 
@@ -3345,9 +3522,9 @@  discard block
 block discarded – undo
3345 3522
 		{
3346 3523
 			$cacheAPI = $testAPI;
3347 3524
 			return $cacheAPI;
3525
+		} else {
3526
+					return $testAPI;
3348 3527
 		}
3349
-		else
3350
-			return $testAPI;
3351 3528
 	}
3352 3529
 }
3353 3530
 
@@ -3367,8 +3544,9 @@  discard block
 block discarded – undo
3367 3544
 
3368 3545
 	// @todo Why are we doing this if caching is disabled?
3369 3546
 
3370
-	if (function_exists('call_integration_hook'))
3371
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3547
+	if (function_exists('call_integration_hook')) {
3548
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3549
+	}
3372 3550
 
3373 3551
 	/* Refresh the cache if either:
3374 3552
 		1. Caching is disabled.
@@ -3382,16 +3560,19 @@  discard block
 block discarded – undo
3382 3560
 		require_once($sourcedir . '/' . $file);
3383 3561
 		$cache_block = call_user_func_array($function, $params);
3384 3562
 
3385
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3386
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3563
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3564
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3565
+		}
3387 3566
 	}
3388 3567
 
3389 3568
 	// Some cached data may need a freshening up after retrieval.
3390
-	if (!empty($cache_block['post_retri_eval']))
3391
-		eval($cache_block['post_retri_eval']);
3569
+	if (!empty($cache_block['post_retri_eval'])) {
3570
+			eval($cache_block['post_retri_eval']);
3571
+	}
3392 3572
 
3393
-	if (function_exists('call_integration_hook'))
3394
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3573
+	if (function_exists('call_integration_hook')) {
3574
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3575
+	}
3395 3576
 
3396 3577
 	return $cache_block['data'];
3397 3578
 }
@@ -3418,8 +3599,9 @@  discard block
 block discarded – undo
3418 3599
 	global $smcFunc, $cache_enable, $cacheAPI;
3419 3600
 	global $cache_hits, $cache_count, $db_show_debug;
3420 3601
 
3421
-	if (empty($cache_enable) || empty($cacheAPI))
3422
-		return;
3602
+	if (empty($cache_enable) || empty($cacheAPI)) {
3603
+			return;
3604
+	}
3423 3605
 
3424 3606
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3425 3607
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3432,12 +3614,14 @@  discard block
 block discarded – undo
3432 3614
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3433 3615
 	$cacheAPI->putData($key, $value, $ttl);
3434 3616
 
3435
-	if (function_exists('call_integration_hook'))
3436
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3617
+	if (function_exists('call_integration_hook')) {
3618
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3619
+	}
3437 3620
 
3438
-	if (isset($db_show_debug) && $db_show_debug === true)
3439
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3440
-}
3621
+	if (isset($db_show_debug) && $db_show_debug === true) {
3622
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3623
+	}
3624
+	}
3441 3625
 
3442 3626
 /**
3443 3627
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3453,8 +3637,9 @@  discard block
 block discarded – undo
3453 3637
 	global $smcFunc, $cache_enable, $cacheAPI;
3454 3638
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3455 3639
 
3456
-	if (empty($cache_enable) || empty($cacheAPI))
3457
-		return;
3640
+	if (empty($cache_enable) || empty($cacheAPI)) {
3641
+			return;
3642
+	}
3458 3643
 
3459 3644
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3460 3645
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3474,16 +3659,18 @@  discard block
 block discarded – undo
3474 3659
 
3475 3660
 		if (empty($value))
3476 3661
 		{
3477
-			if (!is_array($cache_misses))
3478
-				$cache_misses = array();
3662
+			if (!is_array($cache_misses)) {
3663
+							$cache_misses = array();
3664
+			}
3479 3665
 
3480 3666
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3481 3667
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3482 3668
 		}
3483 3669
 	}
3484 3670
 
3485
-	if (function_exists('call_integration_hook') && isset($value))
3486
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3671
+	if (function_exists('call_integration_hook') && isset($value)) {
3672
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3673
+	}
3487 3674
 
3488 3675
 	return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3489 3676
 }
@@ -3505,8 +3692,9 @@  discard block
 block discarded – undo
3505 3692
 	global $cacheAPI;
3506 3693
 
3507 3694
 	// If we can't get to the API, can't do this.
3508
-	if (empty($cacheAPI))
3509
-		return;
3695
+	if (empty($cacheAPI)) {
3696
+			return;
3697
+	}
3510 3698
 
3511 3699
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3512 3700
 	$cacheAPI->cleanCache($type);
@@ -3531,8 +3719,9 @@  discard block
 block discarded – undo
3531 3719
 	global $modSettings, $smcFunc, $image_proxy_enabled, $user_info;
3532 3720
 
3533 3721
 	// Come on!
3534
-	if (empty($data))
3535
-		return array();
3722
+	if (empty($data)) {
3723
+			return array();
3724
+	}
3536 3725
 
3537 3726
 	// Set a nice default var.
3538 3727
 	$image = '';
@@ -3540,11 +3729,11 @@  discard block
 block discarded – undo
3540 3729
 	// Gravatar has been set as mandatory!
3541 3730
 	if (!empty($modSettings['gravatarOverride']))
3542 3731
 	{
3543
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3544
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3545
-
3546
-		else if (!empty($data['email']))
3547
-			$image = get_gravatar_url($data['email']);
3732
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3733
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3734
+		} else if (!empty($data['email'])) {
3735
+					$image = get_gravatar_url($data['email']);
3736
+		}
3548 3737
 	}
3549 3738
 
3550 3739
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3556,54 +3745,60 @@  discard block
 block discarded – undo
3556 3745
 			// Gravatar.
3557 3746
 			if (stristr($data['avatar'], 'gravatar://'))
3558 3747
 			{
3559
-				if ($data['avatar'] == 'gravatar://')
3560
-					$image = get_gravatar_url($data['email']);
3561
-
3562
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3563
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3748
+				if ($data['avatar'] == 'gravatar://') {
3749
+									$image = get_gravatar_url($data['email']);
3750
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3751
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3752
+				}
3564 3753
 			}
3565 3754
 
3566 3755
 			// External url.
3567 3756
 			else
3568 3757
 			{
3569 3758
 				// Using ssl?
3570
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3571
-					$image = get_proxied_url($data['avatar']);
3759
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3760
+									$image = get_proxied_url($data['avatar']);
3761
+				}
3572 3762
 
3573 3763
 				// Just a plain external url.
3574
-				else
3575
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3764
+				else {
3765
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3766
+				}
3576 3767
 			}
3577 3768
 		}
3578 3769
 
3579 3770
 		// Perhaps this user has an attachment as avatar...
3580
-		else if (!empty($data['filename']))
3581
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3771
+		else if (!empty($data['filename'])) {
3772
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3773
+		}
3582 3774
 
3583 3775
 		// Right... no avatar... use our default image.
3584
-		else
3585
-			$image = $modSettings['avatar_url'] . '/default.png';
3776
+		else {
3777
+					$image = $modSettings['avatar_url'] . '/default.png';
3778
+		}
3586 3779
 	}
3587 3780
 
3588 3781
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3589 3782
 
3590 3783
 	// 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.
3591
-	if (!empty($image))
3592
-		return array(
3784
+	if (!empty($image)) {
3785
+			return array(
3593 3786
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3594 3787
 			'image' => '<img class="avatar" src="' . $image . '" />',
3595 3788
 			'href' => $image,
3596 3789
 			'url' => $image,
3597 3790
 		);
3791
+	}
3598 3792
 
3599 3793
 	// Fallback to make life easier for everyone...
3600
-	else
3601
-		return array(
3794
+	else {
3795
+			return array(
3602 3796
 			'name' => '',
3603 3797
 			'image' => '',
3604 3798
 			'href' => '',
3605 3799
 			'url' => '',
3606 3800
 		);
3607
-}
3801
+	}
3802
+	}
3608 3803
 
3609 3804
 ?>
3610 3805
\ No newline at end of file
Please login to merge, or discard this patch.