Completed
Pull Request — release-2.1 (#4401)
by Colin
07:31
created
Sources/Load.php 1 patch
Braces   +784 added lines, -593 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|&quot;|&amp;|&lt;|&gt;|&nbsp;|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -405,27 +422,28 @@  discard block
 block discarded – undo
405 422
 				break;
406 423
 			}
407 424
 		}
425
+	} else {
426
+			$id_member = 0;
408 427
 	}
409
-	else
410
-		$id_member = 0;
411 428
 
412 429
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
413 430
 	{
414 431
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
415 432
 
416
-		if (empty($cookie_data))
417
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
433
+		if (empty($cookie_data)) {
434
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
435
+		}
418 436
 
419 437
 		list ($id_member, $password) = $cookie_data;
420 438
 		$id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0;
421
-	}
422
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
439
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
423 440
 	{
424 441
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
425 442
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
426 443
 
427
-		if (empty($cookie_data))
428
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
444
+		if (empty($cookie_data)) {
445
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
446
+		}
429 447
 
430 448
 		list ($id_member, $password, $login_span) = $cookie_data;
431 449
 		$id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0;
@@ -450,30 +468,34 @@  discard block
 block discarded – undo
450 468
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
451 469
 			$smcFunc['db_free_result']($request);
452 470
 
453
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false)
454
-				$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
471
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) {
472
+							$user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret);
473
+			}
455 474
 
456
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
457
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
475
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
476
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
477
+			}
458 478
 		}
459 479
 
460 480
 		// Did we find 'im?  If not, junk it.
461 481
 		if (!empty($user_settings))
462 482
 		{
463 483
 			// As much as the password should be right, we can assume the integration set things up.
464
-			if (!empty($already_verified) && $already_verified === true)
465
-				$check = true;
484
+			if (!empty($already_verified) && $already_verified === true) {
485
+							$check = true;
486
+			}
466 487
 			// SHA-512 hash should be 128 characters long.
467
-			elseif (strlen($password) == 128)
468
-				$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
469
-			else
470
-				$check = false;
488
+			elseif (strlen($password) == 128) {
489
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
490
+			} else {
491
+							$check = false;
492
+			}
471 493
 
472 494
 			// Wrong password or not activated - either way, you're going nowhere.
473 495
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
496
+		} else {
497
+					$id_member = 0;
474 498
 		}
475
-		else
476
-			$id_member = 0;
477 499
 
478 500
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
479 501
 		if (!$id_member)
@@ -502,8 +524,9 @@  discard block
 block discarded – undo
502 524
 
503 525
 					list ($tfamember, $tfasecret) = $tfa_data;
504 526
 
505
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
506
-						$tfasecret = null;
527
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
528
+											$tfasecret = null;
529
+					}
507 530
 				}
508 531
 
509 532
 				if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret)
@@ -523,10 +546,12 @@  discard block
 block discarded – undo
523 546
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
524 547
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
525 548
 		{
526
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
549
+			if ($modSettings['tfa_mode'] == 2) {
550
+				//only do this if we are just forcing SOME membergroups
527 551
 			{
528 552
 				//Build an array of ALL user membergroups.
529 553
 				$full_groups = array($user_settings['id_group']);
554
+			}
530 555
 				if (!empty($user_settings['additional_groups']))
531 556
 				{
532 557
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -546,15 +571,17 @@  discard block
 block discarded – undo
546 571
 				);
547 572
 				$row = $smcFunc['db_fetch_assoc']($request);
548 573
 				$smcFunc['db_free_result']($request);
574
+			} else {
575
+							$row['total'] = 1;
549 576
 			}
550
-			else
551
-				$row['total'] = 1; //simplifies logics in the next "if"
577
+			//simplifies logics in the next "if"
552 578
 
553 579
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
554 580
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
555 581
 
556
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
557
-				redirectexit('action=profile;area=tfasetup;forced');
582
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
583
+							redirectexit('action=profile;area=tfasetup;forced');
584
+			}
558 585
 		}
559 586
 	}
560 587
 
@@ -591,33 +618,37 @@  discard block
 block discarded – undo
591 618
 				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']));
592 619
 				$user_settings['last_login'] = time();
593 620
 
594
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
595
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
621
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
622
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
623
+				}
596 624
 
597
-				if (!empty($modSettings['cache_enable']))
598
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
625
+				if (!empty($modSettings['cache_enable'])) {
626
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
627
+				}
599 628
 			}
629
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
630
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
600 631
 		}
601
-		elseif (empty($_SESSION['id_msg_last_visit']))
602
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
603 632
 
604 633
 		$username = $user_settings['member_name'];
605 634
 
606
-		if (empty($user_settings['additional_groups']))
607
-			$user_info = array(
635
+		if (empty($user_settings['additional_groups'])) {
636
+					$user_info = array(
608 637
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
609 638
 			);
610
-		else
611
-			$user_info = array(
639
+		} else {
640
+					$user_info = array(
612 641
 				'groups' => array_merge(
613 642
 					array($user_settings['id_group'], $user_settings['id_post_group']),
614 643
 					explode(',', $user_settings['additional_groups'])
615 644
 				)
616 645
 			);
646
+		}
617 647
 
618 648
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
619
-		foreach ($user_info['groups'] as $k => $v)
620
-			$user_info['groups'][$k] = (int) $v;
649
+		foreach ($user_info['groups'] as $k => $v) {
650
+					$user_info['groups'][$k] = (int) $v;
651
+		}
621 652
 
622 653
 		// This is a logged in user, so definitely not a spider.
623 654
 		$user_info['possibly_robot'] = false;
@@ -631,8 +662,7 @@  discard block
 block discarded – undo
631 662
 			$time_system = new DateTime('now', $tz_system);
632 663
 			$time_user = new DateTime('now', $tz_user);
633 664
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
634
-		}
635
-		else
665
+		} else
636 666
 		{
637 667
 			// !!! Compatibility.
638 668
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -646,8 +676,9 @@  discard block
 block discarded – undo
646 676
 		$user_info = array('groups' => array(-1));
647 677
 		$user_settings = array();
648 678
 
649
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
650
-			$_COOKIE[$cookiename] = '';
679
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
680
+					$_COOKIE[$cookiename] = '';
681
+		}
651 682
 
652 683
 		// Expire the 2FA cookie
653 684
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -664,19 +695,20 @@  discard block
 block discarded – undo
664 695
 		}
665 696
 
666 697
 		// Create a login token if it doesn't exist yet.
667
-		if (!isset($_SESSION['token']['post-login']))
668
-			createToken('login');
669
-		else
670
-			list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
698
+		if (!isset($_SESSION['token']['post-login'])) {
699
+					createToken('login');
700
+		} else {
701
+					list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login'];
702
+		}
671 703
 
672 704
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
673 705
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
674 706
 		{
675 707
 			require_once($sourcedir . '/ManageSearchEngines.php');
676 708
 			$user_info['possibly_robot'] = SpiderCheck();
709
+		} elseif (!empty($modSettings['spider_mode'])) {
710
+					$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
677 711
 		}
678
-		elseif (!empty($modSettings['spider_mode']))
679
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
680 712
 		// If we haven't turned on proper spider hunts then have a guess!
681 713
 		else
682 714
 		{
@@ -724,8 +756,9 @@  discard block
 block discarded – undo
724 756
 	$user_info['groups'] = array_unique($user_info['groups']);
725 757
 
726 758
 	// 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.
727
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
728
-		unset($user_info['ignoreboards'][$tmp]);
759
+	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) {
760
+			unset($user_info['ignoreboards'][$tmp]);
761
+	}
729 762
 
730 763
 	// Allow the user to change their language.
731 764
 	if (!empty($modSettings['userLanguage']))
@@ -738,13 +771,14 @@  discard block
 block discarded – undo
738 771
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
739 772
 
740 773
 			// Make it permanent for members.
741
-			if (!empty($user_info['id']))
742
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
743
-			else
744
-				$_SESSION['language'] = $user_info['language'];
774
+			if (!empty($user_info['id'])) {
775
+							updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
776
+			} else {
777
+							$_SESSION['language'] = $user_info['language'];
778
+			}
779
+		} elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) {
780
+					$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
745 781
 		}
746
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
747
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
748 782
 	}
749 783
 
750 784
 	$temp = build_query_board($user_info['id']);
@@ -807,9 +841,9 @@  discard block
 block discarded – undo
807 841
 		}
808 842
 
809 843
 		// Remember redirection is the key to avoiding fallout from your bosses.
