Completed
Pull Request — release-2.1 (#3923)
by Fran
10:32
created
Sources/Load.php 1 patch
Braces   +795 added lines, -600 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;
@@ -1283,13 +1340,16 @@  discard block
 block discarded – undo
1283 1340
 			$row['avatar_original'] = $row['avatar'];
1284 1341
 
1285 1342
 			// Take care of proxying avatar if required, do this here for maximum reach
1286
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false)
1287
-				$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1343
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) {
1344
+							$row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret);
1345
+			}
1288 1346
 
1289
-			if (isset($row['member_ip']))
1290
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1291
-			if (isset($row['member_ip2']))
1292
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1347
+			if (isset($row['member_ip'])) {
1348
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1349
+			}
1350
+			if (isset($row['member_ip2'])) {
1351
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1352
+			}
1293 1353
 			$new_loaded_ids[] = $row['id_member'];
1294 1354
 			$loaded_ids[] = $row['id_member'];
1295 1355
 			$row['options'] = array();
@@ -1308,8 +1368,9 @@  discard block
 block discarded – undo
1308 1368
 				'loaded_ids' => $new_loaded_ids,
1309 1369
 			)
1310 1370
 		);
1311
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1312
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1371
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1372
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1373
+		}
1313 1374
 		$smcFunc['db_free_result']($request);
1314 1375
 	}
1315 1376
 
@@ -1320,10 +1381,11 @@  discard block
 block discarded – undo
1320 1381
 	{
1321 1382
 		foreach ($loaded_ids as $a_member)
1322 1383
 		{
1323
-			if (!empty($user_profile[$a_member]['additional_groups']))
1324
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1325
-			else
1326
-				$groups = array($user_profile[$a_member]['id_group']);
1384
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1385
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1386
+			} else {
1387
+							$groups = array($user_profile[$a_member]['id_group']);
1388
+			}
1327 1389
 
1328 1390
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1329 1391
 
@@ -1336,8 +1398,9 @@  discard block
 block discarded – undo
1336 1398
 
1337 1399
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1338 1400
 	{
1339
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1340
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1401
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1402
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1403
+		}
1341 1404
 	}
1342 1405
 
1343 1406
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1363,14 +1426,17 @@  discard block
 block discarded – undo
1363 1426
 		foreach ($temp_mods as $id)
1364 1427
 		{
1365 1428
 			// By popular demand, don't show admins or global moderators as moderators.
1366
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1367
-				$user_profile[$id]['member_group'] = $row['member_group'];
1429
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1430
+							$user_profile[$id]['member_group'] = $row['member_group'];
1431
+			}
1368 1432
 
1369 1433
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1370
-			if (!empty($row['icons']))
1371
-				$user_profile[$id]['icons'] = $row['icons'];
1372
-			if (!empty($row['member_group_color']))
1373
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1434
+			if (!empty($row['icons'])) {
1435
+							$user_profile[$id]['icons'] = $row['icons'];
1436
+			}
1437
+			if (!empty($row['member_group_color'])) {
1438
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1439
+			}
1374 1440
 		}
1375 1441
 	}
1376 1442
 
@@ -1392,12 +1458,14 @@  discard block
 block discarded – undo
1392 1458
 	static $loadedLanguages = array();
1393 1459
 
1394 1460
 	// If this person's data is already loaded, skip it.
1395
-	if (isset($dataLoaded[$user]))
1396
-		return true;
1461
+	if (isset($dataLoaded[$user])) {
1462
+			return true;
1463
+	}
1397 1464
 
1398 1465
 	// We can't load guests or members not loaded by loadMemberData()!
1399
-	if ($user == 0)
1400
-		return false;
1466
+	if ($user == 0) {
1467
+			return false;
1468
+	}
1401 1469
 	if (!isset($user_profile[$user]))
1402 1470
 	{
1403 1471
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1423,12 +1491,16 @@  discard block
 block discarded – undo
1423 1491
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1424 1492
 
1425 1493
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1426
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1494
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1495
+		//icon is set and exists
1427 1496
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1428
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1497
+	} elseif (isset($profile['icons'][1])) {
1498
+		//icon is set and doesn't exist, fallback to default
1429 1499
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1430
-	else //not set, bye bye
1500
+	} else {
1501
+		//not set, bye bye
1431 1502
 		$group_icon_url = '';
1503
+	}
1432 1504
 
1433 1505
 	// These minimal values are always loaded
1434 1506
 	$memberContext[$user] = array(
@@ -1447,8 +1519,9 @@  discard block
 block discarded – undo
1447 1519
 	if ($context['loadMemberContext_set'] != 'minimal')
1448 1520
 	{
1449 1521
 		// Go the extra mile and load the user's native language name.
1450
-		if (empty($loadedLanguages))
1451
-			$loadedLanguages = getLanguages();
1522
+		if (empty($loadedLanguages)) {
1523
+					$loadedLanguages = getLanguages();
1524
+		}
1452 1525
 
1453 1526
 		$memberContext[$user] += array(
1454 1527
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1502,31 +1575,33 @@  discard block
 block discarded – undo
1502 1575
 	{
1503 1576
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1504 1577
 		{
1505
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1506
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1507
-			else
1508
-				$image = get_gravatar_url($profile['email_address']);
1509
-		}
1510
-		else
1578
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1579
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1580
+			} else {
1581
+							$image = get_gravatar_url($profile['email_address']);
1582
+			}
1583
+		} else
1511 1584
 		{
1512 1585
 			// So it's stored in the member table?
1513 1586
 			if (!empty($profile['avatar']))
1514 1587
 			{
1515 1588
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1589
+			} elseif (!empty($profile['filename'])) {
1590
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1516 1591
 			}
1517
-			elseif (!empty($profile['filename']))
1518
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1519 1592
 			// Right... no avatar...use the default one
1520
-			else
1521
-				$image = $modSettings['avatar_url'] . '/default.png';
1593
+			else {
1594
+							$image = $modSettings['avatar_url'] . '/default.png';
1595
+			}
1522 1596
 		}
1523
-		if (!empty($image))
1524
-			$memberContext[$user]['avatar'] = array(
1597
+		if (!empty($image)) {
1598
+					$memberContext[$user]['avatar'] = array(
1525 1599
 				'name' => $profile['avatar'],
1526 1600
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1527 1601
 				'href' => $image,
1528 1602
 				'url' => $image,
1529 1603
 			);
1604
+		}
1530 1605
 	}
1531 1606
 
1532 1607
 	// Are we also loading the members custom fields into context?
@@ -1534,35 +1609,41 @@  discard block
 block discarded – undo
1534 1609
 	{
1535 1610
 		$memberContext[$user]['custom_fields'] = array();
1536 1611
 
1537
-		if (!isset($context['display_fields']))
1538
-			$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1612
+		if (!isset($context['display_fields'])) {
1613
+					$context['display_fields'] = smf_json_decode($modSettings['displayFields'], true);
1614
+		}
1539 1615
 
1540 1616
 		foreach ($context['display_fields'] as $custom)
1541 1617
 		{
1542
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1543
-				continue;
1618
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1619
+							continue;
1620
+			}
1544 1621
 
1545 1622
 			$value = $profile['options'][$custom['col_name']];
1546 1623
 
1547 1624
 			// Don't show the "disabled" option for the "gender" field.
1548
-			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled')
1549
-				continue;
1625
+			if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') {
1626
+							continue;
1627
+			}
1550 1628
 
1551 1629
 			// BBC?
1552
-			if ($custom['bbc'])
1553
-				$value = parse_bbc($value);
1630
+			if ($custom['bbc']) {
1631
+							$value = parse_bbc($value);
1632
+			}
1554 1633
 			// ... or checkbox?
1555
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1556
-				$value = $value ? $txt['yes'] : $txt['no'];
1634
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1635
+							$value = $value ? $txt['yes'] : $txt['no'];
1636
+			}
1557 1637
 
1558 1638
 			// Enclosing the user input within some other text?
1559
-			if (!empty($custom['enclose']))
1560
-				$value = strtr($custom['enclose'], array(
1639
+			if (!empty($custom['enclose'])) {
1640
+							$value = strtr($custom['enclose'], array(
1561 1641
 					'{SCRIPTURL}' => $scripturl,
1562 1642
 					'{IMAGES_URL}' => $settings['images_url'],
1563 1643
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1564 1644
 					'{INPUT}' => $value,
1565 1645
 				));
1646
+			}
1566 1647
 
1567 1648
 			$memberContext[$user]['custom_fields'][] = array(
1568 1649
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1589,8 +1670,9 @@  discard block
 block discarded – undo
1589 1670
 	global $smcFunc, $txt, $scripturl, $settings;
1590 1671
 
1591 1672
 	// Do not waste my time...
1592
-	if (empty($users) || empty($params))
1593
-		return false;
1673
+	if (empty($users) || empty($params)) {
1674
+			return false;
1675
+	}
1594 1676
 
1595 1677
 	// Make sure it's an array.
1596 1678
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1614,31 +1696,36 @@  discard block
 block discarded – undo
1614 1696
 	while ($row = $smcFunc['db_fetch_assoc']($request))
1615 1697
 	{
1616 1698
 		// BBC?
1617
-		if (!empty($row['bbc']))
1618
-			$row['value'] = parse_bbc($row['value']);
1699
+		if (!empty($row['bbc'])) {
1700
+					$row['value'] = parse_bbc($row['value']);
1701
+		}
1619 1702
 
1620 1703
 		// ... or checkbox?
1621
-		elseif (isset($row['type']) && $row['type'] == 'check')
1622
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1704
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1705
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1706
+		}
1623 1707
 
1624 1708
 		// Enclosing the user input within some other text?
1625
-		if (!empty($row['enclose']))
1626
-			$row['value'] = strtr($row['enclose'], array(
1709
+		if (!empty($row['enclose'])) {
1710
+					$row['value'] = strtr($row['enclose'], array(
1627 1711
 				'{SCRIPTURL}' => $scripturl,
1628 1712
 				'{IMAGES_URL}' => $settings['images_url'],
1629 1713
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1630 1714
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1631 1715
 			));
1716
+		}
1632 1717
 
1633 1718
 		// Send a simple array if there is just 1 param
1634
-		if (count($params) == 1)
1635
-			$return[$row['id_member']] = $row;
1719
+		if (count($params) == 1) {
1720
+					$return[$row['id_member']] = $row;
1721
+		}
1636 1722
 
1637 1723
 		// More than 1? knock yourself out...
1638 1724
 		else
1639 1725
 		{
1640
-			if (!isset($return[$row['id_member']]))
1641
-				$return[$row['id_member']] = array();
1726
+			if (!isset($return[$row['id_member']])) {
1727
+							$return[$row['id_member']] = array();
1728
+			}
1642 1729
 
1643 1730
 			$return[$row['id_member']][$row['variable']] = $row;
1644 1731
 		}
@@ -1672,8 +1759,9 @@  discard block
 block discarded – undo
1672 1759
 	global $context;
1673 1760
 
1674 1761
 	// Don't know any browser!
1675
-	if (empty($context['browser']))
1676
-		detectBrowser();
1762
+	if (empty($context['browser'])) {
1763
+			detectBrowser();
1764
+	}
1677 1765
 
1678 1766
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1679 1767
 }
@@ -1691,8 +1779,9 @@  discard block
 block discarded – undo
1691 1779
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1692 1780
 
1693 1781
 	// The theme was specified by parameter.
1694
-	if (!empty($id_theme))
1695
-		$id_theme = (int) $id_theme;
1782
+	if (!empty($id_theme)) {
1783
+			$id_theme = (int) $id_theme;
1784
+	}
1696 1785
 	// The theme was specified by REQUEST.
1697 1786
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1698 1787
 	{
@@ -1700,51 +1789,58 @@  discard block
 block discarded – undo
1700 1789
 		$_SESSION['id_theme'] = $id_theme;
1701 1790
 	}
1702 1791
 	// The theme was specified by REQUEST... previously.
1703
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1704
-		$id_theme = (int) $_SESSION['id_theme'];
1792
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1793
+			$id_theme = (int) $_SESSION['id_theme'];
1794
+	}
1705 1795
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1706
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1707
-		$id_theme = $user_info['theme'];
1796
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1797
+			$id_theme = $user_info['theme'];
1798
+	}
1708 1799
 	// The theme was specified by the board.
1709
-	elseif (!empty($board_info['theme']))
1710
-		$id_theme = $board_info['theme'];
1800
+	elseif (!empty($board_info['theme'])) {
1801
+			$id_theme = $board_info['theme'];
1802
+	}
1711 1803
 	// The theme is the forum's default.
1712
-	else
1713
-		$id_theme = $modSettings['theme_guests'];
1804
+	else {
1805
+			$id_theme = $modSettings['theme_guests'];
1806
+	}
1714 1807
 
1715 1808
 	// Verify the id_theme... no foul play.
1716 1809
 	// Always allow the board specific theme, if they are overriding.
1717
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1718
-		$id_theme = $board_info['theme'];
1810
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1811
+			$id_theme = $board_info['theme'];
1812
+	}
1719 1813
 	// If they have specified a particular theme to use with SSI allow it to be used.
1720
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1721
-		$id_theme = (int) $id_theme;
1722
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1814
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1815
+			$id_theme = (int) $id_theme;
1816
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1723 1817
 	{
1724 1818
 		$themes = explode(',', $modSettings['enableThemes']);
1725
-		if (!in_array($id_theme, $themes))
1726
-			$id_theme = $modSettings['theme_guests'];
1727
-		else
1819
+		if (!in_array($id_theme, $themes)) {
1820
+					$id_theme = $modSettings['theme_guests'];
1821
+		} else {
1822
+					$id_theme = (int) $id_theme;
1823
+		}
1824
+	} else {
1728 1825
 			$id_theme = (int) $id_theme;
1729 1826
 	}
1730
-	else
1731
-		$id_theme = (int) $id_theme;
1732 1827
 
1733 1828
 	$member = empty($user_info['id']) ? -1 : $user_info['id'];
1734 1829
 
1735 1830
 	// Disable image proxy if we don't have SSL enabled
1736
-	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2)
1737
-		$image_proxy_enabled = false;
1831
+	if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) {
1832
+			$image_proxy_enabled = false;
1833
+	}
1738 1834
 
1739 1835
 	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'])
1740 1836
 	{
1741 1837
 		$themeData = $temp;
1742 1838
 		$flag = true;
1839
+	} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1840
+			$themeData = $temp + array($member => array());
1841
+	} else {
1842
+			$themeData = array(-1 => array(), 0 => array(), $member => array());
1743 1843
 	}
1744
-	elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1745
-		$themeData = $temp + array($member => array());
1746
-	else
1747
-		$themeData = array(-1 => array(), 0 => array(), $member => array());
1748 1844
 
1749 1845
 	if (empty($flag))
1750 1846
 	{
@@ -1763,31 +1859,37 @@  discard block
 block discarded – undo
1763 1859
 		while ($row = $smcFunc['db_fetch_assoc']($result))
1764 1860
 		{
1765 1861
 			// There are just things we shouldn't be able to change as members.
1766
-			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')))
1767
-				continue;
1862
+			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'))) {
1863
+							continue;
1864
+			}
1768 1865
 
1769 1866
 			// If this is the theme_dir of the default theme, store it.
1770
-			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1771
-				$themeData[0]['default_' . $row['variable']] = $row['value'];
1867
+			if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1868
+							$themeData[0]['default_' . $row['variable']] = $row['value'];
1869
+			}
1772 1870
 
1773 1871
 			// If this isn't set yet, is a theme option, or is not the default theme..
1774
-			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1775
-				$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1872
+			if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1873
+							$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1874
+			}
1776 1875
 		}
1777 1876
 		$smcFunc['db_free_result']($result);
1778 1877
 
1779
-		if (!empty($themeData[-1]))
1780
-			foreach ($themeData[-1] as $k => $v)
1878
+		if (!empty($themeData[-1])) {
1879
+					foreach ($themeData[-1] as $k => $v)
1781 1880
 			{
1782 1881
 				if (!isset($themeData[$member][$k]))
1783 1882
 					$themeData[$member][$k] = $v;
1883
+		}
1784 1884
 			}
1785 1885
 
1786
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1787
-			cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1886
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1887
+					cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1888
+		}
1788 1889
 		// Only if we didn't already load that part of the cache...
1789
-		elseif (!isset($temp))
1790
-			cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1890
+		elseif (!isset($temp)) {
1891
+					cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1892
+		}
1791 1893
 	}
1792 1894
 
1793 1895
 	$settings = $themeData[0];
@@ -1804,20 +1906,24 @@  discard block
 block discarded – undo
1804 1906
 	$settings['template_dirs'][] = $settings['theme_dir'];
1805 1907
 
1806 1908
 	// Based on theme (if there is one).
1807
-	if (!empty($settings['base_theme_dir']))
1808
-		$settings['template_dirs'][] = $settings['base_theme_dir'];
1909
+	if (!empty($settings['base_theme_dir'])) {
1910
+			$settings['template_dirs'][] = $settings['base_theme_dir'];
1911
+	}
1809 1912
 
1810 1913
 	// Lastly the default theme.
1811
-	if ($settings['theme_dir'] != $settings['default_theme_dir'])
1812
-		$settings['template_dirs'][] = $settings['default_theme_dir'];
1914
+	if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1915
+			$settings['template_dirs'][] = $settings['default_theme_dir'];
1916
+	}
1813 1917
 
1814
-	if (!$initialize)
1815
-		return;
1918
+	if (!$initialize) {
1919
+			return;
1920
+	}
1816 1921
 
1817 1922
 	// Check to see if we're forcing SSL
1818 1923
 	if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) &&
1819
-		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI')
1820
-		redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1924
+		(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') {
1925
+			redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://')));
1926
+	}
1821 1927
 
1822 1928
 	// Check to see if they're accessing it from the wrong place.
1823 1929
 	if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']))
@@ -1825,8 +1931,9 @@  discard block
 block discarded – undo
1825 1931
 		$detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
1826 1932
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1827 1933
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1828
-		if ($temp != '/')
1829
-			$detected_url .= $temp;
1934
+		if ($temp != '/') {
1935
+					$detected_url .= $temp;
1936
+		}
1830 1937
 	}
1831 1938
 	if (isset($detected_url) && $detected_url != $boardurl)
1832 1939
 	{
@@ -1838,8 +1945,9 @@  discard block
 block discarded – undo
1838 1945
 			foreach ($aliases as $alias)
1839 1946
 			{
1840 1947
 				// Rip off all the boring parts, spaces, etc.
1841
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1842
-					$do_fix = true;
1948
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1949
+									$do_fix = true;
1950
+				}
1843 1951
 			}
1844 1952
 		}
1845 1953
 
@@ -1847,20 +1955,22 @@  discard block
 block discarded – undo
1847 1955
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1848 1956
 		{
1849 1957
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1850
-			if (empty($_GET))
1851
-				redirectexit('wwwRedirect');
1852
-			else
1958
+			if (empty($_GET)) {
1959
+							redirectexit('wwwRedirect');
1960
+			} else
1853 1961
 			{
1854 1962
 				list ($k, $v) = each($_GET);
1855 1963
 
1856
-				if ($k != 'wwwRedirect')
1857
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1964
+				if ($k != 'wwwRedirect') {
1965
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1966
+				}
1858 1967
 			}
1859 1968
 		}
1860 1969
 
1861 1970
 		// #3 is just a check for SSL...
1862
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1863
-			$do_fix = true;
1971
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1972
+					$do_fix = true;
1973
+		}
1864 1974
 
1865 1975
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1866 1976
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1894,8 +2004,9 @@  discard block
 block discarded – undo
1894 2004
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1895 2005
 				}
1896 2006
 			}
1897
-			foreach ($context['linktree'] as $k => $dummy)
1898
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2007
+			foreach ($context['linktree'] as $k => $dummy) {
2008
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2009
+			}
1899 2010
 		}
1900 2011
 	}
1901 2012
 	// Set up the contextual user array.
@@ -1914,16 +2025,16 @@  discard block
 block discarded – undo
1914 2025
 			'email' => $user_info['email'],
1915 2026
 			'ignoreusers' => $user_info['ignoreusers'],
1916 2027
 		);
1917
-		if (!$context['user']['is_guest'])
1918
-			$context['user']['name'] = $user_info['name'];
1919
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1920
-			$context['user']['name'] = $txt['guest_title'];
2028
+		if (!$context['user']['is_guest']) {
2029
+					$context['user']['name'] = $user_info['name'];
2030
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2031
+					$context['user']['name'] = $txt['guest_title'];
2032
+		}
1921 2033
 
1922 2034
 		// Determine the current smiley set.
1923 2035
 		$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'];
1924 2036
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1925
-	}
1926
-	else
2037
+	} else
1927 2038
 	{
1928 2039
 		$context['user'] = array(
1929 2040
 			'id' => -1,
@@ -1939,18 +2050,24 @@  discard block
 block discarded – undo
1939 2050
 	}
1940 2051
 
1941 2052
 	// Some basic information...
1942
-	if (!isset($context['html_headers']))
1943
-		$context['html_headers'] = '';
1944
-	if (!isset($context['javascript_files']))
1945
-		$context['javascript_files'] = array();
1946
-	if (!isset($context['css_files']))
1947
-		$context['css_files'] = array();
1948
-	if (!isset($context['css_header']))
1949
-		$context['css_header'] = array();
1950
-	if (!isset($context['javascript_inline']))
1951
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1952
-	if (!isset($context['javascript_vars']))
1953
-		$context['javascript_vars'] = array();
2053
+	if (!isset($context['html_headers'])) {
2054
+			$context['html_headers'] = '';
2055
+	}
2056
+	if (!isset($context['javascript_files'])) {
2057
+			$context['javascript_files'] = array();
2058
+	}
2059
+	if (!isset($context['css_files'])) {
2060
+			$context['css_files'] = array();
2061
+	}
2062
+	if (!isset($context['css_header'])) {
2063
+			$context['css_header'] = array();
2064
+	}
2065
+	if (!isset($context['javascript_inline'])) {
2066
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2067
+	}
2068
+	if (!isset($context['javascript_vars'])) {
2069
+			$context['javascript_vars'] = array();
2070
+	}
1954 2071
 
1955 2072
 	$context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2';
1956 2073
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -1962,8 +2079,9 @@  discard block
 block discarded – undo
1962 2079
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
1963 2080
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
1964 2081
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
1965
-	if (isset($modSettings['load_average']))
1966
-		$context['load_average'] = $modSettings['load_average'];
2082
+	if (isset($modSettings['load_average'])) {
2083
+			$context['load_average'] = $modSettings['load_average'];
2084
+	}
1967 2085
 
1968 2086
 	// Detect the browser. This is separated out because it's also used in attachment downloads
1969 2087
 	detectBrowser();
@@ -1977,8 +2095,9 @@  discard block
 block discarded – undo
1977 2095
 	// This allows sticking some HTML on the page output - useful for controls.
1978 2096
 	$context['insert_after_template'] = '';
1979 2097
 
1980
-	if (!isset($txt))
1981
-		$txt = array();
2098
+	if (!isset($txt)) {
2099
+			$txt = array();
2100
+	}
1982 2101
 
1983 2102
 	$simpleActions = array(
1984 2103
 		'findmember',
@@ -2024,9 +2143,10 @@  discard block
 block discarded – undo
2024 2143
 
2025 2144
 	// See if theres any extra param to check.
2026 2145
 	$requiresXML = false;
2027
-	foreach ($extraParams as $key => $extra)
2028
-		if (isset($_REQUEST[$extra]))
2146
+	foreach ($extraParams as $key => $extra) {
2147
+			if (isset($_REQUEST[$extra]))
2029 2148
 			$requiresXML = true;
2149
+	}
2030 2150
 
2031 2151
 	// Output is fully XML, so no need for the index template.
2032 2152
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2041,37 +2161,39 @@  discard block
 block discarded – undo
2041 2161
 	{
2042 2162
 		loadLanguage('index+Modifications');
2043 2163
 		$context['template_layers'] = array();
2044
-	}
2045
-
2046
-	else
2164
+	} else
2047 2165
 	{
2048 2166
 		// Custom templates to load, or just default?
2049
-		if (isset($settings['theme_templates']))
2050
-			$templates = explode(',', $settings['theme_templates']);
2051
-		else
2052
-			$templates = array('index');
2167
+		if (isset($settings['theme_templates'])) {
2168
+					$templates = explode(',', $settings['theme_templates']);
2169
+		} else {
2170
+					$templates = array('index');
2171
+		}
2053 2172
 
2054 2173
 		// Load each template...
2055
-		foreach ($templates as $template)
2056
-			loadTemplate($template);
2174
+		foreach ($templates as $template) {
2175
+					loadTemplate($template);
2176
+		}
2057 2177
 
2058 2178
 		// ...and attempt to load their associated language files.
2059 2179
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2060 2180
 		loadLanguage($required_files, '', false);
2061 2181
 
2062 2182
 		// Custom template layers?
2063
-		if (isset($settings['theme_layers']))
2064
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2065
-		else
2066
-			$context['template_layers'] = array('html', 'body');
2183
+		if (isset($settings['theme_layers'])) {
2184
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2185
+		} else {
2186
+					$context['template_layers'] = array('html', 'body');
2187
+		}
2067 2188
 	}
2068 2189
 
2069 2190
 	// Initialize the theme.
2070 2191
 	loadSubTemplate('init', 'ignore');
2071 2192
 
2072 2193
 	// Allow overriding the board wide time/number formats.
2073
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2074
-		$user_info['time_format'] = $txt['time_format'];
2194
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2195
+			$user_info['time_format'] = $txt['time_format'];
2196
+	}
2075 2197
 
2076 2198
 	// Set the character set from the template.
2077 2199
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2079,12 +2201,14 @@  discard block
 block discarded – undo
2079 2201
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2080 2202
 
2081 2203
 	// Guests may still need a name.
2082
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2083
-		$context['user']['name'] = $txt['guest_title'];
2204
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2205
+			$context['user']['name'] = $txt['guest_title'];
2206
+	}
2084 2207
 
2085 2208
 	// Any theme-related strings that need to be loaded?
2086
-	if (!empty($settings['require_theme_strings']))
2087
-		loadLanguage('ThemeStrings', '', false);
2209
+	if (!empty($settings['require_theme_strings'])) {
2210
+			loadLanguage('ThemeStrings', '', false);
2211
+	}
2088 2212
 
2089 2213
 	// Make a special URL for the language.
2090 2214
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2095,8 +2219,9 @@  discard block
 block discarded – undo
2095 2219
 	// Here is my luvly Responsive CSS
2096 2220
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive');
2097 2221
 
2098
-	if ($context['right_to_left'])
2099
-		loadCSSFile('rtl.css', array(), 'smf_rtl');
2222
+	if ($context['right_to_left']) {
2223
+			loadCSSFile('rtl.css', array(), 'smf_rtl');
2224
+	}
2100 2225
 
2101 2226
 	// We allow theme variants, because we're cool.
2102 2227
 	$context['theme_variant'] = '';
@@ -2104,14 +2229,17 @@  discard block
 block discarded – undo
2104 2229
 	if (!empty($settings['theme_variants']))
2105 2230
 	{
2106 2231
 		// Overriding - for previews and that ilk.
2107
-		if (!empty($_REQUEST['variant']))
2108
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2232
+		if (!empty($_REQUEST['variant'])) {
2233
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2234
+		}
2109 2235
 		// User selection?
2110
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2111
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2236
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2237
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2238
+		}
2112 2239
 		// If not a user variant, select the default.
2113
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2114
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2240
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2241
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2242
+		}
2115 2243
 
2116 2244
 		// Do this to keep things easier in the templates.
2117 2245
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2120,20 +2248,23 @@  discard block
 block discarded – undo
2120 2248
 		if (!empty($context['theme_variant']))
