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