Completed
Push — release-2.1 ( 1cb854...9bc16d )
by
unknown
15s
created
Sources/Load.php 1 patch
Braces   +792 added lines, -597 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Load the $modSettings array.
@@ -25,13 +26,14 @@  discard block
 block discarded – undo
25 26
 	global $cache_enable, $sourcedir, $context;
26 27
 
27 28
 	// Most database systems have not set UTF-8 as their default input charset.
28
-	if (!empty($db_character_set))
29
-		$smcFunc['db_query']('', '
29
+	if (!empty($db_character_set)) {
30
+			$smcFunc['db_query']('', '
30 31
 			SET NAMES {string:db_character_set}',
31 32
 			array(
32 33
 				'db_character_set' => $db_character_set,
33 34
 			)
34 35
 		);
36
+	}
35 37
 
36 38
 	// We need some caching support, maybe.
37 39
 	loadCacheAccelerator();
@@ -46,28 +48,36 @@  discard block
 block discarded – undo
46 48
 			)
47 49
 		);
48 50
 		$modSettings = array();
49
-		if (!$request)
50
-			display_db_error();
51
-		while ($row = $smcFunc['db_fetch_row']($request))
52
-			$modSettings[$row[0]] = $row[1];
51
+		if (!$request) {
52
+					display_db_error();
53
+		}
54
+		while ($row = $smcFunc['db_fetch_row']($request)) {
55
+					$modSettings[$row[0]] = $row[1];
56
+		}
53 57
 		$smcFunc['db_free_result']($request);
54 58
 
55 59
 		// Do a few things to protect against missing settings or settings with invalid values...
56
-		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999)
57
-			$modSettings['defaultMaxTopics'] = 20;
58
-		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999)
59
-			$modSettings['defaultMaxMessages'] = 15;
60
-		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999)
61
-			$modSettings['defaultMaxMembers'] = 30;
62
-		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999)
63
-			$modSettings['defaultMaxListItems'] = 15;
60
+		if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) {
61
+					$modSettings['defaultMaxTopics'] = 20;
62
+		}
63
+		if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) {
64
+					$modSettings['defaultMaxMessages'] = 15;
65
+		}
66
+		if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) {
67
+					$modSettings['defaultMaxMembers'] = 30;
68
+		}
69
+		if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) {
70
+					$modSettings['defaultMaxListItems'] = 15;
71
+		}
64 72
 
65 73
 		// We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded.
66
-		if (!is_array($modSettings['attachmentUploadDir']))
67
-			$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
74
+		if (!is_array($modSettings['attachmentUploadDir'])) {
75
+					$modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true);
76
+		}
68 77
 
69
-		if (!empty($cache_enable))
70
-			cache_put_data('modSettings', $modSettings, 90);
78
+		if (!empty($cache_enable)) {
79
+					cache_put_data('modSettings', $modSettings, 90);
80
+		}
71 81
 	}
72 82
 
73 83
 	$modSettings['cache_enable'] = $cache_enable;
@@ -87,8 +97,9 @@  discard block
 block discarded – undo
87 97
 		};
88 98
 	$fix_utf8mb4 = function($string) use ($utf8, $smcFunc)
89 99
 	{
90
-		if (!$utf8 || $smcFunc['db_mb4'])
91
-			return $string;
100
+		if (!$utf8 || $smcFunc['db_mb4']) {
101
+					return $string;
102
+		}
92 103
 
93 104
 		$i = 0;
94 105
 		$len = strlen($string);
@@ -100,18 +111,15 @@  discard block
 block discarded – undo
100 111
 			{
101 112
 				$new_string .= $string[$i];
102 113
 				$i++;
103
-			}
104
-			elseif ($ord < 224)
114
+			} elseif ($ord < 224)
105 115
 			{
106 116
 				$new_string .= $string[$i] . $string[$i + 1];
107 117
 				$i += 2;
108
-			}
109
-			elseif ($ord < 240)
118
+			} elseif ($ord < 240)
110 119
 			{
111 120
 				$new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2];
112 121
 				$i += 3;
113
-			}
114
-			elseif ($ord < 248)
122
+			} elseif ($ord < 248)
115 123
 			{
116 124
 				// Magic happens.
117 125
 				$val = (ord($string[$i]) & 0x07) << 18;
@@ -155,8 +163,7 @@  discard block
 block discarded – undo
155 163
 			{
156 164
 				$result = array_search($needle, array_slice($haystack_arr, $offset));
157 165
 				return is_int($result) ? $result + $offset : false;
158
-			}
159
-			else
166
+			} else
160 167
 			{
161 168
 				$needle_arr = preg_split('~(' . $ent_list . '|.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
162 169
 				$needle_size = count($needle_arr);
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 				while ((int) $result === $result)
166 173
 				{
167 174
 					$offset += $result;
168
-					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr)
169
-						return $offset;
175
+					if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) {
176
+											return $offset;
177
+					}
170 178
 					$result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset));
171 179
 				}
172 180
 				return false;
@@ -204,8 +212,9 @@  discard block
 block discarded – undo
204 212
 			$string = $ent_check($string);
205 213
 			preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches);
206 214
 			$string = $matches[0];
207
-			while (strlen($string) > $length)
208
-				$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
215
+			while (strlen($string) > $length) {
216
+							$string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string);
217
+			}
209 218
 			return $string;
210 219
 		},
211 220
 		'ucfirst' => $utf8 ? function($string) use (&$smcFunc)
@@ -215,8 +224,9 @@  discard block
 block discarded – undo
215 224
 		'ucwords' => $utf8 ? function($string) use (&$smcFunc)
216 225
 		{
217 226
 			$words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
218
-			for ($i = 0, $n = count($words); $i < $n; $i += 2)
219
-				$words[$i] = $smcFunc['ucfirst']($words[$i]);
227
+			for ($i = 0, $n = count($words); $i < $n; $i += 2) {
228
+							$words[$i] = $smcFunc['ucfirst']($words[$i]);
229
+			}
220 230
 			return implode('', $words);
221 231
 		} : 'ucwords',
222 232
 		'json_decode' => 'smf_json_decode',
@@ -224,16 +234,17 @@  discard block
 block discarded – undo
224 234
 	);
225 235
 
226 236
 	// Setting the timezone is a requirement for some functions.
227
-	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list()))
228
-		date_default_timezone_set($modSettings['default_timezone']);
229
-	else
237
+	if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) {
238
+			date_default_timezone_set($modSettings['default_timezone']);
239
+	} else
230 240
 	{
231 241
 		// Get PHP's default timezone, if set
232 242
 		$ini_tz = ini_get('date.timezone');
233
-		if (!empty($ini_tz))
234
-			$modSettings['default_timezone'] = $ini_tz;
235
-		else
236
-			$modSettings['default_timezone'] = '';
243
+		if (!empty($ini_tz)) {
244
+					$modSettings['default_timezone'] = $ini_tz;
245
+		} else {
246
+					$modSettings['default_timezone'] = '';
247
+		}
237 248
 
238 249
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
239 250
 		if (!in_array($modSettings['default_timezone'], timezone_identifiers_list()))
@@ -251,22 +262,26 @@  discard block
 block discarded – undo
251 262
 		if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null)
252 263
 		{
253 264
 			$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
254
-			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0)
255
-				$modSettings['load_average'] = (float) $matches[1];
256
-			elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0)
257
-				$modSettings['load_average'] = (float) $matches[1];
258
-			else
259
-				unset($modSettings['load_average']);
265
+			if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) {
266
+							$modSettings['load_average'] = (float) $matches[1];
267
+			} elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) {
268
+							$modSettings['load_average'] = (float) $matches[1];
269
+			} else {
270
+							unset($modSettings['load_average']);
271
+			}
260 272
 
261
-			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
262
-				cache_put_data('loadavg', $modSettings['load_average'], 90);
273
+			if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
274
+							cache_put_data('loadavg', $modSettings['load_average'], 90);
275
+			}
263 276
 		}
264 277
 
265
-		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
266
-			call_integration_hook('integrate_load_average', array($modSettings['load_average']));
278
+		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) {
279
+					call_integration_hook('integrate_load_average', array($modSettings['load_average']));
280
+		}
267 281
 
268
-		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum'])
269
-			display_loadavg_error();
282
+		if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) {
283
+					display_loadavg_error();
284
+		}
270 285
 	}
271 286
 
272 287
 	// Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is.
@@ -287,8 +302,9 @@  discard block
 block discarded – undo
287 302
 	if (defined('SMF_INTEGRATION_SETTINGS'))
288 303
 	{
289 304
 		$integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true);
290
-		foreach ($integration_settings as $hook => $function)
291
-			add_integration_function($hook, $function, '', false);
305
+		foreach ($integration_settings as $hook => $function) {
306
+					add_integration_function($hook, $function, '', false);
307
+		}
292 308
 	}
293 309
 
294 310
 	// Any files to pre include?
@@ -298,8 +314,9 @@  discard block
 block discarded – undo
298 314
 		foreach ($pre_includes as $include)
299 315
 		{
300 316
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
301
-			if (file_exists($include))
302
-				require_once($include);
317
+			if (file_exists($include)) {
318
+							require_once($include);
319
+			}
303 320
 		}
304 321
 	}
305 322
 
@@ -392,9 +409,9 @@  discard block
 block discarded – undo
392 409
 				break;
393 410
 			}
394 411
 		}
412
+	} else {
413
+			$id_member = 0;
395 414
 	}
396
-	else
397
-		$id_member = 0;
398 415
 
399 416
 	if (empty($id_member) && isset($_COOKIE[$cookiename]))
400 417
 	{
@@ -402,8 +419,9 @@  discard block
 block discarded – undo
402 419
 		$cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false);
403 420
 
404 421
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
405
-		if (empty($cookie_data))
406
-			$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
422
+		if (empty($cookie_data)) {
423
+					$cookie_data = safe_unserialize($_COOKIE[$cookiename]);
424
+		}
407 425
 
408 426
 		list($id_member, $password, $login_span, $cookie_domain, $cookie_path) = array_pad((array) $cookie_data, 5, '');
409 427
 
@@ -411,16 +429,17 @@  discard block
 block discarded – undo
411 429
 
412 430
 		// Make sure the cookie is set to the correct domain and path
413 431
 		require_once($sourcedir . '/Subs-Auth.php');
414
-		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])))
415
-			setLoginCookie((int) $login_span - time(), $id_member);
416
-	}
417
-	elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
432
+		if (array($cookie_domain, $cookie_path) !== url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']))) {
433
+					setLoginCookie((int) $login_span - time(), $id_member);
434
+		}
435
+	} elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA'])))
418 436
 	{
419 437
 		// @todo Perhaps we can do some more checking on this, such as on the first octet of the IP?
420 438
 		$cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename], true);
421 439
 
422
-		if (empty($cookie_data))
423
-			$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
440
+		if (empty($cookie_data)) {
441
+					$cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]);
442
+		}
424 443
 
425 444
 		list($id_member, $password, $login_span) = array_pad((array) $cookie_data, 3, '');
426 445
 		$id_member = !empty($id_member) && strlen($password) == 128 && (int) $login_span > time() ? (int) $id_member : 0;
@@ -445,30 +464,34 @@  discard block
 block discarded – undo
445 464
 			$user_settings = $smcFunc['db_fetch_assoc']($request);
446 465
 			$smcFunc['db_free_result']($request);
447 466
 
448
-			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
449
-				$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
467
+			if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
468
+							$user_settings['avatar'] = get_proxied_url($user_settings['avatar']);
469
+			}
450 470
 
451
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
452
-				cache_put_data('user_settings-' . $id_member, $user_settings, 60);
471
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
472
+							cache_put_data('user_settings-' . $id_member, $user_settings, 60);
473
+			}
453 474
 		}
454 475
 
455 476
 		// Did we find 'im?  If not, junk it.
456 477
 		if (!empty($user_settings))
457 478
 		{
458 479
 			// 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;
480
+			if (!empty($already_verified) && $already_verified === true) {
481
+							$check = true;
482
+			}
461 483
 			// 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;
484
+			elseif (strlen($password) == 128) {
485
+							$check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password;
486
+			} else {
487
+							$check = false;
488
+			}
466 489
 
467 490
 			// Wrong password or not activated - either way, you're going nowhere.
468 491
 			$id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0;
492
+		} else {
493
+					$id_member = 0;
469 494
 		}
470
-		else
471
-			$id_member = 0;
472 495
 
473 496
 		// If we no longer have the member maybe they're being all hackey, stop brute force!
474 497
 		if (!$id_member)
@@ -497,8 +520,9 @@  discard block
 block discarded – undo
497 520
 
498 521
 					list ($tfamember, $tfasecret) = array_pad((array) $tfa_data, 2, '');
499 522
 
500
-					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member)
501
-						$tfasecret = null;
523
+					if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) {
524
+											$tfasecret = null;
525
+					}
502 526
 				}
503 527
 
504 528
 				// They didn't finish logging in before coming here? Then they're no one to us.
@@ -520,10 +544,12 @@  discard block
 block discarded – undo
520 544
 		// Are we forcing 2FA? Need to check if the user groups actually require 2FA
521 545
 		elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret']))
522 546
 		{
523
-			if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups
547
+			if ($modSettings['tfa_mode'] == 2) {
548
+				//only do this if we are just forcing SOME membergroups
524 549
 			{
525 550
 				//Build an array of ALL user membergroups.
526 551
 				$full_groups = array($user_settings['id_group']);
552
+			}
527 553
 				if (!empty($user_settings['additional_groups']))
528 554
 				{
529 555
 					$full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups']));
@@ -543,15 +569,17 @@  discard block
 block discarded – undo
543 569
 				);
544 570
 				$row = $smcFunc['db_fetch_assoc']($request);
545 571
 				$smcFunc['db_free_result']($request);
572
+			} else {
573
+							$row['total'] = 1;
546 574
 			}
547
-			else
548
-				$row['total'] = 1; //simplifies logics in the next "if"
575
+			//simplifies logics in the next "if"
549 576
 
550 577
 			$area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : '';
551 578
 			$action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
552 579
 
553
-			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup'))
554
-				redirectexit('action=profile;area=tfasetup;forced');
580
+			if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) {
581
+							redirectexit('action=profile;area=tfasetup;forced');
582
+			}
555 583
 		}
556 584
 	}
557 585
 
@@ -588,33 +616,37 @@  discard block
 block discarded – undo
588 616
 				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']));
589 617
 				$user_settings['last_login'] = time();
590 618
 
591
-				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
592
-					cache_put_data('user_settings-' . $id_member, $user_settings, 60);
619
+				if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
620
+									cache_put_data('user_settings-' . $id_member, $user_settings, 60);
621
+				}
593 622
 
594
-				if (!empty($modSettings['cache_enable']))
595
-					cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
623
+				if (!empty($modSettings['cache_enable'])) {
624
+									cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600);
625
+				}
596 626
 			}
627
+		} elseif (empty($_SESSION['id_msg_last_visit'])) {
628
+					$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
597 629
 		}
598
-		elseif (empty($_SESSION['id_msg_last_visit']))
599
-			$_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit'];
600 630
 
601 631
 		$username = $user_settings['member_name'];
602 632
 
603
-		if (empty($user_settings['additional_groups']))
604
-			$user_info = array(
633
+		if (empty($user_settings['additional_groups'])) {
634
+					$user_info = array(
605 635
 				'groups' => array($user_settings['id_group'], $user_settings['id_post_group'])
606 636
 			);
607
-		else
608
-			$user_info = array(
637
+		} else {
638
+					$user_info = array(
609 639
 				'groups' => array_merge(
610 640
 					array($user_settings['id_group'], $user_settings['id_post_group']),
611 641
 					explode(',', $user_settings['additional_groups'])
612 642
 				)
613 643
 			);
644
+		}
614 645
 
615 646
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
616
-		foreach ($user_info['groups'] as $k => $v)
617
-			$user_info['groups'][$k] = (int) $v;
647
+		foreach ($user_info['groups'] as $k => $v) {
648
+					$user_info['groups'][$k] = (int) $v;
649
+		}
618 650
 
619 651
 		// This is a logged in user, so definitely not a spider.
620 652
 		$user_info['possibly_robot'] = false;
@@ -628,8 +660,7 @@  discard block
 block discarded – undo
628 660
 			$time_system = new DateTime('now', $tz_system);
629 661
 			$time_user = new DateTime('now', $tz_user);
630 662
 			$user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600;
631
-		}
632
-		else
663
+		} else
633 664
 		{
634 665
 			// !!! Compatibility.
635 666
 			$user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset'];
@@ -643,8 +674,9 @@  discard block
 block discarded – undo
643 674
 		$user_info = array('groups' => array(-1));
644 675
 		$user_settings = array();
645 676
 
646
-		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member']))
647
-			$_COOKIE[$cookiename] = '';
677
+		if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) {
678
+					$_COOKIE[$cookiename] = '';
679
+		}
648 680
 
649 681
 		// Expire the 2FA cookie
650 682
 		if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member']))
@@ -661,19 +693,20 @@  discard block
 block discarded – undo
661 693
 		}
662 694
 
663 695
 		// Create a login token if it doesn't exist yet.
664
-		if (!isset($_SESSION['token']['post-login']))
665
-			createToken('login');
666
-		else
667
-			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
+		}
668 701
 
669 702
 		// Do we perhaps think this is a search robot? Check every five minutes just in case...
670 703
 		if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300))
671 704
 		{
672 705
 			require_once($sourcedir . '/ManageSearchEngines.php');
673 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;
674 709
 		}
675
-		elseif (!empty($modSettings['spider_mode']))
676
-			$user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
677 710
 		// If we haven't turned on proper spider hunts then have a guess!
678 711
 		else
679 712
 		{
@@ -721,8 +754,9 @@  discard block
 block discarded – undo
721 754
 	$user_info['groups'] = array_unique($user_info['groups']);
722 755
 
723 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.
724
-	if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1]))
725
-		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
+	}
726 760
 
727 761
 	// Allow the user to change their language.
728 762
 	if (!empty($modSettings['userLanguage']))
@@ -735,13 +769,14 @@  discard block
 block discarded – undo
735 769
 			$user_info['language'] = strtr($_GET['language'], './\\:', '____');
736 770
 
737 771
 			// Make it permanent for members.
738
-			if (!empty($user_info['id']))
739
-				updateMemberData($user_info['id'], array('lngfile' => $user_info['language']));
740
-			else
741
-				$_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'], './\\:', '____');
742 779
 		}
743
-		elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')]))
744
-			$user_info['language'] = strtr($_SESSION['language'], './\\:', '____');
745 780
 	}
746 781
 
747 782
 	$temp = build_query_board($user_info['id']);
@@ -804,9 +839,9 @@  discard block
 block discarded – undo
804 839
 		}
805 840
 
806 841
 		// Remember redirection is the key to avoiding fallout from your bosses.
807
-		if (!empty($topic))
808
-			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
809
-		else
842
+		if (!empty($topic)) {
843
+					redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']);
844
+		} else
810 845
 		{
811 846
 			loadPermissions();
812 847
 			loadTheme();
@@ -824,10 +859,11 @@  discard block
 block discarded – undo
824 859
 	if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
825 860
 	{
826 861
 		// @todo SLOW?
827
-		if (!empty($topic))
828
-			$temp = cache_get_data('topic_board-' . $topic, 120);
829
-		else
830
-			$temp = cache_get_data('board-' . $board, 120);
862
+		if (!empty($topic)) {
863
+					$temp = cache_get_data('topic_board-' . $topic, 120);
864
+		} else {
865
+					$temp = cache_get_data('board-' . $board, 120);
866
+		}
831 867
 
832 868
 		if (!empty($temp))
833 869
 		{
@@ -865,8 +901,9 @@  discard block
 block discarded – undo
865 901
 			$row = $smcFunc['db_fetch_assoc']($request);
866 902
 
867 903
 			// Set the current board.
868
-			if (!empty($row['id_board']))
869
-				$board = $row['id_board'];
904
+			if (!empty($row['id_board'])) {
905
+							$board = $row['id_board'];
906
+			}
870 907
 
871 908
 			// Basic operating information. (globals... :/)
872 909
 			$board_info = array(
@@ -902,21 +939,23 @@  discard block
 block discarded – undo
902 939
 
903 940
 			do
904 941
 			{
905
-				if (!empty($row['id_moderator']))
906
-					$board_info['moderators'][$row['id_moderator']] = array(
942
+				if (!empty($row['id_moderator'])) {
943
+									$board_info['moderators'][$row['id_moderator']] = array(
907 944
 						'id' => $row['id_moderator'],
908 945
 						'name' => $row['real_name'],
909 946
 						'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
910 947
 						'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
911 948
 					);
949
+				}
912 950
 
913
-				if (!empty($row['id_moderator_group']))
914
-					$board_info['moderator_groups'][$row['id_moderator_group']] = array(
951
+				if (!empty($row['id_moderator_group'])) {
952
+									$board_info['moderator_groups'][$row['id_moderator_group']] = array(
915 953
 						'id' => $row['id_moderator_group'],
916 954
 						'name' => $row['group_name'],
917 955
 						'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
918 956
 						'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
919 957
 					);
958
+				}
920 959
 			}
921 960
 			while ($row = $smcFunc['db_fetch_assoc']($request));
922 961
 
@@ -948,12 +987,12 @@  discard block
 block discarded – undo
948 987
 			if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3))
949 988
 			{
950 989
 				// @todo SLOW?
951
-				if (!empty($topic))
952
-					cache_put_data('topic_board-' . $topic, $board_info, 120);
990
+				if (!empty($topic)) {
991
+									cache_put_data('topic_board-' . $topic, $board_info, 120);
992
+				}
953 993
 				cache_put_data('board-' . $board, $board_info, 120);
954 994
 			}
955
-		}
956
-		else
995
+		} else
957 996
 		{
958 997
 			// Otherwise the topic is invalid, there are no moderators, etc.
959 998
 			$board_info = array(
@@ -967,8 +1006,9 @@  discard block
 block discarded – undo
967 1006
 		$smcFunc['db_free_result']($request);
968 1007
 	}
969 1008
 
970
-	if (!empty($topic))
971
-		$_GET['board'] = (int) $board;
1009
+	if (!empty($topic)) {
1010
+			$_GET['board'] = (int) $board;
1011
+	}
972 1012
 
973 1013
 	if (!empty($board))
974 1014
 	{
@@ -978,10 +1018,12 @@  discard block
 block discarded – undo
978 1018
 		// Now check if the user is a moderator.
979 1019
 		$user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0;
980 1020
 
981
-		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin'])
982
-			$board_info['error'] = 'access';
983
-		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin'])
984
-			$board_info['error'] = 'access';
1021
+		if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) {
1022
+					$board_info['error'] = 'access';
1023
+		}
1024
+		if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) {
1025
+					$board_info['error'] = 'access';
1026
+		}
985 1027
 
986 1028
 		// Build up the linktree.
987 1029
 		$context['linktree'] = array_merge(
@@ -1004,8 +1046,9 @@  discard block
 block discarded – undo
1004 1046
 	$context['current_board'] = $board;
1005 1047
 
1006 1048
 	// No posting in redirection boards!
1007
-	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect']))
1008
-		$board_info['error'] == 'post_in_redirect';
1049
+	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) {
1050
+			$board_info['error'] == 'post_in_redirect';
1051
+	}
1009 1052
 
1010 1053
 	// Hacker... you can't see this topic, I'll tell you that. (but moderators can!)
1011 1054
 	if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod']))
@@ -1031,24 +1074,23 @@  discard block
 block discarded – undo
1031 1074
 			ob_end_clean();
1032 1075
 			header('HTTP/1.1 403 Forbidden');
1033 1076
 			die;
1034
-		}
1035
-		elseif ($board_info['error'] == 'post_in_redirect')
1077
+		} elseif ($board_info['error'] == 'post_in_redirect')
1036 1078
 		{
1037 1079
 			// Slightly different error message here...
1038 1080
 			fatal_lang_error('cannot_post_redirect', false);
1039
-		}
1040
-		elseif ($user_info['is_guest'])
1081
+		} elseif ($user_info['is_guest'])
1041 1082
 		{
1042 1083
 			loadLanguage('Errors');
1043 1084
 			is_not_guest($txt['topic_gone']);
1085
+		} else {
1086
+					fatal_lang_error('topic_gone', false);
1044 1087
 		}
1045
-		else
1046
-			fatal_lang_error('topic_gone', false);
1047 1088
 	}
1048 1089
 
1049
-	if ($user_info['is_mod'])
1050
-		$user_info['groups'][] = 3;
1051
-}
1090
+	if ($user_info['is_mod']) {
1091
+			$user_info['groups'][] = 3;
1092
+	}
1093
+	}
1052 1094
 
1053 1095
 /**
1054 1096
  * Load this user's permissions.
@@ -1069,8 +1111,9 @@  discard block
 block discarded – undo
1069 1111
 		asort($cache_groups);
1070 1112
 		$cache_groups = implode(',', $cache_groups);
1071 1113
 		// If it's a spider then cache it different.
1072
-		if ($user_info['possibly_robot'])
1073
-			$cache_groups .= '-spider';
1114
+		if ($user_info['possibly_robot']) {
1115
+					$cache_groups .= '-spider';
1116
+		}
1074 1117
 
1075 1118
 		if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1076 1119
 		{
@@ -1078,9 +1121,9 @@  discard block
 block discarded – undo
1078 1121
 			banPermissions();
1079 1122
 
1080 1123
 			return;
1124
+		} elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) {
1125
+					list ($user_info['permissions'], $removals) = $temp;
1081 1126
 		}
1082
-		elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated'])
1083
-			list ($user_info['permissions'], $removals) = $temp;
1084 1127
 	}
1085 1128
 
1086 1129
 	// If it is detected as a robot, and we are restricting permissions as a special group - then implement this.
@@ -1102,23 +1145,26 @@  discard block
 block discarded – undo
1102 1145
 		$removals = array();
1103 1146
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1104 1147
 		{
1105
-			if (empty($row['add_deny']))
1106
-				$removals[] = $row['permission'];
1107
-			else
1108
-				$user_info['permissions'][] = $row['permission'];
1148
+			if (empty($row['add_deny'])) {
1149
+							$removals[] = $row['permission'];
1150
+			} else {
1151
+							$user_info['permissions'][] = $row['permission'];
1152
+			}
1109 1153
 		}
1110 1154
 		$smcFunc['db_free_result']($request);
1111 1155
 
1112
-		if (isset($cache_groups))
1113
-			cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1156
+		if (isset($cache_groups)) {
1157
+					cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240);
1158
+		}
1114 1159
 	}
1115 1160
 
1116 1161
 	// Get the board permissions.
1117 1162
 	if (!empty($board))
1118 1163
 	{
1119 1164
 		// Make sure the board (if any) has been loaded by loadBoard().
1120
-		if (!isset($board_info['profile']))
1121
-			fatal_lang_error('no_board');
1165
+		if (!isset($board_info['profile'])) {
1166
+					fatal_lang_error('no_board');
1167
+		}
1122 1168
 
1123 1169
 		$request = $smcFunc['db_query']('', '
1124 1170
 			SELECT permission, add_deny
@@ -1134,20 +1180,23 @@  discard block
 block discarded – undo
1134 1180
 		);
1135 1181
 		while ($row = $smcFunc['db_fetch_assoc']($request))
1136 1182
 		{
1137
-			if (empty($row['add_deny']))
1138
-				$removals[] = $row['permission'];
1139
-			else
1140
-				$user_info['permissions'][] = $row['permission'];
1183
+			if (empty($row['add_deny'])) {
1184
+							$removals[] = $row['permission'];
1185
+			} else {
1186
+							$user_info['permissions'][] = $row['permission'];
1187
+			}
1141 1188
 		}
1142 1189
 		$smcFunc['db_free_result']($request);
1143 1190
 	}
1144 1191
 
1145 1192
 	// Remove all the permissions they shouldn't have ;).
1146
-	if (!empty($modSettings['permission_enable_deny']))
1147
-		$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1193
+	if (!empty($modSettings['permission_enable_deny'])) {
1194
+			$user_info['permissions'] = array_diff($user_info['permissions'], $removals);
1195
+	}
1148 1196
 
1149
-	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2)
1150
-		cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1197
+	if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) {
1198
+			cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240);
1199
+	}
1151 1200
 
1152 1201
 	// Banned?  Watch, don't touch..
1153 1202
 	banPermissions();
@@ -1159,17 +1208,18 @@  discard block
 block discarded – undo
1159 1208
 		{
1160 1209
 			require_once($sourcedir . '/Subs-Auth.php');
1161 1210
 			rebuildModCache();
1211
+		} else {
1212
+					$user_info['mod_cache'] = $_SESSION['mc'];
1162 1213
 		}
1163
-		else
1164
-			$user_info['mod_cache'] = $_SESSION['mc'];
1165 1214
 
1166 1215
 		// This is a useful phantom permission added to the current user, and only the current user while they are logged in.
1167 1216
 		// For example this drastically simplifies certain changes to the profile area.
1168 1217
 		$user_info['permissions'][] = 'is_not_guest';
1169 1218
 		// And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions.
1170 1219
 		$user_info['permissions'][] = 'profile_view_own';
1171
-		if (in_array('profile_view', $user_info['permissions']))
1172
-			$user_info['permissions'][] = 'profile_view_any';
1220
+		if (in_array('profile_view', $user_info['permissions'])) {
1221
+					$user_info['permissions'][] = 'profile_view_any';
1222
+		}
1173 1223
 	}
1174 1224
 }
1175 1225
 
@@ -1187,8 +1237,9 @@  discard block
 block discarded – undo
1187 1237
 	global $image_proxy_enabled, $boardurl, $user_info;
1188 1238
 
1189 1239
 	// Can't just look for no users :P.
1190
-	if (empty($users))
1191
-		return array();
1240
+	if (empty($users)) {
1241
+			return array();
1242
+	}
1192 1243
 
1193 1244
 	// Pass the set value
1194 1245
 	$context['loadMemberContext_set'] = $set;
@@ -1203,8 +1254,9 @@  discard block
 block discarded – undo
1203 1254
 		for ($i = 0, $n = count($users); $i < $n; $i++)
1204 1255
 		{
1205 1256
 			$data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240);
1206
-			if ($data == null)
1207
-				continue;
1257
+			if ($data == null) {
1258
+							continue;
1259
+			}
1208 1260
 
1209 1261
 			$loaded_ids[] = $data['id_member'];
1210 1262
 			$user_profile[$data['id_member']] = $data;
@@ -1271,16 +1323,19 @@  discard block
 block discarded – undo
1271 1323
 			$row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : '';
1272 1324
 
1273 1325
 			// Take care of proxying avatar if required, do this here for maximum reach
1274
-			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
1275
-				$row['avatar'] = get_proxied_url($row['avatar']);
1326
+			if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
1327
+							$row['avatar'] = get_proxied_url($row['avatar']);
1328
+			}
1276 1329
 
1277 1330
 			// Keep track of the member's normal member group
1278 1331
 			$row['primary_group'] = $row['member_group'];
1279 1332
 
1280
-			if (isset($row['member_ip']))
1281
-				$row['member_ip'] = inet_dtop($row['member_ip']);
1282
-			if (isset($row['member_ip2']))
1283
-				$row['member_ip2'] = inet_dtop($row['member_ip2']);
1333
+			if (isset($row['member_ip'])) {
1334
+							$row['member_ip'] = inet_dtop($row['member_ip']);
1335
+			}
1336
+			if (isset($row['member_ip2'])) {
1337
+							$row['member_ip2'] = inet_dtop($row['member_ip2']);
1338
+			}
1284 1339
 			$new_loaded_ids[] = $row['id_member'];
1285 1340
 			$loaded_ids[] = $row['id_member'];
1286 1341
 			$row['options'] = array();
@@ -1299,8 +1354,9 @@  discard block
 block discarded – undo
1299 1354
 				'loaded_ids' => $new_loaded_ids,
1300 1355
 			)
1301 1356
 		);
1302
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1303
-			$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1357
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1358
+					$user_profile[$row['id_member']]['options'][$row['variable']] = $row['value'];
1359
+		}
1304 1360
 		$smcFunc['db_free_result']($request);
1305 1361
 	}
1306 1362
 
@@ -1311,10 +1367,11 @@  discard block
 block discarded – undo
1311 1367
 	{
1312 1368
 		foreach ($loaded_ids as $a_member)
1313 1369
 		{
1314
-			if (!empty($user_profile[$a_member]['additional_groups']))
1315
-				$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1316
-			else
1317
-				$groups = array($user_profile[$a_member]['id_group']);
1370
+			if (!empty($user_profile[$a_member]['additional_groups'])) {
1371
+							$groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups']));
1372
+			} else {
1373
+							$groups = array($user_profile[$a_member]['id_group']);
1374
+			}
1318 1375
 
1319 1376
 			$temp = array_intersect($groups, array_keys($board_info['moderator_groups']));
1320 1377
 
@@ -1327,8 +1384,9 @@  discard block
 block discarded – undo
1327 1384
 
1328 1385
 	if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
1329 1386
 	{
1330
-		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++)
1331
-			cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1387
+		for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) {
1388
+					cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240);
1389
+		}
1332 1390
 	}
1333 1391
 
1334 1392
 	// Are we loading any moderators?  If so, fix their group data...
@@ -1354,14 +1412,17 @@  discard block
 block discarded – undo
1354 1412
 		foreach ($temp_mods as $id)
1355 1413
 		{
1356 1414
 			// By popular demand, don't show admins or global moderators as moderators.
1357
-			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2)
1358
-				$user_profile[$id]['member_group'] = $row['member_group'];
1415
+			if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) {
1416
+							$user_profile[$id]['member_group'] = $row['member_group'];
1417
+			}
1359 1418
 
1360 1419
 			// If the Moderator group has no color or icons, but their group does... don't overwrite.
1361
-			if (!empty($row['icons']))
1362
-				$user_profile[$id]['icons'] = $row['icons'];
1363
-			if (!empty($row['member_group_color']))
1364
-				$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1420
+			if (!empty($row['icons'])) {
1421
+							$user_profile[$id]['icons'] = $row['icons'];
1422
+			}
1423
+			if (!empty($row['member_group_color'])) {
1424
+							$user_profile[$id]['member_group_color'] = $row['member_group_color'];
1425
+			}
1365 1426
 		}
1366 1427
 	}
1367 1428
 
@@ -1383,12 +1444,14 @@  discard block
 block discarded – undo
1383 1444
 	static $loadedLanguages = array();
1384 1445
 
1385 1446
 	// If this person's data is already loaded, skip it.
1386
-	if (isset($dataLoaded[$user]))
1387
-		return true;
1447
+	if (isset($dataLoaded[$user])) {
1448
+			return true;
1449
+	}
1388 1450
 
1389 1451
 	// We can't load guests or members not loaded by loadMemberData()!
1390
-	if ($user == 0)
1391
-		return false;
1452
+	if ($user == 0) {
1453
+			return false;
1454
+	}
1392 1455
 	if (!isset($user_profile[$user]))
1393 1456
 	{
1394 1457
 		trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING);
@@ -1414,12 +1477,16 @@  discard block
 block discarded – undo
1414 1477
 	$buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array();
1415 1478
 
1416 1479
 	//We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme
1417
-	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists
1480
+	if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) {
1481
+		//icon is set and exists
1418 1482
 		$group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1];
1419
-	elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default
1483
+	} elseif (isset($profile['icons'][1])) {
1484
+		//icon is set and doesn't exist, fallback to default
1420 1485
 		$group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1];
1421
-	else //not set, bye bye
1486
+	} else {
1487
+		//not set, bye bye
1422 1488
 		$group_icon_url = '';
1489
+	}
1423 1490
 
1424 1491
 	// These minimal values are always loaded
1425 1492
 	$memberContext[$user] = array(
@@ -1438,8 +1505,9 @@  discard block
 block discarded – undo
1438 1505
 	if ($context['loadMemberContext_set'] != 'minimal')
1439 1506
 	{
1440 1507
 		// Go the extra mile and load the user's native language name.
1441
-		if (empty($loadedLanguages))
1442
-			$loadedLanguages = getLanguages();
1508
+		if (empty($loadedLanguages)) {
1509
+					$loadedLanguages = getLanguages();
1510
+		}
1443 1511
 
1444 1512
 		$memberContext[$user] += array(
1445 1513
 			'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>',
@@ -1494,31 +1562,33 @@  discard block
 block discarded – undo
1494 1562
 	{
1495 1563
 		if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://')))
1496 1564
 		{
1497
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11)
1498
-				$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1499
-			else
1500
-				$image = get_gravatar_url($profile['email_address']);
1501
-		}
1502
-		else
1565
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) {
1566
+							$image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11));
1567
+			} else {
1568
+							$image = get_gravatar_url($profile['email_address']);
1569
+			}
1570
+		} else
1503 1571
 		{
1504 1572
 			// So it's stored in the member table?
1505 1573
 			if (!empty($profile['avatar']))
1506 1574
 			{
1507 1575
 				$image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'];
1576
+			} elseif (!empty($profile['filename'])) {
1577
+							$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1508 1578
 			}
1509
-			elseif (!empty($profile['filename']))
1510
-				$image = $modSettings['custom_avatar_url'] . '/' . $profile['filename'];
1511 1579
 			// Right... no avatar...use the default one
1512
-			else
1513
-				$image = $modSettings['avatar_url'] . '/default.png';
1580
+			else {
1581
+							$image = $modSettings['avatar_url'] . '/default.png';
1582
+			}
1514 1583
 		}
1515
-		if (!empty($image))
1516
-			$memberContext[$user]['avatar'] = array(
1584
+		if (!empty($image)) {
1585
+					$memberContext[$user]['avatar'] = array(
1517 1586
 				'name' => $profile['avatar'],
1518 1587
 				'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">',
1519 1588
 				'href' => $image,
1520 1589
 				'url' => $image,
1521 1590
 			);
1591
+		}
1522 1592
 	}
1523 1593
 
1524 1594
 	// Are we also loading the members custom fields into context?
@@ -1526,13 +1596,15 @@  discard block
 block discarded – undo
1526 1596
 	{
1527 1597
 		$memberContext[$user]['custom_fields'] = array();
1528 1598
 
1529
-		if (!isset($context['display_fields']))
1530
-			$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1599
+		if (!isset($context['display_fields'])) {
1600
+					$context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true);
1601
+		}
1531 1602
 
1532 1603
 		foreach ($context['display_fields'] as $custom)
1533 1604
 		{
1534
-			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']]))
1535
-				continue;
1605
+			if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) {
1606
+							continue;
1607
+			}
1536 1608
 
1537 1609
 			$value = $profile['options'][$custom['col_name']];
1538 1610
 
@@ -1540,31 +1612,36 @@  discard block
 block discarded – undo
1540 1612
 			$currentKey = 0;
1541 1613
 
1542 1614
 			// Create a key => value array for multiple options fields
1543
-			if (!empty($custom['options']))
1544
-				foreach ($custom['options'] as $k => $v)
1615
+			if (!empty($custom['options'])) {
1616
+							foreach ($custom['options'] as $k => $v)
1545 1617
 				{
1546 1618
 					$fieldOptions[] = $v;
1547
-					if (empty($currentKey))
1548
-						$currentKey = $v == $value ? $k : 0;
1619
+			}
1620
+					if (empty($currentKey)) {
1621
+											$currentKey = $v == $value ? $k : 0;
1622
+					}
1549 1623
 				}
1550 1624
 
1551 1625
 			// BBC?
1552
-			if ($custom['bbc'])
1553
-				$value = parse_bbc($value);
1626
+			if ($custom['bbc']) {
1627
+							$value = parse_bbc($value);
1628
+			}
1554 1629
 
1555 1630
 			// ... or checkbox?
1556
-			elseif (isset($custom['type']) && $custom['type'] == 'check')
1557
-				$value = $value ? $txt['yes'] : $txt['no'];
1631
+			elseif (isset($custom['type']) && $custom['type'] == 'check') {
1632
+							$value = $value ? $txt['yes'] : $txt['no'];
1633
+			}
1558 1634
 
1559 1635
 			// Enclosing the user input within some other text?
1560
-			if (!empty($custom['enclose']))
1561
-				$value = strtr($custom['enclose'], array(
1636
+			if (!empty($custom['enclose'])) {
1637
+							$value = strtr($custom['enclose'], array(
1562 1638
 					'{SCRIPTURL}' => $scripturl,
1563 1639
 					'{IMAGES_URL}' => $settings['images_url'],
1564 1640
 					'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1565 1641
 					'{INPUT}' => $value,
1566 1642
 					'{KEY}' => $currentKey,
1567 1643
 				));
1644
+			}
1568 1645
 
1569 1646
 			$memberContext[$user]['custom_fields'][] = array(
1570 1647
 				'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'],
@@ -1591,8 +1668,9 @@  discard block
 block discarded – undo
1591 1668
 	global $smcFunc, $txt, $scripturl, $settings;
1592 1669
 
1593 1670
 	// Do not waste my time...
1594
-	if (empty($users) || empty($params))
1595
-		return false;
1671
+	if (empty($users) || empty($params)) {
1672
+			return false;
1673
+	}
1596 1674
 
1597 1675
 	// Make sure it's an array.
1598 1676
 	$users = !is_array($users) ? array($users) : array_unique($users);
@@ -1619,41 +1697,48 @@  discard block
 block discarded – undo
1619 1697
 		$currentKey = 0;
1620 1698
 
1621 1699
 		// Create a key => value array for multiple options fields
1622
-		if (!empty($row['field_options']))
1623
-			foreach (explode(',', $row['field_options']) as $k => $v)
1700
+		if (!empty($row['field_options'])) {
1701
+					foreach (explode(',', $row['field_options']) as $k => $v)
1624 1702
 			{
1625 1703
 				$fieldOptions[] = $v;
1626
-				if (empty($currentKey))
1627
-					$currentKey = $v == $row['value'] ? $k : 0;
1704
+		}
1705
+				if (empty($currentKey)) {
1706
+									$currentKey = $v == $row['value'] ? $k : 0;
1707
+				}
1628 1708
 			}
1629 1709
 
1630 1710
 		// BBC?
1631
-		if (!empty($row['bbc']))
1632
-			$row['value'] = parse_bbc($row['value']);
1711
+		if (!empty($row['bbc'])) {
1712
+					$row['value'] = parse_bbc($row['value']);
1713
+		}
1633 1714
 
1634 1715
 		// ... or checkbox?
1635
-		elseif (isset($row['type']) && $row['type'] == 'check')
1636
-			$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1716
+		elseif (isset($row['type']) && $row['type'] == 'check') {
1717
+					$row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no'];
1718
+		}
1637 1719
 
1638 1720
 		// Enclosing the user input within some other text?
1639
-		if (!empty($row['enclose']))
1640
-			$row['value'] = strtr($row['enclose'], array(
1721
+		if (!empty($row['enclose'])) {
1722
+					$row['value'] = strtr($row['enclose'], array(
1641 1723
 				'{SCRIPTURL}' => $scripturl,
1642 1724
 				'{IMAGES_URL}' => $settings['images_url'],
1643 1725
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
1644 1726
 				'{INPUT}' => un_htmlspecialchars($row['value']),
1645 1727
 				'{KEY}' => $currentKey,
1646 1728
 			));
1729
+		}
1647 1730
 
1648 1731
 		// Send a simple array if there is just 1 param
1649
-		if (count($params) == 1)
1650
-			$return[$row['id_member']] = $row;
1732
+		if (count($params) == 1) {
1733
+					$return[$row['id_member']] = $row;
1734
+		}
1651 1735
 
1652 1736
 		// More than 1? knock yourself out...
1653 1737
 		else
1654 1738
 		{
1655
-			if (!isset($return[$row['id_member']]))
1656
-				$return[$row['id_member']] = array();
1739
+			if (!isset($return[$row['id_member']])) {
1740
+							$return[$row['id_member']] = array();
1741
+			}
1657 1742
 
1658 1743
 			$return[$row['id_member']][$row['variable']] = $row;
1659 1744
 		}
@@ -1687,8 +1772,9 @@  discard block
 block discarded – undo
1687 1772
 	global $context;
1688 1773
 
1689 1774
 	// Don't know any browser!
1690
-	if (empty($context['browser']))
1691
-		detectBrowser();
1775
+	if (empty($context['browser'])) {
1776
+			detectBrowser();
1777
+	}
1692 1778
 
1693 1779
 	return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false;
1694 1780
 }
@@ -1706,8 +1792,9 @@  discard block
 block discarded – undo
1706 1792
 	global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled;
1707 1793
 
1708 1794
 	// The theme was specified by parameter.
1709
-	if (!empty($id_theme))
1710
-		$id_theme = (int) $id_theme;
1795
+	if (!empty($id_theme)) {
1796
+			$id_theme = (int) $id_theme;
1797
+	}
1711 1798
 	// The theme was specified by REQUEST.
1712 1799
 	elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1713 1800
 	{
@@ -1715,32 +1802,38 @@  discard block
 block discarded – undo
1715 1802
 		$_SESSION['id_theme'] = $id_theme;
1716 1803
 	}
1717 1804
 	// The theme was specified by REQUEST... previously.
1718
-	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum')))
1719
-		$id_theme = (int) $_SESSION['id_theme'];
1805
+	elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) {
1806
+			$id_theme = (int) $_SESSION['id_theme'];
1807
+	}
1720 1808
 	// The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.)
1721
-	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme']))
1722
-		$id_theme = $user_info['theme'];
1809
+	elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) {
1810
+			$id_theme = $user_info['theme'];
1811
+	}
1723 1812
 	// The theme was specified by the board.
1724
-	elseif (!empty($board_info['theme']))
1725
-		$id_theme = $board_info['theme'];
1813
+	elseif (!empty($board_info['theme'])) {
1814
+			$id_theme = $board_info['theme'];
1815
+	}
1726 1816
 	// The theme is the forum's default.
1727
-	else
1728
-		$id_theme = $modSettings['theme_guests'];
1817
+	else {
1818
+			$id_theme = $modSettings['theme_guests'];
1819
+	}
1729 1820
 
1730 1821
 	// Verify the id_theme... no foul play.
1731 1822
 	// Always allow the board specific theme, if they are overriding.
1732
-	if (!empty($board_info['theme']) && $board_info['override_theme'])
1733
-		$id_theme = $board_info['theme'];
1823
+	if (!empty($board_info['theme']) && $board_info['override_theme']) {
1824
+			$id_theme = $board_info['theme'];
1825
+	}
1734 1826
 	// If they have specified a particular theme to use with SSI allow it to be used.
1735
-	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme)
1736
-		$id_theme = (int) $id_theme;
1737
-	elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1827
+	elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) {
1828
+			$id_theme = (int) $id_theme;
1829
+	} elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum'))
1738 1830
 	{
1739 1831
 		$themes = explode(',', $modSettings['enableThemes']);
1740
-		if (!in_array($id_theme, $themes))
1741
-			$id_theme = $modSettings['theme_guests'];
1742
-		else
1743
-			$id_theme = (int) $id_theme;
1832
+		if (!in_array($id_theme, $themes)) {
1833
+					$id_theme = $modSettings['theme_guests'];
1834
+		} else {
1835
+					$id_theme = (int) $id_theme;
1836
+		}
1744 1837
 	}
1745 1838
 		
1746 1839
 	// We already load the basic stuff?
@@ -1749,18 +1842,19 @@  discard block
 block discarded – undo
1749 1842
 		$member = empty($user_info['id']) ? -1 : $user_info['id'];
1750 1843
 
1751 1844
 		// Disable image proxy if we don't have SSL enabled
1752
-		if (empty($modSettings['force_ssl']))
1753
-			$image_proxy_enabled = false;
1845
+		if (empty($modSettings['force_ssl'])) {
1846
+					$image_proxy_enabled = false;
1847
+		}
1754 1848
 
1755 1849
 		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'])
1756 1850
 		{
1757 1851
 			$themeData = $temp;
1758 1852
 			$flag = true;
1853
+		} elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) {
1854
+					$themeData = $temp + array($member => array());
1855
+		} else {
1856
+					$themeData = array(-1 => array(), 0 => array(), $member => array());
1759 1857
 		}
1760
-		elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated'])
1761
-			$themeData = $temp + array($member => array());
1762
-		else
1763
-			$themeData = array(-1 => array(), 0 => array(), $member => array());
1764 1858
 
1765 1859
 		if (empty($flag))
1766 1860
 		{
@@ -1780,31 +1874,37 @@  discard block
 block discarded – undo
1780 1874
 			while ($row = $smcFunc['db_fetch_assoc']($result))
1781 1875
 			{
1782 1876
 				// There are just things we shouldn't be able to change as members.
1783
-				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')))
1784
-					continue;
1877
+				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'))) {
1878
+									continue;
1879
+				}
1785 1880
 
1786 1881
 				// If this is the theme_dir of the default theme, store it.
1787
-				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member']))
1788
-					$themeData[0]['default_' . $row['variable']] = $row['value'];
1882
+				if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) {
1883
+									$themeData[0]['default_' . $row['variable']] = $row['value'];
1884
+				}
1789 1885
 
1790 1886
 				// If this isn't set yet, is a theme option, or is not the default theme..
1791
-				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1')
1792
-					$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1887
+				if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') {
1888
+									$themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value'];
1889
+				}
1793 1890
 			}
1794 1891
 			$smcFunc['db_free_result']($result);
1795 1892
 
1796
-			if (!empty($themeData[-1]))
1797
-				foreach ($themeData[-1] as $k => $v)
1893
+			if (!empty($themeData[-1])) {
1894
+							foreach ($themeData[-1] as $k => $v)
1798 1895
 				{
1799 1896
 					if (!isset($themeData[$member][$k]))
1800 1897
 						$themeData[$member][$k] = $v;
1898
+			}
1801 1899
 				}
1802 1900
 
1803
-			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1804
-				cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1901
+			if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1902
+							cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60);
1903
+			}
1805 1904
 			// Only if we didn't already load that part of the cache...
1806
-			elseif (!isset($temp))
1807
-				cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1905
+			elseif (!isset($temp)) {
1906
+							cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90);
1907
+			}
1808 1908
 		}
1809 1909
 
1810 1910
 		$settings = $themeData[0];
@@ -1821,17 +1921,20 @@  discard block
 block discarded – undo
1821 1921
 		$settings['template_dirs'][] = $settings['theme_dir'];
1822 1922
 
1823 1923
 		// Based on theme (if there is one).
1824
-		if (!empty($settings['base_theme_dir']))
1825
-			$settings['template_dirs'][] = $settings['base_theme_dir'];
1924
+		if (!empty($settings['base_theme_dir'])) {
1925
+					$settings['template_dirs'][] = $settings['base_theme_dir'];
1926
+		}
1826 1927
 
1827 1928
 		// Lastly the default theme.
1828
-		if ($settings['theme_dir'] != $settings['default_theme_dir'])
1829
-			$settings['template_dirs'][] = $settings['default_theme_dir'];
1929
+		if ($settings['theme_dir'] != $settings['default_theme_dir']) {
1930
+					$settings['template_dirs'][] = $settings['default_theme_dir'];
1931
+		}
1830 1932
 	}
1831 1933
 
1832 1934
 
1833
-	if (!$initialize)
1834
-		return;
1935
+	if (!$initialize) {
1936
+			return;
1937
+	}
1835 1938
 
1836 1939
 	// Check to see if we're forcing SSL
1837 1940
 	if (!empty($modSettings['force_ssl']) && empty($maintenance) &&
@@ -1852,8 +1955,9 @@  discard block
 block discarded – undo
1852 1955
 		$detected_url = httpsOn() ? 'https://' : 'http://';
1853 1956
 		$detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST'];
1854 1957
 		$temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/'));
1855
-		if ($temp != '/')
1856
-			$detected_url .= $temp;
1958
+		if ($temp != '/') {
1959
+					$detected_url .= $temp;
1960
+		}
1857 1961
 	}
1858 1962
 	if (isset($detected_url) && $detected_url != $boardurl)
1859 1963
 	{
@@ -1865,8 +1969,9 @@  discard block
 block discarded – undo
1865 1969
 			foreach ($aliases as $alias)
1866 1970
 			{
1867 1971
 				// Rip off all the boring parts, spaces, etc.
1868
-				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias))
1869
-					$do_fix = true;
1972
+				if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) {
1973
+									$do_fix = true;
1974
+				}
1870 1975
 			}
1871 1976
 		}
1872 1977
 
@@ -1874,21 +1979,23 @@  discard block
 block discarded – undo
1874 1979
 		if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI')
1875 1980
 		{
1876 1981
 			// Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;).
1877
-			if (empty($_GET))
1878
-				redirectexit('wwwRedirect');
1879
-			else
1982
+			if (empty($_GET)) {
1983
+							redirectexit('wwwRedirect');
1984
+			} else
1880 1985
 			{
1881 1986
 				$k = key($_GET);
1882 1987
 				$v = current($_GET);
1883 1988
 
1884
-				if ($k != 'wwwRedirect')
1885
-					redirectexit('wwwRedirect;' . $k . '=' . $v);
1989
+				if ($k != 'wwwRedirect') {
1990
+									redirectexit('wwwRedirect;' . $k . '=' . $v);
1991
+				}
1886 1992
 			}
1887 1993
 		}
1888 1994
 
1889 1995
 		// #3 is just a check for SSL...
1890
-		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl)
1891
-			$do_fix = true;
1996
+		if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) {
1997
+					$do_fix = true;
1998
+		}
1892 1999
 
1893 2000
 		// Okay, #4 - perhaps it's an IP address?  We're gonna want to use that one, then. (assuming it's the IP or something...)
1894 2001
 		if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1)
@@ -1923,8 +2030,9 @@  discard block
 block discarded – undo
1923 2030
 					$board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl));
1924 2031
 				}
1925 2032
 			}
1926
-			foreach ($context['linktree'] as $k => $dummy)
1927
-				$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2033
+			foreach ($context['linktree'] as $k => $dummy) {
2034
+							$context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl));
2035
+			}
1928 2036
 		}
1929 2037
 	}
1930 2038
 	// Set up the contextual user array.
@@ -1943,16 +2051,16 @@  discard block
 block discarded – undo
1943 2051
 			'email' => $user_info['email'],
1944 2052
 			'ignoreusers' => $user_info['ignoreusers'],
1945 2053
 		);
1946
-		if (!$context['user']['is_guest'])
1947
-			$context['user']['name'] = $user_info['name'];
1948
-		elseif ($context['user']['is_guest'] && !empty($txt['guest_title']))
1949
-			$context['user']['name'] = $txt['guest_title'];
2054
+		if (!$context['user']['is_guest']) {
2055
+					$context['user']['name'] = $user_info['name'];
2056
+		} elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) {
2057
+					$context['user']['name'] = $txt['guest_title'];
2058
+		}
1950 2059
 
1951 2060
 		// Determine the current smiley set.
1952 2061
 		$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'];
1953 2062
 		$context['user']['smiley_set'] = $user_info['smiley_set'];
1954
-	}
1955
-	else
2063
+	} else
1956 2064
 	{
1957 2065
 		// What to do when there is no $user_info (e.g., an error very early in the login process)
1958 2066
 		$context['user'] = array(
@@ -1986,18 +2094,24 @@  discard block
 block discarded – undo
1986 2094
 	}
1987 2095
 
1988 2096
 	// Some basic information...
1989
-	if (!isset($context['html_headers']))
1990
-		$context['html_headers'] = '';
1991
-	if (!isset($context['javascript_files']))
1992
-		$context['javascript_files'] = array();
1993
-	if (!isset($context['css_files']))
1994
-		$context['css_files'] = array();
1995
-	if (!isset($context['css_header']))
1996
-		$context['css_header'] = array();
1997
-	if (!isset($context['javascript_inline']))
1998
-		$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
1999
-	if (!isset($context['javascript_vars']))
2000
-		$context['javascript_vars'] = array();
2097
+	if (!isset($context['html_headers'])) {
2098
+			$context['html_headers'] = '';
2099
+	}
2100
+	if (!isset($context['javascript_files'])) {
2101
+			$context['javascript_files'] = array();
2102
+	}
2103
+	if (!isset($context['css_files'])) {
2104
+			$context['css_files'] = array();
2105
+	}
2106
+	if (!isset($context['css_header'])) {
2107
+			$context['css_header'] = array();
2108
+	}
2109
+	if (!isset($context['javascript_inline'])) {
2110
+			$context['javascript_inline'] = array('standard' => array(), 'defer' => array());
2111
+	}
2112
+	if (!isset($context['javascript_vars'])) {
2113
+			$context['javascript_vars'] = array();
2114
+	}
2001 2115
 
2002 2116
 	$context['login_url'] =  $scripturl . '?action=login2';
2003 2117
 	$context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | ';
@@ -2009,16 +2123,18 @@  discard block
 block discarded – undo
2009 2123
 	$context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null;
2010 2124
 	$context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null;
2011 2125
 	$context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3;
2012
-	if (isset($modSettings['load_average']))
2013
-		$context['load_average'] = $modSettings['load_average'];
2126
+	if (isset($modSettings['load_average'])) {
2127
+			$context['load_average'] = $modSettings['load_average'];
2128
+	}
2014 2129
 
2015 2130
 	// Detect the browser. This is separated out because it's also used in attachment downloads
2016 2131
 	detectBrowser();
2017 2132
 
2018 2133
 	// Set the top level linktree up.
2019 2134
 	// Note that if we're dealing with certain very early errors (e.g., login) the linktree might not be set yet...
2020
-	if (empty($context['linktree']))
2021
-		$context['linktree'] = array();
2135
+	if (empty($context['linktree'])) {
2136
+			$context['linktree'] = array();
2137
+	}
2022 2138
 	array_unshift($context['linktree'], array(
2023 2139
 		'url' => $scripturl,
2024 2140
 		'name' => $context['forum_name_html_safe']
@@ -2027,8 +2143,9 @@  discard block
 block discarded – undo
2027 2143
 	// This allows sticking some HTML on the page output - useful for controls.
2028 2144
 	$context['insert_after_template'] = '';
2029 2145
 
2030
-	if (!isset($txt))
2031
-		$txt = array();
2146
+	if (!isset($txt)) {
2147
+			$txt = array();
2148
+	}
2032 2149
 
2033 2150
 	$simpleActions = array(
2034 2151
 		'findmember',
@@ -2074,9 +2191,10 @@  discard block
 block discarded – undo
2074 2191
 
2075 2192
 	// See if theres any extra param to check.
2076 2193
 	$requiresXML = false;
2077
-	foreach ($extraParams as $key => $extra)
2078
-		if (isset($_REQUEST[$extra]))
2194
+	foreach ($extraParams as $key => $extra) {
2195
+			if (isset($_REQUEST[$extra]))
2079 2196
 			$requiresXML = true;
2197
+	}
2080 2198
 
2081 2199
 	// Output is fully XML, so no need for the index template.
2082 2200
 	if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML))
@@ -2091,37 +2209,39 @@  discard block
 block discarded – undo
2091 2209
 	{
2092 2210
 		loadLanguage('index+Modifications');
2093 2211
 		$context['template_layers'] = array();
2094
-	}
2095
-
2096
-	else
2212
+	} else
2097 2213
 	{
2098 2214
 		// Custom templates to load, or just default?
2099
-		if (isset($settings['theme_templates']))
2100
-			$templates = explode(',', $settings['theme_templates']);
2101
-		else
2102
-			$templates = array('index');
2215
+		if (isset($settings['theme_templates'])) {
2216
+					$templates = explode(',', $settings['theme_templates']);
2217
+		} else {
2218
+					$templates = array('index');
2219
+		}
2103 2220
 
2104 2221
 		// Load each template...
2105
-		foreach ($templates as $template)
2106
-			loadTemplate($template);
2222
+		foreach ($templates as $template) {
2223
+					loadTemplate($template);
2224
+		}
2107 2225
 
2108 2226
 		// ...and attempt to load their associated language files.
2109 2227
 		$required_files = implode('+', array_merge($templates, array('Modifications')));
2110 2228
 		loadLanguage($required_files, '', false);
2111 2229
 
2112 2230
 		// Custom template layers?
2113
-		if (isset($settings['theme_layers']))
2114
-			$context['template_layers'] = explode(',', $settings['theme_layers']);
2115
-		else
2116
-			$context['template_layers'] = array('html', 'body');
2231
+		if (isset($settings['theme_layers'])) {
2232
+					$context['template_layers'] = explode(',', $settings['theme_layers']);
2233
+		} else {
2234
+					$context['template_layers'] = array('html', 'body');
2235
+		}
2117 2236
 	}
2118 2237
 
2119 2238
 	// Initialize the theme.
2120 2239
 	loadSubTemplate('init', 'ignore');
2121 2240
 
2122 2241
 	// Allow overriding the board wide time/number formats.
2123
-	if (empty($user_settings['time_format']) && !empty($txt['time_format']))
2124
-		$user_info['time_format'] = $txt['time_format'];
2242
+	if (empty($user_settings['time_format']) && !empty($txt['time_format'])) {
2243
+			$user_info['time_format'] = $txt['time_format'];
2244
+	}
2125 2245
 
2126 2246
 	// Set the character set from the template.
2127 2247
 	$context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set'];
@@ -2129,12 +2249,14 @@  discard block
 block discarded – undo
2129 2249
 	$context['right_to_left'] = !empty($txt['lang_rtl']);
2130 2250
 
2131 2251
 	// Guests may still need a name.
2132
-	if ($context['user']['is_guest'] && empty($context['user']['name']))
2133
-		$context['user']['name'] = $txt['guest_title'];
2252
+	if ($context['user']['is_guest'] && empty($context['user']['name'])) {
2253
+			$context['user']['name'] = $txt['guest_title'];
2254
+	}
2134 2255
 
2135 2256
 	// Any theme-related strings that need to be loaded?
2136
-	if (!empty($settings['require_theme_strings']))
2137
-		loadLanguage('ThemeStrings', '', false);
2257
+	if (!empty($settings['require_theme_strings'])) {
2258
+			loadLanguage('ThemeStrings', '', false);
2259
+	}
2138 2260
 
2139 2261
 	// Make a special URL for the language.
2140 2262
 	$settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']);
@@ -2145,8 +2267,9 @@  discard block
 block discarded – undo
2145 2267
 	// Here is my luvly Responsive CSS
2146 2268
 	loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true, 'order_pos' => 9000), 'smf_responsive');
2147 2269
 
2148
-	if ($context['right_to_left'])
2149
-		loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2270
+	if ($context['right_to_left']) {
2271
+			loadCSSFile('rtl.css', array('order_pos' => 200), 'smf_rtl');
2272
+	}
2150 2273
 
2151 2274
 	// We allow theme variants, because we're cool.
2152 2275
 	$context['theme_variant'] = '';
@@ -2154,14 +2277,17 @@  discard block
 block discarded – undo
2154 2277
 	if (!empty($settings['theme_variants']))
2155 2278
 	{
2156 2279
 		// Overriding - for previews and that ilk.
2157
-		if (!empty($_REQUEST['variant']))
2158
-			$_SESSION['id_variant'] = $_REQUEST['variant'];
2280
+		if (!empty($_REQUEST['variant'])) {
2281
+					$_SESSION['id_variant'] = $_REQUEST['variant'];
2282
+		}
2159 2283
 		// User selection?
2160
-		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum'))
2161
-			$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2284
+		if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) {
2285
+					$context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : '');
2286
+		}
2162 2287
 		// If not a user variant, select the default.
2163
-		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants']))
2164
-			$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2288
+		if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) {
2289
+					$context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0];
2290
+		}
2165 2291
 
2166 2292
 		// Do this to keep things easier in the templates.
2167 2293
 		$context['theme_variant'] = '_' . $context['theme_variant'];
@@ -2170,20 +2296,23 @@  discard block
 block discarded – undo
2170 2296
 		if (!empty($context['theme_variant']))
2171 2297
 		{
2172 2298
 			loadCSSFile('index' . $context['theme_variant'] . '.css', array('order_pos' => 300), 'smf_index' . $context['theme_variant']);
2173
-			if ($context['right_to_left'])
2174
-				loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2299
+			if ($context['right_to_left']) {
2300
+							loadCSSFile('rtl' . $context['theme_variant'] . '.css', array('order_pos' => 400), 'smf_rtl' . $context['theme_variant']);
2301
+			}
2175 2302
 		}
2176 2303
 	}
2177 2304
 
2178 2305
 	// Let's be compatible with old themes!
2179
-	if (!function_exists('template_html_above') && in_array('html', $context['template_layers']))
2180
-		$context['template_layers'] = array('main');
2306
+	if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) {
2307
+			$context['template_layers'] = array('main');
2308
+	}
2181 2309
 
2182 2310
 	$context['tabindex'] = 1;
2183 2311
 
2184 2312
 	// Compatibility.
2185
-	if (!isset($settings['theme_version']))
2186
-		$modSettings['memberCount'] = $modSettings['totalMembers'];
2313
+	if (!isset($settings['theme_version'])) {
2314
+			$modSettings['memberCount'] = $modSettings['totalMembers'];
2315
+	}
2187 2316
 
2188 2317
 	// Default JS variables for use in every theme
2189 2318
 	$context['javascript_vars'] = array(
@@ -2202,18 +2331,18 @@  discard block
 block discarded – undo
2202 2331
 	);
2203 2332
 
2204 2333
 	// Add the JQuery library to the list of files to load.
2205
-	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn')
2206
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2207
-
2208
-	elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local')
2209
-		loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2210
-
2211
-	elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom')
2212
-		loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2334
+	if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') {
2335
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2336
+	} elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') {
2337
+			loadJavaScriptFile('jquery-3.2.1.min.js', array('seed' => false), 'smf_jquery');
2338
+	} elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') {
2339
+			loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery');
2340
+	}
2213 2341
 
2214 2342
 	// Auto loading? template_javascript() will take care of the local half of this.
2215
-	else
2216
-		loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2343
+	else {
2344
+			loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array('external' => true), 'smf_jquery');
2345
+	}
2217 2346
 
2218 2347
 	// Queue our JQuery plugins!
2219 2348
 	loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins');
@@ -2236,12 +2365,12 @@  discard block
 block discarded – undo
2236 2365
 			require_once($sourcedir . '/ScheduledTasks.php');
2237 2366
 
2238 2367
 			// What to do, what to do?!
2239
-			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time())
2240
-				AutoTask();
2241
-			else
2242
-				ReduceMailQueue();
2243
-		}
2244
-		else
2368
+			if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) {
2369
+							AutoTask();
2370
+			} else {
2371
+							ReduceMailQueue();
2372
+			}
2373
+		} else
2245 2374
 		{
2246 2375
 			$type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq';
2247 2376
 			$ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time'];
@@ -2292,8 +2421,9 @@  discard block
 block discarded – undo
2292 2421
 		foreach ($theme_includes as $include)
2293 2422
 		{
2294 2423
 			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
2295
-			if (file_exists($include))
2296
-				require_once($include);
2424
+			if (file_exists($include)) {
2425
+							require_once($include);
2426
+			}
2297 2427
 		}
2298 2428
 	}
2299 2429
 
@@ -2323,16 +2453,19 @@  discard block
 block discarded – undo
2323 2453
 	// Do any style sheets first, cause we're easy with those.
2324 2454
 	if (!empty($style_sheets))
2325 2455
 	{
2326
-		if (!is_array($style_sheets))
2327
-			$style_sheets = array($style_sheets);
2456
+		if (!is_array($style_sheets)) {
2457
+					$style_sheets = array($style_sheets);
2458
+		}
2328 2459
 
2329
-		foreach ($style_sheets as $sheet)
2330
-			loadCSSFile($sheet . '.css', array(), $sheet);
2460
+		foreach ($style_sheets as $sheet) {
2461
+					loadCSSFile($sheet . '.css', array(), $sheet);
2462
+		}
2331 2463
 	}
2332 2464
 
2333 2465
 	// No template to load?
2334
-	if ($template_name === false)
2335
-		return true;
2466
+	if ($template_name === false) {
2467
+			return true;
2468
+	}
2336 2469
 
2337 2470
 	$loaded = false;
2338 2471
 	foreach ($settings['template_dirs'] as $template_dir)
@@ -2347,12 +2480,14 @@  discard block
 block discarded – undo
2347 2480
 
2348 2481
 	if ($loaded)
2349 2482
 	{
2350
-		if ($db_show_debug === true)
2351
-			$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2483
+		if ($db_show_debug === true) {
2484
+					$context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')';
2485
+		}
2352 2486
 
2353 2487
 		// If they have specified an initialization function for this template, go ahead and call it now.
2354
-		if (function_exists('template_' . $template_name . '_init'))
2355
-			call_user_func('template_' . $template_name . '_init');
2488
+		if (function_exists('template_' . $template_name . '_init')) {
2489
+					call_user_func('template_' . $template_name . '_init');
2490
+		}
2356 2491
 	}
2357 2492
 	// Hmmm... doesn't exist?!  I don't suppose the directory is wrong, is it?
2358 2493
 	elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default'))
@@ -2372,13 +2507,14 @@  discard block
 block discarded – undo
2372 2507
 		loadTemplate($template_name);
2373 2508
 	}
2374 2509
 	// Cause an error otherwise.
2375
-	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal)
2376
-		fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2377
-	elseif ($fatal)
2378
-		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'));
2379
-	else
2380
-		return false;
2381
-}
2510
+	elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) {
2511
+			fatal_lang_error('theme_template_error', 'template', array((string) $template_name));
2512
+	} elseif ($fatal) {
2513
+			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'));
2514
+	} else {
2515
+			return false;
2516
+	}
2517
+	}
2382 2518
 
2383 2519
 /**
2384 2520
  * Load a sub-template.
@@ -2396,17 +2532,19 @@  discard block
 block discarded – undo
2396 2532
 {
2397 2533
 	global $context, $txt, $db_show_debug;
2398 2534
 
2399
-	if ($db_show_debug === true)
2400
-		$context['debug']['sub_templates'][] = $sub_template_name;
2535
+	if ($db_show_debug === true) {
2536
+			$context['debug']['sub_templates'][] = $sub_template_name;
2537
+	}
2401 2538
 
2402 2539
 	// Figure out what the template function is named.
2403 2540
 	$theme_function = 'template_' . $sub_template_name;
2404
-	if (function_exists($theme_function))
2405
-		$theme_function();
2406
-	elseif ($fatal === false)
2407
-		fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2408
-	elseif ($fatal !== 'ignore')
2409
-		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'));
2541
+	if (function_exists($theme_function)) {
2542
+			$theme_function();
2543
+	} elseif ($fatal === false) {
2544
+			fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name));
2545
+	} elseif ($fatal !== 'ignore') {
2546
+			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'));
2547
+	}
2410 2548
 
2411 2549
 	// Are we showing debugging for templates?  Just make sure not to do it before the doctype...
2412 2550
 	if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml']))
@@ -2436,8 +2574,9 @@  discard block
 block discarded – undo
2436 2574
 {
2437 2575
 	global $settings, $context, $modSettings;
2438 2576
 
2439
-	if (empty($context['css_files_order']))
2440
-		$context['css_files_order'] = array();
2577
+	if (empty($context['css_files_order'])) {
2578
+			$context['css_files_order'] = array();
2579
+	}
2441 2580
 
2442 2581
 	$params['seed'] = (!array_key_exists('seed', $params) || (array_key_exists('seed', $params) && $params['seed'] === true)) ? (array_key_exists('browser_cache', $modSettings) ? $modSettings['browser_cache'] : '') : (is_string($params['seed']) ? ($params['seed'] = $params['seed'][0] === '?' ? $params['seed'] : '?' . $params['seed']) : '');
2443 2582
 	$params['force_current'] = isset($params['force_current']) ? $params['force_current'] : false;
@@ -2448,8 +2587,9 @@  discard block
 block discarded – undo
2448 2587
 	$params['order_pos'] = isset($params['order_pos']) ? (int) $params['order_pos'] : 3000;
2449 2588
 
2450 2589
 	// If this is an external file, automatically set this to false.
2451
-	if (!empty($params['external']))
2452
-		$params['minimize'] = false;
2590
+	if (!empty($params['external'])) {
2591
+			$params['minimize'] = false;
2592
+	}
2453 2593
 
2454 2594
 	// Account for shorthand like admin.css?alp21 filenames
2455 2595
 	$has_seed = strpos($fileName, '.css?');
@@ -2466,16 +2606,12 @@  discard block
 block discarded – undo
2466 2606
 			{
2467 2607
 				$fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2468 2608
 				$filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2469
-			}
2470
-
2471
-			else
2609
+			} else
2472 2610
 			{
2473 2611
 				$fileUrl = false;
2474 2612
 				$filePath = false;
2475 2613
 			}
2476
-		}
2477
-
2478
-		else
2614
+		} else
2479 2615
 		{
2480 2616
 			$fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
2481 2617
 			$filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2493,16 +2629,18 @@  discard block
 block discarded – undo
2493 2629
 	if (!empty($fileName))
2494 2630
 	{
2495 2631
 		// find a free number/position
2496
-		while (isset($context['css_files_order'][$params['order_pos']]))
2497
-			$params['order_pos']++;
2632
+		while (isset($context['css_files_order'][$params['order_pos']])) {
2633
+					$params['order_pos']++;
2634
+		}
2498 2635
 		$context['css_files_order'][$params['order_pos']] = $id;
2499 2636
 
2500 2637
 		$context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2501 2638
 	}
2502 2639
 
2503
-	if (!empty($context['right_to_left']) && !empty($params['rtl']))
2504
-		loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2505
-}
2640
+	if (!empty($context['right_to_left']) && !empty($params['rtl'])) {
2641
+			loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0)));
2642
+	}
2643
+	}
2506 2644
 
2507 2645
 /**
2508 2646
  * Add a block of inline css code to be executed later
@@ -2519,8 +2657,9 @@  discard block
 block discarded – undo
2519 2657
 	global $context;
2520 2658
 
2521 2659
 	// Gotta add something...
2522
-	if (empty($css))
2523
-		return false;
2660
+	if (empty($css)) {
2661
+			return false;
2662
+	}
2524 2663
 
2525 2664
 	$context['css_header'][] = $css;
2526 2665
 }
@@ -2556,8 +2695,9 @@  discard block
 block discarded – undo
2556 2695
 	$params['validate'] = isset($params['validate']) ? $params['validate'] : true;
2557 2696
 
2558 2697
 	// If this is an external file, automatically set this to false.
2559
-	if (!empty($params['external']))
2560
-		$params['minimize'] = false;
2698
+	if (!empty($params['external'])) {
2699
+			$params['minimize'] = false;
2700
+	}
2561 2701
 
2562 2702
 	// Account for shorthand like admin.js?alp21 filenames
2563 2703
 	$has_seed = strpos($fileName, '.js?');
@@ -2574,16 +2714,12 @@  discard block
 block discarded – undo
2574 2714
 			{
2575 2715
 				$fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2576 2716
 				$filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2577
-			}
2578
-
2579
-			else
2717
+			} else
2580 2718
 			{
2581 2719
 				$fileUrl = false;
2582 2720
 				$filePath = false;
2583 2721
 			}
2584
-		}
2585
-
2586
-		else
2722
+		} else
2587 2723
 		{
2588 2724
 			$fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
2589 2725
 			$filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']);
@@ -2598,9 +2734,10 @@  discard block
 block discarded – undo
2598 2734
 	}
2599 2735
 
2600 2736
 	// Add it to the array for use in the template
2601
-	if (!empty($fileName))
2602
-		$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2603
-}
2737
+	if (!empty($fileName)) {
2738
+			$context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params);
2739
+	}
2740
+	}
2604 2741
 
2605 2742
 /**
2606 2743
  * Add a Javascript variable for output later (for feeding text strings and similar to JS)
@@ -2614,9 +2751,10 @@  discard block
 block discarded – undo
2614 2751
 {
2615 2752
 	global $context;
2616 2753
 
2617
-	if (!empty($key) && (!empty($value) || $value === '0'))
2618
-		$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2619
-}
2754
+	if (!empty($key) && (!empty($value) || $value === '0')) {
2755
+			$context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value;
2756
+	}
2757
+	}
2620 2758
 
2621 2759
 /**
2622 2760
  * Add a block of inline Javascript code to be executed later
@@ -2633,8 +2771,9 @@  discard block
 block discarded – undo
2633 2771
 {
2634 2772
 	global $context;
2635 2773
 
2636
-	if (empty($javascript))
2637
-		return false;
2774
+	if (empty($javascript)) {
2775
+			return false;
2776
+	}
2638 2777
 
2639 2778
 	$context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript;
2640 2779
 }
@@ -2655,15 +2794,18 @@  discard block
 block discarded – undo
2655 2794
 	static $already_loaded = array();
2656 2795
 
2657 2796
 	// Default to the user's language.
2658
-	if ($lang == '')
2659
-		$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2797
+	if ($lang == '') {
2798
+			$lang = isset($user_info['language']) ? $user_info['language'] : $language;
2799
+	}
2660 2800
 
2661 2801
 	// Do we want the English version of language file as fallback?
2662
-	if (empty($modSettings['disable_language_fallback']) && $lang != 'english')
2663
-		loadLanguage($template_name, 'english', false);
2802
+	if (empty($modSettings['disable_language_fallback']) && $lang != 'english') {
2803
+			loadLanguage($template_name, 'english', false);
2804
+	}
2664 2805
 
2665
-	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang)
2666
-		return $lang;
2806
+	if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) {
2807
+			return $lang;
2808
+	}
2667 2809
 
2668 2810
 	// Make sure we have $settings - if not we're in trouble and need to find it!
2669 2811
 	if (empty($settings['default_theme_dir']))
@@ -2674,8 +2816,9 @@  discard block
 block discarded – undo
2674 2816
 
2675 2817
 	// What theme are we in?
2676 2818
 	$theme_name = basename($settings['theme_url']);
2677
-	if (empty($theme_name))
2678
-		$theme_name = 'unknown';
2819
+	if (empty($theme_name)) {
2820
+			$theme_name = 'unknown';
2821
+	}
2679 2822
 
2680 2823
 	// For each file open it up and write it out!
2681 2824
 	foreach (explode('+', $template_name) as $template)
@@ -2717,8 +2860,9 @@  discard block
 block discarded – undo
2717 2860
 				$found = true;
2718 2861
 
2719 2862
 				// setlocale is required for basename() & pathinfo() to work properly on the selected language
2720
-				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set']))
2721
-					setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2863
+				if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) {
2864
+									setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']);
2865
+				}
2722 2866
 
2723 2867
 				break;
2724 2868
 			}
@@ -2758,8 +2902,9 @@  discard block
 block discarded – undo
2758 2902
 	}
2759 2903
 
2760 2904
 	// Keep track of what we're up to soldier.
2761
-	if ($db_show_debug === true)
2762
-		$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2905
+	if ($db_show_debug === true) {
2906
+			$context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')';
2907
+	}
2763 2908
 
2764 2909
 	// Remember what we have loaded, and in which language.
2765 2910
 	$already_loaded[$template_name] = $lang;
@@ -2805,8 +2950,9 @@  discard block
 block discarded – undo
2805 2950
 				)
2806 2951
 			);
2807 2952
 			// In the EXTREMELY unlikely event this happens, give an error message.
2808
-			if ($smcFunc['db_num_rows']($result) == 0)
2809
-				fatal_lang_error('parent_not_found', 'critical');
2953
+			if ($smcFunc['db_num_rows']($result) == 0) {
2954
+							fatal_lang_error('parent_not_found', 'critical');
2955
+			}
2810 2956
 			while ($row = $smcFunc['db_fetch_assoc']($result))
2811 2957
 			{
2812 2958
 				if (!isset($boards[$row['id_board']]))
@@ -2823,8 +2969,8 @@  discard block
 block discarded – undo
2823 2969
 					);
2824 2970
 				}
2825 2971
 				// If a moderator exists for this board, add that moderator for all children too.
2826
-				if (!empty($row['id_moderator']))
2827
-					foreach ($boards as $id => $dummy)
2972
+				if (!empty($row['id_moderator'])) {
2973
+									foreach ($boards as $id => $dummy)
2828 2974
 					{
2829 2975
 						$boards[$id]['moderators'][$row['id_moderator']] = array(
2830 2976
 							'id' => $row['id_moderator'],
@@ -2832,11 +2978,12 @@  discard block
 block discarded – undo
2832 2978
 							'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'],
2833 2979
 							'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>'
2834 2980
 						);
2981
+				}
2835 2982
 					}
2836 2983
 
2837 2984
 				// If a moderator group exists for this board, add that moderator group for all children too
2838
-				if (!empty($row['id_moderator_group']))
2839
-					foreach ($boards as $id => $dummy)
2985
+				if (!empty($row['id_moderator_group'])) {
2986
+									foreach ($boards as $id => $dummy)
2840 2987
 					{
2841 2988
 						$boards[$id]['moderator_groups'][$row['id_moderator_group']] = array(
2842 2989
 							'id' => $row['id_moderator_group'],
@@ -2844,6 +2991,7 @@  discard block
 block discarded – undo
2844 2991
 							'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'],
2845 2992
 							'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>'
2846 2993
 						);
2994
+				}
2847 2995
 					}
2848 2996
 			}
2849 2997
 			$smcFunc['db_free_result']($result);
@@ -2870,23 +3018,27 @@  discard block
 block discarded – undo
2870 3018
 	if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null)
2871 3019
 	{
2872 3020
 		// If we don't have our ucwords function defined yet, let's load the settings data.
2873
-		if (empty($smcFunc['ucwords']))
2874
-			reloadSettings();
3021
+		if (empty($smcFunc['ucwords'])) {
3022
+					reloadSettings();
3023
+		}
2875 3024
 
2876 3025
 		// If we don't have our theme information yet, let's get it.
2877
-		if (empty($settings['default_theme_dir']))
2878
-			loadTheme(0, false);
3026
+		if (empty($settings['default_theme_dir'])) {
3027
+					loadTheme(0, false);
3028
+		}
2879 3029
 
2880 3030
 		// Default language directories to try.
2881 3031
 		$language_directories = array(
2882 3032
 			$settings['default_theme_dir'] . '/languages',
2883 3033
 		);
2884
-		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir'])
2885
-			$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3034
+		if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) {
3035
+					$language_directories[] = $settings['actual_theme_dir'] . '/languages';
3036
+		}
2886 3037
 
2887 3038
 		// We possibly have a base theme directory.
2888
-		if (!empty($settings['base_theme_dir']))
2889
-			$language_directories[] = $settings['base_theme_dir'] . '/languages';
3039
+		if (!empty($settings['base_theme_dir'])) {
3040
+					$language_directories[] = $settings['base_theme_dir'] . '/languages';
3041
+		}
2890 3042
 
2891 3043
 		// Remove any duplicates.
2892 3044
 		$language_directories = array_unique($language_directories);
@@ -2900,20 +3052,21 @@  discard block
 block discarded – undo
2900 3052
 		foreach ($language_directories as $language_dir)
2901 3053
 		{
2902 3054
 			// Can't look in here... doesn't exist!
2903
-			if (!file_exists($language_dir))
2904
-				continue;
3055
+			if (!file_exists($language_dir)) {
3056
+							continue;
3057
+			}
2905 3058
 
2906 3059
 			$dir = dir($language_dir);
2907 3060
 			while ($entry = $dir->read())
2908 3061
 			{
2909 3062
 				// Look for the index language file... For good measure skip any "index.language-utf8.php" files
2910
-				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches))
2911
-					continue;
2912
-
2913
-				if (!empty($langList) && !empty($langList[$matches[1]]))
2914
-					$langName = $langList[$matches[1]];
3063
+				if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) {
3064
+									continue;
3065
+				}
2915 3066
 
2916
-				else
3067
+				if (!empty($langList) && !empty($langList[$matches[1]])) {
3068
+									$langName = $langList[$matches[1]];
3069
+				} else
2917 3070
 				{
2918 3071
 					$langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' ')));
2919 3072
 
@@ -2954,12 +3107,14 @@  discard block
 block discarded – undo
2954 3107
 		}
2955 3108
 
2956 3109
 		// Do we need to store the lang list?
2957
-		if (empty($langList))
2958
-			updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3110
+		if (empty($langList)) {
3111
+					updateSettings(array('langList' => $smcFunc['json_encode']($catchLang)));
3112
+		}
2959 3113
 
2960 3114
 		// Let's cash in on this deal.
2961
-		if (!empty($modSettings['cache_enable']))
2962
-			cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3115
+		if (!empty($modSettings['cache_enable'])) {
3116
+					cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600);
3117
+		}
2963 3118
 	}
2964 3119
 
2965 3120
 	return $context['languages'];
@@ -2982,8 +3137,9 @@  discard block
 block discarded – undo
2982 3137
 	global $modSettings, $options, $txt;
2983 3138
 	static $censor_vulgar = null, $censor_proper;
2984 3139
 
2985
-	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '')
2986
-		return $text;
3140
+	if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') {
3141
+			return $text;
3142
+	}
2987 3143
 
2988 3144
 	// If they haven't yet been loaded, load them.
2989 3145
 	if ($censor_vulgar == null)
@@ -3014,9 +3170,9 @@  discard block
 block discarded – undo
3014 3170
 	{
3015 3171
 		$func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace';
3016 3172
 		$text = $func($censor_vulgar, $censor_proper, $text);
3173
+	} else {
3174
+			$text = preg_replace($censor_vulgar, $censor_proper, $text);
3017 3175
 	}
3018
-	else
3019
-		$text = preg_replace($censor_vulgar, $censor_proper, $text);
3020 3176
 
3021 3177
 	return $text;
3022 3178
 }
@@ -3042,30 +3198,35 @@  discard block
 block discarded – undo
3042 3198
 	@ini_set('track_errors', '1');
3043 3199
 
3044 3200
 	// Don't include the file more than once, if $once is true.
3045
-	if ($once && in_array($filename, $templates))
3046
-		return;
3201
+	if ($once && in_array($filename, $templates)) {
3202
+			return;
3203
+	}
3047 3204
 	// Add this file to the include list, whether $once is true or not.
3048
-	else
3049
-		$templates[] = $filename;
3205
+	else {
3206
+			$templates[] = $filename;
3207
+	}
3050 3208
 
3051 3209
 
3052 3210
 	$file_found = file_exists($filename);
3053 3211
 
3054
-	if ($once && $file_found)
3055
-		require_once($filename);
3056
-	elseif ($file_found)
3057
-		require($filename);
3212
+	if ($once && $file_found) {
3213
+			require_once($filename);
3214
+	} elseif ($file_found) {
3215
+			require($filename);
3216
+	}
3058 3217
 
3059 3218
 	if ($file_found !== true)
3060 3219
 	{
3061 3220
 		ob_end_clean();
3062
-		if (!empty($modSettings['enableCompressedOutput']))
3063
-			@ob_start('ob_gzhandler');
3064
-		else
3065
-			ob_start();
3221
+		if (!empty($modSettings['enableCompressedOutput'])) {
3222
+					@ob_start('ob_gzhandler');
3223
+		} else {
3224
+					ob_start();
3225
+		}
3066 3226
 
3067
-		if (isset($_GET['debug']))
3068
-			header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3227
+		if (isset($_GET['debug'])) {
3228
+					header('content-type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3229
+		}
3069 3230
 
3070 3231
 		// Don't cache error pages!!
3071 3232
 		header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -3084,12 +3245,13 @@  discard block
 block discarded – undo
3084 3245
 		echo '<!DOCTYPE html>
3085 3246
 <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '>
3086 3247
 	<head>';
3087
-		if (isset($context['character_set']))
3088
-			echo '
3248
+		if (isset($context['character_set'])) {
3249
+					echo '
3089 3250
 		<meta charset="', $context['character_set'], '">';
3251
+		}
3090 3252
 
3091
-		if (!empty($maintenance) && !allowedTo('admin_forum'))
3092
-			echo '
3253
+		if (!empty($maintenance) && !allowedTo('admin_forum')) {
3254
+					echo '
3093 3255
 		<title>', $mtitle, '</title>
3094 3256
 	</head>
3095 3257
 	<body>
@@ -3097,8 +3259,8 @@  discard block
 block discarded – undo
3097 3259
 		', $mmessage, '
3098 3260
 	</body>
3099 3261
 </html>';
3100
-		elseif (!allowedTo('admin_forum'))
3101
-			echo '
3262
+		} elseif (!allowedTo('admin_forum')) {
3263
+					echo '
3102 3264
 		<title>', $txt['template_parse_error'], '</title>
3103 3265
 	</head>
3104 3266
 	<body>
@@ -3106,14 +3268,16 @@  discard block
 block discarded – undo
3106 3268
 		', $txt['template_parse_error_message'], '
3107 3269
 	</body>
3108 3270
 </html>';
3109
-		else
3271
+		} else
3110 3272
 		{
3111 3273
 			$error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3112 3274
 			$error_array = error_get_last();
3113
-			if (empty($error) && ini_get('track_errors') && !empty($error_array))
3114
-				$error = $error_array['message'];
3115
-			if (empty($error))
3116
-				$error = $txt['template_parse_errmsg'];
3275
+			if (empty($error) && ini_get('track_errors') && !empty($error_array)) {
3276
+							$error = $error_array['message'];
3277
+			}
3278
+			if (empty($error)) {
3279
+							$error = $txt['template_parse_errmsg'];
3280
+			}
3117 3281
 
3118 3282
 			$error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>'));
3119 3283
 
@@ -3124,11 +3288,12 @@  discard block
 block discarded – undo
3124 3288
 		<h3>', $txt['template_parse_error'], '</h3>
3125 3289
 		', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => '')));
3126 3290
 
3127
-			if (!empty($error))
3128
-				echo '
3291
+			if (!empty($error)) {
3292
+							echo '
3129 3293
 		<hr>
3130 3294
 
3131 3295
 		<div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>';
3296
+			}
3132 3297
 
3133 3298
 			// I know, I know... this is VERY COMPLICATED.  Still, it's good.
3134 3299
 			if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0)
@@ -3138,10 +3303,11 @@  discard block
 block discarded – undo
3138 3303
 				$data2 = preg_split('~\<br( /)?\>~', $data2);
3139 3304
 
3140 3305
 				// Fix the PHP code stuff...
3141
-				if (!isBrowser('gecko'))
3142
-					$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3143
-				else
3144
-					$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3306
+				if (!isBrowser('gecko')) {
3307
+									$data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2);
3308
+				} else {
3309
+									$data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2);
3310
+				}
3145 3311
 
3146 3312
 				// Now we get to work around a bug in PHP where it doesn't escape <br>s!
3147 3313
 				$j = -1;
@@ -3149,8 +3315,9 @@  discard block
 block discarded – undo
3149 3315
 				{
3150 3316
 					$j++;
3151 3317
 
3152
-					if (substr_count($line, '<br>') == 0)
3153
-						continue;
3318
+					if (substr_count($line, '<br>') == 0) {
3319
+											continue;
3320
+					}
3154 3321
 
3155 3322
 					$n = substr_count($line, '<br>');
3156 3323
 					for ($i = 0; $i < $n; $i++)
@@ -3169,38 +3336,42 @@  discard block
 block discarded – undo
3169 3336
 				// Figure out what the color coding was before...
3170 3337
 				$line = max($match[1] - 9, 1);
3171 3338
 				$last_line = '';
3172
-				for ($line2 = $line - 1; $line2 > 1; $line2--)
3173
-					if (strpos($data2[$line2], '<') !== false)
3339
+				for ($line2 = $line - 1; $line2 > 1; $line2--) {
3340
+									if (strpos($data2[$line2], '<') !== false)
3174 3341
 					{
3175 3342
 						if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0)
3176 3343
 							$last_line = $color_match[1];
3344
+				}
3177 3345
 						break;
3178 3346
 					}
3179 3347
 
3180 3348
 				// Show the relevant lines...
3181 3349
 				for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++)
3182 3350
 				{
3183
-					if ($line == $match[1])
3184
-						echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3351
+					if ($line == $match[1]) {
3352
+											echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">';
3353
+					}
3185 3354
 
3186 3355
 					echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> ';
3187
-					if (isset($data2[$line]) && $data2[$line] != '')
3188
-						echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3356
+					if (isset($data2[$line]) && $data2[$line] != '') {
3357
+											echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line];
3358
+					}
3189 3359
 
3190 3360
 					if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0)
3191 3361
 					{
3192 3362
 						$last_line = $color_match[1];
3193 3363
 						echo '</', substr($last_line, 1, 4), '>';
3364
+					} elseif ($last_line != '' && strpos($data2[$line], '<') !== false) {
3365
+											$last_line = '';
3366
+					} elseif ($last_line != '' && $data2[$line] != '') {
3367
+											echo '</', substr($last_line, 1, 4), '>';
3194 3368
 					}
3195
-					elseif ($last_line != '' && strpos($data2[$line], '<') !== false)
3196
-						$last_line = '';
3197
-					elseif ($last_line != '' && $data2[$line] != '')
3198
-						echo '</', substr($last_line, 1, 4), '>';
3199 3369
 
3200
-					if ($line == $match[1])
3201
-						echo '</pre></div><pre style="margin: 0;">';
3202
-					else
3203
-						echo "\n";
3370
+					if ($line == $match[1]) {
3371
+											echo '</pre></div><pre style="margin: 0;">';
3372
+					} else {
3373
+											echo "\n";
3374
+					}
3204 3375
 				}
3205 3376
 
3206 3377
 				echo '</pre></div>';
@@ -3224,8 +3395,9 @@  discard block
 block discarded – undo
3224 3395
 	global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port;
3225 3396
 
3226 3397
 	// Figure out what type of database we are using.
3227
-	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
3228
-		$db_type = 'mysql';
3398
+	if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) {
3399
+			$db_type = 'mysql';
3400
+	}
3229 3401
 
3230 3402
 	// Load the file for the database.
3231 3403
 	require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
@@ -3233,8 +3405,9 @@  discard block
 block discarded – undo
3233 3405
 	$db_options = array();
3234 3406
 
3235 3407
 	// Add in the port if needed
3236
-	if (!empty($db_port))
3237
-		$db_options['port'] = $db_port;
3408
+	if (!empty($db_port)) {
3409
+			$db_options['port'] = $db_port;
3410
+	}
3238 3411
 
3239 3412
 	// 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.
3240 3413
 	if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd))
@@ -3253,13 +3426,15 @@  discard block
 block discarded – undo
3253 3426
 	}
3254 3427
 
3255 3428
 	// Safe guard here, if there isn't a valid connection lets put a stop to it.
3256
-	if (!$db_connection)
3257
-		display_db_error();
3429
+	if (!$db_connection) {
3430
+			display_db_error();
3431
+	}
3258 3432
 
3259 3433
 	// If in SSI mode fix up the prefix.
3260
-	if (SMF == 'SSI')
3261
-		db_fix_prefix($db_prefix, $db_name);
3262
-}
3434
+	if (SMF == 'SSI') {
3435
+			db_fix_prefix($db_prefix, $db_name);
3436
+	}
3437
+	}
3263 3438
 
3264 3439
 /**
3265 3440
  * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it.
@@ -3273,10 +3448,11 @@  discard block
 block discarded – undo
3273 3448
 	global $sourcedir, $cacheAPI, $cache_accelerator;
3274 3449
 
3275 3450
 	// Not overriding this and we have a cacheAPI, send it back.
3276
-	if (empty($overrideCache) && is_object($cacheAPI))
3277
-		return $cacheAPI;
3278
-	elseif (is_null($cacheAPI))
3279
-		$cacheAPI = false;
3451
+	if (empty($overrideCache) && is_object($cacheAPI)) {
3452
+			return $cacheAPI;
3453
+	} elseif (is_null($cacheAPI)) {
3454
+			$cacheAPI = false;
3455
+	}
3280 3456
 
3281 3457
 	// Make sure our class is in session.
3282 3458
 	require_once($sourcedir . '/Class-CacheAPI.php');
@@ -3297,8 +3473,9 @@  discard block
 block discarded – undo
3297 3473
 		if (!$testAPI->isSupported())
3298 3474
 		{
3299 3475
 			// Can we save ourselves?
3300
-			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf')
3301
-				return loadCacheAccelerator(null, false);
3476
+			if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') {
3477
+							return loadCacheAccelerator(null, false);
3478
+			}
3302 3479
 			return false;
3303 3480
 		}
3304 3481
 
@@ -3310,9 +3487,9 @@  discard block
 block discarded – undo
3310 3487
 		{
3311 3488
 			$cacheAPI = $testAPI;
3312 3489
 			return $cacheAPI;
3490
+		} else {
3491
+					return $testAPI;
3313 3492
 		}
3314
-		else
3315
-			return $testAPI;
3316 3493
 	}
3317 3494
 }
3318 3495
 
@@ -3332,8 +3509,9 @@  discard block
 block discarded – undo
3332 3509
 
3333 3510
 	// @todo Why are we doing this if caching is disabled?
3334 3511
 
3335
-	if (function_exists('call_integration_hook'))
3336
-		call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3512
+	if (function_exists('call_integration_hook')) {
3513
+			call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
3514
+	}
3337 3515
 
3338 3516
 	/* Refresh the cache if either:
3339 3517
 		1. Caching is disabled.
@@ -3347,16 +3525,19 @@  discard block
 block discarded – undo
3347 3525
 		require_once($sourcedir . '/' . $file);
3348 3526
 		$cache_block = call_user_func_array($function, $params);
3349 3527
 
3350
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level)
3351
-			cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3528
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
3529
+					cache_put_data($key, $cache_block, $cache_block['expires'] - time());
3530
+		}
3352 3531
 	}
3353 3532
 
3354 3533
 	// Some cached data may need a freshening up after retrieval.
3355
-	if (!empty($cache_block['post_retri_eval']))
3356
-		eval($cache_block['post_retri_eval']);
3534
+	if (!empty($cache_block['post_retri_eval'])) {
3535
+			eval($cache_block['post_retri_eval']);
3536
+	}
3357 3537
 
3358
-	if (function_exists('call_integration_hook'))
3359
-		call_integration_hook('post_cache_quick_get', array(&$cache_block));
3538
+	if (function_exists('call_integration_hook')) {
3539
+			call_integration_hook('post_cache_quick_get', array(&$cache_block));
3540
+	}
3360 3541
 
3361 3542
 	return $cache_block['data'];
3362 3543
 }
@@ -3383,8 +3564,9 @@  discard block
 block discarded – undo
3383 3564
 	global $smcFunc, $cache_enable, $cacheAPI;
3384 3565
 	global $cache_hits, $cache_count, $db_show_debug;
3385 3566
 
3386
-	if (empty($cache_enable) || empty($cacheAPI))
3387
-		return;
3567
+	if (empty($cache_enable) || empty($cacheAPI)) {
3568
+			return;
3569
+	}
3388 3570
 
3389 3571
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3390 3572
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3397,12 +3579,14 @@  discard block
 block discarded – undo
3397 3579
 	$value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value));
3398 3580
 	$cacheAPI->putData($key, $value, $ttl);
3399 3581
 
3400
-	if (function_exists('call_integration_hook'))
3401
-		call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3582
+	if (function_exists('call_integration_hook')) {
3583
+			call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl));
3584
+	}
3402 3585
 
3403
-	if (isset($db_show_debug) && $db_show_debug === true)
3404
-		$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3405
-}
3586
+	if (isset($db_show_debug) && $db_show_debug === true) {
3587
+			$cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
3588
+	}
3589
+	}
3406 3590
 
3407 3591
 /**
3408 3592
  * Gets the value from the cache specified by key, so long as it is not older than ttl seconds.
@@ -3418,8 +3602,9 @@  discard block
 block discarded – undo
3418 3602
 	global $smcFunc, $cache_enable, $cacheAPI;
3419 3603
 	global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug;
3420 3604
 
3421
-	if (empty($cache_enable) || empty($cacheAPI))
3422
-		return;
3605
+	if (empty($cache_enable) || empty($cacheAPI)) {
3606
+			return;
3607
+	}
3423 3608
 
3424 3609
 	$cache_count = isset($cache_count) ? $cache_count + 1 : 1;
3425 3610
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -3439,16 +3624,18 @@  discard block
 block discarded – undo
3439 3624
 
3440 3625
 		if (empty($value))
3441 3626
 		{
3442
-			if (!is_array($cache_misses))
3443
-				$cache_misses = array();
3627
+			if (!is_array($cache_misses)) {
3628
+							$cache_misses = array();
3629
+			}
3444 3630
 
3445 3631
 			$cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1;
3446 3632
 			$cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get');
3447 3633
 		}
3448 3634
 	}
3449 3635
 
3450
-	if (function_exists('call_integration_hook') && isset($value))
3451
-		call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3636
+	if (function_exists('call_integration_hook') && isset($value)) {
3637
+			call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value));
3638
+	}
3452 3639
 
3453 3640
 	return empty($value) ? null : (isset($smcFunc['json_decode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true));
3454 3641
 }
@@ -3470,8 +3657,9 @@  discard block
 block discarded – undo
3470 3657
 	global $cacheAPI;
3471 3658
 
3472 3659
 	// If we can't get to the API, can't do this.
3473
-	if (empty($cacheAPI))
3474
-		return;
3660
+	if (empty($cacheAPI)) {
3661
+			return;
3662
+	}
3475 3663
 
3476 3664
 	// Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure.
3477 3665
 	$cacheAPI->cleanCache($type);
@@ -3496,8 +3684,9 @@  discard block
 block discarded – undo
3496 3684
 	global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $user_info;
3497 3685
 
3498 3686
 	// Come on!
3499
-	if (empty($data))
3500
-		return array();
3687
+	if (empty($data)) {
3688
+			return array();
3689
+	}
3501 3690
 
3502 3691
 	// Set a nice default var.
3503 3692
 	$image = '';
@@ -3505,11 +3694,11 @@  discard block
 block discarded – undo
3505 3694
 	// Gravatar has been set as mandatory!
3506 3695
 	if (!empty($modSettings['gravatarOverride']))
3507 3696
 	{
3508
-		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://'))
3509
-			$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3510
-
3511
-		else if (!empty($data['email']))
3512
-			$image = get_gravatar_url($data['email']);
3697
+		if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) {
3698
+					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3699
+		} else if (!empty($data['email'])) {
3700
+					$image = get_gravatar_url($data['email']);
3701
+		}
3513 3702
 	}
3514 3703
 
3515 3704
 	// Look if the user has a gravatar field or has set an external url as avatar.
@@ -3521,54 +3710,60 @@  discard block
 block discarded – undo
3521 3710
 			// Gravatar.
3522 3711
 			if (stristr($data['avatar'], 'gravatar://'))
3523 3712
 			{
3524
-				if ($data['avatar'] == 'gravatar://')
3525
-					$image = get_gravatar_url($data['email']);
3526
-
3527
-				elseif (!empty($modSettings['gravatarAllowExtraEmail']))
3528
-					$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3713
+				if ($data['avatar'] == 'gravatar://') {
3714
+									$image = get_gravatar_url($data['email']);
3715
+				} elseif (!empty($modSettings['gravatarAllowExtraEmail'])) {
3716
+									$image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11));
3717
+				}
3529 3718
 			}
3530 3719
 
3531 3720
 			// External url.
3532 3721
 			else
3533 3722
 			{
3534 3723
 				// Using ssl?
3535
-				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot']))
3536
-					$image = get_proxied_url($data['avatar']);
3724
+				if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false && empty($user_info['possibly_robot'])) {
3725
+									$image = get_proxied_url($data['avatar']);
3726
+				}
3537 3727
 
3538 3728
 				// Just a plain external url.
3539
-				else
3540
-					$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3729
+				else {
3730
+									$image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar'];
3731
+				}
3541 3732
 			}
3542 3733
 		}
3543 3734
 
3544 3735
 		// Perhaps this user has an attachment as avatar...
3545
-		else if (!empty($data['filename']))
3546
-			$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3736
+		else if (!empty($data['filename'])) {
3737
+					$image = $modSettings['custom_avatar_url'] . '/' . $data['filename'];
3738
+		}
3547 3739
 
3548 3740
 		// Right... no avatar... use our default image.
3549
-		else
3550
-			$image = $modSettings['avatar_url'] . '/default.png';
3741
+		else {
3742
+					$image = $modSettings['avatar_url'] . '/default.png';
3743
+		}
3551 3744
 	}
3552 3745
 
3553 3746
 	call_integration_hook('integrate_set_avatar_data', array(&$image, &$data));
3554 3747
 
3555 3748
 	// 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.
3556
-	if (!empty($image))
3557
-		return array(
3749
+	if (!empty($image)) {
3750
+			return array(
3558 3751
 			'name' => !empty($data['avatar']) ? $data['avatar'] : '',
3559 3752
 			'image' => '<img class="avatar" src="' . $image . '" />',
3560 3753
 			'href' => $image,
3561 3754
 			'url' => $image,
3562 3755
 		);
3756
+	}
3563 3757
 
3564 3758
 	// Fallback to make life easier for everyone...
3565
-	else
3566
-		return array(
3759
+	else {
3760
+			return array(
3567 3761
 			'name' => '',
3568 3762
 			'image' => '',
3569 3763
 			'href' => '',
3570 3764
 			'url' => '',
3571 3765
 		);
3572
-}
3766
+	}
3767
+	}
3573 3768
 
3574 3769
 ?>
3575 3770
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Post.php 1 patch
Braces   +674 added lines, -521 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
@@ -35,12 +36,14 @@  discard block
 block discarded – undo
35 36
 	global $sourcedir, $smcFunc, $language;
36 37
 
37 38
 	loadLanguage('Post');
38
-	if (!empty($modSettings['drafts_post_enabled']))
39
-		loadLanguage('Drafts');
39
+	if (!empty($modSettings['drafts_post_enabled'])) {
40
+			loadLanguage('Drafts');
41
+	}
40 42
 
41 43
 	// You can't reply with a poll... hacker.
42
-	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg']))
43
-		unset($_REQUEST['poll']);
44
+	if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) {
45
+			unset($_REQUEST['poll']);
46
+	}
44 47
 
45 48
 	// Posting an event?
46 49
 	$context['make_event'] = isset($_REQUEST['calendar']);
@@ -58,12 +61,14 @@  discard block
 block discarded – undo
58 61
 	{
59 62
 		// Get ids of all the boards they can post in.
60 63
 		$post_permissions = array('post_new');
61
-		if ($modSettings['postmod_active'])
62
-			$post_permissions[] = 'post_unapproved_topics';
64
+		if ($modSettings['postmod_active']) {
65
+					$post_permissions[] = 'post_unapproved_topics';
66
+		}
63 67
 
64 68
 		$boards = boardsAllowedTo($post_permissions);
65
-		if (empty($boards))
66
-			fatal_lang_error('cannot_post_new', false);
69
+		if (empty($boards)) {
70
+					fatal_lang_error('cannot_post_new', false);
71
+		}
67 72
 
68 73
 		// Get a list of boards for the select menu
69 74
 		require_once($sourcedir . '/Subs-MessageIndex.php');
@@ -76,8 +81,9 @@  discard block
 block discarded – undo
76 81
 		$board_list = getBoardList($boardListOptions);
77 82
 	}
78 83
 	// Let's keep things simple for ourselves below
79
-	else
80
-		$boards = array($board);
84
+	else {
85
+			$boards = array($board);
86
+	}
81 87
 
82 88
 	require_once($sourcedir . '/Subs-Post.php');
83 89
 
@@ -100,10 +106,11 @@  discard block
 block discarded – undo
100 106
 			array(
101 107
 				'msg' => (int) $_REQUEST['msg'],
102 108
 		));
103
-		if ($smcFunc['db_num_rows']($request) != 1)
104
-			unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
105
-		else
106
-			list ($topic) = $smcFunc['db_fetch_row']($request);
109
+		if ($smcFunc['db_num_rows']($request) != 1) {
110
+					unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']);
111
+		} else {
112
+					list ($topic) = $smcFunc['db_fetch_row']($request);
113
+		}
107 114
 		$smcFunc['db_free_result']($request);
108 115
 	}
109 116
 
@@ -130,33 +137,36 @@  discard block
 block discarded – undo
130 137
 		$smcFunc['db_free_result']($request);
131 138
 
132 139
 		// If this topic already has a poll, they sure can't add another.
133
-		if (isset($_REQUEST['poll']) && $pollID > 0)
134
-			unset($_REQUEST['poll']);
140
+		if (isset($_REQUEST['poll']) && $pollID > 0) {
141
+					unset($_REQUEST['poll']);
142
+		}
135 143
 
136 144
 		if (empty($_REQUEST['msg']))
137 145
 		{
138
-			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any')))
139
-				is_not_guest();
146
+			if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) {
147
+							is_not_guest();
148
+			}
140 149
 
141 150
 			// By default the reply will be approved...
142 151
 			$context['becomes_approved'] = true;
143 152
 			if ($id_member_poster != $user_info['id'] || $user_info['is_guest'])
144 153
 			{
145
-				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
146
-					$context['becomes_approved'] = false;
147
-				else
148
-					isAllowedTo('post_reply_any');
149
-			}
150
-			elseif (!allowedTo('post_reply_any'))
154
+				if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
155
+									$context['becomes_approved'] = false;
156
+				} else {
157
+									isAllowedTo('post_reply_any');
158
+				}
159
+			} elseif (!allowedTo('post_reply_any'))
151 160
 			{
152
-				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any')))
153
-					$context['becomes_approved'] = false;
154
-				else
155
-					isAllowedTo('post_reply_own');
161
+				if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) {
162
+									$context['becomes_approved'] = false;
163
+				} else {
164
+									isAllowedTo('post_reply_own');
165
+				}
156 166
 			}
167
+		} else {
168
+					$context['becomes_approved'] = true;
157 169
 		}
158
-		else
159
-			$context['becomes_approved'] = true;
160 170
 
161 171
 		$context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own'));
162 172
 		$context['can_sticky'] = allowedTo('make_sticky');
@@ -171,17 +181,18 @@  discard block
 block discarded – undo
171 181
 		$context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky;
172 182
 
173 183
 		// Check whether this is a really old post being bumped...
174
-		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject']))
175
-			$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
176
-	}
177
-	else
184
+		if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) {
185
+					$post_errors[] = array('old_topic', array($modSettings['oldTopicDays']));
186
+		}
187
+	} else
178 188
 	{
179 189
 		// @todo Should use JavaScript to hide and show the warning based on the selection in the board select menu
180 190
 		$context['becomes_approved'] = true;
181
-		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true))
182
-			$context['becomes_approved'] = false;
183
-		else
184
-			isAllowedTo('post_new', $boards, true);
191
+		if ($modSettings['postmod_active'] && !allowedTo('post_new', $boards, true) && allowedTo('post_unapproved_topics', $boards, true)) {
192
+					$context['becomes_approved'] = false;
193
+		} else {
194
+					isAllowedTo('post_new', $boards, true);
195
+		}
185 196
 
186 197
 		$locked = 0;
187 198
 		$context['already_locked'] = 0;
@@ -211,27 +222,32 @@  discard block
 block discarded – undo
211 222
 	if (empty($_REQUEST['message']) && empty($_REQUEST['preview']) && !empty($_SESSION['already_attached']))
212 223
 	{
213 224
 		require_once($sourcedir . '/ManageAttachments.php');
214
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
215
-			removeAttachments(array('id_attach' => $attachID));
225
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
226
+					removeAttachments(array('id_attach' => $attachID));
227
+		}
216 228
 
217 229
 		unset($_SESSION['already_attached']);
218 230
 	}
219 231
 
220 232
 	// Don't allow a post if it's locked and you aren't all powerful.
221
-	if ($locked && !allowedTo('moderate_board'))
222
-		fatal_lang_error('topic_locked', false);
233
+	if ($locked && !allowedTo('moderate_board')) {
234
+			fatal_lang_error('topic_locked', false);
235
+	}
223 236
 	// Check the users permissions - is the user allowed to add or post a poll?
224 237
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
225 238
 	{
226 239
 		// New topic, new poll.
227
-		if (empty($topic))
228
-			isAllowedTo('poll_post');
240
+		if (empty($topic)) {
241
+					isAllowedTo('poll_post');
242
+		}
229 243
 		// This is an old topic - but it is yours!  Can you add to it?
230
-		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any'))
231
-			isAllowedTo('poll_add_own');
244
+		elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) {
245
+					isAllowedTo('poll_add_own');
246
+		}
232 247
 		// If you're not the owner, can you add to any poll?
233
-		else
234
-			isAllowedTo('poll_add_any');
248
+		else {
249
+					isAllowedTo('poll_add_any');
250
+		}
235 251
 
236 252
 		if (!empty($board))
237 253
 		{
@@ -240,8 +256,9 @@  discard block
 block discarded – undo
240 256
 			$guest_vote_enabled = in_array(-1, $allowedVoteGroups['allowed']);
241 257
 		}
242 258
 		// No board, so we'll have to check this again in Post2
243
-		else
244
-			$guest_vote_enabled = true;
259
+		else {
260
+					$guest_vote_enabled = true;
261
+		}
245 262
 
246 263
 		// Set up the poll options.
247 264
 		$context['poll_options'] = array(
@@ -267,8 +284,9 @@  discard block
 block discarded – undo
267 284
 	if ($context['make_event'])
268 285
 	{
269 286
 		// They might want to pick a board.
270
-		if (!isset($context['current_board']))
271
-			$context['current_board'] = 0;
287
+		if (!isset($context['current_board'])) {
288
+					$context['current_board'] = 0;
289
+		}
272 290
 
273 291
 		// Start loading up the event info.
274 292
 		$context['event'] = array();
@@ -282,10 +300,11 @@  discard block
 block discarded – undo
282 300
 		isAllowedTo('calendar_post');
283 301
 
284 302
 		// We want a fairly compact version of the time, but as close as possible to the user's settings.
285
-		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0]))
286
-			$time_string = '%k:%M';
287
-		else
288
-			$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
303
+		if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) {
304
+					$time_string = '%k:%M';
305
+		} else {
306
+					$time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]);
307
+		}
289 308
 
290 309
 		$js_time_string = str_replace(
291 310
 			array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r',      '%R',  '%S', '%T',    '%X'),
@@ -307,8 +326,7 @@  discard block
 block discarded – undo
307 326
 			require_once($sourcedir . '/Subs-Calendar.php');
308 327
 			$eventProperties = getEventProperties($context['event']['id']);
309 328
 			$context['event'] = array_merge($context['event'], $eventProperties);
310
-		}
311
-		else
329
+		} else
312 330
 		{
313 331
 			// Get the current event information.
314 332
 			require_once($sourcedir . '/Subs-Calendar.php');
@@ -316,10 +334,12 @@  discard block
 block discarded – undo
316 334
 			$context['event'] = array_merge($context['event'], $eventProperties);
317 335
 
318 336
 			// Make sure the year and month are in the valid range.
319
-			if ($context['event']['month'] < 1 || $context['event']['month'] > 12)
320
-				fatal_lang_error('invalid_month', false);
321
-			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear'])
322
-				fatal_lang_error('invalid_year', false);
337
+			if ($context['event']['month'] < 1 || $context['event']['month'] > 12) {
338
+							fatal_lang_error('invalid_month', false);
339
+			}
340
+			if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) {
341
+							fatal_lang_error('invalid_year', false);
342
+			}
323 343
 
324 344
 			$context['event']['categories'] = $board_list;
325 345
 		}
@@ -430,10 +450,11 @@  discard block
 block discarded – undo
430 450
 
431 451
 			if (!empty($context['new_replies']))
432 452
 			{
433
-				if ($context['new_replies'] == 1)
434
-					$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
435
-				else
436
-					$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
453
+				if ($context['new_replies'] == 1) {
454
+									$txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply'];
455
+				} else {
456
+									$txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']);
457
+				}
437 458
 
438 459
 				$post_errors[] = 'new_replies';
439 460
 
@@ -445,9 +466,9 @@  discard block
 block discarded – undo
445 466
 	// Get a response prefix (like 'Re:') in the default forum language.
446 467
 	if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
447 468
 	{
448
-		if ($language === $user_info['language'])
449
-			$context['response_prefix'] = $txt['response_prefix'];
450
-		else
469
+		if ($language === $user_info['language']) {
470
+					$context['response_prefix'] = $txt['response_prefix'];
471
+		} else
451 472
 		{
452 473
 			loadLanguage('index', $language, false);
453 474
 			$context['response_prefix'] = $txt['response_prefix'];
@@ -460,23 +481,26 @@  discard block
 block discarded – undo
460 481
 	// Do we have a body, but an error happened.
461 482
 	if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error']))
462 483
 	{
463
-		if (isset($_REQUEST['quickReply']))
464
-			$_REQUEST['message'] = $_REQUEST['quickReply'];
484
+		if (isset($_REQUEST['quickReply'])) {
485
+					$_REQUEST['message'] = $_REQUEST['quickReply'];
486
+		}
465 487
 
466 488
 		// Validate inputs.
467 489
 		if (empty($context['post_error']))
468 490
 		{
469 491
 			// This means they didn't click Post and get an error.
470 492
 			$really_previewing = true;
471
-		}
472
-		else
493
+		} else
473 494
 		{
474
-			if (!isset($_REQUEST['subject']))
475
-				$_REQUEST['subject'] = '';
476
-			if (!isset($_REQUEST['message']))
477
-				$_REQUEST['message'] = '';
478
-			if (!isset($_REQUEST['icon']))
479
-				$_REQUEST['icon'] = 'xx';
495
+			if (!isset($_REQUEST['subject'])) {
496
+							$_REQUEST['subject'] = '';
497
+			}
498
+			if (!isset($_REQUEST['message'])) {
499
+							$_REQUEST['message'] = '';
500
+			}
501
+			if (!isset($_REQUEST['icon'])) {
502
+							$_REQUEST['icon'] = 'xx';
503
+			}
480 504
 
481 505
 			// They are previewing if they asked to preview (i.e. came from quick reply).
482 506
 			$really_previewing = !empty($_POST['preview']);
@@ -492,8 +516,9 @@  discard block
 block discarded – undo
492 516
 		$form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES);
493 517
 
494 518
 		// Make sure the subject isn't too long - taking into account special characters.
495
-		if ($smcFunc['strlen']($form_subject) > 100)
496
-			$form_subject = $smcFunc['substr']($form_subject, 0, 100);
519
+		if ($smcFunc['strlen']($form_subject) > 100) {
520
+					$form_subject = $smcFunc['substr']($form_subject, 0, 100);
521
+		}
497 522
 
498 523
 		if (isset($_REQUEST['poll']))
499 524
 		{
@@ -505,8 +530,9 @@  discard block
 block discarded – undo
505 530
 			$_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']);
506 531
 			foreach ($_POST['options'] as $option)
507 532
 			{
508
-				if (trim($option) == '')
509
-					continue;
533
+				if (trim($option) == '') {
534
+									continue;
535
+				}
510 536
 
511 537
 				$context['choices'][] = array(
512 538
 					'id' => $choice_id++,
@@ -568,13 +594,14 @@  discard block
 block discarded – undo
568 594
 				$context['preview_subject'] = $form_subject;
569 595
 
570 596
 				censorText($context['preview_subject']);
597
+			} else {
598
+							$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
571 599
 			}
572
-			else
573
-				$context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>';
574 600
 
575 601
 			// Protect any CDATA blocks.
576
-			if (isset($_REQUEST['xml']))
577
-				$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
602
+			if (isset($_REQUEST['xml'])) {
603
+							$context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>'));
604
+			}
578 605
 		}
579 606
 
580 607
 		// Set up the checkboxes.
@@ -613,29 +640,32 @@  discard block
 block discarded – undo
613 640
 			);
614 641
 			// The message they were trying to edit was most likely deleted.
615 642
 			// @todo Change this error message?
616
-			if ($smcFunc['db_num_rows']($request) == 0)
617
-				fatal_lang_error('no_board', false);
643
+			if ($smcFunc['db_num_rows']($request) == 0) {
644
+							fatal_lang_error('no_board', false);
645
+			}
618 646
 			$row = $smcFunc['db_fetch_assoc']($request);
619 647
 
620 648
 			$attachment_stuff = array($row);
621
-			while ($row2 = $smcFunc['db_fetch_assoc']($request))
622
-				$attachment_stuff[] = $row2;
649
+			while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
650
+							$attachment_stuff[] = $row2;
651
+			}
623 652
 			$smcFunc['db_free_result']($request);
624 653
 
625 654
 			if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
626 655
 			{
627 656
 				// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
628
-				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
629
-					fatal_lang_error('modify_post_time_passed', false);
630
-				elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
631
-					isAllowedTo('modify_replies');
632
-				else
633
-					isAllowedTo('modify_own');
657
+				if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
658
+									fatal_lang_error('modify_post_time_passed', false);
659
+				} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
660
+									isAllowedTo('modify_replies');
661
+				} else {
662
+									isAllowedTo('modify_own');
663
+				}
664
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
665
+							isAllowedTo('modify_replies');
666
+			} else {
667
+							isAllowedTo('modify_any');
634 668
 			}
635
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
636
-				isAllowedTo('modify_replies');
637
-			else
638
-				isAllowedTo('modify_any');
639 669
 
640 670
 			if ($context['can_announce'] && !empty($row['id_action']))
641 671
 			{
@@ -659,8 +689,9 @@  discard block
 block discarded – undo
659 689
 
660 690
 				while ($row = $smcFunc['db_fetch_assoc']($request))
661 691
 				{
662
-					if ($row['filesize'] <= 0)
663
-						continue;
692
+					if ($row['filesize'] <= 0) {
693
+											continue;
694
+					}
664 695
 					$context['current_attachments'][$row['id_attach']] = array(
665 696
 						'name' => $smcFunc['htmlspecialchars']($row['filename']),
666 697
 						'size' => $row['filesize'],
@@ -730,29 +761,32 @@  discard block
 block discarded – undo
730 761
 			)
731 762
 		);
732 763
 		// The message they were trying to edit was most likely deleted.
733
-		if ($smcFunc['db_num_rows']($request) == 0)
734
-			fatal_lang_error('no_message', false);
764
+		if ($smcFunc['db_num_rows']($request) == 0) {
765
+					fatal_lang_error('no_message', false);
766
+		}
735 767
 		$row = $smcFunc['db_fetch_assoc']($request);
736 768
 
737 769
 		$attachment_stuff = array($row);
738
-		while ($row2 = $smcFunc['db_fetch_assoc']($request))
739
-			$attachment_stuff[] = $row2;
770
+		while ($row2 = $smcFunc['db_fetch_assoc']($request)) {
771
+					$attachment_stuff[] = $row2;
772
+		}
740 773
 		$smcFunc['db_free_result']($request);
741 774
 
742 775
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
743 776
 		{
744 777
 			// Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public.
745
-			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
746
-				fatal_lang_error('modify_post_time_passed', false);
747
-			elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own'))
748
-				isAllowedTo('modify_replies');
749
-			else
750
-				isAllowedTo('modify_own');
778
+			if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
779
+							fatal_lang_error('modify_post_time_passed', false);
780
+			} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) {
781
+							isAllowedTo('modify_replies');
782
+			} else {
783
+							isAllowedTo('modify_own');
784
+			}
785
+		} elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) {
786
+					isAllowedTo('modify_replies');
787
+		} else {
788
+					isAllowedTo('modify_any');
751 789
 		}
752
-		elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any'))
753
-			isAllowedTo('modify_replies');
754
-		else
755
-			isAllowedTo('modify_any');
756 790
 
757 791
 		if ($context['can_announce'] && !empty($row['id_action']))
758 792
 		{
@@ -779,15 +813,17 @@  discard block
 block discarded – undo
779 813
 		$context['icon'] = $row['icon'];
780 814
 
781 815
 		// Show an "approve" box if the user can approve it, and the message isn't approved.
782
-		if (!$row['approved'] && !$context['show_approval'])
783
-			$context['show_approval'] = allowedTo('approve_posts');
816
+		if (!$row['approved'] && !$context['show_approval']) {
817
+					$context['show_approval'] = allowedTo('approve_posts');
818
+		}
784 819
 
785 820
 		// Sort the attachments so they are in the order saved
786 821
 		$temp = array();
787 822
 		foreach ($attachment_stuff as $attachment)
788 823
 		{
789
-			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable']))
790
-				$temp[$attachment['id_attach']] = $attachment;
824
+			if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) {
825
+							$temp[$attachment['id_attach']] = $attachment;
826
+			}
791 827
 		}
792 828
 		ksort($temp);
793 829
 
@@ -848,14 +884,16 @@  discard block
 block discarded – undo
848 884
 					'is_approved' => 1,
849 885
 				)
850 886
 			);
851
-			if ($smcFunc['db_num_rows']($request) == 0)
852
-				fatal_lang_error('quoted_post_deleted', false);
887
+			if ($smcFunc['db_num_rows']($request) == 0) {
888
+							fatal_lang_error('quoted_post_deleted', false);
889
+			}
853 890
 			list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request);
854 891
 			$smcFunc['db_free_result']($request);
855 892
 
856 893
 			// Add 'Re: ' to the front of the quoted subject.
857
-			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
858
-				$form_subject = $context['response_prefix'] . $form_subject;
894
+			if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
895
+							$form_subject = $context['response_prefix'] . $form_subject;
896
+			}
859 897
 
860 898
 			// Censor the message and subject.
861 899
 			censorText($form_message);
@@ -868,10 +906,11 @@  discard block
 block discarded – undo
868 906
 				for ($i = 0, $n = count($parts); $i < $n; $i++)
869 907
 				{
870 908
 					// It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat.
871
-					if ($i % 4 == 0)
872
-						$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
909
+					if ($i % 4 == 0) {
910
+											$parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m)
873 911
 						{
874 912
 							return '[html]' . preg_replace('~<br\s?/?' . '>~i', '&lt;br /&gt;<br>', "$m[1]") . '[/html]';
913
+					}
875 914
 						}, $parts[$i]);
876 915
 				}
877 916
 				$form_message = implode('', $parts);
@@ -880,8 +919,9 @@  discard block
 block discarded – undo
880 919
 			$form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message);
881 920
 
882 921
 			// Remove any nested quotes, if necessary.
883
-			if (!empty($modSettings['removeNestedQuotes']))
884
-				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
922
+			if (!empty($modSettings['removeNestedQuotes'])) {
923
+							$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
924
+			}
885 925
 
886 926
 			// Add a quote string on the front and end.
887 927
 			$form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -893,15 +933,15 @@  discard block
 block discarded – undo
893 933
 			$form_subject = $first_subject;
894 934
 
895 935
 			// Add 'Re: ' to the front of the subject.
896
-			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0)
897
-				$form_subject = $context['response_prefix'] . $form_subject;
936
+			if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) {
937
+							$form_subject = $context['response_prefix'] . $form_subject;
938
+			}
898 939
 
899 940
 			// Censor the subject.
900 941
 			censorText($form_subject);
901 942
 
902 943
 			$form_message = '';
903
-		}
904
-		else
944
+		} else
905 945
 		{
906 946
 			$form_subject = isset($_GET['subject']) ? $_GET['subject'] : '';
907 947
 			$form_message = '';
@@ -920,13 +960,15 @@  discard block
 block discarded – undo
920 960
 		if (isset($_REQUEST['msg']))
921 961
 		{
922 962
 			$context['attachments']['quantity'] = count($context['current_attachments']);
923
-			foreach ($context['current_attachments'] as $attachment)
924
-				$context['attachments']['total_size'] += $attachment['size'];
963
+			foreach ($context['current_attachments'] as $attachment) {
964
+							$context['attachments']['total_size'] += $attachment['size'];
965
+			}
925 966
 		}
926 967
 
927 968
 		// A bit of house keeping first.
928
-		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1)
929
-			unset($_SESSION['temp_attachments']);
969
+		if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) {
970
+					unset($_SESSION['temp_attachments']);
971
+		}
930 972
 
931 973
 		if (!empty($_SESSION['temp_attachments']))
932 974
 		{
@@ -935,9 +977,10 @@  discard block
 block discarded – undo
935 977
 			{
936 978
 				foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
937 979
 				{
938
-					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
939
-						if (file_exists($attachment['tmp_name']))
980
+					if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) {
981
+											if (file_exists($attachment['tmp_name']))
940 982
 							unlink($attachment['tmp_name']);
983
+					}
941 984
 				}
942 985
 				$post_errors[] = 'temp_attachments_gone';
943 986
 				$_SESSION['temp_attachments'] = array();
@@ -951,8 +994,9 @@  discard block
 block discarded – undo
951 994
 					// See if any files still exist before showing the warning message and the files attached.
952 995
 					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
953 996
 					{
954
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
955
-							continue;
997
+						if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
998
+													continue;
999
+						}
956 1000
 
957 1001
 						if (file_exists($attachment['tmp_name']))
958 1002
 						{
@@ -962,20 +1006,21 @@  discard block
 block discarded – undo
962 1006
 							break;
963 1007
 						}
964 1008
 					}
965
-				}
966
-				else
1009
+				} else
967 1010
 				{
968 1011
 					// Since, they don't belong here. Let's inform the user that they exist..
969
-					if (!empty($topic))
970
-						$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
971
-					else
972
-						$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1012
+					if (!empty($topic)) {
1013
+											$delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp';
1014
+					} else {
1015
+											$delete_url = $scripturl . '?action=post' . (!empty($board) ? ';board=' . $board : '') . ';delete_temp';
1016
+					}
973 1017
 
974 1018
 					// Compile a list of the files to show the user.
975 1019
 					$file_list = array();
976
-					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
977
-						if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
1020
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) {
1021
+											if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false)
978 1022
 							$file_list[] = $attachment['name'];
1023
+					}
979 1024
 
980 1025
 					$_SESSION['temp_attachments']['post']['files'] = $file_list;
981 1026
 					$file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>';
@@ -987,8 +1032,7 @@  discard block
 block discarded – undo
987 1032
 
988 1033
 						$post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list));
989 1034
 						$context['ignore_temp_attachments'] = true;
990
-					}
991
-					else
1035
+					} else
992 1036
 					{
993 1037
 						$post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list));
994 1038
 						$context['ignore_temp_attachments'] = true;
@@ -996,16 +1040,19 @@  discard block
 block discarded – undo
996 1040
 				}
997 1041
 			}
998 1042
 
999
-			if (!empty($context['we_are_history']))
1000
-				$post_errors[] = $context['we_are_history'];
1043
+			if (!empty($context['we_are_history'])) {
1044
+							$post_errors[] = $context['we_are_history'];
1045
+			}
1001 1046
 
1002 1047
 			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1003 1048
 			{
1004
-				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files']))
1005
-					break;
1049
+				if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) {
1050
+									break;
1051
+				}
1006 1052
 
1007
-				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1008
-					continue;
1053
+				if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
1054
+									continue;
1055
+				}
1009 1056
 
1010 1057
 				if ($attachID == 'initial_error')
1011 1058
 				{
@@ -1020,15 +1067,17 @@  discard block
 block discarded – undo
1020 1067
 				{
1021 1068
 					$txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : '';
1022 1069
 					$txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">';
1023
-					foreach ($attachment['errors'] as $error)
1024
-						$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1070
+					foreach ($attachment['errors'] as $error) {
1071
+											$txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >';
1072
+					}
1025 1073
 					$txt['error_attach_errors'] .= '</div>';
1026 1074
 					$post_errors[] = 'attach_errors';
1027 1075
 
1028 1076
 					// Take out the trash.
1029 1077
 					unset($_SESSION['temp_attachments'][$attachID]);
1030
-					if (file_exists($attachment['tmp_name']))
1031
-						unlink($attachment['tmp_name']);
1078
+					if (file_exists($attachment['tmp_name'])) {
1079
+											unlink($attachment['tmp_name']);
1080
+					}
1032 1081
 					continue;
1033 1082
 				}
1034 1083
 
@@ -1041,8 +1090,9 @@  discard block
 block discarded – undo
1041 1090
 
1042 1091
 				$context['attachments']['quantity']++;
1043 1092
 				$context['attachments']['total_size'] += $attachment['size'];
1044
-				if (!isset($context['files_in_session_warning']))
1045
-					$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1093
+				if (!isset($context['files_in_session_warning'])) {
1094
+									$context['files_in_session_warning'] = $txt['attached_files_in_session'];
1095
+				}
1046 1096
 
1047 1097
 				$context['current_attachments'][$attachID] = array(
1048 1098
 					'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>',
@@ -1070,8 +1120,9 @@  discard block
 block discarded – undo
1070 1120
 	}
1071 1121
 
1072 1122
 	// If they came from quick reply, and have to enter verification details, give them some notice.
1073
-	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification']))
1074
-		$post_errors[] = 'need_qr_verification';
1123
+	if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) {
1124
+			$post_errors[] = 'need_qr_verification';
1125
+	}
1075 1126
 
1076 1127
 	/*
1077 1128
 	 * There are two error types: serious and minor. Serious errors
@@ -1088,52 +1139,56 @@  discard block
 block discarded – undo
1088 1139
 	{
1089 1140
 		loadLanguage('Errors');
1090 1141
 		$context['error_type'] = 'minor';
1091
-		foreach ($post_errors as $post_error)
1092
-			if (is_array($post_error))
1142
+		foreach ($post_errors as $post_error) {
1143
+					if (is_array($post_error))
1093 1144
 			{
1094 1145
 				$post_error_id = $post_error[0];
1146
+		}
1095 1147
 				$context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]);
1096 1148
 
1097 1149
 				// If it's not a minor error flag it as such.
1098
-				if (!in_array($post_error_id, $minor_errors))
1099
-					$context['error_type'] = 'serious';
1100
-			}
1101
-			else
1150
+				if (!in_array($post_error_id, $minor_errors)) {
1151
+									$context['error_type'] = 'serious';
1152
+				}
1153
+			} else
1102 1154
 			{
1103 1155
 				$context['post_error'][$post_error] = $txt['error_' . $post_error];
1104 1156
 
1105 1157
 				// If it's not a minor error flag it as such.
1106
-				if (!in_array($post_error, $minor_errors))
1107
-					$context['error_type'] = 'serious';
1158
+				if (!in_array($post_error, $minor_errors)) {
1159
+									$context['error_type'] = 'serious';
1160
+				}
1108 1161
 			}
1109 1162
 	}
1110 1163
 
1111 1164
 	// What are you doing? Posting a poll, modifying, previewing, new post, or reply...
1112
-	if (isset($_REQUEST['poll']))
1113
-		$context['page_title'] = $txt['new_poll'];
1114
-	elseif ($context['make_event'])
1115
-		$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1116
-	elseif (isset($_REQUEST['msg']))
1117
-		$context['page_title'] = $txt['modify_msg'];
1118
-	elseif (isset($_REQUEST['subject'], $context['preview_subject']))
1119
-		$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1120
-	elseif (empty($topic))
1121
-		$context['page_title'] = $txt['start_new_topic'];
1122
-	else
1123
-		$context['page_title'] = $txt['post_reply'];
1165
+	if (isset($_REQUEST['poll'])) {
1166
+			$context['page_title'] = $txt['new_poll'];
1167
+	} elseif ($context['make_event']) {
1168
+			$context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit'];
1169
+	} elseif (isset($_REQUEST['msg'])) {
1170
+			$context['page_title'] = $txt['modify_msg'];
1171
+	} elseif (isset($_REQUEST['subject'], $context['preview_subject'])) {
1172
+			$context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']);
1173
+	} elseif (empty($topic)) {
1174
+			$context['page_title'] = $txt['start_new_topic'];
1175
+	} else {
1176
+			$context['page_title'] = $txt['post_reply'];
1177
+	}
1124 1178
 
1125 1179
 	// Build the link tree.
1126
-	if (empty($topic))
1127
-		$context['linktree'][] = array(
1180
+	if (empty($topic)) {
1181
+			$context['linktree'][] = array(
1128 1182
 			'name' => '<em>' . $txt['start_new_topic'] . '</em>'
1129 1183
 		);
1130
-	else
1131
-		$context['linktree'][] = array(
1184
+	} else {
1185
+			$context['linktree'][] = array(
1132 1186
 			'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'],
1133 1187
 			'name' => $form_subject,
1134 1188
 			'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>',
1135 1189
 			'extra_after' => '<span><strong class="nav">)</strong></span>'
1136 1190
 		);
1191
+	}
1137 1192
 
1138 1193
 	$context['subject'] = addcslashes($form_subject, '"');
1139 1194
 	$context['message'] = str_replace(array('"', '<', '>', '&nbsp;'), array('&quot;', '&lt;', '&gt;', ' '), $form_message);
@@ -1177,8 +1232,9 @@  discard block
 block discarded – undo
1177 1232
 	// Message icons - customized icons are off?
1178 1233
 	$context['icons'] = getMessageIcons(!empty($board) ? $board : 0);
1179 1234
 
1180
-	if (!empty($context['icons']))
1181
-		$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1235
+	if (!empty($context['icons'])) {
1236
+			$context['icons'][count($context['icons']) - 1]['is_last'] = true;
1237
+	}
1182 1238
 
1183 1239
 	// Are we starting a poll? if set the poll icon as selected if its available
1184 1240
 	if (isset($_REQUEST['poll']))
@@ -1198,8 +1254,9 @@  discard block
 block discarded – undo
1198 1254
 	for ($i = 0, $n = count($context['icons']); $i < $n; $i++)
1199 1255
 	{
1200 1256
 		$context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value'];
1201
-		if ($context['icons'][$i]['selected'])
1202
-			$context['icon_url'] = $context['icons'][$i]['url'];
1257
+		if ($context['icons'][$i]['selected']) {
1258
+					$context['icon_url'] = $context['icons'][$i]['url'];
1259
+		}
1203 1260
 	}
1204 1261
 	if (empty($context['icon_url']))
1205 1262
 	{
@@ -1213,8 +1270,9 @@  discard block
 block discarded – undo
1213 1270
 		));
1214 1271
 	}
1215 1272
 
1216
-	if (!empty($topic) && !empty($modSettings['topicSummaryPosts']))
1217
-		getTopic();
1273
+	if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) {
1274
+			getTopic();
1275
+	}
1218 1276
 
1219 1277
 	// If the user can post attachments prepare the warning labels.
1220 1278
 	if ($context['can_post_attachment'])
@@ -1225,12 +1283,13 @@  discard block
 block discarded – undo
1225 1283
 		$context['attachment_restrictions'] = array();
1226 1284
 		$context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', '));
1227 1285
 		$attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit');
1228
-		foreach ($attachmentRestrictionTypes as $type)
1229
-			if (!empty($modSettings[$type]))
1286
+		foreach ($attachmentRestrictionTypes as $type) {
1287
+					if (!empty($modSettings[$type]))
1230 1288
 			{
1231 1289
 				// Show the max number of attachments if not 0.
1232 1290
 				if ($type == 'attachmentNumPerPostLimit')
1233 1291
 					$context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']);
1292
+		}
1234 1293
 			}
1235 1294
 	}
1236 1295
 
@@ -1264,8 +1323,8 @@  discard block
 block discarded – undo
1264 1323
 
1265 1324
 	if (!empty($context['current_attachments']))
1266 1325
 	{
1267
-		foreach ($context['current_attachments'] as $key => $mock)
1268
-			addInlineJavaScript('
1326
+		foreach ($context['current_attachments'] as $key => $mock) {
1327
+					addInlineJavaScript('
1269 1328
 	current_attachments.push({
1270 1329
 		name: '. JavaScriptEscape($mock['name']) . ',
1271 1330
 		size: '. $mock['size'] . ',
@@ -1274,6 +1333,7 @@  discard block
 block discarded – undo
1274 1333
 		type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ',
1275 1334
 		thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . '
1276 1335
 	});');
1336
+		}
1277 1337
 	}
1278 1338
 
1279 1339
 	// File Upload.
@@ -1348,9 +1408,10 @@  discard block
 block discarded – undo
1348 1408
 			$context['posting_fields']['board']['dd'] .= '
1349 1409
 							<optgroup label="' . $category['name'] . '">';
1350 1410
 
1351
-			foreach ($category['boards'] as $brd)
1352
-				$context['posting_fields']['board']['dd'] .= '
1411
+			foreach ($category['boards'] as $brd) {
1412
+							$context['posting_fields']['board']['dd'] .= '
1353 1413
 								<option value="' . $brd['id'] . '"' . ($brd['selected'] ? ' selected' : '') . '>' . ($brd['child_level'] > 0 ? str_repeat('==', $brd['child_level'] - 1) . '=&gt;' : '') . ' ' . $brd['name'] . '</option>';
1414
+			}
1354 1415
 
1355 1416
 			$context['posting_fields']['board']['dd'] .= '
1356 1417
 							</optgroup>';
@@ -1381,8 +1442,9 @@  discard block
 block discarded – undo
1381 1442
 
1382 1443
 
1383 1444
 	// Finally, load the template.
1384
-	if (!isset($_REQUEST['xml']))
1385
-		loadTemplate('Post');
1445
+	if (!isset($_REQUEST['xml'])) {
1446
+			loadTemplate('Post');
1447
+	}
1386 1448
 
1387 1449
 	call_integration_hook('integrate_post_end');
1388 1450
 }
@@ -1403,13 +1465,14 @@  discard block
 block discarded – undo
1403 1465
 	// Sneaking off, are we?
1404 1466
 	if (empty($_POST) && empty($topic))
1405 1467
 	{
1406
-		if (empty($_SERVER['CONTENT_LENGTH']))
1407
-			redirectexit('action=post;board=' . $board . '.0');
1408
-		else
1409
-			fatal_lang_error('post_upload_error', false);
1468
+		if (empty($_SERVER['CONTENT_LENGTH'])) {
1469
+					redirectexit('action=post;board=' . $board . '.0');
1470
+		} else {
1471
+					fatal_lang_error('post_upload_error', false);
1472
+		}
1473
+	} elseif (empty($_POST) && !empty($topic)) {
1474
+			redirectexit('action=post;topic=' . $topic . '.0');
1410 1475
 	}
1411
-	elseif (empty($_POST) && !empty($topic))
1412
-		redirectexit('action=post;topic=' . $topic . '.0');
1413 1476
 
1414 1477
 	// No need!
1415 1478
 	$context['robot_no_index'] = true;
@@ -1421,8 +1484,9 @@  discard block
 block discarded – undo
1421 1484
 	$post_errors = array();
1422 1485
 
1423 1486
 	// If the session has timed out, let the user re-submit their form.
1424
-	if (checkSession('post', '', false) != '')
1425
-		$post_errors[] = 'session_timeout';
1487
+	if (checkSession('post', '', false) != '') {
1488
+			$post_errors[] = 'session_timeout';
1489
+	}
1426 1490
 
1427 1491
 	// Wrong verification code?
1428 1492
 	if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1)))
@@ -1432,33 +1496,38 @@  discard block
 block discarded – undo
1432 1496
 			'id' => 'post',
1433 1497
 		);
1434 1498
 		$context['require_verification'] = create_control_verification($verificationOptions, true);
1435
-		if (is_array($context['require_verification']))
1436
-			$post_errors = array_merge($post_errors, $context['require_verification']);
1499
+		if (is_array($context['require_verification'])) {
1500
+					$post_errors = array_merge($post_errors, $context['require_verification']);
1501
+		}
1437 1502
 	}
1438 1503
 
1439 1504
 	require_once($sourcedir . '/Subs-Post.php');
1440 1505
 	loadLanguage('Post');
1441 1506
 
1442 1507
 	// Drafts enabled and needed?
1443
-	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft'])))
1444
-		require_once($sourcedir . '/Drafts.php');
1508
+	if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) {
1509
+			require_once($sourcedir . '/Drafts.php');
1510
+	}
1445 1511
 
1446 1512
 	// First check to see if they are trying to delete any current attachments.
1447 1513
 	if (isset($_POST['attach_del']))
1448 1514
 	{
1449 1515
 		$keep_temp = array();
1450 1516
 		$keep_ids = array();
1451
-		foreach ($_POST['attach_del'] as $dummy)
1452
-			if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1517
+		foreach ($_POST['attach_del'] as $dummy) {
1518
+					if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false)
1453 1519
 				$keep_temp[] = $dummy;
1454
-			else
1455
-				$keep_ids[] = (int) $dummy;
1520
+		}
1521
+			else {
1522
+							$keep_ids[] = (int) $dummy;
1523
+			}
1456 1524
 
1457
-		if (isset($_SESSION['temp_attachments']))
1458
-			foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1525
+		if (isset($_SESSION['temp_attachments'])) {
1526
+					foreach ($_SESSION['temp_attachments'] as $attachID => $attachment)
1459 1527
 			{
1460 1528
 				if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1461 1529
 					continue;
1530
+		}
1462 1531
 
1463 1532
 				unset($_SESSION['temp_attachments'][$attachID]);
1464 1533
 				unlink($attachment['tmp_name']);
@@ -1490,8 +1559,9 @@  discard block
 block discarded – undo
1490 1559
 	{
1491 1560
 		require_once($sourcedir . '/ManageAttachments.php');
1492 1561
 
1493
-		foreach ($_SESSION['already_attached'] as $attachID => $attachment)
1494
-			removeAttachments(array('id_attach' => $attachID));
1562
+		foreach ($_SESSION['already_attached'] as $attachID => $attachment) {
1563
+					removeAttachments(array('id_attach' => $attachID));
1564
+		}
1495 1565
 
1496 1566
 		unset($_SESSION['already_attached']);
1497 1567
 
@@ -1514,12 +1584,14 @@  discard block
 block discarded – undo
1514 1584
 		$smcFunc['db_free_result']($request);
1515 1585
 
1516 1586
 		// Though the topic should be there, it might have vanished.
1517
-		if (!is_array($topic_info))
1518
-			fatal_lang_error('topic_doesnt_exist', 404);
1587
+		if (!is_array($topic_info)) {
1588
+					fatal_lang_error('topic_doesnt_exist', 404);
1589
+		}
1519 1590
 
1520 1591
 		// Did this topic suddenly move? Just checking...
1521
-		if ($topic_info['id_board'] != $board)
1522
-			fatal_lang_error('not_a_topic');
1592
+		if ($topic_info['id_board'] != $board) {
1593
+					fatal_lang_error('not_a_topic');
1594
+		}
1523 1595
 
1524 1596
 		// Do the permissions and approval stuff...
1525 1597
 		$becomesApproved = true;
@@ -1542,49 +1614,50 @@  discard block
 block discarded – undo
1542 1614
 	if (!empty($topic) && !isset($_REQUEST['msg']))
1543 1615
 	{
1544 1616
 		// Don't allow a post if it's locked.
1545
-		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board'))
1546
-			fatal_lang_error('topic_locked', false);
1617
+		if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) {
1618
+					fatal_lang_error('topic_locked', false);
1619
+		}
1547 1620
 
1548 1621
 		// Sorry, multiple polls aren't allowed... yet.  You should stop giving me ideas :P.
1549
-		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0)
1550
-			unset($_REQUEST['poll']);
1551
-
1552
-		elseif ($topic_info['id_member_started'] != $user_info['id'])
1553
-		{
1554
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any'))
1555
-				$becomesApproved = false;
1556
-
1557
-			else
1558
-				isAllowedTo('post_reply_any');
1559
-		}
1560
-		elseif (!allowedTo('post_reply_any'))
1622
+		if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) {
1623
+					unset($_REQUEST['poll']);
1624
+		} elseif ($topic_info['id_member_started'] != $user_info['id'])
1625
+		{
1626
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) {
1627
+							$becomesApproved = false;
1628
+			} else {
1629
+							isAllowedTo('post_reply_any');
1630
+			}
1631
+		} elseif (!allowedTo('post_reply_any'))
1561 1632
 		{
1562
-			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own'))
1563
-				$becomesApproved = false;
1564
-
1565
-			else
1566
-				isAllowedTo('post_reply_own');
1633
+			if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) {
1634
+							$becomesApproved = false;
1635
+			} else {
1636
+							isAllowedTo('post_reply_own');
1637
+			}
1567 1638
 		}
1568 1639
 
1569 1640
 		if (isset($_POST['lock']))
1570 1641
 		{
1571 1642
 			// Nothing is changed to the lock.
1572
-			if (empty($topic_info['locked']) == empty($_POST['lock']))
1573
-				unset($_POST['lock']);
1643
+			if (empty($topic_info['locked']) == empty($_POST['lock'])) {
1644
+							unset($_POST['lock']);
1645
+			}
1574 1646
 
1575 1647
 			// You're have no permission to lock this topic.
1576
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1577
-				unset($_POST['lock']);
1648
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1649
+							unset($_POST['lock']);
1650
+			}
1578 1651
 
1579 1652
 			// You are allowed to (un)lock your own topic only.
1580 1653
 			elseif (!allowedTo('lock_any'))
1581 1654
 			{
1582 1655
 				// You cannot override a moderator lock.
1583
-				if ($topic_info['locked'] == 1)
1584
-					unset($_POST['lock']);
1585
-
1586
-				else
1587
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1656
+				if ($topic_info['locked'] == 1) {
1657
+									unset($_POST['lock']);
1658
+				} else {
1659
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1660
+				}
1588 1661
 			}
1589 1662
 			// Hail mighty moderator, (un)lock this topic immediately.
1590 1663
 			else
@@ -1592,19 +1665,21 @@  discard block
 block discarded – undo
1592 1665
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1593 1666
 
1594 1667
 				// Did someone (un)lock this while you were posting?
1595
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1596
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1668
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1669
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1670
+				}
1597 1671
 			}
1598 1672
 		}
1599 1673
 
1600 1674
 		// So you wanna (un)sticky this...let's see.
1601
-		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky')))
1602
-			unset($_POST['sticky']);
1603
-		elseif (isset($_POST['sticky']))
1675
+		if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) {
1676
+					unset($_POST['sticky']);
1677
+		} elseif (isset($_POST['sticky']))
1604 1678
 		{
1605 1679
 			// Did someone (un)sticky this while you were posting?
1606
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1607
-				$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1680
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1681
+							$post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky';
1682
+			}
1608 1683
 		}
1609 1684
 
1610 1685
 		// If drafts are enabled, then pass this off
@@ -1631,26 +1706,31 @@  discard block
 block discarded – undo
1631 1706
 
1632 1707
 		// Do like, the permissions, for safety and stuff...
1633 1708
 		$becomesApproved = true;
1634
-		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics'))
1635
-			$becomesApproved = false;
1636
-		else
1637
-			isAllowedTo('post_new');
1709
+		if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) {
1710
+					$becomesApproved = false;
1711
+		} else {
1712
+					isAllowedTo('post_new');
1713
+		}
1638 1714
 
1639 1715
 		if (isset($_POST['lock']))
1640 1716
 		{
1641 1717
 			// New topics are by default not locked.
1642
-			if (empty($_POST['lock']))
1643
-				unset($_POST['lock']);
1718
+			if (empty($_POST['lock'])) {
1719
+							unset($_POST['lock']);
1720
+			}
1644 1721
 			// Besides, you need permission.
1645
-			elseif (!allowedTo(array('lock_any', 'lock_own')))
1646
-				unset($_POST['lock']);
1722
+			elseif (!allowedTo(array('lock_any', 'lock_own'))) {
1723
+							unset($_POST['lock']);
1724
+			}
1647 1725
 			// A moderator-lock (1) can override a user-lock (2).
1648
-			else
1649
-				$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1726
+			else {
1727
+							$_POST['lock'] = allowedTo('lock_any') ? 1 : 2;
1728
+			}
1650 1729
 		}
1651 1730
 
1652
-		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky')))
1653
-			unset($_POST['sticky']);
1731
+		if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) {
1732
+					unset($_POST['sticky']);
1733
+		}
1654 1734
 
1655 1735
 		// Saving your new topic as a draft first?
1656 1736
 		if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft']))
@@ -1675,31 +1755,37 @@  discard block
 block discarded – undo
1675 1755
 				'id_msg' => $_REQUEST['msg'],
1676 1756
 			)
1677 1757
 		);
1678
-		if ($smcFunc['db_num_rows']($request) == 0)
1679
-			fatal_lang_error('cant_find_messages', false);
1758
+		if ($smcFunc['db_num_rows']($request) == 0) {
1759
+					fatal_lang_error('cant_find_messages', false);
1760
+		}
1680 1761
 		$row = $smcFunc['db_fetch_assoc']($request);
1681 1762
 		$smcFunc['db_free_result']($request);
1682 1763
 
1683
-		if (!empty($topic_info['locked']) && !allowedTo('moderate_board'))
1684
-			fatal_lang_error('topic_locked', false);
1764
+		if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) {
1765
+					fatal_lang_error('topic_locked', false);
1766
+		}
1685 1767
 
1686 1768
 		if (isset($_POST['lock']))
1687 1769
 		{
1688 1770
 			// Nothing changes to the lock status.
1689
-			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked'])))
1690
-				unset($_POST['lock']);
1771
+			if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) {
1772
+							unset($_POST['lock']);
1773
+			}
1691 1774
 			// You're simply not allowed to (un)lock this.
1692
-			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started']))
1693
-				unset($_POST['lock']);
1775
+			elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) {
1776
+							unset($_POST['lock']);
1777
+			}
1694 1778
 			// You're only allowed to lock your own topics.
1695 1779
 			elseif (!allowedTo('lock_any'))
1696 1780
 			{
1697 1781
 				// You're not allowed to break a moderator's lock.
1698
-				if ($topic_info['locked'] == 1)
1699
-					unset($_POST['lock']);
1782
+				if ($topic_info['locked'] == 1) {
1783
+									unset($_POST['lock']);
1784
+				}
1700 1785
 				// Lock it with a soft lock or unlock it.
1701
-				else
1702
-					$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1786
+				else {
1787
+									$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
1788
+				}
1703 1789
 			}
1704 1790
 			// You must be the moderator.
1705 1791
 			else
@@ -1707,44 +1793,46 @@  discard block
 block discarded – undo
1707 1793
 				$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
1708 1794
 
1709 1795
 				// Did someone (un)lock this while you were posting?
1710
-				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked'])
1711
-					$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1796
+				if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) {
1797
+									$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked';
1798
+				}
1712 1799
 			}
1713 1800
 		}
1714 1801
 
1715 1802
 		// Change the sticky status of this topic?
1716
-		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky']))
1717
-			unset($_POST['sticky']);
1718
-		elseif (isset($_POST['sticky']))
1803
+		if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) {
1804
+					unset($_POST['sticky']);
1805
+		} elseif (isset($_POST['sticky']))
1719 1806
 		{
1720 1807
 			// Did someone (un)sticky this while you were posting?
1721
-			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky'])
1722
-				$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1808
+			if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) {
1809
+							$post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied';
1810
+			}
1723 1811
 		}
1724 1812
 
1725 1813
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
1726 1814
 		{
1727
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
1728
-				fatal_lang_error('modify_post_time_passed', false);
1729
-			elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
1730
-				isAllowedTo('modify_replies');
1731
-			else
1732
-				isAllowedTo('modify_own');
1733
-		}
1734
-		elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1815
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
1816
+							fatal_lang_error('modify_post_time_passed', false);
1817
+			} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
1818
+							isAllowedTo('modify_replies');
1819
+			} else {
1820
+							isAllowedTo('modify_own');
1821
+			}
1822
+		} elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
1735 1823
 		{
1736 1824
 			isAllowedTo('modify_replies');
1737 1825
 
1738 1826
 			// If you're modifying a reply, I say it better be logged...
1739 1827
 			$moderationAction = true;
1740
-		}
1741
-		else
1828
+		} else
1742 1829
 		{
1743 1830
 			isAllowedTo('modify_any');
1744 1831
 
1745 1832
 			// Log it, assuming you're not modifying your own post.
1746
-			if ($row['id_member'] != $user_info['id'])
1747
-				$moderationAction = true;
1833
+			if ($row['id_member'] != $user_info['id']) {
1834
+							$moderationAction = true;
1835
+			}
1748 1836
 		}
1749 1837
 
1750 1838
 		// If drafts are enabled, then lets send this off to save
@@ -1783,20 +1871,24 @@  discard block
 block discarded – undo
1783 1871
 		$_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']);
1784 1872
 		$_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
1785 1873
 
1786
-		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_')
1787
-			$post_errors[] = 'no_name';
1788
-		if ($smcFunc['strlen']($_POST['guestname']) > 25)
1789
-			$post_errors[] = 'long_name';
1874
+		if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') {
1875
+					$post_errors[] = 'no_name';
1876
+		}
1877
+		if ($smcFunc['strlen']($_POST['guestname']) > 25) {
1878
+					$post_errors[] = 'long_name';
1879
+		}
1790 1880
 
1791 1881
 		if (empty($modSettings['guest_post_no_email']))
1792 1882
 		{
1793 1883
 			// Only check if they changed it!
1794 1884
 			if (!isset($row) || $row['poster_email'] != $_POST['email'])
1795 1885
 			{
1796
-				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == ''))
1797
-					$post_errors[] = 'no_email';
1798
-				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
1799
-					$post_errors[] = 'bad_email';
1886
+				if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) {
1887
+									$post_errors[] = 'no_email';
1888
+				}
1889
+				if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
1890
+									$post_errors[] = 'bad_email';
1891
+				}
1800 1892
 			}
1801 1893
 
1802 1894
 			// Now make sure this email address is not banned from posting.
@@ -1812,81 +1904,95 @@  discard block
 block discarded – undo
1812 1904
 	}
1813 1905
 
1814 1906
 	// Coming from the quickReply?
1815
-	if (isset($_POST['quickReply']))
1816
-		$_POST['message'] = $_POST['quickReply'];
1907
+	if (isset($_POST['quickReply'])) {
1908
+			$_POST['message'] = $_POST['quickReply'];
1909
+	}
1817 1910
 
1818 1911
 	// Check the subject and message.
1819
-	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '')
1820
-		$post_errors[] = 'no_subject';
1821
-	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '')
1822
-		$post_errors[] = 'no_message';
1823
-	elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
1824
-		$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1825
-	else
1912
+	if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') {
1913
+			$post_errors[] = 'no_subject';
1914
+	}
1915
+	if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') {
1916
+			$post_errors[] = 'no_message';
1917
+	} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) {
1918
+			$post_errors[] = array('long_message', array($modSettings['max_messageLength']));
1919
+	} else
1826 1920
 	{
1827 1921
 		// Prepare the message a bit for some additional testing.
1828 1922
 		$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
1829 1923
 
1830 1924
 		// Preparse code. (Zef)
1831
-		if ($user_info['is_guest'])
1832
-			$user_info['name'] = $_POST['guestname'];
1925
+		if ($user_info['is_guest']) {
1926
+					$user_info['name'] = $_POST['guestname'];
1927
+		}
1833 1928
 		preparsecode($_POST['message']);
1834 1929
 
1835 1930
 		// Youtube BBC would be stripped out in the next check without this
1836 1931
 		$context['allowed_html_tags'][] = '<iframe>';
1837 1932
 
1838 1933
 		// Let's see if there's still some content left without the tags.
1839
-		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false))
1840
-			$post_errors[] = 'no_message';
1934
+		if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) {
1935
+					$post_errors[] = 'no_message';
1936
+		}
1841 1937
 
1842 1938
 		// Remove iframe from the list
1843 1939
 		array_pop($context['allowed_html_tags']);
1844 1940
 	}
1845
-	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '')
1846
-		$post_errors[] = 'no_event';
1941
+	if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') {
1942
+			$post_errors[] = 'no_event';
1943
+	}
1847 1944
 	// You are not!
1848
-	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin'])
1849
-		fatal_error('Knave! Masquerader! Charlatan!', false);
1945
+	if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) {
1946
+			fatal_error('Knave! Masquerader! Charlatan!', false);
1947
+	}
1850 1948
 
1851 1949
 	// Validate the poll...
1852 1950
 	if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1')
1853 1951
 	{
1854
-		if (!empty($topic) && !isset($_REQUEST['msg']))
1855
-			fatal_lang_error('no_access', false);
1952
+		if (!empty($topic) && !isset($_REQUEST['msg'])) {
1953
+					fatal_lang_error('no_access', false);
1954
+		}
1856 1955
 
1857 1956
 		// This is a new topic... so it's a new poll.
1858
-		if (empty($topic))
1859
-			isAllowedTo('poll_post');
1957
+		if (empty($topic)) {
1958
+					isAllowedTo('poll_post');
1959
+		}
1860 1960
 		// Can you add to your own topics?
1861
-		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any'))
1862
-			isAllowedTo('poll_add_own');
1961
+		elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) {
1962
+					isAllowedTo('poll_add_own');
1963
+		}
1863 1964
 		// Can you add polls to any topic, then?
1864
-		else
1865
-			isAllowedTo('poll_add_any');
1965
+		else {
1966
+					isAllowedTo('poll_add_any');
1967
+		}
1866 1968
 
1867
-		if (!isset($_POST['question']) || trim($_POST['question']) == '')
1868
-			$post_errors[] = 'no_question';
1969
+		if (!isset($_POST['question']) || trim($_POST['question']) == '') {
1970
+					$post_errors[] = 'no_question';
1971
+		}
1869 1972
 
1870 1973
 		$_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']);
1871 1974
 
1872 1975
 		// Get rid of empty ones.
1873
-		foreach ($_POST['options'] as $k => $option)
1874
-			if ($option == '')
1976
+		foreach ($_POST['options'] as $k => $option) {
1977
+					if ($option == '')
1875 1978
 				unset($_POST['options'][$k], $_POST['options'][$k]);
1979
+		}
1876 1980
 
1877 1981
 		// What are you going to vote between with one choice?!?
1878
-		if (count($_POST['options']) < 2)
1879
-			$post_errors[] = 'poll_few';
1880
-		elseif (count($_POST['options']) > 256)
1881
-			$post_errors[] = 'poll_many';
1982
+		if (count($_POST['options']) < 2) {
1983
+					$post_errors[] = 'poll_few';
1984
+		} elseif (count($_POST['options']) > 256) {
1985
+					$post_errors[] = 'poll_many';
1986
+		}
1882 1987
 	}
1883 1988
 
1884 1989
 	if ($posterIsGuest)
1885 1990
 	{
1886 1991
 		// If user is a guest, make sure the chosen name isn't taken.
1887 1992
 		require_once($sourcedir . '/Subs-Members.php');
1888
-		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name']))
1889
-			$post_errors[] = 'bad_name';
1993
+		if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) {
1994
+					$post_errors[] = 'bad_name';
1995
+		}
1890 1996
 	}
1891 1997
 	// If the user isn't a guest, get his or her name and email.
1892 1998
 	elseif (!isset($_REQUEST['msg']))
@@ -1917,8 +2023,9 @@  discard block
 block discarded – undo
1917 2023
 	}
1918 2024
 
1919 2025
 	// Make sure the user isn't spamming the board.
1920
-	if (!isset($_REQUEST['msg']))
1921
-		spamProtection('post');
2026
+	if (!isset($_REQUEST['msg'])) {
2027
+			spamProtection('post');
2028
+	}
1922 2029
 
1923 2030
 	// At about this point, we're posting and that's that.
1924 2031
 	ignore_user_abort(true);
@@ -1931,32 +2038,36 @@  discard block
 block discarded – undo
1931 2038
 	$_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
1932 2039
 
1933 2040
 	// At this point, we want to make sure the subject isn't too long.
1934
-	if ($smcFunc['strlen']($_POST['subject']) > 100)
1935
-		$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2041
+	if ($smcFunc['strlen']($_POST['subject']) > 100) {
2042
+			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2043
+	}
1936 2044
 
1937 2045
 	// Same with the "why did you edit this" text.
1938
-	if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
1939
-		$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2046
+	if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
2047
+			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
2048
+	}
1940 2049
 
1941 2050
 	// Make the poll...
1942 2051
 	if (isset($_REQUEST['poll']))
1943 2052
 	{
1944 2053
 		// Make sure that the user has not entered a ridiculous number of options..
1945
-		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0)
1946
-			$_POST['poll_max_votes'] = 1;
1947
-		elseif ($_POST['poll_max_votes'] > count($_POST['options']))
1948
-			$_POST['poll_max_votes'] = count($_POST['options']);
1949
-		else
1950
-			$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2054
+		if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) {
2055
+					$_POST['poll_max_votes'] = 1;
2056
+		} elseif ($_POST['poll_max_votes'] > count($_POST['options'])) {
2057
+					$_POST['poll_max_votes'] = count($_POST['options']);
2058
+		} else {
2059
+					$_POST['poll_max_votes'] = (int) $_POST['poll_max_votes'];
2060
+		}
1951 2061
 
1952 2062
 		$_POST['poll_expire'] = (int) $_POST['poll_expire'];
1953 2063
 		$_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']);
1954 2064
 
1955 2065
 		// Just set it to zero if it's not there..
1956
-		if (!isset($_POST['poll_hide']))
1957
-			$_POST['poll_hide'] = 0;
1958
-		else
1959
-			$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2066
+		if (!isset($_POST['poll_hide'])) {
2067
+					$_POST['poll_hide'] = 0;
2068
+		} else {
2069
+					$_POST['poll_hide'] = (int) $_POST['poll_hide'];
2070
+		}
1960 2071
 		$_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0;
1961 2072
 
1962 2073
 		$_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0;
@@ -1965,16 +2076,19 @@  discard block
 block discarded – undo
1965 2076
 		{
1966 2077
 			require_once($sourcedir . '/Subs-Members.php');
1967 2078
 			$allowedVoteGroups = groupsAllowedTo('poll_vote', $board);
1968
-			if (!in_array(-1, $allowedVoteGroups['allowed']))
1969
-				$_POST['poll_guest_vote'] = 0;
2079
+			if (!in_array(-1, $allowedVoteGroups['allowed'])) {
2080
+							$_POST['poll_guest_vote'] = 0;
2081
+			}
1970 2082
 		}
1971 2083
 
1972 2084
 		// If the user tries to set the poll too far in advance, don't let them.
1973
-		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1)
1974
-			fatal_lang_error('poll_range_error', false);
2085
+		if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) {
2086
+					fatal_lang_error('poll_range_error', false);
2087
+		}
1975 2088
 		// Don't allow them to select option 2 for hidden results if it's not time limited.
1976
-		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2)
1977
-			$_POST['poll_hide'] = 1;
2089
+		elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) {
2090
+					$_POST['poll_hide'] = 1;
2091
+		}
1978 2092
 
1979 2093
 		// Clean up the question and answers.
1980 2094
 		$_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']);
@@ -1988,13 +2102,15 @@  discard block
 block discarded – undo
1988 2102
 	{
1989 2103
 		$attachIDs = array();
1990 2104
 		$attach_errors = array();
1991
-		if (!empty($context['we_are_history']))
1992
-			$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2105
+		if (!empty($context['we_are_history'])) {
2106
+					$attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>';
2107
+		}
1993 2108
 
1994 2109
 		foreach ($_SESSION['temp_attachments'] as  $attachID => $attachment)
1995 2110
 		{
1996
-			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false)
1997
-				continue;
2111
+			if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) {
2112
+							continue;
2113
+			}
1998 2114
 
1999 2115
 			// If there was an initial error just show that message.
2000 2116
 			if ($attachID == 'initial_error')
@@ -2023,12 +2139,13 @@  discard block
 block discarded – undo
2023 2139
 				if (createAttachment($attachmentOptions))
2024 2140
 				{
2025 2141
 					$attachIDs[] = $attachmentOptions['id'];
2026
-					if (!empty($attachmentOptions['thumb']))
2027
-						$attachIDs[] = $attachmentOptions['thumb'];
2142
+					if (!empty($attachmentOptions['thumb'])) {
2143
+											$attachIDs[] = $attachmentOptions['thumb'];
2144
+					}
2028 2145
 				}
2146
+			} else {
2147
+							$attach_errors[] = '<dt>&nbsp;</dt>';
2029 2148
 			}
2030
-			else
2031
-				$attach_errors[] = '<dt>&nbsp;</dt>';
2032 2149
 
2033 2150
 			if (!empty($attachmentOptions['errors']))
2034 2151
 			{
@@ -2040,14 +2157,16 @@  discard block
 block discarded – undo
2040 2157
 					if (!is_array($error))
2041 2158
 					{
2042 2159
 						$attach_errors[] = '<dd>' . $txt[$error] . '</dd>';
2043
-						if (in_array($error, $log_these))
2044
-							log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2160
+						if (in_array($error, $log_these)) {
2161
+													log_error($attachment['name'] . ': ' . $txt[$error], 'critical');
2162
+						}
2163
+					} else {
2164
+											$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2045 2165
 					}
2046
-					else
2047
-						$attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>';
2048 2166
 				}
2049
-				if (file_exists($attachment['tmp_name']))
2050
-					unlink($attachment['tmp_name']);
2167
+				if (file_exists($attachment['tmp_name'])) {
2168
+									unlink($attachment['tmp_name']);
2169
+				}
2051 2170
 			}
2052 2171
 		}
2053 2172
 		unset($_SESSION['temp_attachments']);
@@ -2088,24 +2207,24 @@  discard block
 block discarded – undo
2088 2207
 		);
2089 2208
 
2090 2209
 		call_integration_hook('integrate_poll_add_edit', array($id_poll, false));
2210
+	} else {
2211
+			$id_poll = 0;
2091 2212
 	}
2092
-	else
2093
-		$id_poll = 0;
2094 2213
 
2095 2214
 	// Creating a new topic?
2096 2215
 	$newTopic = empty($_REQUEST['msg']) && empty($topic);
2097 2216
 
2098 2217
 	// Check the icon.
2099
-	if (!isset($_POST['icon']))
2100
-		$_POST['icon'] = 'xx';
2101
-
2102
-	else
2218
+	if (!isset($_POST['icon'])) {
2219
+			$_POST['icon'] = 'xx';
2220
+	} else
2103 2221
 	{
2104 2222
 		$_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']);
2105 2223
 
2106 2224
 		// Need to figure it out if this is a valid icon name.
2107
-		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')))
2108
-			$_POST['icon'] = 'xx';
2225
+		if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) {
2226
+					$_POST['icon'] = 'xx';
2227
+		}
2109 2228
 	}
2110 2229
 
2111 2230
 	// Collect all parameters for the creation or modification of a post.
@@ -2146,8 +2265,9 @@  discard block
 block discarded – undo
2146 2265
 		}
2147 2266
 
2148 2267
 		// This will save some time...
2149
-		if (empty($approve_has_changed))
2150
-			unset($msgOptions['approved']);
2268
+		if (empty($approve_has_changed)) {
2269
+					unset($msgOptions['approved']);
2270
+		}
2151 2271
 
2152 2272
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2153 2273
 	}
@@ -2156,8 +2276,9 @@  discard block
 block discarded – undo
2156 2276
 	{
2157 2277
 		createPost($msgOptions, $topicOptions, $posterOptions);
2158 2278
 
2159
-		if (isset($topicOptions['id']))
2160
-			$topic = $topicOptions['id'];
2279
+		if (isset($topicOptions['id'])) {
2280
+					$topic = $topicOptions['id'];
2281
+		}
2161 2282
 	}
2162 2283
 
2163 2284
 	// Are there attachments already uploaded and waiting to be assigned?
@@ -2169,8 +2290,9 @@  discard block
 block discarded – undo
2169 2290
 	}
2170 2291
 
2171 2292
 	// If we had a draft for this, its time to remove it since it was just posted
2172
-	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft']))
2173
-		DeleteDraft($_POST['id_draft']);
2293
+	if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) {
2294
+			DeleteDraft($_POST['id_draft']);
2295
+	}
2174 2296
 
2175 2297
 	// Editing or posting an event?
2176 2298
 	if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1))
@@ -2189,8 +2311,7 @@  discard block
 block discarded – undo
2189 2311
 			'member' => $user_info['id'],
2190 2312
 		);
2191 2313
 		insertEvent($eventOptions);
2192
-	}
2193
-	elseif (isset($_POST['calendar']))
2314
+	} elseif (isset($_POST['calendar']))
2194 2315
 	{
2195 2316
 		$_REQUEST['eventid'] = (int) $_REQUEST['eventid'];
2196 2317
 
@@ -2218,14 +2339,15 @@  discard block
 block discarded – undo
2218 2339
 		}
2219 2340
 
2220 2341
 		// Delete it?
2221
-		if (isset($_REQUEST['deleteevent']))
2222
-			$smcFunc['db_query']('', '
2342
+		if (isset($_REQUEST['deleteevent'])) {
2343
+					$smcFunc['db_query']('', '
2223 2344
 				DELETE FROM {db_prefix}calendar
2224 2345
 				WHERE id_event = {int:id_event}',
2225 2346
 				array(
2226 2347
 					'id_event' => $_REQUEST['eventid'],
2227 2348
 				)
2228 2349
 			);
2350
+		}
2229 2351
 		// ... or just update it?
2230 2352
 		else
2231 2353
 		{
@@ -2267,9 +2389,8 @@  discard block
 block discarded – undo
2267 2389
 			array($user_info['id'], $topic, 0),
2268 2390
 			array('id_member', 'id_topic', 'id_board')
2269 2391
 		);
2270
-	}
2271
-	elseif (!$newTopic)
2272
-		$smcFunc['db_query']('', '
2392
+	} elseif (!$newTopic) {
2393
+			$smcFunc['db_query']('', '
2273 2394
 			DELETE FROM {db_prefix}log_notify
2274 2395
 			WHERE id_member = {int:current_member}
2275 2396
 				AND id_topic = {int:current_topic}',
@@ -2278,16 +2399,20 @@  discard block
 block discarded – undo
2278 2399
 				'current_topic' => $topic,
2279 2400
 			)
2280 2401
 		);
2402
+	}
2281 2403
 
2282 2404
 	// Log an act of moderation - modifying.
2283
-	if (!empty($moderationAction))
2284
-		logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2405
+	if (!empty($moderationAction)) {
2406
+			logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board));
2407
+	}
2285 2408
 
2286
-	if (isset($_POST['lock']) && $_POST['lock'] != 2)
2287
-		logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2409
+	if (isset($_POST['lock']) && $_POST['lock'] != 2) {
2410
+			logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2411
+	}
2288 2412
 
2289
-	if (isset($_POST['sticky']))
2290
-		logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2413
+	if (isset($_POST['sticky'])) {
2414
+			logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board']));
2415
+	}
2291 2416
 
2292 2417
 	// Returning to the topic?
2293 2418
 	if (!empty($_REQUEST['goback']))
@@ -2306,26 +2431,31 @@  discard block
 block discarded – undo
2306 2431
 		);
2307 2432
 	}
2308 2433
 
2309
-	if ($board_info['num_topics'] == 0)
2310
-		cache_put_data('board-' . $board, null, 120);
2434
+	if ($board_info['num_topics'] == 0) {
2435
+			cache_put_data('board-' . $board, null, 120);
2436
+	}
2311 2437
 
2312 2438
 	call_integration_hook('integrate_post2_end');
2313 2439
 
2314
-	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic'))
2315
-		redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2440
+	if (!empty($_POST['announce_topic']) && allowedTo('announce_topic')) {
2441
+			redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback'));
2442
+	}
2316 2443
 
2317
-	if (!empty($_POST['move']) && allowedTo('move_any'))
2318
-		redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2444
+	if (!empty($_POST['move']) && allowedTo('move_any')) {
2445
+			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2446
+	}
2319 2447
 
2320 2448
 	// Return to post if the mod is on.
2321
-	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback']))
2322
-		redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2323
-	elseif (!empty($_REQUEST['goback']))
2324
-		redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2449
+	if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) {
2450
+			redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie'));
2451
+	} elseif (!empty($_REQUEST['goback'])) {
2452
+			redirectexit('topic=' . $topic . '.new#new', isBrowser('ie'));
2453
+	}
2325 2454
 	// Dut-dut-duh-duh-DUH-duh-dut-duh-duh!  *dances to the Final Fantasy Fanfare...*
2326
-	else
2327
-		redirectexit('board=' . $board . '.0');
2328
-}
2455
+	else {
2456
+			redirectexit('board=' . $board . '.0');
2457
+	}
2458
+	}
2329 2459
 
2330 2460
 /**
2331 2461
  * Handle the announce topic function (action=announce).
@@ -2343,8 +2473,9 @@  discard block
 block discarded – undo
2343 2473
 
2344 2474
 	validateSession();
2345 2475
 
2346
-	if (empty($topic))
2347
-		fatal_lang_error('topic_gone', false);
2476
+	if (empty($topic)) {
2477
+			fatal_lang_error('topic_gone', false);
2478
+	}
2348 2479
 
2349 2480
 	loadLanguage('Post');
2350 2481
 	loadTemplate('Post');
@@ -2371,8 +2502,9 @@  discard block
 block discarded – undo
2371 2502
 	global $txt, $context, $topic, $board_info, $smcFunc;
2372 2503
 
2373 2504
 	$groups = array_merge($board_info['groups'], array(1));
2374
-	foreach ($groups as $id => $group)
2375
-		$groups[$id] = (int) $group;
2505
+	foreach ($groups as $id => $group) {
2506
+			$groups[$id] = (int) $group;
2507
+	}
2376 2508
 
2377 2509
 	$context['groups'] = array();
2378 2510
 	if (in_array(0, $groups))
@@ -2415,8 +2547,9 @@  discard block
 block discarded – undo
2415 2547
 			'group_list' => $groups,
2416 2548
 		)
2417 2549
 	);
2418
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2419
-		$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2550
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2551
+			$context['groups'][$row['id_group']]['name'] = $row['group_name'];
2552
+	}
2420 2553
 	$smcFunc['db_free_result']($request);
2421 2554
 
2422 2555
 	// Get the subject of the topic we're about to announce.
@@ -2458,16 +2591,19 @@  discard block
 block discarded – undo
2458 2591
 	$context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
2459 2592
 	$groups = array_merge($board_info['groups'], array(1));
2460 2593
 
2461
-	if (isset($_POST['membergroups']))
2462
-		$_POST['who'] = explode(',', $_POST['membergroups']);
2594
+	if (isset($_POST['membergroups'])) {
2595
+			$_POST['who'] = explode(',', $_POST['membergroups']);
2596
+	}
2463 2597
 
2464 2598
 	// Check whether at least one membergroup was selected.
2465
-	if (empty($_POST['who']))
2466
-		fatal_lang_error('no_membergroup_selected');
2599
+	if (empty($_POST['who'])) {
2600
+			fatal_lang_error('no_membergroup_selected');
2601
+	}
2467 2602
 
2468 2603
 	// Make sure all membergroups are integers and can access the board of the announcement.
2469
-	foreach ($_POST['who'] as $id => $mg)
2470
-		$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2604
+	foreach ($_POST['who'] as $id => $mg) {
2605
+			$_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0;
2606
+	}
2471 2607
 
2472 2608
 	// Get the topic subject and censor it.
2473 2609
 	$request = $smcFunc['db_query']('', '
@@ -2513,12 +2649,13 @@  discard block
 block discarded – undo
2513 2649
 	if ($smcFunc['db_num_rows']($request) == 0)
2514 2650
 	{
2515 2651
 		logAction('announce_topic', array('topic' => $topic), 'user');
2516
-		if (!empty($_REQUEST['move']) && allowedTo('move_any'))
2517
-			redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2518
-		elseif (!empty($_REQUEST['goback']))
2519
-			redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2520
-		else
2521
-			redirectexit('board=' . $board . '.0');
2652
+		if (!empty($_REQUEST['move']) && allowedTo('move_any')) {
2653
+					redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback'));
2654
+		} elseif (!empty($_REQUEST['goback'])) {
2655
+					redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie'));
2656
+		} else {
2657
+					redirectexit('board=' . $board . '.0');
2658
+		}
2522 2659
 	}
2523 2660
 
2524 2661
 	$announcements = array();
@@ -2537,8 +2674,9 @@  discard block
 block discarded – undo
2537 2674
 	foreach ($rows as $row)
2538 2675
 	{
2539 2676
 		// Force them to have it?
2540
-		if (empty($prefs[$row['id_member']]['announcements']))
2541
-			continue;
2677
+		if (empty($prefs[$row['id_member']]['announcements'])) {
2678
+					continue;
2679
+		}
2542 2680
 
2543 2681
 		$cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile'];
2544 2682
 
@@ -2566,8 +2704,9 @@  discard block
 block discarded – undo
2566 2704
 	}
2567 2705
 
2568 2706
 	// For each language send a different mail - low priority...
2569
-	foreach ($announcements as $lang => $mail)
2570
-		sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2707
+	foreach ($announcements as $lang => $mail) {
2708
+			sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5);
2709
+	}
2571 2710
 
2572 2711
 	$context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1);
2573 2712
 
@@ -2577,9 +2716,10 @@  discard block
 block discarded – undo
2577 2716
 	$context['sub_template'] = 'announcement_send';
2578 2717
 
2579 2718
 	// Go back to the correct language for the user ;).
2580
-	if (!empty($modSettings['userLanguage']))
2581
-		loadLanguage('Post');
2582
-}
2719
+	if (!empty($modSettings['userLanguage'])) {
2720
+			loadLanguage('Post');
2721
+	}
2722
+	}
2583 2723
 
2584 2724
 /**
2585 2725
  * Get the topic for display purposes.
@@ -2592,12 +2732,13 @@  discard block
 block discarded – undo
2592 2732
 {
2593 2733
 	global $topic, $modSettings, $context, $smcFunc, $counter, $options;
2594 2734
 
2595
-	if (isset($_REQUEST['xml']))
2596
-		$limit = '
2735
+	if (isset($_REQUEST['xml'])) {
2736
+			$limit = '
2597 2737
 		LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']);
2598
-	else
2599
-		$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2738
+	} else {
2739
+			$limit = empty($modSettings['topicSummaryPosts']) ? '' : '
2600 2740
 		LIMIT ' . (int) $modSettings['topicSummaryPosts'];
2741
+	}
2601 2742
 
2602 2743
 	// If you're modifying, get only those posts before the current one. (otherwise get all.)
2603 2744
 	$request = $smcFunc['db_query']('', '
@@ -2635,8 +2776,9 @@  discard block
 block discarded – undo
2635 2776
 			'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']),
2636 2777
 		);
2637 2778
 
2638
-		if (!empty($context['new_replies']))
2639
-			$context['new_replies']--;
2779
+		if (!empty($context['new_replies'])) {
2780
+					$context['new_replies']--;
2781
+		}
2640 2782
 	}
2641 2783
 	$smcFunc['db_free_result']($request);
2642 2784
 }
@@ -2653,8 +2795,9 @@  discard block
 block discarded – undo
2653 2795
 	global $sourcedir, $smcFunc;
2654 2796
 
2655 2797
 	loadLanguage('Post');
2656
-	if (!isset($_REQUEST['xml']))
2657
-		loadTemplate('Post');
2798
+	if (!isset($_REQUEST['xml'])) {
2799
+			loadTemplate('Post');
2800
+	}
2658 2801
 
2659 2802
 	include_once($sourcedir . '/Subs-Post.php');
2660 2803
 
@@ -2685,8 +2828,9 @@  discard block
 block discarded – undo
2685 2828
 	$smcFunc['db_free_result']($request);
2686 2829
 
2687 2830
 	$context['sub_template'] = 'quotefast';
2688
-	if (!empty($row))
2689
-		$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2831
+	if (!empty($row)) {
2832
+			$can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']);
2833
+	}
2690 2834
 
2691 2835
 	if (!empty($can_view_post))
2692 2836
 	{
@@ -2719,8 +2863,9 @@  discard block
 block discarded – undo
2719 2863
 		}
2720 2864
 
2721 2865
 		// Remove any nested quotes.
2722
-		if (!empty($modSettings['removeNestedQuotes']))
2723
-			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2866
+		if (!empty($modSettings['removeNestedQuotes'])) {
2867
+					$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
2868
+		}
2724 2869
 
2725 2870
 		$lb = "\n";
2726 2871
 
@@ -2746,14 +2891,14 @@  discard block
 block discarded – undo
2746 2891
 				'time' => '',
2747 2892
 			),
2748 2893
 		);
2749
-	}
2750
-	else
2751
-		$context['quote'] = array(
2894
+	} else {
2895
+			$context['quote'] = array(
2752 2896
 			'xml' => '',
2753 2897
 			'mozilla' => '',
2754 2898
 			'text' => '',
2755 2899
 		);
2756
-}
2900
+	}
2901
+	}
2757 2902
 
2758 2903
 /**
2759 2904
  * Used to edit the body or subject of a message inline
@@ -2765,8 +2910,9 @@  discard block
 block discarded – undo
2765 2910
 	global $user_info, $context, $smcFunc, $language, $board_info;
2766 2911
 
2767 2912
 	// We have to have a topic!
2768
-	if (empty($topic))
2769
-		obExit(false);
2913
+	if (empty($topic)) {
2914
+			obExit(false);
2915
+	}
2770 2916
 
2771 2917
 	checkSession('get');
2772 2918
 	require_once($sourcedir . '/Subs-Post.php');
@@ -2792,31 +2938,35 @@  discard block
 block discarded – undo
2792 2938
 			'guest_id' => 0,
2793 2939
 		)
2794 2940
 	);
2795
-	if ($smcFunc['db_num_rows']($request) == 0)
2796
-		fatal_lang_error('no_board', false);
2941
+	if ($smcFunc['db_num_rows']($request) == 0) {
2942
+			fatal_lang_error('no_board', false);
2943
+	}
2797 2944
 	$row = $smcFunc['db_fetch_assoc']($request);
2798 2945
 	$smcFunc['db_free_result']($request);
2799 2946
 
2800 2947
 	// Change either body or subject requires permissions to modify messages.
2801 2948
 	if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon']))
2802 2949
 	{
2803
-		if (!empty($row['locked']))
2804
-			isAllowedTo('moderate_board');
2950
+		if (!empty($row['locked'])) {
2951
+					isAllowedTo('moderate_board');
2952
+		}
2805 2953
 
2806 2954
 		if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any'))
2807 2955
 		{
2808
-			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time())
2809
-				fatal_lang_error('modify_post_time_passed', false);
2810
-			elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own'))
2811
-				isAllowedTo('modify_replies');
2812
-			else
2813
-				isAllowedTo('modify_own');
2956
+			if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) {
2957
+							fatal_lang_error('modify_post_time_passed', false);
2958
+			} elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) {
2959
+							isAllowedTo('modify_replies');
2960
+			} else {
2961
+							isAllowedTo('modify_own');
2962
+			}
2814 2963
 		}
2815 2964
 		// Otherwise, they're locked out; someone who can modify the replies is needed.
2816
-		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any'))
2817
-			isAllowedTo('modify_replies');
2818
-		else
2819
-			isAllowedTo('modify_any');
2965
+		elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) {
2966
+					isAllowedTo('modify_replies');
2967
+		} else {
2968
+					isAllowedTo('modify_any');
2969
+		}
2820 2970
 
2821 2971
 		// Only log this action if it wasn't your message.
2822 2972
 		$moderationAction = $row['id_member'] != $user_info['id'];
@@ -2828,10 +2978,10 @@  discard block
 block discarded – undo
2828 2978
 		$_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => ''));
2829 2979
 
2830 2980
 		// Maximum number of characters.
2831
-		if ($smcFunc['strlen']($_POST['subject']) > 100)
2832
-			$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2833
-	}
2834
-	elseif (isset($_POST['subject']))
2981
+		if ($smcFunc['strlen']($_POST['subject']) > 100) {
2982
+					$_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100);
2983
+		}
2984
+	} elseif (isset($_POST['subject']))
2835 2985
 	{
2836 2986
 		$post_errors[] = 'no_subject';
2837 2987
 		unset($_POST['subject']);
@@ -2843,13 +2993,11 @@  discard block
 block discarded – undo
2843 2993
 		{
2844 2994
 			$post_errors[] = 'no_message';
2845 2995
 			unset($_POST['message']);
2846
-		}
2847
-		elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2996
+		} elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength'])
2848 2997
 		{
2849 2998
 			$post_errors[] = 'long_message';
2850 2999
 			unset($_POST['message']);
2851
-		}
2852
-		else
3000
+		} else
2853 3001
 		{
2854 3002
 			$_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES);
2855 3003
 
@@ -2865,31 +3013,34 @@  discard block
 block discarded – undo
2865 3013
 
2866 3014
 	if (isset($_POST['lock']))
2867 3015
 	{
2868
-		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member']))
2869
-			unset($_POST['lock']);
2870
-		elseif (!allowedTo('lock_any'))
3016
+		if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) {
3017
+					unset($_POST['lock']);
3018
+		} elseif (!allowedTo('lock_any'))
2871 3019
 		{
2872
-			if ($row['locked'] == 1)
2873
-				unset($_POST['lock']);
2874
-			else
2875
-				$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3020
+			if ($row['locked'] == 1) {
3021
+							unset($_POST['lock']);
3022
+			} else {
3023
+							$_POST['lock'] = empty($_POST['lock']) ? 0 : 2;
3024
+			}
3025
+		} elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) {
3026
+					unset($_POST['lock']);
3027
+		} else {
3028
+					$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2876 3029
 		}
2877
-		elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked'])
2878
-			unset($_POST['lock']);
2879
-		else
2880
-			$_POST['lock'] = empty($_POST['lock']) ? 0 : 1;
2881 3030
 	}
2882 3031
 
2883
-	if (isset($_POST['sticky']) && !allowedTo('make_sticky'))
2884
-		unset($_POST['sticky']);
3032
+	if (isset($_POST['sticky']) && !allowedTo('make_sticky')) {
3033
+			unset($_POST['sticky']);
3034
+	}
2885 3035
 
2886 3036
 	if (isset($_POST['modify_reason']))
2887 3037
 	{
2888 3038
 		$_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => ''));
2889 3039
 
2890 3040
 		// Maximum number of characters.
2891
-		if ($smcFunc['strlen']($_POST['modify_reason']) > 100)
2892
-			$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3041
+		if ($smcFunc['strlen']($_POST['modify_reason']) > 100) {
3042
+					$_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100);
3043
+		}
2893 3044
 	}
2894 3045
 
2895 3046
 	if (empty($post_errors))
@@ -2926,8 +3077,9 @@  discard block
 block discarded – undo
2926 3077
 			}
2927 3078
 		}
2928 3079
 		// If nothing was changed there's no need to add an entry to the moderation log.
2929
-		else
2930
-			$moderationAction = false;
3080
+		else {
3081
+					$moderationAction = false;
3082
+		}
2931 3083
 
2932 3084
 		modifyPost($msgOptions, $topicOptions, $posterOptions);
2933 3085
 
@@ -2945,9 +3097,9 @@  discard block
 block discarded – undo
2945 3097
 			// Get the proper (default language) response prefix first.
2946 3098
 			if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
2947 3099
 			{
2948
-				if ($language === $user_info['language'])
2949
-					$context['response_prefix'] = $txt['response_prefix'];
2950
-				else
3100
+				if ($language === $user_info['language']) {
3101
+									$context['response_prefix'] = $txt['response_prefix'];
3102
+				} else
2951 3103
 				{
2952 3104
 					loadLanguage('index', $language, false);
2953 3105
 					$context['response_prefix'] = $txt['response_prefix'];
@@ -2969,8 +3121,9 @@  discard block
 block discarded – undo
2969 3121
 			);
2970 3122
 		}
2971 3123
 
2972
-		if (!empty($moderationAction))
2973
-			logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3124
+		if (!empty($moderationAction)) {
3125
+					logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board));
3126
+		}
2974 3127
 	}
2975 3128
 
2976 3129
 	if (isset($_REQUEST['xml']))
@@ -3011,8 +3164,7 @@  discard block
 block discarded – undo
3011 3164
 			);
3012 3165
 
3013 3166
 			censorText($context['message']['subject']);
3014
-		}
3015
-		else
3167
+		} else
3016 3168
 		{
3017 3169
 			$context['message'] = array(
3018 3170
 				'id' => $row['id_msg'],
@@ -3024,15 +3176,16 @@  discard block
 block discarded – undo
3024 3176
 			loadLanguage('Errors');
3025 3177
 			foreach ($post_errors as $post_error)
3026 3178
 			{
3027
-				if ($post_error == 'long_message')
3028
-					$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3029
-				else
3030
-					$context['message']['errors'][] = $txt['error_' . $post_error];
3179
+				if ($post_error == 'long_message') {
3180
+									$context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']);
3181
+				} else {
3182
+									$context['message']['errors'][] = $txt['error_' . $post_error];
3183
+				}
3031 3184
 			}
3032 3185
 		}
3186
+	} else {
3187
+			obExit(false);
3188
+	}
3033 3189
 	}
3034
-	else
3035
-		obExit(false);
3036
-}
3037 3190
 
3038 3191
 ?>
3039 3192
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1454 added lines, -1079 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Update some basic statistics.
@@ -122,10 +123,11 @@  discard block
 block discarded – undo
122 123
 						$smcFunc['db_free_result']($result);
123 124
 
124 125
 						// Add this to the number of unapproved members
125
-						if (!empty($changes['unapprovedMembers']))
126
-							$changes['unapprovedMembers'] += $coppa_approvals;
127
-						else
128
-							$changes['unapprovedMembers'] = $coppa_approvals;
126
+						if (!empty($changes['unapprovedMembers'])) {
127
+													$changes['unapprovedMembers'] += $coppa_approvals;
128
+						} else {
129
+													$changes['unapprovedMembers'] = $coppa_approvals;
130
+						}
129 131
 					}
130 132
 				}
131 133
 			}
@@ -133,9 +135,9 @@  discard block
 block discarded – undo
133 135
 			break;
134 136
 
135 137
 		case 'message':
136
-			if ($parameter1 === true && $parameter2 !== null)
137
-				updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
138
-			else
138
+			if ($parameter1 === true && $parameter2 !== null) {
139
+							updateSettings(array('totalMessages' => true, 'maxMsgID' => $parameter2), true);
140
+			} else
139 141
 			{
140 142
 				// SUM and MAX on a smaller table is better for InnoDB tables.
141 143
 				$result = $smcFunc['db_query']('', '
@@ -175,23 +177,25 @@  discard block
 block discarded – undo
175 177
 				$parameter2 = text2words($parameter2);
176 178
 
177 179
 				$inserts = array();
178
-				foreach ($parameter2 as $word)
179
-					$inserts[] = array($word, $parameter1);
180
+				foreach ($parameter2 as $word) {
181
+									$inserts[] = array($word, $parameter1);
182
+				}
180 183
 
181
-				if (!empty($inserts))
182
-					$smcFunc['db_insert']('ignore',
184
+				if (!empty($inserts)) {
185
+									$smcFunc['db_insert']('ignore',
183 186
 						'{db_prefix}log_search_subjects',
184 187
 						array('word' => 'string', 'id_topic' => 'int'),
185 188
 						$inserts,
186 189
 						array('word', 'id_topic')
187 190
 					);
191
+				}
188 192
 			}
189 193
 			break;
190 194
 
191 195
 		case 'topic':
192
-			if ($parameter1 === true)
193
-				updateSettings(array('totalTopics' => true), true);
194
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
195 199
 			{
196 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
197 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -212,8 +216,9 @@  discard block
 block discarded – undo
212 216
 
213 217
 		case 'postgroups':
214 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
215
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
216
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
217 222
 
218 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
219 224
 			if ($postgroups == null || $parameter1 == null)
@@ -228,8 +233,9 @@  discard block
 block discarded – undo
228 233
 					)
229 234
 				);
230 235
 				$postgroups = array();
231
-				while ($row = $smcFunc['db_fetch_assoc']($request))
232
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
233 239
 				$smcFunc['db_free_result']($request);
234 240
 
235 241
 				// Sort them this way because if it's done with MySQL it causes a filesort :(.
@@ -239,8 +245,9 @@  discard block
 block discarded – undo
239 245
 			}
240 246
 
241 247
 			// Oh great, they've screwed their post groups.
242
-			if (empty($postgroups))
243
-				return;
248
+			if (empty($postgroups)) {
249
+							return;
250
+			}
244 251
 
245 252
 			// Set all membergroups from most posts to least posts.
246 253
 			$conditions = '';
@@ -298,10 +305,9 @@  discard block
 block discarded – undo
298 305
 	{
299 306
 		$condition = 'id_member IN ({array_int:members})';
300 307
 		$parameters['members'] = $members;
301
-	}
302
-	elseif ($members === null)
303
-		$condition = '1=1';
304
-	else
308
+	} elseif ($members === null) {
309
+			$condition = '1=1';
310
+	} else
305 311
 	{
306 312
 		$condition = 'id_member = {int:member}';
307 313
 		$parameters['member'] = $members;
@@ -341,9 +347,9 @@  discard block
 block discarded – undo
341 347
 		if (count($vars_to_integrate) != 0)
342 348
 		{
343 349
 			// Fetch a list of member_names if necessary
344
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
345
-				$member_names = array($user_info['username']);
346
-			else
350
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
351
+							$member_names = array($user_info['username']);
352
+			} else
347 353
 			{
348 354
 				$member_names = array();
349 355
 				$request = $smcFunc['db_query']('', '
@@ -352,14 +358,16 @@  discard block
 block discarded – undo
352 358
 					WHERE ' . $condition,
353 359
 					$parameters
354 360
 				);
355
-				while ($row = $smcFunc['db_fetch_assoc']($request))
356
-					$member_names[] = $row['member_name'];
361
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
362
+									$member_names[] = $row['member_name'];
363
+				}
357 364
 				$smcFunc['db_free_result']($request);
358 365
 			}
359 366
 
360
-			if (!empty($member_names))
361
-				foreach ($vars_to_integrate as $var)
367
+			if (!empty($member_names)) {
368
+							foreach ($vars_to_integrate as $var)
362 369
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
370
+			}
363 371
 		}
364 372
 	}
365 373
 
@@ -367,16 +375,17 @@  discard block
 block discarded – undo
367 375
 	foreach ($data as $var => $val)
368 376
 	{
369 377
 		$type = 'string';
370
-		if (in_array($var, $knownInts))
371
-			$type = 'int';
372
-		elseif (in_array($var, $knownFloats))
373
-			$type = 'float';
374
-		elseif ($var == 'birthdate')
375
-			$type = 'date';
376
-		elseif ($var == 'member_ip')
377
-			$type = 'inet';
378
-		elseif ($var == 'member_ip2')
379
-			$type = 'inet';
378
+		if (in_array($var, $knownInts)) {
379
+					$type = 'int';
380
+		} elseif (in_array($var, $knownFloats)) {
381
+					$type = 'float';
382
+		} elseif ($var == 'birthdate') {
383
+					$type = 'date';
384
+		} elseif ($var == 'member_ip') {
385
+					$type = 'inet';
386
+		} elseif ($var == 'member_ip2') {
387
+					$type = 'inet';
388
+		}
380 389
 
381 390
 		// Doing an increment?
382 391
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -385,18 +394,17 @@  discard block
 block discarded – undo
385 394
 			if (is_array($members))
386 395
 			{
387 396
 				$val = 'CASE ';
388
-				foreach ($members as $k => $v)
389
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
397
+				foreach ($members as $k => $v) {
398
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				}
390 400
 				$val = $val . ' END';
391 401
 				$type = 'raw';
392
-			}
393
-			else
402
+			} else
394 403
 			{
395 404
 				$blub = fetch_alerts($members, false, 0, array(), false);
396 405
 				$val = count($blub);
397 406
 			}
398
-		}
399
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
407
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
400 408
 		{
401 409
 			$val = $var . ' ' . $val . ' 1';
402 410
 			$type = 'raw';
@@ -407,8 +415,9 @@  discard block
 block discarded – undo
407 415
 		{
408 416
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
409 417
 			{
410
-				if ($match[1] != '+ ')
411
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
418
+				if ($match[1] != '+ ') {
419
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				}
412 421
 				$type = 'raw';
413 422
 			}
414 423
 		}
@@ -429,8 +438,9 @@  discard block
 block discarded – undo
429 438
 	// Clear any caching?
430 439
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
431 440
 	{
432
-		if (!is_array($members))
433
-			$members = array($members);
441
+		if (!is_array($members)) {
442
+					$members = array($members);
443
+		}
434 444
 
435 445
 		foreach ($members as $member)
436 446
 		{
@@ -463,29 +473,32 @@  discard block
 block discarded – undo
463 473
 {
464 474
 	global $modSettings, $smcFunc;
465 475
 
466
-	if (empty($changeArray) || !is_array($changeArray))
467
-		return;
476
+	if (empty($changeArray) || !is_array($changeArray)) {
477
+			return;
478
+	}
468 479
 
469 480
 	$toRemove = array();
470 481
 
471 482
 	// Go check if there is any setting to be removed.
472
-	foreach ($changeArray as $k => $v)
473
-		if ($v === null)
483
+	foreach ($changeArray as $k => $v) {
484
+			if ($v === null)
474 485
 		{
475 486
 			// Found some, remove them from the original array and add them to ours.
476 487
 			unset($changeArray[$k]);
488
+	}
477 489
 			$toRemove[] = $k;
478 490
 		}
479 491
 
480 492
 	// Proceed with the deletion.
481
-	if (!empty($toRemove))
482
-		$smcFunc['db_query']('', '
493
+	if (!empty($toRemove)) {
494
+			$smcFunc['db_query']('', '
483 495
 			DELETE FROM {db_prefix}settings
484 496
 			WHERE variable IN ({array_string:remove})',
485 497
 			array(
486 498
 				'remove' => $toRemove,
487 499
 			)
488 500
 		);
501
+	}
489 502
 
490 503
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
491 504
 	if ($update)
@@ -514,19 +527,22 @@  discard block
 block discarded – undo
514 527
 	foreach ($changeArray as $variable => $value)
515 528
 	{
516 529
 		// Don't bother if it's already like that ;).
517
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
518
-			continue;
530
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
531
+					continue;
532
+		}
519 533
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
520
-		elseif (!isset($modSettings[$variable]) && empty($value))
521
-			continue;
534
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
535
+					continue;
536
+		}
522 537
 
523 538
 		$replaceArray[] = array($variable, $value);
524 539
 
525 540
 		$modSettings[$variable] = $value;
526 541
 	}
527 542
 
528
-	if (empty($replaceArray))
529
-		return;
543
+	if (empty($replaceArray)) {
544
+			return;
545
+	}
530 546
 
531 547
 	$smcFunc['db_insert']('replace',
532 548
 		'{db_prefix}settings',
@@ -572,14 +588,17 @@  discard block
 block discarded – undo
572 588
 	$start_invalid = $start < 0;
573 589
 
574 590
 	// Make sure $start is a proper variable - not less than 0.
575
-	if ($start_invalid)
576
-		$start = 0;
591
+	if ($start_invalid) {
592
+			$start = 0;
593
+	}
577 594
 	// Not greater than the upper bound.
578
-	elseif ($start >= $max_value)
579
-		$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
595
+	elseif ($start >= $max_value) {
596
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
597
+	}
580 598
 	// And it has to be a multiple of $num_per_page!
581
-	else
582
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
599
+	else {
600
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	}
583 602
 
584 603
 	$context['current_page'] = $start / $num_per_page;
585 604
 
@@ -609,77 +628,87 @@  discard block
 block discarded – undo
609 628
 
610 629
 		// Show all the pages.
611 630
 		$display_page = 1;
612
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
613
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
631
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
632
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		}
614 634
 
615 635
 		// Show the right arrow.
616 636
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
617
-		if ($start != $counter - $max_value && !$start_invalid)
618
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
619
-	}
620
-	else
637
+		if ($start != $counter - $max_value && !$start_invalid) {
638
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
639
+		}
640
+	} else
621 641
 	{
622 642
 		// If they didn't enter an odd value, pretend they did.
623 643
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
624 644
 
625 645
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
626
-		if (!empty($start) && $show_prevnext)
627
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
628
-		else
629
-			$pageindex .= '';
646
+		if (!empty($start) && $show_prevnext) {
647
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
648
+		} else {
649
+					$pageindex .= '';
650
+		}
630 651
 
631 652
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
632
-		if ($start > $num_per_page * $PageContiguous)
633
-			$pageindex .= sprintf($base_link, 0, '1');
653
+		if ($start > $num_per_page * $PageContiguous) {
654
+					$pageindex .= sprintf($base_link, 0, '1');
655
+		}
634 656
 
635 657
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
636
-		if ($start > $num_per_page * ($PageContiguous + 1))
637
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
658
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
659
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
638 660
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
639 661
 				'{FIRST_PAGE}' => $num_per_page,
640 662
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
641 663
 				'{PER_PAGE}' => $num_per_page,
642 664
 			));
665
+		}
643 666
 
644 667
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
645
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
646
-			if ($start >= $num_per_page * $nCont)
668
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
669
+					if ($start >= $num_per_page * $nCont)
647 670
 			{
648 671
 				$tmpStart = $start - $num_per_page * $nCont;
672
+		}
649 673
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
650 674
 			}
651 675
 
652 676
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
653
-		if (!$start_invalid)
654
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
655
-		else
656
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
677
+		if (!$start_invalid) {
678
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
679
+		} else {
680
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
681
+		}
657 682
 
658 683
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
659 684
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
660
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
661
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
685
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
686
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
662 687
 			{
663 688
 				$tmpStart = $start + $num_per_page * $nCont;
689
+		}
664 690
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
665 691
 			}
666 692
 
667 693
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
668
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
669
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
694
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
695
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
670 696
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
671 697
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
672 698
 				'{LAST_PAGE}' => $tmpMaxPages,
673 699
 				'{PER_PAGE}' => $num_per_page,
674 700
 			));
701
+		}
675 702
 
676 703
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
677
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
678
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
704
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
705
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		}
679 707
 
680 708
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
681
-		if ($start != $tmpMaxPages && $show_prevnext)
682
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
709
+		if ($start != $tmpMaxPages && $show_prevnext) {
710
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		}
683 712
 	}
684 713
 	$pageindex .= $settings['page_index']['extra_after'];
685 714
 
@@ -705,8 +734,9 @@  discard block
 block discarded – undo
705 734
 	if ($decimal_separator === null)
706 735
 	{
707 736
 		// Not set for whatever reason?
708
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
709
-			return $number;
737
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
738
+					return $number;
739
+		}
710 740
 
711 741
 		// Cache these each load...
712 742
 		$thousands_separator = $matches[1];
@@ -740,17 +770,20 @@  discard block
 block discarded – undo
740 770
 	static $unsupportedFormats, $finalizedFormats;
741 771
 
742 772
 	// Offset the time.
743
-	if (!$offset_type)
744
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
773
+	if (!$offset_type) {
774
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
775
+	}
745 776
 	// Just the forum offset?
746
-	elseif ($offset_type == 'forum')
747
-		$time = $log_time + $modSettings['time_offset'] * 3600;
748
-	else
749
-		$time = $log_time;
777
+	elseif ($offset_type == 'forum') {
778
+			$time = $log_time + $modSettings['time_offset'] * 3600;
779
+	} else {
780
+			$time = $log_time;
781
+	}
750 782
 
751 783
 	// We can't have a negative date (on Windows, at least.)
752
-	if ($log_time < 0)
753
-		$log_time = 0;
784
+	if ($log_time < 0) {
785
+			$log_time = 0;
786
+	}
754 787
 
755 788
 	// Today and Yesterday?
756 789
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -767,24 +800,27 @@  discard block
 block discarded – undo
767 800
 		{
768 801
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
769 802
 			$today_fmt = $h . ':%M' . $s . ' %p';
803
+		} else {
804
+					$today_fmt = '%H:%M' . $s;
770 805
 		}
771
-		else
772
-			$today_fmt = '%H:%M' . $s;
773 806
 
774 807
 		// Same day of the year, same year.... Today!
775
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
776
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
808
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
809
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
810
+		}
777 811
 
778 812
 		// Day-of-year is one less and same year, or it's the first of the year and that's the last of the year...
779
-		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31))
780
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
813
+		if ($modSettings['todayMod'] == '2' && (($then['yday'] == $now['yday'] - 1 && $then['year'] == $now['year']) || ($now['yday'] == 0 && $then['year'] == $now['year'] - 1) && $then['mon'] == 12 && $then['mday'] == 31)) {
814
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
815
+		}
781 816
 	}
782 817
 
783 818
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
784 819
 
785 820
 	// Use the cached formats if available
786
-	if (is_null($finalizedFormats))
787
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
821
+	if (is_null($finalizedFormats)) {
822
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
823
+	}
788 824
 
789 825
 	// Make a supported version for this format if we don't already have one
790 826
 	if (empty($finalizedFormats[$str]))
@@ -813,8 +849,9 @@  discard block
 block discarded – undo
813 849
 		);
814 850
 
815 851
 		// No need to do this part again if we already did it once
816
-		if (is_null($unsupportedFormats))
817
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
852
+		if (is_null($unsupportedFormats)) {
853
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
854
+		}
818 855
 		if (empty($unsupportedFormats))
819 856
 		{
820 857
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -823,20 +860,23 @@  discard block
 block discarded – undo
823 860
 
824 861
 				// Windows will return false for unsupported formats
825 862
 				// Other operating systems return the format string as a literal
826
-				if ($value === false || $value === $format)
827
-					$unsupportedFormats[] = $format;
863
+				if ($value === false || $value === $format) {
864
+									$unsupportedFormats[] = $format;
865
+				}
828 866
 			}
829 867
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
830 868
 		}
831 869
 
832 870
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
833
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
834
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
871
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
872
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
873
+		}
835 874
 
836 875
 		// Substitute unsupported formats with supported ones
837
-		if (!empty($unsupportedFormats))
838
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
876
+		if (!empty($unsupportedFormats)) {
877
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
839 878
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
879
+		}
840 880
 
841 881
 		// Remember this so we don't need to do it again
842 882
 		$finalizedFormats[$str] = $timeformat;
@@ -845,33 +885,39 @@  discard block
 block discarded – undo
845 885
 
846 886
 	$str = $finalizedFormats[$str];
847 887
 
848
-	if (!isset($locale_cache))
849
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
888
+	if (!isset($locale_cache)) {
889
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
890
+	}
850 891
 
851 892
 	if ($locale_cache !== false)
852 893
 	{
853 894
 		// Check if another process changed the locale
854
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
855
-			setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
895
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
896
+					setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
897
+		}
856 898
 
857
-		if (!isset($non_twelve_hour))
858
-			$non_twelve_hour = trim(strftime('%p')) === '';
859
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
860
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
899
+		if (!isset($non_twelve_hour)) {
900
+					$non_twelve_hour = trim(strftime('%p')) === '';
901
+		}
902
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
903
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
904
+		}
861 905
 
862
-		foreach (array('%a', '%A', '%b', '%B') as $token)
863
-			if (strpos($str, $token) !== false)
906
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
907
+					if (strpos($str, $token) !== false)
864 908
 				$str = str_replace($token, strftime($token, $time), $str);
865
-	}
866
-	else
909
+		}
910
+	} else
867 911
 	{
868 912
 		// Do-it-yourself time localization.  Fun.
869
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
870
-			if (strpos($str, $token) !== false)
913
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
914
+					if (strpos($str, $token) !== false)
871 915
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
916
+		}
872 917
 
873
-		if (strpos($str, '%p') !== false)
874
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
918
+		if (strpos($str, '%p') !== false) {
919
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
920
+		}
875 921
 	}
876 922
 
877 923
 	// Format the time and then restore any literal percent characters
@@ -894,16 +940,19 @@  discard block
 block discarded – undo
894 940
 	static $translation = array();
895 941
 
896 942
 	// Determine the character set... Default to UTF-8
897
-	if (empty($context['character_set']))
898
-		$charset = 'UTF-8';
943
+	if (empty($context['character_set'])) {
944
+			$charset = 'UTF-8';
945
+	}
899 946
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
900
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
901
-		$charset = 'ISO-8859-1';
902
-	else
903
-		$charset = $context['character_set'];
947
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
948
+			$charset = 'ISO-8859-1';
949
+	} else {
950
+			$charset = $context['character_set'];
951
+	}
904 952
 
905
-	if (empty($translation))
906
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
953
+	if (empty($translation)) {
954
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
955
+	}
907 956
 
908 957
 	return strtr($string, $translation);
909 958
 }
@@ -925,8 +974,9 @@  discard block
 block discarded – undo
925 974
 	global $smcFunc;
926 975
 
927 976
 	// It was already short enough!
928
-	if ($smcFunc['strlen']($subject) <= $len)
929
-		return $subject;
977
+	if ($smcFunc['strlen']($subject) <= $len) {
978
+			return $subject;
979
+	}
930 980
 
931 981
 	// Shorten it by the length it was too long, and strip off junk from the end.
932 982
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -945,10 +995,11 @@  discard block
 block discarded – undo
945 995
 {
946 996
 	global $user_info, $modSettings;
947 997
 
948
-	if ($timestamp === null)
949
-		$timestamp = time();
950
-	elseif ($timestamp == 0)
951
-		return 0;
998
+	if ($timestamp === null) {
999
+			$timestamp = time();
1000
+	} elseif ($timestamp == 0) {
1001
+			return 0;
1002
+	}
952 1003
 
953 1004
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
954 1005
 }
@@ -977,8 +1028,9 @@  discard block
 block discarded – undo
977 1028
 		$array[$i] = $array[$j];
978 1029
 		$array[$j] = $temp;
979 1030
 
980
-		for ($i = 1; $p[$i] == 0; $i++)
981
-			$p[$i] = 1;
1031
+		for ($i = 1; $p[$i] == 0; $i++) {
1032
+					$p[$i] = 1;
1033
+		}
982 1034
 
983 1035
 		$orders[] = $array;
984 1036
 	}
@@ -1010,12 +1062,14 @@  discard block
 block discarded – undo
1010 1062
 	static $disabled;
1011 1063
 
1012 1064
 	// Don't waste cycles
1013
-	if ($message === '')
1014
-		return '';
1065
+	if ($message === '') {
1066
+			return '';
1067
+	}
1015 1068
 
1016 1069
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1017
-	if (!isset($context['utf8']))
1018
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1070
+	if (!isset($context['utf8'])) {
1071
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1072
+	}
1019 1073
 
1020 1074
 	// Clean up any cut/paste issues we may have
1021 1075
 	$message = sanitizeMSCutPaste($message);
@@ -1027,13 +1081,15 @@  discard block
 block discarded – undo
1027 1081
 		return $message;
1028 1082
 	}
1029 1083
 
1030
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1031
-		$smileys = (bool) $smileys;
1084
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1085
+			$smileys = (bool) $smileys;
1086
+	}
1032 1087
 
1033 1088
 	if (empty($modSettings['enableBBC']) && $message !== false)
1034 1089
 	{
1035
-		if ($smileys === true)
1036
-			parsesmileys($message);
1090
+		if ($smileys === true) {
1091
+					parsesmileys($message);
1092
+		}
1037 1093
 
1038 1094
 		return $message;
1039 1095
 	}
@@ -1046,8 +1102,9 @@  discard block
 block discarded – undo
1046 1102
 	}
1047 1103
 
1048 1104
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1049
-	if (!empty($modSettings['autoLinkUrls']))
1050
-		set_tld_regex();
1105
+	if (!empty($modSettings['autoLinkUrls'])) {
1106
+			set_tld_regex();
1107
+	}
1051 1108
 
1052 1109
 	// Allow mods access before entering the main parse_bbc loop
1053 1110
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1061,12 +1118,14 @@  discard block
 block discarded – undo
1061 1118
 
1062 1119
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1063 1120
 
1064
-			foreach ($temp as $tag)
1065
-				$disabled[trim($tag)] = true;
1121
+			foreach ($temp as $tag) {
1122
+							$disabled[trim($tag)] = true;
1123
+			}
1066 1124
 		}
1067 1125
 
1068
-		if (empty($modSettings['enableEmbeddedFlash']))
1069
-			$disabled['flash'] = true;
1126
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1127
+					$disabled['flash'] = true;
1128
+		}
1070 1129
 
1071 1130
 		/* The following bbc are formatted as an array, with keys as follows:
1072 1131
 
@@ -1187,8 +1246,9 @@  discard block
 block discarded – undo
1187 1246
 					$returnContext = '';
1188 1247
 
1189 1248
 					// BBC or the entire attachments feature is disabled
1190
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1191
-						return $data;
1249
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1250
+											return $data;
1251
+					}
1192 1252
 
1193 1253
 					// Save the attach ID.
1194 1254
 					$attachID = $data;
@@ -1199,8 +1259,9 @@  discard block
 block discarded – undo
1199 1259
 					$currentAttachment = parseAttachBBC($attachID);
1200 1260
 
1201 1261
 					// parseAttachBBC will return a string ($txt key) rather than diying with a fatal_error. Up to you to decide what to do.
1202
-					if (is_string($currentAttachment))
1203
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1262
+					if (is_string($currentAttachment)) {
1263
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1264
+					}
1204 1265
 
1205 1266
 					if (!empty($currentAttachment['is_image']))
1206 1267
 					{
@@ -1216,15 +1277,17 @@  discard block
 block discarded – undo
1216 1277
 							$height = ' height="' . $currentAttachment['height'] . '"';
1217 1278
 						}
1218 1279
 
1219
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1220
-							$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1221
-						else
1222
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1280
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1281
+													$returnContext .= '<a href="'. $currentAttachment['href']. ';image" id="link_'. $currentAttachment['id']. '" onclick="'. $currentAttachment['thumbnail']['javascript']. '"><img src="'. $currentAttachment['thumbnail']['href']. '"' . $alt . $title . ' id="thumb_'. $currentAttachment['id']. '" class="atc_img"></a>';
1282
+						} else {
1283
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1284
+						}
1223 1285
 					}
1224 1286
 
1225 1287
 					// No image. Show a link.
1226
-					else
1227
-						$returnContext .= $currentAttachment['link'];
1288
+					else {
1289
+											$returnContext .= $currentAttachment['link'];
1290
+					}
1228 1291
 
1229 1292
 					// Gotta append what we just did.
1230 1293
 					$data = $returnContext;
@@ -1255,8 +1318,9 @@  discard block
 block discarded – undo
1255 1318
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1256 1319
 						{
1257 1320
 							// Do PHP code coloring?
1258
-							if ($php_parts[$php_i] != '&lt;?php')
1259
-								continue;
1321
+							if ($php_parts[$php_i] != '&lt;?php') {
1322
+															continue;
1323
+							}
1260 1324
 
1261 1325
 							$php_string = '';
1262 1326
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1272,8 +1336,9 @@  discard block
 block discarded – undo
1272 1336
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1273 1337
 
1274 1338
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1275
-						if ($context['browser']['is_opera'])
1276
-							$data .= '&nbsp;';
1339
+						if ($context['browser']['is_opera']) {
1340
+													$data .= '&nbsp;';
1341
+						}
1277 1342
 					}
1278 1343
 				},
1279 1344
 				'block_level' => true,
@@ -1292,8 +1357,9 @@  discard block
 block discarded – undo
1292 1357
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1293 1358
 						{
1294 1359
 							// Do PHP code coloring?
1295
-							if ($php_parts[$php_i] != '&lt;?php')
1296
-								continue;
1360
+							if ($php_parts[$php_i] != '&lt;?php') {
1361
+															continue;
1362
+							}
1297 1363
 
1298 1364
 							$php_string = '';
1299 1365
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1309,8 +1375,9 @@  discard block
 block discarded – undo
1309 1375
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1310 1376
 
1311 1377
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1312
-						if ($context['browser']['is_opera'])
1313
-							$data[0] .= '&nbsp;';
1378
+						if ($context['browser']['is_opera']) {
1379
+													$data[0] .= '&nbsp;';
1380
+						}
1314 1381
 					}
1315 1382
 				},
1316 1383
 				'block_level' => true,
@@ -1348,11 +1415,13 @@  discard block
 block discarded – undo
1348 1415
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1349 1416
 				'validate' => function (&$tag, &$data, $disabled)
1350 1417
 				{
1351
-					if (isset($disabled['url']))
1352
-						$tag['content'] = '$1';
1418
+					if (isset($disabled['url'])) {
1419
+											$tag['content'] = '$1';
1420
+					}
1353 1421
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1354
-					if (empty($scheme))
1355
-						$data[0] = '//' . ltrim($data[0], ':/');
1422
+					if (empty($scheme)) {
1423
+											$data[0] = '//' . ltrim($data[0], ':/');
1424
+					}
1356 1425
 				},
1357 1426
 				'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>',
1358 1427
 			),
@@ -1366,10 +1435,11 @@  discard block
 block discarded – undo
1366 1435
 				{
1367 1436
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1368 1437
 
1369
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1370
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1371
-					else
1372
-						$css = '';
1438
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1439
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1440
+					} else {
1441
+											$css = '';
1442
+					}
1373 1443
 
1374 1444
 					$data = $class . $css;
1375 1445
 				},
@@ -1419,17 +1489,20 @@  discard block
 block discarded – undo
1419 1489
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1420 1490
 					if ($image_proxy_enabled)
1421 1491
 					{
1422
-						if (!empty($user_info['possibly_robot']))
1423
-							return;
1492
+						if (!empty($user_info['possibly_robot'])) {
1493
+													return;
1494
+						}
1424 1495
 
1425
-						if (empty($scheme))
1426
-							$data = 'http://' . ltrim($data, ':/');
1496
+						if (empty($scheme)) {
1497
+													$data = 'http://' . ltrim($data, ':/');
1498
+						}
1427 1499
 
1428
-						if ($scheme != 'https')
1429
-							$data = get_proxied_url($data);
1500
+						if ($scheme != 'https') {
1501
+													$data = get_proxied_url($data);
1502
+						}
1503
+					} elseif (empty($scheme)) {
1504
+											$data = '//' . ltrim($data, ':/');
1430 1505
 					}
1431
-					elseif (empty($scheme))
1432
-						$data = '//' . ltrim($data, ':/');
1433 1506
 				},
1434 1507
 				'disabled_content' => '($1)',
1435 1508
 			),
@@ -1445,17 +1518,20 @@  discard block
 block discarded – undo
1445 1518
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1446 1519
 					if ($image_proxy_enabled)
1447 1520
 					{
1448
-						if (!empty($user_info['possibly_robot']))
1449
-							return;
1521
+						if (!empty($user_info['possibly_robot'])) {
1522
+													return;
1523
+						}
1450 1524
 
1451
-						if (empty($scheme))
1452
-							$data = 'http://' . ltrim($data, ':/');
1525
+						if (empty($scheme)) {
1526
+													$data = 'http://' . ltrim($data, ':/');
1527
+						}
1453 1528
 
1454
-						if ($scheme != 'https')
1455
-							$data = get_proxied_url($data);
1529
+						if ($scheme != 'https') {
1530
+													$data = get_proxied_url($data);
1531
+						}
1532
+					} elseif (empty($scheme)) {
1533
+											$data = '//' . ltrim($data, ':/');
1456 1534
 					}
1457
-					elseif (empty($scheme))
1458
-						$data = '//' . ltrim($data, ':/');
1459 1535
 				},
1460 1536
 				'disabled_content' => '($1)',
1461 1537
 			),
@@ -1467,8 +1543,9 @@  discard block
 block discarded – undo
1467 1543
 				{
1468 1544
 					$data = strtr($data, array('<br>' => ''));
1469 1545
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1470
-					if (empty($scheme))
1471
-						$data = '//' . ltrim($data, ':/');
1546
+					if (empty($scheme)) {
1547
+											$data = '//' . ltrim($data, ':/');
1548
+					}
1472 1549
 				},
1473 1550
 			),
1474 1551
 			array(
@@ -1479,13 +1556,14 @@  discard block
 block discarded – undo
1479 1556
 				'after' => '</a>',
1480 1557
 				'validate' => function (&$tag, &$data, $disabled)
1481 1558
 				{
1482
-					if (substr($data, 0, 1) == '#')
1483
-						$data = '#post_' . substr($data, 1);
1484
-					else
1559
+					if (substr($data, 0, 1) == '#') {
1560
+											$data = '#post_' . substr($data, 1);
1561
+					} else
1485 1562
 					{
1486 1563
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1487
-						if (empty($scheme))
1488
-							$data = '//' . ltrim($data, ':/');
1564
+						if (empty($scheme)) {
1565
+													$data = '//' . ltrim($data, ':/');
1566
+						}
1489 1567
 					}
1490 1568
 				},
1491 1569
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1569,8 +1647,9 @@  discard block
 block discarded – undo
1569 1647
 					{
1570 1648
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1571 1649
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1572
-						if ($add_begin)
1573
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1650
+						if ($add_begin) {
1651
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1652
+						}
1574 1653
 					}
1575 1654
 				},
1576 1655
 				'block_level' => false,
@@ -1701,10 +1780,11 @@  discard block
 block discarded – undo
1701 1780
 				'content' => '$1',
1702 1781
 				'validate' => function (&$tag, &$data, $disabled)
1703 1782
 				{
1704
-					if (is_numeric($data))
1705
-						$data = timeformat($data);
1706
-					else
1707
-						$tag['content'] = '[time]$1[/time]';
1783
+					if (is_numeric($data)) {
1784
+											$data = timeformat($data);
1785
+					} else {
1786
+											$tag['content'] = '[time]$1[/time]';
1787
+					}
1708 1788
 				},
1709 1789
 			),
1710 1790
 			array(
@@ -1731,8 +1811,9 @@  discard block
 block discarded – undo
1731 1811
 				{
1732 1812
 					$data = strtr($data, array('<br>' => ''));
1733 1813
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1734
-					if (empty($scheme))
1735
-						$data = '//' . ltrim($data, ':/');
1814
+					if (empty($scheme)) {
1815
+											$data = '//' . ltrim($data, ':/');
1816
+					}
1736 1817
 				},
1737 1818
 			),
1738 1819
 			array(
@@ -1744,8 +1825,9 @@  discard block
 block discarded – undo
1744 1825
 				'validate' => function (&$tag, &$data, $disabled)
1745 1826
 				{
1746 1827
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1747
-					if (empty($scheme))
1748
-						$data = '//' . ltrim($data, ':/');
1828
+					if (empty($scheme)) {
1829
+											$data = '//' . ltrim($data, ':/');
1830
+					}
1749 1831
 				},
1750 1832
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1751 1833
 				'disabled_after' => ' ($1)',
@@ -1771,8 +1853,9 @@  discard block
 block discarded – undo
1771 1853
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1772 1854
 		if ($message === false)
1773 1855
 		{
1774
-			if (isset($temp_bbc))
1775
-				$bbc_codes = $temp_bbc;
1856
+			if (isset($temp_bbc)) {
1857
+							$bbc_codes = $temp_bbc;
1858
+			}
1776 1859
 			usort($codes, function ($a, $b) {
1777 1860
 				return strcmp($a['tag'], $b['tag']);
1778 1861
 			});
@@ -1792,8 +1875,9 @@  discard block
 block discarded – undo
1792 1875
 		);
1793 1876
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1794 1877
 		{
1795
-			foreach ($itemcodes as $c => $dummy)
1796
-				$bbc_codes[$c] = array();
1878
+			foreach ($itemcodes as $c => $dummy) {
1879
+							$bbc_codes[$c] = array();
1880
+			}
1797 1881
 		}
1798 1882
 
1799 1883
 		// Shhhh!
@@ -1814,12 +1898,14 @@  discard block
 block discarded – undo
1814 1898
 		foreach ($codes as $code)
1815 1899
 		{
1816 1900
 			// Make it easier to process parameters later
1817
-			if (!empty($code['parameters']))
1818
-				ksort($code['parameters'], SORT_STRING);
1901
+			if (!empty($code['parameters'])) {
1902
+							ksort($code['parameters'], SORT_STRING);
1903
+			}
1819 1904
 
1820 1905
 			// If we are not doing every tag only do ones we are interested in.
1821
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1822
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1906
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
1907
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
1908
+			}
1823 1909
 		}
1824 1910
 		$codes = null;
1825 1911
 	}
@@ -1830,8 +1916,9 @@  discard block
 block discarded – undo
1830 1916
 		// It's likely this will change if the message is modified.
1831 1917
 		$cache_key = 'parse:' . $cache_id . '-' . md5(md5($message) . '-' . $smileys . (empty($disabled) ? '' : implode(',', array_keys($disabled))) . $smcFunc['json_encode']($context['browser']) . $txt['lang_locale'] . $user_info['time_offset'] . $user_info['time_format']);
1832 1918
 
1833
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1834
-			return $temp;
1919
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
1920
+					return $temp;
1921
+		}
1835 1922
 
1836 1923
 		$cache_t = microtime();
1837 1924
 	}
@@ -1863,8 +1950,9 @@  discard block
 block discarded – undo
1863 1950
 		$disabled['flash'] = true;
1864 1951
 
1865 1952
 		// @todo Change maybe?
1866
-		if (!isset($_GET['images']))
1867
-			$disabled['img'] = true;
1953
+		if (!isset($_GET['images'])) {
1954
+					$disabled['img'] = true;
1955
+		}
1868 1956
 
1869 1957
 		// @todo Interface/setting to add more?
1870 1958
 	}
@@ -1875,8 +1963,9 @@  discard block
 block discarded – undo
1875 1963
 	$alltags = array();
1876 1964
 	foreach ($bbc_codes as $section)
1877 1965
 	{
1878
-		foreach ($section as $code)
1879
-			$alltags[] = $code['tag'];
1966
+		foreach ($section as $code) {
1967
+					$alltags[] = $code['tag'];
1968
+		}
1880 1969
 	}
1881 1970
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
1882 1971
 
@@ -1888,8 +1977,9 @@  discard block
 block discarded – undo
1888 1977
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
1889 1978
 
1890 1979
 		// Failsafe.
1891
-		if ($pos === false || $last_pos > $pos)
1892
-			$pos = strlen($message) + 1;
1980
+		if ($pos === false || $last_pos > $pos) {
1981
+					$pos = strlen($message) + 1;
1982
+		}
1893 1983
 
1894 1984
 		// Can't have a one letter smiley, URL, or email! (sorry.)
1895 1985
 		if ($last_pos < $pos - 1)
@@ -1907,8 +1997,9 @@  discard block
 block discarded – undo
1907 1997
 
1908 1998
 				// <br> should be empty.
1909 1999
 				$empty_tags = array('br', 'hr');
1910
-				foreach ($empty_tags as $tag)
1911
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2000
+				foreach ($empty_tags as $tag) {
2001
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2002
+				}
1912 2003
 
1913 2004
 				// b, u, i, s, pre... basic tags.
1914 2005
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -1917,8 +2008,9 @@  discard block
 block discarded – undo
1917 2008
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
1918 2009
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
1919 2010
 
1920
-					if ($diff > 0)
1921
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2011
+					if ($diff > 0) {
2012
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2013
+					}
1922 2014
 				}
1923 2015
 
1924 2016
 				// Do <img ...> - with security... action= -> action-.
@@ -1931,8 +2023,9 @@  discard block
 block discarded – undo
1931 2023
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
1932 2024
 
1933 2025
 						// Remove action= from the URL - no funny business, now.
1934
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
1935
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2026
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2027
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2028
+						}
1936 2029
 
1937 2030
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
1938 2031
 					}
@@ -1947,16 +2040,18 @@  discard block
 block discarded – undo
1947 2040
 				$no_autolink_area = false;
1948 2041
 				if (!empty($open_tags))
1949 2042
 				{
1950
-					foreach ($open_tags as $open_tag)
1951
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2043
+					foreach ($open_tags as $open_tag) {
2044
+											if (in_array($open_tag['tag'], $no_autolink_tags))
1952 2045
 							$no_autolink_area = true;
2046
+					}
1953 2047
 				}
1954 2048
 
1955 2049
 				// Don't go backwards.
1956 2050
 				// @todo Don't think is the real solution....
1957 2051
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
1958
-				if ($pos < $lastAutoPos)
1959
-					$no_autolink_area = true;
2052
+				if ($pos < $lastAutoPos) {
2053
+									$no_autolink_area = true;
2054
+				}
1960 2055
 				$lastAutoPos = $pos;
1961 2056
 
1962 2057
 				if (!$no_autolink_area)
@@ -2061,29 +2156,33 @@  discard block
 block discarded – undo
2061 2156
 							$url = array_shift($matches);
2062 2157
 
2063 2158
 							// If this isn't a clean URL, bail out
2064
-							if ($url != sanitize_iri($url))
2065
-								return $url;
2159
+							if ($url != sanitize_iri($url)) {
2160
+															return $url;
2161
+							}
2066 2162
 
2067 2163
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2068 2164
 
2069 2165
 							if ($scheme == 'mailto')
2070 2166
 							{
2071 2167
 								$email_address = str_replace('mailto:', '', $url);
2072
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2073
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2074
-								else
2075
-									return $url;
2168
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2169
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2170
+								} else {
2171
+																	return $url;
2172
+								}
2076 2173
 							}
2077 2174
 
2078 2175
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2079
-							if (empty($scheme))
2080
-								$fullUrl = '//' . ltrim($url, ':/');
2081
-							else
2082
-								$fullUrl = $url;
2176
+							if (empty($scheme)) {
2177
+															$fullUrl = '//' . ltrim($url, ':/');
2178
+							} else {
2179
+															$fullUrl = $url;
2180
+							}
2083 2181
 
2084 2182
 							// Make sure that $fullUrl really is valid
2085
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2086
-								return $url;
2183
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2184
+															return $url;
2185
+							}
2087 2186
 
2088 2187
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2089 2188
 						}, $data);
@@ -2132,22 +2231,25 @@  discard block
 block discarded – undo
2132 2231
 		}
2133 2232
 
2134 2233
 		// Are we there yet?  Are we there yet?
2135
-		if ($pos >= strlen($message) - 1)
2136
-			break;
2234
+		if ($pos >= strlen($message) - 1) {
2235
+					break;
2236
+		}
2137 2237
 
2138 2238
 		$tags = strtolower($message[$pos + 1]);
2139 2239
 
2140 2240
 		if ($tags == '/' && !empty($open_tags))
2141 2241
 		{
2142 2242
 			$pos2 = strpos($message, ']', $pos + 1);
2143
-			if ($pos2 == $pos + 2)
2144
-				continue;
2243
+			if ($pos2 == $pos + 2) {
2244
+							continue;
2245
+			}
2145 2246
 
2146 2247
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2147 2248
 
2148 2249
 			// A closing tag that doesn't match any open tags? Skip it.
2149
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2150
-				continue;
2250
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2251
+							continue;
2252
+			}
2151 2253
 
2152 2254
 			$to_close = array();
2153 2255
 			$block_level = null;
@@ -2155,8 +2257,9 @@  discard block
 block discarded – undo
2155 2257
 			do
2156 2258
 			{
2157 2259
 				$tag = array_pop($open_tags);
2158
-				if (!$tag)
2159
-					break;
2260
+				if (!$tag) {
2261
+									break;
2262
+				}
2160 2263
 
2161 2264
 				if (!empty($tag['block_level']))
2162 2265
 				{
@@ -2170,10 +2273,11 @@  discard block
 block discarded – undo
2170 2273
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2171 2274
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2172 2275
 					{
2173
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2174
-							if ($temp['tag'] == $look_for)
2276
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2277
+													if ($temp['tag'] == $look_for)
2175 2278
 							{
2176 2279
 								$block_level = !empty($temp['block_level']);
2280
+						}
2177 2281
 								break;
2178 2282
 							}
2179 2283
 					}
@@ -2195,15 +2299,15 @@  discard block
 block discarded – undo
2195 2299
 			{
2196 2300
 				$open_tags = $to_close;
2197 2301
 				continue;
2198
-			}
2199
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2302
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2200 2303
 			{
2201 2304
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2202 2305
 				{
2203
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2204
-						if ($temp['tag'] == $look_for)
2306
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2307
+											if ($temp['tag'] == $look_for)
2205 2308
 						{
2206 2309
 							$block_level = !empty($temp['block_level']);
2310
+					}
2207 2311
 							break;
2208 2312
 						}
2209 2313
 				}
@@ -2211,8 +2315,9 @@  discard block
 block discarded – undo
2211 2315
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2212 2316
 				if (!$block_level)
2213 2317
 				{
2214
-					foreach ($to_close as $tag)
2215
-						array_push($open_tags, $tag);
2318
+					foreach ($to_close as $tag) {
2319
+											array_push($open_tags, $tag);
2320
+					}
2216 2321
 					continue;
2217 2322
 				}
2218 2323
 			}
@@ -2225,14 +2330,17 @@  discard block
 block discarded – undo
2225 2330
 
2226 2331
 				// See the comment at the end of the big loop - just eating whitespace ;).
2227 2332
 				$whitespace_regex = '';
2228
-				if (!empty($tag['block_level']))
2229
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2333
+				if (!empty($tag['block_level'])) {
2334
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2335
+				}
2230 2336
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2231
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2232
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2337
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2338
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2339
+				}
2233 2340
 
2234
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2235
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2341
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2342
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2343
+				}
2236 2344
 			}
2237 2345
 
2238 2346
 			if (!empty($to_close))
@@ -2245,8 +2353,9 @@  discard block
 block discarded – undo
2245 2353
 		}
2246 2354
 
2247 2355
 		// No tags for this character, so just keep going (fastest possible course.)
2248
-		if (!isset($bbc_codes[$tags]))
2249
-			continue;
2356
+		if (!isset($bbc_codes[$tags])) {
2357
+					continue;
2358
+		}
2250 2359
 
2251 2360
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2252 2361
 		$tag = null;
@@ -2255,48 +2364,57 @@  discard block
 block discarded – undo
2255 2364
 			$pt_strlen = strlen($possible['tag']);
2256 2365
 
2257 2366
 			// Not a match?
2258
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2259
-				continue;
2367
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2368
+							continue;
2369
+			}
2260 2370
 
2261 2371
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2262 2372
 
2263 2373
 			// A tag is the last char maybe
2264
-			if ($next_c == '')
2265
-				break;
2374
+			if ($next_c == '') {
2375
+							break;
2376
+			}
2266 2377
 
2267 2378
 			// A test validation?
2268
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2269
-				continue;
2379
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2380
+							continue;
2381
+			}
2270 2382
 			// Do we want parameters?
2271 2383
 			elseif (!empty($possible['parameters']))
2272 2384
 			{
2273
-				if ($next_c != ' ')
2274
-					continue;
2275
-			}
2276
-			elseif (isset($possible['type']))
2385
+				if ($next_c != ' ') {
2386
+									continue;
2387
+				}
2388
+			} elseif (isset($possible['type']))
2277 2389
 			{
2278 2390
 				// Do we need an equal sign?
2279
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2280
-					continue;
2391
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2392
+									continue;
2393
+				}
2281 2394
 				// Maybe we just want a /...
2282
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2283
-					continue;
2395
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2396
+									continue;
2397
+				}
2284 2398
 				// An immediate ]?
2285
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2286
-					continue;
2399
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2400
+									continue;
2401
+				}
2287 2402
 			}
2288 2403
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2289
-			elseif ($next_c != ']')
2290
-				continue;
2404
+			elseif ($next_c != ']') {
2405
+							continue;
2406
+			}
2291 2407
 
2292 2408
 			// Check allowed tree?
2293
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2294
-				continue;
2295
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2296
-				continue;
2409
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2410
+							continue;
2411
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2412
+							continue;
2413
+			}
2297 2414
 			// If this is in the list of disallowed child tags, don't parse it.
2298
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2299
-				continue;
2415
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2416
+							continue;
2417
+			}
2300 2418
 
2301 2419
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2302 2420
 
@@ -2308,8 +2426,9 @@  discard block
 block discarded – undo
2308 2426
 				foreach ($open_tags as $open_quote)
2309 2427
 				{
2310 2428
 					// Every parent quote this quote has flips the styling
2311
-					if ($open_quote['tag'] == 'quote')
2312
-						$quote_alt = !$quote_alt;
2429
+					if ($open_quote['tag'] == 'quote') {
2430
+											$quote_alt = !$quote_alt;
2431
+					}
2313 2432
 				}
2314 2433
 				// Add a class to the quote to style alternating blockquotes
2315 2434
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2320,8 +2439,9 @@  discard block
 block discarded – undo
2320 2439
 			{
2321 2440
 				// Build a regular expression for each parameter for the current tag.
2322 2441
 				$preg = array();
2323
-				foreach ($possible['parameters'] as $p => $info)
2324
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2442
+				foreach ($possible['parameters'] as $p => $info) {
2443
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2444
+				}
2325 2445
 
2326 2446
 				// Extract the string that potentially holds our parameters.
2327 2447
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2340,24 +2460,27 @@  discard block
 block discarded – undo
2340 2460
 
2341 2461
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2342 2462
 
2343
-					if ($match)
2344
-						$blob_counter = count($blobs) + 1;
2463
+					if ($match) {
2464
+											$blob_counter = count($blobs) + 1;
2465
+					}
2345 2466
 				}
2346 2467
 
2347 2468
 				// Didn't match our parameter list, try the next possible.
2348
-				if (!$match)
2349
-					continue;
2469
+				if (!$match) {
2470
+									continue;
2471
+				}
2350 2472
 
2351 2473
 				$params = array();
2352 2474
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2353 2475
 				{
2354 2476
 					$key = strtok(ltrim($matches[$i]), '=');
2355
-					if (isset($possible['parameters'][$key]['value']))
2356
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2357
-					elseif (isset($possible['parameters'][$key]['validate']))
2358
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2359
-					else
2360
-						$params['{' . $key . '}'] = $matches[$i + 1];
2477
+					if (isset($possible['parameters'][$key]['value'])) {
2478
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2479
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2480
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2481
+					} else {
2482
+											$params['{' . $key . '}'] = $matches[$i + 1];
2483
+					}
2361 2484
 
2362 2485
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2363 2486
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2365,23 +2488,26 @@  discard block
 block discarded – undo
2365 2488
 
2366 2489
 				foreach ($possible['parameters'] as $p => $info)
2367 2490
 				{
2368
-					if (!isset($params['{' . $p . '}']))
2369
-						$params['{' . $p . '}'] = '';
2491
+					if (!isset($params['{' . $p . '}'])) {
2492
+											$params['{' . $p . '}'] = '';
2493
+					}
2370 2494
 				}
2371 2495
 
2372 2496
 				$tag = $possible;
2373 2497
 
2374 2498
 				// Put the parameters into the string.
2375
-				if (isset($tag['before']))
2376
-					$tag['before'] = strtr($tag['before'], $params);
2377
-				if (isset($tag['after']))
2378
-					$tag['after'] = strtr($tag['after'], $params);
2379
-				if (isset($tag['content']))
2380
-					$tag['content'] = strtr($tag['content'], $params);
2499
+				if (isset($tag['before'])) {
2500
+									$tag['before'] = strtr($tag['before'], $params);
2501
+				}
2502
+				if (isset($tag['after'])) {
2503
+									$tag['after'] = strtr($tag['after'], $params);
2504
+				}
2505
+				if (isset($tag['content'])) {
2506
+									$tag['content'] = strtr($tag['content'], $params);
2507
+				}
2381 2508
 
2382 2509
 				$pos1 += strlen($given_param_string);
2383
-			}
2384
-			else
2510
+			} else
2385 2511
 			{
2386 2512
 				$tag = $possible;
2387 2513
 				$params = array();
@@ -2392,8 +2518,9 @@  discard block
 block discarded – undo
2392 2518
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2393 2519
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2394 2520
 		{
2395
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2396
-				continue;
2521
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2522
+							continue;
2523
+			}
2397 2524
 
2398 2525
 			$tag = $itemcodes[$message[$pos + 1]];
2399 2526
 
@@ -2414,9 +2541,9 @@  discard block
 block discarded – undo
2414 2541
 			{
2415 2542
 				array_pop($open_tags);
2416 2543
 				$code = '</li>';
2544
+			} else {
2545
+							$code = '';
2417 2546
 			}
2418
-			else
2419
-				$code = '';
2420 2547
 
2421 2548
 			// Now we open a new tag.
2422 2549
 			$open_tags[] = array(
@@ -2463,12 +2590,14 @@  discard block
 block discarded – undo
2463 2590
 		}
2464 2591
 
2465 2592
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2466
-		if ($tag === null)
2467
-			continue;
2593
+		if ($tag === null) {
2594
+					continue;
2595
+		}
2468 2596
 
2469 2597
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2470
-		if (isset($inside['disallow_children']))
2471
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2598
+		if (isset($inside['disallow_children'])) {
2599
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2600
+		}
2472 2601
 
2473 2602
 		// Is this tag disabled?
2474 2603
 		if (isset($disabled[$tag['tag']]))
@@ -2478,14 +2607,13 @@  discard block
 block discarded – undo
2478 2607
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2479 2608
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2480 2609
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2481
-			}
2482
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2610
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2483 2611
 			{
2484 2612
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2485 2613
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2614
+			} else {
2615
+							$tag['content'] = $tag['disabled_content'];
2486 2616
 			}
2487
-			else
2488
-				$tag['content'] = $tag['disabled_content'];
2489 2617
 		}
2490 2618
 
2491 2619
 		// we use this a lot
@@ -2495,8 +2623,9 @@  discard block
 block discarded – undo
2495 2623
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2496 2624
 		{
2497 2625
 			$n = count($open_tags) - 1;
2498
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2499
-				$n--;
2626
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2627
+							$n--;
2628
+			}
2500 2629
 
2501 2630
 			// Close all the non block level tags so this tag isn't surrounded by them.
2502 2631
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2508,12 +2637,15 @@  discard block
 block discarded – undo
2508 2637
 
2509 2638
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2510 2639
 				$whitespace_regex = '';
2511
-				if (!empty($tag['block_level']))
2512
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2513
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2514
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2515
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2516
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2640
+				if (!empty($tag['block_level'])) {
2641
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2642
+				}
2643
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2644
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2645
+				}
2646
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2647
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2648
+				}
2517 2649
 
2518 2650
 				array_pop($open_tags);
2519 2651
 			}
@@ -2534,16 +2666,19 @@  discard block
 block discarded – undo
2534 2666
 		elseif ($tag['type'] == 'unparsed_content')
2535 2667
 		{
2536 2668
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2537
-			if ($pos2 === false)
2538
-				continue;
2669
+			if ($pos2 === false) {
2670
+							continue;
2671
+			}
2539 2672
 
2540 2673
 			$data = substr($message, $pos1, $pos2 - $pos1);
2541 2674
 
2542
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2543
-				$data = substr($data, 4);
2675
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2676
+							$data = substr($data, 4);
2677
+			}
2544 2678
 
2545
-			if (isset($tag['validate']))
2546
-				$tag['validate']($tag, $data, $disabled, $params);
2679
+			if (isset($tag['validate'])) {
2680
+							$tag['validate']($tag, $data, $disabled, $params);
2681
+			}
2547 2682
 
2548 2683
 			$code = strtr($tag['content'], array('$1' => $data));
2549 2684
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2558,34 +2693,40 @@  discard block
 block discarded – undo
2558 2693
 			if (isset($tag['quoted']))
2559 2694
 			{
2560 2695
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2561
-				if ($tag['quoted'] != 'optional' && !$quoted)
2562
-					continue;
2696
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2697
+									continue;
2698
+				}
2563 2699
 
2564
-				if ($quoted)
2565
-					$pos1 += 6;
2700
+				if ($quoted) {
2701
+									$pos1 += 6;
2702
+				}
2703
+			} else {
2704
+							$quoted = false;
2566 2705
 			}
2567
-			else
2568
-				$quoted = false;
2569 2706
 
2570 2707
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2571
-			if ($pos2 === false)
2572
-				continue;
2708
+			if ($pos2 === false) {
2709
+							continue;
2710
+			}
2573 2711
 
2574 2712
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2575
-			if ($pos3 === false)
2576
-				continue;
2713
+			if ($pos3 === false) {
2714
+							continue;
2715
+			}
2577 2716
 
2578 2717
 			$data = array(
2579 2718
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2580 2719
 				substr($message, $pos1, $pos2 - $pos1)
2581 2720
 			);
2582 2721
 
2583
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2584
-				$data[0] = substr($data[0], 4);
2722
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2723
+							$data[0] = substr($data[0], 4);
2724
+			}
2585 2725
 
2586 2726
 			// Validation for my parking, please!
2587
-			if (isset($tag['validate']))
2588
-				$tag['validate']($tag, $data, $disabled, $params);
2727
+			if (isset($tag['validate'])) {
2728
+							$tag['validate']($tag, $data, $disabled, $params);
2729
+			}
2589 2730
 
2590 2731
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2591 2732
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2602,23 +2743,27 @@  discard block
 block discarded – undo
2602 2743
 		elseif ($tag['type'] == 'unparsed_commas_content')
2603 2744
 		{
2604 2745
 			$pos2 = strpos($message, ']', $pos1);
2605
-			if ($pos2 === false)
2606
-				continue;
2746
+			if ($pos2 === false) {
2747
+							continue;
2748
+			}
2607 2749
 
2608 2750
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2609
-			if ($pos3 === false)
2610
-				continue;
2751
+			if ($pos3 === false) {
2752
+							continue;
2753
+			}
2611 2754
 
2612 2755
 			// We want $1 to be the content, and the rest to be csv.
2613 2756
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2614 2757
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2615 2758
 
2616
-			if (isset($tag['validate']))
2617
-				$tag['validate']($tag, $data, $disabled, $params);
2759
+			if (isset($tag['validate'])) {
2760
+							$tag['validate']($tag, $data, $disabled, $params);
2761
+			}
2618 2762
 
2619 2763
 			$code = $tag['content'];
2620
-			foreach ($data as $k => $d)
2621
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2764
+			foreach ($data as $k => $d) {
2765
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2766
+			}
2622 2767
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2623 2768
 			$pos += strlen($code) - 1 + 2;
2624 2769
 		}
@@ -2626,24 +2771,28 @@  discard block
 block discarded – undo
2626 2771
 		elseif ($tag['type'] == 'unparsed_commas')
2627 2772
 		{
2628 2773
 			$pos2 = strpos($message, ']', $pos1);
2629
-			if ($pos2 === false)
2630
-				continue;
2774
+			if ($pos2 === false) {
2775
+							continue;
2776
+			}
2631 2777
 
2632 2778
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2633 2779
 
2634
-			if (isset($tag['validate']))
2635
-				$tag['validate']($tag, $data, $disabled, $params);
2780
+			if (isset($tag['validate'])) {
2781
+							$tag['validate']($tag, $data, $disabled, $params);
2782
+			}
2636 2783
 
2637 2784
 			// Fix after, for disabled code mainly.
2638
-			foreach ($data as $k => $d)
2639
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2785
+			foreach ($data as $k => $d) {
2786
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2787
+			}
2640 2788
 
2641 2789
 			$open_tags[] = $tag;
2642 2790
 
2643 2791
 			// Replace them out, $1, $2, $3, $4, etc.
2644 2792
 			$code = $tag['before'];
2645
-			foreach ($data as $k => $d)
2646
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2793
+			foreach ($data as $k => $d) {
2794
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2795
+			}
2647 2796
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2648 2797
 			$pos += strlen($code) - 1 + 2;
2649 2798
 		}
@@ -2654,28 +2803,33 @@  discard block
 block discarded – undo
2654 2803
 			if (isset($tag['quoted']))
2655 2804
 			{
2656 2805
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2657
-				if ($tag['quoted'] != 'optional' && !$quoted)
2658
-					continue;
2806
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2807
+									continue;
2808
+				}
2659 2809
 
2660
-				if ($quoted)
2661
-					$pos1 += 6;
2810
+				if ($quoted) {
2811
+									$pos1 += 6;
2812
+				}
2813
+			} else {
2814
+							$quoted = false;
2662 2815
 			}
2663
-			else
2664
-				$quoted = false;
2665 2816
 
2666 2817
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2667
-			if ($pos2 === false)
2668
-				continue;
2818
+			if ($pos2 === false) {
2819
+							continue;
2820
+			}
2669 2821
 
2670 2822
 			$data = substr($message, $pos1, $pos2 - $pos1);
2671 2823
 
2672 2824
 			// Validation for my parking, please!
2673
-			if (isset($tag['validate']))
2674
-				$tag['validate']($tag, $data, $disabled, $params);
2825
+			if (isset($tag['validate'])) {
2826
+							$tag['validate']($tag, $data, $disabled, $params);
2827
+			}
2675 2828
 
2676 2829
 			// For parsed content, we must recurse to avoid security problems.
2677
-			if ($tag['type'] != 'unparsed_equals')
2678
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2830
+			if ($tag['type'] != 'unparsed_equals') {
2831
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2832
+			}
2679 2833
 
2680 2834
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2681 2835
 
@@ -2687,34 +2841,40 @@  discard block
 block discarded – undo
2687 2841
 		}
2688 2842
 
2689 2843
 		// If this is block level, eat any breaks after it.
2690
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2691
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2844
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2845
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2846
+		}
2692 2847
 
2693 2848
 		// Are we trimming outside this tag?
2694
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2695
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2849
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
2850
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
2851
+		}
2696 2852
 	}
2697 2853
 
2698 2854
 	// Close any remaining tags.
2699
-	while ($tag = array_pop($open_tags))
2700
-		$message .= "\n" . $tag['after'] . "\n";
2855
+	while ($tag = array_pop($open_tags)) {
2856
+			$message .= "\n" . $tag['after'] . "\n";
2857
+	}
2701 2858
 
2702 2859
 	// Parse the smileys within the parts where it can be done safely.
2703 2860
 	if ($smileys === true)
2704 2861
 	{
2705 2862
 		$message_parts = explode("\n", $message);
2706
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2707
-			parsesmileys($message_parts[$i]);
2863
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
2864
+					parsesmileys($message_parts[$i]);
2865
+		}
2708 2866
 
2709 2867
 		$message = implode('', $message_parts);
2710 2868
 	}
2711 2869
 
2712 2870
 	// No smileys, just get rid of the markers.
2713
-	else
2714
-		$message = strtr($message, array("\n" => ''));
2871
+	else {
2872
+			$message = strtr($message, array("\n" => ''));
2873
+	}
2715 2874
 
2716
-	if ($message !== '' && $message[0] === ' ')
2717
-		$message = '&nbsp;' . substr($message, 1);
2875
+	if ($message !== '' && $message[0] === ' ') {
2876
+			$message = '&nbsp;' . substr($message, 1);
2877
+	}
2718 2878
 
2719 2879
 	// Cleanup whitespace.
2720 2880
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2723,15 +2883,16 @@  discard block
 block discarded – undo
2723 2883
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2724 2884
 
2725 2885
 	// Cache the output if it took some time...
2726
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2727
-		cache_put_data($cache_key, $message, 240);
2886
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
2887
+			cache_put_data($cache_key, $message, 240);
2888
+	}
2728 2889
 
2729 2890
 	// If this was a force parse revert if needed.
2730 2891
 	if (!empty($parse_tags))
2731 2892
 	{
2732
-		if (empty($temp_bbc))
2733
-			$bbc_codes = array();
2734
-		else
2893
+		if (empty($temp_bbc)) {
2894
+					$bbc_codes = array();
2895
+		} else
2735 2896
 		{
2736 2897
 			$bbc_codes = $temp_bbc;
2737 2898
 			unset($temp_bbc);
@@ -2758,8 +2919,9 @@  discard block
 block discarded – undo
2758 2919
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2759 2920
 
2760 2921
 	// No smiley set at all?!
2761
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2762
-		return;
2922
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
2923
+			return;
2924
+	}
2763 2925
 
2764 2926
 	// If smileyPregSearch hasn't been set, do it now.
2765 2927
 	if (empty($smileyPregSearch))
@@ -2770,8 +2932,7 @@  discard block
 block discarded – undo
2770 2932
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2771 2933
 			$smileysto = array('evil.png', 'cheesy.png', 'rolleyes.png', 'angry.png', 'laugh.png', 'smiley.png', 'wink.png', 'grin.png', 'sad.png', 'shocked.png', 'cool.png', 'tongue.png', 'huh.png', 'embarrassed.png', 'lipsrsealed.png', 'kiss.png', 'cry.png', 'undecided.png', 'azn.png', 'afro.png', 'police.png', 'angel.png');
2772 2934
 			$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
2773
-		}
2774
-		else
2935
+		} else
2775 2936
 		{
2776 2937
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2777 2938
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2795,9 +2956,9 @@  discard block
 block discarded – undo
2795 2956
 				$smcFunc['db_free_result']($result);
2796 2957
 
2797 2958
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
2959
+			} else {
2960
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2798 2961
 			}
2799
-			else
2800
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2801 2962
 		}
2802 2963
 
2803 2964
 		// The non-breaking-space is a complex thing...
@@ -2875,12 +3036,14 @@  discard block
 block discarded – undo
2875 3036
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
2876 3037
 
2877 3038
 	// Only use the proxy if enabled and necessary
2878
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
2879
-		return $url;
3039
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3040
+			return $url;
3041
+	}
2880 3042
 
2881 3043
 	// We don't need to proxy our own resources
2882
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
2883
-		return strtr($url, array('http://' => 'https://'));
3044
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3045
+			return strtr($url, array('http://' => 'https://'));
3046
+	}
2884 3047
 
2885 3048
 	// By default, use SMF's own image proxy script
2886 3049
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -2905,35 +3068,41 @@  discard block
 block discarded – undo
2905 3068
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
2906 3069
 
2907 3070
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
2908
-	if (!empty($context['flush_mail']))
2909
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3071
+	if (!empty($context['flush_mail'])) {
3072
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2910 3073
 		AddMailQueue(true);
3074
+	}
2911 3075
 
2912 3076
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
2913 3077
 
2914
-	if ($add)
2915
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3078
+	if ($add) {
3079
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3080
+	}
2916 3081
 
2917 3082
 	// Put the session ID in.
2918
-	if (defined('SID') && SID != '')
2919
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3083
+	if (defined('SID') && SID != '') {
3084
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3085
+	}
2920 3086
 	// Keep that debug in their for template debugging!
2921
-	elseif (isset($_GET['debug']))
2922
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3087
+	elseif (isset($_GET['debug'])) {
3088
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3089
+	}
2923 3090
 
2924 3091
 	if (!empty($modSettings['queryless_urls']) && (empty($context['server']['is_cgi']) || ini_get('cgi.fix_pathinfo') == 1 || @get_cfg_var('cgi.fix_pathinfo') == 1) && (!empty($context['server']['is_apache']) || !empty($context['server']['is_lighttpd']) || !empty($context['server']['is_litespeed'])))
2925 3092
 	{
2926
-		if (defined('SID') && SID != '')
2927
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3093
+		if (defined('SID') && SID != '') {
3094
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
2928 3095
 				function ($m) use ($scripturl)
2929 3096
 				{
2930 3097
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3098
+		}
2931 3099
 				}, $setLocation);
2932
-		else
2933
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3100
+		else {
3101
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
2934 3102
 				function ($m) use ($scripturl)
2935 3103
 				{
2936 3104
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3105
+		}
2937 3106
 				}, $setLocation);
2938 3107
 	}
2939 3108
 
@@ -2944,8 +3113,9 @@  discard block
 block discarded – undo
2944 3113
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
2945 3114
 
2946 3115
 	// Debugging.
2947
-	if (isset($db_show_debug) && $db_show_debug === true)
2948
-		$_SESSION['debug_redirect'] = $db_cache;
3116
+	if (isset($db_show_debug) && $db_show_debug === true) {
3117
+			$_SESSION['debug_redirect'] = $db_cache;
3118
+	}
2949 3119
 
2950 3120
 	obExit(false);
2951 3121
 }
@@ -2964,51 +3134,60 @@  discard block
 block discarded – undo
2964 3134
 
2965 3135
 	// Attempt to prevent a recursive loop.
2966 3136
 	++$level;
2967
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
2968
-		exit;
2969
-	if ($from_fatal_error)
2970
-		$has_fatal_error = true;
3137
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3138
+			exit;
3139
+	}
3140
+	if ($from_fatal_error) {
3141
+			$has_fatal_error = true;
3142
+	}
2971 3143
 
2972 3144
 	// Clear out the stat cache.
2973 3145
 	trackStats();
2974 3146
 
2975 3147
 	// If we have mail to send, send it.
2976
-	if (!empty($context['flush_mail']))
2977
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3148
+	if (!empty($context['flush_mail'])) {
3149
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
2978 3150
 		AddMailQueue(true);
3151
+	}
2979 3152
 
2980 3153
 	$do_header = $header === null ? !$header_done : $header;
2981
-	if ($do_footer === null)
2982
-		$do_footer = $do_header;
3154
+	if ($do_footer === null) {
3155
+			$do_footer = $do_header;
3156
+	}
2983 3157
 
2984 3158
 	// Has the template/header been done yet?
2985 3159
 	if ($do_header)
2986 3160
 	{
2987 3161
 		// Was the page title set last minute? Also update the HTML safe one.
2988
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
2989
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3162
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3163
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3164
+		}
2990 3165
 
2991 3166
 		// Start up the session URL fixer.
2992 3167
 		ob_start('ob_sessrewrite');
2993 3168
 
2994
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
2995
-			$buffers = explode(',', $settings['output_buffers']);
2996
-		elseif (!empty($settings['output_buffers']))
2997
-			$buffers = $settings['output_buffers'];
2998
-		else
2999
-			$buffers = array();
3169
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3170
+					$buffers = explode(',', $settings['output_buffers']);
3171
+		} elseif (!empty($settings['output_buffers'])) {
3172
+					$buffers = $settings['output_buffers'];
3173
+		} else {
3174
+					$buffers = array();
3175
+		}
3000 3176
 
3001
-		if (isset($modSettings['integrate_buffer']))
3002
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3177
+		if (isset($modSettings['integrate_buffer'])) {
3178
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3179
+		}
3003 3180
 
3004
-		if (!empty($buffers))
3005
-			foreach ($buffers as $function)
3181
+		if (!empty($buffers)) {
3182
+					foreach ($buffers as $function)
3006 3183
 			{
3007 3184
 				$call = call_helper($function, true);
3185
+		}
3008 3186
 
3009 3187
 				// Is it valid?
3010
-				if (!empty($call))
3011
-					ob_start($call);
3188
+				if (!empty($call)) {
3189
+									ob_start($call);
3190
+				}
3012 3191
 			}
3013 3192
 
3014 3193
 		// Display the screen in the logical order.
@@ -3020,8 +3199,9 @@  discard block
 block discarded – undo
3020 3199
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3021 3200
 
3022 3201
 		// Anything special to put out?
3023
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3024
-			echo $context['insert_after_template'];
3202
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3203
+					echo $context['insert_after_template'];
3204
+		}
3025 3205
 
3026 3206
 		// Just so we don't get caught in an endless loop of errors from the footer...
3027 3207
 		if (!$footer_done)
@@ -3030,14 +3210,16 @@  discard block
 block discarded – undo
3030 3210
 			template_footer();
3031 3211
 
3032 3212
 			// (since this is just debugging... it's okay that it's after </html>.)
3033
-			if (!isset($_REQUEST['xml']))
3034
-				displayDebug();
3213
+			if (!isset($_REQUEST['xml'])) {
3214
+							displayDebug();
3215
+			}
3035 3216
 		}
3036 3217
 	}
3037 3218
 
3038 3219
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3039
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3040
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3220
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3221
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3222
+	}
3041 3223
 
3042 3224
 	// For session check verification.... don't switch browsers...
3043 3225
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3046,9 +3228,10 @@  discard block
 block discarded – undo
3046 3228
 	call_integration_hook('integrate_exit', array($do_footer));
3047 3229
 
3048 3230
 	// Don't exit if we're coming from index.php; that will pass through normally.
3049
-	if (!$from_index)
3050
-		exit;
3051
-}
3231
+	if (!$from_index) {
3232
+			exit;
3233
+	}
3234
+	}
3052 3235
 
3053 3236
 /**
3054 3237
  * Get the size of a specified image with better error handling.
@@ -3067,8 +3250,9 @@  discard block
 block discarded – undo
3067 3250
 	$url = str_replace(' ', '%20', $url);
3068 3251
 
3069 3252
 	// Can we pull this from the cache... please please?
3070
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3071
-		return $temp;
3253
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3254
+			return $temp;
3255
+	}
3072 3256
 	$t = microtime();
3073 3257
 
3074 3258
 	// Get the host to pester...
@@ -3078,12 +3262,10 @@  discard block
 block discarded – undo
3078 3262
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3079 3263
 	{
3080 3264
 		return false;
3081
-	}
3082
-	elseif (!isset($match[1]))
3265
+	} elseif (!isset($match[1]))
3083 3266
 	{
3084 3267
 		$size = @getimagesize($url);
3085
-	}
3086
-	else
3268
+	} else
3087 3269
 	{
3088 3270
 		// Try to connect to the server... give it half a second.
3089 3271
 		$temp = 0;
@@ -3120,12 +3302,14 @@  discard block
 block discarded – undo
3120 3302
 	}
3121 3303
 
3122 3304
 	// If we didn't get it, we failed.
3123
-	if (!isset($size))
3124
-		$size = false;
3305
+	if (!isset($size)) {
3306
+			$size = false;
3307
+	}
3125 3308
 
3126 3309
 	// If this took a long time, we may never have to do it again, but then again we might...
3127
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3128
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3310
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3311
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3312
+	}
3129 3313
 
3130 3314
 	// Didn't work.
3131 3315
 	return $size;
@@ -3143,8 +3327,9 @@  discard block
 block discarded – undo
3143 3327
 
3144 3328
 	// Under SSI this function can be called more then once.  That can cause some problems.
3145 3329
 	//   So only run the function once unless we are forced to run it again.
3146
-	if ($loaded && !$forceload)
3147
-		return;
3330
+	if ($loaded && !$forceload) {
3331
+			return;
3332
+	}
3148 3333
 
3149 3334
 	$loaded = true;
3150 3335
 
@@ -3156,14 +3341,16 @@  discard block
 block discarded – undo
3156 3341
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3157 3342
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3158 3343
 	{
3159
-		if (trim($context['news_lines'][$i]) == '')
3160
-			continue;
3344
+		if (trim($context['news_lines'][$i]) == '') {
3345
+					continue;
3346
+		}
3161 3347
 
3162 3348
 		// Clean it up for presentation ;).
3163 3349
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3164 3350
 	}
3165
-	if (!empty($context['news_lines']))
3166
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3351
+	if (!empty($context['news_lines'])) {
3352
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3353
+	}
3167 3354
 
3168 3355
 	if (!$user_info['is_guest'])
3169 3356
 	{
@@ -3172,40 +3359,48 @@  discard block
 block discarded – undo
3172 3359
 		$context['user']['alerts'] = &$user_info['alerts'];
3173 3360
 
3174 3361
 		// Personal message popup...
3175
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3176
-			$context['user']['popup_messages'] = true;
3177
-		else
3178
-			$context['user']['popup_messages'] = false;
3362
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3363
+					$context['user']['popup_messages'] = true;
3364
+		} else {
3365
+					$context['user']['popup_messages'] = false;
3366
+		}
3179 3367
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3180 3368
 
3181
-		if (allowedTo('moderate_forum'))
3182
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3369
+		if (allowedTo('moderate_forum')) {
3370
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3371
+		}
3183 3372
 
3184 3373
 		$context['user']['avatar'] = array();
3185 3374
 
3186 3375
 		// Check for gravatar first since we might be forcing them...
3187 3376
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3188 3377
 		{
3189
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3190
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3191
-			else
3192
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3378
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3379
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3380
+			} else {
3381
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3382
+			}
3193 3383
 		}
3194 3384
 		// Uploaded?
3195
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3196
-			$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3385
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3386
+					$context['user']['avatar']['href'] = $user_info['avatar']['custom_dir'] ? $modSettings['custom_avatar_url'] . '/' . $user_info['avatar']['filename'] : $scripturl . '?action=dlattach;attach=' . $user_info['avatar']['id_attach'] . ';type=avatar';
3387
+		}
3197 3388
 		// Full URL?
3198
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3199
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3389
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3390
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3391
+		}
3200 3392
 		// Otherwise we assume it's server stored.
3201
-		elseif ($user_info['avatar']['url'] != '')
3202
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3393
+		elseif ($user_info['avatar']['url'] != '') {
3394
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3395
+		}
3203 3396
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3204
-		else
3205
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3397
+		else {
3398
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3399
+		}
3206 3400
 
3207
-		if (!empty($context['user']['avatar']))
3208
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3401
+		if (!empty($context['user']['avatar'])) {
3402
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3403
+		}
3209 3404
 
3210 3405
 		// Figure out how long they've been logged in.
3211 3406
 		$context['user']['total_time_logged_in'] = array(
@@ -3213,8 +3408,7 @@  discard block
 block discarded – undo
3213 3408
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3214 3409
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3215 3410
 		);
3216
-	}
3217
-	else
3411
+	} else
3218 3412
 	{
3219 3413
 		$context['user']['messages'] = 0;
3220 3414
 		$context['user']['unread_messages'] = 0;
@@ -3222,12 +3416,14 @@  discard block
 block discarded – undo
3222 3416
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3223 3417
 		$context['user']['popup_messages'] = false;
3224 3418
 
3225
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3226
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3419
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3420
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3421
+		}
3227 3422
 
3228 3423
 		// If we've upgraded recently, go easy on the passwords.
3229
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3230
-			$context['disable_login_hashing'] = true;
3424
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3425
+					$context['disable_login_hashing'] = true;
3426
+		}
3231 3427
 	}
3232 3428
 
3233 3429
 	// Setup the main menu items.
@@ -3240,8 +3436,8 @@  discard block
 block discarded – undo
3240 3436
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3241 3437
 
3242 3438
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3243
-	if ($context['show_pm_popup'])
3244
-		addInlineJavaScript('
3439
+	if ($context['show_pm_popup']) {
3440
+			addInlineJavaScript('
3245 3441
 		jQuery(document).ready(function($) {
3246 3442
 			new smc_Popup({
3247 3443
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3249,24 +3445,28 @@  discard block
 block discarded – undo
3249 3445
 				icon_class: \'generic_icons mail_new\'
3250 3446
 			});
3251 3447
 		});');
3448
+	}
3252 3449
 
3253 3450
 	// Add a generic "Are you sure?" confirmation message.
3254 3451
 	addInlineJavaScript('
3255 3452
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3256 3453
 
3257 3454
 	// Now add the capping code for avatars.
3258
-	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize')
3259
-		addInlineCss('
3455
+	if (!empty($modSettings['avatar_max_width_external']) && !empty($modSettings['avatar_max_height_external']) && !empty($modSettings['avatar_action_too_large']) && $modSettings['avatar_action_too_large'] == 'option_css_resize') {
3456
+			addInlineCss('
3260 3457
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3458
+	}
3261 3459
 
3262 3460
 	// Add max image limits
3263
-	if (!empty($modSettings['max_image_width']))
3264
-		addInlineCss('
3461
+	if (!empty($modSettings['max_image_width'])) {
3462
+			addInlineCss('
3265 3463
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3464
+	}
3266 3465
 
3267
-	if (!empty($modSettings['max_image_height']))
3268
-		addInlineCss('
3466
+	if (!empty($modSettings['max_image_height'])) {
3467
+			addInlineCss('
3269 3468
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3469
+	}
3270 3470
 
3271 3471
 	// This looks weird, but it's because BoardIndex.php references the variable.
3272 3472
 	$context['common_stats']['latest_member'] = array(
@@ -3283,11 +3483,13 @@  discard block
 block discarded – undo
3283 3483
 	);
3284 3484
 	$context['common_stats']['boardindex_total_posts'] = sprintf($txt['boardindex_total_posts'], $context['common_stats']['total_posts'], $context['common_stats']['total_topics'], $context['common_stats']['total_members']);
3285 3485
 
3286
-	if (empty($settings['theme_version']))
3287
-		addJavaScriptVar('smf_scripturl', $scripturl);
3486
+	if (empty($settings['theme_version'])) {
3487
+			addJavaScriptVar('smf_scripturl', $scripturl);
3488
+	}
3288 3489
 
3289
-	if (!isset($context['page_title']))
3290
-		$context['page_title'] = '';
3490
+	if (!isset($context['page_title'])) {
3491
+			$context['page_title'] = '';
3492
+	}
3291 3493
 
3292 3494
 	// Set some specific vars.
3293 3495
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3297,21 +3499,23 @@  discard block
 block discarded – undo
3297 3499
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3298 3500
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3299 3501
 
3300
-	if (!empty($context['meta_keywords']))
3301
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3502
+	if (!empty($context['meta_keywords'])) {
3503
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3504
+	}
3302 3505
 
3303
-	if (!empty($context['canonical_url']))
3304
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3506
+	if (!empty($context['canonical_url'])) {
3507
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3508
+	}
3305 3509
 
3306
-	if (!empty($settings['og_image']))
3307
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3510
+	if (!empty($settings['og_image'])) {
3511
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3512
+	}
3308 3513
 
3309 3514
 	if (!empty($context['meta_description']))
3310 3515
 	{
3311 3516
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3312 3517
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3313
-	}
3314
-	else
3518
+	} else
3315 3519
 	{
3316 3520
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3317 3521
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3336,8 +3540,9 @@  discard block
 block discarded – undo
3336 3540
 	$memory_needed = memoryReturnBytes($needed);
3337 3541
 
3338 3542
 	// should we account for how much is currently being used?
3339
-	if ($in_use)
3340
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3543
+	if ($in_use) {
3544
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3545
+	}
3341 3546
 
3342 3547
 	// if more is needed, request it
3343 3548
 	if ($memory_current < $memory_needed)
@@ -3360,8 +3565,9 @@  discard block
 block discarded – undo
3360 3565
  */
3361 3566
 function memoryReturnBytes($val)
3362 3567
 {
3363
-	if (is_integer($val))
3364
-		return $val;
3568
+	if (is_integer($val)) {
3569
+			return $val;
3570
+	}
3365 3571
 
3366 3572
 	// Separate the number from the designator
3367 3573
 	$val = trim($val);
@@ -3397,10 +3603,11 @@  discard block
 block discarded – undo
3397 3603
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3398 3604
 
3399 3605
 		// Are we debugging the template/html content?
3400
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3401
-			header('content-type: application/xhtml+xml');
3402
-		elseif (!isset($_REQUEST['xml']))
3403
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3606
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3607
+					header('content-type: application/xhtml+xml');
3608
+		} elseif (!isset($_REQUEST['xml'])) {
3609
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3610
+		}
3404 3611
 	}
3405 3612
 
3406 3613
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3409,8 +3616,9 @@  discard block
 block discarded – undo
3409 3616
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3410 3617
 	{
3411 3618
 		$position = array_search('body', $context['template_layers']);
3412
-		if ($position === false)
3413
-			$position = array_search('main', $context['template_layers']);
3619
+		if ($position === false) {
3620
+					$position = array_search('main', $context['template_layers']);
3621
+		}
3414 3622
 
3415 3623
 		if ($position !== false)
3416 3624
 		{
@@ -3438,23 +3646,25 @@  discard block
 block discarded – undo
3438 3646
 
3439 3647
 			foreach ($securityFiles as $i => $securityFile)
3440 3648
 			{
3441
-				if (!file_exists($boarddir . '/' . $securityFile))
3442
-					unset($securityFiles[$i]);
3649
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3650
+									unset($securityFiles[$i]);
3651
+				}
3443 3652
 			}
3444 3653
 
3445 3654
 			// We are already checking so many files...just few more doesn't make any difference! :P
3446
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3447
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3448
-
3449
-			else
3450
-				$path = $modSettings['attachmentUploadDir'];
3655
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3656
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3657
+			} else {
3658
+							$path = $modSettings['attachmentUploadDir'];
3659
+			}
3451 3660
 
3452 3661
 			secureDirectory($path, true);
3453 3662
 			secureDirectory($cachedir);
3454 3663
 
3455 3664
 			// If agreement is enabled, at least the english version shall exists
3456
-			if ($modSettings['requireAgreement'])
3457
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3665
+			if ($modSettings['requireAgreement']) {
3666
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3667
+			}
3458 3668
 
3459 3669
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3460 3670
 			{
@@ -3469,18 +3679,21 @@  discard block
 block discarded – undo
3469 3679
 					echo '
3470 3680
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3471 3681
 
3472
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3473
-						echo '
3682
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3683
+											echo '
3474 3684
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3685
+					}
3475 3686
 				}
3476 3687
 
3477
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3478
-					echo '
3688
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3689
+									echo '
3479 3690
 				<strong>', $txt['cache_writable'], '</strong><br>';
3691
+				}
3480 3692
 
3481
-				if (!empty($agreement))
3482
-					echo '
3693
+				if (!empty($agreement)) {
3694
+									echo '
3483 3695
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3696
+				}
3484 3697
 
3485 3698
 				echo '
3486 3699
 			</p>
@@ -3495,16 +3708,18 @@  discard block
 block discarded – undo
3495 3708
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3496 3709
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3497 3710
 
3498
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3499
-				echo '
3711
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3712
+							echo '
3500 3713
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3714
+			}
3501 3715
 
3502
-			if (!empty($_SESSION['ban']['expire_time']))
3503
-				echo '
3716
+			if (!empty($_SESSION['ban']['expire_time'])) {
3717
+							echo '
3504 3718
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3505
-			else
3506
-				echo '
3719
+			} else {
3720
+							echo '
3507 3721
 					<div>', $txt['your_ban_expires_never'], '</div>';
3722
+			}
3508 3723
 
3509 3724
 			echo '
3510 3725
 				</div>';
@@ -3520,8 +3735,9 @@  discard block
 block discarded – undo
3520 3735
 	global $forum_copyright, $software_year, $forum_version;
3521 3736
 
3522 3737
 	// Don't display copyright for things like SSI.
3523
-	if (!isset($forum_version) || !isset($software_year))
3524
-		return;
3738
+	if (!isset($forum_version) || !isset($software_year)) {
3739
+			return;
3740
+	}
3525 3741
 
3526 3742
 	// Put in the version...
3527 3743
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3539,9 +3755,10 @@  discard block
 block discarded – undo
3539 3755
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3540 3756
 	$context['load_queries'] = $db_count;
3541 3757
 
3542
-	foreach (array_reverse($context['template_layers']) as $layer)
3543
-		loadSubTemplate($layer . '_below', true);
3544
-}
3758
+	foreach (array_reverse($context['template_layers']) as $layer) {
3759
+			loadSubTemplate($layer . '_below', true);
3760
+	}
3761
+	}
3545 3762
 
3546 3763
 /**
3547 3764
  * Output the Javascript files
@@ -3575,8 +3792,7 @@  discard block
 block discarded – undo
3575 3792
 			{
3576 3793
 				echo '
3577 3794
 		var ', $key, ';';
3578
-			}
3579
-			else
3795
+			} else
3580 3796
 			{
3581 3797
 				echo '
3582 3798
 		var ', $key, ' = ', $value, ';';
@@ -3595,27 +3811,29 @@  discard block
 block discarded – undo
3595 3811
 		foreach ($context['javascript_files'] as $id => $js_file)
3596 3812
 		{
3597 3813
 			// Last minute call! allow theme authors to disable single files.
3598
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3599
-				continue;
3814
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3815
+							continue;
3816
+			}
3600 3817
 
3601 3818
 			// By default files don't get minimized unless the file explicitly says so!
3602 3819
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3603 3820
 			{
3604
-				if (!empty($js_file['options']['async']))
3605
-					$toMinify['async'][] = $js_file;
3606
-				elseif (!empty($js_file['options']['defer']))
3607
-					$toMinify['defer'][] = $js_file;
3608
-				else
3609
-					$toMinify['standard'][] = $js_file;
3821
+				if (!empty($js_file['options']['async'])) {
3822
+									$toMinify['async'][] = $js_file;
3823
+				} elseif (!empty($js_file['options']['defer'])) {
3824
+									$toMinify['defer'][] = $js_file;
3825
+				} else {
3826
+									$toMinify['standard'][] = $js_file;
3827
+				}
3610 3828
 
3611 3829
 				// Grab a random seed.
3612
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3613
-					$minSeed = $js_file['options']['seed'];
3614
-			}
3615
-
3616
-			else
3617
-				echo '
3830
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
3831
+									$minSeed = $js_file['options']['seed'];
3832
+				}
3833
+			} else {
3834
+							echo '
3618 3835
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
3836
+			}
3619 3837
 		}
3620 3838
 
3621 3839
 		foreach ($toMinify as $js_files)
@@ -3626,9 +3844,10 @@  discard block
 block discarded – undo
3626 3844
 
3627 3845
 				$minSuccessful = array_keys($result) === array('smf_minified');
3628 3846
 
3629
-				foreach ($result as $minFile)
3630
-					echo '
3847
+				foreach ($result as $minFile) {
3848
+									echo '
3631 3849
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
3850
+				}
3632 3851
 			}
3633 3852
 		}
3634 3853
 	}
@@ -3642,8 +3861,9 @@  discard block
 block discarded – undo
3642 3861
 <script>
3643 3862
 window.addEventListener("DOMContentLoaded", function() {';
3644 3863
 
3645
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3646
-				echo $js_code;
3864
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
3865
+							echo $js_code;
3866
+			}
3647 3867
 
3648 3868
 			echo '
3649 3869
 });
@@ -3655,8 +3875,9 @@  discard block
 block discarded – undo
3655 3875
 			echo '
3656 3876
 	<script>';
3657 3877
 
3658
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3659
-				echo $js_code;
3878
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
3879
+							echo $js_code;
3880
+			}
3660 3881
 
3661 3882
 			echo '
3662 3883
 	</script>';
@@ -3684,23 +3905,26 @@  discard block
 block discarded – undo
3684 3905
 	foreach ($context['css_files'] as $id => $file)
3685 3906
 	{
3686 3907
 		// Last minute call! allow theme authors to disable single files.
3687
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3688
-			continue;
3908
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3909
+					continue;
3910
+		}
3689 3911
 
3690 3912
 		// Files are minimized unless they explicitly opt out.
3691
-		if (!isset($file['options']['minimize']))
3692
-			$file['options']['minimize'] = true;
3913
+		if (!isset($file['options']['minimize'])) {
3914
+					$file['options']['minimize'] = true;
3915
+		}
3693 3916
 
3694 3917
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3695 3918
 		{
3696 3919
 			$toMinify[] = $file;
3697 3920
 
3698 3921
 			// Grab a random seed.
3699
-			if (!isset($minSeed) && isset($file['options']['seed']))
3700
-				$minSeed = $file['options']['seed'];
3922
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
3923
+							$minSeed = $file['options']['seed'];
3924
+			}
3925
+		} else {
3926
+					$normal[] = $file['fileUrl'];
3701 3927
 		}
3702
-		else
3703
-			$normal[] = $file['fileUrl'];
3704 3928
 	}
3705 3929
 
3706 3930
 	if (!empty($toMinify))
@@ -3709,23 +3933,26 @@  discard block
 block discarded – undo
3709 3933
 
3710 3934
 		$minSuccessful = array_keys($result) === array('smf_minified');
3711 3935
 
3712
-		foreach ($result as $minFile)
3713
-			echo '
3936
+		foreach ($result as $minFile) {
3937
+					echo '
3714 3938
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
3939
+		}
3715 3940
 	}
3716 3941
 
3717 3942
 	// Print the rest after the minified files.
3718
-	if (!empty($normal))
3719
-		foreach ($normal as $nf)
3943
+	if (!empty($normal)) {
3944
+			foreach ($normal as $nf)
3720 3945
 			echo '
3721 3946
 	<link rel="stylesheet" href="', $nf ,'">';
3947
+	}
3722 3948
 
3723 3949
 	if ($db_show_debug === true)
3724 3950
 	{
3725 3951
 		// Try to keep only what's useful.
3726 3952
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3727
-		foreach ($context['css_files'] as $file)
3728
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3953
+		foreach ($context['css_files'] as $file) {
3954
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
3955
+		}
3729 3956
 	}
3730 3957
 
3731 3958
 	if (!empty($context['css_header']))
@@ -3733,9 +3960,10 @@  discard block
 block discarded – undo
3733 3960
 		echo '
3734 3961
 	<style>';
3735 3962
 
3736
-		foreach ($context['css_header'] as $css)
3737
-			echo $css .'
3963
+		foreach ($context['css_header'] as $css) {
3964
+					echo $css .'
3738 3965
 	';
3966
+		}
3739 3967
 
3740 3968
 		echo'
3741 3969
 	</style>';
@@ -3758,8 +3986,9 @@  discard block
 block discarded – undo
3758 3986
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3759 3987
 	$data = is_array($data) ? $data : array();
3760 3988
 
3761
-	if (empty($type) || empty($data))
3762
-		return $data;
3989
+	if (empty($type) || empty($data)) {
3990
+			return $data;
3991
+	}
3763 3992
 
3764 3993
 	// Different pages include different files, so we use a hash to label the different combinations
3765 3994
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3768,13 +3997,14 @@  discard block
 block discarded – undo
3768 3997
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3769 3998
 
3770 3999
 	// Already done?
3771
-	if (!empty($toCache))
3772
-		return array('smf_minified' => array(
4000
+	if (!empty($toCache)) {
4001
+			return array('smf_minified' => array(
3773 4002
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3774 4003
 			'filePath' => $toCache,
3775 4004
 			'fileName' => basename($toCache),
3776 4005
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3777 4006
 		));
4007
+	}
3778 4008
 
3779 4009
 
3780 4010
 	// No namespaces, sorry!
@@ -3804,9 +4034,9 @@  discard block
 block discarded – undo
3804 4034
 
3805 4035
 	foreach ($data as $id => $file)
3806 4036
 	{
3807
-		if (empty($file['filePath']))
3808
-			$toAdd = false;
3809
-		else
4037
+		if (empty($file['filePath'])) {
4038
+					$toAdd = false;
4039
+		} else
3810 4040
 		{
3811 4041
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3812 4042
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3814,12 +4044,14 @@  discard block
 block discarded – undo
3814 4044
 		}
3815 4045
 
3816 4046
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3817
-		if (empty($file['options']['async']))
3818
-			$async = false;
4047
+		if (empty($file['options']['async'])) {
4048
+					$async = false;
4049
+		}
3819 4050
 
3820 4051
 		// A minified script should only be deferred if all its components wanted to be.
3821
-		if (empty($file['options']['defer']))
3822
-			$defer = false;
4052
+		if (empty($file['options']['defer'])) {
4053
+					$defer = false;
4054
+		}
3823 4055
 
3824 4056
 		// The file couldn't be located so it won't be added. Log this error.
3825 4057
 		if (empty($toAdd))
@@ -3885,12 +4117,14 @@  discard block
 block discarded – undo
3885 4117
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
3886 4118
 			{
3887 4119
 				// Remove the cache entry
3888
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
3889
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4120
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4121
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4122
+				}
3890 4123
 
3891 4124
 				// Try to delete the file. Add it to our error list if it fails.
3892
-				if (!@unlink($filename))
3893
-					$not_deleted[] = $filename;
4125
+				if (!@unlink($filename)) {
4126
+									$not_deleted[] = $filename;
4127
+				}
3894 4128
 			}
3895 4129
 		}
3896 4130
 	}
@@ -3922,8 +4156,9 @@  discard block
 block discarded – undo
3922 4156
 	global $modSettings, $smcFunc;
3923 4157
 
3924 4158
 	// Just make up a nice hash...
3925
-	if ($new)
3926
-		return sha1(md5($filename . time()) . mt_rand());
4159
+	if ($new) {
4160
+			return sha1(md5($filename . time()) . mt_rand());
4161
+	}
3927 4162
 
3928 4163
 	// Just make sure that attachment id is only a int
3929 4164
 	$attachment_id = (int) $attachment_id;
@@ -3940,23 +4175,25 @@  discard block
 block discarded – undo
3940 4175
 				'id_attach' => $attachment_id,
3941 4176
 			));
3942 4177
 
3943
-		if ($smcFunc['db_num_rows']($request) === 0)
3944
-			return false;
4178
+		if ($smcFunc['db_num_rows']($request) === 0) {
4179
+					return false;
4180
+		}
3945 4181
 
3946 4182
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
3947 4183
 		$smcFunc['db_free_result']($request);
3948 4184
 	}
3949 4185
 
3950 4186
 	// Still no hash? mmm...
3951
-	if (empty($file_hash))
3952
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4187
+	if (empty($file_hash)) {
4188
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4189
+	}
3953 4190
 
3954 4191
 	// Are we using multiple directories?
3955
-	if (is_array($modSettings['attachmentUploadDir']))
3956
-		$path = $modSettings['attachmentUploadDir'][$dir];
3957
-
3958
-	else
3959
-		$path = $modSettings['attachmentUploadDir'];
4192
+	if (is_array($modSettings['attachmentUploadDir'])) {
4193
+			$path = $modSettings['attachmentUploadDir'][$dir];
4194
+	} else {
4195
+			$path = $modSettings['attachmentUploadDir'];
4196
+	}
3960 4197
 
3961 4198
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
3962 4199
 }
@@ -3971,8 +4208,9 @@  discard block
 block discarded – undo
3971 4208
 function ip2range($fullip)
3972 4209
 {
3973 4210
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
3974
-	if ($fullip == 'unknown')
3975
-		$fullip = '255.255.255.255';
4211
+	if ($fullip == 'unknown') {
4212
+			$fullip = '255.255.255.255';
4213
+	}
3976 4214
 
3977 4215
 	$ip_parts = explode('-', $fullip);
3978 4216
 	$ip_array = array();
@@ -3996,10 +4234,11 @@  discard block
 block discarded – undo
3996 4234
 		$ip_array['low'] = $ip_parts[0];
3997 4235
 		$ip_array['high'] = $ip_parts[1];
3998 4236
 		return $ip_array;
3999
-	}
4000
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4237
+	} elseif (count($ip_parts) == 2) {
4238
+		// if ip 22.22.*-22.22.*
4001 4239
 	{
4002 4240
 		$valid_low = isValidIP($ip_parts[0]);
4241
+	}
4003 4242
 		$valid_high = isValidIP($ip_parts[1]);
4004 4243
 		$count = 0;
4005 4244
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4014,7 +4253,9 @@  discard block
 block discarded – undo
4014 4253
 				$ip_parts[0] .= $mode . $min;
4015 4254
 				$valid_low = isValidIP($ip_parts[0]);
4016 4255
 				$count++;
4017
-				if ($count > 9) break;
4256
+				if ($count > 9) {
4257
+					break;
4258
+				}
4018 4259
 			}
4019 4260
 		}
4020 4261
 
@@ -4028,7 +4269,9 @@  discard block
 block discarded – undo
4028 4269
 				$ip_parts[1] .= $mode . $max;
4029 4270
 				$valid_high = isValidIP($ip_parts[1]);
4030 4271
 				$count++;
4031
-				if ($count > 9) break;
4272
+				if ($count > 9) {
4273
+					break;
4274
+				}
4032 4275
 			}
4033 4276
 		}
4034 4277
 
@@ -4052,46 +4295,54 @@  discard block
 block discarded – undo
4052 4295
 {
4053 4296
 	global $modSettings;
4054 4297
 
4055
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4056
-		return $host;
4298
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4299
+			return $host;
4300
+	}
4057 4301
 	$t = microtime();
4058 4302
 
4059 4303
 	// Try the Linux host command, perhaps?
4060 4304
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4061 4305
 	{
4062
-		if (!isset($modSettings['host_to_dis']))
4063
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4064
-		else
4065
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4306
+		if (!isset($modSettings['host_to_dis'])) {
4307
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4308
+		} else {
4309
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4310
+		}
4066 4311
 
4067 4312
 		// Did host say it didn't find anything?
4068
-		if (strpos($test, 'not found') !== false)
4069
-			$host = '';
4313
+		if (strpos($test, 'not found') !== false) {
4314
+					$host = '';
4315
+		}
4070 4316
 		// Invalid server option?
4071
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4072
-			updateSettings(array('host_to_dis' => 1));
4317
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4318
+					updateSettings(array('host_to_dis' => 1));
4319
+		}
4073 4320
 		// Maybe it found something, after all?
4074
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4075
-			$host = $match[1];
4321
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4322
+					$host = $match[1];
4323
+		}
4076 4324
 	}
4077 4325
 
4078 4326
 	// This is nslookup; usually only Windows, but possibly some Unix?
4079 4327
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4080 4328
 	{
4081 4329
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4082
-		if (strpos($test, 'Non-existent domain') !== false)
4083
-			$host = '';
4084
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4085
-			$host = $match[1];
4330
+		if (strpos($test, 'Non-existent domain') !== false) {
4331
+					$host = '';
4332
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4333
+					$host = $match[1];
4334
+		}
4086 4335
 	}
4087 4336
 
4088 4337
 	// This is the last try :/.
4089
-	if (!isset($host) || $host === false)
4090
-		$host = @gethostbyaddr($ip);
4338
+	if (!isset($host) || $host === false) {
4339
+			$host = @gethostbyaddr($ip);
4340
+	}
4091 4341
 
4092 4342
 	// It took a long time, so let's cache it!
4093
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4094
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4343
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4344
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4345
+	}
4095 4346
 
4096 4347
 	return $host;
4097 4348
 }
@@ -4127,20 +4378,21 @@  discard block
 block discarded – undo
4127 4378
 			{
4128 4379
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4129 4380
 				$total = 0;
4130
-				for ($i = 0; $i < $max_chars; $i++)
4131
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4381
+				for ($i = 0; $i < $max_chars; $i++) {
4382
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4383
+				}
4132 4384
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4133 4385
 			}
4134 4386
 		}
4135 4387
 		return array_unique($returned_ints);
4136
-	}
4137
-	else
4388
+	} else
4138 4389
 	{
4139 4390
 		// Trim characters before and after and add slashes for database insertion.
4140 4391
 		$returned_words = array();
4141
-		foreach ($words as $word)
4142
-			if (($word = trim($word, '-_\'')) !== '')
4392
+		foreach ($words as $word) {
4393
+					if (($word = trim($word, '-_\'')) !== '')
4143 4394
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4395
+		}
4144 4396
 
4145 4397
 		// Filter out all words that occur more than once.
4146 4398
 		return array_unique($returned_words);
@@ -4162,16 +4414,18 @@  discard block
 block discarded – undo
4162 4414
 	global $settings, $txt;
4163 4415
 
4164 4416
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4165
-	if (function_exists('template_create_button') && !$force_use)
4166
-		return template_create_button($name, $alt, $label = '', $custom = '');
4417
+	if (function_exists('template_create_button') && !$force_use) {
4418
+			return template_create_button($name, $alt, $label = '', $custom = '');
4419
+	}
4167 4420
 
4168
-	if (!$settings['use_image_buttons'])
4169
-		return $txt[$alt];
4170
-	elseif (!empty($settings['use_buttons']))
4171
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4172
-	else
4173
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4174
-}
4421
+	if (!$settings['use_image_buttons']) {
4422
+			return $txt[$alt];
4423
+	} elseif (!empty($settings['use_buttons'])) {
4424
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4425
+	} else {
4426
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4427
+	}
4428
+	}
4175 4429
 
4176 4430
 /**
4177 4431
  * Sets up all of the top menu buttons
@@ -4214,9 +4468,10 @@  discard block
 block discarded – undo
4214 4468
 	var user_menus = new smc_PopupMenu();
4215 4469
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4216 4470
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4217
-		if ($context['allow_pm'])
4218
-			addInlineJavaScript('
4471
+		if ($context['allow_pm']) {
4472
+					addInlineJavaScript('
4219 4473
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4474
+		}
4220 4475
 
4221 4476
 		if (!empty($modSettings['enable_ajax_alerts']))
4222 4477
 		{
@@ -4376,88 +4631,96 @@  discard block
 block discarded – undo
4376 4631
 
4377 4632
 		// Now we put the buttons in the context so the theme can use them.
4378 4633
 		$menu_buttons = array();
4379
-		foreach ($buttons as $act => $button)
4380
-			if (!empty($button['show']))
4634
+		foreach ($buttons as $act => $button) {
4635
+					if (!empty($button['show']))
4381 4636
 			{
4382 4637
 				$button['active_button'] = false;
4638
+		}
4383 4639
 
4384 4640
 				// This button needs some action.
4385
-				if (isset($button['action_hook']))
4386
-					$needs_action_hook = true;
4641
+				if (isset($button['action_hook'])) {
4642
+									$needs_action_hook = true;
4643
+				}
4387 4644
 
4388 4645
 				// Make sure the last button truly is the last button.
4389 4646
 				if (!empty($button['is_last']))
4390 4647
 				{
4391
-					if (isset($last_button))
4392
-						unset($menu_buttons[$last_button]['is_last']);
4648
+					if (isset($last_button)) {
4649
+											unset($menu_buttons[$last_button]['is_last']);
4650
+					}
4393 4651
 					$last_button = $act;
4394 4652
 				}
4395 4653
 
4396 4654
 				// Go through the sub buttons if there are any.
4397
-				if (!empty($button['sub_buttons']))
4398
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4655
+				if (!empty($button['sub_buttons'])) {
4656
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4399 4657
 					{
4400 4658
 						if (empty($subbutton['show']))
4401 4659
 							unset($button['sub_buttons'][$key]);
4660
+				}
4402 4661
 
4403 4662
 						// 2nd level sub buttons next...
4404 4663
 						if (!empty($subbutton['sub_buttons']))
4405 4664
 						{
4406 4665
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4407 4666
 							{
4408
-								if (empty($sub_button2['show']))
4409
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4667
+								if (empty($sub_button2['show'])) {
4668
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4669
+								}
4410 4670
 							}
4411 4671
 						}
4412 4672
 					}
4413 4673
 
4414 4674
 				// Does this button have its own icon?
4415
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4416
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4417
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4418
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4419
-				elseif (isset($button['icon']))
4420
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4421
-				else
4422
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4675
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4676
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4677
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4678
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4679
+				} elseif (isset($button['icon'])) {
4680
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4681
+				} else {
4682
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4683
+				}
4423 4684
 
4424 4685
 				$menu_buttons[$act] = $button;
4425 4686
 			}
4426 4687
 
4427
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4428
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4688
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4689
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4690
+		}
4429 4691
 	}
4430 4692
 
4431 4693
 	$context['menu_buttons'] = $menu_buttons;
4432 4694
 
4433 4695
 	// Logging out requires the session id in the url.
4434
-	if (isset($context['menu_buttons']['logout']))
4435
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4696
+	if (isset($context['menu_buttons']['logout'])) {
4697
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4698
+	}
4436 4699
 
4437 4700
 	// Figure out which action we are doing so we can set the active tab.
4438 4701
 	// Default to home.
4439 4702
 	$current_action = 'home';
4440 4703
 
4441
-	if (isset($context['menu_buttons'][$context['current_action']]))
4442
-		$current_action = $context['current_action'];
4443
-	elseif ($context['current_action'] == 'search2')
4444
-		$current_action = 'search';
4445
-	elseif ($context['current_action'] == 'theme')
4446
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4447
-	elseif ($context['current_action'] == 'register2')
4448
-		$current_action = 'register';
4449
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4450
-		$current_action = 'login';
4451
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4452
-		$current_action = 'moderate';
4704
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4705
+			$current_action = $context['current_action'];
4706
+	} elseif ($context['current_action'] == 'search2') {
4707
+			$current_action = 'search';
4708
+	} elseif ($context['current_action'] == 'theme') {
4709
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4710
+	} elseif ($context['current_action'] == 'register2') {
4711
+			$current_action = 'register';
4712
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4713
+			$current_action = 'login';
4714
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4715
+			$current_action = 'moderate';
4716
+	}
4453 4717
 
4454 4718
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4455 4719
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4456 4720
 	{
4457 4721
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4458 4722
 		$context[$current_action] = true;
4459
-	}
4460
-	elseif ($context['current_action'] == 'pm')
4723
+	} elseif ($context['current_action'] == 'pm')
4461 4724
 	{
4462 4725
 		$current_action = 'self_pm';
4463 4726
 		$context['self_pm'] = true;
@@ -4514,12 +4777,14 @@  discard block
 block discarded – undo
4514 4777
 	}
4515 4778
 
4516 4779
 	// Not all actions are simple.
4517
-	if (!empty($needs_action_hook))
4518
-		call_integration_hook('integrate_current_action', array(&$current_action));
4780
+	if (!empty($needs_action_hook)) {
4781
+			call_integration_hook('integrate_current_action', array(&$current_action));
4782
+	}
4519 4783
 
4520
-	if (isset($context['menu_buttons'][$current_action]))
4521
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4522
-}
4784
+	if (isset($context['menu_buttons'][$current_action])) {
4785
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4786
+	}
4787
+	}
4523 4788
 
4524 4789
 /**
4525 4790
  * Generate a random seed and ensure it's stored in settings.
@@ -4543,30 +4808,35 @@  discard block
 block discarded – undo
4543 4808
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4544 4809
 	global $context, $txt;
4545 4810
 
4546
-	if ($db_show_debug === true)
4547
-		$context['debug']['hooks'][] = $hook;
4811
+	if ($db_show_debug === true) {
4812
+			$context['debug']['hooks'][] = $hook;
4813
+	}
4548 4814
 
4549 4815
 	// Need to have some control.
4550
-	if (!isset($context['instances']))
4551
-		$context['instances'] = array();
4816
+	if (!isset($context['instances'])) {
4817
+			$context['instances'] = array();
4818
+	}
4552 4819
 
4553 4820
 	$results = array();
4554
-	if (empty($modSettings[$hook]))
4555
-		return $results;
4821
+	if (empty($modSettings[$hook])) {
4822
+			return $results;
4823
+	}
4556 4824
 
4557 4825
 	$functions = explode(',', $modSettings[$hook]);
4558 4826
 	// Loop through each function.
4559 4827
 	foreach ($functions as $function)
4560 4828
 	{
4561 4829
 		// Hook has been marked as "disabled". Skip it!
4562
-		if (strpos($function, '!') !== false)
4563
-			continue;
4830
+		if (strpos($function, '!') !== false) {
4831
+					continue;
4832
+		}
4564 4833
 
4565 4834
 		$call = call_helper($function, true);
4566 4835
 
4567 4836
 		// Is it valid?
4568
-		if (!empty($call))
4569
-			$results[$function] = call_user_func_array($call, $parameters);
4837
+		if (!empty($call)) {
4838
+					$results[$function] = call_user_func_array($call, $parameters);
4839
+		}
4570 4840
 
4571 4841
 		// Whatever it was suppose to call, it failed :(
4572 4842
 		elseif (!empty($function))
@@ -4582,8 +4852,9 @@  discard block
 block discarded – undo
4582 4852
 			}
4583 4853
 
4584 4854
 			// "Assume" the file resides on $boarddir somewhere...
4585
-			else
4586
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4855
+			else {
4856
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
4857
+			}
4587 4858
 		}
4588 4859
 	}
4589 4860
 
@@ -4605,12 +4876,14 @@  discard block
 block discarded – undo
4605 4876
 	global $smcFunc, $modSettings;
4606 4877
 
4607 4878
 	// Any objects?
4608
-	if ($object)
4609
-		$function = $function . '#';
4879
+	if ($object) {
4880
+			$function = $function . '#';
4881
+	}
4610 4882
 
4611 4883
 	// Any files  to load?
4612
-	if (!empty($file) && is_string($file))
4613
-		$function = $file . (!empty($function) ? '|' . $function : '');
4884
+	if (!empty($file) && is_string($file)) {
4885
+			$function = $file . (!empty($function) ? '|' . $function : '');
4886
+	}
4614 4887
 
4615 4888
 	// Get the correct string.
4616 4889
 	$integration_call = $function;
@@ -4632,13 +4905,14 @@  discard block
 block discarded – undo
4632 4905
 		if (!empty($current_functions))
4633 4906
 		{
4634 4907
 			$current_functions = explode(',', $current_functions);
4635
-			if (in_array($integration_call, $current_functions))
4636
-				return;
4908
+			if (in_array($integration_call, $current_functions)) {
4909
+							return;
4910
+			}
4637 4911
 
4638 4912
 			$permanent_functions = array_merge($current_functions, array($integration_call));
4913
+		} else {
4914
+					$permanent_functions = array($integration_call);
4639 4915
 		}
4640
-		else
4641
-			$permanent_functions = array($integration_call);
4642 4916
 
4643 4917
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4644 4918
 	}
@@ -4647,8 +4921,9 @@  discard block
 block discarded – undo
4647 4921
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4648 4922
 
4649 4923
 	// Do nothing, if it's already there.
4650
-	if (in_array($integration_call, $functions))
4651
-		return;
4924
+	if (in_array($integration_call, $functions)) {
4925
+			return;
4926
+	}
4652 4927
 
4653 4928
 	$functions[] = $integration_call;
4654 4929
 	$modSettings[$hook] = implode(',', $functions);
@@ -4671,12 +4946,14 @@  discard block
 block discarded – undo
4671 4946
 	global $smcFunc, $modSettings;
4672 4947
 
4673 4948
 	// Any objects?
4674
-	if ($object)
4675
-		$function = $function . '#';
4949
+	if ($object) {
4950
+			$function = $function . '#';
4951
+	}
4676 4952
 
4677 4953
 	// Any files  to load?
4678
-	if (!empty($file) && is_string($file))
4679
-		$function = $file . '|' . $function;
4954
+	if (!empty($file) && is_string($file)) {
4955
+			$function = $file . '|' . $function;
4956
+	}
4680 4957
 
4681 4958
 	// Get the correct string.
4682 4959
 	$integration_call = $function;
@@ -4697,16 +4974,18 @@  discard block
 block discarded – undo
4697 4974
 	{
4698 4975
 		$current_functions = explode(',', $current_functions);
4699 4976
 
4700
-		if (in_array($integration_call, $current_functions))
4701
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4977
+		if (in_array($integration_call, $current_functions)) {
4978
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
4979
+		}
4702 4980
 	}
4703 4981
 
4704 4982
 	// Turn the function list into something usable.
4705 4983
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4706 4984
 
4707 4985
 	// You can only remove it if it's available.
4708
-	if (!in_array($integration_call, $functions))
4709
-		return;
4986
+	if (!in_array($integration_call, $functions)) {
4987
+			return;
4988
+	}
4710 4989
 
4711 4990
 	$functions = array_diff($functions, array($integration_call));
4712 4991
 	$modSettings[$hook] = implode(',', $functions);
@@ -4727,17 +5006,20 @@  discard block
 block discarded – undo
4727 5006
 	global $context, $smcFunc, $txt, $db_show_debug;
4728 5007
 
4729 5008
 	// Really?
4730
-	if (empty($string))
4731
-		return false;
5009
+	if (empty($string)) {
5010
+			return false;
5011
+	}
4732 5012
 
4733 5013
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4734 5014
 	// A closure? should be a callable one.
4735
-	if (is_array($string) || $string instanceof Closure)
4736
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5015
+	if (is_array($string) || $string instanceof Closure) {
5016
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5017
+	}
4737 5018
 
4738 5019
 	// No full objects, sorry! pass a method or a property instead!
4739
-	if (is_object($string))
4740
-		return false;
5020
+	if (is_object($string)) {
5021
+			return false;
5022
+	}
4741 5023
 
4742 5024
 	// Stay vitaminized my friends...
4743 5025
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4746,8 +5028,9 @@  discard block
 block discarded – undo
4746 5028
 	$string = load_file($string);
4747 5029
 
4748 5030
 	// Loaded file failed
4749
-	if (empty($string))
4750
-		return false;
5031
+	if (empty($string)) {
5032
+			return false;
5033
+	}
4751 5034
 
4752 5035
 	// Found a method.
4753 5036
 	if (strpos($string, '::') !== false)
@@ -4768,8 +5051,9 @@  discard block
 block discarded – undo
4768 5051
 				// Add another one to the list.
4769 5052
 				if ($db_show_debug === true)
4770 5053
 				{
4771
-					if (!isset($context['debug']['instances']))
4772
-						$context['debug']['instances'] = array();
5054
+					if (!isset($context['debug']['instances'])) {
5055
+											$context['debug']['instances'] = array();
5056
+					}
4773 5057
 
4774 5058
 					$context['debug']['instances'][$class] = $class;
4775 5059
 				}
@@ -4779,13 +5063,15 @@  discard block
 block discarded – undo
4779 5063
 		}
4780 5064
 
4781 5065
 		// Right then. This is a call to a static method.
4782
-		else
4783
-			$func = array($class, $method);
5066
+		else {
5067
+					$func = array($class, $method);
5068
+		}
4784 5069
 	}
4785 5070
 
4786 5071
 	// Nope! just a plain regular function.
4787
-	else
4788
-		$func = $string;
5072
+	else {
5073
+			$func = $string;
5074
+	}
4789 5075
 
4790 5076
 	// Right, we got what we need, time to do some checks.
4791 5077
 	if (!is_callable($func, false, $callable_name))
@@ -4801,17 +5087,18 @@  discard block
 block discarded – undo
4801 5087
 	else
4802 5088
 	{
4803 5089
 		// What are we gonna do about it?
4804
-		if ($return)
4805
-			return $func;
5090
+		if ($return) {
5091
+					return $func;
5092
+		}
4806 5093
 
4807 5094
 		// If this is a plain function, avoid the heat of calling call_user_func().
4808 5095
 		else
4809 5096
 		{
4810
-			if (is_array($func))
4811
-				call_user_func($func);
4812
-
4813
-			else
4814
-				$func();
5097
+			if (is_array($func)) {
5098
+							call_user_func($func);
5099
+			} else {
5100
+							$func();
5101
+			}
4815 5102
 		}
4816 5103
 	}
4817 5104
 }
@@ -4828,31 +5115,34 @@  discard block
 block discarded – undo
4828 5115
 {
4829 5116
 	global $sourcedir, $txt, $boarddir, $settings;
4830 5117
 
4831
-	if (empty($string))
4832
-		return false;
5118
+	if (empty($string)) {
5119
+			return false;
5120
+	}
4833 5121
 
4834 5122
 	if (strpos($string, '|') !== false)
4835 5123
 	{
4836 5124
 		list ($file, $string) = explode('|', $string);
4837 5125
 
4838 5126
 		// Match the wildcards to their regular vars.
4839
-		if (empty($settings['theme_dir']))
4840
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
4841
-
4842
-		else
4843
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5127
+		if (empty($settings['theme_dir'])) {
5128
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5129
+		} else {
5130
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5131
+		}
4844 5132
 
4845 5133
 		// Load the file if it can be loaded.
4846
-		if (file_exists($absPath))
4847
-			require_once($absPath);
5134
+		if (file_exists($absPath)) {
5135
+					require_once($absPath);
5136
+		}
4848 5137
 
4849 5138
 		// No? try a fallback to $sourcedir
4850 5139
 		else
4851 5140
 		{
4852 5141
 			$absPath = $sourcedir .'/'. $file;
4853 5142
 
4854
-			if (file_exists($absPath))
4855
-				require_once($absPath);
5143
+			if (file_exists($absPath)) {
5144
+							require_once($absPath);
5145
+			}
4856 5146
 
4857 5147
 			// Sorry, can't do much for you at this point.
4858 5148
 			else
@@ -4891,8 +5181,9 @@  discard block
 block discarded – undo
4891 5181
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
4892 5182
 
4893 5183
 	// No scheme? No data for you!
4894
-	if (empty($match[1]))
4895
-		return false;
5184
+	if (empty($match[1])) {
5185
+			return false;
5186
+	}
4896 5187
 
4897 5188
 	// An FTP url. We should try connecting and RETRieving it...
4898 5189
 	elseif ($match[1] == 'ftp')
@@ -4902,23 +5193,26 @@  discard block
 block discarded – undo
4902 5193
 
4903 5194
 		// Establish a connection and attempt to enable passive mode.
4904 5195
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
4905
-		if ($ftp->error !== false || !$ftp->passive())
4906
-			return false;
5196
+		if ($ftp->error !== false || !$ftp->passive()) {
5197
+					return false;
5198
+		}
4907 5199
 
4908 5200
 		// I want that one *points*!
4909 5201
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
4910 5202
 
4911 5203
 		// Since passive mode worked (or we would have returned already!) open the connection.
4912 5204
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
4913
-		if (!$fp)
4914
-			return false;
5205
+		if (!$fp) {
5206
+					return false;
5207
+		}
4915 5208
 
4916 5209
 		// The server should now say something in acknowledgement.
4917 5210
 		$ftp->check_response(150);
4918 5211
 
4919 5212
 		$data = '';
4920
-		while (!feof($fp))
4921
-			$data .= fread($fp, 4096);
5213
+		while (!feof($fp)) {
5214
+					$data .= fread($fp, 4096);
5215
+		}
4922 5216
 		fclose($fp);
4923 5217
 
4924 5218
 		// All done, right?  Good.
@@ -4930,8 +5224,9 @@  discard block
 block discarded – undo
4930 5224
 	elseif (isset($match[1]) && $match[1] == 'http')
4931 5225
 	{
4932 5226
 		// First try to use fsockopen, because it is fastest.
4933
-		if ($keep_alive && $match[3] == $keep_alive_dom)
4934
-			$fp = $keep_alive_fp;
5227
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5228
+					$fp = $keep_alive_fp;
5229
+		}
4935 5230
 		if (empty($fp))
4936 5231
 		{
4937 5232
 			// Open the socket on the port we want...
@@ -4951,20 +5246,21 @@  discard block
 block discarded – undo
4951 5246
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
4952 5247
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
4953 5248
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
4954
-				if ($keep_alive)
4955
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
4956
-				else
4957
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
4958
-			}
4959
-			else
5249
+				if ($keep_alive) {
5250
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5251
+				} else {
5252
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5253
+				}
5254
+			} else
4960 5255
 			{
4961 5256
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
4962 5257
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
4963 5258
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
4964
-				if ($keep_alive)
4965
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
4966
-				else
4967
-					fwrite($fp, 'connection: close' . "\r\n");
5259
+				if ($keep_alive) {
5260
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5261
+				} else {
5262
+									fwrite($fp, 'connection: close' . "\r\n");
5263
+				}
4968 5264
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
4969 5265
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
4970 5266
 				fwrite($fp, $post_data);
@@ -4977,30 +5273,33 @@  discard block
 block discarded – undo
4977 5273
 			{
4978 5274
 				$header = '';
4979 5275
 				$location = '';
4980
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
4981
-					if (strpos($header, 'location:') !== false)
5276
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5277
+									if (strpos($header, 'location:') !== false)
4982 5278
 						$location = trim(substr($header, strpos($header, ':') + 1));
5279
+				}
4983 5280
 
4984
-				if (empty($location))
4985
-					return false;
4986
-				else
5281
+				if (empty($location)) {
5282
+									return false;
5283
+				} else
4987 5284
 				{
4988
-					if (!$keep_alive)
4989
-						fclose($fp);
5285
+					if (!$keep_alive) {
5286
+											fclose($fp);
5287
+					}
4990 5288
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
4991 5289
 				}
4992 5290
 			}
4993 5291
 
4994 5292
 			// Make sure we get a 200 OK.
4995
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
4996
-				return false;
5293
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5294
+							return false;
5295
+			}
4997 5296
 
4998 5297
 			// Skip the headers...
4999 5298
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5000 5299
 			{
5001
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5002
-					$content_length = $match[1];
5003
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5300
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5301
+									$content_length = $match[1];
5302
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5004 5303
 				{
5005 5304
 					$keep_alive_dom = null;
5006 5305
 					$keep_alive = false;
@@ -5012,17 +5311,19 @@  discard block
 block discarded – undo
5012 5311
 			$data = '';
5013 5312
 			if (isset($content_length))
5014 5313
 			{
5015
-				while (!feof($fp) && strlen($data) < $content_length)
5016
-					$data .= fread($fp, $content_length - strlen($data));
5017
-			}
5018
-			else
5314
+				while (!feof($fp) && strlen($data) < $content_length) {
5315
+									$data .= fread($fp, $content_length - strlen($data));
5316
+				}
5317
+			} else
5019 5318
 			{
5020
-				while (!feof($fp))
5021
-					$data .= fread($fp, 4096);
5319
+				while (!feof($fp)) {
5320
+									$data .= fread($fp, 4096);
5321
+				}
5022 5322
 			}
5023 5323
 
5024
-			if (!$keep_alive)
5025
-				fclose($fp);
5324
+			if (!$keep_alive) {
5325
+							fclose($fp);
5326
+			}
5026 5327
 		}
5027 5328
 
5028 5329
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5035,17 +5336,18 @@  discard block
 block discarded – undo
5035 5336
 			$fetch_data->get_url_data($url, $post_data);
5036 5337
 
5037 5338
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5038
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5039
-				$data = $fetch_data->result('body');
5040
-			else
5041
-				return false;
5339
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5340
+							$data = $fetch_data->result('body');
5341
+			} else {
5342
+							return false;
5343
+			}
5042 5344
 		}
5043 5345
 
5044 5346
 		// Neither fsockopen nor curl are available. Well, phooey.
5045
-		else
5046
-			return false;
5047
-	}
5048
-	else
5347
+		else {
5348
+					return false;
5349
+		}
5350
+	} else
5049 5351
 	{
5050 5352
 		// Umm, this shouldn't happen?
5051 5353
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5065,8 +5367,9 @@  discard block
 block discarded – undo
5065 5367
 	global $user_info, $smcFunc;
5066 5368
 
5067 5369
 	// Make sure we have something to work with.
5068
-	if (empty($topic))
5069
-		return array();
5370
+	if (empty($topic)) {
5371
+			return array();
5372
+	}
5070 5373
 
5071 5374
 
5072 5375
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5089,8 +5392,9 @@  discard block
 block discarded – undo
5089 5392
 				'topic' => $topic,
5090 5393
 			)
5091 5394
 		);
5092
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5093
-			$temp[] = (int) $row['content_id'];
5395
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5396
+					$temp[] = (int) $row['content_id'];
5397
+		}
5094 5398
 
5095 5399
 		cache_put_data($cache_key, $temp, $ttl);
5096 5400
 	}
@@ -5111,8 +5415,9 @@  discard block
 block discarded – undo
5111 5415
 {
5112 5416
 	global $context;
5113 5417
 
5114
-	if (empty($string))
5115
-		return $string;
5418
+	if (empty($string)) {
5419
+			return $string;
5420
+	}
5116 5421
 
5117 5422
 	// UTF-8 occurences of MS special characters
5118 5423
 	$findchars_utf8 = array(
@@ -5153,10 +5458,11 @@  discard block
 block discarded – undo
5153 5458
 		'--',	// &mdash;
5154 5459
 	);
5155 5460
 
5156
-	if ($context['utf8'])
5157
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5158
-	else
5159
-		$string = str_replace($findchars_iso, $replacechars, $string);
5461
+	if ($context['utf8']) {
5462
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5463
+	} else {
5464
+			$string = str_replace($findchars_iso, $replacechars, $string);
5465
+	}
5160 5466
 
5161 5467
 	return $string;
5162 5468
 }
@@ -5175,49 +5481,59 @@  discard block
 block discarded – undo
5175 5481
 {
5176 5482
 	global $context;
5177 5483
 
5178
-	if (!isset($matches[2]))
5179
-		return '';
5484
+	if (!isset($matches[2])) {
5485
+			return '';
5486
+	}
5180 5487
 
5181 5488
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5182 5489
 
5183 5490
 	// remove left to right / right to left overrides
5184
-	if ($num === 0x202D || $num === 0x202E)
5185
-		return '';
5491
+	if ($num === 0x202D || $num === 0x202E) {
5492
+			return '';
5493
+	}
5186 5494
 
5187 5495
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5188
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5189
-		return '&#' . $num . ';';
5496
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5497
+			return '&#' . $num . ';';
5498
+	}
5190 5499
 
5191 5500
 	if (empty($context['utf8']))
5192 5501
 	{
5193 5502
 		// no control characters
5194
-		if ($num < 0x20)
5195
-			return '';
5503
+		if ($num < 0x20) {
5504
+					return '';
5505
+		}
5196 5506
 		// text is text
5197
-		elseif ($num < 0x80)
5198
-			return chr($num);
5507
+		elseif ($num < 0x80) {
5508
+					return chr($num);
5509
+		}
5199 5510
 		// all others get html-ised
5200
-		else
5201
-			return '&#' . $matches[2] . ';';
5202
-	}
5203
-	else
5511
+		else {
5512
+					return '&#' . $matches[2] . ';';
5513
+		}
5514
+	} else
5204 5515
 	{
5205 5516
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5206 5517
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5207
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5208
-			return '';
5518
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5519
+					return '';
5520
+		}
5209 5521
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5210
-		elseif ($num < 0x80)
5211
-			return chr($num);
5522
+		elseif ($num < 0x80) {
5523
+					return chr($num);
5524
+		}
5212 5525
 		// <0x800 (2048)
5213
-		elseif ($num < 0x800)
5214
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5526
+		elseif ($num < 0x800) {
5527
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5528
+		}
5215 5529
 		// < 0x10000 (65536)
5216
-		elseif ($num < 0x10000)
5217
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5530
+		elseif ($num < 0x10000) {
5531
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5532
+		}
5218 5533
 		// <= 0x10FFFF (1114111)
5219
-		else
5220
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5534
+		else {
5535
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5536
+		}
5221 5537
 	}
5222 5538
 }
5223 5539
 
@@ -5233,28 +5549,34 @@  discard block
 block discarded – undo
5233 5549
  */
5234 5550
 function fixchar__callback($matches)
5235 5551
 {
5236
-	if (!isset($matches[1]))
5237
-		return '';
5552
+	if (!isset($matches[1])) {
5553
+			return '';
5554
+	}
5238 5555
 
5239 5556
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5240 5557
 
5241 5558
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5242 5559
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5243
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5244
-		return '';
5560
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5561
+			return '';
5562
+	}
5245 5563
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5246
-	elseif ($num < 0x80)
5247
-		return chr($num);
5564
+	elseif ($num < 0x80) {
5565
+			return chr($num);
5566
+	}
5248 5567
 	// <0x800 (2048)
5249
-	elseif ($num < 0x800)
5250
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5568
+	elseif ($num < 0x800) {
5569
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5570
+	}
5251 5571
 	// < 0x10000 (65536)
5252
-	elseif ($num < 0x10000)
5253
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5572
+	elseif ($num < 0x10000) {
5573
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5574
+	}
5254 5575
 	// <= 0x10FFFF (1114111)
5255
-	else
5256
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5257
-}
5576
+	else {
5577
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5578
+	}
5579
+	}
5258 5580
 
5259 5581
 /**
5260 5582
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5267,17 +5589,19 @@  discard block
 block discarded – undo
5267 5589
  */
5268 5590
 function entity_fix__callback($matches)
5269 5591
 {
5270
-	if (!isset($matches[2]))
5271
-		return '';
5592
+	if (!isset($matches[2])) {
5593
+			return '';
5594
+	}
5272 5595
 
5273 5596
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5274 5597
 
5275 5598
 	// we don't allow control characters, characters out of range, byte markers, etc
5276
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5277
-		return '';
5278
-	else
5279
-		return '&#' . $num . ';';
5280
-}
5599
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5600
+			return '';
5601
+	} else {
5602
+			return '&#' . $num . ';';
5603
+	}
5604
+	}
5281 5605
 
5282 5606
 /**
5283 5607
  * Return a Gravatar URL based on
@@ -5301,18 +5625,23 @@  discard block
 block discarded – undo
5301 5625
 		$ratings = array('G', 'PG', 'R', 'X');
5302 5626
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5303 5627
 		$url_params = array();
5304
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5305
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5306
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5307
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5308
-		if (!empty($modSettings['avatar_max_width_external']))
5309
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5310
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5311
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5628
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5629
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5630
+		}
5631
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5632
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5633
+		}
5634
+		if (!empty($modSettings['avatar_max_width_external'])) {
5635
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5636
+		}
5637
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5638
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5312 5639
 				$size_string = $modSettings['avatar_max_height_external'];
5640
+		}
5313 5641
 
5314
-		if (!empty($size_string))
5315
-			$url_params[] = 's=' . $size_string;
5642
+		if (!empty($size_string)) {
5643
+					$url_params[] = 's=' . $size_string;
5644
+		}
5316 5645
 	}
5317 5646
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5318 5647
 
@@ -5331,22 +5660,26 @@  discard block
 block discarded – undo
5331 5660
 	static $timezones = null, $lastwhen = null;
5332 5661
 
5333 5662
 	// No point doing this over if we already did it once
5334
-	if (!empty($timezones) && $when == $lastwhen)
5335
-		return $timezones;
5336
-	else
5337
-		$lastwhen = $when;
5663
+	if (!empty($timezones) && $when == $lastwhen) {
5664
+			return $timezones;
5665
+	} else {
5666
+			$lastwhen = $when;
5667
+	}
5338 5668
 
5339 5669
 	// Parseable datetime string?
5340
-	if (is_int($timestamp = strtotime($when)))
5341
-		$when = $timestamp;
5670
+	if (is_int($timestamp = strtotime($when))) {
5671
+			$when = $timestamp;
5672
+	}
5342 5673
 
5343 5674
 	// A Unix timestamp?
5344
-	elseif (is_numeric($when))
5345
-		$when = intval($when);
5675
+	elseif (is_numeric($when)) {
5676
+			$when = intval($when);
5677
+	}
5346 5678
 
5347 5679
 	// Invalid value? Just get current Unix timestamp.
5348
-	else
5349
-		$when = time();
5680
+	else {
5681
+			$when = time();
5682
+	}
5350 5683
 
5351 5684
 	// We'll need these too
5352 5685
 	$date_when = date_create('@' . $when);
@@ -5361,8 +5694,9 @@  discard block
 block discarded – undo
5361 5694
 	foreach ($priority_countries as $country)
5362 5695
 	{
5363 5696
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5364
-		if (!empty($country_tzids))
5365
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5697
+		if (!empty($country_tzids)) {
5698
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5699
+		}
5366 5700
 	}
5367 5701
 
5368 5702
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5376,8 +5710,9 @@  discard block
 block discarded – undo
5376 5710
 	foreach ($tzids as $tzid)
5377 5711
 	{
5378 5712
 		// We don't want UTC right now
5379
-		if ($tzid == 'UTC')
5380
-			continue;
5713
+		if ($tzid == 'UTC') {
5714
+					continue;
5715
+		}
5381 5716
 
5382 5717
 		$tz = timezone_open($tzid);
5383 5718
 
@@ -5398,13 +5733,14 @@  discard block
 block discarded – undo
5398 5733
 		}
5399 5734
 
5400 5735
 		// A time zone from a prioritized country?
5401
-		if (in_array($tzid, $priority_tzids))
5402
-			$priority_zones[$tzkey] = true;
5736
+		if (in_array($tzid, $priority_tzids)) {
5737
+					$priority_zones[$tzkey] = true;
5738
+		}
5403 5739
 
5404 5740
 		// Keep track of the location and offset for this tzid
5405
-		if (!empty($txt[$tzid]))
5406
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5407
-		else
5741
+		if (!empty($txt[$tzid])) {
5742
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5743
+		} else
5408 5744
 		{
5409 5745
 			$tzid_parts = explode('/', $tzid);
5410 5746
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5424,23 +5760,27 @@  discard block
 block discarded – undo
5424 5760
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5425 5761
 
5426 5762
 		// Use the custom description, if there is one
5427
-		if (!empty($tztxt[$tzvalue['tzid']]))
5428
-			$desc = $tztxt[$tzvalue['tzid']];
5763
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5764
+					$desc = $tztxt[$tzvalue['tzid']];
5765
+		}
5429 5766
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5430
-		else
5431
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5767
+		else {
5768
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5769
+		}
5432 5770
 
5433 5771
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5434 5772
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5435 5773
 
5436
-		if (isset($priority_zones[$tzkey]))
5437
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5438
-		else
5439
-			$timezones[$tzvalue['tzid']] = $desc;
5774
+		if (isset($priority_zones[$tzkey])) {
5775
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5776
+		} else {
5777
+					$timezones[$tzvalue['tzid']] = $desc;
5778
+		}
5440 5779
 	}
5441 5780
 
5442
-	if (!empty($priority_timezones))
5443
-		$priority_timezones[] = '-----';
5781
+	if (!empty($priority_timezones)) {
5782
+			$priority_timezones[] = '-----';
5783
+	}
5444 5784
 
5445 5785
 	$timezones = array_merge(
5446 5786
 		$priority_timezones,
@@ -5457,8 +5797,9 @@  discard block
 block discarded – undo
5457 5797
  */
5458 5798
 function inet_ptod($ip_address)
5459 5799
 {
5460
-	if (!isValidIP($ip_address))
5461
-		return $ip_address;
5800
+	if (!isValidIP($ip_address)) {
5801
+			return $ip_address;
5802
+	}
5462 5803
 
5463 5804
 	$bin = inet_pton($ip_address);
5464 5805
 	return $bin;
@@ -5470,13 +5811,15 @@  discard block
 block discarded – undo
5470 5811
  */
5471 5812
 function inet_dtop($bin)
5472 5813
 {
5473
-	if(empty($bin))
5474
-		return '';
5814
+	if(empty($bin)) {
5815
+			return '';
5816
+	}
5475 5817
 
5476 5818
 	global $db_type;
5477 5819
 
5478
-	if ($db_type == 'postgresql')
5479
-		return $bin;
5820
+	if ($db_type == 'postgresql') {
5821
+			return $bin;
5822
+	}
5480 5823
 
5481 5824
 	$ip_address = inet_ntop($bin);
5482 5825
 
@@ -5501,26 +5844,32 @@  discard block
 block discarded – undo
5501 5844
  */
5502 5845
 function _safe_serialize($value)
5503 5846
 {
5504
-	if(is_null($value))
5505
-		return 'N;';
5847
+	if(is_null($value)) {
5848
+			return 'N;';
5849
+	}
5506 5850
 
5507
-	if(is_bool($value))
5508
-		return 'b:'. (int) $value .';';
5851
+	if(is_bool($value)) {
5852
+			return 'b:'. (int) $value .';';
5853
+	}
5509 5854
 
5510
-	if(is_int($value))
5511
-		return 'i:'. $value .';';
5855
+	if(is_int($value)) {
5856
+			return 'i:'. $value .';';
5857
+	}
5512 5858
 
5513
-	if(is_float($value))
5514
-		return 'd:'. str_replace(',', '.', $value) .';';
5859
+	if(is_float($value)) {
5860
+			return 'd:'. str_replace(',', '.', $value) .';';
5861
+	}
5515 5862
 
5516
-	if(is_string($value))
5517
-		return 's:'. strlen($value) .':"'. $value .'";';
5863
+	if(is_string($value)) {
5864
+			return 's:'. strlen($value) .':"'. $value .'";';
5865
+	}
5518 5866
 
5519 5867
 	if(is_array($value))
5520 5868
 	{
5521 5869
 		$out = '';
5522
-		foreach($value as $k => $v)
5523
-			$out .= _safe_serialize($k) . _safe_serialize($v);
5870
+		foreach($value as $k => $v) {
5871
+					$out .= _safe_serialize($k) . _safe_serialize($v);
5872
+		}
5524 5873
 
5525 5874
 		return 'a:'. count($value) .':{'. $out .'}';
5526 5875
 	}
@@ -5546,8 +5895,9 @@  discard block
 block discarded – undo
5546 5895
 
5547 5896
 	$out = _safe_serialize($value);
5548 5897
 
5549
-	if (isset($mbIntEnc))
5550
-		mb_internal_encoding($mbIntEnc);
5898
+	if (isset($mbIntEnc)) {
5899
+			mb_internal_encoding($mbIntEnc);
5900
+	}
5551 5901
 
5552 5902
 	return $out;
5553 5903
 }
@@ -5564,8 +5914,9 @@  discard block
 block discarded – undo
5564 5914
 function _safe_unserialize($str)
5565 5915
 {
5566 5916
 	// Input  is not a string.
5567
-	if(empty($str) || !is_string($str))
5568
-		return false;
5917
+	if(empty($str) || !is_string($str)) {
5918
+			return false;
5919
+	}
5569 5920
 
5570 5921
 	$stack = array();
5571 5922
 	$expected = array();
@@ -5581,43 +5932,38 @@  discard block
 block discarded – undo
5581 5932
 	while($state != 1)
5582 5933
 	{
5583 5934
 		$type = isset($str[0]) ? $str[0] : '';
5584
-		if($type == '}')
5585
-			$str = substr($str, 1);
5586
-
5587
-		else if($type == 'N' && $str[1] == ';')
5935
+		if($type == '}') {
5936
+					$str = substr($str, 1);
5937
+		} else if($type == 'N' && $str[1] == ';')
5588 5938
 		{
5589 5939
 			$value = null;
5590 5940
 			$str = substr($str, 2);
5591
-		}
5592
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5941
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5593 5942
 		{
5594 5943
 			$value = $matches[1] == '1' ? true : false;
5595 5944
 			$str = substr($str, 4);
5596
-		}
5597
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5945
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5598 5946
 		{
5599 5947
 			$value = (int)$matches[1];
5600 5948
 			$str = $matches[2];
5601
-		}
5602
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5949
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5603 5950
 		{
5604 5951
 			$value = (float)$matches[1];
5605 5952
 			$str = $matches[3];
5606
-		}
5607
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5953
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5608 5954
 		{
5609 5955
 			$value = substr($matches[2], 0, (int)$matches[1]);
5610 5956
 			$str = substr($matches[2], (int)$matches[1] + 2);
5611
-		}
5612
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5957
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5613 5958
 		{
5614 5959
 			$expectedLength = (int)$matches[1];
5615 5960
 			$str = $matches[2];
5616 5961
 		}
5617 5962
 
5618 5963
 		// Object or unknown/malformed type.
5619
-		else
5620
-			return false;
5964
+		else {
5965
+					return false;
5966
+		}
5621 5967
 
5622 5968
 		switch($state)
5623 5969
 		{
@@ -5645,8 +5991,9 @@  discard block
 block discarded – undo
5645 5991
 				if($type == '}')
5646 5992
 				{
5647 5993
 					// Array size is less than expected.
5648
-					if(count($list) < end($expected))
5649
-						return false;
5994
+					if(count($list) < end($expected)) {
5995
+											return false;
5996
+					}
5650 5997
 
5651 5998
 					unset($list);
5652 5999
 					$list = &$stack[count($stack)-1];
@@ -5655,8 +6002,9 @@  discard block
 block discarded – undo
5655 6002
 					// Go to terminal state if we're at the end of the root array.
5656 6003
 					array_pop($expected);
5657 6004
 
5658
-					if(count($expected) == 0)
5659
-						$state = 1;
6005
+					if(count($expected) == 0) {
6006
+											$state = 1;
6007
+					}
5660 6008
 
5661 6009
 					break;
5662 6010
 				}
@@ -5664,8 +6012,9 @@  discard block
 block discarded – undo
5664 6012
 				if($type == 'i' || $type == 's')
5665 6013
 				{
5666 6014
 					// Array size exceeds expected length.
5667
-					if(count($list) >= end($expected))
5668
-						return false;
6015
+					if(count($list) >= end($expected)) {
6016
+											return false;
6017
+					}
5669 6018
 
5670 6019
 					$key = $value;
5671 6020
 					$state = 3;
@@ -5699,8 +6048,9 @@  discard block
 block discarded – undo
5699 6048
 	}
5700 6049
 
5701 6050
 	// Trailing data in input.
5702
-	if(!empty($str))
5703
-		return false;
6051
+	if(!empty($str)) {
6052
+			return false;
6053
+	}
5704 6054
 
5705 6055
 	return $data;
5706 6056
 }
@@ -5723,8 +6073,9 @@  discard block
 block discarded – undo
5723 6073
 
5724 6074
 	$out = _safe_unserialize($str);
5725 6075
 
5726
-	if (isset($mbIntEnc))
5727
-		mb_internal_encoding($mbIntEnc);
6076
+	if (isset($mbIntEnc)) {
6077
+			mb_internal_encoding($mbIntEnc);
6078
+	}
5728 6079
 
5729 6080
 	return $out;
5730 6081
 }
@@ -5739,12 +6090,14 @@  discard block
 block discarded – undo
5739 6090
 function smf_chmod($file, $value = 0)
5740 6091
 {
5741 6092
 	// No file? no checks!
5742
-	if (empty($file))
5743
-		return false;
6093
+	if (empty($file)) {
6094
+			return false;
6095
+	}
5744 6096
 
5745 6097
 	// Already writable?
5746
-	if (is_writable($file))
5747
-		return true;
6098
+	if (is_writable($file)) {
6099
+			return true;
6100
+	}
5748 6101
 
5749 6102
 	// Do we have a file or a dir?
5750 6103
 	$isDir = is_dir($file);
@@ -5760,10 +6113,9 @@  discard block
 block discarded – undo
5760 6113
 		{
5761 6114
 			$isWritable = true;
5762 6115
 			break;
6116
+		} else {
6117
+					@chmod($file, $val);
5763 6118
 		}
5764
-
5765
-		else
5766
-			@chmod($file, $val);
5767 6119
 	}
5768 6120
 
5769 6121
 	return $isWritable;
@@ -5782,8 +6134,9 @@  discard block
 block discarded – undo
5782 6134
 	global $txt;
5783 6135
 
5784 6136
 	// Come on...
5785
-	if (empty($json) || !is_string($json))
5786
-		return array();
6137
+	if (empty($json) || !is_string($json)) {
6138
+			return array();
6139
+	}
5787 6140
 
5788 6141
 	$returnArray = @json_decode($json, $returnAsArray);
5789 6142
 
@@ -5821,11 +6174,11 @@  discard block
 block discarded – undo
5821 6174
 		$jsonDebug = $jsonDebug[0];
5822 6175
 		loadLanguage('Errors');
5823 6176
 
5824
-		if (!empty($jsonDebug))
5825
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
5826
-
5827
-		else
5828
-			log_error($txt['json_'. $jsonError], 'critical');
6177
+		if (!empty($jsonDebug)) {
6178
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6179
+		} else {
6180
+					log_error($txt['json_'. $jsonError], 'critical');
6181
+		}
5829 6182
 
5830 6183
 		// Everyone expects an array.
5831 6184
 		return array();
@@ -5859,8 +6212,9 @@  discard block
 block discarded – undo
5859 6212
 	global $db_show_debug, $modSettings;
5860 6213
 
5861 6214
 	// Defensive programming anyone?
5862
-	if (empty($data))
5863
-		return false;
6215
+	if (empty($data)) {
6216
+			return false;
6217
+	}
5864 6218
 
5865 6219
 	// Don't need extra stuff...
5866 6220
 	$db_show_debug = false;
@@ -5868,11 +6222,11 @@  discard block
 block discarded – undo
5868 6222
 	// Kill anything else.
5869 6223
 	ob_end_clean();
5870 6224
 
5871
-	if (!empty($modSettings['CompressedOutput']))
5872
-		@ob_start('ob_gzhandler');
5873
-
5874
-	else
5875
-		ob_start();
6225
+	if (!empty($modSettings['CompressedOutput'])) {
6226
+			@ob_start('ob_gzhandler');
6227
+	} else {
6228
+			ob_start();
6229
+	}
5876 6230
 
5877 6231
 	// Set the header.
5878 6232
 	header($type);
@@ -5904,8 +6258,9 @@  discard block
 block discarded – undo
5904 6258
 	static $done = false;
5905 6259
 
5906 6260
 	// If we don't need to do anything, don't
5907
-	if (!$update && $done)
5908
-		return;
6261
+	if (!$update && $done) {
6262
+			return;
6263
+	}
5909 6264
 
5910 6265
 	// Should we get a new copy of the official list of TLDs?
5911 6266
 	if ($update)
@@ -5917,8 +6272,9 @@  discard block
 block discarded – undo
5917 6272
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
5918 6273
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
5919 6274
 		// update to see if civilization has been restored.
5920
-		if ($tlds === false)
5921
-			$postapocalypticNightmare = true;
6275
+		if ($tlds === false) {
6276
+					$postapocalypticNightmare = true;
6277
+		}
5922 6278
 	}
5923 6279
 	// If we aren't updating and the regex is valid, we're done
5924 6280
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -5933,10 +6289,11 @@  discard block
 block discarded – undo
5933 6289
 		// Clean $tlds and convert it to an array
5934 6290
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
5935 6291
 			$line = trim($line);
5936
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
5937
-				return false;
5938
-			else
5939
-				return true;
6292
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6293
+							return false;
6294
+			} else {
6295
+							return true;
6296
+			}
5940 6297
 		});
5941 6298
 
5942 6299
 		// Convert Punycode to Unicode
@@ -6028,8 +6385,7 @@  discard block
 block discarded – undo
6028 6385
 
6029 6386
 		$strlen = 'mb_strlen';
6030 6387
 		$substr = 'mb_substr';
6031
-	}
6032
-	else
6388
+	} else
6033 6389
 	{
6034 6390
 		$strlen = $smcFunc['strlen'];
6035 6391
 		$substr = $smcFunc['substr'];
@@ -6043,20 +6399,21 @@  discard block
 block discarded – undo
6043 6399
 
6044 6400
 		$first = $substr($string, 0, 1);
6045 6401
 
6046
-		if (empty($index[$first]))
6047
-			$index[$first] = array();
6402
+		if (empty($index[$first])) {
6403
+					$index[$first] = array();
6404
+		}
6048 6405
 
6049 6406
 		if ($strlen($string) > 1)
6050 6407
 		{
6051 6408
 			// Sanity check on recursion
6052
-			if ($depth > 99)
6053
-				$index[$first][$substr($string, 1)] = '';
6054
-
6055
-			else
6056
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6409
+			if ($depth > 99) {
6410
+							$index[$first][$substr($string, 1)] = '';
6411
+			} else {
6412
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6413
+			}
6414
+		} else {
6415
+					$index[$first][''] = '';
6057 6416
 		}
6058
-		else
6059
-			$index[$first][''] = '';
6060 6417
 
6061 6418
 		$depth--;
6062 6419
 		return $index;
@@ -6079,9 +6436,9 @@  discard block
 block discarded – undo
6079 6436
 			$key_regex = preg_quote($key, $delim);
6080 6437
 			$new_key = $key;
6081 6438
 
6082
-			if (empty($value))
6083
-				$sub_regex = '';
6084
-			else
6439
+			if (empty($value)) {
6440
+							$sub_regex = '';
6441
+			} else
6085 6442
 			{
6086 6443
 				$sub_regex = $index_to_regex($value, $delim);
6087 6444
 
@@ -6089,22 +6446,22 @@  discard block
 block discarded – undo
6089 6446
 				{
6090 6447
 					$new_key_array = explode('(?'.'>', $sub_regex);
6091 6448
 					$new_key .= $new_key_array[0];
6449
+				} else {
6450
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6092 6451
 				}
6093
-				else
6094
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6095 6452
 			}
6096 6453
 
6097
-			if ($depth > 1)
6098
-				$regex[$new_key] = $key_regex . $sub_regex;
6099
-			else
6454
+			if ($depth > 1) {
6455
+							$regex[$new_key] = $key_regex . $sub_regex;
6456
+			} else
6100 6457
 			{
6101 6458
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6102 6459
 				{
6103 6460
 					$regex[$new_key] = $key_regex . $sub_regex;
6104 6461
 					unset($index[$key]);
6462
+				} else {
6463
+									break;
6105 6464
 				}
6106
-				else
6107
-					break;
6108 6465
 			}
6109 6466
 		}
6110 6467
 
@@ -6113,10 +6470,11 @@  discard block
 block discarded – undo
6113 6470
 			$l1 = $strlen($k1);
6114 6471
 			$l2 = $strlen($k2);
6115 6472
 
6116
-			if ($l1 == $l2)
6117
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6118
-			else
6119
-				return $l1 > $l2 ? -1 : 1;
6473
+			if ($l1 == $l2) {
6474
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6475
+			} else {
6476
+							return $l1 > $l2 ? -1 : 1;
6477
+			}
6120 6478
 		});
6121 6479
 
6122 6480
 		$depth--;
@@ -6127,21 +6485,24 @@  discard block
 block discarded – undo
6127 6485
 	$index = array();
6128 6486
 	$regex = '';
6129 6487
 
6130
-	foreach ($strings as $string)
6131
-		$index = $add_string_to_index($string, $index);
6488
+	foreach ($strings as $string) {
6489
+			$index = $add_string_to_index($string, $index);
6490
+	}
6132 6491
 
6133 6492
 	if ($returnArray === true)
6134 6493
 	{
6135 6494
 		$regex = array();
6136
-		while (!empty($index))
6137
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6495
+		while (!empty($index)) {
6496
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6497
+		}
6498
+	} else {
6499
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6138 6500
 	}
6139
-	else
6140
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6141 6501
 
6142 6502
 	// Restore PHP's internal character encoding to whatever it was originally
6143
-	if (!empty($current_encoding))
6144
-		mb_internal_encoding($current_encoding);
6503
+	if (!empty($current_encoding)) {
6504
+			mb_internal_encoding($current_encoding);
6505
+	}
6145 6506
 
6146 6507
 	return $regex;
6147 6508
 }
@@ -6184,13 +6545,15 @@  discard block
 block discarded – undo
6184 6545
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6185 6546
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6186 6547
 	$headers = @get_headers($url);
6187
-	if ($headers === false)
6188
-		return false;
6548
+	if ($headers === false) {
6549
+			return false;
6550
+	}
6189 6551
 
6190 6552
 	// Now to see if it came back https...
6191 6553
 	// First check for a redirect status code in first row (301, 302, 307)
6192
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6193
-		return false;
6554
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6555
+			return false;
6556
+	}
6194 6557
 
6195 6558
 	// Search for the location entry to confirm https
6196 6559
 	$result = false;
@@ -6228,8 +6591,7 @@  discard block
 block discarded – undo
6228 6591
 		$is_admin = $user_info['is_admin'];
6229 6592
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6230 6593
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6231
-	}
6232
-	else
6594
+	} else
6233 6595
 	{
6234 6596
 		$request = $smcFunc['db_query']('', '
6235 6597
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6243,17 +6605,19 @@  discard block
 block discarded – undo
6243 6605
 
6244 6606
 		$row = $smcFunc['db_fetch_assoc']($request);
6245 6607
 
6246
-		if (empty($row['additional_groups']))
6247
-			$groups = array($row['id_group'], $row['id_post_group']);
6248
-		else
6249
-			$groups = array_merge(
6608
+		if (empty($row['additional_groups'])) {
6609
+					$groups = array($row['id_group'], $row['id_post_group']);
6610
+		} else {
6611
+					$groups = array_merge(
6250 6612
 					array($row['id_group'], $row['id_post_group']),
6251 6613
 					explode(',', $row['additional_groups'])
6252 6614
 			);
6615
+		}
6253 6616
 
6254 6617
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6255
-		foreach ($groups as $k => $v)
6256
-			$groups[$k] = (int) $v;
6618
+		foreach ($groups as $k => $v) {
6619
+					$groups[$k] = (int) $v;
6620
+		}
6257 6621
 
6258 6622
 		$is_admin = in_array(1, $groups);
6259 6623
 
@@ -6270,8 +6634,9 @@  discard block
 block discarded – undo
6270 6634
 				'current_member' => $userid,
6271 6635
 			)
6272 6636
 		);
6273
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6274
-			$boards_mod[] = $row['id_board'];
6637
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6638
+					$boards_mod[] = $row['id_board'];
6639
+		}
6275 6640
 		$smcFunc['db_free_result']($request);
6276 6641
 
6277 6642
 		// Can any of the groups they're in moderate any of the boards?
@@ -6283,8 +6648,9 @@  discard block
 block discarded – undo
6283 6648
 				'groups' => $groups,
6284 6649
 			)
6285 6650
 		);
6286
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6287
-			$boards_mod[] = $row['id_board'];
6651
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6652
+					$boards_mod[] = $row['id_board'];
6653
+		}
6288 6654
 		$smcFunc['db_free_result']($request);
6289 6655
 
6290 6656
 		// Just in case we've got duplicates here...
@@ -6294,21 +6660,25 @@  discard block
 block discarded – undo
6294 6660
 	}
6295 6661
 
6296 6662
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6297
-	if ($is_admin)
6298
-		$query_part['query_see_board'] = '1=1';
6663
+	if ($is_admin) {
6664
+			$query_part['query_see_board'] = '1=1';
6665
+	}
6299 6666
 	// Otherwise just the groups in $user_info['groups'].
6300
-	else
6301
-		$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6667
+	else {
6668
+			$query_part['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $groups) . ', b.member_groups) != 0)' . (!empty($deny_boards_access) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $groups) . ', b.deny_member_groups) = 0)' : '') . (isset($mod_cache) ? ' OR ' . $mod_cache['mq'] : '') . ')';
6669
+	}
6302 6670
 
6303 6671
 	// Build the list of boards they WANT to see.
6304 6672
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6305 6673
 
6306 6674
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6307
-	if (empty($ignoreboards))
6308
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6675
+	if (empty($ignoreboards)) {
6676
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6677
+	}
6309 6678
 	// Ok I guess they don't want to see all the boards
6310
-	else
6311
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6679
+	else {
6680
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6681
+	}
6312 6682
 
6313 6683
 	return $query_part;
6314 6684
 }
@@ -6322,10 +6692,11 @@  discard block
 block discarded – undo
6322 6692
 {
6323 6693
 	$secure = false;
6324 6694
 
6325
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6326
-		$secure = true;
6327
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
6328
-		$secure = true;
6695
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6696
+			$secure = true;
6697
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
6698
+			$secure = true;
6699
+	}
6329 6700
 
6330 6701
 	return $secure;
6331 6702
 }
@@ -6342,11 +6713,12 @@  discard block
 block discarded – undo
6342 6713
 {
6343 6714
 	$url = iri_to_url($iri);
6344 6715
 
6345
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6346
-		return $iri;
6347
-	else
6348
-		return false;
6349
-}
6716
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6717
+			return $iri;
6718
+	} else {
6719
+			return false;
6720
+	}
6721
+	}
6350 6722
 
6351 6723
 /**
6352 6724
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6389,8 +6761,9 @@  discard block
 block discarded – undo
6389 6761
 
6390 6762
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6391 6763
 
6392
-	if (empty($host))
6393
-		return $iri;
6764
+	if (empty($host)) {
6765
+			return $iri;
6766
+	}
6394 6767
 
6395 6768
 	// Convert the domain using the Punycode algorithm
6396 6769
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6426,8 +6799,9 @@  discard block
 block discarded – undo
6426 6799
 
6427 6800
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6428 6801
 
6429
-	if (empty($host))
6430
-		return $url;
6802
+	if (empty($host)) {
6803
+			return $url;
6804
+	}
6431 6805
 
6432 6806
 	// Decode the domain from Punycode
6433 6807
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6453,8 +6827,9 @@  discard block
 block discarded – undo
6453 6827
 {
6454 6828
 	global $user_info, $modSettings, $smcFunc, $txt;
6455 6829
 
6456
-	if (empty($modSettings['cron_last_checked']))
6457
-		$modSettings['cron_last_checked'] = 0;
6830
+	if (empty($modSettings['cron_last_checked'])) {
6831
+			$modSettings['cron_last_checked'] = 0;
6832
+	}
6458 6833
 
6459 6834
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6460 6835
 	{
@@ -6474,9 +6849,9 @@  discard block
 block discarded – undo
6474 6849
 			loadLanguage('ManageScheduledTasks');
6475 6850
 			log_error($txt['cron_not_working']);
6476 6851
 			updateSettings(array('cron_is_real_cron' => 0));
6852
+		} else {
6853
+					updateSettings(array('cron_last_checked' => time()));
6477 6854
 		}
6478
-		else
6479
-			updateSettings(array('cron_last_checked' => time()));
6480 6855
 	}
6481 6856
 }
6482 6857
 
Please login to merge, or discard this patch.
Sources/Search.php 1 patch
Braces   +417 added lines, -309 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 // This defines two version types for checking the API's are compatible with this version of SMF.
20 21
 $GLOBALS['search_versions'] = array(
@@ -39,8 +40,9 @@  discard block
 block discarded – undo
39 40
 	global $txt, $scripturl, $modSettings, $user_info, $context, $smcFunc, $sourcedir;
40 41
 
41 42
 	// Is the load average too high to allow searching just now?
42
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
43
-		fatal_lang_error('loadavg_search_disabled', false);
43
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
44
+			fatal_lang_error('loadavg_search_disabled', false);
45
+	}
44 46
 
45 47
 	loadLanguage('Search');
46 48
 	// Don't load this in XML mode.
@@ -88,23 +90,30 @@  discard block
 block discarded – undo
88 90
 			@list ($k, $v) = explode('|\'|', $data);
89 91
 			$context['search_params'][$k] = $v;
90 92
 		}
91
-		if (isset($context['search_params']['brd']))
92
-			$context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']);
93
+		if (isset($context['search_params']['brd'])) {
94
+					$context['search_params']['brd'] = $context['search_params']['brd'] == '' ? array() : explode(',', $context['search_params']['brd']);
95
+		}
93 96
 	}
94 97
 
95
-	if (isset($_REQUEST['search']))
96
-		$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
98
+	if (isset($_REQUEST['search'])) {
99
+			$context['search_params']['search'] = un_htmlspecialchars($_REQUEST['search']);
100
+	}
97 101
 
98
-	if (isset($context['search_params']['search']))
99
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
100
-	if (isset($context['search_params']['userspec']))
101
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
102
-	if (!empty($context['search_params']['searchtype']))
103
-		$context['search_params']['searchtype'] = 2;
104
-	if (!empty($context['search_params']['minage']))
105
-		$context['search_params']['minage'] = (int) $context['search_params']['minage'];
106
-	if (!empty($context['search_params']['maxage']))
107
-		$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
102
+	if (isset($context['search_params']['search'])) {
103
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
104
+	}
105
+	if (isset($context['search_params']['userspec'])) {
106
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
107
+	}
108
+	if (!empty($context['search_params']['searchtype'])) {
109
+			$context['search_params']['searchtype'] = 2;
110
+	}
111
+	if (!empty($context['search_params']['minage'])) {
112
+			$context['search_params']['minage'] = (int) $context['search_params']['minage'];
113
+	}
114
+	if (!empty($context['search_params']['maxage'])) {
115
+			$context['search_params']['maxage'] = (int) $context['search_params']['maxage'];
116
+	}
108 117
 
109 118
 	$context['search_params']['show_complete'] = !empty($context['search_params']['show_complete']);
110 119
 	$context['search_params']['subject_only'] = !empty($context['search_params']['subject_only']);
@@ -116,11 +125,13 @@  discard block
 block discarded – undo
116 125
 		$context['search_errors']['messages'] = array();
117 126
 		foreach ($context['search_errors'] as $search_error => $dummy)
118 127
 		{
119
-			if ($search_error === 'messages')
120
-				continue;
128
+			if ($search_error === 'messages') {
129
+							continue;
130
+			}
121 131
 
122
-			if ($search_error == 'string_too_long')
123
-				$txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']);
132
+			if ($search_error == 'string_too_long') {
133
+							$txt['error_string_too_long'] = sprintf($txt['error_string_too_long'], $context['search_string_limit']);
134
+			}
124 135
 
125 136
 			$context['search_errors']['messages'][] = $txt['error_' . $search_error];
126 137
 		}
@@ -143,12 +154,13 @@  discard block
 block discarded – undo
143 154
 	while ($row = $smcFunc['db_fetch_assoc']($request))
144 155
 	{
145 156
 		// This category hasn't been set up yet..
146
-		if (!isset($context['categories'][$row['id_cat']]))
147
-			$context['categories'][$row['id_cat']] = array(
157
+		if (!isset($context['categories'][$row['id_cat']])) {
158
+					$context['categories'][$row['id_cat']] = array(
148 159
 				'id' => $row['id_cat'],
149 160
 				'name' => $row['cat_name'],
150 161
 				'boards' => array()
151 162
 			);
163
+		}
152 164
 
153 165
 		// Set this board up, and let the template know when it's a child.  (indent them..)
154 166
 		$context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array(
@@ -159,8 +171,9 @@  discard block
 block discarded – undo
159 171
 		);
160 172
 
161 173
 		// If a board wasn't checked that probably should have been ensure the board selection is selected, yo!
162
-		if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board']))
163
-			$context['boards_check_all'] = false;
174
+		if (!$context['categories'][$row['id_cat']]['boards'][$row['id_board']]['selected'] && (empty($modSettings['recycle_enable']) || $row['id_board'] != $modSettings['recycle_board'])) {
175
+					$context['boards_check_all'] = false;
176
+		}
164 177
 	}
165 178
 	$smcFunc['db_free_result']($request);
166 179
 
@@ -182,18 +195,20 @@  discard block
 block discarded – undo
182 195
 	}
183 196
 
184 197
 	$max_boards = ceil(count($temp_boards) / 2);
185
-	if ($max_boards == 1)
186
-		$max_boards = 2;
198
+	if ($max_boards == 1) {
199
+			$max_boards = 2;
200
+	}
187 201
 
188 202
 	// Now, alternate them so they can be shown left and right ;).
189 203
 	$context['board_columns'] = array();
190 204
 	for ($i = 0; $i < $max_boards; $i++)
191 205
 	{
192 206
 		$context['board_columns'][] = $temp_boards[$i];
193
-		if (isset($temp_boards[$i + $max_boards]))
194
-			$context['board_columns'][] = $temp_boards[$i + $max_boards];
195
-		else
196
-			$context['board_columns'][] = array();
207
+		if (isset($temp_boards[$i + $max_boards])) {
208
+					$context['board_columns'][] = $temp_boards[$i + $max_boards];
209
+		} else {
210
+					$context['board_columns'][] = array();
211
+		}
197 212
 	}
198 213
 
199 214
 	if (!empty($_REQUEST['topic']))
@@ -225,8 +240,9 @@  discard block
 block discarded – undo
225 240
 			)
226 241
 		);
227 242
 
228
-		if ($smcFunc['db_num_rows']($request) == 0)
229
-			fatal_lang_error('topic_gone', false);
243
+		if ($smcFunc['db_num_rows']($request) == 0) {
244
+					fatal_lang_error('topic_gone', false);
245
+		}
230 246
 
231 247
 		list ($context['search_topic']['subject']) = $smcFunc['db_fetch_row']($request);
232 248
 		$smcFunc['db_free_result']($request);
@@ -256,11 +272,13 @@  discard block
 block discarded – undo
256 272
 	global $excludedWords, $participants, $smcFunc;
257 273
 
258 274
 	// if comming from the quick search box, and we want to search on members, well we need to do that ;)
259
-	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members')
260
-		redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
275
+	if (isset($_REQUEST['search_selection']) && $_REQUEST['search_selection'] === 'members') {
276
+			redirectexit($scripturl . '?action=mlist;sa=search;fields=name,email;search=' . urlencode($_REQUEST['search']));
277
+	}
261 278
 
262
-	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search'])
263
-		fatal_lang_error('loadavg_search_disabled', false);
279
+	if (!empty($context['load_average']) && !empty($modSettings['loadavg_search']) && $context['load_average'] >= $modSettings['loadavg_search']) {
280
+			fatal_lang_error('loadavg_search_disabled', false);
281
+	}
264 282
 
265 283
 	// No, no, no... this is a bit hard on the server, so don't you go prefetching it!
266 284
 	if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
@@ -307,8 +325,9 @@  discard block
 block discarded – undo
307 325
 	}
308 326
 
309 327
 	// Zero weight.  Weightless :P.
310
-	if (empty($weight_total))
311
-		fatal_lang_error('search_invalid_weights');
328
+	if (empty($weight_total)) {
329
+			fatal_lang_error('search_invalid_weights');
330
+	}
312 331
 
313 332
 	// These vars don't require an interface, they're just here for tweaking.
314 333
 	$recentPercentage = 0.30;
@@ -326,11 +345,13 @@  discard block
 block discarded – undo
326 345
 	$context['search_string_limit'] = 100;
327 346
 
328 347
 	loadLanguage('Search');
329
-	if (!isset($_REQUEST['xml']))
330
-		loadTemplate('Search');
348
+	if (!isset($_REQUEST['xml'])) {
349
+			loadTemplate('Search');
350
+	}
331 351
 	//If we're doing XML we need to use the results template regardless really.
332
-	else
333
-		$context['sub_template'] = 'results';
352
+	else {
353
+			$context['sub_template'] = 'results';
354
+	}
334 355
 
335 356
 	// Are you allowed?
336 357
 	isAllowedTo('search_posts');
@@ -363,34 +384,39 @@  discard block
 block discarded – undo
363 384
 			$search_params[$k] = $v;
364 385
 		}
365 386
 
366
-		if (isset($search_params['brd']))
367
-			$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
387
+		if (isset($search_params['brd'])) {
388
+					$search_params['brd'] = empty($search_params['brd']) ? array() : explode(',', $search_params['brd']);
389
+		}
368 390
 	}
369 391
 
370 392
 	// Store whether simple search was used (needed if the user wants to do another query).
371
-	if (!isset($search_params['advanced']))
372
-		$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
393
+	if (!isset($search_params['advanced'])) {
394
+			$search_params['advanced'] = empty($_REQUEST['advanced']) ? 0 : 1;
395
+	}
373 396
 
374 397
 	// 1 => 'allwords' (default, don't set as param) / 2 => 'anywords'.
375
-	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2))
376
-		$search_params['searchtype'] = 2;
398
+	if (!empty($search_params['searchtype']) || (!empty($_REQUEST['searchtype']) && $_REQUEST['searchtype'] == 2)) {
399
+			$search_params['searchtype'] = 2;
400
+	}
377 401
 
378 402
 	// Minimum age of messages. Default to zero (don't set param in that case).
379
-	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0))
380
-		$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
403
+	if (!empty($search_params['minage']) || (!empty($_REQUEST['minage']) && $_REQUEST['minage'] > 0)) {
404
+			$search_params['minage'] = !empty($search_params['minage']) ? (int) $search_params['minage'] : (int) $_REQUEST['minage'];
405
+	}
381 406
 
382 407
 	// Maximum age of messages. Default to infinite (9999 days: param not set).
383
-	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999))
384
-		$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
408
+	if (!empty($search_params['maxage']) || (!empty($_REQUEST['maxage']) && $_REQUEST['maxage'] < 9999)) {
409
+			$search_params['maxage'] = !empty($search_params['maxage']) ? (int) $search_params['maxage'] : (int) $_REQUEST['maxage'];
410
+	}
385 411
 
386 412
 	// Searching a specific topic?
387 413
 	if (!empty($_REQUEST['topic']) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'topic'))
388 414
 	{
389 415
 		$search_params['topic'] = empty($_REQUEST['search_selection']) ? (int) $_REQUEST['topic'] : (isset($_REQUEST['sd_topic']) ? (int) $_REQUEST['sd_topic'] : '');
390 416
 		$search_params['show_complete'] = true;
417
+	} elseif (!empty($search_params['topic'])) {
418
+			$search_params['topic'] = (int) $search_params['topic'];
391 419
 	}
392
-	elseif (!empty($search_params['topic']))
393
-		$search_params['topic'] = (int) $search_params['topic'];
394 420
 
395 421
 	if (!empty($search_params['minage']) || !empty($search_params['maxage']))
396 422
 	{
@@ -408,19 +434,21 @@  discard block
 block discarded – undo
408 434
 			)
409 435
 		);
410 436
 		list ($minMsgID, $maxMsgID) = $smcFunc['db_fetch_row']($request);
411
-		if ($minMsgID < 0 || $maxMsgID < 0)
412
-			$context['search_errors']['no_messages_in_time_frame'] = true;
437
+		if ($minMsgID < 0 || $maxMsgID < 0) {
438
+					$context['search_errors']['no_messages_in_time_frame'] = true;
439
+		}
413 440
 		$smcFunc['db_free_result']($request);
414 441
 	}
415 442
 
416 443
 	// Default the user name to a wildcard matching every user (*).
417
-	if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*'))
418
-		$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
444
+	if (!empty($search_params['userspec']) || (!empty($_REQUEST['userspec']) && $_REQUEST['userspec'] != '*')) {
445
+			$search_params['userspec'] = isset($search_params['userspec']) ? $search_params['userspec'] : $_REQUEST['userspec'];
446
+	}
419 447
 
420 448
 	// If there's no specific user, then don't mention it in the main query.
421
-	if (empty($search_params['userspec']))
422
-		$userQuery = '';
423
-	else
449
+	if (empty($search_params['userspec'])) {
450
+			$userQuery = '';
451
+	} else
424 452
 	{
425 453
 		$userString = strtr($smcFunc['htmlspecialchars']($search_params['userspec'], ENT_QUOTES), array('&quot;' => '"'));
426 454
 		$userString = strtr($userString, array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_'));
@@ -432,19 +460,21 @@  discard block
 block discarded – undo
432 460
 		{
433 461
 			$possible_users[$k] = trim($possible_users[$k]);
434 462
 
435
-			if (strlen($possible_users[$k]) == 0)
436
-				unset($possible_users[$k]);
463
+			if (strlen($possible_users[$k]) == 0) {
464
+							unset($possible_users[$k]);
465
+			}
437 466
 		}
438 467
 
439 468
 		// Create a list of database-escaped search names.
440 469
 		$realNameMatches = array();
441
-		foreach ($possible_users as $possible_user)
442
-			$realNameMatches[] = $smcFunc['db_quote'](
470
+		foreach ($possible_users as $possible_user) {
471
+					$realNameMatches[] = $smcFunc['db_quote'](
443 472
 				'{string:possible_user}',
444 473
 				array(
445 474
 					'possible_user' => $possible_user
446 475
 				)
447 476
 			);
477
+		}
448 478
 
449 479
 		// Retrieve a list of possible members.
450 480
 		$request = $smcFunc['db_query']('', '
@@ -456,9 +486,9 @@  discard block
 block discarded – undo
456 486
 			)
457 487
 		);
458 488
 		// Simply do nothing if there're too many members matching the criteria.
459
-		if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch)
460
-			$userQuery = '';
461
-		elseif ($smcFunc['db_num_rows']($request) == 0)
489
+		if ($smcFunc['db_num_rows']($request) > $maxMembersToSearch) {
490
+					$userQuery = '';
491
+		} elseif ($smcFunc['db_num_rows']($request) == 0)
462 492
 		{
463 493
 			$userQuery = $smcFunc['db_quote'](
464 494
 				'm.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})',
@@ -467,12 +497,12 @@  discard block
 block discarded – undo
467 497
 					'match_possible_guest_names' => 'm.poster_name LIKE ' . implode(' OR m.poster_name LIKE ', $realNameMatches),
468 498
 				)
469 499
 			);
470
-		}
471
-		else
500
+		} else
472 501
 		{
473 502
 			$memberlist = array();
474
-			while ($row = $smcFunc['db_fetch_assoc']($request))
475
-				$memberlist[] = $row['id_member'];
503
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
504
+							$memberlist[] = $row['id_member'];
505
+			}
476 506
 			$userQuery = $smcFunc['db_quote'](
477 507
 				'(m.id_member IN ({array_int:matched_members}) OR (m.id_member = {int:id_member_guest} AND ({raw:match_possible_guest_names})))',
478 508
 				array(
@@ -486,22 +516,25 @@  discard block
 block discarded – undo
486 516
 	}
487 517
 
488 518
 	// If the boards were passed by URL (params=), temporarily put them back in $_REQUEST.
489
-	if (!empty($search_params['brd']) && is_array($search_params['brd']))
490
-		$_REQUEST['brd'] = $search_params['brd'];
519
+	if (!empty($search_params['brd']) && is_array($search_params['brd'])) {
520
+			$_REQUEST['brd'] = $search_params['brd'];
521
+	}
491 522
 
492 523
 	// Ensure that brd is an array.
493 524
 	if ((!empty($_REQUEST['brd']) && !is_array($_REQUEST['brd'])) || (!empty($_REQUEST['search_selection']) && $_REQUEST['search_selection'] == 'board'))
494 525
 	{
495
-		if (!empty($_REQUEST['brd']))
496
-			$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
497
-		else
498
-			$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
526
+		if (!empty($_REQUEST['brd'])) {
527
+					$_REQUEST['brd'] = strpos($_REQUEST['brd'], ',') !== false ? explode(',', $_REQUEST['brd']) : array($_REQUEST['brd']);
528
+		} else {
529
+					$_REQUEST['brd'] = isset($_REQUEST['sd_brd']) ? array($_REQUEST['sd_brd']) : array();
530
+		}
499 531
 	}
500 532
 
501 533
 	// Make sure all boards are integers.
502
-	if (!empty($_REQUEST['brd']))
503
-		foreach ($_REQUEST['brd'] as $id => $brd)
534
+	if (!empty($_REQUEST['brd'])) {
535
+			foreach ($_REQUEST['brd'] as $id => $brd)
504 536
 			$_REQUEST['brd'][$id] = (int) $brd;
537
+	}
505 538
 
506 539
 	// Special case for boards: searching just one topic?
507 540
 	if (!empty($search_params['topic']))
@@ -520,17 +553,18 @@  discard block
 block discarded – undo
520 553
 			)
521 554
 		);
522 555
 
523
-		if ($smcFunc['db_num_rows']($request) == 0)
524
-			fatal_lang_error('topic_gone', false);
556
+		if ($smcFunc['db_num_rows']($request) == 0) {
557
+					fatal_lang_error('topic_gone', false);
558
+		}
525 559
 
526 560
 		$search_params['brd'] = array();
527 561
 		list ($search_params['brd'][0]) = $smcFunc['db_fetch_row']($request);
528 562
 		$smcFunc['db_free_result']($request);
529 563
 	}
530 564
 	// Select all boards you've selected AND are allowed to see.
531
-	elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd'])))
532
-		$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
533
-	else
565
+	elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd']))) {
566
+			$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
567
+	} else
534 568
 	{
535 569
 		$see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board';
536 570
 		$request = $smcFunc['db_query']('', '
@@ -548,19 +582,22 @@  discard block
 block discarded – undo
548 582
 			)
549 583
 		);
550 584
 		$search_params['brd'] = array();
551
-		while ($row = $smcFunc['db_fetch_assoc']($request))
552
-			$search_params['brd'][] = $row['id_board'];
585
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
586
+					$search_params['brd'][] = $row['id_board'];
587
+		}
553 588
 		$smcFunc['db_free_result']($request);
554 589
 
555 590
 		// This error should pro'bly only happen for hackers.
556
-		if (empty($search_params['brd']))
557
-			$context['search_errors']['no_boards_selected'] = true;
591
+		if (empty($search_params['brd'])) {
592
+					$context['search_errors']['no_boards_selected'] = true;
593
+		}
558 594
 	}
559 595
 
560 596
 	if (count($search_params['brd']) != 0)
561 597
 	{
562
-		foreach ($search_params['brd'] as $k => $v)
563
-			$search_params['brd'][$k] = (int) $v;
598
+		foreach ($search_params['brd'] as $k => $v) {
599
+					$search_params['brd'][$k] = (int) $v;
600
+		}
564 601
 
565 602
 		// If we've selected all boards, this parameter can be left empty.
566 603
 		$request = $smcFunc['db_query']('', '
@@ -574,15 +611,16 @@  discard block
 block discarded – undo
574 611
 		list ($num_boards) = $smcFunc['db_fetch_row']($request);
575 612
 		$smcFunc['db_free_result']($request);
576 613
 
577
-		if (count($search_params['brd']) == $num_boards)
614
+		if (count($search_params['brd']) == $num_boards) {
615
+					$boardQuery = '';
616
+		} elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd'])) {
617
+					$boardQuery = '!= ' . $modSettings['recycle_board'];
618
+		} else {
619
+					$boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')';
620
+		}
621
+	} else {
578 622
 			$boardQuery = '';
579
-		elseif (count($search_params['brd']) == $num_boards - 1 && !empty($modSettings['recycle_board']) && !in_array($modSettings['recycle_board'], $search_params['brd']))
580
-			$boardQuery = '!= ' . $modSettings['recycle_board'];
581
-		else
582
-			$boardQuery = 'IN (' . implode(', ', $search_params['brd']) . ')';
583 623
 	}
584
-	else
585
-		$boardQuery = '';
586 624
 
587 625
 	$search_params['show_complete'] = !empty($search_params['show_complete']) || !empty($_REQUEST['show_complete']);
588 626
 	$search_params['subject_only'] = !empty($search_params['subject_only']) || !empty($_REQUEST['subject_only']);
@@ -596,11 +634,13 @@  discard block
 block discarded – undo
596 634
 		'id_msg',
597 635
 	);
598 636
 	call_integration_hook('integrate_search_sort_columns', array(&$sort_columns));
599
-	if (empty($search_params['sort']) && !empty($_REQUEST['sort']))
600
-		list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
637
+	if (empty($search_params['sort']) && !empty($_REQUEST['sort'])) {
638
+			list ($search_params['sort'], $search_params['sort_dir']) = array_pad(explode('|', $_REQUEST['sort']), 2, '');
639
+	}
601 640
 	$search_params['sort'] = !empty($search_params['sort']) && in_array($search_params['sort'], $sort_columns) ? $search_params['sort'] : 'relevance';
602
-	if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies')
603
-		$search_params['sort'] = 'id_msg';
641
+	if (!empty($search_params['topic']) && $search_params['sort'] === 'num_replies') {
642
+			$search_params['sort'] = 'id_msg';
643
+	}
604 644
 
605 645
 	// Sorting direction: descending unless stated otherwise.
606 646
 	$search_params['sort_dir'] = !empty($search_params['sort_dir']) && $search_params['sort_dir'] == 'asc' ? 'asc' : 'desc';
@@ -624,17 +664,19 @@  discard block
 block discarded – undo
624 664
 	// What are we searching for?
625 665
 	if (empty($search_params['search']))
626 666
 	{
627
-		if (isset($_GET['search']))
628
-			$search_params['search'] = un_htmlspecialchars($_GET['search']);
629
-		elseif (isset($_POST['search']))
630
-			$search_params['search'] = $_POST['search'];
631
-		else
632
-			$search_params['search'] = '';
667
+		if (isset($_GET['search'])) {
668
+					$search_params['search'] = un_htmlspecialchars($_GET['search']);
669
+		} elseif (isset($_POST['search'])) {
670
+					$search_params['search'] = $_POST['search'];
671
+		} else {
672
+					$search_params['search'] = '';
673
+		}
633 674
 	}
634 675
 
635 676
 	// Nothing??
636
-	if (!isset($search_params['search']) || $search_params['search'] == '')
637
-		$context['search_errors']['invalid_search_string'] = true;
677
+	if (!isset($search_params['search']) || $search_params['search'] == '') {
678
+			$context['search_errors']['invalid_search_string'] = true;
679
+	}
638 680
 	// Too long?
639 681
 	elseif ($smcFunc['strlen']($search_params['search']) > $context['search_string_limit'])
640 682
 	{
@@ -648,8 +690,9 @@  discard block
 block discarded – undo
648 690
 	$stripped_query = un_htmlspecialchars($smcFunc['strtolower']($stripped_query));
649 691
 
650 692
 	// This (hidden) setting will do fulltext searching in the most basic way.
651
-	if (!empty($modSettings['search_simple_fulltext']))
652
-		$stripped_query = strtr($stripped_query, array('"' => ''));
693
+	if (!empty($modSettings['search_simple_fulltext'])) {
694
+			$stripped_query = strtr($stripped_query, array('"' => ''));
695
+	}
653 696
 
654 697
 	$no_regexp = preg_match('~&#(?:\d{1,7}|x[0-9a-fA-F]{1,6});~', $stripped_query) === 1;
655 698
 
@@ -672,8 +715,9 @@  discard block
 block discarded – undo
672 715
 	{
673 716
 		if ($word === '-')
674 717
 		{
675
-			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
676
-				$excludedWords[] = $word;
718
+			if (($word = trim($phraseArray[$index], '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
719
+							$excludedWords[] = $word;
720
+			}
677 721
 			unset($phraseArray[$index]);
678 722
 		}
679 723
 	}
@@ -683,8 +727,9 @@  discard block
 block discarded – undo
683 727
 	{
684 728
 		if (strpos(trim($word), '-') === 0)
685 729
 		{
686
-			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words))
687
-				$excludedWords[] = $word;
730
+			if (($word = trim($word, '-_\' ')) !== '' && !in_array($word, $blacklisted_words)) {
731
+							$excludedWords[] = $word;
732
+			}
688 733
 			unset($wordArray[$index]);
689 734
 		}
690 735
 	}
@@ -697,8 +742,9 @@  discard block
 block discarded – undo
697 742
 	foreach ($searchArray as $index => $value)
698 743
 	{
699 744
 		// Skip anything practically empty.
700
-		if (($searchArray[$index] = trim($value, '-_\' ')) === '')
701
-			unset($searchArray[$index]);
745
+		if (($searchArray[$index] = trim($value, '-_\' ')) === '') {
746
+					unset($searchArray[$index]);
747
+		}
702 748
 		// Skip blacklisted words. Make sure to note we skipped them in case we end up with nothing.
703 749
 		elseif (in_array($searchArray[$index], $blacklisted_words))
704 750
 		{
@@ -716,31 +762,37 @@  discard block
 block discarded – undo
716 762
 
717 763
 	// Create an array of replacements for highlighting.
718 764
 	$context['mark'] = array();
719
-	foreach ($searchArray as $word)
720
-		$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
765
+	foreach ($searchArray as $word) {
766
+			$context['mark'][$word] = '<strong class="highlight">' . $word . '</strong>';
767
+	}
721 768
 
722 769
 	// Initialize two arrays storing the words that have to be searched for.
723 770
 	$orParts = array();
724 771
 	$searchWords = array();
725 772
 
726 773
 	// Make sure at least one word is being searched for.
727
-	if (empty($searchArray))
728
-		$context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
774
+	if (empty($searchArray)) {
775
+			$context['search_errors']['invalid_search_string' . (!empty($foundBlackListedWords) ? '_blacklist' : '')] = true;
776
+	}
729 777
 	// All words/sentences must match.
730
-	elseif (empty($search_params['searchtype']))
731
-		$orParts[0] = $searchArray;
778
+	elseif (empty($search_params['searchtype'])) {
779
+			$orParts[0] = $searchArray;
780
+	}
732 781
 	// Any word/sentence must match.
733
-	else
734
-		foreach ($searchArray as $index => $value)
782
+	else {
783
+			foreach ($searchArray as $index => $value)
735 784
 			$orParts[$index] = array($value);
785
+	}
736 786
 
737 787
 	// Don't allow duplicate error messages if one string is too short.
738
-	if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string']))
739
-		unset($context['search_errors']['invalid_search_string']);
788
+	if (isset($context['search_errors']['search_string_small_words'], $context['search_errors']['invalid_search_string'])) {
789
+			unset($context['search_errors']['invalid_search_string']);
790
+	}
740 791
 	// Make sure the excluded words are in all or-branches.
741
-	foreach ($orParts as $orIndex => $andParts)
742
-		foreach ($excludedWords as $word)
792
+	foreach ($orParts as $orIndex => $andParts) {
793
+			foreach ($excludedWords as $word)
743 794
 			$orParts[$orIndex][] = $word;
795
+	}
744 796
 
745 797
 	// Determine the or-branches and the fulltext search words.
746 798
 	foreach ($orParts as $orIndex => $andParts)
@@ -754,8 +806,9 @@  discard block
 block discarded – undo
754 806
 		);
755 807
 
756 808
 		// Sort the indexed words (large words -> small words -> excluded words).
757
-		if ($searchAPI->supportsMethod('searchSort'))
758
-			usort($orParts[$orIndex], 'searchSort');
809
+		if ($searchAPI->supportsMethod('searchSort')) {
810
+					usort($orParts[$orIndex], 'searchSort');
811
+		}
759 812
 
760 813
 		foreach ($orParts[$orIndex] as $word)
761 814
 		{
@@ -767,15 +820,17 @@  discard block
 block discarded – undo
767 820
 			if (!$is_excluded || count($subjectWords) === 1)
768 821
 			{
769 822
 				$searchWords[$orIndex]['subject_words'] = array_merge($searchWords[$orIndex]['subject_words'], $subjectWords);
770
-				if ($is_excluded)
771
-					$excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords);
823
+				if ($is_excluded) {
824
+									$excludedSubjectWords = array_merge($excludedSubjectWords, $subjectWords);
825
+				}
826
+			} else {
827
+							$excludedPhrases[] = $word;
772 828
 			}
773
-			else
774
-				$excludedPhrases[] = $word;
775 829
 
776 830
 			// Have we got indexes to prepare?
777
-			if ($searchAPI->supportsMethod('prepareIndexes'))
778
-				$searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded);
831
+			if ($searchAPI->supportsMethod('prepareIndexes')) {
832
+							$searchAPI->prepareIndexes($word, $searchWords[$orIndex], $excludedIndexWords, $is_excluded);
833
+			}
779 834
 		}
780 835
 
781 836
 		// Search_force_index requires all AND parts to have at least one fulltext word.
@@ -783,8 +838,7 @@  discard block
 block discarded – undo
783 838
 		{
784 839
 			$context['search_errors']['query_not_specific_enough'] = true;
785 840
 			break;
786
-		}
787
-		elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords))
841
+		} elseif ($search_params['subject_only'] && empty($searchWords[$orIndex]['subject_words']) && empty($excludedSubjectWords))
788 842
 		{
789 843
 			$context['search_errors']['query_not_specific_enough'] = true;
790 844
 			break;
@@ -812,8 +866,9 @@  discard block
 block discarded – undo
812 866
 		$found_misspelling = false;
813 867
 		foreach ($searchArray as $word)
814 868
 		{
815
-			if (empty($link))
816
-				continue;
869
+			if (empty($link)) {
870
+							continue;
871
+			}
817 872
 
818 873
 			// Don't check phrases.
819 874
 			if (preg_match('~^\w+$~', $word) === 0)
@@ -828,8 +883,7 @@  discard block
 block discarded – undo
828 883
 				$did_you_mean['search'][] = $word;
829 884
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
830 885
 				continue;
831
-			}
832
-			elseif (spell_check($link, $word))
886
+			} elseif (spell_check($link, $word))
833 887
 			{
834 888
 				$did_you_mean['search'][] = $word;
835 889
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
@@ -840,11 +894,13 @@  discard block
 block discarded – undo
840 894
 			foreach ($suggestions as $i => $s)
841 895
 			{
842 896
 				// Search is case insensitive.
843
-				if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word))
844
-					unset($suggestions[$i]);
897
+				if ($smcFunc['strtolower']($s) == $smcFunc['strtolower']($word)) {
898
+									unset($suggestions[$i]);
899
+				}
845 900
 				// Plus, don't suggest something the user thinks is rude!
846
-				elseif ($suggestions[$i] != censorText($s))
847
-					unset($suggestions[$i]);
901
+				elseif ($suggestions[$i] != censorText($s)) {
902
+									unset($suggestions[$i]);
903
+				}
848 904
 			}
849 905
 
850 906
 			// Anything found?  If so, correct it!
@@ -854,8 +910,7 @@  discard block
 block discarded – undo
854 910
 				$did_you_mean['search'][] = $suggestions[0];
855 911
 				$did_you_mean['display'][] = '<em><strong>' . $smcFunc['htmlspecialchars']($suggestions[0]) . '</strong></em>';
856 912
 				$found_misspelling = true;
857
-			}
858
-			else
913
+			} else
859 914
 			{
860 915
 				$did_you_mean['search'][] = $word;
861 916
 				$did_you_mean['display'][] = $smcFunc['htmlspecialchars']($word);
@@ -872,8 +927,7 @@  discard block
 block discarded – undo
872 927
 				{
873 928
 					$temp_excluded['search'][] = '-"' . $word . '"';
874 929
 					$temp_excluded['display'][] = '-&quot;' . $smcFunc['htmlspecialchars']($word) . '&quot;';
875
-				}
876
-				else
930
+				} else
877 931
 				{
878 932
 					$temp_excluded['search'][] = '-' . $word;
879 933
 					$temp_excluded['display'][] = '-' . $smcFunc['htmlspecialchars']($word);
@@ -885,11 +939,13 @@  discard block
 block discarded – undo
885 939
 
886 940
 			$temp_params = $search_params;
887 941
 			$temp_params['search'] = implode(' ', $did_you_mean['search']);
888
-			if (isset($temp_params['brd']))
889
-				$temp_params['brd'] = implode(',', $temp_params['brd']);
942
+			if (isset($temp_params['brd'])) {
943
+							$temp_params['brd'] = implode(',', $temp_params['brd']);
944
+			}
890 945
 			$context['params'] = array();
891
-			foreach ($temp_params as $k => $v)
892
-				$context['did_you_mean_params'][] = $k . '|\'|' . $v;
946
+			foreach ($temp_params as $k => $v) {
947
+							$context['did_you_mean_params'][] = $k . '|\'|' . $v;
948
+			}
893 949
 			$context['did_you_mean_params'] = base64_encode(implode('|"|', $context['did_you_mean_params']));
894 950
 			$context['did_you_mean'] = implode(' ', $did_you_mean['display']);
895 951
 		}
@@ -897,18 +953,20 @@  discard block
 block discarded – undo
897 953
 
898 954
 	// Let the user adjust the search query, should they wish?
899 955
 	$context['search_params'] = $search_params;
900
-	if (isset($context['search_params']['search']))
901
-		$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
902
-	if (isset($context['search_params']['userspec']))
903
-		$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
956
+	if (isset($context['search_params']['search'])) {
957
+			$context['search_params']['search'] = $smcFunc['htmlspecialchars']($context['search_params']['search']);
958
+	}
959
+	if (isset($context['search_params']['userspec'])) {
960
+			$context['search_params']['userspec'] = $smcFunc['htmlspecialchars']($context['search_params']['userspec']);
961
+	}
904 962
 
905 963
 	// Do we have captcha enabled?
906 964
 	if ($user_info['is_guest'] && !empty($modSettings['search_enable_captcha']) && empty($_SESSION['ss_vv_passed']) && (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']))
907 965
 	{
908 966
 		// If we come from another search box tone down the error...
909
-		if (!isset($_REQUEST['search_vv']))
910
-			$context['search_errors']['need_verification_code'] = true;
911
-		else
967
+		if (!isset($_REQUEST['search_vv'])) {
968
+					$context['search_errors']['need_verification_code'] = true;
969
+		} else
912 970
 		{
913 971
 			require_once($sourcedir . '/Subs-Editor.php');
914 972
 			$verificationOptions = array(
@@ -918,12 +976,14 @@  discard block
 block discarded – undo
918 976
 
919 977
 			if (is_array($context['require_verification']))
920 978
 			{
921
-				foreach ($context['require_verification'] as $error)
922
-					$context['search_errors'][$error] = true;
979
+				foreach ($context['require_verification'] as $error) {
980
+									$context['search_errors'][$error] = true;
981
+				}
923 982
 			}
924 983
 			// Don't keep asking for it - they've proven themselves worthy.
925
-			else
926
-				$_SESSION['ss_vv_passed'] = true;
984
+			else {
985
+							$_SESSION['ss_vv_passed'] = true;
986
+			}
927 987
 		}
928 988
 	}
929 989
 
@@ -931,19 +991,22 @@  discard block
 block discarded – undo
931 991
 
932 992
 	// All search params have been checked, let's compile them to a single string... made less simple by PHP 4.3.9 and below.
933 993
 	$temp_params = $search_params;
934
-	if (isset($temp_params['brd']))
935
-		$temp_params['brd'] = implode(',', $temp_params['brd']);
994
+	if (isset($temp_params['brd'])) {
995
+			$temp_params['brd'] = implode(',', $temp_params['brd']);
996
+	}
936 997
 	$context['params'] = array();
937
-	foreach ($temp_params as $k => $v)
938
-		$context['params'][] = $k . '|\'|' . $v;
998
+	foreach ($temp_params as $k => $v) {
999
+			$context['params'][] = $k . '|\'|' . $v;
1000
+	}
939 1001
 
940 1002
 	if (!empty($context['params']))
941 1003
 	{
942 1004
 		// Due to old IE's 2083 character limit, we have to compress long search strings
943 1005
 		$params = @gzcompress(implode('|"|', $context['params']));
944 1006
 		// Gzcompress failed, use try non-gz
945
-		if (empty($params))
946
-			$params = implode('|"|', $context['params']);
1007
+		if (empty($params)) {
1008
+					$params = implode('|"|', $context['params']);
1009
+		}
947 1010
 		// Base64 encode, then replace +/= with uri safe ones that can be reverted
948 1011
 		$context['params'] = str_replace(array('+', '/', '='), array('-', '_', '.'), base64_encode($params));
949 1012
 	}
@@ -969,8 +1032,9 @@  discard block
 block discarded – undo
969 1032
 	}
970 1033
 
971 1034
 	// Spam me not, Spam-a-lot?
972
-	if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search'])
973
-		spamProtection('search');
1035
+	if (empty($_SESSION['last_ss']) || $_SESSION['last_ss'] != $search_params['search']) {
1036
+			spamProtection('search');
1037
+	}
974 1038
 	// Store the last search string to allow pages of results to be browsed.
975 1039
 	$_SESSION['last_ss'] = $search_params['search'];
976 1040
 
@@ -1030,8 +1094,9 @@  discard block
 block discarded – undo
1030 1094
 						'where' => array(),
1031 1095
 					);
1032 1096
 
1033
-					if ($modSettings['postmod_active'])
1034
-						$subject_query['where'][] = 't.approved = {int:is_approved}';
1097
+					if ($modSettings['postmod_active']) {
1098
+											$subject_query['where'][] = 't.approved = {int:is_approved}';
1099
+					}
1035 1100
 
1036 1101
 					$numTables = 0;
1037 1102
 					$prev_join = 0;
@@ -1043,8 +1108,7 @@  discard block
 block discarded – undo
1043 1108
 						{
1044 1109
 							$subject_query['left_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}') . ' AND subj' . $numTables . '.id_topic = t.id_topic)';
1045 1110
 							$subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)';
1046
-						}
1047
-						else
1111
+						} else
1048 1112
 						{
1049 1113
 							$subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)';
1050 1114
 							$subject_query['where'][] = 'subj' . $numTables . '.word ' . (empty($modSettings['search_match_words']) ? 'LIKE {string:subject_words_' . $numTables . '_wild}' : '= {string:subject_words_' . $numTables . '}');
@@ -1062,14 +1126,18 @@  discard block
 block discarded – undo
1062 1126
 						}
1063 1127
 						$subject_query['where'][] = $userQuery;
1064 1128
 					}
1065
-					if (!empty($search_params['topic']))
1066
-						$subject_query['where'][] = 't.id_topic = ' . $search_params['topic'];
1067
-					if (!empty($minMsgID))
1068
-						$subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID;
1069
-					if (!empty($maxMsgID))
1070
-						$subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID;
1071
-					if (!empty($boardQuery))
1072
-						$subject_query['where'][] = 't.id_board ' . $boardQuery;
1129
+					if (!empty($search_params['topic'])) {
1130
+											$subject_query['where'][] = 't.id_topic = ' . $search_params['topic'];
1131
+					}
1132
+					if (!empty($minMsgID)) {
1133
+											$subject_query['where'][] = 't.id_first_msg >= ' . $minMsgID;
1134
+					}
1135
+					if (!empty($maxMsgID)) {
1136
+											$subject_query['where'][] = 't.id_last_msg <= ' . $maxMsgID;
1137
+					}
1138
+					if (!empty($boardQuery)) {
1139
+											$subject_query['where'][] = 't.id_board ' . $boardQuery;
1140
+					}
1073 1141
 					if (!empty($excludedPhrases))
1074 1142
 					{
1075 1143
 						if ($subject_query['from'] != '{db_prefix}messages AS m')
@@ -1089,8 +1157,9 @@  discard block
 block discarded – undo
1089 1157
 					foreach ($weight_factors as $type => $value)
1090 1158
 					{
1091 1159
 						$relevance .= $weight[$type];
1092
-						if (!empty($value['results']))
1093
-							$relevance .= ' * ' . $value['results'];
1160
+						if (!empty($value['results'])) {
1161
+													$relevance .= ' * ' . $value['results'];
1162
+						}
1094 1163
 						$relevance .= ' + ';
1095 1164
 					}
1096 1165
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
@@ -1128,20 +1197,23 @@  discard block
 block discarded – undo
1128 1197
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1129 1198
 						{
1130 1199
 							// No duplicates!
1131
-							if (isset($inserts[$row[1]]))
1132
-								continue;
1200
+							if (isset($inserts[$row[1]])) {
1201
+															continue;
1202
+							}
1133 1203
 
1134
-							foreach ($row as $key => $value)
1135
-								$inserts[$row[1]][] = (int) $row[$key];
1204
+							foreach ($row as $key => $value) {
1205
+															$inserts[$row[1]][] = (int) $row[$key];
1206
+							}
1136 1207
 						}
1137 1208
 						$smcFunc['db_free_result']($ignoreRequest);
1138 1209
 						$numSubjectResults = count($inserts);
1210
+					} else {
1211
+											$numSubjectResults += $smcFunc['db_affected_rows']();
1139 1212
 					}
1140
-					else
1141
-						$numSubjectResults += $smcFunc['db_affected_rows']();
1142 1213
 
1143
-					if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results'])
1144
-						break;
1214
+					if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) {
1215
+											break;
1216
+					}
1145 1217
 				}
1146 1218
 
1147 1219
 				// If there's data to be inserted for non-IGNORE databases do it here!
@@ -1156,8 +1228,7 @@  discard block
 block discarded – undo
1156 1228
 				}
1157 1229
 
1158 1230
 				$_SESSION['search_cache']['num_results'] = $numSubjectResults;
1159
-			}
1160
-			else
1231
+			} else
1161 1232
 			{
1162 1233
 				$main_query = array(
1163 1234
 					'select' => array(
@@ -1189,8 +1260,7 @@  discard block
 block discarded – undo
1189 1260
 					$main_query['weights'] = $weight_factors;
1190 1261
 
1191 1262
 					$main_query['group_by'][] = 't.id_topic';
1192
-				}
1193
-				else
1263
+				} else
1194 1264
 				{
1195 1265
 					// This is outrageous!
1196 1266
 					$main_query['select']['id_topic'] = 'm.id_msg AS id_topic';
@@ -1211,8 +1281,9 @@  discard block
 block discarded – undo
1211 1281
 						$main_query['where'][] = 't.id_topic = {int:topic}';
1212 1282
 						$main_query['parameters']['topic'] = $search_params['topic'];
1213 1283
 					}
1214
-					if (!empty($search_params['show_complete']))
1215
-						$main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg';
1284
+					if (!empty($search_params['show_complete'])) {
1285
+											$main_query['group_by'][] = 'm.id_msg, t.id_first_msg, t.id_last_msg';
1286
+					}
1216 1287
 				}
1217 1288
 
1218 1289
 				// *** Get the subject results.
@@ -1237,14 +1308,15 @@  discard block
 block discarded – undo
1237 1308
 					) !== false;
1238 1309
 
1239 1310
 					// Clean up some previous cache.
1240
-					if (!$createTemporary)
1241
-						$smcFunc['db_search_query']('delete_log_search_topics', '
1311
+					if (!$createTemporary) {
1312
+											$smcFunc['db_search_query']('delete_log_search_topics', '
1242 1313
 							DELETE FROM {db_prefix}log_search_topics
1243 1314
 							WHERE id_search = {int:search_id}',
1244 1315
 							array(
1245 1316
 								'search_id' => $_SESSION['search_cache']['id_search'],
1246 1317
 							)
1247 1318
 						);
1319
+					}
1248 1320
 
1249 1321
 					foreach ($searchWords as $orIndex => $words)
1250 1322
 					{
@@ -1276,8 +1348,7 @@  discard block
 block discarded – undo
1276 1348
 								$subject_query['where'][] = '(subj' . $numTables . '.word IS NULL)';
1277 1349
 								$subject_query['where'][] = 'm.body NOT ' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:body_not_' . $count . '}';
1278 1350
 								$subject_query['params']['body_not_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($subjectWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $subjectWord), '\\\'') . '[[:>:]]';
1279
-							}
1280
-							else
1351
+							} else
1281 1352
 							{
1282 1353
 								$subject_query['inner_join'][] = '{db_prefix}log_search_subjects AS subj' . $numTables . ' ON (subj' . $numTables . '.id_topic = ' . ($prev_join === 0 ? 't' : 'subj' . $prev_join) . '.id_topic)';
1283 1354
 								$subject_query['where'][] = 'subj' . $numTables . '.word LIKE {string:subject_like_' . $count . '}';
@@ -1332,8 +1403,9 @@  discard block
 block discarded – undo
1332 1403
 						call_integration_hook('integrate_subject_search_query', array(&$subject_query));
1333 1404
 
1334 1405
 						// Nothing to search for?
1335
-						if (empty($subject_query['where']))
1336
-							continue;
1406
+						if (empty($subject_query['where'])) {
1407
+													continue;
1408
+						}
1337 1409
 
1338 1410
 						$ignoreRequest = $smcFunc['db_search_query']('insert_log_search_topics', ($smcFunc['db_support_ignore'] ? ( '
1339 1411
 							INSERT IGNORE INTO {db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics
@@ -1356,19 +1428,21 @@  discard block
 block discarded – undo
1356 1428
 							{
1357 1429
 								$ind = $createTemporary ? 0 : 1;
1358 1430
 								// No duplicates!
1359
-								if (isset($inserts[$row[$ind]]))
1360
-									continue;
1431
+								if (isset($inserts[$row[$ind]])) {
1432
+																	continue;
1433
+								}
1361 1434
 
1362 1435
 								$inserts[$row[$ind]] = $row;
1363 1436
 							}
1364 1437
 							$smcFunc['db_free_result']($ignoreRequest);
1365 1438
 							$numSubjectResults = count($inserts);
1439
+						} else {
1440
+													$numSubjectResults += $smcFunc['db_affected_rows']();
1366 1441
 						}
1367
-						else
1368
-							$numSubjectResults += $smcFunc['db_affected_rows']();
1369 1442
 
1370
-						if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results'])
1371
-							break;
1443
+						if (!empty($modSettings['search_max_results']) && $numSubjectResults >= $modSettings['search_max_results']) {
1444
+													break;
1445
+						}
1372 1446
 					}
1373 1447
 
1374 1448
 					// Got some non-MySQL data to plonk in?
@@ -1386,8 +1460,9 @@  discard block
 block discarded – undo
1386 1460
 					{
1387 1461
 						$main_query['weights']['subject']['search'] = 'CASE WHEN MAX(lst.id_topic) IS NULL THEN 0 ELSE 1 END';
1388 1462
 						$main_query['left_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_topics AS lst ON (' . ($createTemporary ? '' : 'lst.id_search = {int:id_search} AND ') . 'lst.id_topic = t.id_topic)';
1389
-						if (!$createTemporary)
1390
-							$main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search'];
1463
+						if (!$createTemporary) {
1464
+													$main_query['parameters']['id_search'] = $_SESSION['search_cache']['id_search'];
1465
+						}
1391 1466
 					}
1392 1467
 				}
1393 1468
 
@@ -1413,14 +1488,15 @@  discard block
 block discarded – undo
1413 1488
 					) !== false;
1414 1489
 
1415 1490
 					// Clear, all clear!
1416
-					if (!$createTemporary)
1417
-						$smcFunc['db_search_query']('delete_log_search_messages', '
1491
+					if (!$createTemporary) {
1492
+											$smcFunc['db_search_query']('delete_log_search_messages', '
1418 1493
 							DELETE FROM {db_prefix}log_search_messages
1419 1494
 							WHERE id_search = {int:id_search}',
1420 1495
 							array(
1421 1496
 								'id_search' => $_SESSION['search_cache']['id_search'],
1422 1497
 							)
1423 1498
 						);
1499
+					}
1424 1500
 
1425 1501
 					foreach ($searchWords as $orIndex => $words)
1426 1502
 					{
@@ -1454,19 +1530,21 @@  discard block
 block discarded – undo
1454 1530
 								while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1455 1531
 								{
1456 1532
 									// No duplicates!
1457
-									if (isset($inserts[$row[0]]))
1458
-										continue;
1533
+									if (isset($inserts[$row[0]])) {
1534
+																			continue;
1535
+									}
1459 1536
 
1460 1537
 									$inserts[$row[0]] = $row;
1461 1538
 								}
1462 1539
 								$smcFunc['db_free_result']($ignoreRequest);
1463 1540
 								$indexedResults = count($inserts);
1541
+							} else {
1542
+															$indexedResults += $smcFunc['db_affected_rows']();
1464 1543
 							}
1465
-							else
1466
-								$indexedResults += $smcFunc['db_affected_rows']();
1467 1544
 
1468
-							if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults)
1469
-								break;
1545
+							if (!empty($maxMessageResults) && $indexedResults >= $maxMessageResults) {
1546
+															break;
1547
+							}
1470 1548
 						}
1471 1549
 					}
1472 1550
 
@@ -1486,8 +1564,7 @@  discard block
 block discarded – undo
1486 1564
 						$context['search_errors']['query_not_specific_enough'] = true;
1487 1565
 						$_REQUEST['params'] = $context['params'];
1488 1566
 						return PlushSearch1();
1489
-					}
1490
-					elseif (!empty($indexedResults))
1567
+					} elseif (!empty($indexedResults))
1491 1568
 					{
1492 1569
 						$main_query['inner_join'][] = '{db_prefix}' . ($createTemporary ? 'tmp_' : '') . 'log_search_messages AS lsm ON (lsm.id_msg = m.id_msg)';
1493 1570
 						if (!$createTemporary)
@@ -1509,15 +1586,18 @@  discard block
 block discarded – undo
1509 1586
 						foreach ($words['all_words'] as $regularWord)
1510 1587
 						{
1511 1588
 							$where[] = 'm.body' . (in_array($regularWord, $excludedWords) ? ' NOT' : '') . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1512
-							if (in_array($regularWord, $excludedWords))
1513
-								$where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1589
+							if (in_array($regularWord, $excludedWords)) {
1590
+															$where[] = 'm.subject NOT' . (empty($modSettings['search_match_words']) || $no_regexp ? ' LIKE ' : ' RLIKE ') . '{string:all_word_body_' . $count . '}';
1591
+							}
1514 1592
 							$main_query['parameters']['all_word_body_' . $count++] = empty($modSettings['search_match_words']) || $no_regexp ? '%' . strtr($regularWord, array('_' => '\\_', '%' => '\\%')) . '%' : '[[:<:]]' . addcslashes(preg_replace(array('/([\[\]$.+*?|{}()])/'), array('[$1]'), $regularWord), '\\\'') . '[[:>:]]';
1515 1593
 						}
1516
-						if (!empty($where))
1517
-							$orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0];
1594
+						if (!empty($where)) {
1595
+													$orWhere[] = count($where) > 1 ? '(' . implode(' AND ', $where) . ')' : $where[0];
1596
+						}
1597
+					}
1598
+					if (!empty($orWhere)) {
1599
+											$main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0];
1518 1600
 					}
1519
-					if (!empty($orWhere))
1520
-						$main_query['where'][] = count($orWhere) > 1 ? '(' . implode(' OR ', $orWhere) . ')' : $orWhere[0];
1521 1601
 
1522 1602
 					if (!empty($userQuery))
1523 1603
 					{
@@ -1555,8 +1635,9 @@  discard block
 block discarded – undo
1555 1635
 					foreach ($main_query['weights'] as $type => $value)
1556 1636
 					{
1557 1637
 						$relevance .= $weight[$type];
1558
-						if (!empty($value['search']))
1559
-							$relevance .= ' * ' . $value['search'];
1638
+						if (!empty($value['search'])) {
1639
+													$relevance .= ' * ' . $value['search'];
1640
+						}
1560 1641
 						$relevance .= ' + ';
1561 1642
 						$new_weight_total += $weight[$type];
1562 1643
 					}
@@ -1587,11 +1668,13 @@  discard block
 block discarded – undo
1587 1668
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1588 1669
 						{
1589 1670
 							// No duplicates!
1590
-							if (isset($inserts[$row[2]]))
1591
-								continue;
1671
+							if (isset($inserts[$row[2]])) {
1672
+															continue;
1673
+							}
1592 1674
 
1593
-							foreach ($row as $key => $value)
1594
-								$inserts[$row[2]][] = (int) $row[$key];
1675
+							foreach ($row as $key => $value) {
1676
+															$inserts[$row[2]][] = (int) $row[$key];
1677
+							}
1595 1678
 						}
1596 1679
 						$smcFunc['db_free_result']($ignoreRequest);
1597 1680
 
@@ -1599,8 +1682,9 @@  discard block
 block discarded – undo
1599 1682
 						if (!empty($inserts))
1600 1683
 						{
1601 1684
 							$query_columns = array();
1602
-							foreach ($main_query['select'] as $k => $v)
1603
-								$query_columns[$k] = 'int';
1685
+							foreach ($main_query['select'] as $k => $v) {
1686
+															$query_columns[$k] = 'int';
1687
+							}
1604 1688
 
1605 1689
 							$smcFunc['db_insert']('',
1606 1690
 								'{db_prefix}log_search_results',
@@ -1610,21 +1694,23 @@  discard block
 block discarded – undo
1610 1694
 							);
1611 1695
 						}
1612 1696
 						$_SESSION['search_cache']['num_results'] += count($inserts);
1697
+					} else {
1698
+											$_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows']();
1613 1699
 					}
1614
-					else
1615
-						$_SESSION['search_cache']['num_results'] = $smcFunc['db_affected_rows']();
1616 1700
 				}
1617 1701
 
1618 1702
 				// Insert subject-only matches.
1619 1703
 				if ($_SESSION['search_cache']['num_results'] < $modSettings['search_max_results'] && $numSubjectResults !== 0)
1620 1704
 				{
1621 1705
 					$relevance = '1000 * (';
1622
-					foreach ($weight_factors as $type => $value)
1623
-						if (isset($value['results']))
1706
+					foreach ($weight_factors as $type => $value) {
1707
+											if (isset($value['results']))
1624 1708
 						{
1625 1709
 							$relevance .= $weight[$type];
1626
-							if (!empty($value['results']))
1627
-								$relevance .= ' * ' . $value['results'];
1710
+					}
1711
+							if (!empty($value['results'])) {
1712
+															$relevance .= ' * ' . $value['results'];
1713
+							}
1628 1714
 							$relevance .= ' + ';
1629 1715
 						}
1630 1716
 					$relevance = substr($relevance, 0, -3) . ') / ' . $weight_total . ' AS relevance';
@@ -1658,8 +1744,9 @@  discard block
 block discarded – undo
1658 1744
 						while ($row = $smcFunc['db_fetch_row']($ignoreRequest))
1659 1745
 						{
1660 1746
 							// No duplicates!
1661
-							if (isset($usedIDs[$row[1]]))
1662
-								continue;
1747
+							if (isset($usedIDs[$row[1]])) {
1748
+															continue;
1749
+							}
1663 1750
 
1664 1751
 							$usedIDs[$row[1]] = true;
1665 1752
 							$inserts[] = $row;
@@ -1677,12 +1764,12 @@  discard block
 block discarded – undo
1677 1764
 							);
1678 1765
 						}
1679 1766
 						$_SESSION['search_cache']['num_results'] += count($inserts);
1767
+					} else {
1768
+											$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
1680 1769
 					}
1681
-					else
1682
-						$_SESSION['search_cache']['num_results'] += $smcFunc['db_affected_rows']();
1770
+				} elseif ($_SESSION['search_cache']['num_results'] == -1) {
1771
+									$_SESSION['search_cache']['num_results'] = 0;
1683 1772
 				}
1684
-				elseif ($_SESSION['search_cache']['num_results'] == -1)
1685
-					$_SESSION['search_cache']['num_results'] = 0;
1686 1773
 			}
1687 1774
 		}
1688 1775
 
@@ -1752,14 +1839,16 @@  discard block
 block discarded – undo
1752 1839
 			)
1753 1840
 		);
1754 1841
 		$posters = array();
1755
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1756
-			$posters[] = $row['id_member'];
1842
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1843
+					$posters[] = $row['id_member'];
1844
+		}
1757 1845
 		$smcFunc['db_free_result']($request);
1758 1846
 
1759 1847
 		call_integration_hook('integrate_search_message_list', array(&$msg_list, &$posters));
1760 1848
 
1761
-		if (!empty($posters))
1762
-			loadMemberData(array_unique($posters));
1849
+		if (!empty($posters)) {
1850
+					loadMemberData(array_unique($posters));
1851
+		}
1763 1852
 
1764 1853
 		// Get the messages out for the callback - select enough that it can be made to look just like Display.
1765 1854
 		$messages_request = $smcFunc['db_query']('', '
@@ -1792,8 +1881,9 @@  discard block
 block discarded – undo
1792 1881
 		);
1793 1882
 
1794 1883
 		// If there are no results that means the things in the cache got deleted, so pretend we have no topics anymore.
1795
-		if ($smcFunc['db_num_rows']($messages_request) == 0)
1796
-			$context['topics'] = array();
1884
+		if ($smcFunc['db_num_rows']($messages_request) == 0) {
1885
+					$context['topics'] = array();
1886
+		}
1797 1887
 
1798 1888
 		// If we want to know who participated in what then load this now.
1799 1889
 		if (!empty($modSettings['enableParticipation']) && !$user_info['is_guest'])
@@ -1811,8 +1901,9 @@  discard block
 block discarded – undo
1811 1901
 					'limit' => count($participants),
1812 1902
 				)
1813 1903
 			);
1814
-			while ($row = $smcFunc['db_fetch_assoc']($result))
1815
-				$participants[$row['id_topic']] = true;
1904
+			while ($row = $smcFunc['db_fetch_assoc']($result)) {
1905
+							$participants[$row['id_topic']] = true;
1906
+			}
1816 1907
 			$smcFunc['db_free_result']($result);
1817 1908
 		}
1818 1909
 	}
@@ -1821,15 +1912,17 @@  discard block
 block discarded – undo
1821 1912
 	$context['page_index'] = constructPageIndex($scripturl . '?action=search2;params=' . $context['params'], $_REQUEST['start'], $num_results, $modSettings['search_results_per_page'], false);
1822 1913
 
1823 1914
 	// Consider the search complete!
1824
-	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
1825
-		cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90);
1915
+	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
1916
+			cache_put_data('search_start:' . ($user_info['is_guest'] ? $user_info['ip'] : $user_info['id']), null, 90);
1917
+	}
1826 1918
 
1827 1919
 	$context['key_words'] = &$searchArray;
1828 1920
 
1829 1921
 	// Setup the default topic icons... for checking they exist and the like!
1830 1922
 	$context['icon_sources'] = array();
1831
-	foreach ($context['stable_icons'] as $icon)
1832
-		$context['icon_sources'][$icon] = 'images_url';
1923
+	foreach ($context['stable_icons'] as $icon) {
1924
+			$context['icon_sources'][$icon] = 'images_url';
1925
+	}
1833 1926
 
1834 1927
 	$context['sub_template'] = 'results';
1835 1928
 	$context['page_title'] = $txt['search_results'];
@@ -1860,26 +1953,31 @@  discard block
 block discarded – undo
1860 1953
 	global $boards_can, $participants, $smcFunc;
1861 1954
 	static $recycle_board = null;
1862 1955
 
1863
-	if ($recycle_board === null)
1864
-		$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
1956
+	if ($recycle_board === null) {
1957
+			$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
1958
+	}
1865 1959
 
1866 1960
 	// Remember which message this is.  (ie. reply #83)
1867 1961
 	static $counter = null;
1868
-	if ($counter == null || $reset)
1869
-		$counter = $_REQUEST['start'] + 1;
1962
+	if ($counter == null || $reset) {
1963
+			$counter = $_REQUEST['start'] + 1;
1964
+	}
1870 1965
 
1871 1966
 	// If the query returned false, bail.
1872
-	if ($messages_request == false)
1873
-		return false;
1967
+	if ($messages_request == false) {
1968
+			return false;
1969
+	}
1874 1970
 
1875 1971
 	// Start from the beginning...
1876
-	if ($reset)
1877
-		return @$smcFunc['db_data_seek']($messages_request, 0);
1972
+	if ($reset) {
1973
+			return @$smcFunc['db_data_seek']($messages_request, 0);
1974
+	}
1878 1975
 
1879 1976
 	// Attempt to get the next message.
1880 1977
 	$message = $smcFunc['db_fetch_assoc']($messages_request);
1881
-	if (!$message)
1882
-		return false;
1978
+	if (!$message) {
1979
+			return false;
1980
+	}
1883 1981
 
1884 1982
 	// Can't have an empty subject can we?
1885 1983
 	$message['subject'] = $message['subject'] != '' ? $message['subject'] : $txt['no_subject'];
@@ -1918,9 +2016,9 @@  discard block
 block discarded – undo
1918 2016
 
1919 2017
 		if ($smcFunc['strlen']($message['body']) > $charLimit)
1920 2018
 		{
1921
-			if (empty($context['key_words']))
1922
-				$message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>';
1923
-			else
2019
+			if (empty($context['key_words'])) {
2020
+							$message['body'] = $smcFunc['substr']($message['body'], 0, $charLimit) . '<strong>...</strong>';
2021
+			} else
1924 2022
 			{
1925 2023
 				$matchString = '';
1926 2024
 				$force_partial_word = false;
@@ -1929,18 +2027,20 @@  discard block
 block discarded – undo
1929 2027
 					$keyword = un_htmlspecialchars($keyword);
1930 2028
 					$keyword = preg_replace_callback('~(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', strtr($keyword, array('\\\'' => '\'', '&' => '&amp;')));
1931 2029
 
1932
-					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0)
1933
-						$force_partial_word = true;
2030
+					if (preg_match('~[\'\.,/@%&;:(){}\[\]_\-+\\\\]$~', $keyword) != 0 || preg_match('~^[\'\.,/@%&;:(){}\[\]_\-+\\\\]~', $keyword) != 0) {
2031
+											$force_partial_word = true;
2032
+					}
1934 2033
 					$matchString .= strtr(preg_quote($keyword, '/'), array('\*' => '.+?')) . '|';
1935 2034
 				}
1936 2035
 				$matchString = un_htmlspecialchars(substr($matchString, 0, -1));
1937 2036
 
1938 2037
 				$message['body'] = un_htmlspecialchars(strtr($message['body'], array('&nbsp;' => ' ', '<br>' => "\n", '&#91;' => '[', '&#93;' => ']', '&#58;' => ':', '&#64;' => '@')));
1939 2038
 
1940
-				if (empty($modSettings['search_method']) || $force_partial_word)
1941
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
1942
-				else
1943
-					preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2039
+				if (empty($modSettings['search_method']) || $force_partial_word) {
2040
+									preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?|^)(' . $matchString . ')(.{0,' . $charLimit . '}[\s\W]|[^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2041
+				} else {
2042
+									preg_match_all('/([^\s\W]{' . $charLimit . '}[\s\W]|[\s\W].{0,' . $charLimit . '}?[\s\W]|^)(' . $matchString . ')([\s\W].{0,' . $charLimit . '}[\s\W]|[\s\W][^\s\W]{0,' . $charLimit . '})/is' . ($context['utf8'] ? 'u' : ''), $message['body'], $matches);
2043
+				}
1944 2044
 
1945 2045
 				$message['body'] = '';
1946 2046
 				foreach ($matches[0] as $index => $match)
@@ -1953,8 +2053,7 @@  discard block
 block discarded – undo
1953 2053
 			// Re-fix the international characters.
1954 2054
 			$message['body'] = preg_replace_callback('~(&amp;#(\d{1,7}|x[0-9a-fA-F]{1,6});)~', 'entity_fix__callback', $message['body']);
1955 2055
 		}
1956
-	}
1957
-	else
2056
+	} else
1958 2057
 	{
1959 2058
 		// Run BBC interpreter on the message.
1960 2059
 		$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
@@ -1973,21 +2072,26 @@  discard block
 block discarded – undo
1973 2072
 	// Sadly, we need to check the icon ain't broke.
1974 2073
 	if (!empty($modSettings['messageIconChecks_enable']))
1975 2074
 	{
1976
-		if (!isset($context['icon_sources'][$message['first_icon']]))
1977
-			$context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
1978
-		if (!isset($context['icon_sources'][$message['last_icon']]))
1979
-			$context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
1980
-		if (!isset($context['icon_sources'][$message['icon']]))
1981
-			$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
1982
-	}
1983
-	else
2075
+		if (!isset($context['icon_sources'][$message['first_icon']])) {
2076
+					$context['icon_sources'][$message['first_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['first_icon'] . '.png') ? 'images_url' : 'default_images_url';
2077
+		}
2078
+		if (!isset($context['icon_sources'][$message['last_icon']])) {
2079
+					$context['icon_sources'][$message['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
2080
+		}
2081
+		if (!isset($context['icon_sources'][$message['icon']])) {
2082
+					$context['icon_sources'][$message['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $message['icon'] . '.png') ? 'images_url' : 'default_images_url';
2083
+		}
2084
+	} else
1984 2085
 	{
1985
-		if (!isset($context['icon_sources'][$message['first_icon']]))
1986
-			$context['icon_sources'][$message['first_icon']] = 'images_url';
1987
-		if (!isset($context['icon_sources'][$message['last_icon']]))
1988
-			$context['icon_sources'][$message['last_icon']] = 'images_url';
1989
-		if (!isset($context['icon_sources'][$message['icon']]))
1990
-			$context['icon_sources'][$message['icon']] = 'images_url';
2086
+		if (!isset($context['icon_sources'][$message['first_icon']])) {
2087
+					$context['icon_sources'][$message['first_icon']] = 'images_url';
2088
+		}
2089
+		if (!isset($context['icon_sources'][$message['last_icon']])) {
2090
+					$context['icon_sources'][$message['last_icon']] = 'images_url';
2091
+		}
2092
+		if (!isset($context['icon_sources'][$message['icon']])) {
2093
+					$context['icon_sources'][$message['icon']] = 'images_url';
2094
+		}
1991 2095
 	}
1992 2096
 
1993 2097
 	// Do we have quote tag enabled?
@@ -1997,12 +2101,14 @@  discard block
 block discarded – undo
1997 2101
 	$colorClass = 'windowbg';
1998 2102
 
1999 2103
 	// Sticky topics should get a different color, too.
2000
-	if ($message['is_sticky'])
2001
-		$colorClass .= ' sticky';
2104
+	if ($message['is_sticky']) {
2105
+			$colorClass .= ' sticky';
2106
+	}
2002 2107
 
2003 2108
 	// Locked topics get special treatment as well.
2004
-	if ($message['locked'])
2005
-		$colorClass .= ' locked';
2109
+	if ($message['locked']) {
2110
+			$colorClass .= ' locked';
2111
+	}
2006 2112
 
2007 2113
 	$output = array_merge($context['topics'][$message['id_msg']], array(
2008 2114
 		'id' => $message['id_topic'],
@@ -2096,8 +2202,9 @@  discard block
 block discarded – undo
2096 2202
 		$query = strtr($smcFunc['htmlspecialchars']($query), array('\\\'' => '\''));
2097 2203
 
2098 2204
 		// Highlighting empty strings would make a terrible mess...
2099
-		if (strlen($query) == 0)
2100
-			continue;
2205
+		if (strlen($query) == 0) {
2206
+					continue;
2207
+		}
2101 2208
 
2102 2209
 		$body_highlighted = preg_replace_callback('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => '&#039;')), '/') . ')/i' . ($context['utf8'] ? 'u' : ''), function ($m)
2103 2210
 		{
@@ -2150,8 +2257,9 @@  discard block
 block discarded – undo
2150 2257
 
2151 2258
 	// Load up the search API we are going to use.
2152 2259
 	$modSettings['search_index'] = empty($modSettings['search_index']) ? 'standard' : $modSettings['search_index'];
2153
-	if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php'))
2154
-		fatal_lang_error('search_api_missing');
2260
+	if (!file_exists($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php')) {
2261
+			fatal_lang_error('search_api_missing');
2262
+	}
2155 2263
 	require_once($sourcedir . '/SearchAPI-' . ucwords($modSettings['search_index']) . '.php');
2156 2264
 
2157 2265
 	// Create an instance of the search API and check it is valid for this version of SMF.
Please login to merge, or discard this patch.
Sources/MoveTopic.php 1 patch
Braces   +101 added lines, -72 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * This function allows to move a topic, making sure to ask the moderator
@@ -32,8 +33,9 @@  discard block
 block discarded – undo
32 33
 {
33 34
 	global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir;
34 35
 
35
-	if (empty($topic))
36
-		fatal_lang_error('no_access', false);
36
+	if (empty($topic)) {
37
+			fatal_lang_error('no_access', false);
38
+	}
37 39
 
38 40
 	$request = $smcFunc['db_query']('', '
39 41
 		SELECT t.id_member_started, ms.subject, t.approved
@@ -49,8 +51,9 @@  discard block
 block discarded – undo
49 51
 	$smcFunc['db_free_result']($request);
50 52
 
51 53
 	// Can they see it - if not approved?
52
-	if ($modSettings['postmod_active'] && !$context['is_approved'])
53
-		isAllowedTo('approve_posts');
54
+	if ($modSettings['postmod_active'] && !$context['is_approved']) {
55
+			isAllowedTo('approve_posts');
56
+	}
54 57
 
55 58
 	// Permission check!
56 59
 	// @todo
@@ -59,9 +62,9 @@  discard block
 block discarded – undo
59 62
 		if ($id_member_started == $user_info['id'])
60 63
 		{
61 64
 			isAllowedTo('move_own');
65
+		} else {
66
+					isAllowedTo('move_any');
62 67
 		}
63
-		else
64
-			isAllowedTo('move_any');
65 68
 	}
66 69
 
67 70
 	$context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any'];
@@ -83,11 +86,13 @@  discard block
 block discarded – undo
83 86
 		'not_redirection' => true,
84 87
 	);
85 88
 
86
-	if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board)
87
-		$options['selected_board'] = $_SESSION['move_to_topic'];
89
+	if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) {
90
+			$options['selected_board'] = $_SESSION['move_to_topic'];
91
+	}
88 92
 
89
-	if (!$context['move_any'])
90
-		$options['included_boards'] = $boards;
93
+	if (!$context['move_any']) {
94
+			$options['included_boards'] = $boards;
95
+	}
91 96
 
92 97
 	require_once($sourcedir . '/Subs-MessageIndex.php');
93 98
 	$context['categories'] = getBoardList($options);
@@ -138,12 +143,14 @@  discard block
 block discarded – undo
138 143
 	global $txt, $topic, $scripturl, $sourcedir, $context;
139 144
 	global $board, $language, $user_info, $smcFunc;
140 145
 
141
-	if (empty($topic))
142
-		fatal_lang_error('no_access', false);
146
+	if (empty($topic)) {
147
+			fatal_lang_error('no_access', false);
148
+	}
143 149
 
144 150
 	// You can't choose to have a redirection topic and use an empty reason.
145
-	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == ''))
146
-		fatal_lang_error('movetopic_no_reason', false);
151
+	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) {
152
+			fatal_lang_error('movetopic_no_reason', false);
153
+	}
147 154
 
148 155
 	moveTopicConcurrence();
149 156
 
@@ -163,16 +170,18 @@  discard block
 block discarded – undo
163 170
 	$smcFunc['db_free_result']($request);
164 171
 
165 172
 	// Can they see it?
166
-	if (!$context['is_approved'])
167
-		isAllowedTo('approve_posts');
173
+	if (!$context['is_approved']) {
174
+			isAllowedTo('approve_posts');
175
+	}
168 176
 
169 177
 	// Can they move topics on this board?
170 178
 	if (!allowedTo('move_any'))
171 179
 	{
172
-		if ($id_member_started == $user_info['id'])
173
-			isAllowedTo('move_own');
174
-		else
175
-			isAllowedTo('move_any');
180
+		if ($id_member_started == $user_info['id']) {
181
+					isAllowedTo('move_own');
182
+		} else {
183
+					isAllowedTo('move_any');
184
+		}
176 185
 	}
177 186
 
178 187
 	checkSession();
@@ -197,8 +206,9 @@  discard block
 block discarded – undo
197 206
 			'blank_redirect' => '',
198 207
 		)
199 208
 	);
200
-	if ($smcFunc['db_num_rows']($request) == 0)
201
-		fatal_lang_error('no_board');
209
+	if ($smcFunc['db_num_rows']($request) == 0) {
210
+			fatal_lang_error('no_board');
211
+	}
202 212
 	list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request);
203 213
 	$smcFunc['db_free_result']($request);
204 214
 
@@ -210,8 +220,9 @@  discard block
 block discarded – undo
210 220
 	{
211 221
 		$_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => ''));
212 222
 		// Keep checking the length.
213
-		if ($smcFunc['strlen']($_POST['custom_subject']) > 100)
214
-			$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
223
+		if ($smcFunc['strlen']($_POST['custom_subject']) > 100) {
224
+					$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
225
+		}
215 226
 
216 227
 		// If it's still valid move onwards and upwards.
217 228
 		if ($_POST['custom_subject'] != '')
@@ -221,9 +232,9 @@  discard block
 block discarded – undo
221 232
 				// Get a response prefix, but in the forum's default language.
222 233
 				if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix')))
223 234
 				{
224
-					if ($language === $user_info['language'])
225
-						$context['response_prefix'] = $txt['response_prefix'];
226
-					else
235
+					if ($language === $user_info['language']) {
236
+											$context['response_prefix'] = $txt['response_prefix'];
237
+					} else
227 238
 					{
228 239
 						loadLanguage('index', $language, false);
229 240
 						$context['response_prefix'] = $txt['response_prefix'];
@@ -263,8 +274,9 @@  discard block
 block discarded – undo
263 274
 	if (isset($_POST['postRedirect']))
264 275
 	{
265 276
 		// Should be in the boardwide language.
266
-		if ($user_info['language'] != $language)
267
-			loadLanguage('index', $language);
277
+		if ($user_info['language'] != $language) {
278
+					loadLanguage('index', $language);
279
+		}
268 280
 
269 281
 		$_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES);
270 282
 		preparsecode($_POST['reason']);
@@ -328,8 +340,9 @@  discard block
 block discarded – undo
328 340
 		$posters = array();
329 341
 		while ($row = $smcFunc['db_fetch_assoc']($request))
330 342
 		{
331
-			if (!isset($posters[$row['id_member']]))
332
-				$posters[$row['id_member']] = 0;
343
+			if (!isset($posters[$row['id_member']])) {
344
+							$posters[$row['id_member']] = 0;
345
+			}
333 346
 
334 347
 			$posters[$row['id_member']]++;
335 348
 		}
@@ -338,11 +351,13 @@  discard block
 block discarded – undo
338 351
 		foreach ($posters as $id_member => $posts)
339 352
 		{
340 353
 			// The board we're moving from counted posts, but not to.
341
-			if (empty($pcounter_from))
342
-				updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
354
+			if (empty($pcounter_from)) {
355
+							updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
356
+			}
343 357
 			// The reverse: from didn't, to did.
344
-			else
345
-				updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
358
+			else {
359
+							updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
360
+			}
346 361
 		}
347 362
 	}
348 363
 
@@ -350,19 +365,21 @@  discard block
 block discarded – undo
350 365
 	moveTopics($topic, $_POST['toboard']);
351 366
 
352 367
 	// Log that they moved this topic.
353
-	if (!allowedTo('move_own') || $id_member_started != $user_info['id'])
354
-		logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
368
+	if (!allowedTo('move_own') || $id_member_started != $user_info['id']) {
369
+			logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
370
+	}
355 371
 	// Notify people that this topic has been moved?
356 372
 	sendNotifications($topic, 'move');
357 373
 	
358 374
 	call_integration_hook('integrate_movetopic2_end');
359 375
 
360 376
 	// Why not go back to the original board in case they want to keep moving?
361
-	if (!isset($_REQUEST['goback']))
362
-		redirectexit('board=' . $board . '.0');
363
-	else
364
-		redirectexit('topic=' . $topic . '.0');
365
-}
377
+	if (!isset($_REQUEST['goback'])) {
378
+			redirectexit('board=' . $board . '.0');
379
+	} else {
380
+			redirectexit('topic=' . $topic . '.0');
381
+	}
382
+	}
366 383
 
367 384
 /**
368 385
  * Moves one or more topics to a specific board. (doesn't check permissions.)
@@ -378,18 +395,21 @@  discard block
 block discarded – undo
378 395
 	global $sourcedir, $user_info, $modSettings, $smcFunc;
379 396
 
380 397
 	// Empty array?
381
-	if (empty($topics))
382
-		return;
398
+	if (empty($topics)) {
399
+			return;
400
+	}
383 401
 
384 402
 	// Only a single topic.
385
-	if (is_numeric($topics))
386
-		$topics = array($topics);
403
+	if (is_numeric($topics)) {
404
+			$topics = array($topics);
405
+	}
387 406
 
388 407
 	$fromBoards = array();
389 408
 
390 409
 	// Destination board empty or equal to 0?
391
-	if (empty($toBoard))
392
-		return;
410
+	if (empty($toBoard)) {
411
+			return;
412
+	}
393 413
 
394 414
 	// Are we moving to the recycle board?
395 415
 	$isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard;
@@ -397,8 +417,9 @@  discard block
 block discarded – undo
397 417
 	// Callback for search APIs to do their thing
398 418
 	require_once($sourcedir . '/Search.php');
399 419
 	$searchAPI = findSearchAPI();
400
-	if ($searchAPI->supportsMethod('topicsMoved'))
401
-		$searchAPI->topicsMoved($topics, $toBoard);
420
+	if ($searchAPI->supportsMethod('topicsMoved')) {
421
+			$searchAPI->topicsMoved($topics, $toBoard);
422
+	}
402 423
 
403 424
 	// Determine the source boards...
404 425
 	$request = $smcFunc['db_query']('', '
@@ -412,8 +433,9 @@  discard block
 block discarded – undo
412 433
 		)
413 434
 	);
414 435
 	// Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards.
415
-	if ($smcFunc['db_num_rows']($request) == 0)
416
-		return;
436
+	if ($smcFunc['db_num_rows']($request) == 0) {
437
+			return;
438
+	}
417 439
 	while ($row = $smcFunc['db_fetch_assoc']($request))
418 440
 	{
419 441
 		if (!isset($fromBoards[$row['id_board']]['num_posts']))
@@ -431,10 +453,11 @@  discard block
 block discarded – undo
431 453
 		$fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts'];
432 454
 
433 455
 		// Add the topics to the right type.
434
-		if ($row['approved'])
435
-			$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
436
-		else
437
-			$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
456
+		if ($row['approved']) {
457
+					$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics'];
458
+		} else {
459
+					$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics'];
460
+		}
438 461
 	}
439 462
 	$smcFunc['db_free_result']($request);
440 463
 
@@ -560,13 +583,14 @@  discard block
 block discarded – undo
560 583
 			)
561 584
 		);
562 585
 		$approval_msgs = array();
563
-		while ($row = $smcFunc['db_fetch_assoc']($request))
564
-			$approval_msgs[] = $row['id_msg'];
586
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
587
+					$approval_msgs[] = $row['id_msg'];
588
+		}
565 589
 		$smcFunc['db_free_result']($request);
566 590
 
567 591
 		// Empty the approval queue for these, as we're going to approve them next.
568
-		if (!empty($approval_msgs))
569
-			$smcFunc['db_query']('', '
592
+		if (!empty($approval_msgs)) {
593
+					$smcFunc['db_query']('', '
570 594
 				DELETE FROM {db_prefix}approval_queue
571 595
 				WHERE id_msg IN ({array_int:message_list})
572 596
 					AND id_attach = {int:id_attach}',
@@ -575,6 +599,7 @@  discard block
 block discarded – undo
575 599
 					'id_attach' => 0,
576 600
 				)
577 601
 			);
602
+		}
578 603
 
579 604
 		// Get all the current max and mins.
580 605
 		$request = $smcFunc['db_query']('', '
@@ -608,8 +633,8 @@  discard block
 block discarded – undo
608 633
 		while ($row = $smcFunc['db_fetch_assoc']($request))
609 634
 		{
610 635
 			// If not, update.
611
-			if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max'])
612
-				$smcFunc['db_query']('', '
636
+			if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) {
637
+							$smcFunc['db_query']('', '
613 638
 					UPDATE {db_prefix}topics
614 639
 					SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg}
615 640
 					WHERE id_topic = {int:selected_topic}',
@@ -619,6 +644,7 @@  discard block
 block discarded – undo
619 644
 						'selected_topic' => $row['id_topic'],
620 645
 					)
621 646
 				);
647
+			}
622 648
 		}
623 649
 		$smcFunc['db_free_result']($request);
624 650
 	}
@@ -677,9 +703,10 @@  discard block
 block discarded – undo
677 703
 	}
678 704
 
679 705
 	// Update the cache?
680
-	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3)
681
-		foreach ($topics as $topic_id)
706
+	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) {
707
+			foreach ($topics as $topic_id)
682 708
 			cache_put_data('topic_board-' . $topic_id, null, 120);
709
+	}
683 710
 
684 711
 	require_once($sourcedir . '/Subs-Post.php');
685 712
 
@@ -703,15 +730,17 @@  discard block
 block discarded – undo
703 730
 {
704 731
 	global $board, $topic, $smcFunc, $scripturl;
705 732
 
706
-	if (isset($_GET['current_board']))
707
-		$move_from = (int) $_GET['current_board'];
733
+	if (isset($_GET['current_board'])) {
734
+			$move_from = (int) $_GET['current_board'];
735
+	}
708 736
 
709
-	if (empty($move_from) || empty($board) || empty($topic))
710
-		return true;
737
+	if (empty($move_from) || empty($board) || empty($topic)) {
738
+			return true;
739
+	}
711 740
 
712
-	if ($move_from == $board)
713
-		return true;
714
-	else
741
+	if ($move_from == $board) {
742
+			return true;
743
+	} else
715 744
 	{
716 745
 		$request = $smcFunc['db_query']('', '
717 746
 			SELECT m.subject, b.name
Please login to merge, or discard this patch.
Sources/ManageErrors.php 1 patch
Braces   +52 added lines, -40 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * View the forum's error log.
@@ -30,12 +31,14 @@  discard block
 block discarded – undo
30 31
 	global $scripturl, $txt, $context, $modSettings, $user_profile, $filter, $smcFunc;
31 32
 
32 33
 	// Viewing contents of a file?
33
-	if (isset($_GET['file']))
34
-		return ViewFile();
34
+	if (isset($_GET['file'])) {
35
+			return ViewFile();
36
+	}
35 37
 	
36 38
 	// Viewing contents of a backtrace?
37
-	if (isset($_GET['backtrace']))
38
-		return ViewBacktrace();
39
+	if (isset($_GET['backtrace'])) {
40
+			return ViewBacktrace();
41
+	}
39 42
 
40 43
 	// Check for the administrative permission to do this.
41 44
 	isAllowedTo('admin_forum');
@@ -89,8 +92,8 @@  discard block
 block discarded – undo
89 92
 	);
90 93
 
91 94
 	// Set up the filtering...
92
-	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']]))
93
-		$filter = array(
95
+	if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) {
96
+			$filter = array(
94 97
 			'variable' => $_GET['filter'],
95 98
 			'value' => array(
96 99
 				'sql' => in_array($_GET['filter'], array('message', 'url', 'file')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']),
@@ -98,10 +101,12 @@  discard block
 block discarded – undo
98 101
 			'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'],
99 102
 			'entity' => $filters[$_GET['filter']]['txt']
100 103
 		);
104
+	}
101 105
 
102 106
 	// Deleting, are we?
103
-	if (isset($_POST['delall']) || isset($_POST['delete']))
104
-		deleteErrors();
107
+	if (isset($_POST['delall']) || isset($_POST['delete'])) {
108
+			deleteErrors();
109
+	}
105 110
 
106 111
 	// Just how many errors are there?
107 112
 	$result = $smcFunc['db_query']('', '
@@ -116,12 +121,14 @@  discard block
 block discarded – undo
116 121
 	$smcFunc['db_free_result']($result);
117 122
 
118 123
 	// If this filter is empty...
119
-	if ($num_errors == 0 && isset($filter))
120
-		redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
124
+	if ($num_errors == 0 && isset($filter)) {
125
+			redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : ''));
126
+	}
121 127
 
122 128
 	// Clean up start.
123
-	if (!isset($_GET['start']) || $_GET['start'] < 0)
124
-		$_GET['start'] = 0;
129
+	if (!isset($_GET['start']) || $_GET['start'] < 0) {
130
+			$_GET['start'] = 0;
131
+	}
125 132
 
126 133
 	// Do we want to reverse error listing?
127 134
 	$context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up';
@@ -131,9 +138,9 @@  discard block
 block discarded – undo
131 138
 	$context['start'] = $_GET['start'];
132 139
 
133 140
 	// Update the error count
134
-	if (!isset($filter))
135
-		$context['num_errors'] = $num_errors;
136
-	else
141
+	if (!isset($filter)) {
142
+			$context['num_errors'] = $num_errors;
143
+	} else
137 144
 	{
138 145
 		// We want all errors, not just the number of filtered messages...
139 146
 		$query = $smcFunc['db_query']('', '
@@ -165,8 +172,9 @@  discard block
 block discarded – undo
165 172
 	for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++)
166 173
 	{
167 174
 		$search_message = preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '%', $smcFunc['db_escape_wildcard_string']($row['message']));
168
-		if ($search_message == $filter['value']['sql'])
169
-			$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
175
+		if ($search_message == $filter['value']['sql']) {
176
+					$search_message = $smcFunc['db_escape_wildcard_string']($row['message']);
177
+		}
170 178
 		$show_message = strtr(strtr(preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '$1', $row['message']), array("\r" => '', '<br>' => "\n", '<' => '&lt;', '>' => '&gt;', '"' => '&quot;')), array("\n" => '<br>'));
171 179
 
172 180
 		$context['errors'][$row['id_error']] = array(
@@ -225,8 +233,9 @@  discard block
 block discarded – undo
225 233
 				'members' => count($members),
226 234
 			)
227 235
 		);
228
-		while ($row = $smcFunc['db_fetch_assoc']($request))
229
-			$members[$row['id_member']] = $row;
236
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+					$members[$row['id_member']] = $row;
238
+		}
230 239
 		$smcFunc['db_free_result']($request);
231 240
 
232 241
 		// This is a guest...
@@ -258,20 +267,18 @@  discard block
 block discarded – undo
258 267
 			$id = $filter['value']['sql'];
259 268
 			loadMemberData($id, false, 'minimal');
260 269
 			$context['filter']['value']['html'] = '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $user_profile[$id]['real_name'] . '</a>';
261
-		}
262
-		elseif ($filter['variable'] == 'url')
263
-			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
264
-		elseif ($filter['variable'] == 'message')
270
+		} elseif ($filter['variable'] == 'url') {
271
+					$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\'';
272
+		} elseif ($filter['variable'] == 'message')
265 273
 		{
266 274
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
267 275
 			$context['filter']['value']['html'] = preg_replace('~&amp;lt;span class=&amp;quot;remove&amp;quot;&amp;gt;(.+?)&amp;lt;/span&amp;gt;~', '$1', $context['filter']['value']['html']);
268
-		}
269
-		elseif ($filter['variable'] == 'error_type')
276
+		} elseif ($filter['variable'] == 'error_type')
270 277
 		{
271 278
 			$context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '&lt;br /&gt;' => '<br>', "\t" => '&nbsp;&nbsp;&nbsp;', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\'';
279
+		} else {
280
+					$context['filter']['value']['html'] = &$filter['value']['sql'];
272 281
 		}
273
-		else
274
-			$context['filter']['value']['html'] = &$filter['value']['sql'];
275 282
 	}
276 283
 
277 284
 	$context['error_types'] = array();
@@ -312,10 +319,11 @@  discard block
 block discarded – undo
312 319
 	$context['error_types']['all']['label'] .= ' (' . $sum . ')';
313 320
 
314 321
 	// Finally, work out what is the last tab!
315
-	if (isset($context['error_types'][$sum]))
316
-		$context['error_types'][$sum]['is_last'] = true;
317
-	else
318
-		$context['error_types']['all']['is_last'] = true;
322
+	if (isset($context['error_types'][$sum])) {
323
+			$context['error_types'][$sum]['is_last'] = true;
324
+	} else {
325
+			$context['error_types']['all']['is_last'] = true;
326
+	}
319 327
 
320 328
 	// And this is pretty basic ;).
321 329
 	$context['page_title'] = $txt['errlog'];
@@ -341,21 +349,23 @@  discard block
 block discarded – undo
341 349
 	validateToken('admin-el');
342 350
 
343 351
 	// Delete all or just some?
344
-	if (isset($_POST['delall']) && !isset($filter))
345
-		$smcFunc['db_query']('truncate_table', '
352
+	if (isset($_POST['delall']) && !isset($filter)) {
353
+			$smcFunc['db_query']('truncate_table', '
346 354
 			TRUNCATE {db_prefix}log_errors',
347 355
 			array(
348 356
 			)
349 357
 		);
358
+	}
350 359
 	// Deleting all with a filter?
351
-	elseif (isset($_POST['delall']) && isset($filter))
352
-		$smcFunc['db_query']('', '
360
+	elseif (isset($_POST['delall']) && isset($filter)) {
361
+			$smcFunc['db_query']('', '
353 362
 			DELETE FROM {db_prefix}log_errors
354 363
 			WHERE ' . $filter['variable'] . ' LIKE {string:filter}',
355 364
 			array(
356 365
 				'filter' => $filter['value']['sql'],
357 366
 			)
358 367
 		);
368
+	}
359 369
 	// Just specific errors?
360 370
 	elseif (!empty($_POST['delete']))
361 371
 	{
@@ -401,15 +411,17 @@  discard block
 block discarded – undo
401 411
 	$line = isset($_REQUEST['line']) ? (int) $_REQUEST['line'] : 0;
402 412
 
403 413
 	// Make sure the file we are looking for is one they are allowed to look at
404
-	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file))
405
-		fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
414
+	if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) {
415
+			fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file)));
416
+	}
406 417
 
407 418
 	// get the min and max lines
408 419
 	$min = $line - 20 <= 0 ? 1 : $line - 20;
409 420
 	$max = $line + 21; // One additional line to make everything work out correctly
410 421
 
411
-	if ($max <= 0 || $min >= $max)
412
-		fatal_lang_error('error_bad_line');
422
+	if ($max <= 0 || $min >= $max) {
423
+			fatal_lang_error('error_bad_line');
424
+	}
413 425
 
414 426
 	$file_data = explode('<br />', highlight_php_code($smcFunc['htmlspecialchars'](implode('', file($file)))));
415 427
 
Please login to merge, or discard this patch.
Sources/Errors.php 1 patch
Braces   +130 added lines, -93 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Log an error, if the error logging is enabled.
@@ -39,10 +40,11 @@  discard block
 block discarded – undo
39 40
 	$error_call++;
40 41
 
41 42
 	// Collect a backtrace
42
-	if (!isset($db_show_debug) || $db_show_debug === false)
43
-		$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
44
-	else
45
-		$backtrace = debug_backtrace();
43
+	if (!isset($db_show_debug) || $db_show_debug === false) {
44
+			$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
45
+	} else {
46
+			$backtrace = debug_backtrace();
47
+	}
46 48
 
47 49
 	// are we in a loop?
48 50
 	if($error_call > 2)
@@ -52,8 +54,9 @@  discard block
 block discarded – undo
52 54
 	}
53 55
 
54 56
 	// Check if error logging is actually on.
55
-	if (empty($modSettings['enableErrorLogging']))
56
-		return $error_message;
57
+	if (empty($modSettings['enableErrorLogging'])) {
58
+			return $error_message;
59
+	}
57 60
 
58 61
 	// Basically, htmlspecialchars it minus &. (for entities!)
59 62
 	$error_message = strtr($error_message, array('<' => '&lt;', '>' => '&gt;', '"' => '&quot;'));
@@ -61,33 +64,39 @@  discard block
 block discarded – undo
61 64
 
62 65
 	// Add a file and line to the error message?
63 66
 	// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
64
-	if ($file == null)
65
-		$file = '';
66
-	else
67
-		// Window style slashes don't play well, lets convert them to the unix style.
67
+	if ($file == null) {
68
+			$file = '';
69
+	} else {
70
+			// Window style slashes don't play well, lets convert them to the unix style.
68 71
 		$file = str_replace('\\', '/', $file);
72
+	}
69 73
 
70
-	if ($line == null)
71
-		$line = 0;
72
-	else
73
-		$line = (int) $line;
74
+	if ($line == null) {
75
+			$line = 0;
76
+	} else {
77
+			$line = (int) $line;
78
+	}
74 79
 
75 80
 	// Just in case there's no id_member or IP set yet.
76
-	if (empty($user_info['id']))
77
-		$user_info['id'] = 0;
78
-	if (empty($user_info['ip']))
79
-		$user_info['ip'] = '';
81
+	if (empty($user_info['id'])) {
82
+			$user_info['id'] = 0;
83
+	}
84
+	if (empty($user_info['ip'])) {
85
+			$user_info['ip'] = '';
86
+	}
80 87
 
81 88
 	// Find the best query string we can...
82 89
 	$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
83 90
 
84 91
 	// Don't log the session hash in the url twice, it's a waste.
85
-	if (!empty($smcFunc['htmlspecialchars']))
86
-		$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
92
+	if (!empty($smcFunc['htmlspecialchars'])) {
93
+			$query_string = $smcFunc['htmlspecialchars']((SMF == 'SSI' || SMF == 'BACKGROUND' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
94
+	}
87 95
 
88 96
 	// Just so we know what board error messages are from.
89
-	if (isset($_POST['board']) && !isset($_GET['board']))
90
-		$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
97
+	if (isset($_POST['board']) && !isset($_GET['board'])) {
98
+			$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
99
+	}
91 100
 
92 101
 	// What types of categories do we have?
93 102
 	$known_error_types = array(
@@ -140,9 +149,9 @@  discard block
 block discarded – undo
140 149
 
141 150
 			list($context['num_errors']) = $smcFunc['db_fetch_row']($query);
142 151
 			$smcFunc['db_free_result']($query);
152
+		} else {
153
+					$context['num_errors']++;
143 154
 		}
144
-		else
145
-			$context['num_errors']++;
146 155
 	}
147 156
 
148 157
 	// reset error call
@@ -164,12 +173,14 @@  discard block
 block discarded – undo
164 173
 	global $txt;
165 174
 
166 175
 	// Send the appropriate HTTP status header - set this to 0 or false if you don't want to send one at all
167
-	if (!empty($status))
168
-		send_http_status($status);
176
+	if (!empty($status)) {
177
+			send_http_status($status);
178
+	}
169 179
 
170 180
 	// We don't have $txt yet, but that's okay...
171
-	if (empty($txt))
172
-		die($error);
181
+	if (empty($txt)) {
182
+			die($error);
183
+	}
173 184
 
174 185
 	log_error_online($error, false);
175 186
 	setup_fatal_error_context($log ? log_error($error, $log) : $error);
@@ -196,8 +207,9 @@  discard block
 block discarded – undo
196 207
 	static $fatal_error_called = false;
197 208
 
198 209
 	// Send the status header - set this to 0 or false if you don't want to send one at all
199
-	if (!empty($status))
200
-		send_http_status($status);
210
+	if (!empty($status)) {
211
+			send_http_status($status);
212
+	}
201 213
 
202 214
 	// Try to load a theme if we don't have one.
203 215
 	if (empty($context['theme_loaded']) && empty($fatal_error_called))
@@ -207,8 +219,9 @@  discard block
 block discarded – undo
207 219
 	}
208 220
 
209 221
 	// If we have no theme stuff we can't have the language file...
210
-	if (empty($context['theme_loaded']))
211
-		die($error);
222
+	if (empty($context['theme_loaded'])) {
223
+			die($error);
224
+	}
212 225
 
213 226
 	$reload_lang_file = true;
214 227
 	// Log the error in the forum's language, but don't waste the time if we aren't logging
@@ -244,8 +257,9 @@  discard block
 block discarded – undo
244 257
 	global $settings, $modSettings, $db_show_debug;
245 258
 
246 259
 	// Ignore errors if we're ignoring them or they are strict notices from PHP 5
247
-	if (error_reporting() == 0)
248
-		return;
260
+	if (error_reporting() == 0) {
261
+			return;
262
+	}
249 263
 
250 264
 	if (strpos($file, 'eval()') !== false && !empty($settings['current_include_filename']))
251 265
 	{
@@ -253,19 +267,22 @@  discard block
 block discarded – undo
253 267
 		$count = count($array);
254 268
 		for ($i = 0; $i < $count; $i++)
255 269
 		{
256
-			if ($array[$i]['function'] != 'loadSubTemplate')
257
-				continue;
270
+			if ($array[$i]['function'] != 'loadSubTemplate') {
271
+							continue;
272
+			}
258 273
 
259 274
 			// This is a bug in PHP, with eval, it seems!
260
-			if (empty($array[$i]['args']))
261
-				$i++;
275
+			if (empty($array[$i]['args'])) {
276
+							$i++;
277
+			}
262 278
 			break;
263 279
 		}
264 280
 
265
-		if (isset($array[$i]) && !empty($array[$i]['args']))
266
-			$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
267
-		else
268
-			$file = realpath($settings['current_include_filename']) . ' (eval?)';
281
+		if (isset($array[$i]) && !empty($array[$i]['args'])) {
282
+					$file = realpath($settings['current_include_filename']) . ' (' . $array[$i]['args'][0] . ' sub template - eval?)';
283
+		} else {
284
+					$file = realpath($settings['current_include_filename']) . ' (eval?)';
285
+		}
269 286
 	}
270 287
 
271 288
 	if (isset($db_show_debug) && $db_show_debug === true)
@@ -274,8 +291,9 @@  discard block
 block discarded – undo
274 291
 		if ($error_level % 255 != E_ERROR)
275 292
 		{
276 293
 			$temporary = ob_get_contents();
277
-			if (substr($temporary, -2) == '="')
278
-				echo '"';
294
+			if (substr($temporary, -2) == '="') {
295
+							echo '"';
296
+			}
279 297
 		}
280 298
 
281 299
 		// Debugging!  This should look like a PHP error message.
@@ -291,23 +309,27 @@  discard block
 block discarded – undo
291 309
 	call_integration_hook('integrate_output_error', array($message, $error_type, $error_level, $file, $line));
292 310
 
293 311
 	// Dying on these errors only causes MORE problems (blank pages!)
294
-	if ($file == 'Unknown')
295
-		return;
312
+	if ($file == 'Unknown') {
313
+			return;
314
+	}
296 315
 
297 316
 	// If this is an E_ERROR or E_USER_ERROR.... die.  Violently so.
298
-	if ($error_level % 255 == E_ERROR)
299
-		obExit(false);
300
-	else
301
-		return;
317
+	if ($error_level % 255 == E_ERROR) {
318
+			obExit(false);
319
+	} else {
320
+			return;
321
+	}
302 322
 
303 323
 	// If this is an E_ERROR, E_USER_ERROR, E_WARNING, or E_USER_WARNING.... die.  Violently so.
304
-	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING)
305
-		fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
324
+	if ($error_level % 255 == E_ERROR || $error_level % 255 == E_WARNING) {
325
+			fatal_error(allowedTo('admin_forum') ? $message : $error_string, false);
326
+	}
306 327
 
307 328
 	// We should NEVER get to this point.  Any fatal error MUST quit, or very bad things can happen.
308
-	if ($error_level % 255 == E_ERROR)
309
-		die('No direct access...');
310
-}
329
+	if ($error_level % 255 == E_ERROR) {
330
+			die('No direct access...');
331
+	}
332
+	}
311 333
 
312 334
 /**
313 335
  * It is called by {@link fatal_error()} and {@link fatal_lang_error()}.
@@ -323,24 +345,28 @@  discard block
 block discarded – undo
323 345
 
324 346
 	// Attempt to prevent a recursive loop.
325 347
 	++$level;
326
-	if ($level > 1)
327
-		return false;
348
+	if ($level > 1) {
349
+			return false;
350
+	}
328 351
 
329 352
 	// Maybe they came from dlattach or similar?
330
-	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded']))
331
-		loadTheme();
353
+	if (SMF != 'SSI' && SMF != 'BACKGROUND' && empty($context['theme_loaded'])) {
354
+			loadTheme();
355
+	}
332 356
 
333 357
 	// Don't bother indexing errors mate...
334 358
 	$context['robot_no_index'] = true;
335 359
 
336
-	if (!isset($context['error_title']))
337
-		$context['error_title'] = $txt['error_occured'];
360
+	if (!isset($context['error_title'])) {
361
+			$context['error_title'] = $txt['error_occured'];
362
+	}
338 363
 	$context['error_message'] = isset($context['error_message']) ? $context['error_message'] : $error_message;
339 364
 
340 365
 	$context['error_code'] = isset($error_code) ? 'id="' . $error_code . '" ' : '';
341 366
 
342
-	if (empty($context['page_title']))
343
-		$context['page_title'] = $context['error_title'];
367
+	if (empty($context['page_title'])) {
368
+			$context['page_title'] = $context['error_title'];
369
+	}
344 370
 
345 371
 	loadTemplate('Errors');
346 372
 	$context['sub_template'] = 'fatal_error';
@@ -348,23 +374,26 @@  discard block
 block discarded – undo
348 374
 	// If this is SSI, what do they want us to do?
349 375
 	if (SMF == 'SSI')
350 376
 	{
351
-		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method))
352
-			$ssi_on_error_method();
353
-		elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
354
-			loadSubTemplate('fatal_error');
377
+		if (!empty($ssi_on_error_method) && $ssi_on_error_method !== true && is_callable($ssi_on_error_method)) {
378
+					$ssi_on_error_method();
379
+		} elseif (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
380
+					loadSubTemplate('fatal_error');
381
+		}
355 382
 
356 383
 		// No layers?
357
-		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true)
358
-			exit;
384
+		if (empty($ssi_on_error_method) || $ssi_on_error_method !== true) {
385
+					exit;
386
+		}
359 387
 	}
360 388
 	// Alternatively from the cron call?
361 389
 	elseif (SMF == 'BACKGROUND')
362 390
 	{
363 391
 		// We can't rely on even having language files available.
364
-		if (defined('FROM_CLI') && FROM_CLI)
365
-			echo 'cron error: ', $context['error_message'];
366
-		else
367
-			echo 'An error occurred. More information may be available in your logs.';
392
+		if (defined('FROM_CLI') && FROM_CLI) {
393
+					echo 'cron error: ', $context['error_message'];
394
+		} else {
395
+					echo 'An error occurred. More information may be available in your logs.';
396
+		}
368 397
 		exit;
369 398
 	}
370 399
 
@@ -392,8 +421,8 @@  discard block
 block discarded – undo
392 421
 
393 422
 	set_fatal_error_headers();
394 423
 
395
-	if (!empty($maintenance))
396
-		echo '<!DOCTYPE html>
424
+	if (!empty($maintenance)) {
425
+			echo '<!DOCTYPE html>
397 426
 <html>
398 427
 	<head>
399 428
 		<meta name="robots" content="noindex">
@@ -404,6 +433,7 @@  discard block
 block discarded – undo
404 433
 		', $mmessage, '
405 434
 	</body>
406 435
 </html>';
436
+	}
407 437
 
408 438
 	die();
409 439
 }
@@ -425,15 +455,17 @@  discard block
 block discarded – undo
425 455
 	// For our purposes, we're gonna want this on if at all possible.
426 456
 	$modSettings['cache_enable'] = '1';
427 457
 
428
-	if (($temp = cache_get_data('db_last_error', 600)) !== null)
429
-		$db_last_error = max($db_last_error, $temp);
458
+	if (($temp = cache_get_data('db_last_error', 600)) !== null) {
459
+			$db_last_error = max($db_last_error, $temp);
460
+	}
430 461
 
431 462
 	if ($db_last_error < time() - 3600 * 24 * 3 && empty($maintenance) && !empty($db_error_send))
432 463
 	{
433 464
 		// Avoid writing to the Settings.php file if at all possible; use shared memory instead.
434 465
 		cache_put_data('db_last_error', time(), 600);
435
-		if (($temp = cache_get_data('db_last_error', 600)) === null)
436
-			logLastDatabaseError();
466
+		if (($temp = cache_get_data('db_last_error', 600)) === null) {
467
+					logLastDatabaseError();
468
+		}
437 469
 
438 470
 		// Language files aren't loaded yet :(.
439 471
 		$db_error = @$smcFunc['db_error']($db_connection);
@@ -490,8 +522,9 @@  discard block
 block discarded – undo
490 522
  */
491 523
 function set_fatal_error_headers()
492 524
 {
493
-	if (headers_sent())
494
-		return;
525
+	if (headers_sent()) {
526
+			return;
527
+	}
495 528
 
496 529
 	// Don't cache this page!
497 530
 	header('expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -517,12 +550,14 @@  discard block
 block discarded – undo
517 550
 	global $smcFunc, $user_info, $modSettings;
518 551
 
519 552
 	// Don't bother if Who's Online is disabled.
520
-	if (empty($modSettings['who_enabled']))
521
-		return;
553
+	if (empty($modSettings['who_enabled'])) {
554
+			return;
555
+	}
522 556
 
523 557
 	// Maybe they came from SSI or similar where sessions are not recorded?
524
-	if (SMF == 'SSI' || SMF == 'BACKGROUND')
525
-		return;
558
+	if (SMF == 'SSI' || SMF == 'BACKGROUND') {
559
+			return;
560
+	}
526 561
 
527 562
 	$session_id = !empty($user_info['is_guest']) ? 'ip' . $user_info['ip'] : session_id();
528 563
 
@@ -548,8 +583,9 @@  discard block
 block discarded – undo
548 583
 		$url = $smcFunc['json_decode']($url, true);
549 584
 		$url['error'] = $error;
550 585
 
551
-		if (!empty($sprintf))
552
-			$url['error_params'] = $sprintf;
586
+		if (!empty($sprintf)) {
587
+					$url['error_params'] = $sprintf;
588
+		}
553 589
 
554 590
 		$smcFunc['db_query']('', '
555 591
 			UPDATE {db_prefix}log_online
@@ -580,10 +616,11 @@  discard block
 block discarded – undo
580 616
 
581 617
 	$protocol = preg_match('~HTTP/1\.[01]~i', $_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
582 618
 
583
-	if (!isset($statuses[$code]))
584
-		header($protocol . ' 500 Internal Server Error');
585
-	else
586
-		header($protocol . ' ' . $code . ' ' . $statuses[$code]);
587
-}
619
+	if (!isset($statuses[$code])) {
620
+			header($protocol . ' 500 Internal Server Error');
621
+	} else {
622
+			header($protocol . ' ' . $code . ' ' . $statuses[$code]);
623
+	}
624
+	}
588 625
 
589 626
 ?>
590 627
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Errors.template.php 1 patch
Braces   +39 added lines, -27 removed lines patch added patch discarded remove patch
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 {
24 24
 	global $context, $txt;
25 25
 
26
-	if (!empty($context['simple_action']))
27
-		echo '
26
+	if (!empty($context['simple_action'])) {
27
+			echo '
28 28
 	<strong>
29 29
 		', $context['error_title'], '
30 30
 	</strong><br>
31 31
 	<div ', $context['error_code'], 'class="padding">
32 32
 		', $context['error_message'], '
33 33
 	</div>';
34
-	else
34
+	} else
35 35
 	{
36 36
 		echo '
37 37
 	<div id="fatal_error">
@@ -85,21 +85,23 @@  discard block
 block discarded – undo
85 85
 
86 86
 	$error_types = array();
87 87
 
88
-	foreach ($context['error_types'] as $type => $details)
89
-		$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
88
+	foreach ($context['error_types'] as $type => $details) {
89
+			$error_types[] = ($details['is_selected'] ? '<img src="' . $settings['images_url'] . '/selected.png" alt=""> ' : '') . '<a href="' . $details['url'] . '" ' . ($details['is_selected'] ? 'style="font-weight: bold;"' : '') . ' title="' . $details['description'] . '">' . $details['label'] . '</a>';
90
+	}
90 91
 
91 92
 	echo '
92 93
 						', implode(' | ', $error_types), '
93 94
 					</td>
94 95
 				</tr>';
95 96
 
96
-	if ($context['has_filter'])
97
-		echo '
97
+	if ($context['has_filter']) {
98
+			echo '
98 99
 				<tr>
99 100
 					<td colspan="3" class="windowbg">
100 101
 						<strong>', $txt['applying_filter'], ':</strong> ', $context['filter']['entity'], ' ', $context['filter']['value']['html'], ' [<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', '">', $txt['clear_filter'], '</a>]
101 102
 					</td>
102 103
 				</tr>';
104
+	}
103 105
 
104 106
 	echo '
105 107
 				<tr>
@@ -110,11 +112,12 @@  discard block
 block discarded – undo
110 112
 				</tr>';
111 113
 
112 114
 	// No errors, then show a message
113
-	if (count($context['errors']) == 0)
114
-		echo '
115
+	if (count($context['errors']) == 0) {
116
+			echo '
115 117
 				<tr class="windowbg">
116 118
 					<td class="centertext" colspan="2">', $txt['errlog_no_entries'], '</td>
117 119
 				</tr>';
120
+	}
118 121
 
119 122
 	// We have some errors, must be some mods installed :P
120 123
 	foreach ($context['errors'] as $error)
@@ -128,16 +131,18 @@  discard block
 block discarded – undo
128 131
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? '' : ';desc', $context['has_filter'] ? $context['filter']['href'] : '', '" title="', $txt['reverse_direction'], '"><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></a>
129 132
 							', $error['time'], '<br>';
130 133
 
131
-		if (!empty($error['member']['ip']))
132
-			echo '
134
+		if (!empty($error['member']['ip'])) {
135
+					echo '
133 136
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=ip;value=', $error['member']['ip'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_ip'], '"><span class="generic_icons filter centericon"></span></a>
134 137
 							<strong><a href="', $scripturl, '?action=trackip;searchip=', $error['member']['ip'], '">', $error['member']['ip'], '</a></strong>';
138
+		}
135 139
 
136
-		if ($error['member']['session'] != '')
137
-			echo '
140
+		if ($error['member']['session'] != '') {
141
+					echo '
138 142
 							<br>
139 143
 							<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=session;value=', $error['member']['session'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_session'], '"><span class="generic_icons filter centericon"></span></a>
140 144
 							', $error['member']['session'], '<br>';
145
+		}
141 146
 
142 147
 		echo '
143 148
 						</div>
@@ -152,12 +157,13 @@  discard block
 block discarded – undo
152 157
 							<a href="', $error['url']['html'], '">', $error['url']['html'], '</a>
153 158
 ';
154 159
 
155
-		if (!empty($error['file']))
156
-			echo '
160
+		if (!empty($error['file'])) {
161
+					echo '
157 162
 							<div>
158 163
 								<a href="', $scripturl, '?action=admin;area=logs;sa=errorlog', $context['sort_direction'] == 'down' ? ';desc' : '', ';filter=file;value=', $error['file']['search'], '" title="', $txt['apply_filter'], ': ', $txt['filter_only_file'], '">'
159 164
 				. '					<span class="generic_icons filter"></span></a> ', $error['file']['link'], ' (', $txt['line'], ' ', $error['file']['line'], ')
160 165
 							</div>';
166
+		}
161 167
 
162 168
 		echo '
163 169
 						</div>
@@ -186,9 +192,10 @@  discard block
 block discarded – undo
186 192
 				</div>
187 193
 			</div>';
188 194
 
189
-	if ($context['sort_direction'] == 'down')
190
-		echo '
195
+	if ($context['sort_direction'] == 'down') {
196
+			echo '
191 197
 			<input type="hidden" name="desc" value="1">';
198
+	}
192 199
 
193 200
 	echo '
194 201
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
@@ -283,25 +290,30 @@  discard block
 block discarded – undo
283 290
 			<div class="windowbg noup">
284 291
 				<ul class="padding">';
285 292
 
286
-		if (!empty($context['error_info']['error_type']))
287
-			echo '
293
+		if (!empty($context['error_info']['error_type'])) {
294
+					echo '
288 295
 					<li>', $txt['error_type'], ': ', ucfirst($context['error_info']['error_type']), '</li>';
296
+		}
289 297
 
290
-		if (!empty($context['error_info']['message']))
291
-			echo '
298
+		if (!empty($context['error_info']['message'])) {
299
+					echo '
292 300
 					<li>', $txt['error_message'], ': ', $context['error_info']['message'], '</li>';
301
+		}
293 302
 
294
-		if (!empty($context['error_info']['file']))
295
-			echo '
303
+		if (!empty($context['error_info']['file'])) {
304
+					echo '
296 305
 					<li>', $txt['error_file'], ': ', $context['error_info']['file'], '</li>';
306
+		}
297 307
 
298
-		if (!empty($context['error_info']['line']))
299
-			echo '
308
+		if (!empty($context['error_info']['line'])) {
309
+					echo '
300 310
 					<li>', $txt['error_line'], ': ', $context['error_info']['line'], '</li>';
311
+		}
301 312
 
302
-		if (!empty($context['error_info']['url']))
303
-			echo '
313
+		if (!empty($context['error_info']['url'])) {
314
+					echo '
304 315
 					<li>', $txt['error_url'], ': ', $context['error_info']['url'], '</li>';
316
+		}
305 317
 
306 318
 
307 319
 		echo '
Please login to merge, or discard this patch.
Themes/default/Display.template.php 1 patch
Braces   +236 added lines, -162 removed lines patch added patch discarded remove patch
@@ -18,18 +18,20 @@  discard block
 block discarded – undo
18 18
 	global $context, $settings, $options, $txt, $scripturl, $modSettings;
19 19
 
20 20
 	// Let them know, if their report was a success!
21
-	if ($context['report_sent'])
22
-		echo '
21
+	if ($context['report_sent']) {
22
+			echo '
23 23
 		<div class="infobox">
24 24
 			', $txt['report_sent'], '
25 25
 		</div>';
26
+	}
26 27
 
27 28
 	// Let them know why their message became unapproved.
28
-	if ($context['becomesUnapproved'])
29
-		echo '
29
+	if ($context['becomesUnapproved']) {
30
+			echo '
30 31
 		<div class="noticebox">
31 32
 			', $txt['post_becomesUnapproved'], '
32 33
 		</div>';
34
+	}
33 35
 
34 36
 	// Show new topic info here?
35 37
 	echo '
@@ -49,11 +51,13 @@  discard block
 block discarded – undo
49 51
 			<p>';
50 52
 
51 53
 		// Show just numbers...?
52
-		if ($settings['display_who_viewing'] == 1)
53
-			echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
54
+		if ($settings['display_who_viewing'] == 1) {
55
+					echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
56
+		}
54 57
 		// Or show the actual people viewing the topic?
55
-		else
56
-			echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
58
+		else {
59
+					echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');
60
+		}
57 61
 
58 62
 		// Now show how many guests are here too.
59 63
 		echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_topic'], '
@@ -91,10 +95,11 @@  discard block
 block discarded – undo
91 95
 						<dt class="', $option['voted_this'] ? ' voted' : '', '">', $option['option'], '</dt>
92 96
 						<dd class="statsbar', $option['voted_this'] ? ' voted' : '', '">';
93 97
 
94
-				if ($context['allow_results_view'])
95
-					echo '
98
+				if ($context['allow_results_view']) {
99
+									echo '
96 100
 							', $option['bar_ndt'], '
97 101
 							<span class="percentage">', $option['votes'], ' (', $option['percent'], '%)</span>';
102
+				}
98 103
 
99 104
 				echo '
100 105
 						</dd>';
@@ -103,9 +108,10 @@  discard block
 block discarded – undo
103 108
 			echo '
104 109
 					</dl>';
105 110
 
106
-			if ($context['allow_results_view'])
107
-				echo '
111
+			if ($context['allow_results_view']) {
112
+							echo '
108 113
 					<p><strong>', $txt['poll_total_voters'], ':</strong> ', $context['poll']['total_votes'], '</p>';
114
+			}
109 115
 		}
110 116
 		// They are allowed to vote! Go to it!
111 117
 		else
@@ -114,17 +120,19 @@  discard block
 block discarded – undo
114 120
 					<form action="', $scripturl, '?action=vote;topic=', $context['current_topic'], '.', $context['start'], ';poll=', $context['poll']['id'], '" method="post" accept-charset="', $context['character_set'], '">';
115 121
 
116 122
 			// Show a warning if they are allowed more than one option.
117
-			if ($context['poll']['allowed_warning'])
118
-				echo '
123
+			if ($context['poll']['allowed_warning']) {
124
+							echo '
119 125
 						<p class="smallpadding">', $context['poll']['allowed_warning'], '</p>';
126
+			}
120 127
 
121 128
 			echo '
122 129
 						<ul class="options">';
123 130
 
124 131
 			// Show each option with its button - a radio likely.
125
-			foreach ($context['poll']['options'] as $option)
126
-				echo '
132
+			foreach ($context['poll']['options'] as $option) {
133
+							echo '
127 134
 							<li>', $option['vote_button'], ' <label for="', $option['id'], '">', $option['option'], '</label></li>';
135
+			}
128 136
 
129 137
 			echo '
130 138
 						</ul>
@@ -136,9 +144,10 @@  discard block
 block discarded – undo
136 144
 		}
137 145
 
138 146
 		// Is the clock ticking?
139
-		if (!empty($context['poll']['expire_time']))
140
-			echo '
147
+		if (!empty($context['poll']['expire_time'])) {
148
+					echo '
141 149
 					<p><strong>', ($context['poll']['is_expired'] ? $txt['poll_expired_on'] : $txt['poll_expires_on']), ':</strong> ', $context['poll']['expire_time'], '</p>';
150
+		}
142 151
 
143 152
 		echo '
144 153
 				</div><!-- #poll_options -->
@@ -168,11 +177,13 @@  discard block
 block discarded – undo
168 177
 				<li>
169 178
 					<strong class="event_title"><a href="', $scripturl, '?action=calendar;event=', $event['id'], '">', $event['title'], '</a></strong>';
170 179
 
171
-			if ($event['can_edit'])
172
-				echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
180
+			if ($event['can_edit']) {
181
+							echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>';
182
+			}
173 183
 
174
-			if ($event['can_export'])
175
-				echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
184
+			if ($event['can_export']) {
185
+							echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>';
186
+			}
176 187
 
177 188
 			echo '
178 189
 					<br>';
@@ -180,14 +191,14 @@  discard block
 block discarded – undo
180 191
 			if (!empty($event['allday']))
181 192
 			{
182 193
 				echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : '';
183
-			}
184
-			else
194
+			} else
185 195
 			{
186 196
 				// Display event info relative to user's local timezone
187 197
 				echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
188 198
 
189
-				if ($event['start_date_local'] != $event['end_date_local'])
190
-					echo trim($event['end_date_local']) . ', ';
199
+				if ($event['start_date_local'] != $event['end_date_local']) {
200
+									echo trim($event['end_date_local']) . ', ';
201
+				}
191 202
 
192 203
 				echo trim($event['end_time_local']);
193 204
 
@@ -196,24 +207,28 @@  discard block
 block discarded – undo
196 207
 				{
197 208
 					echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">';
198 209
 
199
-					if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig'])
200
-						echo trim($event['start_date_orig']), ', ';
210
+					if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) {
211
+											echo trim($event['start_date_orig']), ', ';
212
+					}
201 213
 
202 214
 					echo trim($event['start_time_orig']), '</time> &ndash; <time datetime="' . $event['end_iso_gmdate'] . '">';
203 215
 
204
-					if ($event['start_date_orig'] != $event['end_date_orig'])
205
-						echo trim($event['end_date_orig']) . ', ';
216
+					if ($event['start_date_orig'] != $event['end_date_orig']) {
217
+											echo trim($event['end_date_orig']) . ', ';
218
+					}
206 219
 
207 220
 					echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)';
208 221
 				}
209 222
 				// Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion
210
-				else
211
-					echo ' ', $event['tz_abbrev'], '</time>';
223
+				else {
224
+									echo ' ', $event['tz_abbrev'], '</time>';
225
+				}
212 226
 			}
213 227
 
214
-			if (!empty($event['location']))
215
-				echo '
228
+			if (!empty($event['location'])) {
229
+							echo '
216 230
 					<br>', $event['location'];
231
+			}
217 232
 
218 233
 			echo '
219 234
 				</li>';
@@ -250,8 +265,9 @@  discard block
 block discarded – undo
250 265
 	$context['removableMessageIDs'] = array();
251 266
 
252 267
 	// Get all the messages...
253
-	while ($message = $context['get_message']())
254
-		template_single_post($message);
268
+	while ($message = $context['get_message']()) {
269
+			template_single_post($message);
270
+	}
255 271
 
256 272
 	echo '
257 273
 			</form>
@@ -289,8 +305,9 @@  discard block
 block discarded – undo
289 305
 		<div id="display_jump_to"></div>';
290 306
 
291 307
 	// Show quickreply
292
-	if ($context['can_reply'])
293
-		template_quickreply();
308
+	if ($context['can_reply']) {
309
+			template_quickreply();
310
+	}
294 311
 
295 312
 	// User action pop on mobile screen (or actually small screen), this uses responsive css does not check mobile device.
296 313
 	echo '
@@ -305,8 +322,8 @@  discard block
 block discarded – undo
305 322
 		</div>';
306 323
 
307 324
 	// Show the moderation button & pop (if there is anything to show)
308
-	if (!empty($context['mod_buttons']))
309
-		echo '
325
+	if (!empty($context['mod_buttons'])) {
326
+			echo '
310 327
 		<div id="mobile_moderation" class="popup_container">
311 328
 			<div class="popup_window description">
312 329
 				<div class="popup_heading">
@@ -318,6 +335,7 @@  discard block
 block discarded – undo
318 335
 				</div>
319 336
 			</div>
320 337
 		</div>';
338
+	}
321 339
 
322 340
 	echo '
323 341
 		<script>';
@@ -441,9 +459,10 @@  discard block
 block discarded – undo
441 459
 				});
442 460
 			}';
443 461
 
444
-	if (!empty($context['ignoredMsgs']))
445
-		echo '
462
+	if (!empty($context['ignoredMsgs'])) {
463
+			echo '
446 464
 			ignore_toggles([', implode(', ', $context['ignoredMsgs']), '], ', JavaScriptEscape($txt['show_ignore_user_post']), ');';
465
+	}
447 466
 
448 467
 	echo '
449 468
 		</script>';
@@ -460,8 +479,9 @@  discard block
 block discarded – undo
460 479
 
461 480
 	$ignoring = false;
462 481
 
463
-	if ($message['can_remove'])
464
-		$context['removableMessageIDs'][] = $message['id'];
482
+	if ($message['can_remove']) {
483
+			$context['removableMessageIDs'][] = $message['id'];
484
+	}
465 485
 
466 486
 	// Are we ignoring this message?
467 487
 	if (!empty($message['is_ignored']))
@@ -488,9 +508,10 @@  discard block
 block discarded – undo
488 508
 							<div class="custom_fields_above_member">
489 509
 								<ul class="nolist">';
490 510
 
491
-		foreach ($message['custom_fields']['above_member'] as $custom)
492
-			echo '
511
+		foreach ($message['custom_fields']['above_member'] as $custom) {
512
+					echo '
493 513
 									<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
514
+		}
494 515
 
495 516
 		echo '
496 517
 								</ul>
@@ -501,25 +522,28 @@  discard block
 block discarded – undo
501 522
 							<h4>';
502 523
 
503 524
 	// Show online and offline buttons?
504
-	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'])
505
-		echo '
525
+	if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest']) {
526
+			echo '
506 527
 								', $context['can_send_pm'] ? '<a href="' . $message['member']['online']['href'] . '" title="' . $message['member']['online']['label'] . '">' : '', '<span class="' . ($message['member']['online']['is_online'] == 1 ? 'on' : 'off') . '" title="' . $message['member']['online']['text'] . '"></span>', $context['can_send_pm'] ? '</a>' : '';
528
+	}
507 529
 
508 530
 	// Custom fields BEFORE the username?
509
-	if (!empty($message['custom_fields']['before_member']))
510
-		foreach ($message['custom_fields']['before_member'] as $custom)
531
+	if (!empty($message['custom_fields']['before_member'])) {
532
+			foreach ($message['custom_fields']['before_member'] as $custom)
511 533
 			echo '
512 534
 								<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
535
+	}
513 536
 
514 537
 	// Show a link to the member's profile.
515 538
 	echo '
516 539
 								', $message['member']['link'];
517 540
 
518 541
 	// Custom fields AFTER the username?
519
-	if (!empty($message['custom_fields']['after_member']))
520
-		foreach ($message['custom_fields']['after_member'] as $custom)
542
+	if (!empty($message['custom_fields']['after_member'])) {
543
+			foreach ($message['custom_fields']['after_member'] as $custom)
521 544
 			echo '
522 545
 								<span class="custom ', $custom['col_name'], '">', $custom['value'], '</span>';
546
+	}
523 547
 
524 548
 	// Begin display of user info
525 549
 	echo '
@@ -527,50 +551,58 @@  discard block
 block discarded – undo
527 551
 							<ul class="user_info">';
528 552
 
529 553
 	// Show the user's avatar.
530
-	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
531
-		echo '
554
+	if (!empty($modSettings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image'])) {
555
+			echo '
532 556
 								<li class="avatar">
533 557
 									<a href="', $message['member']['href'], '">', $message['member']['avatar']['image'], '</a>
534 558
 								</li>';
559
+	}
535 560
 
536 561
 	// Are there any custom fields below the avatar?
537
-	if (!empty($message['custom_fields']['below_avatar']))
538
-		foreach ($message['custom_fields']['below_avatar'] as $custom)
562
+	if (!empty($message['custom_fields']['below_avatar'])) {
563
+			foreach ($message['custom_fields']['below_avatar'] as $custom)
539 564
 			echo '
540 565
 								<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
566
+	}
541 567
 
542 568
 	// Show the post group icons, but not for guests.
543
-	if (!$message['member']['is_guest'])
544
-		echo '
569
+	if (!$message['member']['is_guest']) {
570
+			echo '
545 571
 								<li class="icons">', $message['member']['group_icons'], '</li>';
572
+	}
546 573
 
547 574
 	// Show the member's primary group (like 'Administrator') if they have one.
548
-	if (!empty($message['member']['group']))
549
-		echo '
575
+	if (!empty($message['member']['group'])) {
576
+			echo '
550 577
 								<li class="membergroup">', $message['member']['group'], '</li>';
578
+	}
551 579
 
552 580
 	// Show the member's custom title, if they have one.
553
-	if (!empty($message['member']['title']))
554
-		echo '
581
+	if (!empty($message['member']['title'])) {
582
+			echo '
555 583
 								<li class="title">', $message['member']['title'], '</li>';
584
+	}
556 585
 
557 586
 	// Don't show these things for guests.
558 587
 	if (!$message['member']['is_guest'])
559 588
 	{
560 589
 		// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
561
-		if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group']))
562
-			echo '
590
+		if ((empty($modSettings['hide_post_group']) || empty($message['member']['group'])) && !empty($message['member']['post_group'])) {
591
+					echo '
563 592
 								<li class="postgroup">', $message['member']['post_group'], '</li>';
593
+		}
564 594
 
565 595
 		// Show how many posts they have made.
566
-		if (!isset($context['disabled_fields']['posts']))
567
-			echo '
596
+		if (!isset($context['disabled_fields']['posts'])) {
597
+					echo '
568 598
 								<li class="postcount">', $txt['member_postcount'], ': ', $message['member']['posts'], '</li>';
599
+		}
569 600
 
570 601
 		// Show their personal text?
571
-		if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb']))
572
-			echo '
602
+		if (!empty($modSettings['show_blurb']) && !empty($message['member']['blurb'])) {
603
+					echo '
573 604
 								<li class="blurb">', $message['member']['blurb'], '</li>';
605
+		}
574 606
 
575 607
 		// Any custom fields to show as icons?
576 608
 		if (!empty($message['custom_fields']['icons']))
@@ -579,9 +611,10 @@  discard block
 block discarded – undo
579 611
 								<li class="im_icons">
580 612
 									<ol>';
581 613
 
582
-			foreach ($message['custom_fields']['icons'] as $custom)
583
-				echo '
614
+			foreach ($message['custom_fields']['icons'] as $custom) {
615
+							echo '
584 616
 										<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
617
+			}
585 618
 
586 619
 			echo '
587 620
 									</ol>
@@ -596,19 +629,22 @@  discard block
 block discarded – undo
596 629
 									<ol class="profile_icons">';
597 630
 
598 631
 			// Don't show an icon if they haven't specified a website.
599
-			if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website']))
600
-				echo '
632
+			if (!empty($message['member']['website']['url']) && !isset($context['disabled_fields']['website'])) {
633
+							echo '
601 634
 										<li><a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank" rel="noopener">', ($settings['use_image_buttons'] ? '<span class="generic_icons www centericon" title="' . $message['member']['website']['title'] . '"></span>' : $txt['www']), '</a></li>';
635
+			}
602 636
 
603 637
 			// Since we know this person isn't a guest, you *can* message them.
604
-			if ($context['can_send_pm'])
605
-				echo '
638
+			if ($context['can_send_pm']) {
639
+							echo '
606 640
 										<li><a href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline'], '">', $settings['use_image_buttons'] ? '<span class="generic_icons im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . ' centericon" title="' . ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']) . '"></span> ' : ($message['member']['online']['is_online'] ? $txt['pm_online'] : $txt['pm_offline']), '</a></li>';
641
+			}
607 642
 
608 643
 			// Show the email if necessary
609
-			if (!empty($message['member']['email']) && $message['member']['show_email'])
610
-				echo '
644
+			if (!empty($message['member']['email']) && $message['member']['show_email']) {
645
+							echo '
611 646
 										<li class="email"><a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a></li>';
647
+			}
612 648
 
613 649
 			echo '
614 650
 									</ol>
@@ -616,57 +652,65 @@  discard block
 block discarded – undo
616 652
 		}
617 653
 
618 654
 		// Any custom fields for standard placement?
619
-		if (!empty($message['custom_fields']['standard']))
620
-			foreach ($message['custom_fields']['standard'] as $custom)
655
+		if (!empty($message['custom_fields']['standard'])) {
656
+					foreach ($message['custom_fields']['standard'] as $custom)
621 657
 				echo '
622 658
 								<li class="custom ', $custom['col_name'], '">', $custom['title'], ': ', $custom['value'], '</li>';
659
+		}
623 660
 	}
624 661
 	// Otherwise, show the guest's email.
625
-	elseif (!empty($message['member']['email']) && $message['member']['show_email'])
626
-		echo '
662
+	elseif (!empty($message['member']['email']) && $message['member']['show_email']) {
663
+			echo '
627 664
 								<li class="email">
628 665
 									<a href="mailto:' . $message['member']['email'] . '" rel="nofollow">', ($settings['use_image_buttons'] ? '<span class="generic_icons mail centericon" title="' . $txt['email'] . '"></span>' : $txt['email']), '</a>
629 666
 								</li>';
667
+	}
630 668
 
631 669
 	// Show the IP to this user for this post - because you can moderate?
632
-	if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip']))
633
-		echo '
670
+	if (!empty($context['can_moderate_forum']) && !empty($message['member']['ip'])) {
671
+			echo '
634 672
 								<li class="poster_ip">
635 673
 									<a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">(?)</a>
636 674
 								</li>';
675
+	}
637 676
 
638 677
 	// Or, should we show it because this is you?
639
-	elseif ($message['can_see_ip'])
640
-		echo '
678
+	elseif ($message['can_see_ip']) {
679
+			echo '
641 680
 								<li class="poster_ip">
642 681
 									<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $message['member']['ip'], '</a>
643 682
 								</li>';
683
+	}
644 684
 
645 685
 	// Okay, are you at least logged in? Then we can show something about why IPs are logged...
646
-	elseif (!$context['user']['is_guest'])
647
-		echo '
686
+	elseif (!$context['user']['is_guest']) {
687
+			echo '
648 688
 								<li class="poster_ip">
649 689
 									<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqOverlayDiv(this.href);" class="help">', $txt['logged'], '</a>
650 690
 								</li>';
691
+	}
651 692
 
652 693
 	// Otherwise, you see NOTHING!
653
-	else
654
-		echo '
694
+	else {
695
+			echo '
655 696
 								<li class="poster_ip">', $txt['logged'], '</li>';
697
+	}
656 698
 
657 699
 	// Are we showing the warning status?
658 700
 	// Don't show these things for guests.
659
-	if (!$message['member']['is_guest'] && $message['member']['can_see_warning'])
660
-		echo '
701
+	if (!$message['member']['is_guest'] && $message['member']['can_see_warning']) {
702
+			echo '
661 703
 								<li class="warning">
662 704
 									', $context['can_issue_warning'] ? '<a href="' . $scripturl . '?action=profile;area=issuewarning;u=' . $message['member']['id'] . '">' : '', '<span class="generic_icons warning_', $message['member']['warning_status'], '"></span> ', $context['can_issue_warning'] ? '</a>' : '', '<span class="warn_', $message['member']['warning_status'], '">', $txt['warn_' . $message['member']['warning_status']], '</span>
663 705
 								</li>';
706
+	}
664 707
 
665 708
 	// Are there any custom fields to show at the bottom of the poster info?
666
-	if (!empty($message['custom_fields']['bottom_poster']))
667
-		foreach ($message['custom_fields']['bottom_poster'] as $custom)
709
+	if (!empty($message['custom_fields']['bottom_poster'])) {
710
+			foreach ($message['custom_fields']['bottom_poster'] as $custom)
668 711
 			echo '
669 712
 								<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
713
+	}
670 714
 
671 715
 	// Poster info ends.
672 716
 	echo '
@@ -696,9 +740,10 @@  discard block
 block discarded – undo
696 740
 	echo '
697 741
 									<span class="smalltext modified floatright', !empty($modSettings['show_modify']) && !empty($message['modified']['name']) ? ' mvisible' : '','" id="modified_', $message['id'], '">';
698 742
 
699
-	if (!empty($modSettings['show_modify']) && !empty($message['modified']['name']))
700
-		echo
743
+	if (!empty($modSettings['show_modify']) && !empty($message['modified']['name'])) {
744
+			echo
701 745
 										$message['modified']['last_edit_text'];
746
+	}
702 747
 
703 748
 	echo '
704 749
 									</span>
@@ -707,22 +752,24 @@  discard block
 block discarded – undo
707 752
 							</div><!-- .keyinfo -->';
708 753
 
709 754
 	// Ignoring this user? Hide the post.
710
-	if ($ignoring)
711
-		echo '
755
+	if ($ignoring) {
756
+			echo '
712 757
 							<div id="msg_', $message['id'], '_ignored_prompt">
713 758
 								', $txt['ignoring_user'], '
714 759
 								<a href="#" id="msg_', $message['id'], '_ignored_link" style="display: none;">', $txt['show_ignore_user_post'], '</a>
715 760
 							</div>';
761
+	}
716 762
 
717 763
 	// Show the post itself, finally!
718 764
 	echo '
719 765
 							<div class="post">';
720 766
 
721
-	if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id'])
722
-		echo '
767
+	if (!$message['approved'] && $message['member']['id'] != 0 && $message['member']['id'] == $context['user']['id']) {
768
+			echo '
723 769
 								<div class="approve_post">
724 770
 									', $txt['post_awaiting_approval'], '
725 771
 								</div>';
772
+	}
726 773
 	echo '
727 774
 								<div class="inner" data-msgid="', $message['id'], '" id="msg_', $message['id'], '"', $ignoring ? ' style="display:none;"' : '', '>
728 775
 									', $message['body'], '
@@ -741,9 +788,9 @@  discard block
 block discarded – undo
741 788
 		foreach ($message['attachment'] as $attachment)
742 789
 		{
743 790
 			// Do we want this attachment to not be showed here?
744
-			if (!empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']]))
745
-				continue;
746
-			elseif (!$div_output)
791
+			if (!empty($modSettings['dont_show_attach_under_post']) && !empty($context['show_attach_under_post'][$attachment['id']])) {
792
+							continue;
793
+			} elseif (!$div_output)
747 794
 			{
748 795
 				$div_output = true;
749 796
 
@@ -760,9 +807,10 @@  discard block
 block discarded – undo
760 807
 									<legend>
761 808
 										', $txt['attach_awaiting_approve'];
762 809
 
763
-				if ($context['can_approve'])
764
-					echo '
810
+				if ($context['can_approve']) {
811
+									echo '
765 812
 										&nbsp;[<a href="', $scripturl, '?action=attachapprove;sa=all;mid=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve_all'], '</a>]';
813
+				}
766 814
 
767 815
 				echo '
768 816
 									</legend>';
@@ -776,12 +824,13 @@  discard block
 block discarded – undo
776 824
 				echo '
777 825
 										<div class="attachments_top">';
778 826
 
779
-				if ($attachment['thumbnail']['has_thumb'])
780
-					echo '
827
+				if ($attachment['thumbnail']['has_thumb']) {
828
+									echo '
781 829
 											<a href="', $attachment['href'], ';image" id="link_', $attachment['id'], '" onclick="', $attachment['thumbnail']['javascript'], '"><img src="', $attachment['thumbnail']['href'], '" alt="" id="thumb_', $attachment['id'], '" class="atc_img"></a>';
782
-				else
783
-					echo '
830
+				} else {
831
+									echo '
784 832
 											<img src="' . $attachment['href'] . ';image" alt="" width="' . $attachment['width'] . '" height="' . $attachment['height'] . '" class="atc_img">';
833
+				}
785 834
 
786 835
 				echo '
787 836
 										</div><!-- .attachments_top -->';
@@ -791,9 +840,10 @@  discard block
 block discarded – undo
791 840
 										<div class="attachments_bot">
792 841
 											<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.png" class="centericon" alt="*">&nbsp;' . $attachment['name'] . '</a> ';
793 842
 
794
-			if (!$attachment['is_approved'] && $context['can_approve'])
795
-				echo '
843
+			if (!$attachment['is_approved'] && $context['can_approve']) {
844
+							echo '
796 845
 											[<a href="', $scripturl, '?action=attachapprove;sa=approve;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['approve'], '</a>] [<a href="', $scripturl, '?action=attachapprove;sa=reject;aid=', $attachment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['delete'], '</a>] ';
846
+			}
797 847
 			echo '
798 848
 											<br>', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . '<br>' . sprintf($txt['attach_viewed'], $attachment['downloads']) : '<br>' . sprintf($txt['attach_downloaded'], $attachment['downloads'])), '
799 849
 										</div><!-- .attachments_bot -->';
@@ -802,35 +852,40 @@  discard block
 block discarded – undo
802 852
 									</div><!-- .attached -->';
803 853
 
804 854
 			// Next attachment line ?
805
-			if (++$i % $attachments_per_line === 0)
806
-				echo '
855
+			if (++$i % $attachments_per_line === 0) {
856
+							echo '
807 857
 									<br>';
858
+			}
808 859
 		}
809 860
 
810 861
 		// If we had unapproved attachments clean up.
811
-		if ($last_approved_state == 0)
812
-			echo '
862
+		if ($last_approved_state == 0) {
863
+					echo '
813 864
 								</fieldset>';
865
+		}
814 866
 
815 867
 		// Only do this if we output a div above - otherwise it'll break things
816
-		if ($div_output)
817
-			echo '
868
+		if ($div_output) {
869
+					echo '
818 870
 							</div><!-- #msg_[id]_footer -->';
871
+		}
819 872
 	}
820 873
 
821 874
 	// And stuff below the attachments.
822
-	if ($context['can_report_moderator'] || !empty($modSettings['enable_likes']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote'])
823
-		echo '
875
+	if ($context['can_report_moderator'] || !empty($modSettings['enable_likes']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote']) {
876
+			echo '
824 877
 							<div class="under_message">';
878
+	}
825 879
 
826 880
 	// Maybe they want to report this post to the moderator(s)?
827
-	if ($context['can_report_moderator'])
828
-		echo '
881
+	if ($context['can_report_moderator']) {
882
+			echo '
829 883
 								<ul class="floatright smalltext">
830 884
 									<li class="report_link">
831 885
 										<a href="', $scripturl, '?action=reporttm;topic=', $context['current_topic'], '.', $message['counter'], ';msg=', $message['id'], '">', $txt['report_to_mod'], '</a>
832 886
 									</li>
833 887
 								</ul>';
888
+	}
834 889
 
835 890
 	// What about likes?
836 891
 	if (!empty($modSettings['enable_likes']))
@@ -877,83 +932,95 @@  discard block
 block discarded – undo
877 932
 								<ul class="quickbuttons">';
878 933
 
879 934
 		// Can they quote? if so they can select and quote as well!
880
-		if ($context['can_quote'])
881
-			echo '
935
+		if ($context['can_quote']) {
936
+					echo '
882 937
 									<li><a href="', $scripturl, '?action=post;quote=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], ';last_msg=', $context['topic_last_message'], '" onclick="return oQuickReply.quote(', $message['id'], ');"><span class="generic_icons quote"></span>', $txt['quote_action'], '</a></li>
883 938
 									<li style="display:none;" id="quoteSelected_', $message['id'], '">
884 939
 										<a href="javascript:void(0)"><span class="generic_icons quote_selected"></span>', $txt['quote_selected_action'], '</a>
885 940
 									</li>';
941
+		}
886 942
 
887 943
 		// Can the user modify the contents of this post? Show the modify inline image.
888
-		if ($message['can_modify'])
889
-			echo '
944
+		if ($message['can_modify']) {
945
+					echo '
890 946
 									<li class="quick_edit">
891 947
 										<a title="', $txt['modify_msg'], '" class="modifybutton" id="modify_button_', $message['id'], '" onclick="oQuickModify.modifyMsg(\'', $message['id'], '\', \'', !empty($modSettings['toggle_subject']), '\')"><span class="generic_icons quick_edit_button"></span>', $txt['quick_edit'], '</a>
892 948
 									</li>';
949
+		}
893 950
 
894
-		if ($message['can_approve'] || $message['can_unapprove'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'])
895
-			echo '
951
+		if ($message['can_approve'] || $message['can_unapprove'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg']) {
952
+					echo '
896 953
 									<li class="post_options">', $txt['post_options'];
954
+		}
897 955
 
898 956
 		echo '
899 957
 										<ul>';
900 958
 
901 959
 		// Can the user modify the contents of this post?
902
-		if ($message['can_modify'])
903
-			echo '
960
+		if ($message['can_modify']) {
961
+					echo '
904 962
 											<li><a href="', $scripturl, '?action=post;msg=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], '"><span class="generic_icons modify_button"></span>', $txt['modify'], '</a></li>';
963
+		}
905 964
 
906 965
 		// How about... even... remove it entirely?!
907
-		if ($context['can_delete'] && ($context['topic_first_message'] == $message['id']))
908
-			echo '
966
+		if ($context['can_delete'] && ($context['topic_first_message'] == $message['id'])) {
967
+					echo '
909 968
 											<li><a href="', $scripturl, '?action=removetopic2;topic=', $context['current_topic'], '.', $context['start'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['are_sure_remove_topic'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove_topic'], '</a></li>';
910
-
911
-		elseif ($message['can_remove'] && ($context['topic_first_message'] != $message['id']))
912
-			echo '
969
+		} elseif ($message['can_remove'] && ($context['topic_first_message'] != $message['id'])) {
970
+					echo '
913 971
 											<li><a href="', $scripturl, '?action=deletemsg;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '" data-confirm="', $txt['remove_message_question'], '" class="you_sure"><span class="generic_icons remove_button"></span>', $txt['remove'], '</a></li>';
972
+		}
914 973
 
915 974
 		// What about splitting it off the rest of the topic?
916
-		if ($context['can_split'] && !empty($context['real_num_replies']))
917
-			echo '
975
+		if ($context['can_split'] && !empty($context['real_num_replies'])) {
976
+					echo '
918 977
 											<li><a href="', $scripturl, '?action=splittopics;topic=', $context['current_topic'], '.0;at=', $message['id'], '"><span class="generic_icons split_button"></span>', $txt['split'], '</a></li>';
978
+		}
919 979
 
920 980
 		// Can we issue a warning because of this post? Remember, we can't give guests warnings.
921
-		if ($context['can_issue_warning'] && !$message['is_message_author'] && !$message['member']['is_guest'])
922
-			echo '
981
+		if ($context['can_issue_warning'] && !$message['is_message_author'] && !$message['member']['is_guest']) {
982
+					echo '
923 983
 											<li><a href="', $scripturl, '?action=profile;area=issuewarning;u=', $message['member']['id'], ';msg=', $message['id'], '"><span class="generic_icons warn_button"></span>', $txt['issue_warning'], '</a></li>';
984
+		}
924 985
 
925 986
 		// Can we restore topics?
926
-		if ($context['can_restore_msg'])
927
-			echo '
987
+		if ($context['can_restore_msg']) {
988
+					echo '
928 989
 											<li><a href="', $scripturl, '?action=restoretopic;msgs=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons restore_button"></span>', $txt['restore_message'], '</a></li>';
990
+		}
929 991
 
930 992
 		// Maybe we can approve it, maybe we should?
931
-		if ($message['can_approve'])
932
-			echo '
993
+		if ($message['can_approve']) {
994
+					echo '
933 995
 											<li><a href="', $scripturl, '?action=moderate;area=postmod;sa=approve;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons approve_button"></span>', $txt['approve'], '</a></li>';
996
+		}
934 997
 
935 998
 		// Maybe we can unapprove it?
936
-		if ($message['can_unapprove'])
937
-			echo '
999
+		if ($message['can_unapprove']) {
1000
+					echo '
938 1001
 											<li><a href="', $scripturl, '?action=moderate;area=postmod;sa=approve;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="generic_icons unapprove_button"></span>', $txt['unapprove'], '</a></li>';
1002
+		}
939 1003
 
940 1004
 		echo '
941 1005
 										</ul>
942 1006
 									</li>';
943 1007
 
944 1008
 		// Show a checkbox for quick moderation?
945
-		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove'])
946
-			echo '
1009
+		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove']) {
1010
+					echo '
947 1011
 									<li style="display: none;" id="in_topic_mod_check_', $message['id'], '"></li>';
1012
+		}
948 1013
 
949
-		if ($message['can_approve'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'])
950
-			echo '
1014
+		if ($message['can_approve'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg']) {
1015
+					echo '
951 1016
 								</ul><!-- .quickbuttons -->';
1017
+		}
952 1018
 	}
953 1019
 
954
-	if ($context['can_report_moderator'] || !empty($modSettings['enable_likes']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote'])
955
-		echo '
1020
+	if ($context['can_report_moderator'] || !empty($modSettings['enable_likes']) || $message['can_approve'] || $message['can_unapprove'] || $context['can_reply'] || $message['can_modify'] || $message['can_remove'] || $context['can_split'] || $context['can_restore_msg'] || $context['can_quote']) {
1021
+			echo '
956 1022
 							</div><!-- .under_message -->';
1023
+	}
957 1024
 
958 1025
 	echo '
959 1026
 						</div><!-- .postarea -->
@@ -966,9 +1033,10 @@  discard block
 block discarded – undo
966 1033
 							<div class="custom_fields_above_signature">
967 1034
 								<ul class="nolist">';
968 1035
 
969
-		foreach ($message['custom_fields']['above_signature'] as $custom)
970
-			echo '
1036
+		foreach ($message['custom_fields']['above_signature'] as $custom) {
1037
+					echo '
971 1038
 									<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
1039
+		}
972 1040
 
973 1041
 		echo '
974 1042
 								</ul>
@@ -976,11 +1044,12 @@  discard block
 block discarded – undo
976 1044
 	}
977 1045
 
978 1046
 	// Show the member's signature?
979
-	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
980
-		echo '
1047
+	if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled']) {
1048
+			echo '
981 1049
 							<div class="signature" id="msg_', $message['id'], '_signature"', $ignoring ? ' style="display:none;"' : '', '>
982 1050
 								', $message['member']['signature'], '
983 1051
 							</div>';
1052
+	}
984 1053
 
985 1054
 
986 1055
 	// Are there any custom profile fields for below the signature?
@@ -990,9 +1059,10 @@  discard block
 block discarded – undo
990 1059
 							<div class="custom_fields_below_signature">
991 1060
 								<ul class="nolist">';
992 1061
 
993
-		foreach ($message['custom_fields']['below_signature'] as $custom)
994
-			echo '
1062
+		foreach ($message['custom_fields']['below_signature'] as $custom) {
1063
+					echo '
995 1064
 									<li class="custom ', $custom['col_name'], '">', $custom['value'], '</li>';
1065
+		}
996 1066
 
997 1067
 		echo '
998 1068
 								</ul>
@@ -1042,8 +1112,8 @@  discard block
 block discarded – undo
1042 1112
 						<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '">';
1043 1113
 
1044 1114
 	// Guests just need more.
1045
-	if ($context['user']['is_guest'])
1046
-		echo '
1115
+	if ($context['user']['is_guest']) {
1116
+			echo '
1047 1117
 						<dl id="post_header">
1048 1118
 							<dt>
1049 1119
 								', $txt['name'], ':
@@ -1058,6 +1128,7 @@  discard block
 block discarded – undo
1058 1128
 								<input type="email" name="email" size="25" value="', $context['email'], '" tabindex="', $context['tabindex']++, '" required>
1059 1129
 							</dd>
1060 1130
 						</dl>';
1131
+	}
1061 1132
 
1062 1133
 	echo '
1063 1134
 						', template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message'), '
@@ -1082,12 +1153,13 @@  discard block
 block discarded – undo
1082 1153
 						</script>';
1083 1154
 
1084 1155
 	// Is visual verification enabled?
1085
-	if ($context['require_verification'])
1086
-		echo '
1156
+	if ($context['require_verification']) {
1157
+			echo '
1087 1158
 						<div class="post_verification">
1088 1159
 							<strong>', $txt['verification'], ':</strong>
1089 1160
 							', template_control_verification($context['visual_verification_id'], 'all'), '
1090 1161
 						</div>';
1162
+	}
1091 1163
 
1092 1164
 	// Finally, the submit buttons.
1093 1165
 	echo '
@@ -1103,8 +1175,8 @@  discard block
 block discarded – undo
1103 1175
 		<br class="clear">';
1104 1176
 
1105 1177
 	// Draft autosave available and the user has it enabled?
1106
-	if (!empty($context['drafts_autosave']))
1107
-		echo '
1178
+	if (!empty($context['drafts_autosave'])) {
1179
+			echo '
1108 1180
 		<script>
1109 1181
 			var oDraftAutoSave = new smf_DraftAutoSave({
1110 1182
 				sSelf: \'oDraftAutoSave\',
@@ -1116,12 +1188,14 @@  discard block
 block discarded – undo
1116 1188
 				iFreq: ', (empty($modSettings['masterAutoSaveDraftsDelay']) ? 60000 : $modSettings['masterAutoSaveDraftsDelay'] * 1000), '
1117 1189
 			});
1118 1190
 		</script>';
1191
+	}
1119 1192
 
1120
-	if ($context['show_spellchecking'])
1121
-		echo '
1193
+	if ($context['show_spellchecking']) {
1194
+			echo '
1122 1195
 		<form action="', $scripturl, '?action=spellcheck" method="post" accept-charset="', $context['character_set'], '" name="spell_form" id="spell_form" target="spellWindow">
1123 1196
 			<input type="hidden" name="spellstring" value="">
1124 1197
 		</form>';
1198
+	}
1125 1199
 
1126 1200
 	echo '
1127 1201
 		<script>
Please login to merge, or discard this patch.