2121 2249
 		{
2122 2250
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']);
2123
-			if ($context['right_to_left'])
2124
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2251
+			if ($context['right_to_left']) {
2252
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']);
2253
+			}
2125 2254
 		}
2126 2255
 	}
2127 2256
 
2128 2257
 	// Let's be compatible with old themes!
2129
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2130
-		$context['template_layers'] = array('main');
2258
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2259
+			$context['template_layers'] = array('main');
2260
+	}
2131 2261
 
2132 2262
 	$context['tabindex'] = 1;
2133 2263
 
2134 2264
 	// Compatibility.
2135
-	if (!isset($settings['theme_version']))
2136
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2265
+	if (!isset($settings['theme_version'])) {
2266
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2267
+	}
2137 2268
 
2138 2269
 	// Default JS variables for use in every theme
2139 2270
 	$context['javascript_vars'] = array(
@@ -2152,18 +2283,18 @@  discard block
 block discarded – undo
2152 2283
 	);
2153 2284
 
2154 2285
 	// Add the JQuery library to the list of files to load.
2155
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2156
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2157
-
2158
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2159
-		loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2160
-
2161
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2162
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2286
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2287
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2288
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2289
+			loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery');
2290
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2291
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2292
+	}
2163 2293
 
2164 2294
 	// Auto loading? template_javascript() will take care of the local half of this.
2165
-	else
2166
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2295
+	else {
2296
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery');
2297
+	}
2167 2298
 
2168 2299
 	// Queue our JQuery plugins!
2169 2300
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2186,12 +2317,12 @@  discard block
 block discarded – undo
2186 2317
 			require_once($sourcedir . '/ScheduledTasks.php');
2187 2318
 
2188 2319
 			// What to do, what to do?!
2189
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2190
-				AutoTask();
2191
-			else
2192
-				ReduceMailQueue();
2193
-		}
2194
-		else
2320
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2321
+							AutoTask();
2322
+			} else {
2323
+							ReduceMailQueue();
2324
+			}
2325
+		} else
2195 2326
 		{
2196 2327
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2197 2328
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2242,8 +2373,9 @@  discard block
 block discarded – undo
2242 2373
 		foreach ($theme_includes as $include)
2243 2374
 		{
2244 2375
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2245
-			if (file_exists($include))
2246
-				require_once($include);
2376
+			if (file_exists($include)) {
2377
+							require_once($include);
2378
+			}
2247 2379
 		}
2248 2380
 	}
2249 2381
 
@@ -2273,16 +2405,19 @@  discard block
 block discarded – undo
2273 2405
 	// Do any style sheets first, cause we're easy with those.
2274 2406
 	if (!empty($style_sheets))
2275 2407
 	{
2276
-		if (!is_array($style_sheets))
2277
-			$style_sheets = array($style_sheets);
2408
+		if (!is_array($style_sheets)) {
2409
+					$style_sheets = array($style_sheets);
2410
+		}
2278 2411
 
2279
-		foreach ($style_sheets as $sheet)
2280
-			loadCSSFile($sheet . '.css', array(), $sheet);
2412
+		foreach ($style_sheets as $sheet) {
2413
+					loadCSSFile($sheet . '.css', array(), $sheet);
2414
+		}
2281 2415
 	}
2282 2416
 
2283 2417
 	// No template to load?
2284
-	if ($template_name === false)
2285
-		return true;
2418
+	if ($template_name === false) {
2419
+			return true;
2420
+	}
2286 2421
 
2287 2422
 	$loaded = false;
2288 2423
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2297,12 +2432,14 @@  discard block
 block discarded – undo
2297 2432
 
2298 2433
 	if ($loaded)
2299 2434
 	{
2300
-		if ($db_show_debug === true)
2301
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2435
+		if ($db_show_debug === true) {
2436
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2437
+		}
2302 2438
 
2303 2439
 		// If they have specified an initialization function for this template, go ahead and call it now.
2304
-		if (function_exists('template_' . $template_name . '_init'))
2305
-			call_user_func('template_' . $template_name . '_init');
2440
+		if (function_exists('template_' . $template_name . '_init')) {
2441
+					call_user_func('template_' . $template_name . '_init');
2442
+		}
2306 2443
 	}
2307 2444
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2308 2445
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2322,13 +2459,14 @@  discard block
 block discarded – undo
2322 2459
 		loadTemplate($template_name);
2323 2460
 	}
2324 2461
 	// Cause an error otherwise.
2325
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2326
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2327
-	elseif ($fatal)
2328
-		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'));
2329
-	else
2330
-		return false;
2331
-}
2462
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2463
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2464
+	} elseif ($fatal) {
2465
+			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'));
2466
+	} else {
2467
+			return false;
2468
+	}
2469
+	}
2332 2470
 
