Completed
Pull Request — release-2.1 (#4452)
by Colin
14:07 queued 06:15
created
Sources/Load.php 1 patch
Braces   +790 added lines, -597 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We 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,13 +1598,15 @@  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
 
@@ -1543,31 +1614,36 @@  discard block
 block discarded – undo
1543 1614
 			$currentKey = 0;
1544 1615
 
1545 1616
 			// Create a key => value array for multiple options fields
1546
-			if (!empty($custom['options']))
1547
-				foreach ($custom['options'] as $k => $v)
1617
+			if (!empty($custom['options'])) {
1618
+							foreach ($custom['options'] as $k => $v)
1548 1619
 				{
1549 1620
 					$fieldOptions[] = $v;
1550
-					if (empty($currentKey))
1551
-						$currentKey = $v == $value ? $k : 0;
1621
+			}
1622
+					if (empty($currentKey)) {
1623
+											$currentKey = $v == $value ? $k : 0;
1624
+					}
1552 1625
 				}
1553 1626
 
1554 1627
 			// BBC?
1555
-			if ($custom['bbc'])
1556
-				$value = parse_bbc($value);
1628
+			if ($custom['bbc']) {
1629
+							$value = parse_bbc($value);
1630
+			}
1557 1631
 
1558 1632
 			// ... or checkbox?
1559
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1560
-				$value = $value ? $txt['yes'] : $txt['no'];
1633
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1634
+							$value = $value ? $txt['yes'] : $txt['no'];
1635
+			}
1561 1636
 
1562 1637
 			// Enclosing the user input within some other text?
1563
-			if (!empty($custom['enclose']))
1564
-				$value = strtr($custom['enclose'], array(
1638
+			if (!empty($custom['enclose'])) {
1639
+							$value = strtr($custom['enclose'], array(
1565 1640
 					'{SCRIPTURL}' => $scripturl,
1566 1641
 					'{IMAGES_URL}' => $settings['images_url'],
1567 1642
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1568 1643
 					'{INPUT}' => $value,
1569 1644
 					'{KEY}' => $currentKey,
1570 1645
 				));
1646
+			}
1571 1647
 
1572 1648
 			$memberContext[$user]['custom_fields'][] = array(
1573 1649
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1594,8 +1670,9 @@  discard block
 block discarded – undo
1594 1670
 	global $smcFunc, $txt, $scripturl, $settings;
1595 1671
 
1596 1672
 	// Do not waste my time...
1597
-	if (empty($users) || empty($params))
1598
-		return false;
1673
+	if (empty($users) || empty($params)) {
1674
+			return false;
1675
+	}
1599 1676
 
1600 1677
 	// Make sure it's an array.
1601 1678
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1622,41 +1699,48 @@  discard block
 block discarded – undo
1622 1699
 		$currentKey = 0;
1623 1700
 
1624 1701
 		// Create a key => value array for multiple options fields
1625
-		if (!empty($row['field_options']))
1626
-			foreach (explode(',', $row['field_options']) as $k => $v)
1702
+		if (!empty($row['field_options'])) {
1703
+					foreach (explode(',', $row['field_options']) as $k => $v)
1627 1704
 			{
1628 1705
 				$fieldOptions[] = $v;
1629
-				if (empty($currentKey))
1630
-					$currentKey = $v == $row['value'] ? $k : 0;
1706
+		}
1707
+				if (empty($currentKey)) {
1708
+									$currentKey = $v == $row['value'] ? $k : 0;
1709
+				}
1631 1710
 			}
1632 1711
 
1633 1712
 		// BBC?
1634
-		if (!empty($row['bbc']))
1635
-			$row['value'] = parse_bbc($row['value']);
1713
+		if (!empty($row['bbc'])) {
1714
+					$row['value'] = parse_bbc($row['value']);
1715
+		}
1636 1716
 
1637 1717
 		// ... or checkbox?
1638
-		elseif (isset($row['type']) && $row['type'] == 'check')
1639
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1718
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1719
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1720
+		}
1640 1721
 
1641 1722
 		// Enclosing the user input within some other text?
1642
-		if (!empty($row['enclose']))
1643
-			$row['value'] = strtr($row['enclose'], array(
1723
+		if (!empty($row['enclose'])) {
1724
+					$row['value'] = strtr($row['enclose'], array(
1644 1725
 				'{SCRIPTURL}' => $scripturl,
1645 1726
 				'{IMAGES_URL}' => $settings['images_url'],
1646 1727
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1647 1728
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1648 1729
 				'{KEY}' => $currentKey,
1649 1730
 			));
1731
+		}
1650 1732
 
1651 1733
 		// Send a simple array if there is just 1 param
1652
-		if (count($params) == 1)
1653
-			$return[$row['id_member']] = $row;
1734
+		if (count($params) == 1) {
1735
+					$return[$row['id_member']] = $row;
1736
+		}
1654 1737
 
1655 1738
 		// More than 1? knock yourself out...
1656 1739
 		else
1657 1740
 		{
1658
-			if (!isset($return[$row['id_member']]))
1659
-				$return[$row['id_member']] = array();
1741
+			if (!isset($return[$row['id_member']])) {
1742
+							$return[$row['id_member']] = array();
1743
+			}
1660 1744
 
1661 1745
 			$return[$row['id_member']][$row['variable']] = $row;
1662 1746
 		}
@@ -1690,8 +1774,9 @@  discard block
 block discarded – undo
1690 1774
 	global $context;
1691 1775
 
1692 1776
 	// Don't know any browser!
1693
-	if (empty($context['browser']))
1694
-		detectBrowser();
1777
+	if (empty($context['browser'])) {
1778
+			detectBrowser();
1779
+	}
1695 1780
 
1696 1781
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1697 1782
 }
@@ -1709,8 +1794,9 @@  discard block
 block discarded – undo
1709 1794
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1710 1795
 
1711 1796
 	// The theme was specified by parameter.
1712
-	if (!empty($id_theme))
1713
-		$id_theme = (int) $id_theme;
1797
+	if (!empty($id_theme)) {
1798
+			$id_theme = (int) $id_theme;
1799
+	}
1714 1800
 	// The theme was specified by REQUEST.
1715 1801
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1716 1802
 	{
@@ -1718,54 +1804,61 @@  discard block
 block discarded – undo
1718 1804
 		$_SESSION['id_theme'] = $id_theme;
1719 1805
 	}
1720 1806
 	// The theme was specified by REQUEST... previously.
1721
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1722
-		$id_theme = (int) $_SESSION['id_theme'];
1807
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1808
+			$id_theme = (int) $_SESSION['id_theme'];
1809
+	}
1723 1810
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1724
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1725
-		$id_theme = $user_info['theme'];
1811
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1812
+			$id_theme = $user_info['theme'];
1813
+	}
1726 1814
 	// The theme was specified by the board.
1727
-	elseif (!empty($board_info['theme']))
1728
-		$id_theme = $board_info['theme'];
1815
+	elseif (!empty($board_info['theme'])) {
1816
+			$id_theme = $board_info['theme'];
1817
+	}
1729 1818
 	// The theme is the forum's default.
1730
-	else
1731
-		$id_theme = $modSettings['theme_guests'];
1819
+	else {
1820
+			$id_theme = $modSettings['theme_guests'];
1821
+	}
1732 1822
 
1733 1823
 	// We already load the basic stuff?
1734 1824
 	if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme )
1735 1825
 	{
1736 1826
 		// Verify the id_theme... no foul play.
1737 1827
 		// Always allow the board specific theme, if they are overriding.
1738
-		if (!empty($board_info['theme']) && $board_info['override_theme'])
1739
-			$id_theme = $board_info['theme'];
1828
+		if (!empty($board_info['theme']) && $board_info['override_theme']) {
1829
+					$id_theme = $board_info['theme'];
1830
+		}
1740 1831
 		// If they have specified a particular theme to use with SSI allow it to be used.
1741
-		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1742
-			$id_theme = (int) $id_theme;
1743
-		elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1832
+		elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1833
+					$id_theme = (int) $id_theme;
1834
+		} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1744 1835
 		{
1745 1836
 			$themes = explode(',', $modSettings['enableThemes']);
1746
-			if (!in_array($id_theme, $themes))
1747
-				$id_theme = $modSettings['theme_guests'];
1748
-			else
1749
-				$id_theme = (int) $id_theme;
1837
+			if (!in_array($id_theme, $themes)) {
1838
+							$id_theme = $modSettings['theme_guests'];
1839
+			} else {
1840
+							$id_theme = (int) $id_theme;
1841
+			}
1842
+		} else {
1843
+					$id_theme = (int) $id_theme;
1750 1844
 		}
1751
-		else
1752
-			$id_theme = (int) $id_theme;
1753 1845
 
1754 1846
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1755 1847
 
1756 1848
 		// Disable image proxy if we don't have SSL enabled
1757
-		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1758
-			$image_proxy_enabled = false;
1849
+		if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1850
+					$image_proxy_enabled = false;
1851
+		}
1759 1852
 
1760 1853
 		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'])
1761 1854
 		{
1762 1855
 			$themeData = $temp;
1763 1856
 			$flag = true;
1857
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1858
+					$themeData = $temp + array($member => array());
1859
+		} else {
1860
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1764 1861
 		}
1765
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1766
-			$themeData = $temp + array($member => array());
1767
-		else
1768
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1769 1862
 
1770 1863
 		if (empty($flag))
1771 1864
 		{
@@ -1784,31 +1877,37 @@  discard block
 block discarded – undo
1784 1877
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1785 1878
 			{
1786 1879
 				// There are just things we shouldn't be able to change as members.
1787
-				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')))
1788
-					continue;
1880
+				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'))) {
1881
+									continue;
1882
+				}
1789 1883
 
1790 1884
 				// If this is the theme_dir of the default theme, store it.
1791
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1792
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1885
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1886
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1887
+				}
1793 1888
 
1794 1889
 				// If this isn't set yet, is a theme option, or is not the default theme..
1795
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1796
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1890
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1891
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1892
+				}
1797 1893
 			}
1798 1894
 			$smcFunc['db_free_result']($result);
1799 1895
 
1800
-			if (!empty($themeData[-1]))
1801
-				foreach ($themeData[-1] as $k => $v)
1896
+			if (!empty($themeData[-1])) {
1897
+							foreach ($themeData[-1] as $k => $v)
1802 1898
 				{
1803 1899
 					if (!isset($themeData[$member][$k]))
1804 1900
 						$themeData[$member][$k] = $v;
1901
+			}
1805 1902
 				}
1806 1903
 
1807
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1808
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1904
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1905
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1906
+			}
1809 1907
 			// Only if we didn't already load that part of the cache...
1810
-			elseif (!isset($temp))
1811
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1908
+			elseif (!isset($temp)) {
1909
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1910
+			}
1812 1911
 		}
1813 1912
 
1814 1913
 		$settings = $themeData[0];
@@ -1825,17 +1924,20 @@  discard block
 block discarded – undo
1825 1924
 		$settings['template_dirs'][] = $settings['theme_dir'];
1826 1925
 
1827 1926
 		// Based on theme (if there is one).
1828
-		if (!empty($settings['base_theme_dir']))
1829
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1927
+		if (!empty($settings['base_theme_dir'])) {
1928
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1929
+		}
1830 1930
 
1831 1931
 		// Lastly the default theme.
1832
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1833
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1932
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1933
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1934
+		}
1834 1935
 	}
1835 1936
 
1836 1937
 
1837
-	if (!$initialize)
1838
-		return;
1938
+	if (!$initialize) {
1939
+			return;
1940
+	}
1839 1941
 
1840 1942
 	// Check to see if we're forcing SSL
1841 1943
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
@@ -1856,8 +1958,9 @@  discard block
 block discarded – undo
1856 1958
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1857 1959
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1858 1960
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1859
-		if ($temp != '/')
1860
-			$detected_url .= $temp;
1961
+		if ($temp != '/') {
1962
+					$detected_url .= $temp;
1963
+		}
1861 1964
 	}
1862 1965
 	if (isset($detected_url) && $detected_url != $boardurl)
1863 1966
 	{
@@ -1869,8 +1972,9 @@  discard block
 block discarded – undo
1869 1972
 			foreach ($aliases as $alias)
1870 1973
 			{
1871 1974
 				// Rip off all the boring parts, spaces, etc.
1872
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1873
-					$do_fix = true;
1975
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1976
+									$do_fix = true;
1977
+				}
1874 1978
 			}
1875 1979
 		}
1876 1980
 
@@ -1878,21 +1982,23 @@  discard block
 block discarded – undo
1878 1982
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1879 1983
 		{
1880 1984
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1881
-			if (empty($_GET))
1882
-				redirectexit('wwwRedirect');
1883
-			else
1985
+			if (empty($_GET)) {
1986
+							redirectexit('wwwRedirect');
1987
+			} else
1884 1988
 			{
1885 1989
 				$k = key($_GET);
1886 1990
 				$v = current($_GET);
1887 1991
 
1888
-				if ($k != 'wwwRedirect')
1889
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1992
+				if ($k != 'wwwRedirect') {
1993
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1994
+				}
1890 1995
 			}
1891 1996
 		}
1892 1997
 
1893 1998
 		// #3 is just a check for SSL...
1894
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1895
-			$do_fix = true;
1999
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
2000
+					$do_fix = true;
2001
+		}
1896 2002
 
1897 2003
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1898 2004
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1927,8 +2033,9 @@  discard block
 block discarded – undo
1927 2033
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1928 2034
 				}
1929 2035
 			}
1930
-			foreach ($context['linktree'] as $k => $dummy)
1931
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2036
+			foreach ($context['linktree'] as $k => $dummy) {
2037
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2038
+			}
1932 2039
 		}
1933 2040
 	}
1934 2041
 	// Set up the contextual user array.
@@ -1947,16 +2054,16 @@  discard block
 block discarded – undo
1947 2054
 			'email' => $user_info['email'],
1948 2055
 			'ignoreusers' => $user_info['ignoreusers'],
1949 2056
 		);