810
-		if (!empty($topic))
811
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
812
-		else
844
+		if (!empty($topic)) {
845
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
846
+		} else
813 847
 		{
814 848
 			loadPermissions();
815 849
 			loadTheme();
@@ -827,10 +861,11 @@  discard block
 block discarded – undo
827 861
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
828 862
 	{
829 863
 		// @todo SLOW?
830
-		if (!empty($topic))
831
-			$temp = cache_get_data('topic_board-' . $topic, 120);
832
-		else
833
-			$temp = cache_get_data('board-' . $board, 120);
864
+		if (!empty($topic)) {
865
+					$temp = cache_get_data('topic_board-' . $topic, 120);
866
+		} else {
867
+					$temp = cache_get_data('board-' . $board, 120);
868
+		}
834 869
 
835 870
 		if (!empty($temp))
836 871
 		{
@@ -868,8 +903,9 @@  discard block
 block discarded – undo
868 903
 			$row = $smcFunc['db_fetch_assoc']($request);
869 904
 
870 905
 			// Set the current board.
871
-			if (!empty($row['id_board']))
872
-				$board = $row['id_board'];
906
+			if (!empty($row['id_board'])) {
907
+							$board = $row['id_board'];
908
+			}
873 909
 
874 910
 			// Basic operating information. (globals... :/)
875 911
 			$board_info = array(
@@ -905,21 +941,23 @@  discard block
 block discarded – undo
905 941
 
906 942
 			do
907 943
 			{
908
-				if (!empty($row['id_moderator']))
909
-					$board_info['moderators'][$row['id_moderator']] = array(
944
+				if (!empty($row['id_moderator'])) {
945
+									$board_info['moderators'][$row['id_moderator']] = array(
910 946
 						'id' => $row['id_moderator'],
911 947
 						'name' => $row['real_name'],
912 948
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
913 949
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
914 950
 					);
951
+				}
915 952
 
916
-				if (!empty($row['id_moderator_group']))
917
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
953
+				if (!empty($row['id_moderator_group'])) {
954
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
918 955
 						'id' => $row['id_moderator_group'],
919 956
 						'name' => $row['group_name'],
920 957
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
921 958
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
922 959
 					);
960
+				}
923 961
 			}
924 962
 			while ($row = $smcFunc['db_fetch_assoc']($request));
925 963
 
@@ -951,12 +989,12 @@  discard block
 block discarded – undo
951 989
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
952 990
 			{
953 991
 				// @todo SLOW?
954
-				if (!empty($topic))
955
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
992
+				if (!empty($topic)) {
993
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
994
+				}
956 995
 				cache_put_data('board-' . $board, $board_info, 120);
957 996
 			}
958
-		}
959
-		else
997
+		} else
960 998
 		{
961 999
 			// Otherwise the topic is invalid, there are no moderators, etc.
962 1000
 			$board_info = array(
@@ -970,8 +1008,9 @@  discard block
 block discarded – undo
970 1008
 		$smcFunc['db_free_result']($request);
971 1009
 	}
972 1010
 
973
-	if (!empty($topic))
974
-		$_GET['board'] = (int) $board;
1011
+	if (!empty($topic)) {
1012
+			$_GET['board'] = (int) $board;
1013
+	}
975 1014
 
976 1015
 	if (!empty($board))
977 1016
 	{
@@ -981,10 +1020,12 @@  discard block
 block discarded – undo
981 1020
 		// Now check if the user is a moderator.
982 1021
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
983 1022
 
984
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
985
-			$board_info['error'] = 'access';
986
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
987
-			$board_info['error'] = 'access';
1023
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1024
+					$board_info['error'] = 'access';
1025
+		}
1026
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1027
+					$board_info['error'] = 'access';
1028
+		}
988 1029
 
989 1030
 		// Build up the linktree.
990 1031
 		$context['linktree'] = array_merge(
@@ -1007,8 +1048,9 @@  discard block
 block discarded – undo
1007 1048
 	$context['current_board'] = $board;
1008 1049
 
1009 1050
 	// No posting in redirection boards!
1010
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1011
-		$board_info['error'] == 'post_in_redirect';
1051
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1052
+			$board_info['error'] == 'post_in_redirect';
1053
+	}
1012 1054
 
1013 1055
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1014 1056
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1034,24 +1076,23 @@  discard block
 block discarded – undo
1034 1076
 			ob_end_clean();
1035 1077
 			header('HTTP/1.1 403 Forbidden');
1036 1078
 			die;
1037
-		}
1038
-		elseif ($board_info['error'] == 'post_in_redirect')
1079
+		} elseif ($board_info['error'] == 'post_in_redirect')
1039 1080
 		{
1040 1081
 			// Slightly different error message here...
1041 1082
 			fatal_lang_error('cannot_post_redirect', false);
1042
-		}
1043
-		elseif ($user_info['is_guest'])
1083
+		} elseif ($user_info['is_guest'])
1044 1084
 		{
1045 1085
 			loadLanguage('Errors');
1046 1086
 			is_not_guest($txt['topic_gone']);
1087
+		} else {
1088
+					fatal_lang_error('topic_gone', false);
1047 1089
 		}
1048
-		else
1049
-			fatal_lang_error('topic_gone', false);
1050 1090
 	}
1051 1091
 
1052
-	if ($user_info['is_mod'])
1053
-		$user_info['groups'][] = 3;
1054
-}
1092
+	if ($user_info['is_mod']) {
1093
+			$user_info['groups'][] = 3;
1094
+	}
1095
+	}
1055 1096
 