2333 2471
 /**
2334 2472
  * Load a sub-template.
@@ -2346,17 +2484,19 @@  discard block
 block discarded – undo
2346 2484
 {
2347 2485
 	global $context, $txt, $db_show_debug;
2348 2486
 
2349
-	if ($db_show_debug === true)
2350
-		$context['debug']['sub_templates'][] = $sub_template_name;
2487
+	if ($db_show_debug === true) {
2488
+			$context['debug']['sub_templates'][] = $sub_template_name;
2489
+	}
2351 2490
 
2352 2491
 	// Figure out what the template function is named.
2353 2492
 	$theme_function = 'template_' . $sub_template_name;
2354
-	if (function_exists($theme_function))
2355
-		$theme_function();
2356
-	elseif ($fatal === false)
2357
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2358
-	elseif ($fatal !== 'ignore')
2359
-		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'));
2493
+	if (function_exists($theme_function)) {
2494
+			$theme_function();
2495
+	} elseif ($fatal === false) {
2496
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2497
+	} elseif ($fatal !== 'ignore') {
2498
+			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'));
2499
+	}
2360 2500
 
2361 2501
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2362 2502
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2393,8 +2533,9 @@  discard block
 block discarded – undo
2393 2533
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2394 2534
 
2395 2535
 	// If this is an external file, automatically set this to false.
2396
-	if (!empty($params['external']))
2397
-		$params['minimize'] = false;
2536
+	if (!empty($params['external'])) {
2537
+			$params['minimize'] = false;
2538
+	}
2398 2539
 
2399 2540
 	// Account for shorthand like admin.css?alp21 filenames
2400 2541
 	$has_seed = strpos($fileName, '.css?');
@@ -2411,13 +2552,10 @@  discard block
 block discarded – undo
2411 2552
 			{
2412 2553
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2413 2554
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2555
+			} else {
2556
+							$fileUrl = false;
2414 2557
 			}
2415
-
2416
-			else
2417
-				$fileUrl = false;
2418
-		}
2419
-
2420
-		else
2558
+		} else
2421 2559
 		{
2422 2560
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2423 2561
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2432,12 +2570,14 @@  discard block
 block discarded – undo
2432 2570
 	}
2433 2571
 
2434 2572
 	// Add it to the array for use in the template
2435
-	if (!empty($fileName))
2436
-		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2573
+	if (!empty($fileName)) {
2574
+			$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2575
+	}
2437 2576
 
2438
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2439
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2440
-}
2577
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2578
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2579
+	}
2580
+	}
2441 2581
 
2442 2582
 /**
2443 2583
  * Add a block of inline css code to be executed later
@@ -2454,8 +2594,9 @@  discard block
 block discarded – undo
2454 2594
 	global $context;
2455 2595
 
2456 2596
 	// Gotta add something...
2457
-	if (empty($css))
2458
-		return false;
2597
+	if (empty($css)) {
2598
+			return false;
2599
+	}
2459 2600
 
2460 2601
 	$context['css_header'][] = $css;
2461 2602
 }
@@ -2490,8 +2631,9 @@  discard block
 block discarded – undo
2490 2631
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2491 2632
 
2492 2633
 	// If this is an external file, automatically set this to false.
2493
-	if (!empty($params['external']))
2494
-		$params['minimize'] = false;
2634
+	if (!empty($params['external'])) {
2635
+			$params['minimize'] = false;
2636
+	}
2495 2637
 
2496 2638
 	// Account for shorthand like admin.js?alp21 filenames
2497 2639
 	$has_seed = strpos($fileName, '.js?');
@@ -2508,16 +2650,12 @@  discard block
 block discarded – undo
2508 2650
 			{
2509 2651
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2510 2652
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2511
-			}
2512
-
2513
-			else
2653
+			} else
2514 2654
 			{
2515 2655
 				$fileUrl = false;
2516 2656
 				$filePath = false;
2517 2657
 			}
2518
-		}
2519
-
2520
-		else
2658
+		} else
2521 2659
 		{
2522 2660
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2523 2661
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2532,9 +2670,10 @@  discard block
 block discarded – undo
2532 2670
 	}
2533 2671
 
2534 2672
 	// Add it to the array for use in the template
2535
-	if (!empty($fileName))
2536
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2537
-}
2673
+	if (!empty($fileName)) {
2674
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2675
+	}
2676
+	}
2538 2677
 
2539 2678
 /**
2540 2679
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2548,9 +2687,10 @@  discard block
 block discarded – undo
2548 2687
 {
2549 2688
 	global $context;
2550 2689
 
2551
-	if (!empty($key) && (!empty($value) || $value === '0'))
2552
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2553
-}
2690
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2691
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2692
+	}
2693
+	}
2554 2694
 
2555 2695
 /**
2556 2696
  * Add a block of inline Javascript code to be executed later
@@ -2567,8 +2707,9 @@  discard block
 block discarded – undo
2567 2707
 {
2568 2708
 	global $context;
2569 2709
 
2570
-	if (empty($javascript))
2571
-		return false;
2710
+	if (empty($javascript)) {
2711
+			return false;
2712
+	}
2572 2713
 
2573 2714
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2574 2715
 }
@@ -2589,15 +2730,18 @@  discard block
 block discarded – undo
2589 2730
 	static $already_loaded = array();
2590 2731
 
2591 2732
 	// Default to the user's language.
2592
-	if ($lang == '')
2593
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2733
+	if ($lang == '') {
2734
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2735
+	}
2594 2736
 
2595 2737
 	// Do we want the English version of language file as fallback?
2596
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2597
-		loadLanguage($template_name, 'english', false);
2738
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2739
+			loadLanguage($template_name, 'english', false);
2740
+	}
2598 2741
 
2599
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2600
-		return $lang;
2742
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2743
+			return $lang;
2744
+	}
2601 2745
 
2602 2746
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2603 2747
 	if (empty($settings['default_theme_dir']))
@@ -2608,8 +2752,9 @@  discard block
 block discarded – undo
2608 2752
 
2609 2753
 	// What theme are we in?
2610 2754
 	$theme_name = basename($settings['theme_url']);
2611
-	if (empty($theme_name))
2612
-		$theme_name = 'unknown';
2755
+	if (empty($theme_name)) {
2756
+			$theme_name = 'unknown';
2757
+	}
2613 2758
 
2614 2759
 	// For each file open it up and write it out!
2615 2760
 	foreach (explode('+', $template_name) as $template)
@@ -2688,8 +2833,9 @@  discard block
 block discarded – undo
2688 2833
 	}
2689 2834
 
2690 2835
 	// Keep track of what we're up to soldier.
2691
-	if ($db_show_debug === true)
2692
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2836
+	if ($db_show_debug === true) {
2837
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2838
+	}
2693 2839
 
2694 2840
 	// Remember what we have loaded, and in which language.
2695 2841
 	$already_loaded[$template_name] = $lang;
@@ -2735,8 +2881,9 @@  discard block
 block discarded – undo
2735 2881
 				)
2736 2882
 			);
2737 2883
 			// In the EXTREMELY unlikely event this happens, give an error message.
2738
-			if ($smcFunc['db_num_rows']($result) == 0)
2739
-				fatal_lang_error('parent_not_found', 'critical');
2884
+			if ($smcFunc['db_num_rows']($result) == 0) {
2885
+							fatal_lang_error('parent_not_found', 'critical');
2886
+			}
2740 2887
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2741 2888
 			{
2742 2889
 				if (!isset($boards[$row['id_board']]))
@@ -2753,8 +2900,8 @@  discard block
 block discarded – undo
2753 2900
 					);
2754 2901
 				}
2755 2902
 				// If a moderator exists for this board, add that moderator for all children too.
2756
-				if (!empty($row['id_moderator']))
2757
-					foreach ($boards as $id => $dummy)
2903
+				if (!empty($row['id_moderator'])) {
2904
+									foreach ($boards as $id => $dummy)
2758 2905
 					{
2759 2906
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2760 2907
 							'id' => $row['id_moderator'],
@@ -2762,11 +2909,12 @@  discard block
 block discarded – undo
2762 2909
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2763 2910
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2764 2911
 						);
2912
+				}
2765 2913
 					}
2766 2914
 
2767 2915
 				// If a moderator group exists for this board, add that moderator group for all children too
2768
-				if (!empty($row['id_moderator_group']))
2769
-					foreach ($boards as $id => $dummy)
2916
+				if (!empty($row['id_moderator_group'])) {
2917
+									foreach ($boards as $id => $dummy)
2770 2918
 					{
2771 2919
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2772 2920
 							'id' => $row['id_moderator_group'],
@@ -2774,6 +2922,7 @@  discard block
 block discarded – undo
2774 2922
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2775 2923
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2776 2924
 						);
2925
+				}
2777 2926
 					}
2778 2927
 			}
2779 2928
 			$smcFunc['db_free_result']($result);
@@ -2800,23 +2949,27 @@  discard block
 block discarded – undo
2800 2949
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2801 2950
 	{
2802 2951
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2803
-		if (empty($smcFunc['ucwords']))
2804
-			reloadSettings();
2952
+		if (empty($smcFunc['ucwords'])) {
2953
+					reloadSettings();
2954
+		}
2805 2955
 
2806 2956
 		// If we don't have our theme information yet, let's get it.
2807
-		if (empty($settings['default_theme_dir']))
2808
-			loadTheme(0, false);
2957
+		if (empty($settings['default_theme_dir'])) {
2958
+					loadTheme(0, false);
2959
+		}
2809 2960
 
2810 2961
 		// Default language directories to try.
2811 2962
 		$language_directories = array(
2812 2963
 			$settings['default_theme_dir'] . '/languages',
2813 2964
 		);
2814
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2815
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2965
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
2966
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
2967
+		}
2816 2968
 
2817 2969
 		// We possibly have a base theme directory.
2818
-		if (!empty($settings['base_theme_dir']))
2819
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
2970
+		if (!empty($settings['base_theme_dir'])) {
2971
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
2972
+		}
2820 2973
 
2821 2974
 		// Remove any duplicates.
2822 2975
 		$language_directories = array_unique($language_directories);
@@ -2830,20 +2983,21 @@  discard block
 block discarded – undo
2830 2983
 		foreach ($language_directories as $language_dir)
2831 2984
 		{
2832 2985
 			// Can't look in here... doesn't exist!
2833
-			if (!file_exists($language_dir))
2834
-				continue;
2986
+			if (!file_exists($language_dir)) {
2987
+							continue;
2988
+			}
2835 2989
 
2836 2990
 			$dir = dir($language_dir);
2837 2991
 			while ($entry = $dir->read())
2838 2992
 			{
2839 2993
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2840
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2841
-					continue;
2842
-
2843
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2844
-					$langName = $langList[$matches[1]];
2994
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
2995
+									continue;
2996
+				}
2845 2997
 
2846
-				else
2998
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
2999
+									$langName = $langList[$matches[1]];
3000
+				} else
2847 3001
 				{
2848 3002
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2849 3003
 
@@ -2884,12 +3038,14 @@  discard block
 block discarded – undo
2884 3038
 		}
2885 3039
 
2886 3040
 		// Do we need to store the lang list?
2887
-		if (empty($langList))
2888
-			updateSettings(array('langList' => json_encode($catchLang)));
3041
+		if (empty($langList)) {
3042
+					updateSettings(array('langList' => json_encode($catchLang)));
3043
+		}
2889 3044
 
2890 3045
 		// Let's cash in on this deal.
2891
-		if (!empty($modSettings['cache_enable']))
2892
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3046
+		if (!empty($modSettings['cache_enable'])) {
3047
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3048
+		}
2893 3049
 	}
2894 3050
 
2895 3051
 	return $context['languages'];
@@ -2912,8 +3068,9 @@  discard block
 block discarded – undo
2912 3068
 	global $modSettings, $options, $txt;
2913 3069
 	static $censor_vulgar = null, $censor_proper;
2914 3070
 
2915
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2916
-		return $text;
3071
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3072
+			return $text;
3073
+	}
2917 3074
 
2918 3075
 	// If they haven't yet been loaded, load them.
2919 3076
 	if ($censor_vulgar == null)
@@ -2941,9 +3098,9 @@  discard block
 block discarded – undo
2941 3098
 	{
2942 3099
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
2943 3100
 		$text = $func($censor_vulgar, $censor_proper, $text);
3101
+	} else {
3102
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
2944 3103
 	}
2945
-	else
2946
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
2947 3104
 
2948 3105
 	return $text;
2949 3106
 }
@@ -2969,38 +3126,42 @@  discard block
 block discarded – undo
2969 3126
 	@ini_set('track_errors', '1');
2970 3127
 
2971 3128
 	// Don't include the file more than once, if $once is true.
2972
-	if ($once && in_array($filename, $templates))
2973
-		return;
3129
+	if ($once && in_array($filename, $templates)) {
3130
+			return;
3131
+	}
2974 3132
 	// Add this file to the include list, whether $once is true or not.
2975
-	else
2976
-		$templates[] = $filename;
3133
+	else {
3134
+			$templates[] = $filename;
3135
+	}
2977 3136
 
2978 3137
 	// Are we going to use eval?
2979 3138
 	if (empty($modSettings['disableTemplateEval']))
2980 3139
 	{
2981 3140
 		$file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false;
2982 3141
 		$settings['current_include_filename'] = $filename;
2983
-	}
2984
-	else
3142
+	} else
2985 3143
 	{
2986 3144
 		$file_found = file_exists($filename);
2987 3145
 
2988
-		if ($once && $file_found)
2989
-			require_once($filename);
2990
-		elseif ($file_found)
2991
-			require($filename);
3146
+		if ($once && $file_found) {
3147
+					require_once($filename);
3148
+		} elseif ($file_found) {
3149
+					require($filename);
3150
+		}
2992 3151
 	}
2993 3152
 
2994 3153
 	if ($file_found !== true)
2995 3154
 	{
2996 3155
 		ob_end_clean();
2997
-		if (!empty($modSettings['enableCompressedOutput']))
2998
-			@ob_start('ob_gzhandler');
2999
-		else
3000
-			ob_start();
3156
+		if (!empty($modSettings['enableCompressedOutput'])) {
3157
+					@ob_start('ob_gzhandler');
3158
+		} else {
3159
+					ob_start();
3160
+		}
3001 3161
 
3002
-		if (isset($_GET['debug']))
3003
-			header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3162
+		if (isset($_GET['debug'])) {
3163
+					header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3164
+		}
3004 3165
 
3005 3166
 		// Don't cache error pages!!
3006 3167
 		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3019,12 +3180,13 @@  discard block
 block discarded – undo
3019 3180
 		echo '<!DOCTYPE html>
3020 3181
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3021 3182
 	<head>';
3022
-		if (isset($context['character_set']))
3023
-			echo '
3183
+		if (isset($context['character_set'])) {
3184
+					echo '
3024 3185
 		<meta charset="', $context['character_set'], '">';
3186
+		}
3025 3187
 
3026
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3027
-			echo '
3188
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3189
+					echo '
3028 3190
 		<title>', $mtitle, '</title>
3029 3191
 	</head>
3030 3192
 	<body>
@@ -3032,8 +3194,8 @@  discard block
 block discarded – undo
3032 3194
 		', $mmessage, '
3033 3195
 	</body>
3034 3196
 </html>';
3035
-		elseif (!allowedTo('admin_forum'))
3036
-			echo '
3197
+		} elseif (!allowedTo('admin_forum')) {
3198
+					echo '
3037 3199
 		<title>', $txt['template_parse_error'], '</title>
3038 3200
 	</head>
3039 3201
 	<body>
@@ -3041,15 +3203,17 @@  discard block
 block discarded – undo
3041 3203
 		', $txt['template_parse_error_message'], '
3042 3204
 	</body>
3043 3205
 </html>';
3044
-		else
3206
+		} else
3045 3207
 		{
3046 3208
 			require_once($sourcedir . '/Subs-Package.php');
3047 3209
 
3048 3210
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3049
-			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg))
3050
-				$error = $php_errormsg;
3051
-			if (empty($error))
3052
-				$error = $txt['template_parse_errmsg'];
3211
+			if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) {
3212
+							$error = $php_errormsg;
3213
+			}
3214
+			if (empty($error)) {
3215
+							$error = $txt['template_parse_errmsg'];
3216
+			}
3053 3217
 
3054 3218
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3055 3219
 
@@ -3060,11 +3224,12 @@  discard block
 block discarded – undo
3060 3224
 		<h3>', $txt['template_parse_error'], '</h3>
3061 3225
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3062 3226
 
3063
-			if (!empty($error))
3064
-				echo '
3227
+			if (!empty($error)) {
3228
+							echo '
3065 3229
 		<hr>
3066 3230
 
3067 3231
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3232
+			}
3068 3233
 
3069 3234
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3070 3235
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3074,10 +3239,11 @@  discard block
 block discarded – undo
3074 3239
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3075 3240
 
3076 3241
 				// Fix the PHP code stuff...
3077
-				if (!isBrowser('gecko'))
3078
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3079
-				else
3080
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3242
+				if (!isBrowser('gecko')) {
3243
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3244
+				} else {
3245
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3246
+				}
3081 3247
 
3082 3248
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3083 3249
 				$j = -1;
@@ -3085,8 +3251,9 @@  discard block
 block discarded – undo
3085 3251
 				{
3086 3252
 					$j++;
3087 3253
 
3088
-					if (substr_count($line, '<br>') == 0)
3089
-						continue;
3254
+					if (substr_count($line, '<br>') == 0) {
3255
+											continue;
3256
+					}
3090 3257
 
3091 3258
 					$n = substr_count($line, '<br>');
3092 3259
 					for ($i = 0; $i < $n; $i++)
@@ -3105,38 +3272,42 @@  discard block
 block discarded – undo
3105 3272
 				// Figure out what the color coding was before...
3106 3273
 				$line = max($match[1] - 9, 1);
3107 3274
 				$last_line = '';
3108
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3109
-					if (strpos($data2[$line2], '<') !== false)
3275
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3276
+									if (strpos($data2[$line2], '<') !== false)
3110 3277
 					{
3111 3278
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3112 3279
 							$last_line = $color_match[1];
3280
+				}
3113 3281
 						break;
3114 3282
 					}
3115 3283
 
3116 3284
 				// Show the relevant lines...
3117 3285
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3118 3286
 				{
3119
-					if ($line == $match[1])
3120
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3287
+					if ($line == $match[1]) {
3288
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3289
+					}
3121 3290
 
3122 3291
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3123
-					if (isset($data2[$line]) && $data2[$line] != '')
3124
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3292
+					if (isset($data2[$line]) && $data2[$line] != '') {
3293
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3294
+					}
3125 3295
 
3126 3296
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3127 3297
 					{
3128 3298
 						$last_line = $color_match[1];
3129 3299
 						echo '</', substr($last_line, 1, 4), '>';
3300
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3301
+											$last_line = '';
3302
+					} elseif ($last_line != '' && $data2[$line] != '') {
3303
+											echo '</', substr($last_line, 1, 4), '>';
3130 3304
 					}
3131
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3132
-						$last_line = '';
3133
-					elseif ($last_line != '' && $data2[$line] != '')
3134
-						echo '</', substr($last_line, 1, 4), '>';
3135 3305
 
3136
-					if ($line == $match[1])
3137
-						echo '</pre></div><pre style="margin: 0;">';
3138
-					else
3139
-						echo "\n";
3306
+					if ($line == $match[1]) {
3307
+											echo '</pre></div><pre style="margin: 0;">';
3308
+					} else {
3309
+											echo "\n";
3310
+					}
3140 3311
 				}
3141 3312
 
3142 3313
 				echo '</pre></div>';
@@ -3160,8 +3331,9 @@  discard block
 block discarded – undo
3160 3331
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3161 3332
 
3162 3333
 	// Figure out what type of database we are using.
3163
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3164
-		$db_type = 'mysql';
3334
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3335
+			$db_type = 'mysql';
3336
+	}
3165 3337
 
3166 3338
 	// Load the file for the database.
3167 3339
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3169,8 +3341,9 @@  discard block
 block discarded – undo
3169 3341
 	$db_options = array();
3170 3342
 
3171 3343
 	// Add in the port if needed
3172
-	if (!empty($db_port))
3173
-		$db_options['port'] = $db_port;
3344
+	if (!empty($db_port)) {
3345
+			$db_options['port'] = $db_port;
3346
+	}
3174 3347
 
3175 3348
 	// 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.
3176 3349
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3189,13 +3362,15 @@  discard block
 block discarded – undo
3189 3362
 	}
3190 3363
 
3191 3364
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3192
-	if (!$db_connection)
3193
-		display_db_error();
3365
+	if (!$db_connection) {
3366
+			display_db_error();
3367
+	}
3194 3368
 
3195 3369
 	// If in SSI mode fix up the prefix.
3196
-	if (SMF == 'SSI')
3197
-		db_fix_prefix($db_prefix, $db_name);
3198
-}
3370
+	if (SMF == 'SSI') {
3371
+			db_fix_prefix($db_prefix, $db_name);
3372
+	}
3373
+	}
3199 3374
 
3200 3375
 /**
3201 3376
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3209,10 +3384,11 @@  discard block
 block discarded – undo
3209 3384
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3210 3385
 
3211 3386
 	// Not overriding this and we have a cacheAPI, send it back.
3212
-	if (empty($overrideCache) && is_object($cacheAPI))
3213
-		return $cacheAPI;
3214
-	elseif (is_null($cacheAPI))
3215
-		$cacheAPI = false;
3387
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3388
+			return $cacheAPI;
3389
+	} elseif (is_null($cacheAPI)) {
3390
+			$cacheAPI = false;
3391
+	}
3216 3392
 
3217 3393
 	// Make sure our class is in session.
3218 3394
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3233,8 +3409,9 @@  discard block
 block discarded – undo
3233 3409
 		if (!$testAPI->isSupported())
3234 3410
 		{
3235 3411
 			// Can we save ourselves?
3236
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3237
-				return loadCacheAccelerator(null, false);
3412
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3413
+							return loadCacheAccelerator(null, false);
3414
+			}
3238 3415
 			return false;
3239 3416
 		}
3240 3417
 
@@ -3246,9 +3423,9 @@  discard block
 block discarded – undo
3246 3423
 		{
3247 3424
 			$cacheAPI = $testAPI;
3248 3425
 			return $cacheAPI;
3426
+		} else {
3427
+					return $testAPI;
3249 3428
 		}
3250
-		else
3251
-			return $testAPI;
3252 3429
 	}
3253 3430
 }
3254 3431
 
@@ -3268,8 +3445,9 @@  discard block
 block discarded – undo
3268 3445
 
3269 3446
 	// @todo Why are we doing this if caching is disabled?
3270 3447
 
3271
-	if (function_exists('call_integration_hook'))
3272
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3448
+	if (function_exists('call_integration_hook')) {
3449
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3450
+	}
3273 3451
 
3274 3452
 	/* Refresh the cache if either:
3275 3453
 		1. Caching is disabled.
@@ -3283,16 +3461,19 @@  discard block
 block discarded – undo
3283 3461
 		require_once($sourcedir . '/' . $file);
3284 3462
 		$cache_block = call_user_func_array($function, $params);
3285 3463
 
3286
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3287
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3464
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3465
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3466
+		}
3288 3467
 	}
3289 3468
 
3290 3469
 	// Some cached data may need a freshening up after retrieval.
3291
-	if (!empty($cache_block['post_retri_eval']))
3292
-		eval($cache_block['post_retri_eval']);
3470
+	if (!empty($cache_block['post_retri_eval'])) {
3471
+			eval($cache_block['post_retri_eval']);
3472
+	}
3293 3473
 
3294
-	if (function_exists('call_integration_hook'))
3295
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3474
+	if (function_exists('call_integration_hook')) {
3475
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3476
+	}
3296 3477
 
3297 3478
 	return $cache_block['data'];
3298 3479
 }
@@ -3319,8 +3500,9 @@  discard block
 block discarded – undo
3319 3500
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3320 3501
 	global $cache_hits, $cache_count, $db_show_debug;
3321 3502
 
3322
-	if (empty($cache_enable) || empty($cacheAPI))
3323
-		return;
3503
+	if (empty($cache_enable) || empty($cacheAPI)) {
3504
+			return;
3505
+	}
3324 3506
 
3325 3507
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3326 3508
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3333,12 +3515,14 @@  discard block
 block discarded – undo
3333 3515
 	$value = $value === null ? null : json_encode($value);
3334 3516
 	$cacheAPI->putData($key, $value, $ttl);
3335 3517
 
3336
-	if (function_exists('call_integration_hook'))
3337
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3518
+	if (function_exists('call_integration_hook')) {
3519
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3520
+	}
3338 3521
 
3339
-	if (isset($db_show_debug) && $db_show_debug === true)
3340
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3341
-}
3522
+	if (isset($db_show_debug) && $db_show_debug === true) {
3523
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3524
+	}
3525
+	}
3342 3526
 
3343 3527
 /**
3344 3528
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3354,8 +3538,9 @@  discard block
 block discarded – undo
3354 3538
 	global $boardurl, $modSettings, $cache_enable, $cacheAPI;
3355 3539
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3356 3540
 
3357
-	if (empty($cache_enable) || empty($cacheAPI))
3358
-		return;
3541
+	if (empty($cache_enable) || empty($cacheAPI)) {
3542
+			return;
3543
+	}
3359 3544
 
3360 3545
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3361 3546
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3375,16 +3560,18 @@  discard block
 block discarded – undo
3375 3560
 
3376 3561
 		if (empty($value))
3377 3562
 		{
3378
-			if (!is_array($cache_misses))
3379
-				$cache_misses = array();
3563
+			if (!is_array($cache_misses)) {
3564
+							$cache_misses = array();
3565
+			}
3380 3566
 
3381 3567
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3382 3568
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3383 3569
 		}
3384 3570
 	}
3385 3571
 
3386
-	if (function_exists('call_integration_hook') && isset($value))
3387
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3572
+	if (function_exists('call_integration_hook') && isset($value)) {
3573
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3574
+	}
3388 3575
 
3389 3576
 	return empty($value) ? null : smf_json_decode($value, true);
3390 3577
 }
@@ -3406,8 +3593,9 @@  discard block
 block discarded – undo
3406 3593
 	global $cacheAPI;
3407 3594
 
3408 3595
 	// If we can't get to the API, can't do this.
3409
-	if (empty($cacheAPI))
3410
-		return;
3596
+	if (empty($cacheAPI)) {
3597
+			return;
3598
+	}
3411 3599
 
3412 3600
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3413 3601
 	$cacheAPI->cleanCache($type);
@@ -3432,8 +3620,9 @@  discard block
 block discarded – undo
3432 3620
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret;
3433 3621
 
3434 3622
 	// Come on!
3435
-	if (empty($data))
3436
-		return array();
3623
+	if (empty($data)) {
3624
+			return array();
3625
+	}
3437 3626
 
3438 3627
 	// Set a nice default var.
3439 3628
 	$image = '';
@@ -3441,11 +3630,11 @@  discard block
 block discarded – undo
3441 3630
 	// Gravatar has been set as mandatory!
3442 3631
 	if (!empty($modSettings['gravatarOverride']))
3443 3632
 	{
3444
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3445
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3446
-
3447
-		else if (!empty($data['email']))
3448
-			$image = get_gravatar_url($data['email']);
3633
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3634
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3635
+		} else if (!empty($data['email'])) {
3636
+					$image = get_gravatar_url($data['email']);
3637
+		}
3449 3638
 	}
3450 3639
 
3451 3640
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3457,54 +3646,60 @@  discard block
 block discarded – undo
3457 3646
 			// Gravatar.
3458 3647
 			if (stristr($data['avatar'], 'gravatar://'))
3459 3648
 			{
3460
-				if ($data['avatar'] == 'gravatar://')
3461
-					$image = get_gravatar_url($data['email']);
3462
-
3463
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3464
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3649
+				if ($data['avatar'] == 'gravatar://') {
3650
+									$image = get_gravatar_url($data['email']);
3651
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3652
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3653
+				}
3465 3654
 			}
3466 3655
 
3467 3656
 			// External url.
3468 3657
 			else
3469 3658
 			{
3470 3659
 				// Using ssl?
3471
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false)
3472
-					$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3660
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) {
3661
+									$image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret);
3662
+				}
3473 3663
 
3474 3664
 				// Just a plain external url.
3475
-				else
3476
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3665
+				else {
3666
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3667
+				}
3477 3668
 			}
3478 3669
 		}
3479 3670
 
3480 3671
 		// Perhaps this user has an attachment as avatar...
3481
-		else if (!empty($data['filename']))
3482
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3672
+		else if (!empty($data['filename'])) {
3673
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3674
+		}
3483 3675
 
3484 3676
 		// Right... no avatar... use our default image.
3485
-		else
3486
-			$image = $modSettings['avatar_url'] . '/default.png';
3677
+		else {
3678
+					$image = $modSettings['avatar_url'] . '/default.png';
3679
+		}
3487 3680
 	}
3488 3681
 
3489 3682
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3490 3683
 
3491 3684
 	// 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.
3492
-	if (!empty($image))
3493
-		return array(
3685
+	if (!empty($image)) {
3686
+			return array(
3494 3687
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3495 3688
 			'image' => '<img class="avatar" src="' . $image . '" />',
3496 3689
 			'href' => $image,
3497 3690
 			'url' => $image,
3498 3691
 		);
3692
+	}
3499 3693
 
3500 3694
 	// Fallback to make life easier for everyone...
3501
-	else
3502
-		return array(
3695
+	else {
3696
+			return array(
3503 3697
 			'name' => '',
3504 3698
 			'image' => '',
3505 3699
 			'href' => '',
3506 3700
 			'url' => '',
3507 3701
 		);
3508
-}
3702
+	}
3703
+	}
3509 3704
 
3510 3705
 ?>
3511 3706
\ No newline at end of file
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +867 added lines, -635 removed lines patch added patch discarded remove patch
@@ -81,8 +81,9 @@  discard block
 block discarded – undo
81 81
 $upcontext['inactive_timeout'] = 10;
82 82
 
83 83
 // The helper is crucial. Include it first thing.
84
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
84
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
85 85
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
86
+}
86 87
 
87 88
 require_once($upgrade_path . '/upgrade-helper.php');
88 89
 
@@ -106,11 +107,14 @@  discard block
 block discarded – undo
106 107
 	ini_set('default_socket_timeout', 900);
107 108
 }
108 109
 // Clean the upgrade path if this is from the client.
109
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
110
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
110
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
111
+	for ($i = 1;
112
+}
113
+$i < $_SERVER['argc']; $i++)
111 114
 	{
112
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
113
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
115
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
116
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
117
+		}
114 118
 	}
115 119
 
116 120
 // Are we from the client?
@@ -118,16 +122,17 @@  discard block
 block discarded – undo
118 122
 {
119 123
 	$command_line = true;
120 124
 	$disable_security = true;
121
-}
122
-else
125
+} else {
123 126
 	$command_line = false;
127
+}
124 128
 
125 129
 // Load this now just because we can.
126 130
 require_once($upgrade_path . '/Settings.php');
127 131
 
128 132
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
129
-if (isset($language))
133
+if (isset($language)) {
130 134
 	$language = str_ireplace('-utf8', '', $language);
135
+}
131 136
 
132 137
 // Are we logged in?
133 138
 if (isset($upgradeData))
@@ -135,10 +140,12 @@  discard block
 block discarded – undo
135 140
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
136 141
 
137 142
 	// Check for sensible values.
138
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
139
-		$upcontext['user']['started'] = time();
140
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
141
-		$upcontext['user']['updated'] = 0;
143
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
144
+			$upcontext['user']['started'] = time();
145
+	}
146
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
147
+			$upcontext['user']['updated'] = 0;
148
+	}
142 149
 
143 150
 	$upcontext['started'] = $upcontext['user']['started'];
144 151
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -196,8 +203,9 @@  discard block
 block discarded – undo
196 203
 			'db_error_skip' => true,
197 204
 		)
198 205
 	);
199
-	while ($row = $smcFunc['db_fetch_assoc']($request))
200
-		$modSettings[$row['variable']] = $row['value'];
206
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
207
+			$modSettings[$row['variable']] = $row['value'];
208
+	}
201 209
 	$smcFunc['db_free_result']($request);
202 210
 }
203 211
 
@@ -207,10 +215,12 @@  discard block
 block discarded – undo
207 215
 	$modSettings['theme_url'] = 'Themes/default';
208 216
 	$modSettings['images_url'] = 'Themes/default/images';
209 217
 }
210
-if (!isset($settings['default_theme_url']))
218
+if (!isset($settings['default_theme_url'])) {
211 219
 	$settings['default_theme_url'] = $modSettings['theme_url'];
212
-if (!isset($settings['default_theme_dir']))
220
+}
221
+if (!isset($settings['default_theme_dir'])) {
213 222
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
223
+}
214 224
 
215 225
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
216 226
 // Default title...
@@ -228,13 +238,15 @@  discard block
 block discarded – undo
228 238
 	$support_js = $upcontext['upgrade_status']['js'];
229 239
 
230 240
 	// Only set this if the upgrader status says so.
231
-	if (empty($is_debug))
232
-		$is_debug = $upcontext['upgrade_status']['debug'];
241
+	if (empty($is_debug)) {
242
+			$is_debug = $upcontext['upgrade_status']['debug'];
243
+	}
233 244
 
234 245
 	// Load the language.
235
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
236
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
237
-}
246
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
247
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
248
+	}
249
+	}
238 250
 // Set the defaults.
239 251
 else
240 252
 {
@@ -252,15 +264,18 @@  discard block
 block discarded – undo
252 264
 }
253 265
 
254 266
 // If this isn't the first stage see whether they are logging in and resuming.
255
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
267
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
256 268
 	checkLogin();
269
+}
257 270
 
258
-if ($command_line)
271
+if ($command_line) {
259 272
 	cmdStep0();
273
+}
260 274
 
261 275
 // Don't error if we're using xml.
262
-if (isset($_GET['xml']))
276
+if (isset($_GET['xml'])) {
263 277
 	$upcontext['return_error'] = true;
278
+}
264 279
 
265 280
 // Loop through all the steps doing each one as required.
266 281
 $upcontext['overall_percent'] = 0;
@@ -281,10 +296,11 @@  discard block
 block discarded – undo
281 296
 		}
282 297
 
283 298
 		// Call the step and if it returns false that means pause!
284
-		if (function_exists($step[2]) && $step[2]() === false)
285
-			break;
286
-		elseif (function_exists($step[2]))
287
-			$upcontext['current_step']++;
299
+		if (function_exists($step[2]) && $step[2]() === false) {
300
+					break;
301
+		} elseif (function_exists($step[2])) {
302
+					$upcontext['current_step']++;
303
+		}
288 304
 	}
289 305
 	$upcontext['overall_percent'] += $step[3];
290 306
 }
@@ -323,17 +339,18 @@  discard block
 block discarded – undo
323 339
 		// This should not happen my dear... HELP ME DEVELOPERS!!
324 340
 		if (!empty($command_line))
325 341
 		{
326
-			if (function_exists('debug_print_backtrace'))
327
-				debug_print_backtrace();
342
+			if (function_exists('debug_print_backtrace')) {
343
+							debug_print_backtrace();
344
+			}
328 345
 
329 346
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
330 347
 			flush();
331 348
 			die();
332 349
 		}
333 350
 
334
-		if (!isset($_GET['xml']))
335
-			template_upgrade_above();
336
-		else
351
+		if (!isset($_GET['xml'])) {
352
+					template_upgrade_above();
353
+		} else
337 354
 		{
338 355
 			header('Content-Type: text/xml; charset=UTF-8');
339 356
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -355,21 +372,24 @@  discard block
 block discarded – undo
355 372
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
356 373
 
357 374
 			// Custom stuff to pass back?
358
-			if (!empty($upcontext['query_string']))
359
-				$upcontext['form_url'] .= $upcontext['query_string'];
375
+			if (!empty($upcontext['query_string'])) {
376
+							$upcontext['form_url'] .= $upcontext['query_string'];
377
+			}
360 378
 
361 379
 			call_user_func('template_' . $upcontext['sub_template']);
362 380
 		}
363 381
 
364 382
 		// Was there an error?
365
-		if (!empty($upcontext['forced_error_message']))
366
-			echo $upcontext['forced_error_message'];
383
+		if (!empty($upcontext['forced_error_message'])) {
384
+					echo $upcontext['forced_error_message'];
385
+		}
367 386
 
368 387
 		// Show the footer.
369
-		if (!isset($_GET['xml']))
370
-			template_upgrade_below();
371
-		else
372
-			template_xml_below();
388
+		if (!isset($_GET['xml'])) {
389
+					template_upgrade_below();
390
+		} else {
391
+					template_xml_below();
392
+		}
373 393
 	}
374 394
 
375 395
 
@@ -381,15 +401,19 @@  discard block
 block discarded – undo
381 401
 		$seconds = intval($active % 60);
382 402
 
383 403
 		$totalTime = '';
384
-		if ($hours > 0)
385
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
386
-		if ($minutes > 0)
387
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
388
-		if ($seconds > 0)
389
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
404
+		if ($hours > 0) {
405
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
406
+		}
407
+		if ($minutes > 0) {
408
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
409
+		}
410
+		if ($seconds > 0) {
411
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
412
+		}
390 413
 
391
-		if (!empty($totalTime))
392
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
414
+		if (!empty($totalTime)) {
415
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
416
+		}
393 417
 	}
394 418
 
395 419
 	// Bang - gone!
@@ -402,8 +426,9 @@  discard block
 block discarded – undo
402 426
 	global $upgradeurl, $upcontext, $command_line;
403 427
 
404 428
 	// Command line users can't be redirected.
405
-	if ($command_line)
406
-		upgradeExit(true);
429
+	if ($command_line) {
430
+			upgradeExit(true);
431
+	}
407 432
 
408 433
 	// Are we providing the core info?
409 434
 	if ($addForm)
@@ -426,19 +451,22 @@  discard block
 block discarded – undo
426 451
 	global $modSettings, $sourcedir, $smcFunc;
427 452
 
428 453
 	// Do the non-SSI stuff...
429
-	if (function_exists('set_magic_quotes_runtime'))
430
-		@set_magic_quotes_runtime(0);
454
+	if (function_exists('set_magic_quotes_runtime')) {
455
+			@set_magic_quotes_runtime(0);
456
+	}
431 457
 
432 458
 	error_reporting(E_ALL);
433 459
 	define('SMF', 1);
434 460
 
435 461
 	// Start the session.
436
-	if (@ini_get('session.save_handler') == 'user')
437
-		@ini_set('session.save_handler', 'files');
462
+	if (@ini_get('session.save_handler') == 'user') {
463
+			@ini_set('session.save_handler', 'files');
464
+	}
438 465
 	@session_start();
439 466
 
440
-	if (empty($smcFunc))
441
-		$smcFunc = array();
467
+	if (empty($smcFunc)) {
468
+			$smcFunc = array();
469
+	}
442 470
 
443 471
 	// We need this for authentication and some upgrade code
444 472
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -450,8 +478,9 @@  discard block
 block discarded – undo
450 478
 	initialize_inputs();
451 479
 
452 480
 	// Get the database going!
453
-	if (empty($db_type) || $db_type == 'mysqli')
454
-		$db_type = 'mysql';
481
+	if (empty($db_type) || $db_type == 'mysqli') {
482
+			$db_type = 'mysql';
483
+	}
455 484
 
456 485
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
457 486
 	{
@@ -461,17 +490,19 @@  discard block
 block discarded – undo
461 490
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
462 491
 
463 492
 		// Oh dear god!!
464
-		if ($db_connection === null)
465
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
493
+		if ($db_connection === null) {
494
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
495
+		}
466 496
 
467
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
468
-			$smcFunc['db_query']('', '
497
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
498
+					$smcFunc['db_query']('', '
469 499
 			SET NAMES {string:db_character_set}',
470 500
 			array(
471 501
 				'db_error_skip' => true,
472 502
 				'db_character_set' => $db_character_set,
473 503
 			)
474 504
 		);
505
+		}
475 506
 
476 507
 		// Load the modSettings data...
477 508
 		$request = $smcFunc['db_query']('', '
@@ -482,11 +513,11 @@  discard block
 block discarded – undo
482 513
 			)
483 514
 		);
484 515
 		$modSettings = array();
485
-		while ($row = $smcFunc['db_fetch_assoc']($request))
486
-			$modSettings[$row['variable']] = $row['value'];
516
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
517
+					$modSettings[$row['variable']] = $row['value'];
518
+		}
487 519
 		$smcFunc['db_free_result']($request);
488
-	}
489
-	else
520
+	} else
490 521
 	{
491 522
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
492 523
 	}
@@ -500,9 +531,10 @@  discard block
 block discarded – undo
500 531
 		cleanRequest();
501 532
 	}
502 533
 
503
-	if (!isset($_GET['substep']))
504
-		$_GET['substep'] = 0;
505
-}
534
+	if (!isset($_GET['substep'])) {
535
+			$_GET['substep'] = 0;
536
+	}
537
+	}
506 538
 
507 539
 function initialize_inputs()
508 540
 {
@@ -532,8 +564,9 @@  discard block
 block discarded – undo
532 564
 		$dh = opendir(dirname(__FILE__));
533 565
 		while ($file = readdir($dh))
534 566
 		{
535
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
536
-				@unlink(dirname(__FILE__) . '/' . $file);
567
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
568
+							@unlink(dirname(__FILE__) . '/' . $file);
569
+			}
537 570
 		}
538 571
 		closedir($dh);
539 572
 
@@ -563,8 +596,9 @@  discard block
 block discarded – undo
563 596
 	{
564 597
 		$upcontext['remote_files_available'] = false;
565 598
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
566
-		if ($test)
567
-			$upcontext['remote_files_available'] = true;
599
+		if ($test) {
600
+					$upcontext['remote_files_available'] = true;
601
+		}
568 602
 		@fclose($test);
569 603
 	}
570 604
 
@@ -572,8 +606,9 @@  discard block
 block discarded – undo
572 606
 	$temp = 'upgrade_php?step';
573 607
 	while (strlen($temp) > 4)
574 608
 	{
575
-		if (isset($_GET[$temp]))
576
-			unset($_GET[$temp]);
609
+		if (isset($_GET[$temp])) {
610
+					unset($_GET[$temp]);
611
+		}
577 612
 		$temp = substr($temp, 1);
578 613
 	}
579 614
 
@@ -600,32 +635,39 @@  discard block
 block discarded – undo
600 635
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
601 636
 
602 637
 	// Need legacy scripts?
603
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
604
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
605
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
606
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
607
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
608
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
638
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
639
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
640
+	}
641
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
642
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
643
+	}
644
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
645
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
646
+	}
609 647
 
610 648
 	// We don't need "-utf8" files anymore...
611 649
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
612 650
 
613 651
 	// This needs to exist!
614
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
615
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
616
-	else
617
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
652
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
653
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
654
+	} else {
655
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
656
+	}
618 657
 
619
-	if (!$check)
620
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
658
+	if (!$check) {
659
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
621 660
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
661
+	}
622 662
 
623 663
 	// Do they meet the install requirements?
624
-	if (!php_version_check())
625
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
664
+	if (!php_version_check()) {
665
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
666
+	}
626 667
 
627
-	if (!db_version_check())
628
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
668
+	if (!db_version_check()) {
669
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
670
+	}
629 671
 
630 672
 	// Do some checks to make sure they have proper privileges
631 673
 	db_extend('packages');
@@ -640,14 +682,16 @@  discard block
 block discarded – undo
640 682
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
641 683
 
642 684
 	// Sorry... we need CREATE, ALTER and DROP
643
-	if (!$create || !$alter || !$drop)
644
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
685
+	if (!$create || !$alter || !$drop) {
686
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
687
+	}
645 688
 
646 689
 	// Do a quick version spot check.
647 690
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
648 691
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
649
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
650
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
692
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
693
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
694
+	}
651 695
 
652 696
 	// What absolutely needs to be writable?
653 697
 	$writable_files = array(
@@ -669,12 +713,13 @@  discard block
 block discarded – undo
669 713
 	quickFileWritable($custom_av_dir);
670 714
 
671 715
 	// Are we good now?
672
-	if (!is_writable($custom_av_dir))
673
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
674
-	elseif ($need_settings_update)
716
+	if (!is_writable($custom_av_dir)) {
717
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
718
+	} elseif ($need_settings_update)
675 719
 	{
676
-		if (!function_exists('cache_put_data'))
677
-			require_once($sourcedir . '/Load.php');
720
+		if (!function_exists('cache_put_data')) {
721
+					require_once($sourcedir . '/Load.php');
722
+		}
678 723
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
679 724
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
680 725
 	}
@@ -683,28 +728,33 @@  discard block
 block discarded – undo
683 728
 
684 729
 	// Check the cache directory.
685 730
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
686
-	if (!file_exists($cachedir_temp))
687
-		@mkdir($cachedir_temp);
688
-	if (!file_exists($cachedir_temp))
689
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
690
-
691
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
692
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
693
-	elseif (!isset($_GET['skiplang']))
731
+	if (!file_exists($cachedir_temp)) {
732
+			@mkdir($cachedir_temp);
733
+	}
734
+	if (!file_exists($cachedir_temp)) {
735
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
736
+	}
737
+
738
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
739
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
740
+	} elseif (!isset($_GET['skiplang']))
694 741
 	{
695 742
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
696 743
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
697 744
 
698
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
699
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
745
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
746
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
747
+		}
700 748
 	}
701 749
 
702
-	if (!makeFilesWritable($writable_files))
703
-		return false;
750
+	if (!makeFilesWritable($writable_files)) {
751
+			return false;
752
+	}
704 753
 
705 754
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
706
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
707
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
755
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
756
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
757
+	}
708 758
 
709 759
 	// Upgrade the agreement.
710 760
 	elseif (isset($modSettings['agreement']))
@@ -715,8 +765,8 @@  discard block
 block discarded – undo
715 765
 	}
716 766
 
717 767
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
718
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
719
-		$upcontext['warning'] = '
768
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
769
+			$upcontext['warning'] = '
720 770
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
721 771
 			<ul>
722 772
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -724,10 +774,12 @@  discard block
 block discarded – undo
724 774
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
725 775
 			</ul>
726 776
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="http://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
777
+	}
727 778
 
728 779
 	// Either we're logged in or we're going to present the login.
729
-	if (checkLogin())
730
-		return true;
780
+	if (checkLogin()) {
781
+			return true;
782
+	}
731 783
 
732 784
 	$upcontext += createToken('login');
733 785
 
@@ -741,15 +793,17 @@  discard block
 block discarded – undo
741 793
 	global $smcFunc, $db_type, $support_js;
742 794
 
743 795
 	// Don't bother if the security is disabled.
744
-	if ($disable_security)
745
-		return true;
796
+	if ($disable_security) {
797
+			return true;
798
+	}
746 799
 
747 800
 	// Are we trying to login?
748 801
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
749 802
 	{
750 803
 		// If we've disabled security pick a suitable name!
751
-		if (empty($_POST['user']))
752
-			$_POST['user'] = 'Administrator';
804
+		if (empty($_POST['user'])) {
805
+					$_POST['user'] = 'Administrator';
806
+		}
753 807
 
754 808
 		// Before 2.0 these column names were different!
755 809
 		$oldDB = false;
@@ -764,16 +818,17 @@  discard block
 block discarded – undo
764 818
 					'db_error_skip' => true,
765 819
 				)
766 820
 			);
767
-			if ($smcFunc['db_num_rows']($request) != 0)
768
-				$oldDB = true;
821
+			if ($smcFunc['db_num_rows']($request) != 0) {
822
+							$oldDB = true;
823
+			}
769 824
 			$smcFunc['db_free_result']($request);
770 825
 		}
771 826
 
772 827
 		// Get what we believe to be their details.
773 828
 		if (!$disable_security)
774 829
 		{
775
-			if ($oldDB)
776
-				$request = $smcFunc['db_query']('', '
830
+			if ($oldDB) {
831
+							$request = $smcFunc['db_query']('', '
777 832
 					SELECT id_member, memberName AS member_name, passwd, id_group,
778 833
 					additionalGroups AS additional_groups, lngfile
779 834
 					FROM {db_prefix}members
@@ -783,8 +838,8 @@  discard block
 block discarded – undo
783 838
 						'db_error_skip' => true,
784 839
 					)
785 840
 				);
786
-			else
787
-				$request = $smcFunc['db_query']('', '
841
+			} else {
842
+							$request = $smcFunc['db_query']('', '
788 843
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
789 844
 					FROM {db_prefix}members
790 845
 					WHERE member_name = {string:member_name}',
@@ -793,6 +848,7 @@  discard block
 block discarded – undo
793 848
 						'db_error_skip' => true,
794 849
 					)
795 850
 				);
851
+			}
796 852
 			if ($smcFunc['db_num_rows']($request) != 0)
797 853
 			{
798 854
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -800,16 +856,17 @@  discard block
 block discarded – undo
800 856
 				$groups = explode(',', $addGroups);
801 857
 				$groups[] = $id_group;
802 858
 
803
-				foreach ($groups as $k => $v)
804
-					$groups[$k] = (int) $v;
859
+				foreach ($groups as $k => $v) {
860
+									$groups[$k] = (int) $v;
861
+				}
805 862
 
806 863
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
807 864
 
808 865
 				// We don't use "-utf8" anymore...
809 866
 				$user_language = str_ireplace('-utf8', '', $user_language);
867
+			} else {
868
+							$upcontext['username_incorrect'] = true;
810 869
 			}
811
-			else
812
-				$upcontext['username_incorrect'] = true;
813 870
 			$smcFunc['db_free_result']($request);
814 871
 		}
815 872
 		$upcontext['username'] = $_POST['user'];
@@ -819,13 +876,14 @@  discard block
 block discarded – undo
819 876
 		{
820 877
 			$upcontext['upgrade_status']['js'] = 1;
821 878
 			$support_js = 1;
879
+		} else {
880
+					$support_js = 0;
822 881
 		}
823
-		else
824
-			$support_js = 0;
825 882
 
826 883
 		// Note down the version we are coming from.
827
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
828
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
884
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
885
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
886
+		}
829 887
 
830 888
 		// Didn't get anywhere?
831 889
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -859,15 +917,15 @@  discard block
 block discarded – undo
859 917
 							'db_error_skip' => true,
860 918
 						)
861 919
 					);
862
-					if ($smcFunc['db_num_rows']($request) == 0)
863
-						return throw_error('You need to be an admin to perform an upgrade!');
920
+					if ($smcFunc['db_num_rows']($request) == 0) {
921
+											return throw_error('You need to be an admin to perform an upgrade!');
922
+					}
864 923
 					$smcFunc['db_free_result']($request);
865 924
 				}
866 925
 
867 926
 				$upcontext['user']['id'] = $id_member;
868 927
 				$upcontext['user']['name'] = $name;
869
-			}
870
-			else
928
+			} else
871 929
 			{
872 930
 				$upcontext['user']['id'] = 1;
873 931
 				$upcontext['user']['name'] = 'Administrator';
@@ -883,11 +941,11 @@  discard block
 block discarded – undo
883 941
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
884 942
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
885 943
 
886
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
887
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
888
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
889
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
890
-				else
944
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
945
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
946
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
947
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
948
+				} else
891 949
 				{
892 950
 					// Set this as the new language.
893 951
 					$upcontext['language'] = $user_language;
@@ -931,8 +989,9 @@  discard block
 block discarded – undo
931 989
 	unset($member_columns);
932 990
 
933 991
 	// If we've not submitted then we're done.
934
-	if (empty($_POST['upcont']))
935
-		return false;
992
+	if (empty($_POST['upcont'])) {
993
+			return false;
994
+	}
936 995
 
937 996
 	// Firstly, if they're enabling SM stat collection just do it.
938 997
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']))
@@ -947,25 +1006,26 @@  discard block
 block discarded – undo
947 1006
 			fwrite($fp, $out);
948 1007
 
949 1008
 			$return_data = '';
950
-			while (!feof($fp))
951
-				$return_data .= fgets($fp, 128);
1009
+			while (!feof($fp)) {
1010
+							$return_data .= fgets($fp, 128);
1011
+			}
952 1012
 
953 1013
 			fclose($fp);
954 1014
 
955 1015
 			// Get the unique site ID.
956 1016
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
957 1017
 
958
-			if (!empty($ID[1]))
959
-				$smcFunc['db_insert']('replace',
1018
+			if (!empty($ID[1])) {
1019
+							$smcFunc['db_insert']('replace',
960 1020
 					$db_prefix . 'settings',
961 1021
 					array('variable' => 'string', 'value' => 'string'),
962 1022
 					array('allow_sm_stats', $ID[1]),
963 1023
 					array('variable')
964 1024
 				);
1025
+			}
965 1026
 		}
966
-	}
967
-	else
968
-		$smcFunc['db_query']('', '
1027
+	} else {
1028
+			$smcFunc['db_query']('', '
969 1029
 			DELETE FROM {db_prefix}settings
970 1030
 			WHERE variable = {string:allow_sm_stats}',
971 1031
 			array(
@@ -973,6 +1033,7 @@  discard block
 block discarded – undo
973 1033
 				'db_error_skip' => true,
974 1034
 			)
975 1035
 		);
1036
+	}
976 1037
 
977 1038
 	// Deleting old karma stuff?
978 1039
 	if (!empty($_POST['delete_karma']))
@@ -987,20 +1048,22 @@  discard block
 block discarded – undo
987 1048
 		);
988 1049
 
989 1050
 		// Cleaning up old karma member settings.
990
-		if ($upcontext['karma_installed']['good'])
991
-			$smcFunc['db_query']('', '
1051
+		if ($upcontext['karma_installed']['good']) {
1052
+					$smcFunc['db_query']('', '
992 1053
 				ALTER TABLE {db_prefix}members
993 1054
 				DROP karma_good',
994 1055
 				array()
995 1056
 			);
1057
+		}
996 1058
 
997 1059
 		// Does karma bad was enable?
998
-		if ($upcontext['karma_installed']['bad'])
999
-			$smcFunc['db_query']('', '
1060
+		if ($upcontext['karma_installed']['bad']) {
1061
+					$smcFunc['db_query']('', '
1000 1062
 				ALTER TABLE {db_prefix}members
1001 1063
 				DROP karma_bad',
1002 1064
 				array()
1003 1065
 			);
1066
+		}
1004 1067
 
1005 1068
 		// Cleaning up old karma permissions.
1006 1069
 		$smcFunc['db_query']('', '
@@ -1013,26 +1076,29 @@  discard block
 block discarded – undo
1013 1076
 	}
1014 1077
 
1015 1078
 	// Emptying the error log?
1016
-	if (!empty($_POST['empty_error']))
1017
-		$smcFunc['db_query']('truncate_table', '
1079
+	if (!empty($_POST['empty_error'])) {
1080
+			$smcFunc['db_query']('truncate_table', '
1018 1081
 			TRUNCATE {db_prefix}log_errors',
1019 1082
 			array(
1020 1083
 			)
1021 1084
 		);
1085
+	}
1022 1086
 
1023 1087
 	$changes = array();
1024 1088
 
1025 1089
 	// Add proxy settings.
1026
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1027
-		$changes += array(
1090
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1091
+			$changes += array(
1028 1092
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1029 1093
 			'image_proxy_maxsize' => 5190,
1030 1094
 			'image_proxy_enabled' => 0,
1031 1095
 		);
1096
+	}
1032 1097
 
1033 1098
 	// If we're overriding the language follow it through.
1034
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1035
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1099
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1100
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1101
+	}
1036 1102
 
1037 1103
 	if (!empty($_POST['maint']))
1038 1104
 	{
@@ -1044,30 +1110,34 @@  discard block
 block discarded – undo
1044 1110
 		{
1045 1111
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1046 1112
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1047
-		}
1048
-		else
1113
+		} else
1049 1114
 		{
1050 1115
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1051 1116
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1052 1117
 		}
1053 1118
 	}
1054 1119
 
1055
-	if ($command_line)
1056
-		echo ' * Updating Settings.php...';
1120
+	if ($command_line) {
1121
+			echo ' * Updating Settings.php...';
1122
+	}
1057 1123
 
1058 1124
 	// Fix some old paths.
1059
-	if (substr($boarddir, 0, 1) == '.')
1060
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1125
+	if (substr($boarddir, 0, 1) == '.') {
1126
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1127
+	}
1061 1128
 
1062
-	if (substr($sourcedir, 0, 1) == '.')
1063
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1129
+	if (substr($sourcedir, 0, 1) == '.') {
1130
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1131
+	}
1064 1132
 
1065
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1066
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1133
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1134
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1135
+	}
1067 1136
 
1068 1137
 	// Not had the database type added before?
1069
-	if (empty($db_type))
1070
-		$changes['db_type'] = 'mysql';
1138
+	if (empty($db_type)) {
1139
+			$changes['db_type'] = 'mysql';
1140
+	}
1071 1141
 
1072 1142
 	// If they have a "host:port" setup for the host, split that into separate values
1073 1143
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1078,32 +1148,36 @@  discard block
 block discarded – undo
1078 1148
 		$changes['db_server'] = '\'' . $db_server . '\'';
1079 1149
 
1080 1150
 		// Only set this if we're not using the default port
1081
-		if ($db_port != ini_get('mysqli.default_port'))
1082
-			$changes['db_port'] = (int) $db_port;
1083
-	}
1084
-	elseif (!empty($db_port))
1151
+		if ($db_port != ini_get('mysqli.default_port')) {
1152
+					$changes['db_port'] = (int) $db_port;
1153
+		}
1154
+	} elseif (!empty($db_port))
1085 1155
 	{
1086 1156
 		// If db_port is set and is the same as the default, set it to ''
1087 1157
 		if ($db_type == 'mysql')
1088 1158
 		{
1089
-			if ($db_port == ini_get('mysqli.default_port'))
1090
-				$changes['db_port'] = '\'\'';
1091
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1092
-				$changes['db_port'] = '\'\'';
1159
+			if ($db_port == ini_get('mysqli.default_port')) {
1160
+							$changes['db_port'] = '\'\'';
1161
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1162
+							$changes['db_port'] = '\'\'';
1163
+			}
1093 1164
 		}
1094 1165
 	}
1095 1166
 
1096 1167
 	// Maybe we haven't had this option yet?
1097
-	if (empty($packagesdir))
1098
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1168
+	if (empty($packagesdir)) {
1169
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1170
+	}
1099 1171
 
1100 1172
 	// Add support for $tasksdir var.
1101
-	if (empty($tasksdir))
1102
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1173
+	if (empty($tasksdir)) {
1174
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1175
+	}
1103 1176
 
1104 1177
 	// Make sure we fix the language as well.
1105
-	if (stristr($language, '-utf8'))
1106
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1178
+	if (stristr($language, '-utf8')) {
1179
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1180
+	}
1107 1181
 
1108 1182
 	// @todo Maybe change the cookie name if going to 1.1, too?
1109 1183
 
@@ -1111,8 +1185,9 @@  discard block
 block discarded – undo
1111 1185
 	require_once($sourcedir . '/Subs-Admin.php');
1112 1186
 	updateSettingsFile($changes);
1113 1187
 
1114
-	if ($command_line)
1115
-		echo ' Successful.' . "\n";
1188
+	if ($command_line) {
1189
+			echo ' Successful.' . "\n";
1190
+	}
1116 1191
 
1117 1192
 	// Are we doing debug?
1118 1193
 	if (isset($_POST['debug']))
@@ -1122,8 +1197,9 @@  discard block
 block discarded – undo
1122 1197
 	}
1123 1198
 
1124 1199
 	// If we're not backing up then jump one.
1125
-	if (empty($_POST['backup']))
1126
-		$upcontext['current_step']++;
1200
+	if (empty($_POST['backup'])) {
1201
+			$upcontext['current_step']++;
1202
+	}
1127 1203
 
1128 1204
 	// If we've got here then let's proceed to the next step!
1129 1205
 	return true;
@@ -1138,8 +1214,9 @@  discard block
 block discarded – undo
1138 1214
 	$upcontext['page_title'] = 'Backup Database';
1139 1215
 
1140 1216
 	// Done it already - js wise?
1141
-	if (!empty($_POST['backup_done']))
1142
-		return true;
1217
+	if (!empty($_POST['backup_done'])) {
1218
+			return true;
1219
+	}
1143 1220
 
1144 1221
 	// Some useful stuff here.
1145 1222
 	db_extend();
@@ -1153,9 +1230,10 @@  discard block
 block discarded – undo
1153 1230
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1154 1231
 
1155 1232
 	$table_names = array();
1156
-	foreach ($tables as $table)
1157
-		if (substr($table, 0, 7) !== 'backup_')
1233
+	foreach ($tables as $table) {
1234
+			if (substr($table, 0, 7) !== 'backup_')
1158 1235
 			$table_names[] = $table;
1236
+	}
1159 1237
 
1160 1238
 	$upcontext['table_count'] = count($table_names);
1161 1239
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1165,12 +1243,14 @@  discard block
 block discarded – undo
1165 1243
 	$file_steps = $upcontext['table_count'];
1166 1244
 
1167 1245
 	// What ones have we already done?
1168
-	foreach ($table_names as $id => $table)
1169
-		if ($id < $_GET['substep'])
1246
+	foreach ($table_names as $id => $table) {
1247
+			if ($id < $_GET['substep'])
1170 1248
 			$upcontext['previous_tables'][] = $table;
1249
+	}
1171 1250
 
1172
-	if ($command_line)
1173
-		echo 'Backing Up Tables.';
1251
+	if ($command_line) {
1252
+			echo 'Backing Up Tables.';
1253
+	}
1174 1254
 
1175 1255
 	// If we don't support javascript we backup here.
1176 1256
 	if (!$support_js || isset($_GET['xml']))
@@ -1189,8 +1269,9 @@  discard block
 block discarded – undo
1189 1269
 			backupTable($table_names[$substep]);
1190 1270
 
1191 1271
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1192
-			if (isset($_GET['xml']))
1193
-				return upgradeExit();
1272
+			if (isset($_GET['xml'])) {
1273
+							return upgradeExit();
1274
+			}
1194 1275
 		}
1195 1276
 
1196 1277
 		if ($command_line)
@@ -1223,9 +1304,10 @@  discard block
 block discarded – undo
1223 1304
 
1224 1305
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1225 1306
 
1226
-	if ($command_line)
1227
-		echo ' done.';
1228
-}
1307
+	if ($command_line) {
1308
+			echo ' done.';
1309
+	}
1310
+	}
1229 1311
 
1230 1312
 // Step 2: Everything.
1231 1313
 function DatabaseChanges()
@@ -1234,8 +1316,9 @@  discard block
 block discarded – undo
1234 1316
 	global $upcontext, $support_js, $db_type;
1235 1317
 
1236 1318
 	// Have we just completed this?
1237
-	if (!empty($_POST['database_done']))
1238
-		return true;
1319
+	if (!empty($_POST['database_done'])) {
1320
+			return true;
1321
+	}
1239 1322
 
1240 1323
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1241 1324
 	$upcontext['page_title'] = 'Database Changes';
@@ -1250,15 +1333,16 @@  discard block
 block discarded – undo
1250 1333
 	);
1251 1334
 
1252 1335
 	// How many files are there in total?
1253
-	if (isset($_GET['filecount']))
1254
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1255
-	else
1336
+	if (isset($_GET['filecount'])) {
1337
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1338
+	} else
1256 1339
 	{
1257 1340
 		$upcontext['file_count'] = 0;
1258 1341
 		foreach ($files as $file)
1259 1342
 		{
1260
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1261
-				$upcontext['file_count']++;
1343
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1344
+							$upcontext['file_count']++;
1345
+			}
1262 1346
 		}
1263 1347
 	}
1264 1348
 
@@ -1268,9 +1352,9 @@  discard block
 block discarded – undo
1268 1352
 	$upcontext['cur_file_num'] = 0;
1269 1353
 	foreach ($files as $file)
1270 1354
 	{
1271
-		if ($did_not_do)
1272
-			$did_not_do--;
1273
-		else
1355
+		if ($did_not_do) {
1356
+					$did_not_do--;
1357
+		} else
1274 1358
 		{
1275 1359
 			$upcontext['cur_file_num']++;
1276 1360
 			$upcontext['cur_file_name'] = $file[0];
@@ -1297,12 +1381,13 @@  discard block
 block discarded – undo
1297 1381
 					// Flag to move on to the next.
1298 1382
 					$upcontext['completed_step'] = true;
1299 1383
 					// Did we complete the whole file?
1300
-					if ($nextFile)
1301
-						$upcontext['current_debug_item_num'] = -1;
1384
+					if ($nextFile) {
1385
+											$upcontext['current_debug_item_num'] = -1;
1386
+					}
1302 1387
 					return upgradeExit();
1388
+				} elseif ($support_js) {
1389
+									break;
1303 1390
 				}
1304
-				elseif ($support_js)
1305
-					break;
1306 1391
 			}
1307 1392
 			// Set the progress bar to be right as if we had - even if we hadn't...
1308 1393
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1327,8 +1412,9 @@  discard block
 block discarded – undo
1327 1412
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1328 1413
 
1329 1414
 	// Now it's nice to have some of the basic SMF source files.
1330
-	if (!isset($_GET['ssi']) && !$command_line)
1331
-		redirectLocation('&ssi=1');
1415
+	if (!isset($_GET['ssi']) && !$command_line) {
1416
+			redirectLocation('&ssi=1');
1417
+	}
1332 1418
 
1333 1419
 	$upcontext['sub_template'] = 'upgrade_complete';
1334 1420
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1344,14 +1430,16 @@  discard block
 block discarded – undo
1344 1430
 	// Are we in maintenance mode?
1345 1431
 	if (isset($upcontext['user']['main']))
1346 1432
 	{
1347
-		if ($command_line)
1348
-			echo ' * ';
1433
+		if ($command_line) {
1434
+					echo ' * ';
1435
+		}
1349 1436
 		$upcontext['removed_maintenance'] = true;
1350 1437
 		$changes['maintenance'] = $upcontext['user']['main'];
1351 1438
 	}
1352 1439
 	// Otherwise if somehow we are in 2 let's go to 1.
1353
-	elseif (!empty($maintenance) && $maintenance == 2)
1354
-		$changes['maintenance'] = 1;
1440
+	elseif (!empty($maintenance) && $maintenance == 2) {
1441
+			$changes['maintenance'] = 1;
1442
+	}
1355 1443
 
1356 1444
 	// Wipe this out...
1357 1445
 	$upcontext['user'] = array();
@@ -1366,9 +1454,9 @@  discard block
 block discarded – undo
1366 1454
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1367 1455
 
1368 1456
 	// Now is the perfect time to fetch the SM files.
1369
-	if ($command_line)
1370
-		cli_scheduled_fetchSMfiles();
1371
-	else
1457
+	if ($command_line) {
1458
+			cli_scheduled_fetchSMfiles();
1459
+	} else
1372 1460
 	{
1373 1461
 		require_once($sourcedir . '/ScheduledTasks.php');
1374 1462
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1376,8 +1464,9 @@  discard block
 block discarded – undo
1376 1464
 	}
1377 1465
 
1378 1466
 	// Log what we've done.
1379
-	if (empty($user_info['id']))
1380
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1467
+	if (empty($user_info['id'])) {
1468
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1469
+	}
1381 1470
 
1382 1471
 	// Log the action manually, so CLI still works.
1383 1472
 	$smcFunc['db_insert']('',
@@ -1396,8 +1485,9 @@  discard block
 block discarded – undo
1396 1485
 
1397 1486
 	// Save the current database version.
1398 1487
 	$server_version = $smcFunc['db_server_info']();
1399
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1400
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1488
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1489
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1490
+	}
1401 1491
 
1402 1492
 	if ($command_line)
1403 1493
 	{
@@ -1409,8 +1499,9 @@  discard block
 block discarded – undo
1409 1499
 
1410 1500
 	// Make sure it says we're done.
1411 1501
 	$upcontext['overall_percent'] = 100;
1412
-	if (isset($upcontext['step_progress']))
1413
-		unset($upcontext['step_progress']);
1502
+	if (isset($upcontext['step_progress'])) {
1503
+			unset($upcontext['step_progress']);
1504
+	}
1414 1505
 
1415 1506
 	$_GET['substep'] = 0;
1416 1507
 	return false;
@@ -1421,8 +1512,9 @@  discard block
 block discarded – undo
1421 1512
 {
1422 1513
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1423 1514
 
1424
-	if (empty($modSettings['time_format']))
1425
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1515
+	if (empty($modSettings['time_format'])) {
1516
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1517
+	}
1426 1518
 
1427 1519
 	// What files do we want to get
1428 1520
 	$request = $smcFunc['db_query']('', '
@@ -1456,8 +1548,9 @@  discard block
 block discarded – undo
1456 1548
 		$file_data = fetch_web_data($url);
1457 1549
 
1458 1550
 		// If we got an error - give up - the site might be down.
1459
-		if ($file_data === false)
1460
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1551
+		if ($file_data === false) {
1552
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1553
+		}
1461 1554
 
1462 1555
 		// Save the file to the database.
1463 1556
 		$smcFunc['db_query']('substring', '
@@ -1499,8 +1592,9 @@  discard block
 block discarded – undo
1499 1592
 	$themeData = array();
1500 1593
 	foreach ($values as $variable => $value)
1501 1594
 	{
1502
-		if (!isset($value) || $value === null)
1503
-			$value = 0;
1595
+		if (!isset($value) || $value === null) {
1596
+					$value = 0;
1597
+		}
1504 1598
 
1505 1599
 		$themeData[] = array(0, 1, $variable, $value);
1506 1600
 	}
@@ -1529,8 +1623,9 @@  discard block
 block discarded – undo
1529 1623
 
1530 1624
 	foreach ($values as $variable => $value)
1531 1625
 	{
1532
-		if (empty($modSettings[$value[0]]))
1533
-			continue;
1626
+		if (empty($modSettings[$value[0]])) {
1627
+					continue;
1628
+		}
1534 1629
 
1535 1630
 		$smcFunc['db_query']('', '
1536 1631
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1616,10 +1711,11 @@  discard block
 block discarded – undo
1616 1711
 	set_error_handler(
1617 1712
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1618 1713
 		{
1619
-			if ($support_js)
1620
-				return true;
1621
-			else
1622
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1714
+			if ($support_js) {
1715
+							return true;
1716
+			} else {
1717
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1718
+			}
1623 1719
 		}
1624 1720
 	);
1625 1721
 
@@ -1634,8 +1730,9 @@  discard block
 block discarded – undo
1634 1730
 				'db_error_skip' => true,
1635 1731
 			)
1636 1732
 		);
1637
-		if ($smcFunc['db_num_rows']($request) === 0)
1638
-			die('Unable to find members table!');
1733
+		if ($smcFunc['db_num_rows']($request) === 0) {
1734
+					die('Unable to find members table!');
1735
+		}
1639 1736
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1640 1737
 		$smcFunc['db_free_result']($request);
1641 1738
 
@@ -1650,17 +1747,20 @@  discard block
 block discarded – undo
1650 1747
 				)
1651 1748
 			);
1652 1749
 			// Got something?
1653
-			if ($smcFunc['db_num_rows']($request) !== 0)
1654
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1750
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1751
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1752
+			}
1655 1753
 			$smcFunc['db_free_result']($request);
1656 1754
 
1657 1755
 			// Excellent!
1658
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1659
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1756
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1757
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1758
+			}
1660 1759
 		}
1661 1760
 	}
1662
-	if (empty($db_collation))
1663
-		$db_collation = '';
1761
+	if (empty($db_collation)) {
1762
+			$db_collation = '';
1763
+	}
1664 1764
 
1665 1765
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1666 1766
 
@@ -1672,8 +1772,9 @@  discard block
 block discarded – undo
1672 1772
 	$last_step = '';
1673 1773
 
1674 1774
 	// Make sure all newly created tables will have the proper characters set.
1675
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1676
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1775
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1776
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1777
+	}
1677 1778
 
1678 1779
 	// Count the total number of steps within this file - for progress.
1679 1780
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1693,15 +1794,18 @@  discard block
 block discarded – undo
1693 1794
 		$do_current = $substep >= $_GET['substep'];
1694 1795
 
1695 1796
 		// Get rid of any comments in the beginning of the line...
1696
-		if (substr(trim($line), 0, 2) === '/*')
1697
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1797
+		if (substr(trim($line), 0, 2) === '/*') {
1798
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1799
+		}
1698 1800
 
1699 1801
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1700
-		if ($is_debug && !$support_js && $command_line)
1701
-			flush();
1802
+		if ($is_debug && !$support_js && $command_line) {
1803
+					flush();
1804
+		}
1702 1805
 
1703
-		if (trim($line) === '')
1704
-			continue;
1806
+		if (trim($line) === '') {
1807
+					continue;
1808
+		}
1705 1809
 
1706 1810
 		if (trim(substr($line, 0, 3)) === '---')
1707 1811
 		{
@@ -1711,8 +1815,9 @@  discard block
 block discarded – undo
1711 1815
 			if (trim($current_data) != '' && $type !== '}')
1712 1816
 			{
1713 1817
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1714
-				if ($command_line)
1715
-					echo $upcontext['error_message'];
1818
+				if ($command_line) {
1819
+									echo $upcontext['error_message'];
1820
+				}
1716 1821
 			}
1717 1822
 
1718 1823
 			if ($type == ' ')
@@ -1730,17 +1835,18 @@  discard block
 block discarded – undo
1730 1835
 				if ($do_current)
1731 1836
 				{
1732 1837
 					$upcontext['actioned_items'][] = $last_step;
1733
-					if ($command_line)
1734
-						echo ' * ';
1838
+					if ($command_line) {
1839
+											echo ' * ';
1840
+					}
1735 1841
 				}
1736
-			}
1737
-			elseif ($type == '#')
1842
+			} elseif ($type == '#')
1738 1843
 			{
1739 1844
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1740 1845
 
1741 1846
 				$upcontext['current_debug_item_num']++;
1742
-				if (trim($line) != '---#')
1743
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1847
+				if (trim($line) != '---#') {
1848
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1849
+				}
1744 1850
 
1745 1851
 				// Have we already done something?
1746 1852
 				if (isset($_GET['xml']) && $done_something)
@@ -1751,34 +1857,36 @@  discard block
 block discarded – undo
1751 1857
 
1752 1858
 				if ($do_current)
1753 1859
 				{
1754
-					if (trim($line) == '---#' && $command_line)
1755
-						echo ' done.', $endl;
1756
-					elseif ($command_line)
1757
-						echo ' +++ ', rtrim(substr($line, 4));
1758
-					elseif (trim($line) != '---#')
1860
+					if (trim($line) == '---#' && $command_line) {
1861
+											echo ' done.', $endl;
1862
+					} elseif ($command_line) {
1863
+											echo ' +++ ', rtrim(substr($line, 4));
1864
+					} elseif (trim($line) != '---#')
1759 1865
 					{
1760
-						if ($is_debug)
1761
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1866
+						if ($is_debug) {
1867
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1868
+						}
1762 1869
 					}
1763 1870
 				}
1764 1871
 
1765 1872
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1766 1873
 				{
1767
-					if ($command_line)
1768
-						echo ' * ';
1769
-					else
1770
-						$upcontext['actioned_items'][] = $last_step;
1874
+					if ($command_line) {
1875
+											echo ' * ';
1876
+					} else {
1877
+											$upcontext['actioned_items'][] = $last_step;
1878
+					}
1771 1879
 				}
1772 1880
 
1773 1881
 				// Small step - only if we're actually doing stuff.
1774
-				if ($do_current)
1775
-					nextSubstep(++$substep);
1776
-				else
1777
-					$substep++;
1778
-			}
1779
-			elseif ($type == '{')
1780
-				$current_type = 'code';
1781
-			elseif ($type == '}')
1882
+				if ($do_current) {
1883
+									nextSubstep(++$substep);
1884
+				} else {
1885
+									$substep++;
1886
+				}
1887
+			} elseif ($type == '{') {
1888
+							$current_type = 'code';
1889
+			} elseif ($type == '}')
1782 1890
 			{
1783 1891
 				$current_type = 'sql';
1784 1892
 
@@ -1791,8 +1899,9 @@  discard block
 block discarded – undo
1791 1899
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1792 1900
 				{
1793 1901
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1794
-					if ($command_line)
1795
-						echo $upcontext['error_message'];
1902
+					if ($command_line) {
1903
+											echo $upcontext['error_message'];
1904
+					}
1796 1905
 				}
1797 1906
 
1798 1907
 				// Done with code!
@@ -1872,8 +1981,9 @@  discard block
 block discarded – undo
1872 1981
 	$db_unbuffered = false;
1873 1982
 
1874 1983
 	// Failure?!
1875
-	if ($result !== false)
1876
-		return $result;
1984
+	if ($result !== false) {
1985
+			return $result;
1986
+	}
1877 1987
 
1878 1988
 	$db_error_message = $smcFunc['db_error']($db_connection);
1879 1989
 	// If MySQL we do something more clever.
@@ -1901,54 +2011,61 @@  discard block
 block discarded – undo
1901 2011
 			{
1902 2012
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1903 2013
 				$result = mysqli_query($db_connection, $string);
1904
-				if ($result !== false)
1905
-					return $result;
2014
+				if ($result !== false) {
2015
+									return $result;
2016
+				}
1906 2017
 			}
1907
-		}
1908
-		elseif ($mysqli_errno == 2013)
2018
+		} elseif ($mysqli_errno == 2013)
1909 2019
 		{
1910 2020
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1911 2021
 			mysqli_select_db($db_connection, $db_name);
1912 2022
 			if ($db_connection)
1913 2023
 			{
1914 2024
 				$result = mysqli_query($db_connection, $string);
1915
-				if ($result !== false)
1916
-					return $result;
2025
+				if ($result !== false) {
2026
+									return $result;
2027
+				}
1917 2028
 			}
1918 2029
 		}
1919 2030
 		// Duplicate column name... should be okay ;).
1920
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1921
-			return false;
2031
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2032
+					return false;
2033
+		}
1922 2034
 		// Duplicate insert... make sure it's the proper type of query ;).
1923
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1924
-			return false;
2035
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2036
+					return false;
2037
+		}
1925 2038
 		// Creating an index on a non-existent column.
1926
-		elseif ($mysqli_errno == 1072)
1927
-			return false;
1928
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1929
-			return false;
2039
+		elseif ($mysqli_errno == 1072) {
2040
+					return false;
2041
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2042
+					return false;
2043
+		}
1930 2044
 	}
1931 2045
 	// If a table already exists don't go potty.
1932 2046
 	else
1933 2047
 	{
1934 2048
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1935 2049
 		{
1936
-			if (strpos($db_error_message, 'exist') !== false)
1937
-				return true;
1938
-		}
1939
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2050
+			if (strpos($db_error_message, 'exist') !== false) {
2051
+							return true;
2052
+			}
2053
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1940 2054
 		{
1941
-			if (strpos($db_error_message, 'duplicate') !== false)
1942
-				return true;
2055
+			if (strpos($db_error_message, 'duplicate') !== false) {
2056
+							return true;
2057
+			}
1943 2058
 		}
1944 2059
 	}
1945 2060
 
1946 2061
 	// Get the query string so we pass everything.
1947 2062
 	$query_string = '';
1948
-	foreach ($_GET as $k => $v)
1949
-		$query_string .= ';' . $k . '=' . $v;
1950
-	if (strlen($query_string) != 0)
1951
-		$query_string = '?' . substr($query_string, 1);
2063
+	foreach ($_GET as $k => $v) {
2064
+			$query_string .= ';' . $k . '=' . $v;
2065
+	}
2066
+	if (strlen($query_string) != 0) {
2067
+			$query_string = '?' . substr($query_string, 1);
2068
+	}
1952 2069
 
1953 2070
 	if ($command_line)
1954 2071
 	{
@@ -2003,16 +2120,18 @@  discard block
 block discarded – undo
2003 2120
 			{
2004 2121
 				$found |= 1;
2005 2122
 				// Do some checks on the data if we have it set.
2006
-				if (isset($change['col_type']))
2007
-					$found &= $change['col_type'] === $column['type'];
2008
-				if (isset($change['null_allowed']))
2009
-					$found &= $column['null'] == $change['null_allowed'];
2010
-				if (isset($change['default']))
2011
-					$found &= $change['default'] === $column['default'];
2123
+				if (isset($change['col_type'])) {
2124
+									$found &= $change['col_type'] === $column['type'];
2125
+				}
2126
+				if (isset($change['null_allowed'])) {
2127
+									$found &= $column['null'] == $change['null_allowed'];
2128
+				}
2129
+				if (isset($change['default'])) {
2130
+									$found &= $change['default'] === $column['default'];
2131
+				}
2012 2132
 			}
2013 2133
 		}
2014
-	}
2015
-	elseif ($change['type'] === 'index')
2134
+	} elseif ($change['type'] === 'index')
2016 2135
 	{
2017 2136
 		$request = upgrade_query('
2018 2137
 			SHOW INDEX
@@ -2021,9 +2140,10 @@  discard block
 block discarded – undo
2021 2140
 		{
2022 2141
 			$cur_index = array();
2023 2142
 
2024
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2025
-				if ($row['Key_name'] === $change['name'])
2143
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2144
+							if ($row['Key_name'] === $change['name'])
2026 2145
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2146
+			}
2027 2147
 
2028 2148
 			ksort($cur_index, SORT_NUMERIC);
2029 2149
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2033,14 +2153,17 @@  discard block
 block discarded – undo
2033 2153
 	}
2034 2154
 
2035 2155
 	// If we're trying to add and it's added, we're done.
2036
-	if ($found && in_array($change['method'], array('add', 'change')))
2037
-		return true;
2156
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2157
+			return true;
2158
+	}
2038 2159
 	// Otherwise if we're removing and it wasn't found we're also done.
2039
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2040
-		return true;
2160
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2161
+			return true;
2162
+	}
2041 2163
 	// Otherwise is it just a test?
2042
-	elseif ($is_test)
2043
-		return false;
2164
+	elseif ($is_test) {
2165
+			return false;
2166
+	}
2044 2167
 
2045 2168
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2046 2169
 	$running = false;
@@ -2051,8 +2174,9 @@  discard block
 block discarded – undo
2051 2174
 			SHOW FULL PROCESSLIST');
2052 2175
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2053 2176
 		{
2054
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2055
-				$found = true;
2177
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2178
+							$found = true;
2179
+			}
2056 2180
 		}
2057 2181
 
2058 2182
 		// Can't find it? Then we need to run it fools!
@@ -2064,8 +2188,9 @@  discard block
 block discarded – undo
2064 2188
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2065 2189
 				' . $change['text'], true) !== false;
2066 2190
 
2067
-			if (!$success)
2068
-				return false;
2191
+			if (!$success) {
2192
+							return false;
2193
+			}
2069 2194
 
2070 2195
 			// Return
2071 2196
 			$running = true;
@@ -2107,8 +2232,9 @@  discard block
 block discarded – undo
2107 2232
 			'db_error_skip' => true,
2108 2233
 		)
2109 2234
 	);
2110
-	if ($smcFunc['db_num_rows']($request) === 0)
2111
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2235
+	if ($smcFunc['db_num_rows']($request) === 0) {
2236
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2237
+	}
2112 2238
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2113 2239
 	$smcFunc['db_free_result']($request);
2114 2240
 
@@ -2130,18 +2256,19 @@  discard block
 block discarded – undo
2130 2256
 			)
2131 2257
 		);
2132 2258
 		// No results? Just forget it all together.
2133
-		if ($smcFunc['db_num_rows']($request) === 0)
2134
-			unset($table_row['Collation']);
2135
-		else
2136
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2259
+		if ($smcFunc['db_num_rows']($request) === 0) {
2260
+					unset($table_row['Collation']);
2261
+		} else {
2262
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2263
+		}
2137 2264
 		$smcFunc['db_free_result']($request);
2138 2265
 	}
2139 2266
 
2140 2267
 	if ($column_fix)
2141 2268
 	{
2142 2269
 		// Make sure there are no NULL's left.
2143
-		if ($null_fix)
2144
-			$smcFunc['db_query']('', '
2270
+		if ($null_fix) {
2271
+					$smcFunc['db_query']('', '
2145 2272
 				UPDATE {db_prefix}' . $change['table'] . '
2146 2273
 				SET ' . $change['column'] . ' = {string:default}
2147 2274
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2150,6 +2277,7 @@  discard block
 block discarded – undo
2150 2277
 					'db_error_skip' => true,
2151 2278
 				)
2152 2279
 			);
2280
+		}
2153 2281
 
2154 2282
 		// Do the actual alteration.
2155 2283
 		$smcFunc['db_query']('', '
@@ -2178,8 +2306,9 @@  discard block
 block discarded – undo
2178 2306
 	}
2179 2307
 
2180 2308
 	// Not a column we need to check on?
2181
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2182
-		return;
2309
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2310
+			return;
2311
+	}
2183 2312
 
2184 2313
 	// Break it up you (six|seven).
2185 2314
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2198,13 +2327,13 @@  discard block
 block discarded – undo
2198 2327
 				'new_name' => $temp[2],
2199 2328
 		));
2200 2329
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2201
-		if ($smcFunc['db_num_rows'] != 1)
2202
-			return;
2330
+		if ($smcFunc['db_num_rows'] != 1) {
2331
+					return;
2332
+		}
2203 2333
 
2204 2334
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2205 2335
 		$smcFunc['db_free_result']($request);
2206
-	}
2207
-	else
2336
+	} else
2208 2337
 	{
2209 2338
 		// Do this the old fashion, sure method way.
2210 2339
 		$request = $smcFunc['db_query']('', '
@@ -2215,21 +2344,24 @@  discard block
 block discarded – undo
2215 2344
 		));
2216 2345
 		// Mayday!
2217 2346
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2218
-		if ($smcFunc['db_num_rows'] == 0)
2219
-			return;
2347
+		if ($smcFunc['db_num_rows'] == 0) {
2348
+					return;
2349
+		}
2220 2350
 
2221 2351
 		// Oh where, oh where has my little field gone. Oh where can it be...
2222
-		while ($row = $smcFunc['db_query']($request))
2223
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2352
+		while ($row = $smcFunc['db_query']($request)) {
2353
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2224 2354
 			{
2225 2355
 				$current_type = $row['Type'];
2356
+		}
2226 2357
 				break;
2227 2358
 			}
2228 2359
 	}
2229 2360
 
2230 2361
 	// If this doesn't match, the column may of been altered for a reason.
2231
-	if (trim($current_type) != trim($temp[3]))
2232
-		$temp[3] = $current_type;
2362
+	if (trim($current_type) != trim($temp[3])) {
2363
+			$temp[3] = $current_type;
2364
+	}
2233 2365
 
2234 2366
 	// Piece this back together.
2235 2367
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2241,8 +2373,9 @@  discard block
 block discarded – undo
2241 2373
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2242 2374
 	global $step_progress, $is_debug, $upcontext;
2243 2375
 
2244
-	if ($_GET['substep'] < $substep)
2245
-		$_GET['substep'] = $substep;
2376
+	if ($_GET['substep'] < $substep) {
2377
+			$_GET['substep'] = $substep;
2378
+	}
2246 2379
 
2247 2380
 	if ($command_line)
2248 2381
 	{
@@ -2255,29 +2388,33 @@  discard block
 block discarded – undo
2255 2388
 	}
2256 2389
 
2257 2390
 	@set_time_limit(300);
2258
-	if (function_exists('apache_reset_timeout'))
2259
-		@apache_reset_timeout();
2391
+	if (function_exists('apache_reset_timeout')) {
2392
+			@apache_reset_timeout();
2393
+	}
2260 2394
 
2261
-	if (time() - $start_time <= $timeLimitThreshold)
2262
-		return;
2395
+	if (time() - $start_time <= $timeLimitThreshold) {
2396
+			return;
2397
+	}
2263 2398
 
2264 2399
 	// Do we have some custom step progress stuff?
2265 2400
 	if (!empty($step_progress))
2266 2401
 	{
2267 2402
 		$upcontext['substep_progress'] = 0;
2268 2403
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2269
-		if ($step_progress['current'] > $step_progress['total'])
2270
-			$upcontext['substep_progress'] = 99.9;
2271
-		else
2272
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2404
+		if ($step_progress['current'] > $step_progress['total']) {
2405
+					$upcontext['substep_progress'] = 99.9;
2406
+		} else {
2407
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2408
+		}
2273 2409
 
2274 2410
 		// Make it nicely rounded.
2275 2411
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2276 2412
 	}
2277 2413
 
2278 2414
 	// If this is XML we just exit right away!
2279
-	if (isset($_GET['xml']))
2280
-		return upgradeExit();
2415
+	if (isset($_GET['xml'])) {
2416
+			return upgradeExit();
2417
+	}
2281 2418
 
2282 2419
 	// We're going to pause after this!
2283 2420
 	$upcontext['pause'] = true;
@@ -2285,13 +2422,15 @@  discard block
 block discarded – undo
2285 2422
 	$upcontext['query_string'] = '';
2286 2423
 	foreach ($_GET as $k => $v)
2287 2424
 	{
2288
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2289
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2425
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2426
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2427
+		}
2290 2428
 	}
2291 2429
 
2292 2430
 	// Custom warning?
2293
-	if (!empty($custom_warning))
2294
-		$upcontext['custom_warning'] = $custom_warning;
2431
+	if (!empty($custom_warning)) {
2432
+			$upcontext['custom_warning'] = $custom_warning;
2433
+	}
2295 2434
 
2296 2435
 	upgradeExit();
2297 2436
 }
@@ -2306,25 +2445,26 @@  discard block
 block discarded – undo
2306 2445
 	ob_implicit_flush(true);
2307 2446
 	@set_time_limit(600);
2308 2447
 
2309
-	if (!isset($_SERVER['argv']))
2310
-		$_SERVER['argv'] = array();
2448
+	if (!isset($_SERVER['argv'])) {
2449
+			$_SERVER['argv'] = array();
2450
+	}
2311 2451
 	$_GET['maint'] = 1;
2312 2452
 
2313 2453
 	foreach ($_SERVER['argv'] as $i => $arg)
2314 2454
 	{
2315
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2316
-			$_GET['lang'] = $match[1];
2317
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2318
-			continue;
2319
-		elseif ($arg == '--no-maintenance')
2320
-			$_GET['maint'] = 0;
2321
-		elseif ($arg == '--debug')
2322
-			$is_debug = true;
2323
-		elseif ($arg == '--backup')
2324
-			$_POST['backup'] = 1;
2325
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2326
-			$_GET['conv'] = 1;
2327
-		elseif ($i != 0)
2455
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2456
+					$_GET['lang'] = $match[1];
2457
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2458
+					continue;
2459
+		} elseif ($arg == '--no-maintenance') {
2460
+					$_GET['maint'] = 0;
2461
+		} elseif ($arg == '--debug') {
2462
+					$is_debug = true;
2463
+		} elseif ($arg == '--backup') {
2464
+					$_POST['backup'] = 1;
2465
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2466
+					$_GET['conv'] = 1;
2467
+		} elseif ($i != 0)
2328 2468
 		{
2329 2469
 			echo 'SMF Command-line Upgrader
2330 2470
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2338,10 +2478,12 @@  discard block
 block discarded – undo
2338 2478
 		}
2339 2479
 	}
2340 2480
 
2341
-	if (!php_version_check())
2342
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2343
-	if (!db_version_check())
2344
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2481
+	if (!php_version_check()) {
2482
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2483
+	}
2484
+	if (!db_version_check()) {
2485
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2486
+	}
2345 2487
 
2346 2488
 	// Do some checks to make sure they have proper privileges
2347 2489
 	db_extend('packages');
@@ -2356,34 +2498,39 @@  discard block
 block discarded – undo
2356 2498
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2357 2499
 
2358 2500
 	// Sorry... we need CREATE, ALTER and DROP
2359
-	if (!$create || !$alter || !$drop)
2360
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2501
+	if (!$create || !$alter || !$drop) {
2502
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2503
+	}
2361 2504
 
2362 2505
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2363 2506
 		&& @file_exists($sourcedir . '/QueryString.php')
2364 2507
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2365
-	if (!$check && !isset($modSettings['smfVersion']))
2366
-		print_error('Error: Some files are missing or out-of-date.', true);
2508
+	if (!$check && !isset($modSettings['smfVersion'])) {
2509
+			print_error('Error: Some files are missing or out-of-date.', true);
2510
+	}
2367 2511
 
2368 2512
 	// Do a quick version spot check.
2369 2513
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2370 2514
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2371
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2372
-		print_error('Error: Some files have not yet been updated properly.');
2515
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2516
+			print_error('Error: Some files have not yet been updated properly.');
2517
+	}
2373 2518
 
2374 2519
 	// Make sure Settings.php is writable.
2375 2520
 		quickFileWritable($boarddir . '/Settings.php');
2376
-	if (!is_writable($boarddir . '/Settings.php'))
2377
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2521
+	if (!is_writable($boarddir . '/Settings.php')) {
2522
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2523
+	}
2378 2524
 
2379 2525
 	// Make sure Settings_bak.php is writable.
2380 2526
 		quickFileWritable($boarddir . '/Settings_bak.php');
2381
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2382
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2527
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2528
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2529
+	}
2383 2530
 
2384
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2385
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2386
-	elseif (isset($modSettings['agreement']))
2531
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2532
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2533
+	} elseif (isset($modSettings['agreement']))
2387 2534
 	{
2388 2535
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2389 2536
 		fwrite($fp, $modSettings['agreement']);
@@ -2393,31 +2540,36 @@  discard block
 block discarded – undo
2393 2540
 	// Make sure Themes is writable.
2394 2541
 	quickFileWritable($modSettings['theme_dir']);
2395 2542
 
2396
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2397
-		print_error('Error: Unable to obtain write access to "Themes".');
2543
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2544
+			print_error('Error: Unable to obtain write access to "Themes".');
2545
+	}
2398 2546
 
2399 2547
 	// Make sure cache directory exists and is writable!
2400 2548
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2401
-	if (!file_exists($cachedir_temp))
2402
-		@mkdir($cachedir_temp);
2549
+	if (!file_exists($cachedir_temp)) {
2550
+			@mkdir($cachedir_temp);
2551
+	}
2403 2552
 
2404 2553
 	// Make sure the cache temp dir is writable.
2405 2554
 	quickFileWritable($cachedir_temp);
2406 2555
 
2407
-	if (!is_writable($cachedir_temp))
2408
-		print_error('Error: Unable to obtain write access to "cache".', true);
2556
+	if (!is_writable($cachedir_temp)) {
2557
+			print_error('Error: Unable to obtain write access to "cache".', true);
2558
+	}
2409 2559
 
2410
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2411
-		print_error('Error: Unable to find language files!', true);
2412
-	else
2560
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2561
+			print_error('Error: Unable to find language files!', true);
2562
+	} else
2413 2563
 	{
2414 2564
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2415 2565
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2416 2566
 
2417
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2418
-			print_error('Error: Language files out of date.', true);
2419
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2420
-			print_error('Error: Install language is missing for selected language.', true);
2567
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2568
+					print_error('Error: Language files out of date.', true);
2569
+		}
2570
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2571
+					print_error('Error: Install language is missing for selected language.', true);
2572
+		}
2421 2573
 
2422 2574
 		// Otherwise include it!
2423 2575
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2446,8 +2598,7 @@  discard block
 block discarded – undo
2446 2598
 		);
2447 2599
 
2448 2600
 		return true;
2449
-	}
2450
-	else
2601
+	} else
2451 2602
 	{
2452 2603
 		$upcontext['page_title'] = 'Converting to UTF8';
2453 2604
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2491,8 +2642,9 @@  discard block
 block discarded – undo
2491 2642
 			)
2492 2643
 		);
2493 2644
 		$db_charsets = array();
2494
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2495
-			$db_charsets[] = $row['Charset'];
2645
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2646
+					$db_charsets[] = $row['Charset'];
2647
+		}
2496 2648
 
2497 2649
 		$smcFunc['db_free_result']($request);
2498 2650
 
@@ -2528,13 +2680,15 @@  discard block
 block discarded – undo
2528 2680
 		// If there's a fulltext index, we need to drop it first...
2529 2681
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2530 2682
 		{
2531
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2532
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2683
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2684
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2533 2685
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2686
+			}
2534 2687
 			$smcFunc['db_free_result']($request);
2535 2688
 
2536
-			if (isset($upcontext['fulltext_index']))
2537
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2689
+			if (isset($upcontext['fulltext_index'])) {
2690
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2691
+			}
2538 2692
 		}
2539 2693
 
2540 2694
 		// Drop it and make a note...
@@ -2724,8 +2878,9 @@  discard block
 block discarded – undo
2724 2878
 			$replace = '%field%';
2725 2879
 
2726 2880
 			// Build a huge REPLACE statement...
2727
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2728
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2881
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2882
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2883
+			}
2729 2884
 		}
2730 2885
 
2731 2886
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2759,8 +2914,9 @@  discard block
 block discarded – undo
2759 2914
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2760 2915
 
2761 2916
 			// Just to make sure it doesn't time out.
2762
-			if (function_exists('apache_reset_timeout'))
2763
-				@apache_reset_timeout();
2917
+			if (function_exists('apache_reset_timeout')) {
2918
+							@apache_reset_timeout();
2919
+			}
2764 2920
 
2765 2921
 			$table_charsets = array();
2766 2922
 
@@ -2781,8 +2937,9 @@  discard block
 block discarded – undo
2781 2937
 					{
2782 2938
 						list($charset) = explode('_', $collation);
2783 2939
 
2784
-						if (!isset($table_charsets[$charset]))
2785
-							$table_charsets[$charset] = array();
2940
+						if (!isset($table_charsets[$charset])) {
2941
+													$table_charsets[$charset] = array();
2942
+						}
2786 2943
 
2787 2944
 						$table_charsets[$charset][] = $column_info;
2788 2945
 					}
@@ -2822,10 +2979,11 @@  discard block
 block discarded – undo
2822 2979
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2823 2980
 				{
2824 2981
 					$update = '';
2825
-					foreach ($table_charsets as $charset => $columns)
2826
-						foreach ($columns as $column)
2982
+					foreach ($table_charsets as $charset => $columns) {
2983
+											foreach ($columns as $column)
2827 2984
 							$update .= '
2828 2985
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2986
+					}
2829 2987
 
2830 2988
 					$smcFunc['db_query']('', '
2831 2989
 						UPDATE {raw:table_name}
@@ -2850,8 +3008,9 @@  discard block
 block discarded – undo
2850 3008
 			// Now do the actual conversion (if still needed).
2851 3009
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2852 3010
 			{
2853
-				if ($command_line)
2854
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3011
+				if ($command_line) {
3012
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3013
+				}
2855 3014
 
2856 3015
 				$smcFunc['db_query']('', '
2857 3016
 					ALTER TABLE {raw:table_name}
@@ -2861,8 +3020,9 @@  discard block
 block discarded – undo
2861 3020
 					)
2862 3021
 				);
2863 3022
 
2864
-				if ($command_line)
2865
-					echo " done.\n";
3023
+				if ($command_line) {
3024
+									echo " done.\n";
3025
+				}
2866 3026
 			}
2867 3027
 		}
2868 3028
 
@@ -2892,8 +3052,8 @@  discard block
 block discarded – undo
2892 3052
 		);
2893 3053
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2894 3054
 		{
2895
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
2896
-				$smcFunc['db_query']('', '
3055
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3056
+							$smcFunc['db_query']('', '
2897 3057
 					UPDATE {db_prefix}log_actions
2898 3058
 					SET extra = {string:extra}
2899 3059
 					WHERE id_action = {int:current_action}',
@@ -2902,6 +3062,7 @@  discard block
 block discarded – undo
2902 3062
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2903 3063
 					)
2904 3064
 				);
3065
+			}
2905 3066
 		}
2906 3067
 		$smcFunc['db_free_result']($request);
2907 3068
 
@@ -2923,15 +3084,17 @@  discard block
 block discarded – undo
2923 3084
 	// First thing's first - did we already do this?
2924 3085
 	if (!empty($modSettings['json_done']))
2925 3086
 	{
2926
-		if ($command_line)
2927
-			return DeleteUpgrade();
2928
-		else
2929
-			return true;
3087
+		if ($command_line) {
3088
+					return DeleteUpgrade();
3089
+		} else {
3090
+					return true;
3091
+		}
2930 3092
 	}
2931 3093
 
2932 3094
 	// Done it already - js wise?
2933
-	if (!empty($_POST['json_done']))
2934
-		return true;
3095
+	if (!empty($_POST['json_done'])) {
3096
+			return true;
3097
+	}
2935 3098
 
2936 3099
 	// List of tables affected by this function
2937 3100
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2962,12 +3125,14 @@  discard block
 block discarded – undo
2962 3125
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2963 3126
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2964 3127
 
2965
-	foreach ($keys as $id => $table)
2966
-		if ($id < $_GET['substep'])
3128
+	foreach ($keys as $id => $table) {
3129
+			if ($id < $_GET['substep'])
2967 3130
 			$upcontext['previous_tables'][] = $table;
3131
+	}
2968 3132
 
2969
-	if ($command_line)
2970
-		echo 'Converting data from serialize() to json_encode().';
3133
+	if ($command_line) {
3134
+			echo 'Converting data from serialize() to json_encode().';
3135
+	}
2971 3136
 
2972 3137
 	if (!$support_js || isset($_GET['xml']))
2973 3138
 	{
@@ -3007,8 +3172,9 @@  discard block
 block discarded – undo
3007 3172
 
3008 3173
 				// Loop through and fix these...
3009 3174
 				$new_settings = array();
3010
-				if ($command_line)
3011
-					echo "\n" . 'Fixing some settings...';
3175
+				if ($command_line) {
3176
+									echo "\n" . 'Fixing some settings...';
3177
+				}
3012 3178
 
3013 3179
 				foreach ($serialized_settings as $var)
3014 3180
 				{
@@ -3016,22 +3182,24 @@  discard block
 block discarded – undo
3016 3182
 					{
3017 3183
 						// Attempt to unserialize the setting
3018 3184
 						$temp = @safe_unserialize($modSettings[$var]);
3019
-						if (!$temp && $command_line)
3020
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3021
-						elseif ($temp !== false)
3022
-							$new_settings[$var] = json_encode($temp);
3185
+						if (!$temp && $command_line) {
3186
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3187
+						} elseif ($temp !== false) {
3188
+													$new_settings[$var] = json_encode($temp);
3189
+						}
3023 3190
 					}
3024 3191
 				}
3025 3192
 
3026 3193
 				// Update everything at once
3027
-				if (!function_exists('cache_put_data'))
3028
-					require_once($sourcedir . '/Load.php');
3194
+				if (!function_exists('cache_put_data')) {
3195
+									require_once($sourcedir . '/Load.php');
3196
+				}
3029 3197
 				updateSettings($new_settings, true);
3030 3198
 
3031
-				if ($command_line)
3032
-					echo ' done.';
3033
-			}
3034
-			elseif ($table == 'themes')
3199
+				if ($command_line) {
3200
+									echo ' done.';
3201
+				}
3202
+			} elseif ($table == 'themes')
3035 3203
 			{
3036 3204
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3037 3205
 				$query = $smcFunc['db_query']('', '
@@ -3050,10 +3218,11 @@  discard block
 block discarded – undo
3050 3218
 
3051 3219
 						if ($command_line)
3052 3220
 						{
3053
-							if ($temp === false)
3054
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3055
-							else
3056
-								echo "\n" . 'Fixing admin preferences...';
3221
+							if ($temp === false) {
3222
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3223
+							} else {
3224
+															echo "\n" . 'Fixing admin preferences...';
3225
+							}
3057 3226
 						}
3058 3227
 
3059 3228
 						if ($temp !== false)
@@ -3075,15 +3244,15 @@  discard block
 block discarded – undo
3075 3244
 								)
3076 3245
 							);
3077 3246
 
3078
-							if ($command_line)
3079
-								echo ' done.';
3247
+							if ($command_line) {
3248
+															echo ' done.';
3249
+							}
3080 3250
 						}
3081 3251
 					}
3082 3252
 
3083 3253
 					$smcFunc['db_free_result']($query);
3084 3254
 				}
3085
-			}
3086
-			else
3255
+			} else
3087 3256
 			{
3088 3257
 				// First item is always the key...
3089 3258
 				$key = $info[0];
@@ -3094,8 +3263,7 @@  discard block
 block discarded – undo
3094 3263
 				{
3095 3264
 					$col_select = $info[1];
3096 3265
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3097
-				}
3098
-				else
3266
+				} else
3099 3267
 				{
3100 3268
 					$col_select = implode(', ', $info);
3101 3269
 				}
@@ -3128,8 +3296,7 @@  discard block
 block discarded – undo
3128 3296
 								if ($temp === false && $command_line)
3129 3297
 								{
3130 3298
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3131
-								}
3132
-								else
3299
+								} else
3133 3300
 								{
3134 3301
 									$row[$col] = json_encode($temp);
3135 3302
 
@@ -3154,16 +3321,18 @@  discard block
 block discarded – undo
3154 3321
 						}
3155 3322
 					}
3156 3323
 
3157
-					if ($command_line)
3158
-						echo ' done.';
3324
+					if ($command_line) {
3325
+											echo ' done.';
3326
+					}
3159 3327
 
3160 3328
 					// Free up some memory...
3161 3329
 					$smcFunc['db_free_result']($query);
3162 3330
 				}
3163 3331
 			}
3164 3332
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3165
-			if (isset($_GET['xml']))
3166
-				return upgradeExit();
3333
+			if (isset($_GET['xml'])) {
3334
+							return upgradeExit();
3335
+			}
3167 3336
 		}
3168 3337
 
3169 3338
 		if ($command_line)
@@ -3178,8 +3347,9 @@  discard block
 block discarded – undo
3178 3347
 
3179 3348
 		$_GET['substep'] = 0;
3180 3349
 		// Make sure we move on!
3181
-		if ($command_line)
3182
-			return DeleteUpgrade();
3350
+		if ($command_line) {
3351
+					return DeleteUpgrade();
3352
+		}
3183 3353
 
3184 3354
 		return true;
3185 3355
 	}
@@ -3199,14 +3369,16 @@  discard block
 block discarded – undo
3199 3369
 	global $upcontext, $txt, $settings;
3200 3370
 
3201 3371
 	// Don't call me twice!
3202
-	if (!empty($upcontext['chmod_called']))
3203
-		return;
3372
+	if (!empty($upcontext['chmod_called'])) {
3373
+			return;
3374
+	}
3204 3375
 
3205 3376
 	$upcontext['chmod_called'] = true;
3206 3377
 
3207 3378
 	// Nothing?
3208
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3209
-		return;
3379
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3380
+			return;
3381
+	}
3210 3382
 
3211 3383
 	// Was it a problem with Windows?
3212 3384
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3238,11 +3410,12 @@  discard block
 block discarded – undo
3238 3410
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3239 3411
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3240 3412
 
3241
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3242
-		echo '
3413
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3414
+			echo '
3243 3415
 					content.write(\'<hr>\n\t\t\t\');
3244 3416
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3245 3417
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3418
+	}
3246 3419
 
3247 3420
 	echo '
3248 3421
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3250,17 +3423,19 @@  discard block
 block discarded – undo
3250 3423
 				}
3251 3424
 		</script>';
3252 3425
 
3253
-	if (!empty($upcontext['chmod']['ftp_error']))
3254
-		echo '
3426
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3427
+			echo '
3255 3428
 			<div class="error_message red">
3256 3429
 				The following error was encountered when trying to connect:<br><br>
3257 3430
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3258 3431
 			</div>
3259 3432
 			<br>';
3433
+	}
3260 3434
 
3261
-	if (empty($upcontext['chmod_in_form']))
3262
-		echo '
3435
+	if (empty($upcontext['chmod_in_form'])) {
3436
+			echo '
3263 3437
 	<form action="', $upcontext['form_url'], '" method="post">';
3438
+	}
3264 3439
 
3265 3440
 	echo '
3266 3441
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3295,10 +3470,11 @@  discard block
 block discarded – undo
3295 3470
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3296 3471
 	</div>';
3297 3472
 
3298
-	if (empty($upcontext['chmod_in_form']))
3299
-		echo '
3473
+	if (empty($upcontext['chmod_in_form'])) {
3474
+			echo '
3300 3475
 	</form>';
3301
-}
3476
+	}
3477
+	}
3302 3478
 
3303 3479
 function template_upgrade_above()
3304 3480
 {
@@ -3358,9 +3534,10 @@  discard block
 block discarded – undo
3358 3534
 				<h2>', $txt['upgrade_progress'], '</h2>
3359 3535
 				<ul>';
3360 3536
 
3361
-	foreach ($upcontext['steps'] as $num => $step)
3362
-		echo '
3537
+	foreach ($upcontext['steps'] as $num => $step) {
3538
+			echo '
3363 3539
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3540
+	}
3364 3541
 
3365 3542
 	echo '
3366 3543
 					</ul>
@@ -3373,8 +3550,8 @@  discard block
 block discarded – undo
3373 3550
 				</div>
3374 3551
 			</div>';
3375 3552
 
3376
-	if (isset($upcontext['step_progress']))
3377
-		echo '
3553
+	if (isset($upcontext['step_progress'])) {
3554
+			echo '
3378 3555
 				<br>
3379 3556
 				<br>
3380 3557
 				<div id="progress_bar_step">
@@ -3383,6 +3560,7 @@  discard block
 block discarded – undo
3383 3560
 						<span>', $txt['upgrade_step_progress'], '</span>
3384 3561
 					</div>
3385 3562
 				</div>';
3563
+	}
3386 3564
 
3387 3565
 	echo '
3388 3566
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3413,32 +3591,36 @@  discard block
 block discarded – undo
3413 3591
 {
3414 3592
 	global $upcontext, $txt;
3415 3593
 
3416
-	if (!empty($upcontext['pause']))
3417
-		echo '
3594
+	if (!empty($upcontext['pause'])) {
3595
+			echo '
3418 3596
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3419 3597
 
3420 3598
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3421 3599
 								<h3>
3422 3600
 									', $txt['upgrade_paused_overload'], '
3423 3601
 								</h3>';
3602
+	}
3424 3603
 
3425
-	if (!empty($upcontext['custom_warning']))
3426
-		echo '
3604
+	if (!empty($upcontext['custom_warning'])) {
3605
+			echo '
3427 3606
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3428 3607
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3429 3608
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3430 3609
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3431 3610
 								</div>';
3611
+	}
3432 3612
 
3433 3613
 	echo '
3434 3614
 								<div class="righttext" style="margin: 1ex;">';
3435 3615
 
3436
-	if (!empty($upcontext['continue']))
3437
-		echo '
3616
+	if (!empty($upcontext['continue'])) {
3617
+			echo '
3438 3618
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3439
-	if (!empty($upcontext['skip']))
3440
-		echo '
3619
+	}
3620
+	if (!empty($upcontext['skip'])) {
3621
+			echo '
3441 3622
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3623
+	}
3442 3624
 
3443 3625
 	echo '
3444 3626
 								</div>
@@ -3488,11 +3670,12 @@  discard block
 block discarded – undo
3488 3670
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3489 3671
 	<smf>';
3490 3672
 
3491
-	if (!empty($upcontext['get_data']))
3492
-		foreach ($upcontext['get_data'] as $k => $v)
3673
+	if (!empty($upcontext['get_data'])) {
3674
+			foreach ($upcontext['get_data'] as $k => $v)
3493 3675
 			echo '
3494 3676
 		<get key="', $k, '">', $v, '</get>';
3495
-}
3677
+	}
3678
+	}
3496 3679
 
3497 3680
 function template_xml_below()
3498 3681
 {
@@ -3533,8 +3716,8 @@  discard block
 block discarded – undo
3533 3716
 	template_chmod();
3534 3717
 
3535 3718
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3536
-	if ($upcontext['is_large_forum'])
3537
-		echo '
3719
+	if ($upcontext['is_large_forum']) {
3720
+			echo '
3538 3721
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3539 3722
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3540 3723
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3542,10 +3725,11 @@  discard block
 block discarded – undo
3542 3725
 				', $txt['upgrade_warning_lots_data'], '
3543 3726
 			</div>
3544 3727
 		</div>';
3728
+	}
3545 3729
 
3546 3730
 	// A warning message?
3547
-	if (!empty($upcontext['warning']))
3548
-		echo '
3731
+	if (!empty($upcontext['warning'])) {
3732
+			echo '
3549 3733
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3550 3734
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3551 3735
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3553,6 +3737,7 @@  discard block
 block discarded – undo
3553 3737
 				', $upcontext['warning'], '
3554 3738
 			</div>
3555 3739
 		</div>';
3740
+	}
3556 3741
 
3557 3742
 	// Paths are incorrect?
3558 3743
 	echo '
@@ -3568,20 +3753,22 @@  discard block
 block discarded – undo
3568 3753
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3569 3754
 	{
3570 3755
 		$ago = time() - $upcontext['started'];
3571
-		if ($ago < 60)
3572
-			$ago = $ago . ' seconds';
3573
-		elseif ($ago < 3600)
3574
-			$ago = (int) ($ago / 60) . ' minutes';
3575
-		else
3576
-			$ago = (int) ($ago / 3600) . ' hours';
3756
+		if ($ago < 60) {
3757
+					$ago = $ago . ' seconds';
3758
+		} elseif ($ago < 3600) {
3759
+					$ago = (int) ($ago / 60) . ' minutes';
3760
+		} else {
3761
+					$ago = (int) ($ago / 3600) . ' hours';
3762
+		}
3577 3763
 
3578 3764
 		$active = time() - $upcontext['updated'];
3579
-		if ($active < 60)
3580
-			$updated = $active . ' seconds';
3581
-		elseif ($active < 3600)
3582
-			$updated = (int) ($active / 60) . ' minutes';
3583
-		else
3584
-			$updated = (int) ($active / 3600) . ' hours';
3765
+		if ($active < 60) {
3766
+					$updated = $active . ' seconds';
3767
+		} elseif ($active < 3600) {
3768
+					$updated = (int) ($active / 60) . ' minutes';
3769
+		} else {
3770
+					$updated = (int) ($active / 3600) . ' hours';
3771
+		}
3585 3772
 
3586 3773
 		echo '
3587 3774
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3590,16 +3777,18 @@  discard block
 block discarded – undo
3590 3777
 			<div style="padding-left: 6ex;">
3591 3778
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3592 3779
 
3593
-		if ($active < 600)
3594
-			echo '
3780
+		if ($active < 600) {
3781
+					echo '
3595 3782
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3783
+		}
3596 3784
 
3597
-		if ($active > $upcontext['inactive_timeout'])
3598
-			echo '
3785
+		if ($active > $upcontext['inactive_timeout']) {
3786
+					echo '
3599 3787
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
3600
-		else
3601
-			echo '
3788
+		} else {
3789
+					echo '
3602 3790
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3791
+		}
3603 3792
 
3604 3793
 		echo '
3605 3794
 			</div>
@@ -3615,9 +3804,10 @@  discard block
 block discarded – undo
3615 3804
 					<td>
3616 3805
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3617 3806
 
3618
-	if (!empty($upcontext['username_incorrect']))
3619
-		echo '
3807
+	if (!empty($upcontext['username_incorrect'])) {
3808
+			echo '
3620 3809
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3810
+	}
3621 3811
 
3622 3812
 	echo '
3623 3813
 					</td>
@@ -3628,9 +3818,10 @@  discard block
 block discarded – undo
3628 3818
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3629 3819
 						<input type="hidden" name="hash_passwrd" value="">';
3630 3820
 
3631
-	if (!empty($upcontext['password_failed']))
3632
-		echo '
3821
+	if (!empty($upcontext['password_failed'])) {
3822
+			echo '
3633 3823
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3824
+	}
3634 3825
 
3635 3826
 	echo '
3636 3827
 					</td>
@@ -3701,8 +3892,8 @@  discard block
 block discarded – undo
3701 3892
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3702 3893
 
3703 3894
 	// Warning message?
3704
-	if (!empty($upcontext['upgrade_options_warning']))
3705
-		echo '
3895
+	if (!empty($upcontext['upgrade_options_warning'])) {
3896
+			echo '
3706 3897
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3707 3898
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3708 3899
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3710,6 +3901,7 @@  discard block
 block discarded – undo
3710 3901
 				', $upcontext['upgrade_options_warning'], '
3711 3902
 			</div>
3712 3903
 		</div>';
3904
+	}
3713 3905
 
3714 3906
 	echo '
3715 3907
 				<table>
@@ -3752,8 +3944,8 @@  discard block
 block discarded – undo
3752 3944
 						</td>
3753 3945
 					</tr>';
3754 3946
 
3755
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3756
-		echo '
3947
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3948
+			echo '
3757 3949
 					<tr valign="top">
3758 3950
 						<td width="2%">
3759 3951
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3762,6 +3954,7 @@  discard block
 block discarded – undo
3762 3954
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3763 3955
 						</td>
3764 3956
 					</tr>';
3957
+	}
3765 3958
 
3766 3959
 	echo '
3767 3960
 					<tr valign="top">
@@ -3799,10 +3992,11 @@  discard block
 block discarded – undo
3799 3992
 			</div>';
3800 3993
 
3801 3994
 	// Dont any tables so far?
3802
-	if (!empty($upcontext['previous_tables']))
3803
-		foreach ($upcontext['previous_tables'] as $table)
3995
+	if (!empty($upcontext['previous_tables'])) {
3996
+			foreach ($upcontext['previous_tables'] as $table)
3804 3997
 			echo '
3805 3998
 			<br>Completed Table: &quot;', $table, '&quot;.';
3999
+	}
3806 4000
 
3807 4001
 	echo '
3808 4002
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3839,12 +4033,13 @@  discard block
 block discarded – undo
3839 4033
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3840 4034
 
3841 4035
 		// If debug flood the screen.
3842
-		if ($is_debug)
3843
-			echo '
4036
+		if ($is_debug) {
4037
+					echo '
3844 4038
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3845 4039
 
3846 4040
 				if (document.getElementById(\'debug_section\').scrollHeight)
3847 4041
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4042
+		}
3848 4043
 
3849 4044
 		echo '
3850 4045
 				// Get the next update...
@@ -3876,8 +4071,9 @@  discard block
 block discarded – undo
3876 4071
 {
3877 4072
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3878 4073
 
3879
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3880
-		$is_debug = true;
4074
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4075
+			$is_debug = true;
4076
+	}
3881 4077
 
3882 4078
 	echo '
3883 4079
 		<h3>Executing database changes</h3>
@@ -3892,8 +4088,9 @@  discard block
 block discarded – undo
3892 4088
 	{
3893 4089
 		foreach ($upcontext['actioned_items'] as $num => $item)
3894 4090
 		{
3895
-			if ($num != 0)
3896
-				echo ' Successful!';
4091
+			if ($num != 0) {
4092
+							echo ' Successful!';
4093
+			}
3897 4094
 			echo '<br>' . $item;
3898 4095
 		}
3899 4096
 		if (!empty($upcontext['changes_complete']))
@@ -3906,28 +4103,32 @@  discard block
 block discarded – undo
3906 4103
 				$seconds = intval($active % 60);
3907 4104
 
3908 4105
 				$totalTime = '';
3909
-				if ($hours > 0)
3910
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3911
-				if ($minutes > 0)
3912
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3913
-				if ($seconds > 0)
3914
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4106
+				if ($hours > 0) {
4107
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4108
+				}
4109
+				if ($minutes > 0) {
4110
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4111
+				}
4112
+				if ($seconds > 0) {
4113
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4114
+				}
3915 4115
 			}
3916 4116
 
3917
-			if ($is_debug && !empty($totalTime))
3918
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3919
-			else
3920
-				echo ' Successful!<br><br>';
4117
+			if ($is_debug && !empty($totalTime)) {
4118
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4119
+			} else {
4120
+							echo ' Successful!<br><br>';
4121
+			}
3921 4122
 
3922 4123
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3923 4124
 		}
3924
-	}
3925
-	else
4125
+	} else
3926 4126
 	{
3927 4127
 		// Tell them how many files we have in total.
3928
-		if ($upcontext['file_count'] > 1)
3929
-			echo '
4128
+		if ($upcontext['file_count'] > 1) {
4129
+					echo '
3930 4130
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4131
+		}
3931 4132
 
3932 4133
 		echo '
3933 4134
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3943,19 +4144,23 @@  discard block
 block discarded – undo
3943 4144
 				$seconds = intval($active % 60);
3944 4145
 
3945 4146
 				$totalTime = '';
3946
-				if ($hours > 0)
3947
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3948
-				if ($minutes > 0)
3949
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3950
-				if ($seconds > 0)
3951
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4147
+				if ($hours > 0) {
4148
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4149
+				}
4150
+				if ($minutes > 0) {
4151
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4152
+				}
4153
+				if ($seconds > 0) {
4154
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4155
+				}
3952 4156
 			}
3953 4157
 
3954 4158
 			echo '
3955 4159
 			<br><span id="upgradeCompleted">';
3956 4160
 
3957
-			if (!empty($totalTime))
3958
-				echo 'Completed in ', $totalTime, '<br>';
4161
+			if (!empty($totalTime)) {
4162
+							echo 'Completed in ', $totalTime, '<br>';
4163
+			}
3959 4164
 
3960 4165
 			echo '</span>
3961 4166
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -3992,9 +4197,10 @@  discard block
 block discarded – undo
3992 4197
 			var getData = "";
3993 4198
 			var debugItems = ', $upcontext['debug_items'], ';';
3994 4199
 
3995
-		if ($is_debug)
3996
-			echo '
4200
+		if ($is_debug) {
4201
+					echo '
3997 4202
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4203
+		}
3998 4204
 
3999 4205
 		echo '
4000 4206
 			function getNextItem()
@@ -4034,9 +4240,10 @@  discard block
 block discarded – undo
4034 4240
 						document.getElementById("error_block").style.display = "";
4035 4241
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4036 4242
 
4037
-	if ($is_debug)
4038
-		echo '
4243
+	if ($is_debug) {
4244
+			echo '
4039 4245
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4246
+	}
4040 4247
 
4041 4248
 	echo '
4042 4249
 					}
@@ -4057,9 +4264,10 @@  discard block
 block discarded – undo
4057 4264
 						document.getElementById("error_block").style.display = "";
4058 4265
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4059 4266
 
4060
-	if ($is_debug)
4061
-		echo '
4267
+	if ($is_debug) {
4268
+			echo '
4062 4269
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4270
+	}
4063 4271
 
4064 4272
 	echo '
4065 4273
 					}
@@ -4118,8 +4326,8 @@  discard block
 block discarded – undo
4118 4326
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4119 4327
 				{';
4120 4328
 
4121
-		if ($is_debug)
4122
-			echo '
4329
+		if ($is_debug) {
4330
+					echo '
4123 4331
 					document.getElementById(\'debug_section\').style.display = "none";
4124 4332
 
4125 4333
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4137,6 +4345,7 @@  discard block
 block discarded – undo
4137 4345
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4138 4346
 
4139 4347
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4348
+		}
4140 4349
 
4141 4350
 		echo '
4142 4351
 
@@ -4144,9 +4353,10 @@  discard block
 block discarded – undo
4144 4353
 					document.getElementById(\'contbutt\').disabled = 0;
4145 4354
 					document.getElementById(\'database_done\').value = 1;';
4146 4355
 
4147
-		if ($upcontext['file_count'] > 1)
4148
-			echo '
4356
+		if ($upcontext['file_count'] > 1) {
4357
+					echo '
4149 4358
 					document.getElementById(\'info1\').style.display = "none";';
4359
+		}
4150 4360
 
4151 4361
 		echo '
4152 4362
 					document.getElementById(\'info2\').style.display = "none";
@@ -4159,9 +4369,10 @@  discard block
 block discarded – undo
4159 4369
 					lastItem = 0;
4160 4370
 					prevFile = curFile;';
4161 4371
 
4162
-		if ($is_debug)
4163
-			echo '
4372
+		if ($is_debug) {
4373
+					echo '
4164 4374
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4375
+		}
4165 4376
 
4166 4377
 		echo '
4167 4378
 					getNextItem();
@@ -4169,8 +4380,8 @@  discard block
 block discarded – undo
4169 4380
 				}';
4170 4381
 
4171 4382
 		// If debug scroll the screen.
4172
-		if ($is_debug)
4173
-			echo '
4383
+		if ($is_debug) {
4384
+					echo '
4174 4385
 				if (iLastSubStepProgress == -1)
4175 4386
 				{
4176 4387
 					// Give it consistent dots.
@@ -4189,6 +4400,7 @@  discard block
 block discarded – undo
4189 4400
 
4190 4401
 				if (document.getElementById(\'debug_section\').scrollHeight)
4191 4402
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4403
+		}
4192 4404
 
4193 4405
 		echo '
4194 4406
 				// Update the page.
@@ -4249,9 +4461,10 @@  discard block
 block discarded – undo
4249 4461
 			}';
4250 4462
 
4251 4463
 		// Start things off assuming we've not errored.
4252
-		if (empty($upcontext['error_message']))
4253
-			echo '
4464
+		if (empty($upcontext['error_message'])) {
4465
+					echo '
4254 4466
 			getNextItem();';
4467
+		}
4255 4468
 
4256 4469
 		echo '
4257 4470
 		</script>';
@@ -4268,18 +4481,21 @@  discard block
 block discarded – undo
4268 4481
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4269 4482
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4270 4483
 
4271
-	if (!empty($upcontext['error_message']))
4272
-		echo '
4484
+	if (!empty($upcontext['error_message'])) {
4485
+			echo '
4273 4486
 	<error>', $upcontext['error_message'], '</error>';
4487
+	}
4274 4488
 
4275
-	if (!empty($upcontext['error_string']))
4276
-		echo '
4489
+	if (!empty($upcontext['error_string'])) {
4490
+			echo '
4277 4491
 	<sql>', $upcontext['error_string'], '</sql>';
4492
+	}
4278 4493
 
4279
-	if ($is_debug)
4280
-		echo '
4494
+	if ($is_debug) {
4495
+			echo '
4281 4496
 	<curtime>', time(), '</curtime>';
4282
-}
4497
+	}
4498
+	}
4283 4499
 
4284 4500
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4285 4501
 function template_convert_utf8()
@@ -4296,18 +4512,20 @@  discard block
 block discarded – undo
4296 4512
 			<span id="debuginfo"></span>';
4297 4513
 
4298 4514
 	// Done any tables so far?
4299
-	if (!empty($upcontext['previous_tables']))
4300
-		foreach ($upcontext['previous_tables'] as $table)
4515
+	if (!empty($upcontext['previous_tables'])) {
4516
+			foreach ($upcontext['previous_tables'] as $table)
4301 4517
 			echo '
4302 4518
 			<br>Completed Table: &quot;', $table, '&quot;.';
4519
+	}
4303 4520
 
4304 4521
 	echo '
4305 4522
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4306 4523
 
4307 4524
 	// If we dropped their index, let's let them know
4308
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4309
-		echo '
4525
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4526
+			echo '
4310 4527
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4528
+	}
4311 4529
 
4312 4530
 	echo '
4313 4531
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>';
@@ -4343,9 +4561,10 @@  discard block
 block discarded – undo
4343 4561
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4344 4562
 
4345 4563
 		// If debug flood the screen.
4346
-		if ($is_debug)
4347
-			echo '
4564
+		if ($is_debug) {
4565
+					echo '
4348 4566
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4567
+		}
4349 4568
 
4350 4569
 		echo '
4351 4570
 				// Get the next update...
@@ -4387,19 +4606,21 @@  discard block
 block discarded – undo
4387 4606
 			<span id="debuginfo"></span>';
4388 4607
 
4389 4608
 	// Dont any tables so far?
4390
-	if (!empty($upcontext['previous_tables']))
4391
-		foreach ($upcontext['previous_tables'] as $table)
4609
+	if (!empty($upcontext['previous_tables'])) {
4610
+			foreach ($upcontext['previous_tables'] as $table)
4392 4611
 			echo '
4393 4612
 			<br>Completed Table: &quot;', $table, '&quot;.';
4613
+	}
4394 4614
 
4395 4615
 	echo '
4396 4616
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4397 4617
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4398 4618
 
4399 4619
 	// Try to make sure substep was reset.
4400
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4401
-		echo '
4620
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4621
+			echo '
4402 4622
 			<input type="hidden" name="substep" id="substep" value="0">';
4623
+	}
4403 4624
 
4404 4625
 	// Continue please!
4405 4626
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4432,9 +4653,10 @@  discard block
 block discarded – undo
4432 4653
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4433 4654
 
4434 4655
 		// If debug flood the screen.
4435
-		if ($is_debug)
4436
-			echo '
4656
+		if ($is_debug) {
4657
+					echo '
4437 4658
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4659
+		}
4438 4660
 
4439 4661
 		echo '
4440 4662
 				// Get the next update...
@@ -4469,8 +4691,8 @@  discard block
 block discarded – undo
4469 4691
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4470 4692
 	<form action="', $boardurl, '/index.php">';
4471 4693
 
4472
-	if (!empty($upcontext['can_delete_script']))
4473
-		echo '
4694
+	if (!empty($upcontext['can_delete_script'])) {
4695
+			echo '
4474 4696
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4475 4697
 			<script>
4476 4698
 				function doTheDelete(theCheck)
@@ -4482,6 +4704,7 @@  discard block
 block discarded – undo
4482 4704
 				}
4483 4705
 			</script>
4484 4706
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4707
+	}
4485 4708
 
4486 4709
 	$active = time() - $upcontext['started'];
4487 4710
 	$hours = floor($active / 3600);
@@ -4491,16 +4714,20 @@  discard block
 block discarded – undo
4491 4714
 	if ($is_debug)
4492 4715
 	{
4493 4716
 		$totalTime = '';
4494
-		if ($hours > 0)
4495
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4496
-		if ($minutes > 0)
4497
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4498
-		if ($seconds > 0)
4499
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4717
+		if ($hours > 0) {
4718
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4719
+		}
4720
+		if ($minutes > 0) {
4721
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4722
+		}
4723
+		if ($seconds > 0) {
4724
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4725
+		}
4500 4726
 	}
4501 4727
 
4502
-	if ($is_debug && !empty($totalTime))
4503
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4728
+	if ($is_debug && !empty($totalTime)) {
4729
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4730
+	}
4504 4731
 
4505 4732
 	echo '<br>
4506 4733
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4567,16 +4794,19 @@  discard block
 block discarded – undo
4567 4794
 				'empty' => '',
4568 4795
 				'limit' => $limit,
4569 4796
 		));
4570
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4571
-			$arIp[] = $row[$oldCol];
4797
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4798
+					$arIp[] = $row[$oldCol];
4799
+		}
4572 4800
 		$smcFunc['db_free_result']($request);
4573 4801
 
4574 4802
 		// Special case, null ip could keep us in a loop.
4575
-		if (is_null($arIp[0]))
4576
-			unset($arIp[0]);
4803
+		if (is_null($arIp[0])) {
4804
+					unset($arIp[0]);
4805
+		}
4577 4806
 
4578
-		if (empty($arIp))
4579
-			$is_done = true;
4807
+		if (empty($arIp)) {
4808
+					$is_done = true;
4809
+		}
4580 4810
 
4581 4811
 		$updates = array();
4582 4812
 		$cases = array();
@@ -4585,16 +4815,18 @@  discard block
 block discarded – undo
4585 4815
 		{
4586 4816
 			$arIp[$i] = trim($arIp[$i]);
4587 4817
 
4588
-			if (empty($arIp[$i]))
4589
-				continue;
4818
+			if (empty($arIp[$i])) {
4819
+							continue;
4820
+			}
4590 4821
 
4591 4822
 			$updates['ip' . $i] = $arIp[$i];
4592 4823
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4593 4824
 
4594 4825
 			if ($setSize > 0 && $i % $setSize === 0)
4595 4826
 			{
4596
-				if (count($updates) == 1)
4597
-					continue;
4827
+				if (count($updates) == 1) {
4828
+									continue;
4829
+				}
4598 4830
 
4599 4831
 				$updates['whereSet'] = array_values($updates);
4600 4832
 				$smcFunc['db_query']('', '
@@ -4628,8 +4860,7 @@  discard block
 block discarded – undo
4628 4860
 							'ip' => $ip
4629 4861
 					));
4630 4862
 				}
4631
-			}
4632
-			else
4863
+			} else
4633 4864
 			{
4634 4865
 				$updates['whereSet'] = array_values($updates);
4635 4866
 				$smcFunc['db_query']('', '
@@ -4643,9 +4874,9 @@  discard block
 block discarded – undo
4643 4874
 					$updates
4644 4875
 				);
4645 4876
 			}
4877
+		} else {
4878
+					$is_done = true;
4646 4879
 		}
4647
-		else
4648
-			$is_done = true;
4649 4880
 
4650 4881
 		$_GET['a'] += $limit;
4651 4882
 		$step_progress['current'] = $_GET['a'];
@@ -4671,10 +4902,11 @@  discard block
 block discarded – undo
4671 4902
  
4672 4903
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4673 4904
 
4674
-	if (isset($columns[$column]))
4675
-		return $columns[$column];
4676
-	else
4677
-		return null;
4678
-}
4905
+	if (isset($columns[$column])) {
4906
+			return $columns[$column];
4907
+	} else {
4908
+			return null;
4909
+	}
4910
+	}
4679 4911
 
4680 4912
 ?>
4681 4913
\ No newline at end of file
Please login to merge, or discard this patch.
SSI.php 1 patch
Braces   +428 added lines, -304 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Don't do anything if SMF is already loaded.
15
-if (defined('SMF'))
15
+if (defined('SMF')) {
16 16
 	return true;
17
+}
17 18
 
18 19
 define('SMF', 'SSI');
19 20
 
@@ -26,21 +27,24 @@  discard block
 block discarded – undo
26 27
 
27 28
 // Remember the current configuration so it can be set back.
28 29
 $ssi_magic_quotes_runtime = function_exists('get_magic_quotes_gpc') && get_magic_quotes_runtime();
29
-if (function_exists('set_magic_quotes_runtime'))
30
+if (function_exists('set_magic_quotes_runtime')) {
30 31
 	@set_magic_quotes_runtime(0);
32
+}
31 33
 $time_start = microtime();
32 34
 
33 35
 // Just being safe...
34
-foreach (array('db_character_set', 'cachedir') as $variable)
36
+foreach (array('db_character_set', 'cachedir') as $variable) {
35 37
 	if (isset($GLOBALS[$variable]))
36 38
 		unset($GLOBALS[$variable]);
39
+}
37 40
 
38 41
 // Get the forum's settings for database and file paths.
39 42
 require_once(dirname(__FILE__) . '/Settings.php');
40 43
 
41 44
 // Make absolutely sure the cache directory is defined.
42
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
45
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
43 46
 	$cachedir = $boarddir . '/cache';
47
+}
44 48
 
45 49
 $ssi_error_reporting = error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL);
46 50
 /* Set this to one of three values depending on what you want to happen in the case of a fatal error.
@@ -51,12 +55,14 @@  discard block
 block discarded – undo
51 55
 $ssi_on_error_method = false;
52 56
 
53 57
 // Don't do john didley if the forum's been shut down completely.
54
-if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true))
58
+if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) {
55 59
 	die($mmessage);
60
+}
56 61
 
57 62
 // Fix for using the current directory as a path.
58
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
63
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
59 64
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
65
+}
60 66
 
61 67
 // Load the important includes.
62 68
 require_once($sourcedir . '/QueryString.php');
@@ -81,34 +87,38 @@  discard block
 block discarded – undo
81 87
 cleanRequest();
82 88
 
83 89
 // Seed the random generator?
84
-if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
90
+if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) {
85 91
 	smf_seed_generator();
92
+}
86 93
 
87 94
 // Check on any hacking attempts.
88
-if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
95
+if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
89 96
 	die('No direct access...');
90
-elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme)
97
+} elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) {
91 98
 	die('No direct access...');
92
-elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme)
99
+} elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) {
93 100
 	die('No direct access...');
94
-elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers)
101
+} elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) {
95 102
 	die('No direct access...');
96
-if (isset($_REQUEST['context']))
103
+}
104
+if (isset($_REQUEST['context'])) {
97 105
 	die('No direct access...');
106
+}
98 107
 
99 108
 // Gzip output? (because it must be boolean and true, this can't be hacked.)
100
-if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>='))
109
+if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) {
101 110
 	ob_start('ob_gzhandler');
102
-else
111
+} else {
103 112
 	$modSettings['enableCompressedOutput'] = '0';
113
+}
104 114
 
105 115
 // Primarily, this is to fix the URLs...
106 116
 ob_start('ob_sessrewrite');
107 117
 
108 118
 // Start the session... known to scramble SSI includes in cases...
109
-if (!headers_sent())
119
+if (!headers_sent()) {
110 120
 	loadSession();
111
-else
121
+} else
112 122
 {
113 123
 	if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()]))
114 124
 	{
@@ -142,12 +152,14 @@  discard block
 block discarded – undo
142 152
 loadTheme(isset($ssi_theme) ? (int) $ssi_theme : 0);
143 153
 
144 154
 // @todo: probably not the best place, but somewhere it should be set...
145
-if (!headers_sent())
155
+if (!headers_sent()) {
146 156
 	header('Content-Type: text/html; charset=' . (empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set']));
157
+}
147 158
 
148 159
 // Take care of any banning that needs to be done.
149
-if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true))
160
+if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) {
150 161
 	is_not_banned();
162
+}
151 163
 
152 164
 // Do we allow guests in here?
153 165
 if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php')
@@ -162,17 +174,19 @@  discard block
 block discarded – undo
162 174
 {
163 175
 	$context['template_layers'] = $ssi_layers;
164 176
 	template_header();
165
-}
166
-else
177
+} else {
167 178
 	setupThemeContext();
179
+}
168 180
 
169 181
 // Make sure they didn't muss around with the settings... but only if it's not cli.
170
-if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '')
182
+if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') {
171 183
 	trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);
184
+}
172 185
 
173 186
 // Without visiting the forum this session variable might not be set on submit.
174
-if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote'))
187
+if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) {
175 188
 	$_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
189
+}
176 190
 
177 191
 // Have the ability to easily add functions to SSI.
178 192
 call_integration_hook('integrate_SSI');
@@ -183,15 +197,18 @@  discard block
 block discarded – undo
183 197
 	call_user_func('ssi_' . $_GET['ssi_function']);
184 198
 	exit;
185 199
 }
186
-if (isset($_GET['ssi_function']))
200
+if (isset($_GET['ssi_function'])) {
187 201
 	exit;
202
+}
188 203
 // You shouldn't just access SSI.php directly by URL!!
189
-elseif (basename($_SERVER['PHP_SELF']) == 'SSI.php')
204
+elseif (basename($_SERVER['PHP_SELF']) == 'SSI.php') {
190 205
 	die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
206
+}
191 207
 
192 208
 error_reporting($ssi_error_reporting);
193
-if (function_exists('set_magic_quotes_runtime'))
209
+if (function_exists('set_magic_quotes_runtime')) {
194 210
 	@set_magic_quotes_runtime($ssi_magic_quotes_runtime);
211
+}
195 212
 
196 213
 return true;
197 214
 
@@ -201,9 +218,10 @@  discard block
 block discarded – undo
201 218
  */