1950
-		if (!$context['user']['is_guest'])
1951
-			$context['user']['name'] = $user_info['name'];
1952
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1953
-			$context['user']['name'] = $txt['guest_title'];
2057
+		if (!$context['user']['is_guest']) {
2058
+					$context['user']['name'] = $user_info['name'];
2059
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2060
+					$context['user']['name'] = $txt['guest_title'];
2061
+		}
1954 2062
 
1955 2063
 		// Determine the current smiley set.
1956 2064
 		$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'];
1957 2065
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1958
-	}
1959
-	else
2066
+	} else
1960 2067
 	{
1961 2068
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1962 2069
 		$context['user'] = array(
@@ -1990,18 +2097,24 @@  discard block
 block discarded – undo
1990 2097
 	}
1991 2098
 
1992 2099
 	// Some basic information...
1993
-	if (!isset($context['html_headers']))
1994
-		$context['html_headers'] = '';
1995
-	if (!isset($context['javascript_files']))
1996
-		$context['javascript_files'] = array();
1997
-	if (!isset($context['css_files']))
1998
-		$context['css_files'] = array();
1999
-	if (!isset($context['css_header']))
2000
-		$context['css_header'] = array();
2001
-	if (!isset($context['javascript_inline']))
2002
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2003
-	if (!isset($context['javascript_vars']))
2004
-		$context['javascript_vars'] = array();
2100
+	if (!isset($context['html_headers'])) {
2101
+			$context['html_headers'] = '';
2102
+	}
2103
+	if (!isset($context['javascript_files'])) {
2104
+			$context['javascript_files'] = array();
2105
+	}
2106
+	if (!isset($context['css_files'])) {
2107
+			$context['css_files'] = array();
2108
+	}
2109
+	if (!isset($context['css_header'])) {
2110
+			$context['css_header'] = array();
2111
+	}
2112
+	if (!isset($context['javascript_inline'])) {
2113
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2114
+	}
2115
+	if (!isset($context['javascript_vars'])) {
2116
+			$context['javascript_vars'] = array();
2117
+	}
2005 2118
 
2006 2119
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
2007 2120
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2013,16 +2126,18 @@  discard block
 block discarded – undo
2013 2126
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2014 2127
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2015 2128
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2016
-	if (isset($modSettings['load_average']))
2017
-		$context['load_average'] = $modSettings['load_average'];
2129
+	if (isset($modSettings['load_average'])) {
2130
+			$context['load_average'] = $modSettings['load_average'];
2131
+	}
2018 2132
 
2019 2133
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2020 2134
 	detectBrowser();
2021 2135
 
2022 2136
 	// Set the top level linktree up.
2023 2137
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2024
-	if (empty($context['linktree']))
2025
-		$context['linktree'] = array();
2138
+	if (empty($context['linktree'])) {
2139
+			$context['linktree'] = array();
2140
+	}
2026 2141
 	array_unshift($context['linktree'], array(
2027 2142
 		'url' => $scripturl,
2028 2143
 		'name' => $context['forum_name_html_safe']
@@ -2031,8 +2146,9 @@  discard block
 block discarded – undo
2031 2146
 	// This allows sticking some HTML on the page output - useful for controls.
2032 2147
 	$context['insert_after_template'] = '';
2033 2148
 
2034
-	if (!isset($txt))
2035
-		$txt = array();
2149
+	if (!isset($txt)) {
2150
+			$txt = array();
2151
+	}
2036 2152
 
2037 2153
 	$simpleActions = array(
2038 2154
 		'findmember',
@@ -2078,9 +2194,10 @@  discard block
 block discarded – undo
2078 2194
 
2079 2195
 	// See if theres any extra param to check.
2080 2196
 	$requiresXML = false;
2081
-	foreach ($extraParams as $key => $extra)
2082
-		if (isset($_REQUEST[$extra]))
2197
+	foreach ($extraParams as $key => $extra) {
2198
+			if (isset($_REQUEST[$extra]))
2083 2199
 			$requiresXML = true;
2200
+	}
2084 2201
 
2085 2202
 	// Output is fully XML, so no need for the index template.
2086 2203
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2095,37 +2212,39 @@  discard block
 block discarded – undo
2095 2212
 	{
2096 2213
 		loadLanguage('index+Modifications');
2097 2214
 		$context['template_layers'] = array();
2098
-	}
2099
-
2100
-	else
2215
+	} else
2101 2216
 	{
2102 2217
 		// Custom templates to load, or just default?
2103
-		if (isset($settings['theme_templates']))
2104
-			$templates = explode(',', $settings['theme_templates']);
2105
-		else
2106
-			$templates = array('index');
2218
+		if (isset($settings['theme_templates'])) {
2219
+					$templates = explode(',', $settings['theme_templates']);
2220
+		} else {
2221
+					$templates = array('index');
2222
+		}
2107 2223
 
2108 2224
 		// Load each template...
2109
-		foreach ($templates as $template)
2110
-			loadTemplate($template);
2225
+		foreach ($templates as $template) {
2226
+					loadTemplate($template);
2227
+		}
2111 2228
 
2112 2229
 		// ...and attempt to load their associated language files.
2113 2230
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2114 2231
 		loadLanguage($required_files, '', false);
2115 2232
 
2116 2233
 		// Custom template layers?
2117
-		if (isset($settings['theme_layers']))
2118
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2119
-		else
2120
-			$context['template_layers'] = array('html', 'body');
2234
+		if (isset($settings['theme_layers'])) {
2235
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2236
+		} else {
2237
+					$context['template_layers'] = array('html', 'body');
2238
+		}
2121 2239
 	}
2122 2240
 
2123 2241
 	// Initialize the theme.
2124 2242
 	loadSubTemplate('init', 'ignore');
2125 2243
 
2126 2244
 	// Allow overriding the board wide time/number formats.
2127
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2128
-		$user_info['time_format'] = $txt['time_format'];
2245
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2246
+			$user_info['time_format'] = $txt['time_format'];
2247
+	}
2129 2248
 
2130 2249
 	// Set the character set from the template.
2131 2250
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2133,12 +2252,14 @@  discard block
 block discarded – undo
2133 2252
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2134 2253
 
2135 2254
 	// Guests may still need a name.
2136
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2137
-		$context['user']['name'] = $txt['guest_title'];
2255
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2256
+			$context['user']['name'] = $txt['guest_title'];
2257
+	}
2138 2258
 
2139 2259
 	// Any theme-related strings that need to be loaded?
2140
-	if (!empty($settings['require_theme_strings']))
2141
-		loadLanguage('ThemeStrings', '', false);
2260
+	if (!empty($settings['require_theme_strings'])) {
2261
+			loadLanguage('ThemeStrings', '', false);
2262
+	}
2142 2263
 
2143 2264
 	// Make a special URL for the language.
2144 2265
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2149,8 +2270,9 @@  discard block
 block discarded – undo
2149 2270
 	// Here is my luvly Responsive CSS
2150 2271
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2151 2272
 
2152
-	if ($context['right_to_left'])
2153
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2273
+	if ($context['right_to_left']) {
2274
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2275
+	}
2154 2276
 
2155 2277
 	// We allow theme variants, because we're cool.
2156 2278
 	$context['theme_variant'] = '';
@@ -2158,14 +2280,17 @@  discard block
 block discarded – undo
2158 2280
 	if (!empty($settings['theme_variants']))
2159 2281
 	{
2160 2282
 		// Overriding - for previews and that ilk.
2161
-		if (!empty($_REQUEST['variant']))
2162
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2283
+		if (!empty($_REQUEST['variant'])) {
2284
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2285
+		}
2163 2286
 		// User selection?
2164
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2165
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2287
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2288
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2289
+		}
2166 2290
 		// If not a user variant, select the default.
2167
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2168
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2291
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2292
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2293
+		}
2169 2294
 