1056 1097
 /**
1057 1098
  * Load this user's permissions.
@@ -1072,8 +1113,9 @@  discard block
 block discarded – undo
1072 1113
 		asort($cache_groups);
1073 1114
 		$cache_groups = implode(',', $cache_groups);
1074 1115
 		// If it's a spider then cache it different.
1075
-		if ($user_info['possibly_robot'])
1076
-			$cache_groups .= '-spider';
1116
+		if ($user_info['possibly_robot']) {
1117
+					$cache_groups .= '-spider';
1118
+		}
1077 1119
 
1078 1120
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1079 1121
 		{
@@ -1081,9 +1123,9 @@  discard block
 block discarded – undo
1081 1123
 			banPermissions();
1082 1124
 
1083 1125
 			return;
1126
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1127
+					list ($user_info['permissions'], $removals) = $temp;
1084 1128
 		}
1085
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1086
-			list ($user_info['permissions'], $removals) = $temp;
1087 1129
 	}
1088 1130
 
1089 1131
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1105,23 +1147,26 @@  discard block
 block discarded – undo
1105 1147
 		$removals = array();
1106 1148
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1107 1149
 		{
1108
-			if (empty($row['add_deny']))
1109
-				$removals[] = $row['permission'];
1110
-			else
1111
-				$user_info['permissions'][] = $row['permission'];
1150
+			if (empty($row['add_deny'])) {
1151
+							$removals[] = $row['permission'];
1152
+			} else {
1153
+							$user_info['permissions'][] = $row['permission'];
1154
+			}
1112 1155
 		}
1113 1156
 		$smcFunc['db_free_result']($request);
1114 1157
 
1115
-		if (isset($cache_groups))
1116
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1158
+		if (isset($cache_groups)) {
1159
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1160
+		}
1117 1161
 	}
1118 1162
 
1119 1163
 	// Get the board permissions.
1120 1164
 	if (!empty($board))
1121 1165
 	{
1122 1166
 		// Make sure the board (if any) has been loaded by loadBoard().
1123
-		if (!isset($board_info['profile']))
1124
-			fatal_lang_error('no_board');
1167
+		if (!isset($board_info['profile'])) {
1168
+					fatal_lang_error('no_board');
1169
+		}
1125 1170
 
1126 1171
 		$request = $smcFunc['db_query']('', '
1127 1172
 			SELECT permission, add_deny
@@ -1137,20 +1182,23 @@  discard block
 block discarded – undo
1137 1182
 		);
1138 1183
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1139 1184
 		{
1140
-			if (empty($row['add_deny']))
1141
-				$removals[] = $row['permission'];
1142
-			else
1143
-				$user_info['permissions'][] = $row['permission'];
1185
+			if (empty($row['add_deny'])) {
1186
+							$removals[] = $row['permission'];
1187
+			} else {
1188
+							$user_info['permissions'][] = $row['permission'];
1189
+			}
1144 1190
 		}
1145 1191
 		$smcFunc['db_free_result']($request);
1146 1192
 	}
1147 1193
 
1148 1194
 	// Remove all the permissions they shouldn't have ;).
1149
-	if (!empty($modSettings['permission_enable_deny']))
1150
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1195
+	if (!empty($modSettings['permission_enable_deny'])) {
1196
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1197
+	}
1151 1198
 
1152
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1153
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1199
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1200
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1201
+	}
1154 1202
 
1155 1203
 	// Banned?  Watch, don't touch..
1156 1204
 	banPermissions();
@@ -1162,17 +1210,18 @@  discard block
 block discarded – undo
1162 1210
 		{
1163 1211
 			require_once($sourcedir . '/Subs-Auth.php');
1164 1212
 			rebuildModCache();
1213
+		} else {
1214
+					$user_info['mod_cache'] = $_SESSION['mc'];
1165 1215
 		}
1166
-		else
1167
-			$user_info['mod_cache'] = $_SESSION['mc'];
1168 1216
 
1169 1217
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1170 1218
 		// For example this drastically simplifies certain changes to the profile area.
1171 1219
 		$user_info['permissions'][] = 'is_not_guest';
1172 1220
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1173 1221
 		$user_info['permissions'][] = 'profile_view_own';
1174
-		if (in_array('profile_view', $user_info['permissions']))
1175
-			$user_info['permissions'][] = 'profile_view_any';
1222
+		if (in_array('profile_view', $user_info['permissions'])) {
1223
+					$user_info['permissions'][] = 'profile_view_any';
1224
+		}
1176 1225
 	}
1177 1226
 }
1178 1227
 
@@ -1190,8 +1239,9 @@  discard block
 block discarded – undo
1190 1239
 	global $image_proxy_enabled, $image_proxy_secret, $boardurl;
1191 1240
 
1192 1241
 	// Can't just look for no users :P.
1193
-	if (empty($users))
1194
-		return array();
1242
+	if (empty($users)) {
1243
+			return array();
1244
+	}
1195 1245
 
1196 1246
 	// Pass the set value
1197 1247
 	$context['loadMemberContext_set'] = $set;
@@ -1206,8 +1256,9 @@  discard block
 block discarded – undo
1206 1256
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1207 1257
 		{
1208 1258
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1209
-			if ($data == null)
1210
-				continue;
1259
+			if ($data == null) {
1260
+							continue;
1261
+			}
1211 1262
 
1212 1263
 			$loaded_ids[] = $data['id_member'];
1213 1264
 			$user_profile[$data['id_member']] = $data;
@@ -1274,16 +1325,19 @@  discard block
 block discarded – undo
1274 1325
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1275 1326
 
1276 1327
 			// Take care of proxying avatar if required, do this here for maximum reach
1277
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1278
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1328
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1329
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1330
+			}
1279 1331
 
1280 1332
 			// Keep track of the member's normal member group
1281 1333
 			$row['primary_group'] = $row['member_group'];
1282 1334
 
1283
-			if (isset($row['member_ip']))
1284
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1285
-			if (isset($row['member_ip2']))
1286
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1335
+			if (isset($row['member_ip'])) {
1336
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1337
+			}
1338
+			if (isset($row['member_ip2'])) {
1339
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1340
+			}
1287 1341
 			$new_loaded_ids[] = $row['id_member'];
1288 1342
 			$loaded_ids[] = $row['id_member'];
1289 1343
 			$row['options'] = array();
@@ -1302,8 +1356,9 @@  discard block
 block discarded – undo
1302 1356
 				'loaded_ids' => $new_loaded_ids,
1303 1357
 			)
1304 1358
 		);
1305
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1306
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1359
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1360
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1361
+		}
1307 1362
 		$smcFunc['db_free_result']($request);
1308 1363
 	}
1309 1364
 
@@ -1314,10 +1369,11 @@  discard block
 block discarded – undo
1314 1369
 	{
1315 1370
 		foreach ($loaded_ids as $a_member)
1316 1371
 		{
1317
-			if (!empty($user_profile[$a_member]['additional_groups']))
1318
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1319
-			else
1320
-				$groups = array($user_profile[$a_member]['id_group']);
1372
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1373
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1374
+			} else {
1375
+							$groups = array($user_profile[$a_member]['id_group']);
1376
+			}
1321 1377
 
1322 1378
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1323 1379
 
@@ -1330,8 +1386,9 @@  discard block
 block discarded – undo
1330 1386
 
1331 1387
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1332 1388
 	{
1333
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1334
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1389
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1390
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1391
+		}
1335 1392
 	}
1336 1393
 
1337 1394
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1357,14 +1414,17 @@  discard block
 block discarded – undo
1357 1414
 		foreach ($temp_mods as $id)
1358 1415
 		{
1359 1416
 			// By popular demand, don't show admins or global moderators as moderators.
1360
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1361
-				$user_profile[$id]['member_group'] = $row['member_group'];
1417
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1418
+							$user_profile[$id]['member_group'] = $row['member_group'];
1419
+			}
1362 1420
 
1363 1421
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1364
-			if (!empty($row['icons']))
1365
-				$user_profile[$id]['icons'] = $row['icons'];
1366
-			if (!empty($row['member_group_color']))
1367
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1422
+			if (!empty($row['icons'])) {
1423
+							$user_profile[$id]['icons'] = $row['icons'];
1424
+			}
1425
+			if (!empty($row['member_group_color'])) {
1426
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1427
+			}
1368 1428
 		}
1369 1429
 	}
1370 1430
 
@@ -1386,12 +1446,14 @@  discard block
 block discarded – undo
1386 1446
 	static $loadedLanguages = array();
1387 1447
 
1388 1448
 	// If this person's data is already loaded, skip it.
1389
-	if (isset($dataLoaded[$user]))
1390
-		return true;
1449
+	if (isset($dataLoaded[$user])) {
1450
+			return true;
1451
+	}
1391 1452
 
1392 1453
 	// We can't load guests or members not loaded by loadMemberData()!
1393
-	if ($user == 0)
1394
-		return false;
1454
+	if ($user == 0) {
1455
+			return false;
1456
+	}
1395 1457
 	if (!isset($user_profile[$user]))
1396 1458
 	{
1397 1459
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1417,12 +1479,16 @@  discard block
 block discarded – undo
1417 1479
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1418 1480
 
1419 1481
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1420
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1482
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1483
+		//icon is set and exists
1421 1484
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1422
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1485
+	} elseif (isset($profile['icons'][1])) {
1486
+		//icon is set and doesn't exist, fallback to default
1423 1487
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1424
-	else //not set, bye bye
1488
+	} else {
1489
+		//not set, bye bye
1425 1490
 		$group_icon_url = '';
1491
+	}
1426 1492
 
1427 1493
 	// These minimal values are always loaded
1428 1494
 	$memberContext[$user] = array(
@@ -1441,8 +1507,9 @@  discard block
 block discarded – undo
1441 1507
 	if ($context['loadMemberContext_set'] != 'minimal')
1442 1508
 	{
1443 1509
 		// Go the extra mile and load the user's native language name.
1444
-		if (empty($loadedLanguages))
1445
-			$loadedLanguages = getLanguages();
1510
+		if (empty($loadedLanguages)) {
1511
+					$loadedLanguages = getLanguages();
1512
+		}
1446 1513
 
1447 1514
 		$memberContext[$user] += array(
1448 1515
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1497,31 +1564,33 @@  discard block
 block discarded – undo
1497 1564
 	{
1498 1565
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1499 1566
 		{
1500
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1501
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1502
-			else
1503
-				$image = get_gravatar_url($profile['email_address']);
1504
-		}
1505
-		else
1567
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1568
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1569
+			} else {
1570
+							$image = get_gravatar_url($profile['email_address']);
1571
+			}
1572
+		} else
1506 1573
 		{
1507 1574
 			// So it's stored in the member table?
1508 1575
 			if (!empty($profile['avatar']))
1509 1576
 			{
1510 1577
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1578
+			} elseif (!empty($profile['filename'])) {
1579
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1511 1580
 			}
1512
-			elseif (!empty($profile['filename']))
1513
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1514 1581
 			// Right... no avatar...use the default one
1515
-			else
1516
-				$image = $modSettings['avatar_url'] . '/default.png';
1582
+			else {
1583
+							$image = $modSettings['avatar_url'] . '/default.png';
1584
+			}
1517 1585
 		}
1518
-		if (!empty($image))
1519
-			$memberContext[$user]['avatar'] = array(
1586
+		if (!empty($image)) {
1587
+					$memberContext[$user]['avatar'] = array(
1520 1588
 				'name' => $profile['avatar'],
1521 1589
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1522 1590
 				'href' => $image,
1523 1591
 				'url' => $image,
1524 1592
 			);
1593
+		}
1525 1594
 	}
1526 1595
 
1527 1596
 	// Are we also loading the members custom fields into context?
@@ -1529,35 +1598,41 @@  discard block
 block discarded – undo
1529 1598
 	{
1530 1599
 		$memberContext[$user]['custom_fields'] = array();
1531 1600
 
1532
-		if (!isset($context['display_fields']))
1533
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1601
+		if (!isset($context['display_fields'])) {
1602
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1603
+		}
1534 1604
 
1535 1605
 		foreach ($context['display_fields'] as $custom)
1536 1606
 		{
1537
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1538
-				continue;
1607
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1608
+							continue;
1609
+			}
1539 1610
 
1540 1611
 			$value = $profile['options'][$custom['col_name']];
1541 1612
 
1542 1613
 			// Don't show the "disabled" option for the "gender" field.
1543
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1544
-				continue;
1614
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1615
+							continue;
1616
+			}
1545 1617
 
1546 1618
 			// BBC?
1547
-			if ($custom['bbc'])
1548
-				$value = parse_bbc($value);
1619
+			if ($custom['bbc']) {
1620
+							$value = parse_bbc($value);
1621
+			}
1549 1622
 			// ... or checkbox?
1550
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1551
-				$value = $value ? $txt['yes'] : $txt['no'];
1623
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1624
+							$value = $value ? $txt['yes'] : $txt['no'];
1625
+			}
1552 1626
 
1553 1627
 			// Enclosing the user input within some other text?
1554
-			if (!empty($custom['enclose']))
1555
-				$value = strtr($custom['enclose'], array(
1628
+			if (!empty($custom['enclose'])) {
1629
+							$value = strtr($custom['enclose'], array(
1556 1630
 					'{SCRIPTURL}' => $scripturl,
1557 1631
 					'{IMAGES_URL}' => $settings['images_url'],
1558 1632
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1559 1633
 					'{INPUT}' => $value,
1560 1634
 				));
1635
+			}
1561 1636
 
1562 1637
 			$memberContext[$user]['custom_fields'][] = array(
1563 1638
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1584,8 +1659,9 @@  discard block
 block discarded – undo
1584 1659
 	global $smcFunc, $txt, $scripturl, $settings;
1585 1660
 
1586 1661
 	// Do not waste my time...
1587
-	if (empty($users) || empty($params))
1588
-		return false;
1662
+	if (empty($users) || empty($params)) {
1663
+			return false;
1664
+	}
1589 1665
 
1590 1666
 	// Make sure it's an array.
1591 1667
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1609,31 +1685,36 @@  discard block
 block discarded – undo
1609 1685
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1610 1686
 	{
1611 1687
 		// BBC?
1612
-		if (!empty($row['bbc']))
1613
-			$row['value'] = parse_bbc($row['value']);
1688
+		if (!empty($row['bbc'])) {
1689
+					$row['value'] = parse_bbc($row['value']);
1690
+		}
1614 1691
 
1615 1692
 		// ... or checkbox?
1616
-		elseif (isset($row['type']) && $row['type'] == 'check')
1617
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1693
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1694
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1695
+		}
1618 1696
 
1619 1697
 		// Enclosing the user input within some other text?
1620
-		if (!empty($row['enclose']))
1621
-			$row['value'] = strtr($row['enclose'], array(
1698
+		if (!empty($row['enclose'])) {
1699
+					$row['value'] = strtr($row['enclose'], array(
1622 1700
 				'{SCRIPTURL}' => $scripturl,
1623 1701
 				'{IMAGES_URL}' => $settings['images_url'],
1624 1702
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1625 1703
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1626 1704
 			));
1705
+		}
1627 1706
 
1628 1707
 		// Send a simple array if there is just 1 param
1629
-		if (count($params) == 1)
1630
-			$return[$row['id_member']] = $row;
1708
+		if (count($params) == 1) {
1709
+					$return[$row['id_member']] = $row;
1710
+		}
1631 1711
 
1632 1712
 		// More than 1? knock yourself out...
1633 1713
 		else
1634 1714
 		{
1635
-			if (!isset($return[$row['id_member']]))
1636
-				$return[$row['id_member']] = array();
1715
+			if (!isset($return[$row['id_member']])) {
1716
+							$return[$row['id_member']] = array();
1717
+			}
1637 1718
 
1638 1719
 			$return[$row['id_member']][$row['variable']] = $row;
1639 1720
 		}
@@ -1667,8 +1748,9 @@  discard block
 block discarded – undo
1667 1748
 	global $context;
1668 1749
 
1669 1750
 	// Don't know any browser!
1670
-	if (empty($context['browser']))
1671
-		detectBrowser();
1751
+	if (empty($context['browser'])) {
1752
+			detectBrowser();
1753
+	}
1672 1754
 
1673 1755
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1674 1756
 }
@@ -1686,8 +1768,9 @@  discard block
 block discarded – undo
1686 1768
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1687 1769
 
1688 1770
 	// The theme was specified by parameter.
1689
-	if (!empty($id_theme))
1690
-		$id_theme = (int) $id_theme;
1771
+	if (!empty($id_theme)) {
1772
+			$id_theme = (int) $id_theme;
1773
+	}
1691 1774
 	// The theme was specified by REQUEST.
1692 1775
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1693 1776
 	{
@@ -1695,54 +1778,61 @@  discard block
 block discarded – undo
1695 1778
 		$_SESSION['id_theme'] = $id_theme;
1696 1779
 	}
1697 1780
 	// The theme was specified by REQUEST... previously.
1698
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1699
-		$id_theme = (int) $_SESSION['id_theme'];
1781
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1782
+			$id_theme = (int) $_SESSION['id_theme'];
1783
+	}
1700 1784
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1701
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1702
-		$id_theme = $user_info['theme'];
1785
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1786
+			$id_theme = $user_info['theme'];
1787
+	}
1703 1788
 	// The theme was specified by the board.
1704
-	elseif (!empty($board_info['theme']))
1705
-		$id_theme = $board_info['theme'];
1789
+	elseif (!empty($board_info['theme'])) {
1790
+			$id_theme = $board_info['theme'];
1791
+	}
1706 1792
 	// The theme is the forum's default.
1707
-	else
1708
-		$id_theme = $modSettings['theme_guests'];
1793
+	else {
1794
+			$id_theme = $modSettings['theme_guests'];
1795
+	}
1709 1796
 
1710 1797
 	// We already load the basic stuff?
1711 1798
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1712 1799
 	{
1713 1800
 		// Verify the id_theme... no foul play.
1714 1801
 		// Always allow the board specific theme, if they are overriding.
1715
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1716
-			$id_theme = $board_info['theme'];
1802
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1803
+					$id_theme = $board_info['theme'];
1804
+		}
1717 1805
 		// If they have specified a particular theme to use with SSI allow it to be used.
1718
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1719
-			$id_theme = (int) $id_theme;
1720
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1806
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1807
+					$id_theme = (int) $id_theme;
1808
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1721 1809
 		{
1722 1810
 			$themes = explode(',', $modSettings['enableThemes']);
1723
-			if (!in_array($id_theme, $themes))
1724
-				$id_theme = $modSettings['theme_guests'];
1725
-			else
1726
-				$id_theme = (int) $id_theme;
1811
+			if (!in_array($id_theme, $themes)) {
1812
+							$id_theme = $modSettings['theme_guests'];
1813
+			} else {
1814
+							$id_theme = (int) $id_theme;
1815
+			}
1816
+		} else {
1817
+					$id_theme = (int) $id_theme;
1727 1818
 		}
1728
-		else
1729
-			$id_theme = (int) $id_theme;
1730 1819
 
1731 1820
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1732 1821
 
1733 1822
 		// Disable image proxy if we don't have SSL enabled
1734
-		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1735
-			$image_proxy_enabled = false;
1823
+		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1824
+					$image_proxy_enabled = false;
1825
+		}
1736 1826
 
1737 1827
 		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'])
1738 1828
 		{
1739 1829
 			$themeData = $temp;
1740 1830
 			$flag = true;
1831
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1832
+					$themeData = $temp + array($member => array());
1833
+		} else {
1834
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1741 1835
 		}
1742
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1743
-			$themeData = $temp + array($member => array());
1744
-		else
1745
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1746 1836
 
1747 1837
 		if (empty($flag))
1748 1838
 		{
@@ -1761,31 +1851,37 @@  discard block
 block discarded – undo
1761 1851
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1762 1852
 			{
1763 1853
 				// There are just things we shouldn't be able to change as members.
1764
-				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')))
1765
-					continue;
1854
+				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'))) {
1855
+									continue;
1856
+				}
1766 1857
 
1767 1858
 				// If this is the theme_dir of the default theme, store it.
1768
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1769
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1859
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1860
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1861
+				}
1770 1862
 
1771 1863
 				// If this isn't set yet, is a theme option, or is not the default theme..
1772
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1773
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1864
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1865
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1866
+				}
1774 1867
 			}
1775 1868
 			$smcFunc['db_free_result']($result);
1776 1869
 
1777
-			if (!empty($themeData[-1]))
1778
-				foreach ($themeData[-1] as $k => $v)
1870
+			if (!empty($themeData[-1])) {
1871
+							foreach ($themeData[-1] as $k => $v)
1779 1872
 				{
1780 1873
 					if (!isset($themeData[$member][$k]))
1781 1874
 						$themeData[$member][$k] = $v;
1875
+			}
1782 1876
 				}
1783 1877
 
1784
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1785
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1878
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1879
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1880
+			}
1786 1881
 			// Only if we didn't already load that part of the cache...
1787
-			elseif (!isset($temp))
1788
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1882
+			elseif (!isset($temp)) {
1883
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1884
+			}
1789 1885
 		}
1790 1886
 
1791 1887
 		$settings = $themeData[0];
@@ -1802,22 +1898,26 @@  discard block
 block discarded – undo
1802 1898
 		$settings['template_dirs'][] = $settings['theme_dir'];
1803 1899
 
1804 1900
 		// Based on theme (if there is one).
1805
-		if (!empty($settings['base_theme_dir']))
1806
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1901
+		if (!empty($settings['base_theme_dir'])) {
1902
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1903
+		}
1807 1904
 
1808 1905
 		// Lastly the default theme.
1809
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1810
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1906
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1907
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1908
+		}
1811 1909
 	}
1812 1910
 
1813 1911
 
1814
-	if (!$initialize)
1815
-		return;
1912
+	if (!$initialize) {
1913
+			return;
1914
+	}
1816 1915
 
1817 1916
 	// Check to see if we're forcing SSL
1818 1917
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1819
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1820
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1918
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1919
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1920
+	}
1821 1921
 
1822 1922
 	// Check to see if they're accessing it from the wrong place.
1823 1923
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1825,8 +1925,9 @@  discard block
 block discarded – undo
1825 1925
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1826 1926
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1827 1927
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1828
-		if ($temp != '/')
1829
-			$detected_url .= $temp;
1928
+		if ($temp != '/') {
1929
+					$detected_url .= $temp;
1930
+		}
1830 1931
 	}
1831 1932
 	if (isset($detected_url) && $detected_url != $boardurl)
1832 1933
 	{
@@ -1838,8 +1939,9 @@  discard block
 block discarded – undo
1838 1939
 			foreach ($aliases as $alias)
1839 1940
 			{
1840 1941
 				// Rip off all the boring parts, spaces, etc.
1841
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1842
-					$do_fix = true;
1942
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1943
+									$do_fix = true;
1944
+				}
1843 1945
 			}
1844 1946
 		}
1845 1947
 
@@ -1847,20 +1949,22 @@  discard block
 block discarded – undo
1847 1949
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1848 1950
 		{
1849 1951
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1850
-			if (empty($_GET))
1851
-				redirectexit('wwwRedirect');
1852
-			else
1952
+			if (empty($_GET)) {
1953
+							redirectexit('wwwRedirect');
1954
+			} else
1853 1955
 			{
1854 1956
 				list ($k, $v) = each($_GET);
1855 1957
 
1856
-				if ($k != 'wwwRedirect')
1857
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1958
+				if ($k != 'wwwRedirect') {
1959
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1960
+				}
1858 1961
 			}
1859 1962
 		}
1860 1963
 
1861 1964
 		// #3 is just a check for SSL...
1862
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1863
-			$do_fix = true;
1965
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1966
+					$do_fix = true;
1967
+		}
1864 1968
 
1865 1969
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1866 1970
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1895,8 +1999,9 @@  discard block
 block discarded – undo
1895 1999
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1896 2000
 				}
1897 2001
 			}
1898
-			foreach ($context['linktree'] as $k => $dummy)
1899
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2002
+			foreach ($context['linktree'] as $k => $dummy) {
2003
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2004
+			}
1900 2005
 		}
1901 2006
 	}
1902 2007
 	// Set up the contextual user array.
@@ -1915,16 +2020,16 @@  discard block
 block discarded – undo
1915 2020
 			'email' => $user_info['email'],
1916 2021
 			'ignoreusers' => $user_info['ignoreusers'],
1917 2022
 		);
1918
-		if (!$context['user']['is_guest'])
1919
-			$context['user']['name'] = $user_info['name'];
1920
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1921
-			$context['user']['name'] = $txt['guest_title'];
2023
+		if (!$context['user']['is_guest']) {
2024
+					$context['user']['name'] = $user_info['name'];
2025
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2026
+					$context['user']['name'] = $txt['guest_title'];
2027
+		}
1922 2028
 
1923 2029
 		// Determine the current smiley set.
1924 2030
 		$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'];
1925 2031
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1926
-	}
1927
-	else
2032
+	} else
1928 2033
 	{
1929 2034
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1930 2035
 		$context['user'] = array(
@@ -1958,18 +2063,24 @@  discard block
 block discarded – undo
1958 2063
 	}
1959 2064
 
1960 2065
 	// Some basic information...
1961
-	if (!isset($context['html_headers']))
1962
-		$context['html_headers'] = '';
1963
-	if (!isset($context['javascript_files']))
1964
-		$context['javascript_files'] = array();
1965
-	if (!isset($context['css_files']))
1966
-		$context['css_files'] = array();
1967
-	if (!isset($context['css_header']))
1968
-		$context['css_header'] = array();
1969
-	if (!isset($context['javascript_inline']))
1970
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1971
-	if (!isset($context['javascript_vars']))
1972
-		$context['javascript_vars'] = array();
2066
+	if (!isset($context['html_headers'])) {
2067
+			$context['html_headers'] = '';
2068
+	}
2069
+	if (!isset($context['javascript_files'])) {
2070
+			$context['javascript_files'] = array();
2071
+	}
2072
+	if (!isset($context['css_files'])) {
2073
+			$context['css_files'] = array();
2074
+	}
2075
+	if (!isset($context['css_header'])) {
2076
+			$context['css_header'] = array();
2077
+	}
2078
+	if (!isset($context['javascript_inline'])) {
2079
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2080
+	}
2081
+	if (!isset($context['javascript_vars'])) {
2082
+			$context['javascript_vars'] = array();
2083
+	}
1973 2084
 
1974 2085
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1975 2086
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1981,16 +2092,18 @@  discard block
 block discarded – undo
1981 2092
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1982 2093
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1983 2094
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1984
-	if (isset($modSettings['load_average']))
1985
-		$context['load_average'] = $modSettings['load_average'];
2095
+	if (isset($modSettings['load_average'])) {
2096
+			$context['load_average'] = $modSettings['load_average'];
2097
+	}
1986 2098
 
1987 2099
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1988 2100
 	detectBrowser();
1989 2101
 
1990 2102
 	// Set the top level linktree up.
1991 2103
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
1992
-	if (empty($context['linktree']))
1993
-		$context['linktree'] = array();
2104
+	if (empty($context['linktree'])) {
2105
+			$context['linktree'] = array();
2106
+	}
1994 2107
 	array_unshift($context['linktree'], array(
1995 2108
 		'url' => $scripturl,
1996 2109
 		'name' => $context['forum_name_html_safe']
@@ -1999,8 +2112,9 @@  discard block
 block discarded – undo
1999 2112
 	// This allows sticking some HTML on the page output - useful for controls.
2000 2113
 	$context['insert_after_template'] = '';
2001 2114
 
2002
-	if (!isset($txt))
2003
-		$txt = array();
2115
+	if (!isset($txt)) {
2116
+			$txt = array();
2117
+	}
2004 2118
 
2005 2119
 	$simpleActions = array(
2006 2120
 		'findmember',
@@ -2046,9 +2160,10 @@  discard block
 block discarded – undo
2046 2160
 
2047 2161
 	// See if theres any extra param to check.
2048 2162
 	$requiresXML = false;
2049
-	foreach ($extraParams as $key => $extra)
2050
-		if (isset($_REQUEST[$extra]))
2163
+	foreach ($extraParams as $key => $extra) {
2164
+			if (isset($_REQUEST[$extra]))
2051 2165
 			$requiresXML = true;
2166
+	}
2052 2167
 
2053 2168
 	// Output is fully XML, so no need for the index template.
2054 2169
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2063,37 +2178,39 @@  discard block
 block discarded – undo
2063 2178
 	{
2064 2179
 		loadLanguage('index+Modifications');
2065 2180
 		$context['template_layers'] = array();
2066
-	}
2067
-
2068
-	else
2181
+	} else
2069 2182
 	{
2070 2183
 		// Custom templates to load, or just default?
2071
-		if (isset($settings['theme_templates']))
2072
-			$templates = explode(',', $settings['theme_templates']);
2073
-		else
2074
-			$templates = array('index');
2184
+		if (isset($settings['theme_templates'])) {
2185
+					$templates = explode(',', $settings['theme_templates']);
2186
+		} else {
2187
+					$templates = array('index');
2188
+		}
2075 2189
 
2076 2190
 		// Load each template...
2077
-		foreach ($templates as $template)
2078
-			loadTemplate($template);
2191
+		foreach ($templates as $template) {
2192
+					loadTemplate($template);
2193
+		}
2079 2194
 
2080 2195
 		// ...and attempt to load their associated language files.
2081 2196
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2082 2197
 		loadLanguage($required_files, '', false);
2083 2198
 
2084 2199
 		// Custom template layers?
2085
-		if (isset($settings['theme_layers']))
2086
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2087
-		else
2088
-			$context['template_layers'] = array('html', 'body');
2200
+		if (isset($settings['theme_layers'])) {
2201
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2202
+		} else {
2203
+					$context['template_layers'] = array('html', 'body');
2204
+		}
2089 2205
 	}
2090 2206
 
2091 2207
 	// Initialize the theme.
2092 2208
 	loadSubTemplate('init', 'ignore');
2093 2209
 
2094 2210
 	// Allow overriding the board wide time/number formats.
2095
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2096
-		$user_info['time_format'] = $txt['time_format'];
2211
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2212
+			$user_info['time_format'] = $txt['time_format'];
2213
+	}
2097 2214
 
2098 2215
 	// Set the character set from the template.
2099 2216
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2101,12 +2218,14 @@  discard block
 block discarded – undo
2101 2218
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2102 2219
 
2103 2220
 	// Guests may still need a name.
2104
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2105
-		$context['user']['name'] = $txt['guest_title'];
2221
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2222
+			$context['user']['name'] = $txt['guest_title'];
2223
+	}
2106 2224
 
2107 2225
 	// Any theme-related strings that need to be loaded?
2108
-	if (!empty($settings['require_theme_strings']))
2109
-		loadLanguage('ThemeStrings', '', false);
2226
+	if (!empty($settings['require_theme_strings'])) {
2227
+			loadLanguage('ThemeStrings', '', false);
2228
+	}
2110 2229
 
2111 2230
 	// Make a special URL for the language.
2112 2231
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2117,8 +2236,9 @@  discard block
 block discarded – undo
2117 2236
 	// Here is my luvly Responsive CSS
2118 2237
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2119 2238
 
2120
-	if ($context['right_to_left'])
2121
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2239
+	if ($context['right_to_left']) {
2240
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2241
+	}
2122 2242
 
2123 2243
 	// We allow theme variants, because we're cool.
2124 2244
 	$context['theme_variant'] = '';
@@ -2126,14 +2246,17 @@  discard block
 block discarded – undo
2126 2246
 	if (!empty($settings['theme_variants']))
2127 2247
 	{
2128 2248
 		// Overriding - for previews and that ilk.
2129
-		if (!empty($_REQUEST['variant']))
2130
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2249
+		if (!empty($_REQUEST['variant'])) {
2250
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2251
+		}
2131 2252
 		// User selection?
2132
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2133
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2253
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2254
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2255
+		}
2134 2256
 		// If not a user variant, select the default.
2135
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2136
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2257
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2258
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2259
+		}
2137 2260
 
2138 2261
 		// Do this to keep things easier in the templates.
2139 2262
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2142,20 +2265,23 @@  discard block
 block discarded – undo
2142 2265
 		if (!empty($context['theme_variant']))
2143 2266
 		{
2144 2267
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2145
-			if ($context['right_to_left'])
2146
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2268
+			if ($context['right_to_left']) {
2269
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2270
+			}
2147 2271
 		}
2148 2272
 	}
2149 2273
 
2150 2274
 	// Let's be compatible with old themes!
2151
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2152
-		$context['template_layers'] = array('main');
2275
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2276
+			$context['template_layers'] = array('main');
2277
+	}
2153 2278
 
2154 2279
 	$context['tabindex'] = 1;
2155 2280
 
2156 2281
 	// Compatibility.
2157
-	if (!isset($settings['theme_version']))
2158
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2282
+	if (!isset($settings['theme_version'])) {
2283
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2284
+	}
2159 2285
 
2160 2286
 	// Default JS variables for use in every theme
2161 2287
 	$context['javascript_vars'] = array(
@@ -2174,18 +2300,18 @@  discard block
 block discarded – undo
2174 2300
 	);
2175 2301
 
2176 2302
 	// Add the JQuery library to the list of files to load.
2177
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2178
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2179
-
2180
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2181
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2182
-
2183
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2184
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2303
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2304
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2305
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2306
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2307
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2308
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2309
+	}
2185 2310
 
2186 2311
 	// Auto loading? template_javascript() will take care of the local half of this.
2187
-	else
2188
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2312
+	else {
2313
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2314
+	}
2189 2315
 
2190 2316
 	// Queue our JQuery plugins!
2191 2317
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2208,12 +2334,12 @@  discard block
 block discarded – undo
2208 2334
 			require_once($sourcedir . '/ScheduledTasks.php');
2209 2335
 
2210 2336
 			// What to do, what to do?!
2211
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2212
-				AutoTask();
2213
-			else
2214
-				ReduceMailQueue();
2215
-		}
2216
-		else
2337
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2338
+							AutoTask();
2339
+			} else {
2340
+							ReduceMailQueue();
2341
+			}
2342
+		} else
2217 2343
 		{
2218 2344
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2219 2345
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2264,8 +2390,9 @@  discard block
 block discarded – undo
2264 2390
 		foreach ($theme_includes as $include)
2265 2391
 		{
2266 2392
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2267
-			if (file_exists($include))
2268
-				require_once($include);
2393
+			if (file_exists($include)) {
2394
+							require_once($include);
2395
+			}
2269 2396
 		}
2270 2397
 	}
2271 2398
 
@@ -2295,16 +2422,19 @@  discard block
 block discarded – undo
2295 2422
 	// Do any style sheets first, cause we're easy with those.
2296 2423
 	if (!empty($style_sheets))
2297 2424
 	{
2298
-		if (!is_array($style_sheets))
2299
-			$style_sheets = array($style_sheets);
2425
+		if (!is_array($style_sheets)) {
2426
+					$style_sheets = array($style_sheets);
2427
+		}
2300 2428
 
2301
-		foreach ($style_sheets as $sheet)
2302
-			loadCSSFile($sheet . '.css', array(), $sheet);
2429
+		foreach ($style_sheets as $sheet) {
2430
+					loadCSSFile($sheet . '.css', array(), $sheet);
2431
+		}
2303 2432
 	}
2304 2433
 
2305 2434
 	// No template to load?
2306
-	if ($template_name === false)
2307
-		return true;
2435
+	if ($template_name === false) {
2436
+			return true;
2437
+	}
2308 2438
 
2309 2439
 	$loaded = false;
2310 2440
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2319,12 +2449,14 @@  discard block
 block discarded – undo
2319 2449
 
2320 2450
 	if ($loaded)
2321 2451
 	{
2322
-		if ($db_show_debug === true)
2323
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2452
+		if ($db_show_debug === true) {
2453
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2454
+		}
2324 2455
 
2325 2456
 		// If they have specified an initialization function for this template, go ahead and call it now.
2326
-		if (function_exists('template_' . $template_name . '_init'))
2327
-			call_user_func('template_' . $template_name . '_init');
2457
+		if (function_exists('template_' . $template_name . '_init')) {
2458
+					call_user_func('template_' . $template_name . '_init');
2459
+		}
2328 2460
 	}
2329 2461
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2330 2462
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2344,13 +2476,14 @@  discard block
 block discarded – undo
2344 2476
 		loadTemplate($template_name);
2345 2477
 	}
2346 2478
 	// Cause an error otherwise.
2347
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2348
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2349
-	elseif ($fatal)
2350
-		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'));
2351
-	else
2352
-		return false;
2353
-}
2479
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2480
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2481
+	} elseif ($fatal) {
2482
+			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'));
2483
+	} else {
2484
+			return false;
2485
+	}
2486
+	}
2354 2487
 
2355 2488
 /**
2356 2489
  * Load a sub-template.
@@ -2368,17 +2501,19 @@  discard block
 block discarded – undo
2368 2501
 {
2369 2502
 	global $context, $txt, $db_show_debug;
2370 2503
 
2371
-	if ($db_show_debug === true)
2372
-		$context['debug']['sub_templates'][] = $sub_template_name;
2504
+	if ($db_show_debug === true) {
2505
+			$context['debug']['sub_templates'][] = $sub_template_name;
2506
+	}
2373 2507
 
2374 2508
 	// Figure out what the template function is named.
2375 2509
 	$theme_function = 'template_' . $sub_template_name;
2376
-	if (function_exists($theme_function))
2377
-		$theme_function();
2378
-	elseif ($fatal === false)
2379
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2380
-	elseif ($fatal !== 'ignore')
2381
-		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'));
2510
+	if (function_exists($theme_function)) {
2511
+			$theme_function();
2512
+	} elseif ($fatal === false) {
2513
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2514
+	} elseif ($fatal !== 'ignore') {
2515
+			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'));
2516
+	}
2382 2517
 
2383 2518
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2384 2519
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2415,8 +2550,9 @@  discard block
 block discarded – undo
2415 2550
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2416 2551
 
2417 2552
 	// If this is an external file, automatically set this to false.
2418
-	if (!empty($params['external']))
2419
-		$params['minimize'] = false;
2553
+	if (!empty($params['external'])) {
2554
+			$params['minimize'] = false;
2555
+	}
2420 2556
 
2421 2557
 	// Account for shorthand like admin.css?alp21 filenames
2422 2558
 	$has_seed = strpos($fileName, '.css?');
@@ -2433,13 +2569,10 @@  discard block
 block discarded – undo
2433 2569
 			{
2434 2570
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2435 2571
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2572
+			} else {
2573
+							$fileUrl = false;
2436 2574
 			}
2437
-
2438
-			else
2439
-				$fileUrl = false;
2440
-		}
2441
-
2442
-		else
2575
+		} else
2443 2576
 		{
2444 2577
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2445 2578
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2454,12 +2587,14 @@  discard block
 block discarded – undo
2454 2587
 	}
2455 2588
 
2456 2589
 	// Add it to the array for use in the template
2457
-	if (!empty($fileName))
2458
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2590
+	if (!empty($fileName)) {
2591
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2592
+	}
2459 2593
 
2460
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2461
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2462
-}
2594
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2595
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2596
+	}
2597
+	}
2463 2598
 
2464 2599
 /**
2465 2600
  * Add a block of inline css code to be executed later
@@ -2476,8 +2611,9 @@  discard block
 block discarded – undo
2476 2611
 	global $context;
2477 2612
 
2478 2613
 	// Gotta add something...
2479
-	if (empty($css))
2480
-		return false;
2614
+	if (empty($css)) {
2615
+			return false;
2616
+	}
2481 2617
 
2482 2618
 	$context['css_header'][] = $css;
2483 2619
 }
@@ -2512,8 +2648,9 @@  discard block
 block discarded – undo
2512 2648
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2513 2649
 
2514 2650
 	// If this is an external file, automatically set this to false.
2515
-	if (!empty($params['external']))
2516
-		$params['minimize'] = false;
2651
+	if (!empty($params['external'])) {
2652
+			$params['minimize'] = false;
2653
+	}
2517 2654
 
2518 2655
 	// Account for shorthand like admin.js?alp21 filenames
2519 2656
 	$has_seed = strpos($fileName, '.js?');
@@ -2530,16 +2667,12 @@  discard block
 block discarded – undo
2530 2667
 			{
2531 2668
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2532 2669
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2533
-			}
2534
-
2535
-			else
2670
+			} else
2536 2671
 			{
2537 2672
 				$fileUrl = false;
2538 2673
 				$filePath = false;
2539 2674
 			}
2540
-		}
2541
-
2542
-		else
2675
+		} else
2543 2676
 		{
2544 2677
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2545 2678
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2554,9 +2687,10 @@  discard block
 block discarded – undo
2554 2687
 	}
2555 2688
 
2556 2689
 	// Add it to the array for use in the template
2557
-	if (!empty($fileName))
2558
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2559
-}
2690
+	if (!empty($fileName)) {
2691
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2692
+	}
2693
+	}
2560 2694
 
2561 2695
 /**
2562 2696
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2570,9 +2704,10 @@  discard block
 block discarded – undo
2570 2704
 {
2571 2705
 	global $context;
2572 2706
 
2573
-	if (!empty($key) && (!empty($value) || $value === '0'))
2574
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2575
-}
2707
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2708
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2709
+	}
2710
+	}
2576 2711
 
2577 2712
 /**
2578 2713
  * Add a block of inline Javascript code to be executed later
@@ -2589,8 +2724,9 @@  discard block
 block discarded – undo
2589 2724
 {
2590 2725
 	global $context;
2591 2726
 
2592
-	if (empty($javascript))
2593
-		return false;
2727
+	if (empty($javascript)) {
2728
+			return false;
2729
+	}
2594 2730
 
2595 2731
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2596 2732
 }
@@ -2611,15 +2747,18 @@  discard block
 block discarded – undo
2611 2747
 	static $already_loaded = array();
2612 2748
 
2613 2749
 	// Default to the user's language.
2614
-	if ($lang == '')
2615
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2750
+	if ($lang == '') {
2751
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2752
+	}
2616 2753
 
2617 2754
 	// Do we want the English version of language file as fallback?
2618
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2619
-		loadLanguage($template_name, 'english', false);
2755
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2756
+			loadLanguage($template_name, 'english', false);
2757
+	}
2620 2758
 
2621
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2622
-		return $lang;
2759
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2760
+			return $lang;
2761
+	}
2623 2762
 
2624 2763
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2625 2764
 	if (empty($settings['default_theme_dir']))
@@ -2630,8 +2769,9 @@  discard block
 block discarded – undo
2630 2769
 
2631 2770
 	// What theme are we in?
2632 2771
 	$theme_name = basename($settings['theme_url']);
2633
-	if (empty($theme_name))
2634
-		$theme_name = 'unknown';
2772
+	if (empty($theme_name)) {
2773
+			$theme_name = 'unknown';
2774
+	}
2635 2775
 
2636 2776
 	// For each file open it up and write it out!
2637 2777
 	foreach (explode('+', $template_name) as $template)
@@ -2673,8 +2813,9 @@  discard block
 block discarded – undo
2673 2813
 				$found = true;
2674 2814
 
2675 2815
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2676
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2677
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2816
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2817
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2818
+				}
2678 2819
 
2679 2820
 				break;
2680 2821
 			}
@@ -2714,8 +2855,9 @@  discard block
 block discarded – undo
2714 2855
 	}
2715 2856
 
2716 2857
 	// Keep track of what we're up to soldier.
2717
-	if ($db_show_debug === true)
2718
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2858
+	if ($db_show_debug === true) {
2859
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2860
+	}
2719 2861
 
2720 2862
 	// Remember what we have loaded, and in which language.
2721 2863
 	$already_loaded[$template_name] = $lang;
@@ -2761,8 +2903,9 @@  discard block
 block discarded – undo
2761 2903
 				)
2762 2904
 			);
2763 2905
 			// In the EXTREMELY unlikely event this happens, give an error message.
2764
-			if ($smcFunc['db_num_rows']($result) == 0)
2765
-				fatal_lang_error('parent_not_found', 'critical');
2906
+			if ($smcFunc['db_num_rows']($result) == 0) {
2907
+							fatal_lang_error('parent_not_found', 'critical');
2908
+			}
2766 2909
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2767 2910
 			{
2768 2911
 				if (!isset($boards[$row['id_board']]))
@@ -2779,8 +2922,8 @@  discard block
 block discarded – undo
2779 2922
 					);
2780 2923
 				}
2781 2924
 				// If a moderator exists for this board, add that moderator for all children too.
2782
-				if (!empty($row['id_moderator']))
2783
-					foreach ($boards as $id => $dummy)
2925
+				if (!empty($row['id_moderator'])) {
2926
+									foreach ($boards as $id => $dummy)
2784 2927
 					{
2785 2928
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2786 2929
 							'id' => $row['id_moderator'],
@@ -2788,11 +2931,12 @@  discard block
 block discarded – undo
2788 2931
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2789 2932
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2790 2933
 						);
2934
+				}
2791 2935
 					}
2792 2936
 
2793 2937
 				// If a moderator group exists for this board, add that moderator group for all children too
2794
-				if (!empty($row['id_moderator_group']))
2795
-					foreach ($boards as $id => $dummy)
2938
+				if (!empty($row['id_moderator_group'])) {
2939
+									foreach ($boards as $id => $dummy)
2796 2940
 					{
2797 2941
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2798 2942
 							'id' => $row['id_moderator_group'],
@@ -2800,6 +2944,7 @@  discard block
 block discarded – undo
2800 2944
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2801 2945
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2802 2946
 						);
2947
+				}
2803 2948
 					}
2804 2949
 			}
2805 2950
 			$smcFunc['db_free_result']($result);
@@ -2826,23 +2971,27 @@  discard block
 block discarded – undo
2826 2971
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2827 2972
 	{
2828 2973
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2829
-		if (empty($smcFunc['ucwords']))
2830
-			reloadSettings();
2974
+		if (empty($smcFunc['ucwords'])) {
2975
+					reloadSettings();
2976
+		}
2831 2977
 
2832 2978
 		// If we don't have our theme information yet, let's get it.
2833
-		if (empty($settings['default_theme_dir']))
2834
-			loadTheme(0, false);
2979
+		if (empty($settings['default_theme_dir'])) {
2980
+					loadTheme(0, false);
2981
+		}
2835 2982
 
2836 2983
 		// Default language directories to try.
2837 2984
 		$language_directories = array(
2838 2985
 			$settings['default_theme_dir'] . '/languages',
2839 2986
 		);
2840
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2841
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2987
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2988
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2989
+		}
2842 2990
 
2843 2991
 		// We possibly have a base theme directory.
2844
-		if (!empty($settings['base_theme_dir']))
2845
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2992
+		if (!empty($settings['base_theme_dir'])) {
2993
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2994
+		}
2846 2995
 
2847 2996
 		// Remove any duplicates.
2848 2997
 		$language_directories = array_unique($language_directories);
@@ -2856,20 +3005,21 @@  discard block
 block discarded – undo
2856 3005
 		foreach ($language_directories as $language_dir)
2857 3006
 		{
2858 3007
 			// Can't look in here... doesn't exist!
2859
-			if (!file_exists($language_dir))
2860
-				continue;
3008
+			if (!file_exists($language_dir)) {
3009
+							continue;
3010
+			}
2861 3011
 
2862 3012
 			$dir = dir($language_dir);
2863 3013
 			while ($entry = $dir->read())
2864 3014
 			{
2865 3015
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2866
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2867
-					continue;
2868
-
2869
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2870
-					$langName = $langList[$matches[1]];
3016
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3017
+									continue;
3018
+				}
2871 3019
 
2872
-				else
3020
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3021
+									$langName = $langList[$matches[1]];
3022
+				} else
2873 3023
 				{
2874 3024
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2875 3025
 
@@ -2910,12 +3060,14 @@  discard block
 block discarded – undo
2910 3060
 		}
2911 3061
 
2912 3062
 		// Do we need to store the lang list?
2913
-		if (empty($langList))
2914
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3063
+		if (empty($langList)) {
3064
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3065
+		}
2915 3066
 
2916 3067
 		// Let's cash in on this deal.
2917
-		if (!empty($modSettings['cache_enable']))
2918
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3068
+		if (!empty($modSettings['cache_enable'])) {
3069
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3070
+		}
2919 3071
 	}
2920 3072
 
2921 3073
 	return $context['languages'];
@@ -2938,8 +3090,9 @@  discard block
 block discarded – undo
2938 3090
 	global $modSettings, $options, $txt;
2939 3091
 	static $censor_vulgar = null, $censor_proper;
2940 3092
 
2941
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2942
-		return $text;
3093
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3094
+			return $text;
3095
+	}
2943 3096
 
2944 3097
 	// If they haven't yet been loaded, load them.
2945 3098
 	if ($censor_vulgar == null)
@@ -2967,9 +3120,9 @@  discard block
 block discarded – undo
2967 3120
 	{
2968 3121
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2969 3122
 		$text = $func($censor_vulgar, $censor_proper, $text);
3123
+	} else {
3124
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2970 3125
 	}
2971
-	else
2972
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2973 3126
 
2974 3127
 	return $text;
2975 3128
 }
@@ -2995,38 +3148,42 @@  discard block
 block discarded – undo
2995 3148
 	@ini_set('track_errors', '1');
2996 3149
 
2997 3150
 	// Don't include the file more than once, if $once is true.
2998
-	if ($once && in_array($filename, $templates))
2999
-		return;
3151
+	if ($once && in_array($filename, $templates)) {
3152
+			return;
3153
+	}
3000 3154
 	// Add this file to the include list, whether $once is true or not.
3001
-	else
3002
-		$templates[] = $filename;
3155
+	else {
3156
+			$templates[] = $filename;
3157
+	}
3003 3158
 
3004 3159
 	// Are we going to use eval?
3005 3160
 	if (empty($modSettings['disableTemplateEval']))
3006 3161
 	{
3007 3162
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3008 3163
 		$settings['current_include_filename'] = $filename;
3009
-	}
3010
-	else
3164
+	} else
3011 3165
 	{
3012 3166
 		$file_found = file_exists($filename);
3013 3167
 
3014
-		if ($once && $file_found)
3015
-			require_once($filename);
3016
-		elseif ($file_found)
3017
-			require($filename);
3168
+		if ($once && $file_found) {
3169
+					require_once($filename);
3170
+		} elseif ($file_found) {
3171
+					require($filename);
3172
+		}
3018 3173
 	}
3019 3174
 
3020 3175
 	if ($file_found !== true)
3021 3176
 	{
3022 3177
 		ob_end_clean();
3023
-		if (!empty($modSettings['enableCompressedOutput']))
3024
-			@ob_start('ob_gzhandler');
3025
-		else
3026
-			ob_start();
3178
+		if (!empty($modSettings['enableCompressedOutput'])) {
3179
+					@ob_start('ob_gzhandler');
3180
+		} else {
3181
+					ob_start();
3182
+		}
3027 3183
 
3028
-		if (isset($_GET['debug']))
3029
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3184
+		if (isset($_GET['debug'])) {
3185
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3186
+		}
3030 3187
 
3031 3188
 		// Don't cache error pages!!
3032 3189
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3045,12 +3202,13 @@  discard block
 block discarded – undo
3045 3202
 		echo '<!DOCTYPE html>
3046 3203
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3047 3204
 	<head>';
3048
-		if (isset($context['character_set']))
3049
-			echo '
3205
+		if (isset($context['character_set'])) {
3206
+					echo '
3050 3207
 		<meta charset="', $context['character_set'], '">';
3208
+		}
3051 3209
 
3052
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3053
-			echo '
3210
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3211
+					echo '
3054 3212
 		<title>', $mtitle, '</title>
3055 3213
 	</head>
3056 3214
 	<body>
@@ -3058,8 +3216,8 @@  discard block
 block discarded – undo
3058 3216
 		', $mmessage, '
3059 3217
 	</body>
3060 3218
 </html>';
3061
-		elseif (!allowedTo('admin_forum'))
3062
-			echo '
3219
+		} elseif (!allowedTo('admin_forum')) {
3220
+					echo '
3063 3221
 		<title>', $txt['template_parse_error'], '</title>
3064 3222
 	</head>
3065 3223
 	<body>
@@ -3067,16 +3225,18 @@  discard block
 block discarded – undo
3067 3225
 		', $txt['template_parse_error_message'], '
3068 3226
 	</body>
3069 3227
 </html>';
3070
-		else
3228
+		} else
3071 3229
 		{
3072 3230
 			require_once($sourcedir . '/Subs-Package.php');
3073 3231
 
3074 3232
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3075 3233
 			$error_array = error_get_last();
3076
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3077
-				$error = $error_array['message'];
3078
-			if (empty($error))
3079
-				$error = $txt['template_parse_errmsg'];
3234
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3235
+							$error = $error_array['message'];
3236
+			}
3237
+			if (empty($error)) {
3238
+							$error = $txt['template_parse_errmsg'];
3239
+			}
3080 3240
 
3081 3241
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3082 3242
 
@@ -3087,11 +3247,12 @@  discard block
 block discarded – undo
3087 3247
 		<h3>', $txt['template_parse_error'], '</h3>
3088 3248
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3089 3249
 
3090
-			if (!empty($error))
3091
-				echo '
3250
+			if (!empty($error)) {
3251
+							echo '
3092 3252
 		<hr>
3093 3253
 
3094 3254
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3255
+			}
3095 3256
 
3096 3257
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3097 3258
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3101,10 +3262,11 @@  discard block
 block discarded – undo
3101 3262
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3102 3263
 
3103 3264
 				// Fix the PHP code stuff...
3104
-				if (!isBrowser('gecko'))
3105
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3106
-				else
3107
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3265
+				if (!isBrowser('gecko')) {
3266
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3267
+				} else {
3268
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3269
+				}
3108 3270
 
3109 3271
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3110 3272
 				$j = -1;
@@ -3112,8 +3274,9 @@  discard block
 block discarded – undo
3112 3274
 				{
3113 3275
 					$j++;
3114 3276
 
3115
-					if (substr_count($line, '<br>') == 0)
3116
-						continue;
3277
+					if (substr_count($line, '<br>') == 0) {
3278
+											continue;
3279
+					}
3117 3280
 
3118 3281
 					$n = substr_count($line, '<br>');
3119 3282
 					for ($i = 0; $i < $n; $i++)
@@ -3132,38 +3295,42 @@  discard block
 block discarded – undo
3132 3295
 				// Figure out what the color coding was before...
3133 3296
 				$line = max($match[1] - 9, 1);
3134 3297
 				$last_line = '';
3135
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3136
-					if (strpos($data2[$line2], '<') !== false)
3298
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3299
+									if (strpos($data2[$line2], '<') !== false)
3137 3300
 					{
3138 3301
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3139 3302
 							$last_line = $color_match[1];
3303
+				}
3140 3304
 						break;
3141 3305
 					}
3142 3306
 
3143 3307
 				// Show the relevant lines...
3144 3308
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3145 3309
 				{
3146
-					if ($line == $match[1])
3147
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3310
+					if ($line == $match[1]) {
3311
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3312
+					}
3148 3313
 
3149 3314
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3150
-					if (isset($data2[$line]) && $data2[$line] != '')
3151
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3315
+					if (isset($data2[$line]) && $data2[$line] != '') {
3316
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3317
+					}
3152 3318
 
3153 3319
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3154 3320
 					{
3155 3321
 						$last_line = $color_match[1];
3156 3322
 						echo '</', substr($last_line, 1, 4), '>';
3323
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3324
+											$last_line = '';
3325
+					} elseif ($last_line != '' && $data2[$line] != '') {
3326
+											echo '</', substr($last_line, 1, 4), '>';
3157 3327
 					}
3158
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3159
-						$last_line = '';
3160
-					elseif ($last_line != '' && $data2[$line] != '')
3161
-						echo '</', substr($last_line, 1, 4), '>';
3162 3328
 
3163
-					if ($line == $match[1])
3164
-						echo '</pre></div><pre style="margin: 0;">';
3165
-					else
3166
-						echo "\n";
3329
+					if ($line == $match[1]) {
3330
+											echo '</pre></div><pre style="margin: 0;">';
3331
+					} else {
3332
+											echo "\n";
3333
+					}
3167 3334
 				}
3168 3335
 
3169 3336
 				echo '</pre></div>';
@@ -3187,8 +3354,9 @@  discard block
 block discarded – undo
3187 3354
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3188 3355
 
3189 3356
 	// Figure out what type of database we are using.
3190
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3191
-		$db_type = 'mysql';
3357
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3358
+			$db_type = 'mysql';
3359
+	}
3192 3360
 
3193 3361
 	// Load the file for the database.
3194 3362
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3196,8 +3364,9 @@  discard block
 block discarded – undo
3196 3364
 	$db_options = array();
3197 3365
 
3198 3366
 	// Add in the port if needed
3199
-	if (!empty($db_port))
3200
-		$db_options['port'] = $db_port;
3367
+	if (!empty($db_port)) {
3368
+			$db_options['port'] = $db_port;
3369
+	}
3201 3370
 
3202 3371
 	// 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.
3203 3372
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3216,13 +3385,15 @@  discard block
 block discarded – undo
3216 3385
 	}
3217 3386
 
3218 3387
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3219
-	if (!$db_connection)
3220
-		display_db_error();
3388
+	if (!$db_connection) {
3389
+			display_db_error();
3390
+	}
3221 3391
 
3222 3392
 	// If in SSI mode fix up the prefix.
3223
-	if (SMF == 'SSI')
3224
-		db_fix_prefix($db_prefix, $db_name);
3225
-}
3393
+	if (SMF == 'SSI') {
3394
+			db_fix_prefix($db_prefix, $db_name);
3395
+	}
3396
+	}
3226 3397
 
3227 3398
 /**
3228 3399
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3236,10 +3407,11 @@  discard block
 block discarded – undo
3236 3407
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3237 3408
 
3238 3409
 	// Not overriding this and we have a cacheAPI, send it back.
3239
-	if (empty($overrideCache) && is_object($cacheAPI))
3240
-		return $cacheAPI;
3241
-	elseif (is_null($cacheAPI))
3242
-		$cacheAPI = false;
3410
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3411
+			return $cacheAPI;
3412
+	} elseif (is_null($cacheAPI)) {
3413
+			$cacheAPI = false;
3414
+	}
3243 3415
 
3244 3416
 	// Make sure our class is in session.
3245 3417
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3260,8 +3432,9 @@  discard block
 block discarded – undo
3260 3432
 		if (!$testAPI->isSupported())
3261 3433
 		{
3262 3434
 			// Can we save ourselves?
3263
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3264
-				return loadCacheAccelerator(null, false);
3435
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3436
+							return loadCacheAccelerator(null, false);
3437
+			}
3265 3438
 			return false;
3266 3439
 		}
3267 3440
 
@@ -3273,9 +3446,9 @@  discard block
 block discarded – undo
3273 3446
 		{
3274 3447
 			$cacheAPI = $testAPI;
3275 3448
 			return $cacheAPI;
3449
+		} else {
3450
+					return $testAPI;
3276 3451
 		}
3277
-		else
3278
-			return $testAPI;
3279 3452
 	}
3280 3453
 }
3281 3454
 
@@ -3295,8 +3468,9 @@  discard block
 block discarded – undo
3295 3468
 
3296 3469
 	// @todo Why are we doing this if caching is disabled?
3297 3470
 
3298
-	if (function_exists('call_integration_hook'))
3299
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3471
+	if (function_exists('call_integration_hook')) {
3472
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3473
+	}
3300 3474
 
3301 3475
 	/* Refresh the cache if either:
3302 3476
 		1. Caching is disabled.
@@ -3310,16 +3484,19 @@  discard block
 block discarded – undo
3310 3484
 		require_once($sourcedir . '/' . $file);
3311 3485
 		$cache_block = call_user_func_array($function, $params);
3312 3486
 
3313
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3314
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3487
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3488
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3489
+		}
3315 3490
 	}
3316 3491
 
3317 3492
 	// Some cached data may need a freshening up after retrieval.
3318
-	if (!empty($cache_block['post_retri_eval']))
3319
-		eval($cache_block['post_retri_eval']);
3493
+	if (!empty($cache_block['post_retri_eval'])) {
3494
+			eval($cache_block['post_retri_eval']);
3495
+	}
3320 3496
 
3321
-	if (function_exists('call_integration_hook'))
3322
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3497
+	if (function_exists('call_integration_hook')) {
3498
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3499
+	}
3323 3500
 
3324 3501
 	return $cache_block['data'];
3325 3502
 }
@@ -3346,8 +3523,9 @@  discard block
 block discarded – undo
3346 3523
 	global $smcFunc, $cache_enable, $cacheAPI;
3347 3524
 	global $cache_hits, $cache_count, $db_show_debug;
3348 3525
 
3349
-	if (empty($cache_enable) || empty($cacheAPI))
3350
-		return;
3526
+	if (empty($cache_enable) || empty($cacheAPI)) {
3527
+			return;
3528
+	}
3351 3529
 
3352 3530
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3353 3531
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3360,12 +3538,14 @@  discard block
 block discarded – undo
3360 3538
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3361 3539
 	$cacheAPI->putData($key, $value, $ttl);
3362 3540
 
3363
-	if (function_exists('call_integration_hook'))
3364
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3541
+	if (function_exists('call_integration_hook')) {
3542
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3543
+	}
3365 3544
 
3366
-	if (isset($db_show_debug) && $db_show_debug === true)
3367
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3368
-}
3545
+	if (isset($db_show_debug) && $db_show_debug === true) {
3546
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3547
+	}
3548
+	}
3369 3549
 
3370 3550
 /**
3371 3551
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3381,8 +3561,9 @@  discard block
 block discarded – undo
3381 3561
 	global $smcFunc, $cache_enable, $cacheAPI;
3382 3562
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3383 3563
 
3384
-	if (empty($cache_enable) || empty($cacheAPI))
3385
-		return;
3564
+	if (empty($cache_enable) || empty($cacheAPI)) {
3565
+			return;
3566
+	}
3386 3567
 
3387 3568
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3388 3569
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3402,16 +3583,18 @@  discard block
 block discarded – undo
3402 3583
 
3403 3584
 		if (empty($value))
3404 3585
 		{
3405
-			if (!is_array($cache_misses))
3406
-				$cache_misses = array();
3586
+			if (!is_array($cache_misses)) {
3587
+							$cache_misses = array();
3588
+			}
3407 3589
 
3408 3590
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3409 3591
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3410 3592
 		}
3411 3593
 	}
3412 3594
 
3413
-	if (function_exists('call_integration_hook') && isset($value))
3414
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3595
+	if (function_exists('call_integration_hook') && isset($value)) {
3596
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3597
+	}
3415 3598
 
3416 3599
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3417 3600
 }
@@ -3433,8 +3616,9 @@  discard block
 block discarded – undo
3433 3616
 	global $cacheAPI;
3434 3617
 
3435 3618
 	// If we can't get to the API, can't do this.
3436
-	if (empty($cacheAPI))
3437
-		return;
3619
+	if (empty($cacheAPI)) {
3620
+			return;
3621
+	}
3438 3622
 
3439 3623
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3440 3624
 	$cacheAPI->cleanCache($type);
@@ -3459,8 +3643,9 @@  discard block
 block discarded – undo
3459 3643
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3460 3644
 
3461 3645
 	// Come on!
3462
-	if (empty($data))
3463
-		return array();
3646
+	if (empty($data)) {
3647
+			return array();
3648
+	}
3464 3649
 
3465 3650
 	// Set a nice default var.
3466 3651
 	$image = '';
@@ -3468,11 +3653,11 @@  discard block
 block discarded – undo
3468 3653
 	// Gravatar has been set as mandatory!
3469 3654
 	if (!empty($modSettings['gravatarOverride']))
3470 3655
 	{
3471
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3472
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3473
-
3474
-		else if (!empty($data['email']))
3475
-			$image = get_gravatar_url($data['email']);
3656
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3657
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3658
+		} else if (!empty($data['email'])) {
3659
+					$image = get_gravatar_url($data['email']);
3660
+		}
3476 3661
 	}
3477 3662
 
3478 3663
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3484,54 +3669,60 @@  discard block
 block discarded – undo
3484 3669
 			// Gravatar.
3485 3670
 			if (stristr($data['avatar'], 'gravatar://'))
3486 3671
 			{
3487
-				if ($data['avatar'] == 'gravatar://')
3488
-					$image = get_gravatar_url($data['email']);
3489
-
3490
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3491
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3672
+				if ($data['avatar'] == 'gravatar://') {
3673
+									$image = get_gravatar_url($data['email']);
3674
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3675
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3676
+				}
3492 3677
 			}
3493 3678
 
3494 3679
 			// External url.
3495 3680
 			else
3496 3681
 			{
3497 3682
 				// Using ssl?
3498
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3499
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3683
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3684
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3685
+				}
3500 3686
 
3501 3687
 				// Just a plain external url.
3502
-				else
3503
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3688
+				else {
3689
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3690
+				}
3504 3691
 			}
3505 3692
 		}
3506 3693
 
3507 3694
 		// Perhaps this user has an attachment as avatar...
3508
-		else if (!empty($data['filename']))
3509
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3695
+		else if (!empty($data['filename'])) {
3696
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3697
+		}
3510 3698
 
3511 3699
 		// Right... no avatar... use our default image.
3512
-		else
3513
-			$image = $modSettings['avatar_url'] . '/default.png';
3700
+		else {
3701
+					$image = $modSettings['avatar_url'] . '/default.png';
3702
+		}
3514 3703
 	}
3515 3704
 
3516 3705
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3517 3706
 
3518 3707
 	// 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.
3519
-	if (!empty($image))
3520
-		return array(
3708
+	if (!empty($image)) {
3709
+			return array(
3521 3710
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3522 3711
 			'image' => '<img class="avatar" src="' . $image . '" />',
3523 3712
 			'href' => $image,
3524 3713
 			'url' => $image,
3525 3714
 		);
3715
+	}
3526 3716
 
3527 3717
 	// Fallback to make life easier for everyone...
3528
-	else
3529
-		return array(
3718
+	else {
3719
+			return array(
3530 3720
 			'name' => '',
3531 3721
 			'image' => '',
3532 3722
 			'href' => '',
3533 3723
 			'url' => '',
3534 3724
 		);
3535
-}
3725
+	}
3726
+	}
3536 3727
 
3537 3728
 ?>
3538 3729
\ No newline at end of file
Please login to merge, or discard this patch.