202 219
 function ssi_shutdown()
203 220
 {
204
-	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown')
205
-		template_footer();
206
-}
221
+	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') {
222
+			template_footer();
223
+	}
224
+	}
207 225
 
208 226
 /**
209 227
  * Display a welcome message, like: Hey, User, you have 0 messages, 0 are new.
@@ -216,15 +234,17 @@  discard block
 block discarded – undo
216 234
 
217 235
 	if ($output_method == 'echo')
218 236
 	{
219
-		if ($context['user']['is_guest'])
220
-			echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
221
-		else
222
-			echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
237
+		if ($context['user']['is_guest']) {
238
+					echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
239
+		} else {
240
+					echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
241
+		}
223 242
 	}
224 243
 	// Don't echo... then do what?!
225
-	else
226
-		return $context['user'];
227
-}
244
+	else {
245
+			return $context['user'];
246
+	}
247
+	}
228 248
 
229 249
 /**
230 250
  * Display a menu bar, like is displayed at the top of the forum.
@@ -235,12 +255,14 @@  discard block
 block discarded – undo
235 255
 {
236 256
 	global $context;
237 257
 
238
-	if ($output_method == 'echo')
239
-		template_menu();
258
+	if ($output_method == 'echo') {
259
+			template_menu();
260
+	}
240 261
 	// What else could this do?
241
-	else
242
-		return $context['menu_buttons'];
243
-}
262
+	else {
263
+			return $context['menu_buttons'];
264
+	}
265
+	}
244 266
 
245 267
 /**
246 268
  * Show a logout link.
@@ -252,20 +274,23 @@  discard block
 block discarded – undo
252 274
 {
253 275
 	global $context, $txt, $scripturl;
254 276
 
255
-	if ($redirect_to != '')
256
-		$_SESSION['logout_url'] = $redirect_to;
277
+	if ($redirect_to != '') {
278
+			$_SESSION['logout_url'] = $redirect_to;
279
+	}
257 280
 
258 281
 	// Guests can't log out.
259
-	if ($context['user']['is_guest'])
260
-		return false;
282
+	if ($context['user']['is_guest']) {
283
+			return false;
284
+	}
261 285
 
262 286
 	$link = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>';
263 287
 
264
-	if ($output_method == 'echo')
265
-		echo $link;
266
-	else
267
-		return $link;
268
-}
288
+	if ($output_method == 'echo') {
289
+			echo $link;
290
+	} else {
291
+			return $link;
292
+	}
293
+	}
269 294
 
270 295
 /**
271 296
  * Recent post list:   [board] Subject by Poster    Date
@@ -281,17 +306,17 @@  discard block
 block discarded – undo
281 306
 	global $modSettings, $context;
282 307
 
283 308
 	// Excluding certain boards...
284
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
285
-		$exclude_boards = array($modSettings['recycle_board']);
286
-	else
287
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
309
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
310
+			$exclude_boards = array($modSettings['recycle_board']);
311
+	} else {
312
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
313
+	}
288 314
 
289 315
 	// What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter.
290 316
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
291 317
 	{
292 318
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
293
-	}
294
-	elseif ($include_boards != null)
319
+	} elseif ($include_boards != null)
295 320
 	{
296 321
 		$include_boards = array();
297 322
 	}
@@ -328,8 +353,9 @@  discard block
 block discarded – undo
328 353
 {
329 354
 	global $modSettings;
330 355
 
331
-	if (empty($post_ids))
332
-		return;
356
+	if (empty($post_ids)) {
357
+			return;
358
+	}
333 359
 
334 360
 	// Allow the user to request more than one - why not?
335 361
 	$post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
@@ -364,8 +390,9 @@  discard block
 block discarded – undo
364 390
 	global $scripturl, $txt, $user_info;
365 391
 	global $modSettings, $smcFunc, $context;
366 392
 
367
-	if (!empty($modSettings['enable_likes']))
368
-		$context['can_like'] = allowedTo('likes_like');
393
+	if (!empty($modSettings['enable_likes'])) {
394
+			$context['can_like'] = allowedTo('likes_like');
395
+	}
369 396
 
370 397
 	// Find all the posts. Newer ones will have higher IDs.
371 398
 	$request = $smcFunc['db_query']('substring', '
@@ -431,12 +458,13 @@  discard block
 block discarded – undo
431 458
 		);
432 459
 
433 460
 		// Get the likes for each message.
434
-		if (!empty($modSettings['enable_likes']))
435
-			$posts[$row['id_msg']]['likes'] = array(
461
+		if (!empty($modSettings['enable_likes'])) {
462
+					$posts[$row['id_msg']]['likes'] = array(
436 463
 				'count' => $row['likes'],
437 464
 				'you' => in_array($row['id_msg'], prepareLikesContext($row['id_topic'])),
438 465
 				'can_like' => !$context['user']['is_guest'] && $row['id_member'] != $context['user']['id'] && !empty($context['can_like']),
439 466
 			);
467
+		}
440 468
 	}
441 469
 	$smcFunc['db_free_result']($request);
442 470
 
@@ -444,13 +472,14 @@  discard block
 block discarded – undo
444 472
 	call_integration_hook('integrate_ssi_queryPosts', array(&$posts));
445 473
 
446 474
 	// Just return it.
447
-	if ($output_method != 'echo' || empty($posts))
448
-		return $posts;
475
+	if ($output_method != 'echo' || empty($posts)) {
476
+			return $posts;
477
+	}
449 478
 
450 479
 	echo '
451 480
 		<table style="border: none" class="ssi_table">';
452
-	foreach ($posts as $post)
453
-		echo '
481
+	foreach ($posts as $post) {
482
+			echo '
454 483
 			<tr>
455 484
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
456 485
 					[', $post['board']['link'], ']
@@ -464,6 +493,7 @@  discard block
 block discarded – undo
464 493
 					', $post['time'], '
465 494
 				</td>
466 495
 			</tr>';
496
+	}
467 497
 	echo '
468 498
 		</table>';
469 499
 }
@@ -481,25 +511,26 @@  discard block
 block discarded – undo
481 511
 	global $settings, $scripturl, $txt, $user_info;
482 512
 	global $modSettings, $smcFunc, $context;
483 513
 
484
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
485
-		$exclude_boards = array($modSettings['recycle_board']);
486
-	else
487
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
514
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
515
+			$exclude_boards = array($modSettings['recycle_board']);
516
+	} else {
517
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
518
+	}
488 519
 
489 520
 	// Only some boards?.
490 521
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
491 522
 	{
492 523
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
493
-	}
494
-	elseif ($include_boards != null)
524
+	} elseif ($include_boards != null)
495 525
 	{
496 526
 		$output_method = $include_boards;
497 527
 		$include_boards = array();
498 528
 	}
499 529
 
500 530
 	$icon_sources = array();
501
-	foreach ($context['stable_icons'] as $icon)
502
-		$icon_sources[$icon] = 'images_url';
531
+	foreach ($context['stable_icons'] as $icon) {
532
+			$icon_sources[$icon] = 'images_url';
533
+	}
503 534
 
504 535
 	// Find all the posts in distinct topics.  Newer ones will have higher IDs.
505 536
 	$request = $smcFunc['db_query']('substring', '
@@ -524,13 +555,15 @@  discard block
 block discarded – undo
524 555
 		)
525 556
 	);
526 557
 	$topics = array();
527
-	while ($row = $smcFunc['db_fetch_assoc']($request))
528
-		$topics[$row['id_topic']] = $row;
558
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
559
+			$topics[$row['id_topic']] = $row;
560
+	}
529 561
 	$smcFunc['db_free_result']($request);
530 562
 
531 563
 	// Did we find anything? If not, bail.
532
-	if (empty($topics))
533
-		return array();
564
+	if (empty($topics)) {
565
+			return array();
566
+	}
534 567
 
535 568
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
536 569
 
@@ -558,19 +591,22 @@  discard block
 block discarded – undo
558 591
 	while ($row = $smcFunc['db_fetch_assoc']($request))
559 592
 	{
560 593
 		$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => '&#10;')));
561
-		if ($smcFunc['strlen']($row['body']) > 128)
562
-			$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
594
+		if ($smcFunc['strlen']($row['body']) > 128) {
595
+					$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
596
+		}
563 597
 
564 598
 		// Censor the subject.
565 599
 		censorText($row['subject']);
566 600
 		censorText($row['body']);
567 601
 
568 602
 		// Recycled icon
569
-		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board'])
570
-			$row['icon'] = 'recycled';
603
+		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) {
604
+					$row['icon'] = 'recycled';
605
+		}
571 606
 
572
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
573
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
607
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
608
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
609
+		}
574 610
 
575 611
 		// Build the array.
576 612
 		$posts[] = array(
@@ -609,13 +645,14 @@  discard block
 block discarded – undo
609 645
 	call_integration_hook('integrate_ssi_recentTopics', array(&$posts));
610 646
 
611 647
 	// Just return it.
612
-	if ($output_method != 'echo' || empty($posts))
613
-		return $posts;
648
+	if ($output_method != 'echo' || empty($posts)) {
649
+			return $posts;
650
+	}
614 651
 
615 652
 	echo '
616 653
 		<table style="border: none" class="ssi_table">';
617
-	foreach ($posts as $post)
618
-		echo '
654
+	foreach ($posts as $post) {
655
+			echo '
619 656
 			<tr>
620 657
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
621 658
 					[', $post['board']['link'], ']
@@ -629,6 +666,7 @@  discard block
 block discarded – undo
629 666
 					', $post['time'], '
630 667
 				</td>
631 668
 			</tr>';
669
+	}
632 670
 	echo '
633 671
 		</table>';
634 672
 }
@@ -653,27 +691,30 @@  discard block
 block discarded – undo
653 691
 		)
654 692
 	);
655 693
 	$return = array();
656
-	while ($row = $smcFunc['db_fetch_assoc']($request))
657
-		$return[] = array(
694
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
695
+			$return[] = array(
658 696
 			'id' => $row['id_member'],
659 697
 			'name' => $row['real_name'],
660 698
 			'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
661 699
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
662 700
 			'posts' => $row['posts']
663 701
 		);
702
+	}
664 703
 	$smcFunc['db_free_result']($request);
665 704
 
666 705
 	// If mods want to do somthing with this list of members, let them do that now.
667 706
 	call_integration_hook('integrate_ssi_topPoster', array(&$return));
668 707
 
669 708
 	// Just return all the top posters.
670
-	if ($output_method != 'echo')
671
-		return $return;
709
+	if ($output_method != 'echo') {
710
+			return $return;
711
+	}
672 712
 
673 713
 	// Make a quick array to list the links in.
674 714
 	$temp_array = array();
675
-	foreach ($return as $member)
676
-		$temp_array[] = $member['link'];
715
+	foreach ($return as $member) {
716
+			$temp_array[] = $member['link'];
717
+	}
677 718
 
678 719
 	echo implode(', ', $temp_array);
679 720
 }
@@ -705,8 +746,8 @@  discard block
 block discarded – undo
705 746
 		)
706 747
 	);
707 748
 	$boards = array();
708
-	while ($row = $smcFunc['db_fetch_assoc']($request))
709
-		$boards[] = array(
749
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
750
+			$boards[] = array(
710 751
 			'id' => $row['id_board'],
711 752
 			'num_posts' => $row['num_posts'],
712 753
 			'num_topics' => $row['num_topics'],
@@ -715,14 +756,16 @@  discard block
 block discarded – undo
715 756
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
716 757
 			'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'
717 758
 		);
759
+	}
718 760
 	$smcFunc['db_free_result']($request);
719 761
 
720 762
 	// If mods want to do somthing with this list of boards, let them do that now.
721 763
 	call_integration_hook('integrate_ssi_topBoards', array(&$boards));
722 764
 
723 765
 	// If we shouldn't output or have nothing to output, just jump out.
724
-	if ($output_method != 'echo' || empty($boards))
725
-		return $boards;
766
+	if ($output_method != 'echo' || empty($boards)) {
767
+			return $boards;
768
+	}
726 769
 
727 770
 	echo '
728 771
 		<table class="ssi_table">
@@ -731,13 +774,14 @@  discard block
 block discarded – undo
731 774
 				<th style="text-align: left">', $txt['board_topics'], '</th>
732 775
 				<th style="text-align: left">', $txt['posts'], '</th>
733 776
 			</tr>';
734
-	foreach ($boards as $sBoard)
735
-		echo '
777
+	foreach ($boards as $sBoard) {
778
+			echo '
736 779
 			<tr>
737 780
 				<td>', $sBoard['link'], $sBoard['new'] ? ' <a href="' . $sBoard['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>' : '', '</td>
738 781
 				<td style="text-align: right">', comma_format($sBoard['num_topics']), '</td>
739 782
 				<td style="text-align: right">', comma_format($sBoard['num_posts']), '</td>
740 783
 			</tr>';
784
+	}
741 785
 	echo '
742 786
 		</table>';
743 787
 }
@@ -770,12 +814,13 @@  discard block
 block discarded – undo
770 814
 			)
771 815
 		);
772 816
 		$topic_ids = array();
773
-		while ($row = $smcFunc['db_fetch_assoc']($request))
774
-			$topic_ids[] = $row['id_topic'];
817
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
818
+					$topic_ids[] = $row['id_topic'];
819
+		}
775 820
 		$smcFunc['db_free_result']($request);
821
+	} else {
822
+			$topic_ids = array();
776 823
 	}
777
-	else
778
-		$topic_ids = array();
779 824
 
780 825
 	$request = $smcFunc['db_query']('', '
781 826
 		SELECT m.subject, m.id_topic, t.num_views, t.num_replies
@@ -814,8 +859,9 @@  discard block
 block discarded – undo
814 859
 	// If mods want to do somthing with this list of topics, let them do that now.
815 860
 	call_integration_hook('integrate_ssi_topTopics', array(&$topics, $type));
816 861
 
817
-	if ($output_method != 'echo' || empty($topics))
818
-		return $topics;
862
+	if ($output_method != 'echo' || empty($topics)) {
863
+			return $topics;
864
+	}
819 865
 
820 866
 	echo '
821 867
 		<table class="ssi_table">
@@ -824,8 +870,8 @@  discard block
 block discarded – undo
824 870
 				<th style="text-align: left">', $txt['views'], '</th>
825 871
 				<th style="text-align: left">', $txt['replies'], '</th>
826 872
 			</tr>';
827
-	foreach ($topics as $sTopic)
828
-		echo '
873
+	foreach ($topics as $sTopic) {
874
+			echo '
829 875
 			<tr>
830 876
 				<td style="text-align: left">
831 877
 					', $sTopic['link'], '
@@ -833,6 +879,7 @@  discard block
 block discarded – undo
833 879
 				<td style="text-align: right">', comma_format($sTopic['num_views']), '</td>
834 880
 				<td style="text-align: right">', comma_format($sTopic['num_replies']), '</td>
835 881
 			</tr>';
882
+	}
836 883
 	echo '
837 884
 		</table>';
838 885
 }
@@ -868,12 +915,13 @@  discard block
 block discarded – undo
868 915
 {
869 916
 	global $txt, $context;
870 917
 
871
-	if ($output_method == 'echo')
872
-		echo '
918
+	if ($output_method == 'echo') {
919
+			echo '
873 920
 	', sprintf($txt['welcome_newest_member'], $context['common_stats']['latest_member']['link']), '<br>';
874
-	else
875
-		return $context['common_stats']['latest_member'];
876
-}
921
+	} else {
922
+			return $context['common_stats']['latest_member'];
923
+	}
924
+	}
877 925
 
878 926
 /**
879 927
  * Fetches a random member.
@@ -922,8 +970,9 @@  discard block
 block discarded – undo
922 970
 	}
923 971
 
924 972
 	// Just to be sure put the random generator back to something... random.
925
-	if ($random_type != '')
926
-		mt_srand(time());
973
+	if ($random_type != '') {
974
+			mt_srand(time());
975
+	}
927 976
 
928 977
 	return $result;
929 978
 }
@@ -936,8 +985,9 @@  discard block
 block discarded – undo
936 985
  */