2170 2295
 		// Do this to keep things easier in the templates.
2171 2296
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2174,20 +2299,23 @@  discard block
 block discarded – undo
2174 2299
 		if (!empty($context['theme_variant']))
2175 2300
 		{
2176 2301
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2177
-			if ($context['right_to_left'])
2178
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2302
+			if ($context['right_to_left']) {
2303
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2304
+			}
2179 2305
 		}
2180 2306
 	}
2181 2307
 
2182 2308
 	// Let's be compatible with old themes!
2183
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2184
-		$context['template_layers'] = array('main');
2309
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2310
+			$context['template_layers'] = array('main');
2311
+	}
2185 2312
 
2186 2313
 	$context['tabindex'] = 1;
2187 2314
 
2188 2315
 	// Compatibility.
2189
-	if (!isset($settings['theme_version']))
2190
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2316
+	if (!isset($settings['theme_version'])) {
2317
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2318
+	}
2191 2319
 
2192 2320
 	// Default JS variables for use in every theme
2193 2321
 	$context['javascript_vars'] = array(
@@ -2206,18 +2334,18 @@  discard block
 block discarded – undo
2206 2334
 	);
2207 2335
 
2208 2336
 	// Add the JQuery library to the list of files to load.
2209
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2210
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2211
-
2212
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2213
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2214
-
2215
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2216
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2337
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2338
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2339
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2340
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2341
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2342
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2343
+	}
2217 2344
 
2218 2345
 	// Auto loading? template_javascript() will take care of the local half of this.
2219
-	else
2220
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2346
+	else {
2347
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2348
+	}
2221 2349
 
2222 2350
 	// Queue our JQuery plugins!
2223 2351
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2240,12 +2368,12 @@  discard block
 block discarded – undo
2240 2368
 			require_once($sourcedir . '/ScheduledTasks.php');
2241 2369
 
2242 2370
 			// What to do, what to do?!
2243
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2244
-				AutoTask();
2245
-			else
2246
-				ReduceMailQueue();
2247
-		}
2248
-		else
2371
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2372
+							AutoTask();
2373
+			} else {
2374
+							ReduceMailQueue();
2375
+			}
2376
+		} else
2249 2377
 		{
2250 2378
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2251 2379
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2296,8 +2424,9 @@  discard block
 block discarded – undo
2296 2424
 		foreach ($theme_includes as $include)
2297 2425
 		{
2298 2426
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2299
-			if (file_exists($include))
2300
-				require_once($include);
2427
+			if (file_exists($include)) {
2428
+							require_once($include);
2429
+			}
2301 2430
 		}
2302 2431
 	}
2303 2432
 
@@ -2327,16 +2456,19 @@  discard block
 block discarded – undo
2327 2456
 	// Do any style sheets first, cause we're easy with those.
2328 2457
 	if (!empty($style_sheets))
2329 2458
 	{
2330
-		if (!is_array($style_sheets))
2331
-			$style_sheets = array($style_sheets);
2459
+		if (!is_array($style_sheets)) {
2460
+					$style_sheets = array($style_sheets);
2461
+		}
2332 2462
 
2333
-		foreach ($style_sheets as $sheet)
2334
-			loadCSSFile($sheet . '.css', array(), $sheet);
2463
+		foreach ($style_sheets as $sheet) {
2464
+					loadCSSFile($sheet . '.css', array(), $sheet);
2465
+		}
2335 2466
 	}
2336 2467
 
2337 2468
 	// No template to load?
2338
-	if ($template_name === false)
2339
-		return true;
2469
+	if ($template_name === false) {
2470
+			return true;
2471
+	}
2340 2472
 
2341 2473
 	$loaded = false;
2342 2474
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2351,12 +2483,14 @@  discard block
 block discarded – undo
2351 2483
 
2352 2484
 	if ($loaded)
2353 2485
 	{
2354
-		if ($db_show_debug === true)
2355
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2486
+		if ($db_show_debug === true) {
2487
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2488
+		}
2356 2489
 
2357 2490
 		// If they have specified an initialization function for this template, go ahead and call it now.
2358
-		if (function_exists('template_' . $template_name . '_init'))
2359
-			call_user_func('template_' . $template_name . '_init');
2491
+		if (function_exists('template_' . $template_name . '_init')) {
2492
+					call_user_func('template_' . $template_name . '_init');
2493
+		}
2360 2494
 	}
2361 2495
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2362 2496
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2376,13 +2510,14 @@  discard block
 block discarded – undo
2376 2510
 		loadTemplate($template_name);
2377 2511
 	}
2378 2512
 	// Cause an error otherwise.
2379
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2380
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2381
-	elseif ($fatal)
2382
-		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'));
2383
-	else
2384
-		return false;
2385
-}
2513
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2514
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2515
+	} elseif ($fatal) {
2516
+			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'));
2517
+	} else {
2518
+			return false;
2519
+	}
2520
+	}
2386 2521
 