937 986
 function ssi_fetchMember($member_ids = array(), $output_method = 'echo')
938 987
 {
939
-	if (empty($member_ids))
940
-		return;
988
+	if (empty($member_ids)) {
989
+			return;
990
+	}
941 991
 
942 992
 	// Can have more than one member if you really want...
943 993
 	$member_ids = is_array($member_ids) ? $member_ids : array($member_ids);
@@ -962,8 +1012,9 @@  discard block
 block discarded – undo
962 1012
  */
963 1013
 function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo')
964 1014
 {
965
-	if ($group_id === null)
966
-		return;
1015
+	if ($group_id === null) {
1016
+			return;
1017
+	}
967 1018
 
968 1019
 	$query_where = '
969 1020
 		id_group = {int:id_group}
@@ -990,8 +1041,9 @@  discard block
 block discarded – undo
990 1041
 {
991 1042
 	global $smcFunc, $memberContext;
992 1043
 
993
-	if ($query_where === null)
994
-		return;
1044
+	if ($query_where === null) {
1045
+			return;
1046
+	}
995 1047
 
996 1048
 	// Fetch the members in question.
997 1049
 	$request = $smcFunc['db_query']('', '
@@ -1004,12 +1056,14 @@  discard block
 block discarded – undo
1004 1056
 		))
1005 1057
 	);
1006 1058
 	$members = array();
1007
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1008
-		$members[] = $row['id_member'];
1059
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1060
+			$members[] = $row['id_member'];
1061
+	}
1009 1062
 	$smcFunc['db_free_result']($request);
1010 1063
 
1011
-	if (empty($members))
1012
-		return array();
1064
+	if (empty($members)) {
1065
+			return array();
1066
+	}
1013 1067
 
1014 1068
 	// If mods want to do somthing with this list of members, let them do that now.
1015 1069
 	call_integration_hook('integrate_ssi_queryMembers', array(&$members));
@@ -1018,23 +1072,25 @@  discard block
 block discarded – undo
1018 1072
 	loadMemberData($members);
1019 1073
 
1020 1074
 	// Draw the table!
1021
-	if ($output_method == 'echo')
1022
-		echo '
1075
+	if ($output_method == 'echo') {
1076
+			echo '
1023 1077
 		<table style="border: none" class="ssi_table">';
1078
+	}
1024 1079
 
1025 1080
 	$query_members = array();
1026 1081
 	foreach ($members as $member)
1027 1082
 	{
1028 1083
 		// Load their context data.
1029
-		if (!loadMemberContext($member))
1030
-			continue;
1084
+		if (!loadMemberContext($member)) {
1085
+					continue;
1086
+		}
1031 1087
 
1032 1088
 		// Store this member's information.
1033 1089
 		$query_members[$member] = $memberContext[$member];
1034 1090
 
1035 1091
 		// Only do something if we're echo'ing.
1036
-		if ($output_method == 'echo')
1037
-			echo '
1092
+		if ($output_method == 'echo') {
1093
+					echo '
1038 1094
 			<tr>
1039 1095
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
1040 1096
 					', $query_members[$member]['link'], '
@@ -1042,12 +1098,14 @@  discard block
 block discarded – undo
1042 1098
 					<br>', $query_members[$member]['avatar']['image'], '
1043 1099
 				</td>
1044 1100
 			</tr>';
1101
+		}
1045 1102
 	}