2387 2522
 /**
2388 2523
  * Load a sub-template.
@@ -2400,17 +2535,19 @@  discard block
 block discarded – undo
2400 2535
 {
2401 2536
 	global $context, $txt, $db_show_debug;
2402 2537
 
2403
-	if ($db_show_debug === true)
2404
-		$context['debug']['sub_templates'][] = $sub_template_name;
2538
+	if ($db_show_debug === true) {
2539
+			$context['debug']['sub_templates'][] = $sub_template_name;
2540
+	}
2405 2541
 
2406 2542
 	// Figure out what the template function is named.
2407 2543
 	$theme_function = 'template_' . $sub_template_name;
2408
-	if (function_exists($theme_function))
2409
-		$theme_function();
2410
-	elseif ($fatal === false)
2411
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2412
-	elseif ($fatal !== 'ignore')
2413
-		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'));
2544
+	if (function_exists($theme_function)) {
2545
+			$theme_function();
2546
+	} elseif ($fatal === false) {
2547
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2548
+	} elseif ($fatal !== 'ignore') {
2549
+			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'));
2550
+	}
2414 2551
 
2415 2552
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2416 2553
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2447,8 +2584,9 @@  discard block
 block discarded – undo
2447 2584
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2448 2585
 
2449 2586
 	// If this is an external file, automatically set this to false.
2450
-	if (!empty($params['external']))
2451
-		$params['minimize'] = false;
2587
+	if (!empty($params['external'])) {
2588
+			$params['minimize'] = false;
2589
+	}
2452 2590
 
2453 2591
 	// Account for shorthand like admin.css?alp21 filenames
2454 2592
 	$has_seed = strpos($fileName, '.css?');
@@ -2465,13 +2603,10 @@  discard block
 block discarded – undo
2465 2603
 			{
2466 2604
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2467 2605
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2606
+			} else {
2607
+							$fileUrl = false;
2468 2608
 			}
2469
-
2470
-			else
2471
-				$fileUrl = false;
2472
-		}
2473
-
2474
-		else
2609
+		} else
2475 2610
 		{
2476 2611
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2477 2612
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2486,12 +2621,14 @@  discard block
 block discarded – undo
2486 2621
 	}
2487 2622
 
2488 2623
 	// Add it to the array for use in the template
2489
-	if (!empty($fileName))
2490
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2624
+	if (!empty($fileName)) {
2625
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2626
+	}
2491 2627
 
2492
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2493
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2494
-}
2628
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2629
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2630
+	}
2631
+	}
2495 2632
 
2496 2633
 /**
2497 2634
  * Add a block of inline css code to be executed later
@@ -2508,8 +2645,9 @@  discard block
 block discarded – undo
2508 2645
 	global $context;
2509 2646
 
2510 2647
 	// Gotta add something...
2511
-	if (empty($css))
2512
-		return false;
2648
+	if (empty($css)) {
2649
+			return false;
2650
+	}
2513 2651
 
2514 2652
 	$context['css_header'][] = $css;
2515 2653
 }
@@ -2544,8 +2682,9 @@  discard block
 block discarded – undo
2544 2682
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2545 2683
 
2546 2684
 	// If this is an external file, automatically set this to false.
2547
-	if (!empty($params['external']))
2548
-		$params['minimize'] = false;
2685
+	if (!empty($params['external'])) {
2686
+			$params['minimize'] = false;
2687
+	}
2549 2688
 
2550 2689
 	// Account for shorthand like admin.js?alp21 filenames
2551 2690
 	$has_seed = strpos($fileName, '.js?');
@@ -2562,16 +2701,12 @@  discard block
 block discarded – undo
2562 2701
 			{
2563 2702
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2564 2703
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2565
-			}
2566
-
2567
-			else
2704
+			} else
2568 2705
 			{
2569 2706
 				$fileUrl = false;
2570 2707
 				$filePath = false;
2571 2708
 			}
2572
-		}
2573
-
2574
-		else
2709
+		} else
2575 2710
 		{
2576 2711
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2577 2712
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2586,9 +2721,10 @@  discard block
 block discarded – undo
2586 2721
 	}
2587 2722
 
2588 2723
 	// Add it to the array for use in the template
2589
-	if (!empty($fileName))
2590
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2591
-}
2724
+	if (!empty($fileName)) {
2725
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2726
+	}
2727
+	}
2592 2728
 
2593 2729
 /**
2594 2730
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2602,9 +2738,10 @@  discard block
 block discarded – undo
2602 2738
 {
2603 2739
 	global $context;
2604 2740
 
2605
-	if (!empty($key) && (!empty($value) || $value === '0'))
2606
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2607
-}
2741
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2742
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2743
+	}
2744
+	}
2608 2745
 
2609 2746
 /**
2610 2747
  * Add a block of inline Javascript code to be executed later
@@ -2621,8 +2758,9 @@  discard block
 block discarded – undo
2621 2758
 {
2622 2759
 	global $context;
2623 2760
 
2624
-	if (empty($javascript))
2625
-		return false;
2761
+	if (empty($javascript)) {
2762
+			return false;
2763
+	}
2626 2764
 
2627 2765
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2628 2766
 }
@@ -2643,15 +2781,18 @@  discard block
 block discarded – undo
2643 2781
 	static $already_loaded = array();
2644 2782
 
2645 2783
 	// Default to the user's language.
2646
-	if ($lang == '')
2647
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2784
+	if ($lang == '') {
2785
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2786
+	}
2648 2787
 
2649 2788
 	// Do we want the English version of language file as fallback?
2650
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2651
-		loadLanguage($template_name, 'english', false);
2789
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2790
+			loadLanguage($template_name, 'english', false);
2791
+	}
2652 2792
 
2653
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2654
-		return $lang;
2793
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2794
+			return $lang;
2795
+	}
2655 2796
 
2656 2797
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2657 2798
 	if (empty($settings['default_theme_dir']))
@@ -2662,8 +2803,9 @@  discard block
 block discarded – undo
2662 2803
 
2663 2804
 	// What theme are we in?
2664 2805
 	$theme_name = basename($settings['theme_url']);
2665
-	if (empty($theme_name))
2666
-		$theme_name = 'unknown';
2806
+	if (empty($theme_name)) {
2807
+			$theme_name = 'unknown';
2808
+	}
2667 2809
 
2668 2810
 	// For each file open it up and write it out!
2669 2811
 	foreach (explode('+', $template_name) as $template)
@@ -2705,8 +2847,9 @@  discard block
 block discarded – undo
2705 2847
 				$found = true;
2706 2848
 
2707 2849
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2708
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2709
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2850
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2851
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2852
+				}
2710 2853
 
2711 2854
 				break;
2712 2855
 			}
@@ -2746,8 +2889,9 @@  discard block
 block discarded – undo
2746 2889
 	}
2747 2890
 
2748 2891
 	// Keep track of what we're up to soldier.
2749
-	if ($db_show_debug === true)
2750
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2892
+	if ($db_show_debug === true) {
2893
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2894
+	}
2751 2895
 
2752 2896
 	// Remember what we have loaded, and in which language.
2753 2897
 	$already_loaded[$template_name] = $lang;
@@ -2793,8 +2937,9 @@  discard block
 block discarded – undo
2793 2937
 				)
2794 2938
 			);
2795 2939
 			// In the EXTREMELY unlikely event this happens, give an error message.
2796
-			if ($smcFunc['db_num_rows']($result) == 0)
2797
-				fatal_lang_error('parent_not_found', 'critical');
2940
+			if ($smcFunc['db_num_rows']($result) == 0) {
2941
+							fatal_lang_error('parent_not_found', 'critical');
2942
+			}
2798 2943
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2799 2944
 			{
2800 2945
 				if (!isset($boards[$row['id_board']]))
@@ -2811,8 +2956,8 @@  discard block
 block discarded – undo
2811 2956
 					);
2812 2957
 				}
2813 2958
 				// If a moderator exists for this board, add that moderator for all children too.
2814
-				if (!empty($row['id_moderator']))
2815
-					foreach ($boards as $id => $dummy)
2959
+				if (!empty($row['id_moderator'])) {
2960
+									foreach ($boards as $id => $dummy)
2816 2961
 					{
2817 2962
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2818 2963
 							'id' => $row['id_moderator'],
@@ -2820,11 +2965,12 @@  discard block
 block discarded – undo
2820 2965
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2821 2966
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2822 2967
 						);
2968
+				}
2823 2969
 					}
2824 2970
 
2825 2971
 				// If a moderator group exists for this board, add that moderator group for all children too
2826
-				if (!empty($row['id_moderator_group']))
2827
-					foreach ($boards as $id => $dummy)
2972
+				if (!empty($row['id_moderator_group'])) {
2973
+									foreach ($boards as $id => $dummy)
2828 2974
 					{
2829 2975
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2830 2976
 							'id' => $row['id_moderator_group'],
@@ -2832,6 +2978,7 @@  discard block
 block discarded – undo
2832 2978
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2833 2979
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2834 2980
 						);
2981
+				}
2835 2982
 					}
2836 2983
 			}
2837 2984
 			$smcFunc['db_free_result']($result);
@@ -2858,23 +3005,27 @@  discard block
 block discarded – undo
2858 3005
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2859 3006
 	{
2860 3007
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2861
-		if (empty($smcFunc['ucwords']))
2862
-			reloadSettings();
3008
+		if (empty($smcFunc['ucwords'])) {
3009
+					reloadSettings();
3010
+		}
2863 3011
 
2864 3012
 		// If we don't have our theme information yet, let's get it.
2865
-		if (empty($settings['default_theme_dir']))
2866
-			loadTheme(0, false);
3013
+		if (empty($settings['default_theme_dir'])) {
3014
+					loadTheme(0, false);
3015
+		}
2867 3016
 
2868 3017
 		// Default language directories to try.
2869 3018
 		$language_directories = array(
2870 3019
 			$settings['default_theme_dir'] . '/languages',
2871 3020
 		);
2872
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2873
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3021
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3022
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3023
+		}
2874 3024
 
2875 3025
 		// We possibly have a base theme directory.
2876
-		if (!empty($settings['base_theme_dir']))
2877
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3026
+		if (!empty($settings['base_theme_dir'])) {
3027
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3028
+		}
2878 3029
 
2879 3030
 		// Remove any duplicates.
2880 3031
 		$language_directories = array_unique($language_directories);
@@ -2888,20 +3039,21 @@  discard block
 block discarded – undo
2888 3039
 		foreach ($language_directories as $language_dir)
2889 3040
 		{
2890 3041
 			// Can't look in here... doesn't exist!
2891
-			if (!file_exists($language_dir))
2892
-				continue;
3042
+			if (!file_exists($language_dir)) {
3043
+							continue;
3044
+			}
2893 3045
 
2894 3046
 			$dir = dir($language_dir);
2895 3047
 			while ($entry = $dir->read())
2896 3048
 			{
2897 3049
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2898
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2899
-					continue;
2900
-
2901
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2902
-					$langName = $langList[$matches[1]];
3050
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3051
+									continue;
3052
+				}
2903 3053
 
2904
-				else
3054
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3055
+									$langName = $langList[$matches[1]];
3056
+				} else
2905 3057
 				{
2906 3058
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2907 3059
 
@@ -2942,12 +3094,14 @@  discard block
 block discarded – undo
2942 3094
 		}
2943 3095
 
2944 3096
 		// Do we need to store the lang list?
2945
-		if (empty($langList))
2946
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3097
+		if (empty($langList)) {
3098
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3099
+		}
2947 3100
 
2948 3101
 		// Let's cash in on this deal.
2949
-		if (!empty($modSettings['cache_enable']))
2950
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3102
+		if (!empty($modSettings['cache_enable'])) {
3103
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3104
+		}
2951 3105
 	}
2952 3106
 
2953 3107
 	return $context['languages'];
@@ -2970,8 +3124,9 @@  discard block
 block discarded – undo
2970 3124
 	global $modSettings, $options, $txt;
2971 3125
 	static $censor_vulgar = null, $censor_proper;
2972 3126
 
2973
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2974
-		return $text;
3127
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3128
+			return $text;
3129
+	}
2975 3130
 
2976 3131
 	// If they haven't yet been loaded, load them.
2977 3132
 	if ($censor_vulgar == null)
@@ -2999,9 +3154,9 @@  discard block
 block discarded – undo
2999 3154
 	{
3000 3155
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3001 3156
 		$text = $func($censor_vulgar, $censor_proper, $text);
3157
+	} else {
3158
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3002 3159
 	}
3003
-	else
3004
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3005 3160
 
3006 3161
 	return $text;
3007 3162
 }
@@ -3027,38 +3182,42 @@  discard block
 block discarded – undo
3027 3182
 	@ini_set('track_errors', '1');
3028 3183
 
3029 3184
 	// Don't include the file more than once, if $once is true.
3030
-	if ($once && in_array($filename, $templates))
3031
-		return;
3185
+	if ($once && in_array($filename, $templates)) {
3186
+			return;
3187
+	}
3032 3188
 	// Add this file to the include list, whether $once is true or not.
3033
-	else
3034
-		$templates[] = $filename;
3189
+	else {
3190
+			$templates[] = $filename;
3191
+	}
3035 3192
 
3036 3193
 	// Are we going to use eval?
3037 3194
 	if (empty($modSettings['disableTemplateEval']))
3038 3195
 	{
3039 3196
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
3040 3197
 		$settings['current_include_filename'] = $filename;
3041
-	}
3042
-	else
3198
+	} else
3043 3199
 	{
3044 3200
 		$file_found = file_exists($filename);
3045 3201
 
3046
-		if ($once && $file_found)
3047
-			require_once($filename);
3048
-		elseif ($file_found)
3049
-			require($filename);
3202
+		if ($once && $file_found) {
3203
+					require_once($filename);
3204
+		} elseif ($file_found) {
3205
+					require($filename);
3206
+		}
3050 3207
 	}
3051 3208
 
3052 3209
 	if ($file_found !== true)
3053 3210
 	{
3054 3211
 		ob_end_clean();
3055
-		if (!empty($modSettings['enableCompressedOutput']))
3056
-			@ob_start('ob_gzhandler');
3057
-		else
3058
-			ob_start();
3212
+		if (!empty($modSettings['enableCompressedOutput'])) {
3213
+					@ob_start('ob_gzhandler');
3214
+		} else {
3215
+					ob_start();
3216
+		}
3059 3217
 
3060
-		if (isset($_GET['debug']))
3061
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3218
+		if (isset($_GET['debug'])) {
3219
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3220
+		}
3062 3221
 
3063 3222
 		// Don't cache error pages!!
3064 3223
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3077,12 +3236,13 @@  discard block
 block discarded – undo
3077 3236
 		echo '<!DOCTYPE html>
3078 3237
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3079 3238
 	<head>';
3080
-		if (isset($context['character_set']))
3081
-			echo '
3239
+		if (isset($context['character_set'])) {
3240
+					echo '
3082 3241
 		<meta charset="', $context['character_set'], '">';
3242
+		}
3083 3243
 
3084
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3085
-			echo '
3244
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3245
+					echo '
3086 3246
 		<title>', $mtitle, '</title>
3087 3247
 	</head>
3088 3248
 	<body>
@@ -3090,8 +3250,8 @@  discard block
 block discarded – undo
3090 3250
 		', $mmessage, '
3091 3251
 	</body>
3092 3252
 </html>';
3093
-		elseif (!allowedTo('admin_forum'))
3094
-			echo '
3253
+		} elseif (!allowedTo('admin_forum')) {
3254
+					echo '
3095 3255
 		<title>', $txt['template_parse_error'], '</title>
3096 3256
 	</head>
3097 3257
 	<body>
@@ -3099,16 +3259,18 @@  discard block
 block discarded – undo
3099 3259
 		', $txt['template_parse_error_message'], '
3100 3260
 	</body>
3101 3261
 </html>';
3102
-		else
3262
+		} else
3103 3263
 		{
3104 3264
 			require_once($sourcedir . '/Subs-Package.php');
3105 3265
 
3106 3266
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3107 3267
 			$error_array = error_get_last();
3108
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3109
-				$error = $error_array['message'];
3110
-			if (empty($error))
3111
-				$error = $txt['template_parse_errmsg'];
3268
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3269
+							$error = $error_array['message'];
3270
+			}
3271
+			if (empty($error)) {
3272
+							$error = $txt['template_parse_errmsg'];
3273
+			}
3112 3274
 
3113 3275
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3114 3276
 
@@ -3119,11 +3281,12 @@  discard block
 block discarded – undo
3119 3281
 		<h3>', $txt['template_parse_error'], '</h3>
3120 3282
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3121 3283
 
3122
-			if (!empty($error))
3123
-				echo '
3284
+			if (!empty($error)) {
3285
+							echo '
3124 3286
 		<hr>
3125 3287
 
3126 3288
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3289
+			}
3127 3290
 
3128 3291
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3129 3292
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3133,10 +3296,11 @@  discard block
 block discarded – undo
3133 3296
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3134 3297
 
3135 3298
 				// Fix the PHP code stuff...
3136
-				if (!isBrowser('gecko'))
3137
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3138
-				else
3139
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3299
+				if (!isBrowser('gecko')) {
3300
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3301
+				} else {
3302
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3303
+				}
3140 3304
 
3141 3305
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3142 3306
 				$j = -1;
@@ -3144,8 +3308,9 @@  discard block
 block discarded – undo
3144 3308
 				{
3145 3309
 					$j++;
3146 3310
 
3147
-					if (substr_count($line, '<br>') == 0)
3148
-						continue;
3311
+					if (substr_count($line, '<br>') == 0) {
3312
+											continue;
3313
+					}
3149 3314
 
3150 3315
 					$n = substr_count($line, '<br>');
3151 3316
 					for ($i = 0; $i < $n; $i++)
@@ -3164,38 +3329,42 @@  discard block
 block discarded – undo
3164 3329
 				// Figure out what the color coding was before...
3165 3330
 				$line = max($match[1] - 9, 1);
3166 3331
 				$last_line = '';
3167
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3168
-					if (strpos($data2[$line2], '<') !== false)
3332
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3333
+									if (strpos($data2[$line2], '<') !== false)
3169 3334
 					{
3170 3335
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3171 3336
 							$last_line = $color_match[1];
3337
+				}
3172 3338
 						break;
3173 3339
 					}
3174 3340
 
3175 3341
 				// Show the relevant lines...
3176 3342
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3177 3343
 				{
3178
-					if ($line == $match[1])
3179
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3344
+					if ($line == $match[1]) {
3345
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3346
+					}
3180 3347
 
3181 3348
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3182
-					if (isset($data2[$line]) && $data2[$line] != '')
3183
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3349
+					if (isset($data2[$line]) && $data2[$line] != '') {
3350
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3351
+					}
3184 3352
 
3185 3353
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3186 3354
 					{
3187 3355
 						$last_line = $color_match[1];
3188 3356
 						echo '</', substr($last_line, 1, 4), '>';
3357
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3358
+											$last_line = '';
3359
+					} elseif ($last_line != '' && $data2[$line] != '') {
3360
+											echo '</', substr($last_line, 1, 4), '>';
3189 3361
 					}
3190
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3191
-						$last_line = '';
3192
-					elseif ($last_line != '' && $data2[$line] != '')
3193
-						echo '</', substr($last_line, 1, 4), '>';
3194 3362
 
3195
-					if ($line == $match[1])
3196
-						echo '</pre></div><pre style="margin: 0;">';
3197
-					else
3198
-						echo "\n";
3363
+					if ($line == $match[1]) {
3364
+											echo '</pre></div><pre style="margin: 0;">';
3365
+					} else {
3366
+											echo "\n";
3367
+					}
3199 3368
 				}
3200 3369
 
3201 3370
 				echo '</pre></div>';
@@ -3219,8 +3388,9 @@  discard block
 block discarded – undo
3219 3388
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3220 3389
 
3221 3390
 	// Figure out what type of database we are using.
3222
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3223
-		$db_type = 'mysql';
3391
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3392
+			$db_type = 'mysql';
3393
+	}
3224 3394
 
3225 3395
 	// Load the file for the database.
3226 3396
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3228,8 +3398,9 @@  discard block
 block discarded – undo
3228 3398
 	$db_options = array();
3229 3399
 
3230 3400
 	// Add in the port if needed
3231
-	if (!empty($db_port))
3232
-		$db_options['port'] = $db_port;
3401
+	if (!empty($db_port)) {
3402
+			$db_options['port'] = $db_port;
3403
+	}
3233 3404
 
3234 3405
 	// 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.
3235 3406
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3248,13 +3419,15 @@  discard block
 block discarded – undo
3248 3419
 	}
3249 3420
 
3250 3421
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3251
-	if (!$db_connection)
3252
-		display_db_error();
3422
+	if (!$db_connection) {
3423
+			display_db_error();
3424
+	}
3253 3425
 
3254 3426
 	// If in SSI mode fix up the prefix.
3255
-	if (SMF == 'SSI')
3256
-		db_fix_prefix($db_prefix, $db_name);
3257
-}
3427
+	if (SMF == 'SSI') {
3428
+			db_fix_prefix($db_prefix, $db_name);
3429
+	}
3430
+	}
3258 3431
 
3259 3432
 /**
3260 3433
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3268,10 +3441,11 @@  discard block
 block discarded – undo
3268 3441
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3269 3442
 
3270 3443
 	// Not overriding this and we have a cacheAPI, send it back.
3271
-	if (empty($overrideCache) && is_object($cacheAPI))
3272
-		return $cacheAPI;
3273
-	elseif (is_null($cacheAPI))
3274
-		$cacheAPI = false;
3444
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3445
+			return $cacheAPI;
3446
+	} elseif (is_null($cacheAPI)) {
3447
+			$cacheAPI = false;
3448
+	}
3275 3449
 
3276 3450
 	// Make sure our class is in session.
3277 3451
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3292,8 +3466,9 @@  discard block
 block discarded – undo
3292 3466
 		if (!$testAPI->isSupported())
3293 3467
 		{
3294 3468
 			// Can we save ourselves?
3295
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3296
-				return loadCacheAccelerator(null, false);
3469
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3470
+							return loadCacheAccelerator(null, false);
3471
+			}
3297 3472
 			return false;
3298 3473
 		}
3299 3474
 
@@ -3305,9 +3480,9 @@  discard block
 block discarded – undo
3305 3480
 		{
3306 3481
 			$cacheAPI = $testAPI;
3307 3482
 			return $cacheAPI;
3483
+		} else {
3484
+					return $testAPI;
3308 3485
 		}
3309
-		else
3310
-			return $testAPI;
3311 3486
 	}
3312 3487
 }
3313 3488
 
@@ -3327,8 +3502,9 @@  discard block
 block discarded – undo
3327 3502
 
3328 3503
 	// @todo Why are we doing this if caching is disabled?
3329 3504
 
3330
-	if (function_exists('call_integration_hook'))
3331
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3505
+	if (function_exists('call_integration_hook')) {
3506
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3507
+	}
3332 3508
 
3333 3509
 	/* Refresh the cache if either:
3334 3510
 		1. Caching is disabled.
@@ -3342,16 +3518,19 @@  discard block
 block discarded – undo
3342 3518
 		require_once($sourcedir . '/' . $file);
3343 3519
 		$cache_block = call_user_func_array($function, $params);
3344 3520
 
3345
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3346
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3521
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3522
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3523
+		}
3347 3524
 	}
3348 3525
 
3349 3526
 	// Some cached data may need a freshening up after retrieval.
3350
-	if (!empty($cache_block['post_retri_eval']))
3351
-		eval($cache_block['post_retri_eval']);
3527
+	if (!empty($cache_block['post_retri_eval'])) {
3528
+			eval($cache_block['post_retri_eval']);
3529
+	}
3352 3530
 
3353
-	if (function_exists('call_integration_hook'))
3354
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3531
+	if (function_exists('call_integration_hook')) {
3532
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3533
+	}
3355 3534
 
3356 3535
 	return $cache_block['data'];
3357 3536
 }
@@ -3378,8 +3557,9 @@  discard block
 block discarded – undo
3378 3557
 	global $smcFunc, $cache_enable, $cacheAPI;
3379 3558
 	global $cache_hits, $cache_count, $db_show_debug;
3380 3559
 
3381
-	if (empty($cache_enable) || empty($cacheAPI))
3382
-		return;
3560
+	if (empty($cache_enable) || empty($cacheAPI)) {
3561
+			return;
3562
+	}
3383 3563
 
3384 3564
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3385 3565
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3392,12 +3572,14 @@  discard block
 block discarded – undo
3392 3572
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3393 3573
 	$cacheAPI->putData($key, $value, $ttl);
3394 3574
 
3395
-	if (function_exists('call_integration_hook'))
3396
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3575
+	if (function_exists('call_integration_hook')) {
3576
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3577
+	}
3397 3578
 
3398
-	if (isset($db_show_debug) && $db_show_debug === true)
3399
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3400
-}
3579
+	if (isset($db_show_debug) && $db_show_debug === true) {
3580
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3581
+	}
3582
+	}
3401 3583
 
3402 3584
 /**
3403 3585
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3413,8 +3595,9 @@  discard block
 block discarded – undo
3413 3595
 	global $smcFunc, $cache_enable, $cacheAPI;
3414 3596
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3415 3597
 
3416
-	if (empty($cache_enable) || empty($cacheAPI))
3417
-		return;
3598
+	if (empty($cache_enable) || empty($cacheAPI)) {
3599
+			return;
3600
+	}
3418 3601
 
3419 3602
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3420 3603
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3434,16 +3617,18 @@  discard block
 block discarded – undo
3434 3617
 
3435 3618
 		if (empty($value))
3436 3619
 		{
3437
-			if (!is_array($cache_misses))
3438
-				$cache_misses = array();
3620
+			if (!is_array($cache_misses)) {
3621
+							$cache_misses = array();
3622
+			}
3439 3623
 
3440 3624
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3441 3625
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3442 3626
 		}
3443 3627
 	}
3444 3628
 
3445
-	if (function_exists('call_integration_hook') && isset($value))
3446
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3629
+	if (function_exists('call_integration_hook') && isset($value)) {
3630
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3631
+	}
3447 3632
 
3448 3633
 	return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3449 3634
 }
@@ -3465,8 +3650,9 @@  discard block
 block discarded – undo
3465 3650
 	global $cacheAPI;
3466 3651
 
3467 3652
 	// If we can't get to the API, can't do this.
3468
-	if (empty($cacheAPI))
3469
-		return;
3653
+	if (empty($cacheAPI)) {
3654
+			return;
3655
+	}
3470 3656
 
3471 3657
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3472 3658
 	$cacheAPI->cleanCache($type);
@@ -3491,8 +3677,9 @@  discard block
 block discarded – undo
3491 3677
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3492 3678
 
3493 3679
 	// Come on!
3494
-	if (empty($data))
3495
-		return array();
3680
+	if (empty($data)) {
3681
+			return array();
3682
+	}
3496 3683
 
3497 3684
 	// Set a nice default var.
3498 3685
 	$image = '';
@@ -3500,11 +3687,11 @@  discard block
 block discarded – undo
3500 3687
 	// Gravatar has been set as mandatory!
3501 3688
 	if (!empty($modSettings['gravatarOverride']))
3502 3689
 	{
3503
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3504
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3505
-
3506
-		else if (!empty($data['email']))
3507
-			$image = get_gravatar_url($data['email']);
3690
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3691
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3692
+		} else if (!empty($data['email'])) {
3693
+					$image = get_gravatar_url($data['email']);
3694
+		}
3508 3695
 	}
3509 3696
 
3510 3697
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3516,54 +3703,60 @@  discard block
 block discarded – undo
3516 3703
 			// Gravatar.
3517 3704
 			if (stristr($data['avatar'], 'gravatar://'))
3518 3705
 			{
3519
-				if ($data['avatar'] == 'gravatar://')
3520
-					$image = get_gravatar_url($data['email']);
3521
-
3522
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3523
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3706
+				if ($data['avatar'] == 'gravatar://') {
3707
+									$image = get_gravatar_url($data['email']);
3708
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3709
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3710
+				}
3524 3711
 			}
3525 3712
 
3526 3713
 			// External url.
3527 3714
 			else
3528 3715
 			{
3529 3716
 				// Using ssl?
3530
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3531
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3717
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3718
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3719
+				}
3532 3720
 
3533 3721
 				// Just a plain external url.
3534
-				else
3535
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3722
+				else {
3723
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3724
+				}
3536 3725
 			}
3537 3726
 		}
3538 3727
 
3539 3728
 		// Perhaps this user has an attachment as avatar...
3540
-		else if (!empty($data['filename']))
3541
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3729
+		else if (!empty($data['filename'])) {
3730
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3731
+		}
3542 3732
 
3543 3733
 		// Right... no avatar... use our default image.
3544
-		else
3545
-			$image = $modSettings['avatar_url'] . '/default.png';
3734
+		else {
3735
+					$image = $modSettings['avatar_url'] . '/default.png';
3736
+		}
3546 3737
 	}
3547 3738
 
3548 3739
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3549 3740
 
3550 3741
 	// 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.
3551
-	if (!empty($image))
3552
-		return array(
3742
+	if (!empty($image)) {
3743
+			return array(
3553 3744
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3554 3745
 			'image' => '<img class="avatar" src="' . $image . '" />',
3555 3746
 			'href' => $image,
3556 3747
 			'url' => $image,
3557 3748
 		);
3749
+	}
3558 3750
 
3559 3751
 	// Fallback to make life easier for everyone...
3560
-	else
3561
-		return array(
3752
+	else {
3753
+			return array(
3562 3754
 			'name' => '',
3563 3755
 			'image' => '',
3564 3756
 			'href' => '',
3565 3757
 			'url' => '',
3566 3758
 		);
3567
-}
3759
+	}
3760
+	}
3568 3761
 
3569 3762
 ?>
3570 3763
\ No newline at end of file
Please login to merge, or discard this patch.