1046 1103
 
1047 1104
 	// End the table if appropriate.
1048
-	if ($output_method == 'echo')
1049
-		echo '
1105
+	if ($output_method == 'echo') {
1106
+			echo '
1050 1107
 		</table>';
1108
+	}
1051 1109
 
1052 1110
 	// Send back the data.
1053 1111
 	return $query_members;
@@ -1062,8 +1120,9 @@  discard block
 block discarded – undo
1062 1120
 {
1063 1121
 	global $txt, $scripturl, $modSettings, $smcFunc;
1064 1122
 
1065
-	if (!allowedTo('view_stats'))
1066
-		return;
1123
+	if (!allowedTo('view_stats')) {
1124
+			return;
1125
+	}
1067 1126
 
1068 1127
 	$totals = array(
1069 1128
 		'members' => $modSettings['totalMembers'],
@@ -1092,8 +1151,9 @@  discard block
 block discarded – undo
1092 1151
 	// If mods want to do somthing with the board stats, let them do that now.
1093 1152
 	call_integration_hook('integrate_ssi_boardStats', array(&$totals));
1094 1153
 
1095
-	if ($output_method != 'echo')
1096
-		return $totals;
1154
+	if ($output_method != 'echo') {
1155
+			return $totals;
1156
+	}
1097 1157
 
1098 1158
 	echo '
1099 1159
 		', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', comma_format($totals['members']), '</a><br>
@@ -1122,8 +1182,8 @@  discard block
 block discarded – undo
1122 1182
 	call_integration_hook('integrate_ssi_whosOnline', array(&$return));
1123 1183
 
1124 1184
 	// Add some redundancy for backwards compatibility reasons.
1125
-	if ($output_method != 'echo')
1126
-		return $return + array(
1185
+	if ($output_method != 'echo') {
1186
+			return $return + array(
1127 1187
 			'users' => $return['users_online'],
1128 1188
 			'guests' => $return['num_guests'],
1129 1189
 			'hidden' => $return['num_users_hidden'],
@@ -1131,29 +1191,35 @@  discard block
 block discarded – undo
1131 1191
 			'num_users' => $return['num_users_online'],
1132 1192
 			'total_users' => $return['num_users_online'] + $return['num_guests'],
1133 1193
 		);
1194
+	}
1134 1195
 
1135 1196
 	echo '
1136 1197
 		', comma_format($return['num_guests']), ' ', $return['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($return['num_users_online']), ' ', $return['num_users_online'] == 1 ? $txt['user'] : $txt['users'];
1137 1198
 
1138 1199
 	$bracketList = array();
1139
-	if (!empty($user_info['buddies']))
1140
-		$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1141
-	if (!empty($return['num_spiders']))
1142
-		$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1143
-	if (!empty($return['num_users_hidden']))
1144
-		$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1200
+	if (!empty($user_info['buddies'])) {
1201
+			$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1202
+	}
1203
+	if (!empty($return['num_spiders'])) {
1204
+			$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1205
+	}
1206
+	if (!empty($return['num_users_hidden'])) {
1207
+			$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1208
+	}
1145 1209
 
1146
-	if (!empty($bracketList))
1147
-		echo ' (' . implode(', ', $bracketList) . ')';
1210
+	if (!empty($bracketList)) {
1211
+			echo ' (' . implode(', ', $bracketList) . ')';
1212
+	}
1148 1213
 
1149 1214
 	echo '<br>
1150 1215
 			', implode(', ', $return['list_users_online']);
1151 1216
 
1152 1217
 	// Showing membergroups?
1153
-	if (!empty($settings['show_group_key']) && !empty($return['membergroups']))
1154
-		echo '<br>
1218
+	if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) {
1219
+			echo '<br>
1155 1220
 			[' . implode(']&nbsp;&nbsp;[', $return['membergroups']) . ']';
1156
-}
1221
+	}
1222
+	}
1157 1223
 
1158 1224
 /**
1159 1225
  * Just like whosOnline except it also logs the online presence.
@@ -1164,11 +1230,12 @@  discard block
 block discarded – undo
1164 1230
 {
1165 1231
 	writeLog();
1166 1232
 
1167
-	if ($output_method != 'echo')
1168
-		return ssi_whosOnline($output_method);
1169
-	else
1170
-		ssi_whosOnline($output_method);
1171
-}
1233
+	if ($output_method != 'echo') {
1234
+			return ssi_whosOnline($output_method);
1235
+	} else {
1236
+			ssi_whosOnline($output_method);
1237
+	}
1238
+	}
1172 1239
 
1173 1240
 // Shows a login box.
1174 1241
 /**
@@ -1181,11 +1248,13 @@  discard block
 block discarded – undo
1181 1248
 {
1182 1249
 	global $scripturl, $txt, $user_info, $context;
1183 1250
 
1184
-	if ($redirect_to != '')
1185
-		$_SESSION['login_url'] = $redirect_to;
1251
+	if ($redirect_to != '') {
1252
+			$_SESSION['login_url'] = $redirect_to;
1253
+	}
1186 1254
 
1187
-	if ($output_method != 'echo' || !$user_info['is_guest'])
1188
-		return $user_info['is_guest'];
1255
+	if ($output_method != 'echo' || !$user_info['is_guest']) {
1256
+			return $user_info['is_guest'];
1257
+	}
1189 1258
 
1190 1259
 	// Create a login token
1191 1260
 	createToken('login');
@@ -1237,8 +1306,9 @@  discard block
 block discarded – undo
1237 1306
 
1238 1307
 	$boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote'));
1239 1308
 
1240
-	if (empty($boardsAllowed))
1241
-		return array();
1309
+	if (empty($boardsAllowed)) {
1310
+			return array();
1311
+	}
1242 1312
 
1243 1313
 	$request = $smcFunc['db_query']('', '
1244 1314
 		SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time
@@ -1271,12 +1341,14 @@  discard block
 block discarded – undo
1271 1341
 	$smcFunc['db_free_result']($request);
1272 1342
 
1273 1343
 	// This user has voted on all the polls.
1274
-	if (empty($row) || !is_array($row))
1275
-		return array();
1344
+	if (empty($row) || !is_array($row)) {
1345
+			return array();
1346
+	}
1276 1347
 
1277 1348
 	// If this is a guest who's voted we'll through ourselves to show poll to show the results.
1278
-	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))))
1279
-		return ssi_showPoll($row['id_topic'], $output_method);
1349
+	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) {
1350
+			return ssi_showPoll($row['id_topic'], $output_method);
1351
+	}
1280 1352
 
1281 1353
 	$request = $smcFunc['db_query']('', '
1282 1354
 		SELECT COUNT(DISTINCT id_member)
@@ -1340,8 +1412,9 @@  discard block
 block discarded – undo
1340 1412
 	// If mods want to do somthing with this list of polls, let them do that now.
1341 1413
 	call_integration_hook('integrate_ssi_recentPoll', array(&$return, $topPollInstead));
1342 1414
 
1343
-	if ($output_method != 'echo')
1344
-		return $return;
1415
+	if ($output_method != 'echo') {
1416
+			return $return;
1417
+	}
1345 1418
 
1346 1419
 	if ($allow_view_results)
1347 1420
 	{
@@ -1350,19 +1423,20 @@  discard block
 block discarded – undo
1350 1423
 			<strong>', $return['question'], '</strong><br>
1351 1424
 			', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1352 1425
 
1353
-		foreach ($return['options'] as $option)
1354
-			echo '
1426
+		foreach ($return['options'] as $option) {
1427
+					echo '
1355 1428
 			<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1429
+		}
1356 1430
 
1357 1431
 		echo '
1358 1432
 			<input type="submit" value="', $txt['poll_vote'], '" class="button_submit">
1359 1433
 			<input type="hidden" name="poll" value="', $return['id'], '">
1360 1434
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1361 1435
 		</form>';
1436
+	} else {
1437
+			echo $txt['poll_cannot_see'];
1438
+	}
1362 1439
 	}
1363
-	else
1364
-		echo $txt['poll_cannot_see'];
1365
-}
1366 1440
 
1367 1441
 /**
1368 1442
  * Shows the poll from the specified topic
@@ -1376,13 +1450,15 @@  discard block
 block discarded – undo
1376 1450
 
1377 1451
 	$boardsAllowed = boardsAllowedTo('poll_view');
1378 1452
 
1379
-	if (empty($boardsAllowed))
1380
-		return array();
1453
+	if (empty($boardsAllowed)) {
1454
+			return array();
1455
+	}
1381 1456
 
1382
-	if ($topic === null && isset($_REQUEST['ssi_topic']))
1383
-		$topic = (int) $_REQUEST['ssi_topic'];
1384
-	else
1385
-		$topic = (int) $topic;
1457
+	if ($topic === null && isset($_REQUEST['ssi_topic'])) {
1458
+			$topic = (int) $_REQUEST['ssi_topic'];
1459
+	} else {
1460
+			$topic = (int) $topic;
1461
+	}
1386 1462
 
1387 1463
 	$request = $smcFunc['db_query']('', '
1388 1464
 		SELECT
@@ -1403,17 +1479,18 @@  discard block
 block discarded – undo
1403 1479
 	);
1404 1480
 
1405 1481
 	// Either this topic has no poll, or the user cannot view it.
1406
-	if ($smcFunc['db_num_rows']($request) == 0)
1407
-		return array();
1482
+	if ($smcFunc['db_num_rows']($request) == 0) {
1483
+			return array();
1484
+	}
1408 1485
 
1409 1486
 	$row = $smcFunc['db_fetch_assoc']($request);
1410 1487
 	$smcFunc['db_free_result']($request);
1411 1488
 
1412 1489
 	// Check if they can vote.
1413 1490
 	$already_voted = false;
1414
-	if (!empty($row['expire_time']) && $row['expire_time'] < time())
1415
-		$allow_vote = false;
1416
-	elseif ($user_info['is_guest'])
1491
+	if (!empty($row['expire_time']) && $row['expire_time'] < time()) {
1492
+			$allow_vote = false;
1493
+	} elseif ($user_info['is_guest'])
1417 1494
 	{
1418 1495
 		// There's a difference between "allowed to vote" and "already voted"...
1419 1496
 		$allow_vote = $row['guest_vote'];
@@ -1423,10 +1500,9 @@  discard block
 block discarded – undo
1423 1500
 		{
1424 1501
 			$already_voted = true;
1425 1502
 		}
1426
-	}
1427
-	elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board']))
1428
-		$allow_vote = false;
1429
-	else
1503
+	} elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) {
1504
+			$allow_vote = false;
1505
+	} else
1430 1506
 	{
1431 1507
 		$request = $smcFunc['db_query']('', '
1432 1508
 			SELECT id_member
@@ -1508,8 +1584,9 @@  discard block
 block discarded – undo
1508 1584
 	// If mods want to do somthing with this poll, let them do that now.
1509 1585
 	call_integration_hook('integrate_ssi_showPoll', array(&$return));
1510 1586
 
1511
-	if ($output_method != 'echo')
1512
-		return $return;
1587
+	if ($output_method != 'echo') {
1588
+			return $return;
1589
+	}
1513 1590
 
1514 1591
 	if ($return['allow_vote'])
1515 1592
 	{
@@ -1518,17 +1595,17 @@  discard block
 block discarded – undo
1518 1595
 				<strong>', $return['question'], '</strong><br>
1519 1596
 				', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1520 1597
 
1521
-		foreach ($return['options'] as $option)
1522
-			echo '
1598
+		foreach ($return['options'] as $option) {
1599
+					echo '
1523 1600
 				<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1601
+		}
1524 1602
 
1525 1603
 		echo '
1526 1604
 				<input type="submit" value="', $txt['poll_vote'], '" class="button_submit">
1527 1605
 				<input type="hidden" name="poll" value="', $return['id'], '">
1528 1606
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1529 1607
 			</form>';
1530
-	}
1531
-	else
1608
+	} else
1532 1609
 	{
1533 1610
 		echo '
1534 1611
 			<div class="ssi_poll">
@@ -1608,27 +1685,32 @@  discard block
 block discarded – undo
1608 1685
 			'is_approved' => 1,
1609 1686
 		)
1610 1687
 	);
1611
-	if ($smcFunc['db_num_rows']($request) == 0)
1612
-		die;
1688
+	if ($smcFunc['db_num_rows']($request) == 0) {
1689
+			die;
1690
+	}
1613 1691
 	$row = $smcFunc['db_fetch_assoc']($request);
1614 1692
 	$smcFunc['db_free_result']($request);
1615 1693
 
1616
-	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time']))
1617
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1694
+	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) {
1695
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1696
+	}
1618 1697
 
1619 1698
 	// Too many options checked?
1620
-	if (count($_REQUEST['options']) > $row['max_votes'])
1621
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1699
+	if (count($_REQUEST['options']) > $row['max_votes']) {
1700
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1701
+	}
1622 1702
 
1623 1703
 	// It's a guest who has already voted?
1624 1704
 	if ($user_info['is_guest'])
1625 1705
 	{
1626 1706
 		// Guest voting disabled?
1627
-		if (!$row['guest_vote'])
1628
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1707
+		if (!$row['guest_vote']) {
1708
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1709
+		}
1629 1710
 		// Already voted?
1630
-		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))
1631
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1711
+		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) {
1712
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1713
+		}
1632 1714
 	}
1633 1715
 
1634 1716
 	$sOptions = array();
@@ -1682,11 +1764,13 @@  discard block
 block discarded – undo
1682 1764
 {
1683 1765
 	global $scripturl, $txt, $context;
1684 1766
 
1685
-	if (!allowedTo('search_posts'))
1686
-		return;
1767
+	if (!allowedTo('search_posts')) {
1768
+			return;
1769
+	}
1687 1770
 
1688
-	if ($output_method != 'echo')
1689
-		return $scripturl . '?action=search';
1771
+	if ($output_method != 'echo') {
1772
+			return $scripturl . '?action=search';
1773
+	}
1690 1774
 
1691 1775
 	echo '
1692 1776
 		<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
@@ -1708,8 +1792,9 @@  discard block
 block discarded – undo
1708 1792
 	// If mods want to do somthing with the news, let them do that now. Don't need to pass the news line itself, since it is already in $context.
1709 1793
 	call_integration_hook('integrate_ssi_news');
1710 1794
 
1711
-	if ($output_method != 'echo')
1712
-		return $context['random_news_line'];
1795
+	if ($output_method != 'echo') {
1796
+			return $context['random_news_line'];
1797
+	}
1713 1798
 
1714 1799
 	echo $context['random_news_line'];
1715 1800
 }
@@ -1723,8 +1808,9 @@  discard block
 block discarded – undo
1723 1808
 {
1724 1809
 	global $scripturl, $modSettings, $user_info;
1725 1810
 
1726
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view'))
1727
-		return;
1811
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) {
1812
+			return;
1813
+	}
1728 1814
 
1729 1815
 	$eventOptions = array(
1730 1816
 		'include_birthdays' => true,
@@ -1735,13 +1821,15 @@  discard block
 block discarded – undo
1735 1821
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1736 1822
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1737 1823
 
1738
-	if ($output_method != 'echo')
1739
-		return $return['calendar_birthdays'];
1824
+	if ($output_method != 'echo') {
1825
+			return $return['calendar_birthdays'];
1826
+	}
1740 1827
 
1741
-	foreach ($return['calendar_birthdays'] as $member)
1742
-		echo '
1828
+	foreach ($return['calendar_birthdays'] as $member) {
1829
+			echo '
1743 1830
 			<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">' . $member['name'] . '</span>' . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>' . (!$member['is_last'] ? ', ' : '');
1744
-}
1831
+	}
1832
+	}
1745 1833
 
1746 1834
 /**
1747 1835
  * Shows today's holidays.
@@ -1752,8 +1840,9 @@  discard block
 block discarded – undo
1752 1840
 {
1753 1841
 	global $modSettings, $user_info;
1754 1842
 
1755
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1756
-		return;
1843
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1844
+			return;
1845
+	}
1757 1846
 
1758 1847
 	$eventOptions = array(
1759 1848
 		'include_holidays' => true,
@@ -1764,8 +1853,9 @@  discard block
 block discarded – undo
1764 1853
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1765 1854
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1766 1855
 
1767
-	if ($output_method != 'echo')
1768
-		return $return['calendar_holidays'];
1856
+	if ($output_method != 'echo') {
1857
+			return $return['calendar_holidays'];
1858
+	}
1769 1859
 
1770 1860
 	echo '
1771 1861
 		', implode(', ', $return['calendar_holidays']);
@@ -1779,8 +1869,9 @@  discard block
 block discarded – undo
1779 1869
 {
1780 1870
 	global $modSettings, $user_info;
1781 1871
 
1782
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1783
-		return;
1872
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1873
+			return;
1874
+	}
1784 1875
 
1785 1876
 	$eventOptions = array(
1786 1877
 		'include_events' => true,
@@ -1791,14 +1882,16 @@  discard block
 block discarded – undo
1791 1882
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1792 1883
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1793 1884
 
1794
-	if ($output_method != 'echo')
1795
-		return $return['calendar_events'];
1885
+	if ($output_method != 'echo') {
1886
+			return $return['calendar_events'];
1887
+	}
1796 1888
 
1797 1889
 	foreach ($return['calendar_events'] as $event)
1798 1890
 	{
1799
-		if ($event['can_edit'])
1800
-			echo '
1891
+		if ($event['can_edit']) {
1892
+					echo '
1801 1893
 	<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1894
+		}
1802 1895
 		echo '
1803 1896
 	' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1804 1897
 	}
@@ -1813,8 +1906,9 @@  discard block
 block discarded – undo
1813 1906
 {
1814 1907
 	global $modSettings, $txt, $scripturl, $user_info;
1815 1908
 
1816
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1817
-		return;
1909
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1910
+			return;
1911
+	}
1818 1912
 
1819 1913
 	$eventOptions = array(
1820 1914
 		'include_birthdays' => allowedTo('profile_view'),
@@ -1827,19 +1921,22 @@  discard block
 block discarded – undo
1827 1921
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1828 1922
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1829 1923
 
1830
-	if ($output_method != 'echo')
1831
-		return $return;
1924
+	if ($output_method != 'echo') {
1925
+			return $return;
1926
+	}
1832 1927
 
1833
-	if (!empty($return['calendar_holidays']))
1834
-		echo '
1928
+	if (!empty($return['calendar_holidays'])) {
1929
+			echo '
1835 1930
 			<span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br></span>';
1931
+	}
1836 1932
 	if (!empty($return['calendar_birthdays']))
1837 1933
 	{
1838 1934
 		echo '
1839 1935
 			<span class="birthday">' . $txt['birthdays_upcoming'] . '</span> ';
1840
-		foreach ($return['calendar_birthdays'] as $member)
1841
-			echo '
1936
+		foreach ($return['calendar_birthdays'] as $member) {
1937
+					echo '
1842 1938
 			<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', !$member['is_last'] ? ', ' : '';
1939
+		}
1843 1940
 		echo '
1844 1941
 			<br>';
1845 1942
 	}
@@ -1849,9 +1946,10 @@  discard block
 block discarded – undo
1849 1946
 			<span class="event">' . $txt['events_upcoming'] . '</span> ';
1850 1947
 		foreach ($return['calendar_events'] as $event)
1851 1948
 		{
1852
-			if ($event['can_edit'])
1853
-				echo '
1949
+			if ($event['can_edit']) {
1950
+							echo '
1854 1951
 			<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1952
+			}
1855 1953
 			echo '
1856 1954
 			' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1857 1955
 		}
@@ -1875,25 +1973,29 @@  discard block
 block discarded – undo
1875 1973
 	loadLanguage('Stats');
1876 1974
 
1877 1975
 	// Must be integers....
1878
-	if ($limit === null)
1879
-		$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
1880
-	else
1881
-		$limit = (int) $limit;
1882
-
1883
-	if ($start === null)
1884
-		$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1885
-	else
1886
-		$start = (int) $start;
1887
-
1888
-	if ($board !== null)
1889
-		$board = (int) $board;
1890
-	elseif (isset($_GET['board']))
1891
-		$board = (int) $_GET['board'];
1892
-
1893
-	if ($length === null)
1894
-		$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
1895
-	else
1896
-		$length = (int) $length;
1976
+	if ($limit === null) {
1977
+			$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
1978
+	} else {
1979
+			$limit = (int) $limit;
1980
+	}
1981
+
1982
+	if ($start === null) {
1983
+			$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1984
+	} else {
1985
+			$start = (int) $start;
1986
+	}
1987
+
1988
+	if ($board !== null) {
1989
+			$board = (int) $board;
1990
+	} elseif (isset($_GET['board'])) {
1991
+			$board = (int) $_GET['board'];
1992
+	}
1993
+
1994
+	if ($length === null) {
1995
+			$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
1996
+	} else {
1997
+			$length = (int) $length;
1998
+	}
1897 1999
 
1898 2000
 	$limit = max(0, $limit);
1899 2001
 	$start = max(0, $start);
@@ -1911,17 +2013,19 @@  discard block
 block discarded – undo
1911 2013
 	);
1912 2014
 	if ($smcFunc['db_num_rows']($request) == 0)
1913 2015
 	{
1914
-		if ($output_method == 'echo')
1915
-			die($txt['ssi_no_guests']);
1916
-		else
1917
-			return array();
2016
+		if ($output_method == 'echo') {
2017
+					die($txt['ssi_no_guests']);
2018
+		} else {
2019
+					return array();
2020
+		}
1918 2021
 	}
1919 2022
 	list ($board) = $smcFunc['db_fetch_row']($request);
1920 2023
 	$smcFunc['db_free_result']($request);
1921 2024
 
1922 2025
 	$icon_sources = array();
1923
-	foreach ($context['stable_icons'] as $icon)
1924
-		$icon_sources[$icon] = 'images_url';
2026
+	foreach ($context['stable_icons'] as $icon) {
2027
+			$icon_sources[$icon] = 'images_url';
2028
+	}
1925 2029
 
1926 2030
 	if (!empty($modSettings['enable_likes']))
1927 2031
 	{
@@ -1945,12 +2049,14 @@  discard block
 block discarded – undo
1945 2049
 		)
1946 2050
 	);
1947 2051
 	$posts = array();
1948
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1949
-		$posts[] = $row['id_first_msg'];
2052
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2053
+			$posts[] = $row['id_first_msg'];
2054
+	}
1950 2055
 	$smcFunc['db_free_result']($request);
1951 2056
 
1952
-	if (empty($posts))
1953
-		return array();
2057
+	if (empty($posts)) {
2058
+			return array();
2059
+	}
1954 2060
 
1955 2061
 	// Find the posts.
1956 2062
 	$request = $smcFunc['db_query']('', '
@@ -1980,24 +2086,28 @@  discard block
 block discarded – undo
1980 2086
 			$last_space = strrpos($row['body'], ' ');
1981 2087
 			$last_open = strrpos($row['body'], '<');
1982 2088
 			$last_close = strrpos($row['body'], '>');
1983
-			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6)
1984
-				$cutoff = $last_open;
1985
-			elseif (empty($last_close) || $last_close < $last_open)
1986
-				$cutoff = $last_space;
2089
+			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6) {
2090
+							$cutoff = $last_open;
2091
+			} elseif (empty($last_close) || $last_close < $last_open) {
2092
+							$cutoff = $last_space;
2093
+			}
1987 2094
 
1988
-			if ($cutoff !== false)
1989
-				$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2095
+			if ($cutoff !== false) {
2096
+							$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2097
+			}
1990 2098
 			$row['body'] .= '...';
1991 2099
 		}
1992 2100
 
1993 2101
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
1994 2102
 
1995
-		if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
1996
-			$row['icon'] = 'recycled';
2103
+		if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
2104
+					$row['icon'] = 'recycled';
2105
+		}
1997 2106
 
1998 2107
 		// Check that this message icon is there...
1999
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
2000
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2108
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
2109
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2110
+		}
2001 2111
 
2002 2112
 		censorText($row['subject']);
2003 2113
 		censorText($row['body']);
@@ -2034,16 +2144,18 @@  discard block
 block discarded – undo
2034 2144
 	}
2035 2145
 	$smcFunc['db_free_result']($request);
2036 2146
 
2037
-	if (empty($return))
2038
-		return $return;
2147
+	if (empty($return)) {
2148
+			return $return;
2149
+	}
2039 2150
 
2040 2151
 	$return[count($return) - 1]['is_last'] = true;
2041 2152
 
2042 2153
 	// If mods want to do somthing with this list of posts, let them do that now.
2043 2154
 	call_integration_hook('integrate_ssi_boardNews', array(&$return));
2044 2155
 
2045
-	if ($output_method != 'echo')
2046
-		return $return;
2156
+	if ($output_method != 'echo') {
2157
+			return $return;
2158
+	}
2047 2159
 
2048 2160
 	foreach ($return as $news)
2049 2161
 	{
@@ -2095,9 +2207,10 @@  discard block
 block discarded – undo
2095 2207
 		echo '
2096 2208
 			</div>';
2097 2209
 
2098
-		if (!$news['is_last'])
2099
-			echo '
2210
+		if (!$news['is_last']) {
2211
+					echo '
2100 2212
 			<hr>';
2213
+		}
2101 2214
 	}
2102 2215
 }
2103 2216
 
@@ -2111,8 +2224,9 @@  discard block
 block discarded – undo
2111 2224
 {
2112 2225
 	global $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc;
2113 2226
 
2114
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
2115
-		return;
2227
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
2228
+			return;
2229
+	}
2116 2230
 
2117 2231
 	// Find all events which are happening in the near future that the member can see.
2118 2232
 	$request = $smcFunc['db_query']('', '
@@ -2138,20 +2252,23 @@  discard block
 block discarded – undo
2138 2252
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2139 2253
 	{
2140 2254
 		// Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
2141
-		if (!empty($duplicates[$row['title'] . $row['id_topic']]))
2142
-			continue;
2255
+		if (!empty($duplicates[$row['title'] . $row['id_topic']])) {
2256
+					continue;
2257
+		}
2143 2258
 
2144 2259
 		// Censor the title.
2145 2260
 		censorText($row['title']);
2146 2261
 
2147
-		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false)))
2148
-			$date = strftime('%Y-%m-%d', forum_time(false));
2149
-		else
2150
-			$date = $row['start_date'];
2262
+		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) {
2263
+					$date = strftime('%Y-%m-%d', forum_time(false));
2264
+		} else {
2265
+					$date = $row['start_date'];
2266
+		}
2151 2267
 
2152 2268
 		// If the topic it is attached to is not approved then don't link it.
2153
-		if (!empty($row['id_first_msg']) && !$row['approved'])
2154
-			$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2269
+		if (!empty($row['id_first_msg']) && !$row['approved']) {
2270
+					$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2271
+		}
2155 2272
 
2156 2273
 		$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
2157 2274
 
@@ -2177,24 +2294,27 @@  discard block
 block discarded – undo
2177 2294
 	}
2178 2295
 	$smcFunc['db_free_result']($request);
2179 2296
 
2180
-	foreach ($return as $mday => $array)
2181
-		$return[$mday][count($array) - 1]['is_last'] = true;
2297
+	foreach ($return as $mday => $array) {
2298
+			$return[$mday][count($array) - 1]['is_last'] = true;
2299
+	}
2182 2300
 
2183 2301
 	// If mods want to do somthing with this list of events, let them do that now.
2184 2302
 	call_integration_hook('integrate_ssi_recentEvents', array(&$return));
2185 2303
 
2186
-	if ($output_method != 'echo' || empty($return))
2187
-		return $return;
2304
+	if ($output_method != 'echo' || empty($return)) {
2305
+			return $return;
2306
+	}
2188 2307
 
2189 2308
 	// Well the output method is echo.
2190 2309
 	echo '
2191 2310
 			<span class="event">' . $txt['events'] . '</span> ';
2192
-	foreach ($return as $mday => $array)
2193
-		foreach ($array as $event)
2311
+	foreach ($return as $mday => $array) {
2312
+			foreach ($array as $event)
2194 2313
 		{
2195 2314
 			if ($event['can_edit'])
2196 2315
 				echo '
2197 2316
 				<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
2317
+	}
2198 2318
 
2199 2319
 			echo '
2200 2320
 				' . $event['link'] . (!$event['is_last'] ? ', ' : '');
@@ -2213,8 +2333,9 @@  discard block
 block discarded – undo
2213 2333
 	global $smcFunc;
2214 2334
 
2215 2335
 	// If $id is null, this was most likely called from a query string and should do nothing.
2216
-	if ($id === null)
2217
-		return;
2336
+	if ($id === null) {
2337
+			return;
2338
+	}
2218 2339
 
2219 2340
 	$request = $smcFunc['db_query']('', '
2220 2341
 		SELECT passwd, member_name, is_activated
@@ -2246,8 +2367,9 @@  discard block
 block discarded – undo
2246 2367
 	$attachments_boards = boardsAllowedTo('view_attachments');
2247 2368
 
2248 2369
 	// No boards?  Adios amigo.
2249
-	if (empty($attachments_boards))
2250
-		return array();
2370
+	if (empty($attachments_boards)) {
2371
+			return array();
2372
+	}
2251 2373
 
2252 2374
 	// Is it an array?
2253 2375
 	$attachment_ext = (array) $attachment_ext;
@@ -2331,8 +2453,9 @@  discard block
 block discarded – undo
2331 2453
 	call_integration_hook('integrate_ssi_recentAttachments', array(&$attachments));
2332 2454
 
2333 2455
 	// So you just want an array?  Here you can have it.
2334
-	if ($output_method == 'array' || empty($attachments))
2335
-		return $attachments;
2456
+	if ($output_method == 'array' || empty($attachments)) {
2457
+			return $attachments;
2458
+	}
2336 2459
 
2337 2460
 	// Give them the default.
2338 2461
 	echo '
@@ -2343,14 +2466,15 @@  discard block
 block discarded – undo
2343 2466
 				<th style="text-align: left; padding: 2">', $txt['downloads'], '</th>
2344 2467
 				<th style="text-align: left; padding: 2">', $txt['filesize'], '</th>
2345 2468
 			</tr>';
2346
-	foreach ($attachments as $attach)
2347
-		echo '
2469
+	foreach ($attachments as $attach) {
2470
+			echo '
2348 2471
 			<tr>
2349 2472
 				<td>', $attach['file']['link'], '</td>
2350 2473
 				<td>', $attach['member']['link'], '</td>
2351 2474
 				<td style="text-align: center">', $attach['file']['downloads'], '</td>
2352 2475
 				<td>', $attach['file']['filesize'], '</td>
2353 2476
 			</tr>';
2477
+	}
2354 2478
 	echo '
2355 2479
 		</table>';
2356 2480
 }
Please login to merge, or discard this patch.
custom_avatar/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('Location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
attachments/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('Location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
Smileys/fugue/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Smileys/aaron/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Smileys/akyhne/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Smileys/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('Location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.