Completed
Push — release-2.1 ( 0c47ec...0c190a )
by Jeremy
19:40 queued 12:01
created
other/upgrade.php 1 patch
Braces   +907 added lines, -664 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
 	die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -107,11 +108,14 @@  discard block
 block discarded – undo
107 108
 	ini_set('default_socket_timeout', 900);
108 109
 }
109 110
 // Clean the upgrade path if this is from the client.
110
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
111
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
111
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
112
+	for ($i = 1;
113
+}
114
+$i < $_SERVER['argc']; $i++)
112 115
 	{
113
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
114
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
116
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
117
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
118
+		}
115 119
 	}
116 120
 
117 121
 // Are we from the client?
@@ -119,16 +123,17 @@  discard block
 block discarded – undo
119 123
 {
120 124
 	$command_line = true;
121 125
 	$disable_security = true;
122
-}
123
-else
126
+} else {
124 127
 	$command_line = false;
128
+}
125 129
 
126 130
 // Load this now just because we can.
127 131
 require_once($upgrade_path . '/Settings.php');
128 132
 
129 133
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
130
-if (isset($language))
134
+if (isset($language)) {
131 135
 	$language = str_ireplace('-utf8', '', $language);
136
+}
132 137
 
133 138
 // Are we logged in?
134 139
 if (isset($upgradeData))
@@ -136,10 +141,12 @@  discard block
 block discarded – undo
136 141
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
137 142
 
138 143
 	// Check for sensible values.
139
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
140
-		$upcontext['user']['started'] = time();
141
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
142
-		$upcontext['user']['updated'] = 0;
144
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
145
+			$upcontext['user']['started'] = time();
146
+	}
147
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
148
+			$upcontext['user']['updated'] = 0;
149
+	}
143 150
 
144 151
 	$upcontext['started'] = $upcontext['user']['started'];
145 152
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 			'db_error_skip' => true,
205 212
 		)
206 213
 	);
207
-	while ($row = $smcFunc['db_fetch_assoc']($request))
208
-		$modSettings[$row['variable']] = $row['value'];
214
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
215
+			$modSettings[$row['variable']] = $row['value'];
216
+	}
209 217
 	$smcFunc['db_free_result']($request);
210 218
 }
211 219
 
@@ -215,14 +223,17 @@  discard block
 block discarded – undo
215 223
 	$modSettings['theme_url'] = 'Themes/default';
216 224
 	$modSettings['images_url'] = 'Themes/default/images';
217 225
 }
218
-if (!isset($settings['default_theme_url']))
226
+if (!isset($settings['default_theme_url'])) {
219 227
 	$settings['default_theme_url'] = $modSettings['theme_url'];
220
-if (!isset($settings['default_theme_dir']))
228
+}
229
+if (!isset($settings['default_theme_dir'])) {
221 230
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
231
+}
222 232
 
223 233
 // This is needed in case someone invokes the upgrader using https when upgrading an http forum
224
-if (httpsOn())
234
+if (httpsOn()) {
225 235
 	$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
236
+}
226 237
 
227 238
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
228 239
 // Default title...
@@ -240,13 +251,15 @@  discard block
 block discarded – undo
240 251
 	$support_js = $upcontext['upgrade_status']['js'];
241 252
 
242 253
 	// Only set this if the upgrader status says so.
243
-	if (empty($is_debug))
244
-		$is_debug = $upcontext['upgrade_status']['debug'];
254
+	if (empty($is_debug)) {
255
+			$is_debug = $upcontext['upgrade_status']['debug'];
256
+	}
245 257
 
246 258
 	// Load the language.
247
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
248
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
249
-}
259
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
260
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
261
+	}
262
+	}
250 263
 // Set the defaults.
251 264
 else
252 265
 {
@@ -264,15 +277,18 @@  discard block
 block discarded – undo
264 277
 }
265 278
 
266 279
 // If this isn't the first stage see whether they are logging in and resuming.
267
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
280
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
268 281
 	checkLogin();
282
+}
269 283
 
270
-if ($command_line)
284
+if ($command_line) {
271 285
 	cmdStep0();
286
+}
272 287
 
273 288
 // Don't error if we're using xml.
274
-if (isset($_GET['xml']))
289
+if (isset($_GET['xml'])) {
275 290
 	$upcontext['return_error'] = true;
291
+}
276 292
 
277 293
 // Loop through all the steps doing each one as required.
278 294
 $upcontext['overall_percent'] = 0;
@@ -293,9 +309,9 @@  discard block
 block discarded – undo
293 309
 		}
294 310
 
295 311
 		// Call the step and if it returns false that means pause!
296
-		if (function_exists($step[2]) && $step[2]() === false)
297
-			break;
298
-		elseif (function_exists($step[2])) {
312
+		if (function_exists($step[2]) && $step[2]() === false) {
313
+					break;
314
+		} elseif (function_exists($step[2])) {
299 315
 			//Start each new step with this unset, so the 'normal' template is called first
300 316
 			unset($_GET['xml']);
301 317
 			//Clear out warnings at the start of each step
@@ -341,17 +357,18 @@  discard block
 block discarded – undo
341 357
 		// This should not happen my dear... HELP ME DEVELOPERS!!
342 358
 		if (!empty($command_line))
343 359
 		{
344
-			if (function_exists('debug_print_backtrace'))
345
-				debug_print_backtrace();
360
+			if (function_exists('debug_print_backtrace')) {
361
+							debug_print_backtrace();
362
+			}
346 363
 
347 364
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
348 365
 			flush();
349 366
 			die();
350 367
 		}
351 368
 
352
-		if (!isset($_GET['xml']))
353
-			template_upgrade_above();
354
-		else
369
+		if (!isset($_GET['xml'])) {
370
+					template_upgrade_above();
371
+		} else
355 372
 		{
356 373
 			header('content-type: text/xml; charset=UTF-8');
357 374
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -373,25 +390,29 @@  discard block
 block discarded – undo
373 390
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
374 391
 
375 392
 			// Custom stuff to pass back?
376
-			if (!empty($upcontext['query_string']))
377
-				$upcontext['form_url'] .= $upcontext['query_string'];
393
+			if (!empty($upcontext['query_string'])) {
394
+							$upcontext['form_url'] .= $upcontext['query_string'];
395
+			}
378 396
 
379 397
 			// Call the appropriate subtemplate
380
-			if (is_callable('template_' . $upcontext['sub_template']))
381
-				call_user_func('template_' . $upcontext['sub_template']);
382
-			else
383
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
398
+			if (is_callable('template_' . $upcontext['sub_template'])) {
399
+							call_user_func('template_' . $upcontext['sub_template']);
400
+			} else {
401
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
402
+			}
384 403
 		}
385 404
 
386 405
 		// Was there an error?
387
-		if (!empty($upcontext['forced_error_message']))
388
-			echo $upcontext['forced_error_message'];
406
+		if (!empty($upcontext['forced_error_message'])) {
407
+					echo $upcontext['forced_error_message'];
408
+		}
389 409
 
390 410
 		// Show the footer.
391
-		if (!isset($_GET['xml']))
392
-			template_upgrade_below();
393
-		else
394
-			template_xml_below();
411
+		if (!isset($_GET['xml'])) {
412
+					template_upgrade_below();
413
+		} else {
414
+					template_xml_below();
415
+		}
395 416
 	}
396 417
 
397 418
 
@@ -403,15 +424,19 @@  discard block
 block discarded – undo
403 424
 		$seconds = intval($active % 60);
404 425
 
405 426
 		$totalTime = '';
406
-		if ($hours > 0)
407
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
408
-		if ($minutes > 0)
409
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
410
-		if ($seconds > 0)
411
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
427
+		if ($hours > 0) {
428
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
429
+		}
430
+		if ($minutes > 0) {
431
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
432
+		}
433
+		if ($seconds > 0) {
434
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
435
+		}
412 436
 
413
-		if (!empty($totalTime))
414
-			echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
437
+		if (!empty($totalTime)) {
438
+					echo "\n" . '', $txt['upgrade_completed_time'], ' ' . $totalTime . "\n";
439
+		}
415 440
 	}
416 441
 
417 442
 	// Bang - gone!
@@ -432,8 +457,9 @@  discard block
 block discarded – undo
432 457
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
433 458
 		while ($entry = $dir->read())
434 459
 		{
435
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
436
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
460
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
461
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
462
+			}
437 463
 		}
438 464
 		$dir->close();
439 465
 	}
@@ -477,10 +503,11 @@  discard block
 block discarded – undo
477 503
 	}
478 504
 
479 505
 	// Override the language file?
480
-	if (isset($_GET['lang_file']))
481
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
482
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
483
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
506
+	if (isset($_GET['lang_file'])) {
507
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
508
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
509
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
510
+	}
484 511
 
485 512
 	// Make sure it exists, if it doesn't reset it.
486 513
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -489,12 +516,14 @@  discard block
 block discarded – undo
489 516
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
490 517
 
491 518
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
492
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
493
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
519
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
520
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
521
+		}
494 522
 
495 523
 		// For backup we load the english at first -> second language overwrite the english one
496
-		if (count($incontext['detected_languages']) > 1)
497
-			require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
524
+		if (count($incontext['detected_languages']) > 1) {
525
+					require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
526
+		}
498 527
 	}
499 528
 
500 529
 	// And now include the actual language file itself.
@@ -502,11 +531,12 @@  discard block
 block discarded – undo
502 531
 
503 532
 	// Which language did we load? Assume that he likes his language.
504 533
 	preg_match('~^Install\.(.+[^-utf8])\.php$~', $_SESSION['installer_temp_lang'], $matches);
505
-	if (empty($matches[1]))
506
-		$matches = [
534
+	if (empty($matches[1])) {
535
+			$matches = [
507 536
 			0 => 'nothing',
508 537
 			1 => 'english',
509 538
 		];
539
+	}
510 540
 	$user_info['language'] = $matches[1];
511 541
 }
512 542
 
@@ -516,8 +546,9 @@  discard block
 block discarded – undo
516 546
 	global $upgradeurl, $upcontext, $command_line;
517 547
 
518 548
 	// Command line users can't be redirected.
519
-	if ($command_line)
520
-		upgradeExit(true);
549
+	if ($command_line) {
550
+			upgradeExit(true);
551
+	}
521 552
 
522 553
 	// Are we providing the core info?
523 554
 	if ($addForm)
@@ -543,12 +574,14 @@  discard block
 block discarded – undo
543 574
 	define('SMF', 1);
544 575
 
545 576
 	// Start the session.
546
-	if (@ini_get('session.save_handler') == 'user')
547
-		@ini_set('session.save_handler', 'files');
577
+	if (@ini_get('session.save_handler') == 'user') {
578
+			@ini_set('session.save_handler', 'files');
579
+	}
548 580
 	@session_start();
549 581
 
550
-	if (empty($smcFunc))
551
-		$smcFunc = array();
582
+	if (empty($smcFunc)) {
583
+			$smcFunc = array();
584
+	}
552 585
 
553 586
 	// We need this for authentication and some upgrade code
554 587
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -575,24 +608,27 @@  discard block
 block discarded – undo
575 608
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
576 609
 
577 610
 		// Make the connection...
578
-		if (empty($db_connection))
579
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
580
-		else
581
-			// If we've returned here, ping/reconnect to be safe
611
+		if (empty($db_connection)) {
612
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
613
+		} else {
614
+					// If we've returned here, ping/reconnect to be safe
582 615
 			$smcFunc['db_ping']($db_connection);
616
+		}
583 617
 
584 618
 		// Oh dear god!!
585
-		if ($db_connection === null)
586
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
619
+		if ($db_connection === null) {
620
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
621
+		}
587 622
 
588
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
589
-			$smcFunc['db_query']('', '
623
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
624
+					$smcFunc['db_query']('', '
590 625
 			SET NAMES {string:db_character_set}',
591 626
 			array(
592 627
 				'db_error_skip' => true,
593 628
 				'db_character_set' => $db_character_set,
594 629
 			)
595 630
 		);
631
+		}
596 632
 
597 633
 		// Load the modSettings data...
598 634
 		$request = $smcFunc['db_query']('', '
@@ -603,11 +639,11 @@  discard block
 block discarded – undo
603 639
 			)
604 640
 		);
605 641
 		$modSettings = array();
606
-		while ($row = $smcFunc['db_fetch_assoc']($request))
607
-			$modSettings[$row['variable']] = $row['value'];
642
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
643
+					$modSettings[$row['variable']] = $row['value'];
644
+		}
608 645
 		$smcFunc['db_free_result']($request);
609
-	}
610
-	else
646
+	} else
611 647
 	{
612 648
 		return throw_error('Cannot find ' . $sourcedir . '/Subs-Db-' . $db_type . '.php' . '. Please check you have uploaded all source files and have the correct paths set.');
613 649
 	}
@@ -621,9 +657,10 @@  discard block
 block discarded – undo
621 657
 		cleanRequest();
622 658
 	}
623 659
 
624
-	if (!isset($_GET['substep']))
625
-		$_GET['substep'] = 0;
626
-}
660
+	if (!isset($_GET['substep'])) {
661
+			$_GET['substep'] = 0;
662
+	}
663
+	}
627 664
 
628 665
 function initialize_inputs()
629 666
 {
@@ -653,8 +690,9 @@  discard block
 block discarded – undo
653 690
 		$dh = opendir(dirname(__FILE__));
654 691
 		while ($file = readdir($dh))
655 692
 		{
656
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
657
-				@unlink(dirname(__FILE__) . '/' . $file);
693
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
694
+							@unlink(dirname(__FILE__) . '/' . $file);
695
+			}
658 696
 		}
659 697
 		closedir($dh);
660 698
 
@@ -683,8 +721,9 @@  discard block
 block discarded – undo
683 721
 	$temp = 'upgrade_php?step';
684 722
 	while (strlen($temp) > 4)
685 723
 	{
686
-		if (isset($_GET[$temp]))
687
-			unset($_GET[$temp]);
724
+		if (isset($_GET[$temp])) {
725
+					unset($_GET[$temp]);
726
+		}
688 727
 		$temp = substr($temp, 1);
689 728
 	}
690 729
 
@@ -711,32 +750,39 @@  discard block
 block discarded – undo
711 750
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
712 751
 
713 752
 	// Need legacy scripts?
714
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
715
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
716
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
717
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
718
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
719
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
753
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
754
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
755
+	}
756
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
757
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
758
+	}
759
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
760
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
761
+	}
720 762
 
721 763
 	// We don't need "-utf8" files anymore...
722 764
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
723 765
 
724 766
 	// This needs to exist!
725
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
726
-		return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
727
-	else
728
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
767
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
768
+			return throw_error('The upgrader could not find the &quot;Install&quot; language file for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
769
+	} else {
770
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
771
+	}
729 772
 
730
-	if (!$check)
731
-		// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
773
+	if (!$check) {
774
+			// Don't tell them what files exactly because it's a spot check - just like teachers don't tell which problems they are spot checking, that's dumb.
732 775
 		return throw_error('The upgrader was unable to find some crucial files.<br><br>Please make sure you uploaded all of the files included in the package, including the Themes, Sources, and other directories.');
776
+	}
733 777
 
734 778
 	// Do they meet the install requirements?
735
-	if (!php_version_check())
736
-		return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
779
+	if (!php_version_check()) {
780
+			return throw_error('Warning!  You do not appear to have a version of PHP installed on your webserver that meets SMF\'s minimum installations requirements.<br><br>Please ask your host to upgrade.');
781
+	}
737 782
 
738
-	if (!db_version_check())
739
-		return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
783
+	if (!db_version_check()) {
784
+			return throw_error('Your ' . $databases[$db_type]['name'] . ' version does not meet the minimum requirements of SMF.<br><br>Please ask your host to upgrade.');
785
+	}
740 786
 
741 787
 	// Do some checks to make sure they have proper privileges
742 788
 	db_extend('packages');
@@ -751,14 +797,16 @@  discard block
 block discarded – undo
751 797
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
752 798
 
753 799
 	// Sorry... we need CREATE, ALTER and DROP
754
-	if (!$create || !$alter || !$drop)
755
-		return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
800
+	if (!$create || !$alter || !$drop) {
801
+			return throw_error('The ' . $databases[$db_type]['name'] . ' user you have set in Settings.php does not have proper privileges.<br><br>Please ask your host to give this user the ALTER, CREATE, and DROP privileges.');
802
+	}
756 803
 
757 804
 	// Do a quick version spot check.
758 805
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
759 806
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
760
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
761
-		return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
807
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
808
+			return throw_error('The upgrader found some old or outdated files.<br><br>Please make certain you uploaded the new versions of all the files included in the package.');
809
+	}
762 810
 
763 811
 	// What absolutely needs to be writable?
764 812
 	$writable_files = array(
@@ -767,12 +815,13 @@  discard block
 block discarded – undo
767 815
 	);
768 816
 
769 817
 	// Only check for minified writable files if we have it enabled or not set.
770
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
771
-		$writable_files += array(
818
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
819
+			$writable_files += array(
772 820
 			$modSettings['theme_dir'] . '/css/minified.css',
773 821
 			$modSettings['theme_dir'] . '/scripts/minified.js',
774 822
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
775 823
 		);
824
+	}
776 825
 
777 826
 	// Do we need to add this setting?
778 827
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -784,12 +833,13 @@  discard block
 block discarded – undo
784 833
 	quickFileWritable($custom_av_dir);
785 834
 
786 835
 	// Are we good now?
787
-	if (!is_writable($custom_av_dir))
788
-		return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
789
-	elseif ($need_settings_update)
836
+	if (!is_writable($custom_av_dir)) {
837
+			return throw_error(sprintf('The directory: %1$s has to be writable to continue the upgrade. Please make sure permissions are correctly set to allow this.', $custom_av_dir));
838
+	} elseif ($need_settings_update)
790 839
 	{
791
-		if (!function_exists('cache_put_data'))
792
-			require_once($sourcedir . '/Load.php');
840
+		if (!function_exists('cache_put_data')) {
841
+					require_once($sourcedir . '/Load.php');
842
+		}
793 843
 
794 844
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
795 845
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
@@ -799,29 +849,34 @@  discard block
 block discarded – undo
799 849
 
800 850
 	// Check the cache directory.
801 851
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
802
-	if (!file_exists($cachedir_temp))
803
-		@mkdir($cachedir_temp);
852
+	if (!file_exists($cachedir_temp)) {
853
+			@mkdir($cachedir_temp);
854
+	}
804 855
 
805
-	if (!file_exists($cachedir_temp))
806
-		return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
856
+	if (!file_exists($cachedir_temp)) {
857
+			return throw_error('The cache directory could not be found.<br><br>Please make sure you have a directory called &quot;cache&quot; in your forum directory before continuing.');
858
+	}
807 859
 
808
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
809
-		return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
810
-	elseif (!isset($_GET['skiplang']))
860
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
861
+			return throw_error('The upgrader was unable to find language files for the language specified in Settings.php.<br>SMF will not work without the primary language files installed.<br><br>Please either install them, or <a href="' . $upgradeurl . '?step=0;lang=english">use english instead</a>.');
862
+	} elseif (!isset($_GET['skiplang']))
811 863
 	{
812 864
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
813 865
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
814 866
 
815
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
816
-			return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
867
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
868
+					return throw_error('The upgrader found some old or outdated language files, for the forum default language, ' . $upcontext['language'] . '.<br><br>Please make certain you uploaded the new versions of all the files included in the package, even the theme and language files for the default theme.<br>&nbsp;&nbsp;&nbsp;[<a href="' . $upgradeurl . '?skiplang">SKIP</a>] [<a href="' . $upgradeurl . '?lang=english">Try English</a>]');
869
+		}
817 870
 	}
818 871
 
819
-	if (!makeFilesWritable($writable_files))
820
-		return false;
872
+	if (!makeFilesWritable($writable_files)) {
873
+			return false;
874
+	}
821 875
 
822 876
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
823
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
824
-		return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
877
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
878
+			return throw_error('The upgrader was unable to obtain write access to agreement.txt.<br><br>If you are using a linux or unix based server, please ensure that the file is chmod\'d to 777, or if it does not exist that the directory this upgrader is in is 777.<br>If your server is running Windows, please ensure that the internet guest account has the proper permissions on it or its folder.');
879
+	}
825 880
 
826 881
 	// Upgrade the agreement.
827 882
 	elseif (isset($modSettings['agreement']))
@@ -832,8 +887,8 @@  discard block
 block discarded – undo
832 887
 	}
833 888
 
834 889
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
835
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
836
-		$upcontext['warning'] = '
890
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
891
+			$upcontext['warning'] = '
837 892
 			'. sprintf($txt['upgrade_boarddir_settings'], $boarddir, dirname(__FILE__)) .'<br>
838 893
 			<ul>
839 894
 				<li>'. $txt['upgrade_boarddir'] .'  ' . $boarddir . '</li>
@@ -841,19 +896,23 @@  discard block
 block discarded – undo
841 896
 				<li>'. $txt['upgrade_cachedir'] .'  ' . $cachedir_temp . '</li>
842 897
 			</ul>
843 898
 			'. $txt['upgrade_incorrect_settings'] .'';
899
+	}
844 900
 
845 901
 	// Confirm mbstring is loaded...
846
-	if (!extension_loaded('mbstring'))
847
-		return throw_error($txt['install_no_mbstring']);
902
+	if (!extension_loaded('mbstring')) {
903
+			return throw_error($txt['install_no_mbstring']);
904
+	}
848 905
 
849 906
 	// Check for https stream support.
850 907
 	$supported_streams = stream_get_wrappers();
851
-	if (!in_array('https', $supported_streams))
852
-		$upcontext['custom_warning'] = $txt['install_no_https'];
908
+	if (!in_array('https', $supported_streams)) {
909
+			$upcontext['custom_warning'] = $txt['install_no_https'];
910
+	}
853 911
 
854 912
 	// Either we're logged in or we're going to present the login.
855
-	if (checkLogin())
856
-		return true;
913
+	if (checkLogin()) {
914
+			return true;
915
+	}
857 916
 
858 917
 	$upcontext += createToken('login');
859 918
 
@@ -867,15 +926,17 @@  discard block
 block discarded – undo
867 926
 	global $smcFunc, $db_type, $support_js;
868 927
 
869 928
 	// Don't bother if the security is disabled.
870
-	if ($disable_security)
871
-		return true;
929
+	if ($disable_security) {
930
+			return true;
931
+	}
872 932
 
873 933
 	// Are we trying to login?
874 934
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
875 935
 	{
876 936
 		// If we've disabled security pick a suitable name!
877
-		if (empty($_POST['user']))
878
-			$_POST['user'] = 'Administrator';
937
+		if (empty($_POST['user'])) {
938
+					$_POST['user'] = 'Administrator';
939
+		}
879 940
 
880 941
 		// Before 2.0 these column names were different!
881 942
 		$oldDB = false;
@@ -890,16 +951,17 @@  discard block
 block discarded – undo
890 951
 					'db_error_skip' => true,
891 952
 				)
892 953
 			);
893
-			if ($smcFunc['db_num_rows']($request) != 0)
894
-				$oldDB = true;
954
+			if ($smcFunc['db_num_rows']($request) != 0) {
955
+							$oldDB = true;
956
+			}
895 957
 			$smcFunc['db_free_result']($request);
896 958
 		}
897 959
 
898 960
 		// Get what we believe to be their details.
899 961
 		if (!$disable_security)
900 962
 		{
901
-			if ($oldDB)
902
-				$request = $smcFunc['db_query']('', '
963
+			if ($oldDB) {
964
+							$request = $smcFunc['db_query']('', '
903 965
 					SELECT id_member, memberName AS member_name, passwd, id_group,
904 966
 					additionalGroups AS additional_groups, lngfile
905 967
 					FROM {db_prefix}members
@@ -909,8 +971,8 @@  discard block
 block discarded – undo
909 971
 						'db_error_skip' => true,
910 972
 					)
911 973
 				);
912
-			else
913
-				$request = $smcFunc['db_query']('', '
974
+			} else {
975
+							$request = $smcFunc['db_query']('', '
914 976
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
915 977
 					FROM {db_prefix}members
916 978
 					WHERE member_name = {string:member_name}',
@@ -919,6 +981,7 @@  discard block
 block discarded – undo
919 981
 						'db_error_skip' => true,
920 982
 					)
921 983
 				);
984
+			}
922 985
 			if ($smcFunc['db_num_rows']($request) != 0)
923 986
 			{
924 987
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -926,16 +989,17 @@  discard block
 block discarded – undo
926 989
 				$groups = explode(',', $addGroups);
927 990
 				$groups[] = $id_group;
928 991
 
929
-				foreach ($groups as $k => $v)
930
-					$groups[$k] = (int) $v;
992
+				foreach ($groups as $k => $v) {
993
+									$groups[$k] = (int) $v;
994
+				}
931 995
 
932 996
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
933 997
 
934 998
 				// We don't use "-utf8" anymore...
935 999
 				$user_language = str_ireplace('-utf8', '', $user_language);
1000
+			} else {
1001
+							$upcontext['username_incorrect'] = true;
936 1002
 			}
937
-			else
938
-				$upcontext['username_incorrect'] = true;
939 1003
 
940 1004
 			$smcFunc['db_free_result']($request);
941 1005
 		}
@@ -946,13 +1010,14 @@  discard block
 block discarded – undo
946 1010
 		{
947 1011
 			$upcontext['upgrade_status']['js'] = 1;
948 1012
 			$support_js = 1;
1013
+		} else {
1014
+					$support_js = 0;
949 1015
 		}
950
-		else
951
-			$support_js = 0;
952 1016
 
953 1017
 		// Note down the version we are coming from.
954
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
955
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
1018
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
1019
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
1020
+		}
956 1021
 
957 1022
 		// Didn't get anywhere?
958 1023
 		if (!$disable_security && (empty($sha_passwd) || (!empty($password) ? $password : '') != $sha_passwd) && !hash_verify_password((!empty($name) ? $name : ''), $_REQUEST['passwrd'], (!empty($password) ? $password : '')) && empty($upcontext['username_incorrect']))
@@ -986,15 +1051,15 @@  discard block
 block discarded – undo
986 1051
 							'db_error_skip' => true,
987 1052
 						)
988 1053
 					);
989
-					if ($smcFunc['db_num_rows']($request) == 0)
990
-						return throw_error('You need to be an admin to perform an upgrade!');
1054
+					if ($smcFunc['db_num_rows']($request) == 0) {
1055
+											return throw_error('You need to be an admin to perform an upgrade!');
1056
+					}
991 1057
 					$smcFunc['db_free_result']($request);
992 1058
 				}
993 1059
 
994 1060
 				$upcontext['user']['id'] = $id_member;
995 1061
 				$upcontext['user']['name'] = $name;
996
-			}
997
-			else
1062
+			} else
998 1063
 			{
999 1064
 				$upcontext['user']['id'] = 1;
1000 1065
 				$upcontext['user']['name'] = 'Administrator';
@@ -1010,11 +1075,11 @@  discard block
 block discarded – undo
1010 1075
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
1011 1076
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
1012 1077
 
1013
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
1014
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1015
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
1016
-					$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1017
-				else
1078
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1079
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been updated to the latest version. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1080
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1081
+									$upcontext['upgrade_options_warning'] = 'The language files for your selected language, ' . $user_language . ', have not been uploaded/updated as the &quot;Install&quot; language file is missing. Upgrade will continue with the forum default, ' . $upcontext['language'] . '.';
1082
+				} else
1018 1083
 				{
1019 1084
 					// Set this as the new language.
1020 1085
 					$upcontext['language'] = $user_language;
@@ -1058,8 +1123,9 @@  discard block
 block discarded – undo
1058 1123
 	unset($member_columns);
1059 1124
 
1060 1125
 	// If we've not submitted then we're done.
1061
-	if (empty($_POST['upcont']))
1062
-		return false;
1126
+	if (empty($_POST['upcont'])) {
1127
+			return false;
1128
+	}
1063 1129
 
1064 1130
 	// Firstly, if they're enabling SM stat collection just do it.
1065 1131
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1079,16 +1145,17 @@  discard block
 block discarded – undo
1079 1145
 				fwrite($fp, $out);
1080 1146
 
1081 1147
 				$return_data = '';
1082
-				while (!feof($fp))
1083
-					$return_data .= fgets($fp, 128);
1148
+				while (!feof($fp)) {
1149
+									$return_data .= fgets($fp, 128);
1150
+				}
1084 1151
 
1085 1152
 				fclose($fp);
1086 1153
 
1087 1154
 				// Get the unique site ID.
1088 1155
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1089 1156
 
1090
-				if (!empty($ID[1]))
1091
-					$smcFunc['db_insert']('replace',
1157
+				if (!empty($ID[1])) {
1158
+									$smcFunc['db_insert']('replace',
1092 1159
 						$db_prefix . 'settings',
1093 1160
 						array('variable' => 'string', 'value' => 'string'),
1094 1161
 						array(
@@ -1097,9 +1164,9 @@  discard block
 block discarded – undo
1097 1164
 						),
1098 1165
 						array('variable')
1099 1166
 					);
1167
+				}
1100 1168
 			}
1101
-		}
1102
-		else
1169
+		} else
1103 1170
 		{
1104 1171
 			$smcFunc['db_insert']('replace',
1105 1172
 				$db_prefix . 'settings',
@@ -1110,8 +1177,8 @@  discard block
 block discarded – undo
1110 1177
 		}
1111 1178
 	}
1112 1179
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1113
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1114
-		$smcFunc['db_query']('', '
1180
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1181
+			$smcFunc['db_query']('', '
1115 1182
 			DELETE FROM {db_prefix}settings
1116 1183
 			WHERE variable = {string:enable_sm_stats}',
1117 1184
 			array(
@@ -1119,6 +1186,7 @@  discard block
 block discarded – undo
1119 1186
 				'db_error_skip' => true,
1120 1187
 			)
1121 1188
 		);
1189
+	}
1122 1190
 
1123 1191
 	// Deleting old karma stuff?
1124 1192
 	if (!empty($_POST['delete_karma']))
@@ -1133,20 +1201,22 @@  discard block
 block discarded – undo
1133 1201
 		);
1134 1202
 
1135 1203
 		// Cleaning up old karma member settings.
1136
-		if ($upcontext['karma_installed']['good'])
1137
-			$smcFunc['db_query']('', '
1204
+		if ($upcontext['karma_installed']['good']) {
1205
+					$smcFunc['db_query']('', '
1138 1206
 				ALTER TABLE {db_prefix}members
1139 1207
 				DROP karma_good',
1140 1208
 				array()
1141 1209
 			);
1210
+		}
1142 1211
 
1143 1212
 		// Does karma bad was enable?
1144
-		if ($upcontext['karma_installed']['bad'])
1145
-			$smcFunc['db_query']('', '
1213
+		if ($upcontext['karma_installed']['bad']) {
1214
+					$smcFunc['db_query']('', '
1146 1215
 				ALTER TABLE {db_prefix}members
1147 1216
 				DROP karma_bad',
1148 1217
 				array()
1149 1218
 			);
1219
+		}
1150 1220
 
1151 1221
 		// Cleaning up old karma permissions.
1152 1222
 		$smcFunc['db_query']('', '
@@ -1164,32 +1234,37 @@  discard block
 block discarded – undo
1164 1234
 	}
1165 1235
 
1166 1236
 	// Emptying the error log?
1167
-	if (!empty($_POST['empty_error']))
1168
-		$smcFunc['db_query']('truncate_table', '
1237
+	if (!empty($_POST['empty_error'])) {
1238
+			$smcFunc['db_query']('truncate_table', '
1169 1239
 			TRUNCATE {db_prefix}log_errors',
1170 1240
 			array(
1171 1241
 			)
1172 1242
 		);
1243
+	}
1173 1244
 
1174 1245
 	$changes = array();
1175 1246
 
1176 1247
 	// Add proxy settings.
1177
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1178
-		$changes += array(
1248
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1249
+			$changes += array(
1179 1250
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1180 1251
 			'image_proxy_maxsize' => 5190,
1181 1252
 			'image_proxy_enabled' => 0,
1182 1253
 		);
1254
+	}
1183 1255
 
1184 1256
 	// If $boardurl reflects https, set force_ssl
1185
-	if (!function_exists('cache_put_data'))
1186
-		require_once($sourcedir . '/Load.php');
1187
-	if (stripos($boardurl, 'https://') !== false)
1188
-		updateSettings(array('force_ssl' => '1'));
1257
+	if (!function_exists('cache_put_data')) {
1258
+			require_once($sourcedir . '/Load.php');
1259
+	}
1260
+	if (stripos($boardurl, 'https://') !== false) {
1261
+			updateSettings(array('force_ssl' => '1'));
1262
+	}
1189 1263
 
1190 1264
 	// If we're overriding the language follow it through.
1191
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1192
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1265
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1266
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1267
+	}
1193 1268
 
1194 1269
 	if (!empty($_POST['maint']))
1195 1270
 	{
@@ -1201,26 +1276,29 @@  discard block
 block discarded – undo
1201 1276
 		{
1202 1277
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1203 1278
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1204
-		}
1205
-		else
1279
+		} else
1206 1280
 		{
1207 1281
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1208 1282
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1209 1283
 		}
1210 1284
 	}
1211 1285
 
1212
-	if ($command_line)
1213
-		echo ' * Updating Settings.php...';
1286
+	if ($command_line) {
1287
+			echo ' * Updating Settings.php...';
1288
+	}
1214 1289
 
1215 1290
 	// Fix some old paths.
1216
-	if (substr($boarddir, 0, 1) == '.')
1217
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1291
+	if (substr($boarddir, 0, 1) == '.') {
1292
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1293
+	}
1218 1294
 
1219
-	if (substr($sourcedir, 0, 1) == '.')
1220
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1295
+	if (substr($sourcedir, 0, 1) == '.') {
1296
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1297
+	}
1221 1298
 
1222
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1223
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1299
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1300
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1301
+	}
1224 1302
 
1225 1303
 	// If they have a "host:port" setup for the host, split that into separate values
1226 1304
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1231,32 +1309,36 @@  discard block
 block discarded – undo
1231 1309
 		$changes['db_server'] = '\'' . $db_server . '\'';
1232 1310
 
1233 1311
 		// Only set this if we're not using the default port
1234
-		if ($db_port != ini_get('mysqli.default_port'))
1235
-			$changes['db_port'] = (int) $db_port;
1236
-	}
1237
-	elseif (!empty($db_port))
1312
+		if ($db_port != ini_get('mysqli.default_port')) {
1313
+					$changes['db_port'] = (int) $db_port;
1314
+		}
1315
+	} elseif (!empty($db_port))
1238 1316
 	{
1239 1317
 		// If db_port is set and is the same as the default, set it to ''
1240 1318
 		if ($db_type == 'mysql')
1241 1319
 		{
1242
-			if ($db_port == ini_get('mysqli.default_port'))
1243
-				$changes['db_port'] = '\'\'';
1244
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1245
-				$changes['db_port'] = '\'\'';
1320
+			if ($db_port == ini_get('mysqli.default_port')) {
1321
+							$changes['db_port'] = '\'\'';
1322
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1323
+							$changes['db_port'] = '\'\'';
1324
+			}
1246 1325
 		}
1247 1326
 	}
1248 1327
 
1249 1328
 	// Maybe we haven't had this option yet?
1250
-	if (empty($packagesdir))
1251
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1329
+	if (empty($packagesdir)) {
1330
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1331
+	}
1252 1332
 
1253 1333
 	// Add support for $tasksdir var.
1254
-	if (empty($tasksdir))
1255
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1334
+	if (empty($tasksdir)) {
1335
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1336
+	}
1256 1337
 
1257 1338
 	// Make sure we fix the language as well.
1258
-	if (stristr($language, '-utf8'))
1259
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1339
+	if (stristr($language, '-utf8')) {
1340
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1341
+	}
1260 1342
 
1261 1343
 	// @todo Maybe change the cookie name if going to 1.1, too?
1262 1344
 
@@ -1267,8 +1349,9 @@  discard block
 block discarded – undo
1267 1349
 	// Tell Settings.php to store db_last_error.php in the cache
1268 1350
 	move_db_last_error_to_cachedir();
1269 1351
 
1270
-	if ($command_line)
1271
-		echo ' Successful.' . "\n";
1352
+	if ($command_line) {
1353
+			echo ' Successful.' . "\n";
1354
+	}
1272 1355
 
1273 1356
 	// Are we doing debug?
1274 1357
 	if (isset($_POST['debug']))
@@ -1278,8 +1361,9 @@  discard block
 block discarded – undo
1278 1361
 	}
1279 1362
 
1280 1363
 	// If we're not backing up then jump one.
1281
-	if (empty($_POST['backup']))
1282
-		$upcontext['current_step']++;
1364
+	if (empty($_POST['backup'])) {
1365
+			$upcontext['current_step']++;
1366
+	}
1283 1367
 
1284 1368
 	// If we've got here then let's proceed to the next step!
1285 1369
 	return true;
@@ -1294,8 +1378,9 @@  discard block
 block discarded – undo
1294 1378
 	$upcontext['page_title'] = $txt['backup_database'];
1295 1379
 
1296 1380
 	// Done it already - js wise?
1297
-	if (!empty($_POST['backup_done']))
1298
-		return true;
1381
+	if (!empty($_POST['backup_done'])) {
1382
+			return true;
1383
+	}
1299 1384
 
1300 1385
 	// Some useful stuff here.
1301 1386
 	db_extend();
@@ -1309,9 +1394,10 @@  discard block
 block discarded – undo
1309 1394
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1310 1395
 
1311 1396
 	$table_names = array();
1312
-	foreach ($tables as $table)
1313
-		if (substr($table, 0, 7) !== 'backup_')
1397
+	foreach ($tables as $table) {
1398
+			if (substr($table, 0, 7) !== 'backup_')
1314 1399
 			$table_names[] = $table;
1400
+	}
1315 1401
 
1316 1402
 	$upcontext['table_count'] = count($table_names);
1317 1403
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1321,12 +1407,14 @@  discard block
 block discarded – undo
1321 1407
 	$file_steps = $upcontext['table_count'];
1322 1408
 
1323 1409
 	// What ones have we already done?
1324
-	foreach ($table_names as $id => $table)
1325
-		if ($id < $_GET['substep'])
1410
+	foreach ($table_names as $id => $table) {
1411
+			if ($id < $_GET['substep'])
1326 1412
 			$upcontext['previous_tables'][] = $table;
1413
+	}
1327 1414
 
1328
-	if ($command_line)
1329
-		echo 'Backing Up Tables.';
1415
+	if ($command_line) {
1416
+			echo 'Backing Up Tables.';
1417
+	}
1330 1418
 
1331 1419
 	// If we don't support javascript we backup here.
1332 1420
 	if (!$support_js || isset($_GET['xml']))
@@ -1345,8 +1433,9 @@  discard block
 block discarded – undo
1345 1433
 			backupTable($table_names[$substep]);
1346 1434
 
1347 1435
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1348
-			if (isset($_GET['xml']))
1349
-				return upgradeExit();
1436
+			if (isset($_GET['xml'])) {
1437
+							return upgradeExit();
1438
+			}
1350 1439
 		}
1351 1440
 
1352 1441
 		if ($command_line)
@@ -1379,9 +1468,10 @@  discard block
 block discarded – undo
1379 1468
 
1380 1469
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1381 1470
 
1382
-	if ($command_line)
1383
-		echo ' done.';
1384
-}
1471
+	if ($command_line) {
1472
+			echo ' done.';
1473
+	}
1474
+	}
1385 1475
 
1386 1476
 // Step 2: Everything.
1387 1477
 function DatabaseChanges()
@@ -1390,8 +1480,9 @@  discard block
 block discarded – undo
1390 1480
 	global $upcontext, $support_js, $db_type;
1391 1481
 
1392 1482
 	// Have we just completed this?
1393
-	if (!empty($_POST['database_done']))
1394
-		return true;
1483
+	if (!empty($_POST['database_done'])) {
1484
+			return true;
1485
+	}
1395 1486
 
1396 1487
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1397 1488
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1406,15 +1497,16 @@  discard block
 block discarded – undo
1406 1497
 	);
1407 1498
 
1408 1499
 	// How many files are there in total?
1409
-	if (isset($_GET['filecount']))
1410
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1411
-	else
1500
+	if (isset($_GET['filecount'])) {
1501
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1502
+	} else
1412 1503
 	{
1413 1504
 		$upcontext['file_count'] = 0;
1414 1505
 		foreach ($files as $file)
1415 1506
 		{
1416
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1417
-				$upcontext['file_count']++;
1507
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1508
+							$upcontext['file_count']++;
1509
+			}
1418 1510
 		}
1419 1511
 	}
1420 1512
 
@@ -1424,9 +1516,9 @@  discard block
 block discarded – undo
1424 1516
 	$upcontext['cur_file_num'] = 0;
1425 1517
 	foreach ($files as $file)
1426 1518
 	{
1427
-		if ($did_not_do)
1428
-			$did_not_do--;
1429
-		else
1519
+		if ($did_not_do) {
1520
+					$did_not_do--;
1521
+		} else
1430 1522
 		{
1431 1523
 			$upcontext['cur_file_num']++;
1432 1524
 			$upcontext['cur_file_name'] = $file[0];
@@ -1453,12 +1545,13 @@  discard block
 block discarded – undo
1453 1545
 					// Flag to move on to the next.
1454 1546
 					$upcontext['completed_step'] = true;
1455 1547
 					// Did we complete the whole file?
1456
-					if ($nextFile)
1457
-						$upcontext['current_debug_item_num'] = -1;
1548
+					if ($nextFile) {
1549
+											$upcontext['current_debug_item_num'] = -1;
1550
+					}
1458 1551
 					return upgradeExit();
1552
+				} elseif ($support_js) {
1553
+									break;
1459 1554
 				}
1460
-				elseif ($support_js)
1461
-					break;
1462 1555
 			}
1463 1556
 			// Set the progress bar to be right as if we had - even if we hadn't...
1464 1557
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1484,8 +1577,9 @@  discard block
 block discarded – undo
1484 1577
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt, $settings;
1485 1578
 
1486 1579
 	// Now it's nice to have some of the basic SMF source files.
1487
-	if (!isset($_GET['ssi']) && !$command_line)
1488
-		redirectLocation('&ssi=1');
1580
+	if (!isset($_GET['ssi']) && !$command_line) {
1581
+			redirectLocation('&ssi=1');
1582
+	}
1489 1583
 
1490 1584
 	$upcontext['sub_template'] = 'upgrade_complete';
1491 1585
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1501,14 +1595,16 @@  discard block
 block discarded – undo
1501 1595
 	// Are we in maintenance mode?
1502 1596
 	if (isset($upcontext['user']['main']))
1503 1597
 	{
1504
-		if ($command_line)
1505
-			echo ' * ';
1598
+		if ($command_line) {
1599
+					echo ' * ';
1600
+		}
1506 1601
 		$upcontext['removed_maintenance'] = true;
1507 1602
 		$changes['maintenance'] = $upcontext['user']['main'];
1508 1603
 	}
1509 1604
 	// Otherwise if somehow we are in 2 let's go to 1.
1510
-	elseif (!empty($maintenance) && $maintenance == 2)
1511
-		$changes['maintenance'] = 1;
1605
+	elseif (!empty($maintenance) && $maintenance == 2) {
1606
+			$changes['maintenance'] = 1;
1607
+	}
1512 1608
 
1513 1609
 	// Wipe this out...
1514 1610
 	$upcontext['user'] = array();
@@ -1523,21 +1619,23 @@  discard block
 block discarded – undo
1523 1619
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1524 1620
 
1525 1621
 	// Now is the perfect time to fetch the SM files.
1526
-	if ($command_line)
1527
-		cli_scheduled_fetchSMfiles();
1528
-	else
1622
+	if ($command_line) {
1623
+			cli_scheduled_fetchSMfiles();
1624
+	} else
1529 1625
 	{
1530 1626
 		require_once($sourcedir . '/ScheduledTasks.php');
1531 1627
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
1532 1628
 		scheduled_fetchSMfiles(); // Now go get those files!
1533 1629
 		// This is needed in case someone invokes the upgrader using https when upgrading an http forum
1534
-		if (httpsOn())
1535
-			$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
1630
+		if (httpsOn()) {
1631
+					$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
1632
+		}
1536 1633
 	}
1537 1634
 
1538 1635
 	// Log what we've done.
1539
-	if (empty($user_info['id']))
1540
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1636
+	if (empty($user_info['id'])) {
1637
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1638
+	}
1541 1639
 
1542 1640
 	// Log the action manually, so CLI still works.
1543 1641
 	$smcFunc['db_insert']('',
@@ -1556,8 +1654,9 @@  discard block
 block discarded – undo
1556 1654
 
1557 1655
 	// Save the current database version.
1558 1656
 	$server_version = $smcFunc['db_server_info']();
1559
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1560
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1657
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1658
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1659
+	}
1561 1660
 
1562 1661
 	if ($command_line)
1563 1662
 	{
@@ -1569,8 +1668,9 @@  discard block
 block discarded – undo
1569 1668
 
1570 1669
 	// Make sure it says we're done.
1571 1670
 	$upcontext['overall_percent'] = 100;
1572
-	if (isset($upcontext['step_progress']))
1573
-		unset($upcontext['step_progress']);
1671
+	if (isset($upcontext['step_progress'])) {
1672
+			unset($upcontext['step_progress']);
1673
+	}
1574 1674
 
1575 1675
 	$_GET['substep'] = 0;
1576 1676
 	return false;
@@ -1581,8 +1681,9 @@  discard block
 block discarded – undo
1581 1681
 {
1582 1682
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1583 1683
 
1584
-	if (empty($modSettings['time_format']))
1585
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1684
+	if (empty($modSettings['time_format'])) {
1685
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1686
+	}
1586 1687
 
1587 1688
 	// What files do we want to get
1588 1689
 	$request = $smcFunc['db_query']('', '
@@ -1616,8 +1717,9 @@  discard block
 block discarded – undo
1616 1717
 		$file_data = fetch_web_data($url);
1617 1718
 
1618 1719
 		// If we got an error - give up - the site might be down.
1619
-		if ($file_data === false)
1620
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1720
+		if ($file_data === false) {
1721
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1722
+		}
1621 1723
 
1622 1724
 		// Save the file to the database.
1623 1725
 		$smcFunc['db_query']('substring', '
@@ -1659,8 +1761,9 @@  discard block
 block discarded – undo
1659 1761
 	$themeData = array();
1660 1762
 	foreach ($values as $variable => $value)
1661 1763
 	{
1662
-		if (!isset($value) || $value === null)
1663
-			$value = 0;
1764
+		if (!isset($value) || $value === null) {
1765
+					$value = 0;
1766
+		}
1664 1767
 
1665 1768
 		$themeData[] = array(0, 1, $variable, $value);
1666 1769
 	}
@@ -1689,8 +1792,9 @@  discard block
 block discarded – undo
1689 1792
 
1690 1793
 	foreach ($values as $variable => $value)
1691 1794
 	{
1692
-		if (empty($modSettings[$value[0]]))
1693
-			continue;
1795
+		if (empty($modSettings[$value[0]])) {
1796
+					continue;
1797
+		}
1694 1798
 
1695 1799
 		$smcFunc['db_query']('', '
1696 1800
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1776,19 +1880,21 @@  discard block
 block discarded – undo
1776 1880
 	set_error_handler(
1777 1881
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1778 1882
 		{
1779
-			if ($support_js)
1780
-				return true;
1781
-			else
1782
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1883
+			if ($support_js) {
1884
+							return true;
1885
+			} else {
1886
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1887
+			}
1783 1888
 		}
1784 1889
 	);
1785 1890
 
1786 1891
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1787 1892
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1788
-	if ($db_type == 'mysql')
1789
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1790
-	else
1791
-		$db_collation = '';
1893
+	if ($db_type == 'mysql') {
1894
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1895
+	} else {
1896
+			$db_collation = '';
1897
+	}
1792 1898
 
1793 1899
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1794 1900
 
@@ -1800,8 +1906,9 @@  discard block
 block discarded – undo
1800 1906
 	$last_step = '';
1801 1907
 
1802 1908
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1803
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1804
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1909
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1910
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1911
+	}
1805 1912
 
1806 1913
 	// Count the total number of steps within this file - for progress.
1807 1914
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1821,15 +1928,18 @@  discard block
 block discarded – undo
1821 1928
 		$do_current = $substep >= $_GET['substep'];
1822 1929
 
1823 1930
 		// Get rid of any comments in the beginning of the line...
1824
-		if (substr(trim($line), 0, 2) === '/*')
1825
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1931
+		if (substr(trim($line), 0, 2) === '/*') {
1932
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1933
+		}
1826 1934
 
1827 1935
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1828
-		if ($is_debug && !$support_js && $command_line)
1829
-			flush();
1936
+		if ($is_debug && !$support_js && $command_line) {
1937
+					flush();
1938
+		}
1830 1939
 
1831
-		if (trim($line) === '')
1832
-			continue;
1940
+		if (trim($line) === '') {
1941
+					continue;
1942
+		}
1833 1943
 
1834 1944
 		if (trim(substr($line, 0, 3)) === '---')
1835 1945
 		{
@@ -1839,8 +1949,9 @@  discard block
 block discarded – undo
1839 1949
 			if (trim($current_data) != '' && $type !== '}')
1840 1950
 			{
1841 1951
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1842
-				if ($command_line)
1843
-					echo $upcontext['error_message'];
1952
+				if ($command_line) {
1953
+									echo $upcontext['error_message'];
1954
+				}
1844 1955
 			}
1845 1956
 
1846 1957
 			if ($type == ' ')
@@ -1858,17 +1969,18 @@  discard block
 block discarded – undo
1858 1969
 				if ($do_current)
1859 1970
 				{
1860 1971
 					$upcontext['actioned_items'][] = $last_step;
1861
-					if ($command_line)
1862
-						echo ' * ';
1972
+					if ($command_line) {
1973
+											echo ' * ';
1974
+					}
1863 1975
 				}
1864
-			}
1865
-			elseif ($type == '#')
1976
+			} elseif ($type == '#')
1866 1977
 			{
1867 1978
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1868 1979
 
1869 1980
 				$upcontext['current_debug_item_num']++;
1870
-				if (trim($line) != '---#')
1871
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1981
+				if (trim($line) != '---#') {
1982
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1983
+				}
1872 1984
 
1873 1985
 				// Have we already done something?
1874 1986
 				if (isset($_GET['xml']) && $done_something)
@@ -1879,34 +1991,36 @@  discard block
 block discarded – undo
1879 1991
 
1880 1992
 				if ($do_current)
1881 1993
 				{
1882
-					if (trim($line) == '---#' && $command_line)
1883
-						echo ' done.', $endl;
1884
-					elseif ($command_line)
1885
-						echo ' +++ ', rtrim(substr($line, 4));
1886
-					elseif (trim($line) != '---#')
1994
+					if (trim($line) == '---#' && $command_line) {
1995
+											echo ' done.', $endl;
1996
+					} elseif ($command_line) {
1997
+											echo ' +++ ', rtrim(substr($line, 4));
1998
+					} elseif (trim($line) != '---#')
1887 1999
 					{
1888
-						if ($is_debug)
1889
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2000
+						if ($is_debug) {
2001
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2002
+						}
1890 2003
 					}
1891 2004
 				}
1892 2005
 
1893 2006
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1894 2007
 				{
1895
-					if ($command_line)
1896
-						echo ' * ';
1897
-					else
1898
-						$upcontext['actioned_items'][] = $last_step;
2008
+					if ($command_line) {
2009
+											echo ' * ';
2010
+					} else {
2011
+											$upcontext['actioned_items'][] = $last_step;
2012
+					}
1899 2013
 				}
1900 2014
 
1901 2015
 				// Small step - only if we're actually doing stuff.
1902
-				if ($do_current)
1903
-					nextSubstep(++$substep);
1904
-				else
1905
-					$substep++;
1906
-			}
1907
-			elseif ($type == '{')
1908
-				$current_type = 'code';
1909
-			elseif ($type == '}')
2016
+				if ($do_current) {
2017
+									nextSubstep(++$substep);
2018
+				} else {
2019
+									$substep++;
2020
+				}
2021
+			} elseif ($type == '{') {
2022
+							$current_type = 'code';
2023
+			} elseif ($type == '}')
1910 2024
 			{
1911 2025
 				$current_type = 'sql';
1912 2026
 
@@ -1919,8 +2033,9 @@  discard block
 block discarded – undo
1919 2033
 				if (eval('global $db_prefix, $modSettings, $smcFunc, $txt; ' . $current_data) === false)
1920 2034
 				{
1921 2035
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1922
-					if ($command_line)
1923
-						echo $upcontext['error_message'];
2036
+					if ($command_line) {
2037
+											echo $upcontext['error_message'];
2038
+					}
1924 2039
 				}
1925 2040
 
1926 2041
 				// Done with code!
@@ -2008,8 +2123,9 @@  discard block
 block discarded – undo
2008 2123
 	$db_unbuffered = false;
2009 2124
 
2010 2125
 	// Failure?!
2011
-	if ($result !== false)
2012
-		return $result;
2126
+	if ($result !== false) {
2127
+			return $result;
2128
+	}
2013 2129
 
2014 2130
 	$db_error_message = $smcFunc['db_error']($db_connection);
2015 2131
 	// If MySQL we do something more clever.
@@ -2037,54 +2153,61 @@  discard block
 block discarded – undo
2037 2153
 			{
2038 2154
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2039 2155
 				$result = mysqli_query($db_connection, $string);
2040
-				if ($result !== false)
2041
-					return $result;
2156
+				if ($result !== false) {
2157
+									return $result;
2158
+				}
2042 2159
 			}
2043
-		}
2044
-		elseif ($mysqli_errno == 2013)
2160
+		} elseif ($mysqli_errno == 2013)
2045 2161
 		{
2046 2162
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2047 2163
 			mysqli_select_db($db_connection, $db_name);
2048 2164
 			if ($db_connection)
2049 2165
 			{
2050 2166
 				$result = mysqli_query($db_connection, $string);
2051
-				if ($result !== false)
2052
-					return $result;
2167
+				if ($result !== false) {
2168
+									return $result;
2169
+				}
2053 2170
 			}
2054 2171
 		}
2055 2172
 		// Duplicate column name... should be okay ;).
2056
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2057
-			return false;
2173
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2174
+					return false;
2175
+		}
2058 2176
 		// Duplicate insert... make sure it's the proper type of query ;).
2059
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2060
-			return false;
2177
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2178
+					return false;
2179
+		}
2061 2180
 		// Creating an index on a non-existent column.
2062
-		elseif ($mysqli_errno == 1072)
2063
-			return false;
2064
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2065
-			return false;
2181
+		elseif ($mysqli_errno == 1072) {
2182
+					return false;
2183
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2184
+					return false;
2185
+		}
2066 2186
 	}
2067 2187
 	// If a table already exists don't go potty.
2068 2188
 	else
2069 2189
 	{
2070 2190
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2071 2191
 		{
2072
-			if (strpos($db_error_message, 'exist') !== false)
2073
-				return true;
2074
-		}
2075
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2192
+			if (strpos($db_error_message, 'exist') !== false) {
2193
+							return true;
2194
+			}
2195
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2076 2196
 		{
2077
-			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error)
2078
-				return true;
2197
+			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) {
2198
+							return true;
2199
+			}
2079 2200
 		}
2080 2201
 	}
2081 2202
 
2082 2203
 	// Get the query string so we pass everything.
2083 2204
 	$query_string = '';
2084
-	foreach ($_GET as $k => $v)
2085
-		$query_string .= ';' . $k . '=' . $v;
2086
-	if (strlen($query_string) != 0)
2087
-		$query_string = '?' . substr($query_string, 1);
2205
+	foreach ($_GET as $k => $v) {
2206
+			$query_string .= ';' . $k . '=' . $v;
2207
+	}
2208
+	if (strlen($query_string) != 0) {
2209
+			$query_string = '?' . substr($query_string, 1);
2210
+	}
2088 2211
 
2089 2212
 	if ($command_line)
2090 2213
 	{
@@ -2139,16 +2262,18 @@  discard block
 block discarded – undo
2139 2262
 			{
2140 2263
 				$found |= 1;
2141 2264
 				// Do some checks on the data if we have it set.
2142
-				if (isset($change['col_type']))
2143
-					$found &= $change['col_type'] === $column['type'];
2144
-				if (isset($change['null_allowed']))
2145
-					$found &= $column['null'] == $change['null_allowed'];
2146
-				if (isset($change['default']))
2147
-					$found &= $change['default'] === $column['default'];
2265
+				if (isset($change['col_type'])) {
2266
+									$found &= $change['col_type'] === $column['type'];
2267
+				}
2268
+				if (isset($change['null_allowed'])) {
2269
+									$found &= $column['null'] == $change['null_allowed'];
2270
+				}
2271
+				if (isset($change['default'])) {
2272
+									$found &= $change['default'] === $column['default'];
2273
+				}
2148 2274
 			}
2149 2275
 		}
2150
-	}
2151
-	elseif ($change['type'] === 'index')
2276
+	} elseif ($change['type'] === 'index')
2152 2277
 	{
2153 2278
 		$request = upgrade_query('
2154 2279
 			SHOW INDEX
@@ -2157,9 +2282,10 @@  discard block
 block discarded – undo
2157 2282
 		{
2158 2283
 			$cur_index = array();
2159 2284
 
2160
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2161
-				if ($row['Key_name'] === $change['name'])
2285
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2286
+							if ($row['Key_name'] === $change['name'])
2162 2287
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2288
+			}
2163 2289
 
2164 2290
 			ksort($cur_index, SORT_NUMERIC);
2165 2291
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2169,14 +2295,17 @@  discard block
 block discarded – undo
2169 2295
 	}
2170 2296
 
2171 2297
 	// If we're trying to add and it's added, we're done.
2172
-	if ($found && in_array($change['method'], array('add', 'change')))
2173
-		return true;
2298
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2299
+			return true;
2300
+	}
2174 2301
 	// Otherwise if we're removing and it wasn't found we're also done.
2175
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2176
-		return true;
2302
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2303
+			return true;
2304
+	}
2177 2305
 	// Otherwise is it just a test?
2178
-	elseif ($is_test)
2179
-		return false;
2306
+	elseif ($is_test) {
2307
+			return false;
2308
+	}
2180 2309
 
2181 2310
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2182 2311
 	$running = false;
@@ -2187,8 +2316,9 @@  discard block
 block discarded – undo
2187 2316
 			SHOW FULL PROCESSLIST');
2188 2317
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2189 2318
 		{
2190
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2191
-				$found = true;
2319
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2320
+							$found = true;
2321
+			}
2192 2322
 		}
2193 2323
 
2194 2324
 		// Can't find it? Then we need to run it fools!
@@ -2200,8 +2330,9 @@  discard block
 block discarded – undo
2200 2330
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2201 2331
 				' . $change['text'], true) !== false;
2202 2332
 
2203
-			if (!$success)
2204
-				return false;
2333
+			if (!$success) {
2334
+							return false;
2335
+			}
2205 2336
 
2206 2337
 			// Return
2207 2338
 			$running = true;
@@ -2243,8 +2374,9 @@  discard block
 block discarded – undo
2243 2374
 			'db_error_skip' => true,
2244 2375
 		)
2245 2376
 	);
2246
-	if ($smcFunc['db_num_rows']($request) === 0)
2247
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2377
+	if ($smcFunc['db_num_rows']($request) === 0) {
2378
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2379
+	}
2248 2380
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2249 2381
 	$smcFunc['db_free_result']($request);
2250 2382
 
@@ -2266,18 +2398,19 @@  discard block
 block discarded – undo
2266 2398
 			)
2267 2399
 		);
2268 2400
 		// No results? Just forget it all together.
2269
-		if ($smcFunc['db_num_rows']($request) === 0)
2270
-			unset($table_row['Collation']);
2271
-		else
2272
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2401
+		if ($smcFunc['db_num_rows']($request) === 0) {
2402
+					unset($table_row['Collation']);
2403
+		} else {
2404
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2405
+		}
2273 2406
 		$smcFunc['db_free_result']($request);
2274 2407
 	}
2275 2408
 
2276 2409
 	if ($column_fix)
2277 2410
 	{
2278 2411
 		// Make sure there are no NULL's left.
2279
-		if ($null_fix)
2280
-			$smcFunc['db_query']('', '
2412
+		if ($null_fix) {
2413
+					$smcFunc['db_query']('', '
2281 2414
 				UPDATE {db_prefix}' . $change['table'] . '
2282 2415
 				SET ' . $change['column'] . ' = {string:default}
2283 2416
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2286,6 +2419,7 @@  discard block
 block discarded – undo
2286 2419
 					'db_error_skip' => true,
2287 2420
 				)
2288 2421
 			);
2422
+		}
2289 2423
 
2290 2424
 		// Do the actual alteration.
2291 2425
 		$smcFunc['db_query']('', '
@@ -2314,8 +2448,9 @@  discard block
 block discarded – undo
2314 2448
 	}
2315 2449
 
2316 2450
 	// Not a column we need to check on?
2317
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2318
-		return;
2451
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2452
+			return;
2453
+	}
2319 2454
 
2320 2455
 	// Break it up you (six|seven).
2321 2456
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2334,13 +2469,13 @@  discard block
 block discarded – undo
2334 2469
 				'new_name' => $temp[2],
2335 2470
 		));
2336 2471
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2337
-		if ($smcFunc['db_num_rows'] != 1)
2338
-			return;
2472
+		if ($smcFunc['db_num_rows'] != 1) {
2473
+					return;
2474
+		}
2339 2475
 
2340 2476
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2341 2477
 		$smcFunc['db_free_result']($request);
2342
-	}
2343
-	else
2478
+	} else
2344 2479
 	{
2345 2480
 		// Do this the old fashion, sure method way.
2346 2481
 		$request = $smcFunc['db_query']('', '
@@ -2351,21 +2486,24 @@  discard block
 block discarded – undo
2351 2486
 		));
2352 2487
 		// Mayday!
2353 2488
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2354
-		if ($smcFunc['db_num_rows'] == 0)
2355
-			return;
2489
+		if ($smcFunc['db_num_rows'] == 0) {
2490
+					return;
2491
+		}
2356 2492
 
2357 2493
 		// Oh where, oh where has my little field gone. Oh where can it be...
2358
-		while ($row = $smcFunc['db_query']($request))
2359
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2494
+		while ($row = $smcFunc['db_query']($request)) {
2495
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2360 2496
 			{
2361 2497
 				$current_type = $row['Type'];
2498
+		}
2362 2499
 				break;
2363 2500
 			}
2364 2501
 	}
2365 2502
 
2366 2503
 	// If this doesn't match, the column may of been altered for a reason.
2367
-	if (trim($current_type) != trim($temp[3]))
2368
-		$temp[3] = $current_type;
2504
+	if (trim($current_type) != trim($temp[3])) {
2505
+			$temp[3] = $current_type;
2506
+	}
2369 2507
 
2370 2508
 	// Piece this back together.
2371 2509
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2377,8 +2515,9 @@  discard block
 block discarded – undo
2377 2515
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2378 2516
 	global $step_progress, $is_debug, $upcontext;
2379 2517
 
2380
-	if ($_GET['substep'] < $substep)
2381
-		$_GET['substep'] = $substep;
2518
+	if ($_GET['substep'] < $substep) {
2519
+			$_GET['substep'] = $substep;
2520
+	}
2382 2521
 
2383 2522
 	if ($command_line)
2384 2523
 	{
@@ -2391,29 +2530,33 @@  discard block
 block discarded – undo
2391 2530
 	}
2392 2531
 
2393 2532
 	@set_time_limit(300);
2394
-	if (function_exists('apache_reset_timeout'))
2395
-		@apache_reset_timeout();
2533
+	if (function_exists('apache_reset_timeout')) {
2534
+			@apache_reset_timeout();
2535
+	}
2396 2536
 
2397
-	if (time() - $start_time <= $timeLimitThreshold)
2398
-		return;
2537
+	if (time() - $start_time <= $timeLimitThreshold) {
2538
+			return;
2539
+	}
2399 2540
 
2400 2541
 	// Do we have some custom step progress stuff?
2401 2542
 	if (!empty($step_progress))
2402 2543
 	{
2403 2544
 		$upcontext['substep_progress'] = 0;
2404 2545
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2405
-		if ($step_progress['current'] > $step_progress['total'])
2406
-			$upcontext['substep_progress'] = 99.9;
2407
-		else
2408
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2546
+		if ($step_progress['current'] > $step_progress['total']) {
2547
+					$upcontext['substep_progress'] = 99.9;
2548
+		} else {
2549
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2550
+		}
2409 2551
 
2410 2552
 		// Make it nicely rounded.
2411 2553
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2412 2554
 	}
2413 2555
 
2414 2556
 	// If this is XML we just exit right away!
2415
-	if (isset($_GET['xml']))
2416
-		return upgradeExit();
2557
+	if (isset($_GET['xml'])) {
2558
+			return upgradeExit();
2559
+	}
2417 2560
 
2418 2561
 	// We're going to pause after this!
2419 2562
 	$upcontext['pause'] = true;
@@ -2421,13 +2564,15 @@  discard block
 block discarded – undo
2421 2564
 	$upcontext['query_string'] = '';
2422 2565
 	foreach ($_GET as $k => $v)
2423 2566
 	{
2424
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2425
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2567
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2568
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2569
+		}
2426 2570
 	}
2427 2571
 
2428 2572
 	// Custom warning?
2429
-	if (!empty($custom_warning))
2430
-		$upcontext['custom_warning'] = $custom_warning;
2573
+	if (!empty($custom_warning)) {
2574
+			$upcontext['custom_warning'] = $custom_warning;
2575
+	}
2431 2576
 
2432 2577
 	upgradeExit();
2433 2578
 }
@@ -2442,25 +2587,26 @@  discard block
 block discarded – undo
2442 2587
 	ob_implicit_flush(true);
2443 2588
 	@set_time_limit(600);
2444 2589
 
2445
-	if (!isset($_SERVER['argv']))
2446
-		$_SERVER['argv'] = array();
2590
+	if (!isset($_SERVER['argv'])) {
2591
+			$_SERVER['argv'] = array();
2592
+	}
2447 2593
 	$_GET['maint'] = 1;
2448 2594
 
2449 2595
 	foreach ($_SERVER['argv'] as $i => $arg)
2450 2596
 	{
2451
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2452
-			$_GET['lang'] = $match[1];
2453
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2454
-			continue;
2455
-		elseif ($arg == '--no-maintenance')
2456
-			$_GET['maint'] = 0;
2457
-		elseif ($arg == '--debug')
2458
-			$is_debug = true;
2459
-		elseif ($arg == '--backup')
2460
-			$_POST['backup'] = 1;
2461
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2462
-			$_GET['conv'] = 1;
2463
-		elseif ($i != 0)
2597
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2598
+					$_GET['lang'] = $match[1];
2599
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2600
+					continue;
2601
+		} elseif ($arg == '--no-maintenance') {
2602
+					$_GET['maint'] = 0;
2603
+		} elseif ($arg == '--debug') {
2604
+					$is_debug = true;
2605
+		} elseif ($arg == '--backup') {
2606
+					$_POST['backup'] = 1;
2607
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2608
+					$_GET['conv'] = 1;
2609
+		} elseif ($i != 0)
2464 2610
 		{
2465 2611
 			echo 'SMF Command-line Upgrader
2466 2612
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2474,10 +2620,12 @@  discard block
 block discarded – undo
2474 2620
 		}
2475 2621
 	}
2476 2622
 
2477
-	if (!php_version_check())
2478
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2479
-	if (!db_version_check())
2480
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2623
+	if (!php_version_check()) {
2624
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2625
+	}
2626
+	if (!db_version_check()) {
2627
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2628
+	}
2481 2629
 
2482 2630
 	// Do some checks to make sure they have proper privileges
2483 2631
 	db_extend('packages');
@@ -2492,34 +2640,39 @@  discard block
 block discarded – undo
2492 2640
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2493 2641
 
2494 2642
 	// Sorry... we need CREATE, ALTER and DROP
2495
-	if (!$create || !$alter || !$drop)
2496
-		print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2643
+	if (!$create || !$alter || !$drop) {
2644
+			print_error("The " . $databases[$db_type]['name'] . " user you have set in Settings.php does not have proper privileges.\n\nPlease ask your host to give this user the ALTER, CREATE, and DROP privileges.", true);
2645
+	}
2497 2646
 
2498 2647
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2499 2648
 		&& @file_exists($sourcedir . '/QueryString.php')
2500 2649
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2501
-	if (!$check && !isset($modSettings['smfVersion']))
2502
-		print_error('Error: Some files are missing or out-of-date.', true);
2650
+	if (!$check && !isset($modSettings['smfVersion'])) {
2651
+			print_error('Error: Some files are missing or out-of-date.', true);
2652
+	}
2503 2653
 
2504 2654
 	// Do a quick version spot check.
2505 2655
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2506 2656
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2507
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2508
-		print_error('Error: Some files have not yet been updated properly.');
2657
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2658
+			print_error('Error: Some files have not yet been updated properly.');
2659
+	}
2509 2660
 
2510 2661
 	// Make sure Settings.php is writable.
2511 2662
 	quickFileWritable($boarddir . '/Settings.php');
2512
-	if (!is_writable($boarddir . '/Settings.php'))
2513
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2663
+	if (!is_writable($boarddir . '/Settings.php')) {
2664
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2665
+	}
2514 2666
 
2515 2667
 	// Make sure Settings_bak.php is writable.
2516 2668
 	quickFileWritable($boarddir . '/Settings_bak.php');
2517
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2518
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2669
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2670
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2671
+	}
2519 2672
 
2520
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2521
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2522
-	elseif (isset($modSettings['agreement']))
2673
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2674
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2675
+	} elseif (isset($modSettings['agreement']))
2523 2676
 	{
2524 2677
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2525 2678
 		fwrite($fp, $modSettings['agreement']);
@@ -2529,36 +2682,42 @@  discard block
 block discarded – undo
2529 2682
 	// Make sure Themes is writable.
2530 2683
 	quickFileWritable($modSettings['theme_dir']);
2531 2684
 
2532
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2533
-		print_error('Error: Unable to obtain write access to "Themes".');
2685
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2686
+			print_error('Error: Unable to obtain write access to "Themes".');
2687
+	}
2534 2688
 
2535 2689
 	// Make sure cache directory exists and is writable!
2536 2690
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2537
-	if (!file_exists($cachedir_temp))
2538
-		@mkdir($cachedir_temp);
2691
+	if (!file_exists($cachedir_temp)) {
2692
+			@mkdir($cachedir_temp);
2693
+	}
2539 2694
 
2540 2695
 	// Make sure the cache temp dir is writable.
2541 2696
 	quickFileWritable($cachedir_temp);
2542 2697
 
2543
-	if (!is_writable($cachedir_temp))
2544
-		print_error('Error: Unable to obtain write access to "cache".', true);
2698
+	if (!is_writable($cachedir_temp)) {
2699
+			print_error('Error: Unable to obtain write access to "cache".', true);
2700
+	}
2545 2701
 
2546 2702
 	// Make sure db_last_error.php is writable.
2547 2703
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2548
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2549
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2704
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2705
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2706
+	}
2550 2707
 
2551
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2552
-		print_error('Error: Unable to find language files!', true);
2553
-	else
2708
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2709
+			print_error('Error: Unable to find language files!', true);
2710
+	} else
2554 2711
 	{
2555 2712
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2556 2713
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2557 2714
 
2558
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2559
-			print_error('Error: Language files out of date.', true);
2560
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2561
-			print_error('Error: Install language is missing for selected language.', true);
2715
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2716
+					print_error('Error: Language files out of date.', true);
2717
+		}
2718
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2719
+					print_error('Error: Install language is missing for selected language.', true);
2720
+		}
2562 2721
 
2563 2722
 		// Otherwise include it!
2564 2723
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2578,8 +2737,9 @@  discard block
 block discarded – undo
2578 2737
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2579 2738
 
2580 2739
 	// Done it already?
2581
-	if (!empty($_POST['utf8_done']))
2582
-		return true;
2740
+	if (!empty($_POST['utf8_done'])) {
2741
+			return true;
2742
+	}
2583 2743
 
2584 2744
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2585 2745
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2592,8 +2752,7 @@  discard block
 block discarded – undo
2592 2752
 		);
2593 2753
 
2594 2754
 		return true;
2595
-	}
2596
-	else
2755
+	} else
2597 2756
 	{
2598 2757
 		$upcontext['page_title'] = $txt['converting_utf8'];
2599 2758
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2637,8 +2796,9 @@  discard block
 block discarded – undo
2637 2796
 			)
2638 2797
 		);
2639 2798
 		$db_charsets = array();
2640
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2641
-			$db_charsets[] = $row['Charset'];
2799
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2800
+					$db_charsets[] = $row['Charset'];
2801
+		}
2642 2802
 
2643 2803
 		$smcFunc['db_free_result']($request);
2644 2804
 
@@ -2674,13 +2834,15 @@  discard block
 block discarded – undo
2674 2834
 		// If there's a fulltext index, we need to drop it first...
2675 2835
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2676 2836
 		{
2677
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2678
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2837
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2838
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2679 2839
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2840
+			}
2680 2841
 			$smcFunc['db_free_result']($request);
2681 2842
 
2682
-			if (isset($upcontext['fulltext_index']))
2683
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2843
+			if (isset($upcontext['fulltext_index'])) {
2844
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2845
+			}
2684 2846
 		}
2685 2847
 
2686 2848
 		// Drop it and make a note...
@@ -2870,8 +3032,9 @@  discard block
 block discarded – undo
2870 3032
 			$replace = '%field%';
2871 3033
 
2872 3034
 			// Build a huge REPLACE statement...
2873
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2874
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3035
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3036
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3037
+			}
2875 3038
 		}
2876 3039
 
2877 3040
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2881,9 +3044,10 @@  discard block
 block discarded – undo
2881 3044
 		$upcontext['table_count'] = count($queryTables);
2882 3045
 
2883 3046
 		// What ones have we already done?
2884
-		foreach ($queryTables as $id => $table)
2885
-			if ($id < $_GET['substep'])
3047
+		foreach ($queryTables as $id => $table) {
3048
+					if ($id < $_GET['substep'])
2886 3049
 				$upcontext['previous_tables'][] = $table;
3050
+		}
2887 3051
 
2888 3052
 		$upcontext['cur_table_num'] = $_GET['substep'];
2889 3053
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2920,8 +3084,9 @@  discard block
 block discarded – undo
2920 3084
 			nextSubstep($substep);
2921 3085
 
2922 3086
 			// Just to make sure it doesn't time out.
2923
-			if (function_exists('apache_reset_timeout'))
2924
-				@apache_reset_timeout();
3087
+			if (function_exists('apache_reset_timeout')) {
3088
+							@apache_reset_timeout();
3089
+			}
2925 3090
 
2926 3091
 			$table_charsets = array();
2927 3092
 
@@ -2944,8 +3109,9 @@  discard block
 block discarded – undo
2944 3109
 
2945 3110
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2946 3111
 						if ($charset != 'utf8') {
2947
-							if (!isset($table_charsets[$charset]))
2948
-								$table_charsets[$charset] = array();
3112
+							if (!isset($table_charsets[$charset])) {
3113
+															$table_charsets[$charset] = array();
3114
+							}
2949 3115
 
2950 3116
 							$table_charsets[$charset][] = $column_info;
2951 3117
 						}
@@ -2986,10 +3152,11 @@  discard block
 block discarded – undo
2986 3152
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2987 3153
 				{
2988 3154
 					$update = '';
2989
-					foreach ($table_charsets as $charset => $columns)
2990
-						foreach ($columns as $column)
3155
+					foreach ($table_charsets as $charset => $columns) {
3156
+											foreach ($columns as $column)
2991 3157
 							$update .= '
2992 3158
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3159
+					}
2993 3160
 
2994 3161
 					$smcFunc['db_query']('', '
2995 3162
 						UPDATE {raw:table_name}
@@ -3014,8 +3181,9 @@  discard block
 block discarded – undo
3014 3181
 			// Now do the actual conversion (if still needed).
3015 3182
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
3016 3183
 			{
3017
-				if ($command_line)
3018
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3184
+				if ($command_line) {
3185
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3186
+				}
3019 3187
 
3020 3188
 				$smcFunc['db_query']('', '
3021 3189
 					ALTER TABLE {raw:table_name}
@@ -3025,12 +3193,14 @@  discard block
 block discarded – undo
3025 3193
 					)
3026 3194
 				);
3027 3195
 
3028
-				if ($command_line)
3029
-					echo " done.\n";
3196
+				if ($command_line) {
3197
+									echo " done.\n";
3198
+				}
3030 3199
 			}
3031 3200
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3032
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
3033
-				return upgradeExit();
3201
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3202
+							return upgradeExit();
3203
+			}
3034 3204
 		}
3035 3205
 
3036 3206
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3059,8 +3229,8 @@  discard block
 block discarded – undo
3059 3229
 		);
3060 3230
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3061 3231
 		{
3062
-			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1)
3063
-				$smcFunc['db_query']('', '
3232
+			if (@safe_unserialize($row['extra']) === false && preg_match('~^(a:3:{s:5:"topic";i:\d+;s:7:"subject";s:)(\d+):"(.+)"(;s:6:"member";s:5:"\d+";})$~', $row['extra'], $matches) === 1) {
3233
+							$smcFunc['db_query']('', '
3064 3234
 					UPDATE {db_prefix}log_actions
3065 3235
 					SET extra = {string:extra}
3066 3236
 					WHERE id_action = {int:current_action}',
@@ -3069,6 +3239,7 @@  discard block
 block discarded – undo
3069 3239
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3070 3240
 					)
3071 3241
 				);
3242
+			}
3072 3243
 		}
3073 3244
 		$smcFunc['db_free_result']($request);
3074 3245
 
@@ -3090,15 +3261,17 @@  discard block
 block discarded – undo
3090 3261
 	// First thing's first - did we already do this?
3091 3262
 	if (!empty($modSettings['json_done']))
3092 3263
 	{
3093
-		if ($command_line)
3094
-			return DeleteUpgrade();
3095
-		else
3096
-			return true;
3264
+		if ($command_line) {
3265
+					return DeleteUpgrade();
3266
+		} else {
3267
+					return true;
3268
+		}
3097 3269
 	}
3098 3270
 
3099 3271
 	// Done it already - js wise?
3100
-	if (!empty($_POST['json_done']))
3101
-		return true;
3272
+	if (!empty($_POST['json_done'])) {
3273
+			return true;
3274
+	}
3102 3275
 
3103 3276
 	// List of tables affected by this function
3104 3277
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3130,12 +3303,14 @@  discard block
 block discarded – undo
3130 3303
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3131 3304
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3132 3305
 
3133
-	foreach ($keys as $id => $table)
3134
-		if ($id < $_GET['substep'])
3306
+	foreach ($keys as $id => $table) {
3307
+			if ($id < $_GET['substep'])
3135 3308
 			$upcontext['previous_tables'][] = $table;
3309
+	}
3136 3310
 
3137
-	if ($command_line)
3138
-		echo 'Converting data from serialize() to json_encode().';
3311
+	if ($command_line) {
3312
+			echo 'Converting data from serialize() to json_encode().';
3313
+	}
3139 3314
 
3140 3315
 	if (!$support_js || isset($_GET['xml']))
3141 3316
 	{
@@ -3175,8 +3350,9 @@  discard block
 block discarded – undo
3175 3350
 
3176 3351
 				// Loop through and fix these...
3177 3352
 				$new_settings = array();
3178
-				if ($command_line)
3179
-					echo "\n" . 'Fixing some settings...';
3353
+				if ($command_line) {
3354
+									echo "\n" . 'Fixing some settings...';
3355
+				}
3180 3356
 
3181 3357
 				foreach ($serialized_settings as $var)
3182 3358
 				{
@@ -3184,22 +3360,24 @@  discard block
 block discarded – undo
3184 3360
 					{
3185 3361
 						// Attempt to unserialize the setting
3186 3362
 						$temp = @safe_unserialize($modSettings[$var]);
3187
-						if (!$temp && $command_line)
3188
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3189
-						elseif ($temp !== false)
3190
-							$new_settings[$var] = json_encode($temp);
3363
+						if (!$temp && $command_line) {
3364
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3365
+						} elseif ($temp !== false) {
3366
+													$new_settings[$var] = json_encode($temp);
3367
+						}
3191 3368
 					}
3192 3369
 				}
3193 3370
 
3194 3371
 				// Update everything at once
3195
-				if (!function_exists('cache_put_data'))
3196
-					require_once($sourcedir . '/Load.php');
3372
+				if (!function_exists('cache_put_data')) {
3373
+									require_once($sourcedir . '/Load.php');
3374
+				}
3197 3375
 				updateSettings($new_settings, true);
3198 3376
 
3199
-				if ($command_line)
3200
-					echo ' done.';
3201
-			}
3202
-			elseif ($table == 'themes')
3377
+				if ($command_line) {
3378
+									echo ' done.';
3379
+				}
3380
+			} elseif ($table == 'themes')
3203 3381
 			{
3204 3382
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3205 3383
 				$query = $smcFunc['db_query']('', '
@@ -3218,10 +3396,11 @@  discard block
 block discarded – undo
3218 3396
 
3219 3397
 						if ($command_line)
3220 3398
 						{
3221
-							if ($temp === false)
3222
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3223
-							else
3224
-								echo "\n" . 'Fixing admin preferences...';
3399
+							if ($temp === false) {
3400
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3401
+							} else {
3402
+															echo "\n" . 'Fixing admin preferences...';
3403
+							}
3225 3404
 						}
3226 3405
 
3227 3406
 						if ($temp !== false)
@@ -3243,15 +3422,15 @@  discard block
 block discarded – undo
3243 3422
 								)
3244 3423
 							);
3245 3424
 
3246
-							if ($command_line)
3247
-								echo ' done.';
3425
+							if ($command_line) {
3426
+															echo ' done.';
3427
+							}
3248 3428
 						}
3249 3429
 					}
3250 3430
 
3251 3431
 					$smcFunc['db_free_result']($query);
3252 3432
 				}
3253
-			}
3254
-			else
3433
+			} else
3255 3434
 			{
3256 3435
 				// First item is always the key...
3257 3436
 				$key = $info[0];
@@ -3262,8 +3441,7 @@  discard block
 block discarded – undo
3262 3441
 				{
3263 3442
 					$col_select = $info[1];
3264 3443
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3265
-				}
3266
-				else
3444
+				} else
3267 3445
 				{
3268 3446
 					$col_select = implode(', ', $info);
3269 3447
 				}
@@ -3296,8 +3474,7 @@  discard block
 block discarded – undo
3296 3474
 								if ($temp === false && $command_line)
3297 3475
 								{
3298 3476
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3299
-								}
3300
-								else
3477
+								} else
3301 3478
 								{
3302 3479
 									$row[$col] = json_encode($temp);
3303 3480
 
@@ -3322,16 +3499,18 @@  discard block
 block discarded – undo
3322 3499
 						}
3323 3500
 					}
3324 3501
 
3325
-					if ($command_line)
3326
-						echo ' done.';
3502
+					if ($command_line) {
3503
+											echo ' done.';
3504
+					}
3327 3505
 
3328 3506
 					// Free up some memory...
3329 3507
 					$smcFunc['db_free_result']($query);
3330 3508
 				}
3331 3509
 			}
3332 3510
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3333
-			if (isset($_GET['xml']))
3334
-				return upgradeExit();
3511
+			if (isset($_GET['xml'])) {
3512
+							return upgradeExit();
3513
+			}
3335 3514
 		}
3336 3515
 
3337 3516
 		if ($command_line)
@@ -3346,8 +3525,9 @@  discard block
 block discarded – undo
3346 3525
 
3347 3526
 		$_GET['substep'] = 0;
3348 3527
 		// Make sure we move on!
3349
-		if ($command_line)
3350
-			return DeleteUpgrade();
3528
+		if ($command_line) {
3529
+					return DeleteUpgrade();
3530
+		}
3351 3531
 
3352 3532
 		return true;
3353 3533
 	}
@@ -3404,14 +3584,16 @@  discard block
 block discarded – undo
3404 3584
 	global $upcontext, $txt, $settings;
3405 3585
 
3406 3586
 	// Don't call me twice!
3407
-	if (!empty($upcontext['chmod_called']))
3408
-		return;
3587
+	if (!empty($upcontext['chmod_called'])) {
3588
+			return;
3589
+	}
3409 3590
 
3410 3591
 	$upcontext['chmod_called'] = true;
3411 3592
 
3412 3593
 	// Nothing?
3413
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3414
-		return;
3594
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3595
+			return;
3596
+	}
3415 3597
 
3416 3598
 	// Was it a problem with Windows?
3417 3599
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3443,11 +3625,12 @@  discard block
 block discarded – undo
3443 3625
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3444 3626
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3445 3627
 
3446
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3447
-		echo '
3628
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3629
+			echo '
3448 3630
 					content.write(\'<hr>\n\t\t\t\');
3449 3631
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3450 3632
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3633
+	}
3451 3634
 
3452 3635
 	echo '
3453 3636
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3455,16 +3638,18 @@  discard block
 block discarded – undo
3455 3638
 				}
3456 3639
 			</script>';
3457 3640
 
3458
-	if (!empty($upcontext['chmod']['ftp_error']))
3459
-		echo '
3641
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3642
+			echo '
3460 3643
 			<div class="error_message red">
3461 3644
 				<p>', $txt['upgrade_ftp_error'], '<p>
3462 3645
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3463 3646
 			</div>';
3647
+	}
3464 3648
 
3465
-	if (empty($upcontext['chmod_in_form']))
3466
-		echo '
3649
+	if (empty($upcontext['chmod_in_form'])) {
3650
+			echo '
3467 3651
 			<form action="', $upcontext['form_url'], '" method="post">';
3652
+	}
3468 3653
 
3469 3654
 	echo '
3470 3655
 				<dl class="settings">
@@ -3506,9 +3691,10 @@  discard block
 block discarded – undo
3506 3691
 					<input type="submit" value="', $txt['ftp_connect'], '" class="button">
3507 3692
 				</div>';
3508 3693
 
3509
-	if (empty($upcontext['chmod_in_form']))
3510
-		echo '
3694
+	if (empty($upcontext['chmod_in_form'])) {
3695
+			echo '
3511 3696
 			</form>';
3697
+	}
3512 3698
 
3513 3699
 	echo '
3514 3700
 		</div><!-- .panel -->';
@@ -3572,9 +3758,10 @@  discard block
 block discarded – undo
3572 3758
 					<h2>', $txt['upgrade_progress'], '</h2>
3573 3759
 					<ul>';
3574 3760
 
3575
-	foreach ($upcontext['steps'] as $num => $step)
3576
-		echo '
3761
+	foreach ($upcontext['steps'] as $num => $step) {
3762
+			echo '
3577 3763
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3764
+	}
3578 3765
 
3579 3766
 	echo '
3580 3767
 					</ul>
@@ -3587,13 +3774,14 @@  discard block
 block discarded – undo
3587 3774
 						<span id="overall_text">', $upcontext['overall_percent'], '%</span>
3588 3775
 					</div>';
3589 3776
 
3590
-	if (isset($upcontext['step_progress']))
3591
-		echo '
3777
+	if (isset($upcontext['step_progress'])) {
3778
+			echo '
3592 3779
 					<div id="progress_bar_step" class="progress_bar progress_yellow">
3593 3780
 						<h3>', $txt['upgrade_step_progress'], '</h3>
3594 3781
 						<div id="step_progress" class="bar" style="width: ', $upcontext['step_progress'], '%;"></div>
3595 3782
 						<span id="step_text">', $upcontext['step_progress'], '%</span>
3596 3783
 					</div>';
3784
+	}
3597 3785
 
3598 3786
 	echo '
3599 3787
 					<div id="substep_bar_div" class="progress_bar" style="display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">
@@ -3624,31 +3812,35 @@  discard block
 block discarded – undo
3624 3812
 {
3625 3813
 	global $upcontext, $txt;
3626 3814
 
3627
-	if (!empty($upcontext['pause']))
3628
-		echo '
3815
+	if (!empty($upcontext['pause'])) {
3816
+			echo '
3629 3817
 					<em>', $txt['upgrade_incomplete'], '.</em><br>
3630 3818
 
3631 3819
 					<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3632 3820
 					<h3>
3633 3821
 						', $txt['upgrade_paused_overload'], '
3634 3822
 					</h3>';
3823
+	}
3635 3824
 
3636
-	if (!empty($upcontext['custom_warning']))
3637
-		echo '
3825
+	if (!empty($upcontext['custom_warning'])) {
3826
+			echo '
3638 3827
 					<div class="errorbox">
3639 3828
 						<h3>', $txt['upgrade_note'], '</h3>
3640 3829
 						', $upcontext['custom_warning'], '
3641 3830
 					</div>';
3831
+	}
3642 3832
 
3643 3833
 	echo '
3644 3834
 					<div class="righttext" style="margin: 1ex;">';
3645 3835
 
3646
-	if (!empty($upcontext['continue']))
3647
-		echo '
3836
+	if (!empty($upcontext['continue'])) {
3837
+			echo '
3648 3838
 						<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3649
-	if (!empty($upcontext['skip']))
3650
-		echo '
3839
+	}
3840
+	if (!empty($upcontext['skip'])) {
3841
+			echo '
3651 3842
 						<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3843
+	}
3652 3844
 
3653 3845
 	echo '
3654 3846
 					</div>
@@ -3699,11 +3891,12 @@  discard block
 block discarded – undo
3699 3891
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3700 3892
 	<smf>';
3701 3893
 
3702
-	if (!empty($upcontext['get_data']))
3703
-		foreach ($upcontext['get_data'] as $k => $v)
3894
+	if (!empty($upcontext['get_data'])) {
3895
+			foreach ($upcontext['get_data'] as $k => $v)
3704 3896
 			echo '
3705 3897
 		<get key="', $k, '">', $v, '</get>';
3706
-}
3898
+	}
3899
+	}
3707 3900
 
3708 3901
 function template_xml_below()
3709 3902
 {
@@ -3743,20 +3936,22 @@  discard block
 block discarded – undo
3743 3936
 	template_chmod();
3744 3937
 
3745 3938
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3746
-	if ($upcontext['is_large_forum'])
3747
-		echo '
3939
+	if ($upcontext['is_large_forum']) {
3940
+			echo '
3748 3941
 					<div class="errorbox">
3749 3942
 						<h3>', $txt['upgrade_warning'], '</h3>
3750 3943
 						', $txt['upgrade_warning_lots_data'], '
3751 3944
 					</div>';
3945
+	}
3752 3946
 
3753 3947
 	// A warning message?
3754
-	if (!empty($upcontext['warning']))
3755
-		echo '
3948
+	if (!empty($upcontext['warning'])) {
3949
+			echo '
3756 3950
 					<div class="errorbox">
3757 3951
 						<h3>', $txt['upgrade_warning'], '</h3>
3758 3952
 						', $upcontext['warning'], '
3759 3953
 					</div>';
3954
+	}
3760 3955
 
3761 3956
 	// Paths are incorrect?
3762 3957
 	echo '
@@ -3769,35 +3964,39 @@  discard block
 block discarded – undo
3769 3964
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3770 3965
 	{
3771 3966
 		$ago = time() - $upcontext['started'];
3772
-		if ($ago < 60)
3773
-			$ago = $ago . ' seconds';
3774
-		elseif ($ago < 3600)
3775
-			$ago = (int) ($ago / 60) . ' minutes';
3776
-		else
3777
-			$ago = (int) ($ago / 3600) . ' hours';
3967
+		if ($ago < 60) {
3968
+					$ago = $ago . ' seconds';
3969
+		} elseif ($ago < 3600) {
3970
+					$ago = (int) ($ago / 60) . ' minutes';
3971
+		} else {
3972
+					$ago = (int) ($ago / 3600) . ' hours';
3973
+		}
3778 3974
 
3779 3975
 		$active = time() - $upcontext['updated'];
3780
-		if ($active < 60)
3781
-			$updated = $active . ' seconds';
3782
-		elseif ($active < 3600)
3783
-			$updated = (int) ($active / 60) . ' minutes';
3784
-		else
3785
-			$updated = (int) ($active / 3600) . ' hours';
3976
+		if ($active < 60) {
3977
+					$updated = $active . ' seconds';
3978
+		} elseif ($active < 3600) {
3979
+					$updated = (int) ($active / 60) . ' minutes';
3980
+		} else {
3981
+					$updated = (int) ($active / 3600) . ' hours';
3982
+		}
3786 3983
 
3787 3984
 		echo '
3788 3985
 					<div class="errorbox">
3789 3986
 						<h3>', $txt['upgrade_warning'], '</h3>
3790 3987
 						<p>', sprintf($txt['upgrade_time'], $upcontext['user']['name'], $ago, $updated), '</p>';
3791
-		if ($active < 600)
3792
-			echo '
3988
+		if ($active < 600) {
3989
+					echo '
3793 3990
 						<p>', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '</p>';
3991
+		}
3794 3992
 
3795
-		if ($active > $upcontext['inactive_timeout'])
3796
-			echo '
3993
+		if ($active > $upcontext['inactive_timeout']) {
3994
+					echo '
3797 3995
 						<p>',$txt['upgrade_run'], '</p>';
3798
-		else
3799
-			echo '
3996
+		} else {
3997
+					echo '
3800 3998
 						<p>', $txt['upgrade_script_timeout'], ' ', $upcontext['user']['name'], ' ', $txt['upgrade_script_timeout2'], ' ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!'), '</p>';
3999
+		}
3801 4000
 
3802 4001
 		echo '
3803 4002
 					</div>';
@@ -3813,9 +4012,10 @@  discard block
 block discarded – undo
3813 4012
 						<dd>
3814 4013
 							<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3815 4014
 
3816
-	if (!empty($upcontext['username_incorrect']))
3817
-		echo '
4015
+	if (!empty($upcontext['username_incorrect'])) {
4016
+			echo '
3818 4017
 							<div class="smalltext red">', $txt['upgrade_wrong_username'], '</div>';
4018
+	}
3819 4019
 
3820 4020
 	echo '
3821 4021
 						</dd>
@@ -3826,9 +4026,10 @@  discard block
 block discarded – undo
3826 4026
 							<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3827 4027
 							<input type="hidden" name="hash_passwrd" value="">';
3828 4028
 
3829
-	if (!empty($upcontext['password_failed']))
3830
-		echo '
4029
+	if (!empty($upcontext['password_failed'])) {
4030
+			echo '
3831 4031
 							<div class="smalltext red">', $txt['upgrade_wrong_password'], '</div>';
4032
+	}
3832 4033
 
3833 4034
 	echo '
3834 4035
 						</dd>';
@@ -3896,12 +4097,13 @@  discard block
 block discarded – undo
3896 4097
 				<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3897 4098
 
3898 4099
 	// Warning message?
3899
-	if (!empty($upcontext['upgrade_options_warning']))
3900
-		echo '
4100
+	if (!empty($upcontext['upgrade_options_warning'])) {
4101
+			echo '
3901 4102
 				<div class="errorbox">
3902 4103
 					<h3>', $txt['upgrade_warning'] ,'</h3>
3903 4104
 					', $upcontext['upgrade_options_warning'], '
3904 4105
 				</div>';
4106
+	}
3905 4107
 
3906 4108
 	echo '
3907 4109
 				<ul class="upgrade_settings">
@@ -3930,12 +4132,13 @@  discard block
 block discarded – undo
3930 4132
 						<label for="empty_error">', $txt['upgrade_empty_errlog'], '</label>
3931 4133
 					</li>';
3932 4134
 
3933
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3934
-		echo '
4135
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4136
+			echo '
3935 4137
 					<li>
3936 4138
 						<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
3937 4139
 						<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3938 4140
 					</li>';
4141
+	}
3939 4142
 
3940 4143
 	echo '
3941 4144
 					<li>
@@ -3969,10 +4172,11 @@  discard block
 block discarded – undo
3969 4172
 					</div>';
3970 4173
 
3971 4174
 	// Dont any tables so far?
3972
-	if (!empty($upcontext['previous_tables']))
3973
-		foreach ($upcontext['previous_tables'] as $table)
4175
+	if (!empty($upcontext['previous_tables'])) {
4176
+			foreach ($upcontext['previous_tables'] as $table)
3974 4177
 			echo '
3975 4178
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4179
+	}
3976 4180
 
3977 4181
 	echo '
3978 4182
 					<h3 id="current_tab">
@@ -4011,12 +4215,13 @@  discard block
 block discarded – undo
4011 4215
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4012 4216
 
4013 4217
 		// If debug flood the screen.
4014
-		if ($is_debug)
4015
-			echo '
4218
+		if ($is_debug) {
4219
+					echo '
4016 4220
 							setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4017 4221
 
4018 4222
 							if (document.getElementById(\'debug_section\').scrollHeight)
4019 4223
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4224
+		}
4020 4225
 
4021 4226
 		echo '
4022 4227
 							// Get the next update...
@@ -4049,8 +4254,9 @@  discard block
 block discarded – undo
4049 4254
 {
4050 4255
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4051 4256
 
4052
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4053
-		$is_debug = true;
4257
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4258
+			$is_debug = true;
4259
+	}
4054 4260
 
4055 4261
 	echo '
4056 4262
 				<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4065,8 +4271,9 @@  discard block
 block discarded – undo
4065 4271
 	{
4066 4272
 		foreach ($upcontext['actioned_items'] as $num => $item)
4067 4273
 		{
4068
-			if ($num != 0)
4069
-				echo ' Successful!';
4274
+			if ($num != 0) {
4275
+							echo ' Successful!';
4276
+			}
4070 4277
 			echo '<br>' . $item;
4071 4278
 		}
4072 4279
 		if (!empty($upcontext['changes_complete']))
@@ -4079,29 +4286,33 @@  discard block
 block discarded – undo
4079 4286
 				$seconds = intval($active % 60);
4080 4287
 
4081 4288
 				$totalTime = '';
4082
-				if ($hours > 0)
4083
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4084
-				if ($minutes > 0)
4085
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4086
-				if ($seconds > 0)
4087
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4289
+				if ($hours > 0) {
4290
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4291
+				}
4292
+				if ($minutes > 0) {
4293
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4294
+				}
4295
+				if ($seconds > 0) {
4296
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4297
+				}
4088 4298
 			}
4089 4299
 
4090
-			if ($is_debug && !empty($totalTime))
4091
-				echo '', sprintf($txt['upgrade_success_time'], $totalTime), '<br>';
4092
-			else
4093
-				echo '', $txt['upgrade_success'], '<br>';
4300
+			if ($is_debug && !empty($totalTime)) {
4301
+							echo '', sprintf($txt['upgrade_success_time'], $totalTime), '<br>';
4302
+			} else {
4303
+							echo '', $txt['upgrade_success'], '<br>';
4304
+			}
4094 4305
 
4095 4306
 			echo '
4096 4307
 					<p id="commess">', $txt['upgrade_db_complete'], '</p>';
4097 4308
 		}
4098
-	}
4099
-	else
4309
+	} else
4100 4310
 	{
4101 4311
 		// Tell them how many files we have in total.
4102
-		if ($upcontext['file_count'] > 1)
4103
-			echo '
4312
+		if ($upcontext['file_count'] > 1) {
4313
+					echo '
4104 4314
 					<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4315
+		}
4105 4316
 
4106 4317
 		echo '
4107 4318
 					<h3 id="info2">
@@ -4119,19 +4330,23 @@  discard block
 block discarded – undo
4119 4330
 				$seconds = intval($active % 60);
4120 4331
 
4121 4332
 				$totalTime = '';
4122
-				if ($hours > 0)
4123
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4124
-				if ($minutes > 0)
4125
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4126
-				if ($seconds > 0)
4127
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4333
+				if ($hours > 0) {
4334
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4335
+				}
4336
+				if ($minutes > 0) {
4337
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4338
+				}
4339
+				if ($seconds > 0) {
4340
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4341
+				}
4128 4342
 			}
4129 4343
 
4130 4344
 			echo '
4131 4345
 					<p id="upgradeCompleted">';
4132 4346
 
4133
-			if (!empty($totalTime))
4134
-				echo '', sprintf($txt['upgrade_completed_time2'], $totalTime), '';
4347
+			if (!empty($totalTime)) {
4348
+							echo '', sprintf($txt['upgrade_completed_time2'], $totalTime), '';
4349
+			}
4135 4350
 
4136 4351
 			echo '
4137 4352
 					</p>
@@ -4168,9 +4383,10 @@  discard block
 block discarded – undo
4168 4383
 						var getData = "";
4169 4384
 						var debugItems = ', $upcontext['debug_items'], ';';
4170 4385
 
4171
-		if ($is_debug)
4172
-			echo '
4386
+		if ($is_debug) {
4387
+					echo '
4173 4388
 						var upgradeStartTime = ' . $upcontext['started'] . ';';
4389
+		}
4174 4390
 
4175 4391
 		echo '
4176 4392
 						function getNextItem()
@@ -4210,9 +4426,10 @@  discard block
 block discarded – undo
4210 4426
 									document.getElementById("error_block").style.display = "";
4211 4427
 									setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4212 4428
 
4213
-	if ($is_debug)
4214
-		echo '
4429
+	if ($is_debug) {
4430
+			echo '
4215 4431
 									setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4432
+	}
4216 4433
 
4217 4434
 	echo '
4218 4435
 								}
@@ -4233,9 +4450,10 @@  discard block
 block discarded – undo
4233 4450
 									document.getElementById("error_block").style.display = "";
4234 4451
 									setInnerHTML(document.getElementById("error_message"), "', $txt['upgrade_loop'], '" + sDebugName);';
4235 4452
 
4236
-	if ($is_debug)
4237
-		echo '
4453
+	if ($is_debug) {
4454
+			echo '
4238 4455
 									setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4456
+	}
4239 4457
 
4240 4458
 	echo '
4241 4459
 								}
@@ -4292,8 +4510,8 @@  discard block
 block discarded – undo
4292 4510
 							if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4293 4511
 							{';
4294 4512
 
4295
-		if ($is_debug)
4296
-			echo '
4513
+		if ($is_debug) {
4514
+					echo '
4297 4515
 								document.getElementById(\'debug_section\').style.display = "none";
4298 4516
 
4299 4517
 								var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4311,6 +4529,7 @@  discard block
 block discarded – undo
4311 4529
 									totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4312 4530
 
4313 4531
 								setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4532
+		}
4314 4533
 
4315 4534
 		echo '
4316 4535
 
@@ -4318,9 +4537,10 @@  discard block
 block discarded – undo
4318 4537
 								document.getElementById(\'contbutt\').disabled = 0;
4319 4538
 								document.getElementById(\'database_done\').value = 1;';
4320 4539
 
4321
-		if ($upcontext['file_count'] > 1)
4322
-			echo '
4540
+		if ($upcontext['file_count'] > 1) {
4541
+					echo '
4323 4542
 								document.getElementById(\'info1\').style.display = "none";';
4543
+		}
4324 4544
 
4325 4545
 		echo '
4326 4546
 								document.getElementById(\'info2\').style.display = "none";
@@ -4333,9 +4553,10 @@  discard block
 block discarded – undo
4333 4553
 								lastItem = 0;
4334 4554
 								prevFile = curFile;';
4335 4555
 
4336
-		if ($is_debug)
4337
-			echo '
4556
+		if ($is_debug) {
4557
+					echo '
4338 4558
 								setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4559
+		}
4339 4560
 
4340 4561
 		echo '
4341 4562
 								getNextItem();
@@ -4343,8 +4564,8 @@  discard block
 block discarded – undo
4343 4564
 							}';
4344 4565
 
4345 4566
 		// If debug scroll the screen.
4346
-		if ($is_debug)
4347
-			echo '
4567
+		if ($is_debug) {
4568
+					echo '
4348 4569
 							if (iLastSubStepProgress == -1)
4349 4570
 							{
4350 4571
 								// Give it consistent dots.
@@ -4363,6 +4584,7 @@  discard block
 block discarded – undo
4363 4584
 
4364 4585
 							if (document.getElementById(\'debug_section\').scrollHeight)
4365 4586
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4587
+		}
4366 4588
 
4367 4589
 		echo '
4368 4590
 							// Update the page.
@@ -4423,9 +4645,10 @@  discard block
 block discarded – undo
4423 4645
 						}';
4424 4646
 
4425 4647
 		// Start things off assuming we've not errored.
4426
-		if (empty($upcontext['error_message']))
4427
-			echo '
4648
+		if (empty($upcontext['error_message'])) {
4649
+					echo '
4428 4650
 						getNextItem();';
4651
+		}
4429 4652
 
4430 4653
 		echo '
4431 4654
 					//# sourceURL=dynamicScript-dbch.js
@@ -4443,18 +4666,21 @@  discard block
 block discarded – undo
4443 4666
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4444 4667
 	<debug num="', $upcontext['current_debug_item_num'], '" percent="', isset($upcontext['substep_progress']) ? $upcontext['substep_progress'] : '-1', '" complete="', empty($upcontext['completed_step']) ? 0 : 1, '">', $upcontext['current_debug_item_name'], '</debug>';
4445 4668
 
4446
-	if (!empty($upcontext['error_message']))
4447
-		echo '
4669
+	if (!empty($upcontext['error_message'])) {
4670
+			echo '
4448 4671
 	<error>', $upcontext['error_message'], '</error>';
4672
+	}
4449 4673
 
4450
-	if (!empty($upcontext['error_string']))
4451
-		echo '
4674
+	if (!empty($upcontext['error_string'])) {
4675
+			echo '
4452 4676
 	<sql>', $upcontext['error_string'], '</sql>';
4677
+	}
4453 4678
 
4454
-	if ($is_debug)
4455
-		echo '
4679
+	if ($is_debug) {
4680
+			echo '
4456 4681
 	<curtime>', time(), '</curtime>';
4457
-}
4682
+	}
4683
+	}
4458 4684
 
4459 4685
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4460 4686
 function template_convert_utf8()
@@ -4471,10 +4697,11 @@  discard block
 block discarded – undo
4471 4697
 					</div>';
4472 4698
 
4473 4699
 	// Done any tables so far?
4474
-	if (!empty($upcontext['previous_tables']))
4475
-		foreach ($upcontext['previous_tables'] as $table)
4700
+	if (!empty($upcontext['previous_tables'])) {
4701
+			foreach ($upcontext['previous_tables'] as $table)
4476 4702
 			echo '
4477 4703
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4704
+	}
4478 4705
 
4479 4706
 	echo '
4480 4707
 					<h3 id="current_tab">
@@ -4482,9 +4709,10 @@  discard block
 block discarded – undo
4482 4709
 					</h3>';
4483 4710
 
4484 4711
 	// If we dropped their index, let's let them know
4485
-	if ($upcontext['dropping_index'])
4486
-		echo '
4712
+	if ($upcontext['dropping_index']) {
4713
+			echo '
4487 4714
 					<p id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_fulltext'], '</p>';
4715
+	}
4488 4716
 
4489 4717
 	// Completion notification
4490 4718
 	echo '
@@ -4521,12 +4749,13 @@  discard block
 block discarded – undo
4521 4749
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4522 4750
 
4523 4751
 		// If debug flood the screen.
4524
-		if ($is_debug)
4525
-			echo '
4752
+		if ($is_debug) {
4753
+					echo '
4526 4754
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4527 4755
 
4528 4756
 						if (document.getElementById(\'debug_section\').scrollHeight)
4529 4757
 							document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4758
+		}
4530 4759
 
4531 4760
 		echo '
4532 4761
 						// Get the next update...
@@ -4572,10 +4801,11 @@  discard block
 block discarded – undo
4572 4801
 					</div>';
4573 4802
 
4574 4803
 	// Dont any tables so far?
4575
-	if (!empty($upcontext['previous_tables']))
4576
-		foreach ($upcontext['previous_tables'] as $table)
4804
+	if (!empty($upcontext['previous_tables'])) {
4805
+			foreach ($upcontext['previous_tables'] as $table)
4577 4806
 			echo '
4578 4807
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4808
+	}
4579 4809
 
4580 4810
 	echo '
4581 4811
 					<h3 id="current_tab">
@@ -4584,9 +4814,10 @@  discard block
 block discarded – undo
4584 4814
 					<p id="commess" style="display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">', $txt['upgrade_json_completed'], '</p>';
4585 4815
 
4586 4816
 	// Try to make sure substep was reset.
4587
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4588
-		echo '
4817
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4818
+			echo '
4589 4819
 					<input type="hidden" name="substep" id="substep" value="0">';
4820
+	}
4590 4821
 
4591 4822
 	// Continue please!
4592 4823
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4619,12 +4850,13 @@  discard block
 block discarded – undo
4619 4850
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4620 4851
 
4621 4852
 		// If debug flood the screen.
4622
-		if ($is_debug)
4623
-			echo '
4853
+		if ($is_debug) {
4854
+					echo '
4624 4855
 							setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4625 4856
 
4626 4857
 							if (document.getElementById(\'debug_section\').scrollHeight)
4627 4858
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4859
+		}
4628 4860
 
4629 4861
 		echo '
4630 4862
 							// Get the next update...
@@ -4660,8 +4892,8 @@  discard block
 block discarded – undo
4660 4892
 				<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4661 4893
 				<form action="', $boardurl, '/index.php">';
4662 4894
 
4663
-	if (!empty($upcontext['can_delete_script']))
4664
-		echo '
4895
+	if (!empty($upcontext['can_delete_script'])) {
4896
+			echo '
4665 4897
 					<label>
4666 4898
 						<input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '
4667 4899
 					</label>
@@ -4675,6 +4907,7 @@  discard block
 block discarded – undo
4675 4907
 						}
4676 4908
 					</script>
4677 4909
 					<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4910
+	}
4678 4911
 
4679 4912
 	$active = time() - $upcontext['started'];
4680 4913
 	$hours = floor($active / 3600);
@@ -4684,17 +4917,21 @@  discard block
 block discarded – undo
4684 4917
 	if ($is_debug)
4685 4918
 	{
4686 4919
 		$totalTime = '';
4687
-		if ($hours > 0)
4688
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4689
-		if ($minutes > 0)
4690
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4691
-		if ($seconds > 0)
4692
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4920
+		if ($hours > 0) {
4921
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4922
+		}
4923
+		if ($minutes > 0) {
4924
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4925
+		}
4926
+		if ($seconds > 0) {
4927
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4928
+		}
4693 4929
 	}
4694 4930
 
4695
-	if ($is_debug && !empty($totalTime))
4696
-		echo '
4931
+	if ($is_debug && !empty($totalTime)) {
4932
+			echo '
4697 4933
 					<p> ', $txt['upgrade_completed_time'], ' ', $totalTime, '</p>';
4934
+	}
4698 4935
 
4699 4936
 	echo '
4700 4937
 					<p>
@@ -4723,8 +4960,9 @@  discard block
 block discarded – undo
4723 4960
 
4724 4961
 	$current_substep = $_GET['substep'];
4725 4962
 
4726
-	if (empty($_GET['a']))
4727
-		$_GET['a'] = 0;
4963
+	if (empty($_GET['a'])) {
4964
+			$_GET['a'] = 0;
4965
+	}
4728 4966
 	$step_progress['name'] = 'Converting ips';
4729 4967
 	$step_progress['current'] = $_GET['a'];
4730 4968
 
@@ -4767,16 +5005,19 @@  discard block
 block discarded – undo
4767 5005
 				'empty' => '',
4768 5006
 				'limit' => $limit,
4769 5007
 		));
4770
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4771
-			$arIp[] = $row[$oldCol];
5008
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5009
+					$arIp[] = $row[$oldCol];
5010
+		}
4772 5011
 		$smcFunc['db_free_result']($request);
4773 5012
 
4774 5013
 		// Special case, null ip could keep us in a loop.
4775
-		if (is_null($arIp[0]))
4776
-			unset($arIp[0]);
5014
+		if (is_null($arIp[0])) {
5015
+					unset($arIp[0]);
5016
+		}
4777 5017
 
4778
-		if (empty($arIp))
4779
-			$is_done = true;
5018
+		if (empty($arIp)) {
5019
+					$is_done = true;
5020
+		}
4780 5021
 
4781 5022
 		$updates = array();
4782 5023
 		$cases = array();
@@ -4785,16 +5026,18 @@  discard block
 block discarded – undo
4785 5026
 		{
4786 5027
 			$arIp[$i] = trim($arIp[$i]);
4787 5028
 
4788
-			if (empty($arIp[$i]))
4789
-				continue;
5029
+			if (empty($arIp[$i])) {
5030
+							continue;
5031
+			}
4790 5032
 
4791 5033
 			$updates['ip' . $i] = $arIp[$i];
4792 5034
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4793 5035
 
4794 5036
 			if ($setSize > 0 && $i % $setSize === 0)
4795 5037
 			{
4796
-				if (count($updates) == 1)
4797
-					continue;
5038
+				if (count($updates) == 1) {
5039
+									continue;
5040
+				}
4798 5041
 
4799 5042
 				$updates['whereSet'] = array_values($updates);
4800 5043
 				$smcFunc['db_query']('', '
@@ -4828,8 +5071,7 @@  discard block
 block discarded – undo
4828 5071
 							'ip' => $ip
4829 5072
 					));
4830 5073
 				}
4831
-			}
4832
-			else
5074
+			} else
4833 5075
 			{
4834 5076
 				$updates['whereSet'] = array_values($updates);
4835 5077
 				$smcFunc['db_query']('', '
@@ -4843,9 +5085,9 @@  discard block
 block discarded – undo
4843 5085
 					$updates
4844 5086
 				);
4845 5087
 			}
5088
+		} else {
5089
+					$is_done = true;
4846 5090
 		}
4847
-		else
4848
-			$is_done = true;
4849 5091
 
4850 5092
 		$_GET['a'] += $limit;
4851 5093
 		$step_progress['current'] = $_GET['a'];
@@ -4871,10 +5113,11 @@  discard block
 block discarded – undo
4871 5113
 
4872 5114
 	$columns = $smcFunc['db_list_columns']($targetTable, true);
4873 5115
 
4874
-	if (isset($columns[$column]))
4875
-		return $columns[$column];
4876
-	else
4877
-		return null;
4878
-}
5116
+	if (isset($columns[$column])) {
5117
+			return $columns[$column];
5118
+	} else {
5119
+			return null;
5120
+	}
5121
+	}
4879 5122
 
4880 5123
 ?>
4881 5124
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs.php 1 patch
Braces   +1480 added lines, -1106 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,24 +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
-
195
-			else
196
+			if ($parameter1 === true) {
197
+							updateSettings(array('totalTopics' => true), true);
198
+			} else
196 199
 			{
197 200
 				// Get the number of topics - a SUM is better for InnoDB tables.
198 201
 				// We also ignore the recycle bin here because there will probably be a bunch of one-post topics there.
@@ -213,8 +216,9 @@  discard block
 block discarded – undo
213 216
 
214 217
 		case 'postgroups':
215 218
 			// Parameter two is the updated columns: we should check to see if we base groups off any of these.
216
-			if ($parameter2 !== null && !in_array('posts', $parameter2))
217
-				return;
219
+			if ($parameter2 !== null && !in_array('posts', $parameter2)) {
220
+							return;
221
+			}
218 222
 
219 223
 			$postgroups = cache_get_data('updateStats:postgroups', 360);
220 224
 			if ($postgroups == null || $parameter1 == null)
@@ -229,8 +233,9 @@  discard block
 block discarded – undo
229 233
 					)
230 234
 				);
231 235
 				$postgroups = array();
232
-				while ($row = $smcFunc['db_fetch_assoc']($request))
233
-					$postgroups[$row['id_group']] = $row['min_posts'];
236
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
237
+									$postgroups[$row['id_group']] = $row['min_posts'];
238
+				}
234 239
 
235 240
 				$smcFunc['db_free_result']($request);
236 241
 
@@ -241,8 +246,9 @@  discard block
 block discarded – undo
241 246
 			}
242 247
 
243 248
 			// Oh great, they've screwed their post groups.
244
-			if (empty($postgroups))
245
-				return;
249
+			if (empty($postgroups)) {
250
+							return;
251
+			}
246 252
 
247 253
 			// Set all membergroups from most posts to least posts.
248 254
 			$conditions = '';
@@ -301,12 +307,9 @@  discard block
 block discarded – undo
301 307
 	{
302 308
 		$condition = 'id_member IN ({array_int:members})';
303 309
 		$parameters['members'] = $members;
304
-	}
305
-
306
-	elseif ($members === null)
307
-		$condition = '1=1';
308
-
309
-	else
310
+	} elseif ($members === null) {
311
+			$condition = '1=1';
312
+	} else
310 313
 	{
311 314
 		$condition = 'id_member = {int:member}';
312 315
 		$parameters['member'] = $members;
@@ -346,9 +349,9 @@  discard block
 block discarded – undo
346 349
 		if (count($vars_to_integrate) != 0)
347 350
 		{
348 351
 			// Fetch a list of member_names if necessary
349
-			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members)))
350
-				$member_names = array($user_info['username']);
351
-			else
352
+			if ((!is_array($members) && $members === $user_info['id']) || (is_array($members) && count($members) == 1 && in_array($user_info['id'], $members))) {
353
+							$member_names = array($user_info['username']);
354
+			} else
352 355
 			{
353 356
 				$member_names = array();
354 357
 				$request = $smcFunc['db_query']('', '
@@ -357,14 +360,16 @@  discard block
 block discarded – undo
357 360
 					WHERE ' . $condition,
358 361
 					$parameters
359 362
 				);
360
-				while ($row = $smcFunc['db_fetch_assoc']($request))
361
-					$member_names[] = $row['member_name'];
363
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
364
+									$member_names[] = $row['member_name'];
365
+				}
362 366
 				$smcFunc['db_free_result']($request);
363 367
 			}
364 368
 
365
-			if (!empty($member_names))
366
-				foreach ($vars_to_integrate as $var)
369
+			if (!empty($member_names)) {
370
+							foreach ($vars_to_integrate as $var)
367 371
 					call_integration_hook('integrate_change_member_data', array($member_names, $var, &$data[$var], &$knownInts, &$knownFloats));
372
+			}
368 373
 		}
369 374
 	}
370 375
 
@@ -372,16 +377,17 @@  discard block
 block discarded – undo
372 377
 	foreach ($data as $var => $val)
373 378
 	{
374 379
 		$type = 'string';
375
-		if (in_array($var, $knownInts))
376
-			$type = 'int';
377
-		elseif (in_array($var, $knownFloats))
378
-			$type = 'float';
379
-		elseif ($var == 'birthdate')
380
-			$type = 'date';
381
-		elseif ($var == 'member_ip')
382
-			$type = 'inet';
383
-		elseif ($var == 'member_ip2')
384
-			$type = 'inet';
380
+		if (in_array($var, $knownInts)) {
381
+					$type = 'int';
382
+		} elseif (in_array($var, $knownFloats)) {
383
+					$type = 'float';
384
+		} elseif ($var == 'birthdate') {
385
+					$type = 'date';
386
+		} elseif ($var == 'member_ip') {
387
+					$type = 'inet';
388
+		} elseif ($var == 'member_ip2') {
389
+					$type = 'inet';
390
+		}
385 391
 
386 392
 		// Doing an increment?
387 393
 		if ($var == 'alerts' && ($val === '+' || $val === '-'))
@@ -390,18 +396,17 @@  discard block
 block discarded – undo
390 396
 			if (is_array($members))
391 397
 			{
392 398
 				$val = 'CASE ';
393
-				foreach ($members as $k => $v)
394
-					$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
399
+				foreach ($members as $k => $v) {
400
+									$val .= 'WHEN id_member = ' . $v . ' THEN '. count(fetch_alerts($v, false, 0, array(), false)) . ' ';
401
+				}
395 402
 				$val = $val . ' END';
396 403
 				$type = 'raw';
397
-			}
398
-			else
404
+			} else
399 405
 			{
400 406
 				$blub = fetch_alerts($members, false, 0, array(), false);
401 407
 				$val = count($blub);
402 408
 			}
403
-		}
404
-		else if ($type == 'int' && ($val === '+' || $val === '-'))
409
+		} else if ($type == 'int' && ($val === '+' || $val === '-'))
405 410
 		{
406 411
 			$val = $var . ' ' . $val . ' 1';
407 412
 			$type = 'raw';
@@ -412,8 +417,9 @@  discard block
 block discarded – undo
412 417
 		{
413 418
 			if (preg_match('~^' . $var . ' (\+ |- |\+ -)([\d]+)~', $val, $match))
414 419
 			{
415
-				if ($match[1] != '+ ')
416
-					$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
420
+				if ($match[1] != '+ ') {
421
+									$val = 'CASE WHEN ' . $var . ' <= ' . abs($match[2]) . ' THEN 0 ELSE ' . $val . ' END';
422
+				}
417 423
 				$type = 'raw';
418 424
 			}
419 425
 		}
@@ -434,8 +440,9 @@  discard block
 block discarded – undo
434 440
 	// Clear any caching?
435 441
 	if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && !empty($members))
436 442
 	{
437
-		if (!is_array($members))
438
-			$members = array($members);
443
+		if (!is_array($members)) {
444
+					$members = array($members);
445
+		}
439 446
 
440 447
 		foreach ($members as $member)
441 448
 		{
@@ -468,29 +475,32 @@  discard block
 block discarded – undo
468 475
 {
469 476
 	global $modSettings, $smcFunc;
470 477
 
471
-	if (empty($changeArray) || !is_array($changeArray))
472
-		return;
478
+	if (empty($changeArray) || !is_array($changeArray)) {
479
+			return;
480
+	}
473 481
 
474 482
 	$toRemove = array();
475 483
 
476 484
 	// Go check if there is any setting to be removed.
477
-	foreach ($changeArray as $k => $v)
478
-		if ($v === null)
485
+	foreach ($changeArray as $k => $v) {
486
+			if ($v === null)
479 487
 		{
480 488
 			// Found some, remove them from the original array and add them to ours.
481 489
 			unset($changeArray[$k]);
490
+	}
482 491
 			$toRemove[] = $k;
483 492
 		}
484 493
 
485 494
 	// Proceed with the deletion.
486
-	if (!empty($toRemove))
487
-		$smcFunc['db_query']('', '
495
+	if (!empty($toRemove)) {
496
+			$smcFunc['db_query']('', '
488 497
 			DELETE FROM {db_prefix}settings
489 498
 			WHERE variable IN ({array_string:remove})',
490 499
 			array(
491 500
 				'remove' => $toRemove,
492 501
 			)
493 502
 		);
503
+	}
494 504
 
495 505
 	// In some cases, this may be better and faster, but for large sets we don't want so many UPDATEs.
496 506
 	if ($update)
@@ -519,19 +529,22 @@  discard block
 block discarded – undo
519 529
 	foreach ($changeArray as $variable => $value)
520 530
 	{
521 531
 		// Don't bother if it's already like that ;).
522
-		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value)
523
-			continue;
532
+		if (isset($modSettings[$variable]) && $modSettings[$variable] == $value) {
533
+					continue;
534
+		}
524 535
 		// If the variable isn't set, but would only be set to nothing'ness, then don't bother setting it.
525
-		elseif (!isset($modSettings[$variable]) && empty($value))
526
-			continue;
536
+		elseif (!isset($modSettings[$variable]) && empty($value)) {
537
+					continue;
538
+		}
527 539
 
528 540
 		$replaceArray[] = array($variable, $value);
529 541
 
530 542
 		$modSettings[$variable] = $value;
531 543
 	}
532 544
 
533
-	if (empty($replaceArray))
534
-		return;
545
+	if (empty($replaceArray)) {
546
+			return;
547
+	}
535 548
 
536 549
 	$smcFunc['db_insert']('replace',
537 550
 		'{db_prefix}settings',
@@ -577,14 +590,17 @@  discard block
 block discarded – undo
577 590
 	$start_invalid = $start < 0;
578 591
 
579 592
 	// Make sure $start is a proper variable - not less than 0.
580
-	if ($start_invalid)
581
-		$start = 0;
593
+	if ($start_invalid) {
594
+			$start = 0;
595
+	}
582 596
 	// Not greater than the upper bound.
583
-	elseif ($start >= $max_value)
584
-		$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
+	elseif ($start >= $max_value) {
598
+			$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
599
+	}
585 600
 	// And it has to be a multiple of $num_per_page!
586
-	else
587
-		$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
601
+	else {
602
+			$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
603
+	}
588 604
 
589 605
 	$context['current_page'] = $start / $num_per_page;
590 606
 
@@ -614,77 +630,87 @@  discard block
 block discarded – undo
614 630
 
615 631
 		// Show all the pages.
616 632
 		$display_page = 1;
617
-		for ($counter = 0; $counter < $max_value; $counter += $num_per_page)
618
-			$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
633
+		for ($counter = 0; $counter < $max_value; $counter += $num_per_page) {
634
+					$pageindex .= $start == $counter && !$start_invalid ? sprintf($settings['page_index']['current_page'], $display_page++) : sprintf($base_link, $counter, $display_page++);
635
+		}
619 636
 
620 637
 		// Show the right arrow.
621 638
 		$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
622
-		if ($start != $counter - $max_value && !$start_invalid)
623
-			$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
624
-	}
625
-	else
639
+		if ($start != $counter - $max_value && !$start_invalid) {
640
+					$pageindex .= $display_page > $counter - $num_per_page ? ' ' : sprintf($base_link, $display_page, $settings['page_index']['next_page']);
641
+		}
642
+	} else
626 643
 	{
627 644
 		// If they didn't enter an odd value, pretend they did.
628 645
 		$PageContiguous = (int) ($modSettings['compactTopicPagesContiguous'] - ($modSettings['compactTopicPagesContiguous'] % 2)) / 2;
629 646
 
630 647
 		// Show the "prev page" link. (>prev page< 1 ... 6 7 [8] 9 10 ... 15 next page)
631
-		if (!empty($start) && $show_prevnext)
632
-			$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
633
-		else
634
-			$pageindex .= '';
648
+		if (!empty($start) && $show_prevnext) {
649
+					$pageindex .= sprintf($base_link, $start - $num_per_page, $settings['page_index']['previous_page']);
650
+		} else {
651
+					$pageindex .= '';
652
+		}
635 653
 
636 654
 		// Show the first page. (prev page >1< ... 6 7 [8] 9 10 ... 15)
637
-		if ($start > $num_per_page * $PageContiguous)
638
-			$pageindex .= sprintf($base_link, 0, '1');
655
+		if ($start > $num_per_page * $PageContiguous) {
656
+					$pageindex .= sprintf($base_link, 0, '1');
657
+		}
639 658
 
640 659
 		// Show the ... after the first page.  (prev page 1 >...< 6 7 [8] 9 10 ... 15 next page)
641
-		if ($start > $num_per_page * ($PageContiguous + 1))
642
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
660
+		if ($start > $num_per_page * ($PageContiguous + 1)) {
661
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
643 662
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
644 663
 				'{FIRST_PAGE}' => $num_per_page,
645 664
 				'{LAST_PAGE}' => $start - $num_per_page * $PageContiguous,
646 665
 				'{PER_PAGE}' => $num_per_page,
647 666
 			));
667
+		}
648 668
 
649 669
 		// Show the pages before the current one. (prev page 1 ... >6 7< [8] 9 10 ... 15 next page)
650
-		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--)
651
-			if ($start >= $num_per_page * $nCont)
670
+		for ($nCont = $PageContiguous; $nCont >= 1; $nCont--) {
671
+					if ($start >= $num_per_page * $nCont)
652 672
 			{
653 673
 				$tmpStart = $start - $num_per_page * $nCont;
674
+		}
654 675
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
655 676
 			}
656 677
 
657 678
 		// Show the current page. (prev page 1 ... 6 7 >[8]< 9 10 ... 15 next page)
658
-		if (!$start_invalid)
659
-			$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
660
-		else
661
-			$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
679
+		if (!$start_invalid) {
680
+					$pageindex .= sprintf($settings['page_index']['current_page'], $start / $num_per_page + 1);
681
+		} else {
682
+					$pageindex .= sprintf($base_link, $start, $start / $num_per_page + 1);
683
+		}
662 684
 
663 685
 		// Show the pages after the current one... (prev page 1 ... 6 7 [8] >9 10< ... 15 next page)
664 686
 		$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
665
-		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++)
666
-			if ($start + $num_per_page * $nCont <= $tmpMaxPages)
687
+		for ($nCont = 1; $nCont <= $PageContiguous; $nCont++) {
688
+					if ($start + $num_per_page * $nCont <= $tmpMaxPages)
667 689
 			{
668 690
 				$tmpStart = $start + $num_per_page * $nCont;
691
+		}
669 692
 				$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
670 693
 			}
671 694
 
672 695
 		// Show the '...' part near the end. (prev page 1 ... 6 7 [8] 9 10 >...< 15 next page)
673
-		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages)
674
-			$pageindex .= strtr($settings['page_index']['expand_pages'], array(
696
+		if ($start + $num_per_page * ($PageContiguous + 1) < $tmpMaxPages) {
697
+					$pageindex .= strtr($settings['page_index']['expand_pages'], array(
675 698
 				'{LINK}' => JavaScriptEscape($smcFunc['htmlspecialchars']($base_link)),
676 699
 				'{FIRST_PAGE}' => $start + $num_per_page * ($PageContiguous + 1),
677 700
 				'{LAST_PAGE}' => $tmpMaxPages,
678 701
 				'{PER_PAGE}' => $num_per_page,
679 702
 			));
703
+		}
680 704
 
681 705
 		// Show the last number in the list. (prev page 1 ... 6 7 [8] 9 10 ... >15<  next page)
682
-		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages)
683
-			$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
706
+		if ($start + $num_per_page * $PageContiguous < $tmpMaxPages) {
707
+					$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
708
+		}
684 709
 
685 710
 		// Show the "next page" link. (prev page 1 ... 6 7 [8] 9 10 ... 15 >next page<)
686
-		if ($start != $tmpMaxPages && $show_prevnext)
687
-			$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
711
+		if ($start != $tmpMaxPages && $show_prevnext) {
712
+					$pageindex .= sprintf($base_link, $start + $num_per_page, $settings['page_index']['next_page']);
713
+		}
688 714
 	}
689 715
 	$pageindex .= $settings['page_index']['extra_after'];
690 716
 
@@ -710,8 +736,9 @@  discard block
 block discarded – undo
710 736
 	if ($decimal_separator === null)
711 737
 	{
712 738
 		// Not set for whatever reason?
713
-		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1)
714
-			return $number;
739
+		if (empty($txt['number_format']) || preg_match('~^1([^\d]*)?234([^\d]*)(0*?)$~', $txt['number_format'], $matches) != 1) {
740
+					return $number;
741
+		}
715 742
 
716 743
 		// Cache these each load...
717 744
 		$thousands_separator = $matches[1];
@@ -752,17 +779,20 @@  discard block
 block discarded – undo
752 779
 	$user_info['time_format'] = !empty($user_info['time_format']) ? $user_info['time_format'] : (!empty($modSettings['time_format']) ? $modSettings['time_format'] : '%F %H:%M');
753 780
 
754 781
 	// Offset the time.
755
-	if (!$offset_type)
756
-		$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
782
+	if (!$offset_type) {
783
+			$time = $log_time + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
784
+	}
757 785
 	// Just the forum offset?
758
-	elseif ($offset_type == 'forum')
759
-		$time = $log_time + $modSettings['time_offset'] * 3600;
760
-	else
761
-		$time = $log_time;
786
+	elseif ($offset_type == 'forum') {
787
+			$time = $log_time + $modSettings['time_offset'] * 3600;
788
+	} else {
789
+			$time = $log_time;
790
+	}
762 791
 
763 792
 	// We can't have a negative date (on Windows, at least.)
764
-	if ($log_time < 0)
765
-		$log_time = 0;
793
+	if ($log_time < 0) {
794
+			$log_time = 0;
795
+	}
766 796
 
767 797
 	// Today and Yesterday?
768 798
 	if ($modSettings['todayMod'] >= 1 && $show_today === true)
@@ -779,24 +809,27 @@  discard block
 block discarded – undo
779 809
 		{
780 810
 			$h = strpos($user_info['time_format'], '%l') === false ? '%I' : '%l';
781 811
 			$today_fmt = $h . ':%M' . $s . ' %p';
812
+		} else {
813
+					$today_fmt = '%H:%M' . $s;
782 814
 		}
783
-		else
784
-			$today_fmt = '%H:%M' . $s;
785 815
 
786 816
 		// Same day of the year, same year.... Today!
787
-		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year'])
788
-			return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
817
+		if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
818
+					return $txt['today'] . timeformat($log_time, $today_fmt, $offset_type);
819
+		}
789 820
 
790 821
 		// 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...
791
-		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))
792
-			return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
822
+		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)) {
823
+					return $txt['yesterday'] . timeformat($log_time, $today_fmt, $offset_type);
824
+		}
793 825
 	}
794 826
 
795 827
 	$str = !is_bool($show_today) ? $show_today : $user_info['time_format'];
796 828
 
797 829
 	// Use the cached formats if available
798
-	if (is_null($finalizedFormats))
799
-		$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
830
+	if (is_null($finalizedFormats)) {
831
+			$finalizedFormats = (array) cache_get_data('timeformatstrings', 86400);
832
+	}
800 833
 
801 834
 	// Make a supported version for this format if we don't already have one
802 835
 	if (empty($finalizedFormats[$str]))
@@ -825,8 +858,9 @@  discard block
 block discarded – undo
825 858
 		);
826 859
 
827 860
 		// No need to do this part again if we already did it once
828
-		if (is_null($unsupportedFormats))
829
-			$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
861
+		if (is_null($unsupportedFormats)) {
862
+					$unsupportedFormats = (array) cache_get_data('unsupportedtimeformats', 86400);
863
+		}
830 864
 		if (empty($unsupportedFormats))
831 865
 		{
832 866
 			foreach($strftimeFormatSubstitutions as $format => $substitution)
@@ -842,20 +876,23 @@  discard block
 block discarded – undo
842 876
 
843 877
 				// Windows will return false for unsupported formats
844 878
 				// Other operating systems return the format string as a literal
845
-				if ($value === false || $value === $format)
846
-					$unsupportedFormats[] = $format;
879
+				if ($value === false || $value === $format) {
880
+									$unsupportedFormats[] = $format;
881
+				}
847 882
 			}
848 883
 			cache_put_data('unsupportedtimeformats', $unsupportedFormats, 86400);
849 884
 		}
850 885
 
851 886
 		// Windows needs extra help if $timeformat contains something completely invalid, e.g. '%Q'
852
-		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
853
-			$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
887
+		if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
888
+					$timeformat = preg_replace('~%(?!' . implode('|', array_keys($strftimeFormatSubstitutions)) . ')~', '&#37;', $timeformat);
889
+		}
854 890
 
855 891
 		// Substitute unsupported formats with supported ones
856
-		if (!empty($unsupportedFormats))
857
-			while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
892
+		if (!empty($unsupportedFormats)) {
893
+					while (preg_match('~%(' . implode('|', $unsupportedFormats) . ')~', $timeformat, $matches))
858 894
 				$timeformat = str_replace($matches[0], $strftimeFormatSubstitutions[$matches[1]], $timeformat);
895
+		}
859 896
 
860 897
 		// Remember this so we don't need to do it again
861 898
 		$finalizedFormats[$str] = $timeformat;
@@ -864,33 +901,39 @@  discard block
 block discarded – undo
864 901
 
865 902
 	$str = $finalizedFormats[$str];
866 903
 
867
-	if (!isset($locale_cache))
868
-		$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
904
+	if (!isset($locale_cache)) {
905
+			$locale_cache = setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
906
+	}
869 907
 
870 908
 	if ($locale_cache !== false)
871 909
 	{
872 910
 		// Check if another process changed the locale
873
-		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache)
874
-			setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
911
+		if ($process_safe === true && setlocale(LC_TIME, '0') != $locale_cache) {
912
+					setlocale(LC_TIME, $txt['lang_locale'] . !empty($modSettings['global_character_set']) ? '.' . $modSettings['global_character_set'] : '');
913
+		}
875 914
 
876
-		if (!isset($non_twelve_hour))
877
-			$non_twelve_hour = trim(strftime('%p')) === '';
878
-		if ($non_twelve_hour && strpos($str, '%p') !== false)
879
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
915
+		if (!isset($non_twelve_hour)) {
916
+					$non_twelve_hour = trim(strftime('%p')) === '';
917
+		}
918
+		if ($non_twelve_hour && strpos($str, '%p') !== false) {
919
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
920
+		}
880 921
 
881
-		foreach (array('%a', '%A', '%b', '%B') as $token)
882
-			if (strpos($str, $token) !== false)
922
+		foreach (array('%a', '%A', '%b', '%B') as $token) {
923
+					if (strpos($str, $token) !== false)
883 924
 				$str = str_replace($token, strftime($token, $time), $str);
884
-	}
885
-	else
925
+		}
926
+	} else
886 927
 	{
887 928
 		// Do-it-yourself time localization.  Fun.
888
-		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label)
889
-			if (strpos($str, $token) !== false)
929
+		foreach (array('%a' => 'days_short', '%A' => 'days', '%b' => 'months_short', '%B' => 'months') as $token => $text_label) {
930
+					if (strpos($str, $token) !== false)
890 931
 				$str = str_replace($token, $txt[$text_label][(int) strftime($token === '%a' || $token === '%A' ? '%w' : '%m', $time)], $str);
932
+		}
891 933
 
892
-		if (strpos($str, '%p') !== false)
893
-			$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
934
+		if (strpos($str, '%p') !== false) {
935
+					$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);
936
+		}
894 937
 	}
895 938
 
896 939
 	// Format the time and then restore any literal percent characters
@@ -913,16 +956,19 @@  discard block
 block discarded – undo
913 956
 	static $translation = array();
914 957
 
915 958
 	// Determine the character set... Default to UTF-8
916
-	if (empty($context['character_set']))
917
-		$charset = 'UTF-8';
959
+	if (empty($context['character_set'])) {
960
+			$charset = 'UTF-8';
961
+	}
918 962
 	// Use ISO-8859-1 in place of non-supported ISO-8859 charsets...
919
-	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15')))
920
-		$charset = 'ISO-8859-1';
921
-	else
922
-		$charset = $context['character_set'];
963
+	elseif (strpos($context['character_set'], 'ISO-8859-') !== false && !in_array($context['character_set'], array('ISO-8859-5', 'ISO-8859-15'))) {
964
+			$charset = 'ISO-8859-1';
965
+	} else {
966
+			$charset = $context['character_set'];
967
+	}
923 968
 
924
-	if (empty($translation))
925
-		$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
969
+	if (empty($translation)) {
970
+			$translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES, $charset)) + array('&#039;' => '\'', '&#39;' => '\'', '&nbsp;' => ' ');
971
+	}
926 972
 
927 973
 	return strtr($string, $translation);
928 974
 }
@@ -944,8 +990,9 @@  discard block
 block discarded – undo
944 990
 	global $smcFunc;
945 991
 
946 992
 	// It was already short enough!
947
-	if ($smcFunc['strlen']($subject) <= $len)
948
-		return $subject;
993
+	if ($smcFunc['strlen']($subject) <= $len) {
994
+			return $subject;
995
+	}
949 996
 
950 997
 	// Shorten it by the length it was too long, and strip off junk from the end.
951 998
 	return $smcFunc['substr']($subject, 0, $len) . '...';
@@ -964,10 +1011,11 @@  discard block
 block discarded – undo
964 1011
 {
965 1012
 	global $user_info, $modSettings;
966 1013
 
967
-	if ($timestamp === null)
968
-		$timestamp = time();
969
-	elseif ($timestamp == 0)
970
-		return 0;
1014
+	if ($timestamp === null) {
1015
+			$timestamp = time();
1016
+	} elseif ($timestamp == 0) {
1017
+			return 0;
1018
+	}
971 1019
 
972 1020
 	return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
973 1021
 }
@@ -996,8 +1044,9 @@  discard block
 block discarded – undo
996 1044
 		$array[$i] = $array[$j];
997 1045
 		$array[$j] = $temp;
998 1046
 
999
-		for ($i = 1; $p[$i] == 0; $i++)
1000
-			$p[$i] = 1;
1047
+		for ($i = 1; $p[$i] == 0; $i++) {
1048
+					$p[$i] = 1;
1049
+		}
1001 1050
 
1002 1051
 		$orders[] = $array;
1003 1052
 	}
@@ -1029,12 +1078,14 @@  discard block
 block discarded – undo
1029 1078
 	static $disabled;
1030 1079
 
1031 1080
 	// Don't waste cycles
1032
-	if ($message === '')
1033
-		return '';
1081
+	if ($message === '') {
1082
+			return '';
1083
+	}
1034 1084
 
1035 1085
 	// Just in case it wasn't determined yet whether UTF-8 is enabled.
1036
-	if (!isset($context['utf8']))
1037
-		$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1086
+	if (!isset($context['utf8'])) {
1087
+			$context['utf8'] = (empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']) === 'UTF-8';
1088
+	}
1038 1089
 
1039 1090
 	// Clean up any cut/paste issues we may have
1040 1091
 	$message = sanitizeMSCutPaste($message);
@@ -1046,13 +1097,15 @@  discard block
 block discarded – undo
1046 1097
 		return $message;
1047 1098
 	}
1048 1099
 
1049
-	if ($smileys !== null && ($smileys == '1' || $smileys == '0'))
1050
-		$smileys = (bool) $smileys;
1100
+	if ($smileys !== null && ($smileys == '1' || $smileys == '0')) {
1101
+			$smileys = (bool) $smileys;
1102
+	}
1051 1103
 
1052 1104
 	if (empty($modSettings['enableBBC']) && $message !== false)
1053 1105
 	{
1054
-		if ($smileys === true)
1055
-			parsesmileys($message);
1106
+		if ($smileys === true) {
1107
+					parsesmileys($message);
1108
+		}
1056 1109
 
1057 1110
 		return $message;
1058 1111
 	}
@@ -1065,8 +1118,9 @@  discard block
 block discarded – undo
1065 1118
 	}
1066 1119
 
1067 1120
 	// Ensure $modSettings['tld_regex'] contains a valid regex for the autolinker
1068
-	if (!empty($modSettings['autoLinkUrls']))
1069
-		set_tld_regex();
1121
+	if (!empty($modSettings['autoLinkUrls'])) {
1122
+			set_tld_regex();
1123
+	}
1070 1124
 
1071 1125
 	// Allow mods access before entering the main parse_bbc loop
1072 1126
 	call_integration_hook('integrate_pre_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
@@ -1080,12 +1134,14 @@  discard block
 block discarded – undo
1080 1134
 
1081 1135
 			$temp = explode(',', strtolower($modSettings['disabledBBC']));
1082 1136
 
1083
-			foreach ($temp as $tag)
1084
-				$disabled[trim($tag)] = true;
1137
+			foreach ($temp as $tag) {
1138
+							$disabled[trim($tag)] = true;
1139
+			}
1085 1140
 		}
1086 1141
 
1087
-		if (empty($modSettings['enableEmbeddedFlash']))
1088
-			$disabled['flash'] = true;
1142
+		if (empty($modSettings['enableEmbeddedFlash'])) {
1143
+					$disabled['flash'] = true;
1144
+		}
1089 1145
 
1090 1146
 		/* The following bbc are formatted as an array, with keys as follows:
1091 1147
 
@@ -1214,8 +1270,9 @@  discard block
 block discarded – undo
1214 1270
 					$returnContext = '';
1215 1271
 
1216 1272
 					// BBC or the entire attachments feature is disabled
1217
-					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach']))
1218
-						return $data;
1273
+					if (empty($modSettings['attachmentEnable']) || !empty($disabled['attach'])) {
1274
+											return $data;
1275
+					}
1219 1276
 
1220 1277
 					// Save the attach ID.
1221 1278
 					$attachID = $data;
@@ -1226,8 +1283,9 @@  discard block
 block discarded – undo
1226 1283
 					$currentAttachment = parseAttachBBC($attachID);
1227 1284
 
1228 1285
 					// parseAttachBBC will return a string ($txt key) rather than dying with a fatal_error. Up to you to decide what to do.
1229
-					if (is_string($currentAttachment))
1230
-						return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1286
+					if (is_string($currentAttachment)) {
1287
+											return $data = !empty($txt[$currentAttachment]) ? $txt[$currentAttachment] : $currentAttachment;
1288
+					}
1231 1289
 
1232 1290
 					if (!empty($currentAttachment['is_image']))
1233 1291
 					{
@@ -1243,15 +1301,17 @@  discard block
 block discarded – undo
1243 1301
 							$height = ' height="' . $currentAttachment['height'] . '"';
1244 1302
 						}
1245 1303
 
1246
-						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}']))
1247
-							$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>';
1248
-						else
1249
-							$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1304
+						if ($currentAttachment['thumbnail']['has_thumb'] && empty($params['{width}']) && empty($params['{height}'])) {
1305
+													$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>';
1306
+						} else {
1307
+													$returnContext .= '<img src="' . $currentAttachment['href'] . ';image"' . $alt . $title . $width . $height . ' class="bbc_img"/>';
1308
+						}
1250 1309
 					}
1251 1310
 
1252 1311
 					// No image. Show a link.
1253
-					else
1254
-						$returnContext .= $currentAttachment['link'];
1312
+					else {
1313
+											$returnContext .= $currentAttachment['link'];
1314
+					}
1255 1315
 
1256 1316
 					// Gotta append what we just did.
1257 1317
 					$data = $returnContext;
@@ -1305,8 +1365,9 @@  discard block
 block discarded – undo
1305 1365
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1306 1366
 						{
1307 1367
 							// Do PHP code coloring?
1308
-							if ($php_parts[$php_i] != '&lt;?php')
1309
-								continue;
1368
+							if ($php_parts[$php_i] != '&lt;?php') {
1369
+															continue;
1370
+							}
1310 1371
 
1311 1372
 							$php_string = '';
1312 1373
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1322,8 +1383,9 @@  discard block
 block discarded – undo
1322 1383
 						$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
1323 1384
 
1324 1385
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1325
-						if ($context['browser']['is_opera'])
1326
-							$data .= '&nbsp;';
1386
+						if ($context['browser']['is_opera']) {
1387
+													$data .= '&nbsp;';
1388
+						}
1327 1389
 					}
1328 1390
 				},
1329 1391
 				'block_level' => true,
@@ -1342,8 +1404,9 @@  discard block
 block discarded – undo
1342 1404
 						for ($php_i = 0, $php_n = count($php_parts); $php_i < $php_n; $php_i++)
1343 1405
 						{
1344 1406
 							// Do PHP code coloring?
1345
-							if ($php_parts[$php_i] != '&lt;?php')
1346
-								continue;
1407
+							if ($php_parts[$php_i] != '&lt;?php') {
1408
+															continue;
1409
+							}
1347 1410
 
1348 1411
 							$php_string = '';
1349 1412
 							while ($php_i + 1 < count($php_parts) && $php_parts[$php_i] != '?&gt;')
@@ -1359,8 +1422,9 @@  discard block
 block discarded – undo
1359 1422
 						$data[0] = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data[0]);
1360 1423
 
1361 1424
 						// Recent Opera bug requiring temporary fix. &nsbp; is needed before </code> to avoid broken selection.
1362
-						if ($context['browser']['is_opera'])
1363
-							$data[0] .= '&nbsp;';
1425
+						if ($context['browser']['is_opera']) {
1426
+													$data[0] .= '&nbsp;';
1427
+						}
1364 1428
 					}
1365 1429
 				},
1366 1430
 				'block_level' => true,
@@ -1398,11 +1462,13 @@  discard block
 block discarded – undo
1398 1462
 				'content' => '<embed type="application/x-shockwave-flash" src="$1" width="$2" height="$3" play="true" loop="true" quality="high" AllowScriptAccess="never">',
1399 1463
 				'validate' => function (&$tag, &$data, $disabled)
1400 1464
 				{
1401
-					if (isset($disabled['url']))
1402
-						$tag['content'] = '$1';
1465
+					if (isset($disabled['url'])) {
1466
+											$tag['content'] = '$1';
1467
+					}
1403 1468
 					$scheme = parse_url($data[0], PHP_URL_SCHEME);
1404
-					if (empty($scheme))
1405
-						$data[0] = '//' . ltrim($data[0], ':/');
1469
+					if (empty($scheme)) {
1470
+											$data[0] = '//' . ltrim($data[0], ':/');
1471
+					}
1406 1472
 				},
1407 1473
 				'disabled_content' => '<a href="$1" target="_blank" rel="noopener">$1</a>',
1408 1474
 			),
@@ -1416,10 +1482,11 @@  discard block
 block discarded – undo
1416 1482
 				{
1417 1483
 					$class = 'class="bbc_float float' . (strpos($data, 'left') === 0 ? 'left' : 'right') . '"';
1418 1484
 
1419
-					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches))
1420
-						$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1421
-					else
1422
-						$css = '';
1485
+					if (preg_match('~\bmax=(\d+(?:%|px|em|rem|ex|pt|pc|ch|vw|vh|vmin|vmax|cm|mm|in)?)~', $data, $matches)) {
1486
+											$css = ' style="max-width:' . $matches[1] . (is_numeric($matches[1]) ? 'px' : '') . '"';
1487
+					} else {
1488
+											$css = '';
1489
+					}
1423 1490
 
1424 1491
 					$data = $class . $css;
1425 1492
 				},
@@ -1434,8 +1501,9 @@  discard block
 block discarded – undo
1434 1501
 				{
1435 1502
 					$data = strtr($data, array('<br />' => ''));
1436 1503
 
1437
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1438
-						$data = 'ftp://' . $data;
1504
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1505
+											$data = 'ftp://' . $data;
1506
+					}
1439 1507
 				},
1440 1508
 			),
1441 1509
 			array(
@@ -1445,8 +1513,9 @@  discard block
 block discarded – undo
1445 1513
 				'after' => '</a>',
1446 1514
 				'validate' => function(&$tag, &$data, $disabled)
1447 1515
 				{
1448
-					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0)
1449
-						$data = 'ftp://' . $data;
1516
+					if (strpos($data, 'ftp://') !== 0 && strpos($data, 'ftps://') !== 0) {
1517
+											$data = 'ftp://' . $data;
1518
+					}
1450 1519
 				},
1451 1520
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1452 1521
 				'disabled_after' => ' ($1)',
@@ -1506,17 +1575,20 @@  discard block
 block discarded – undo
1506 1575
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1507 1576
 					if ($image_proxy_enabled)
1508 1577
 					{
1509
-						if (!empty($user_info['possibly_robot']))
1510
-							return;
1578
+						if (!empty($user_info['possibly_robot'])) {
1579
+													return;
1580
+						}
1511 1581
 
1512
-						if (empty($scheme))
1513
-							$data = 'http://' . ltrim($data, ':/');
1582
+						if (empty($scheme)) {
1583
+													$data = 'http://' . ltrim($data, ':/');
1584
+						}
1514 1585
 
1515
-						if ($scheme != 'https')
1516
-							$data = get_proxied_url($data);
1586
+						if ($scheme != 'https') {
1587
+													$data = get_proxied_url($data);
1588
+						}
1589
+					} elseif (empty($scheme)) {
1590
+											$data = '//' . ltrim($data, ':/');
1517 1591
 					}
1518
-					elseif (empty($scheme))
1519
-						$data = '//' . ltrim($data, ':/');
1520 1592
 				},
1521 1593
 				'disabled_content' => '($1)',
1522 1594
 			),
@@ -1532,17 +1604,20 @@  discard block
 block discarded – undo
1532 1604
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1533 1605
 					if ($image_proxy_enabled)
1534 1606
 					{
1535
-						if (!empty($user_info['possibly_robot']))
1536
-							return;
1607
+						if (!empty($user_info['possibly_robot'])) {
1608
+													return;
1609
+						}
1537 1610
 
1538
-						if (empty($scheme))
1539
-							$data = 'http://' . ltrim($data, ':/');
1611
+						if (empty($scheme)) {
1612
+													$data = 'http://' . ltrim($data, ':/');
1613
+						}
1540 1614
 
1541
-						if ($scheme != 'https')
1542
-							$data = get_proxied_url($data);
1615
+						if ($scheme != 'https') {
1616
+													$data = get_proxied_url($data);
1617
+						}
1618
+					} elseif (empty($scheme)) {
1619
+											$data = '//' . ltrim($data, ':/');
1543 1620
 					}
1544
-					elseif (empty($scheme))
1545
-						$data = '//' . ltrim($data, ':/');
1546 1621
 				},
1547 1622
 				'disabled_content' => '($1)',
1548 1623
 			),
@@ -1554,8 +1629,9 @@  discard block
 block discarded – undo
1554 1629
 				{
1555 1630
 					$data = strtr($data, array('<br>' => ''));
1556 1631
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1557
-					if (empty($scheme))
1558
-						$data = '//' . ltrim($data, ':/');
1632
+					if (empty($scheme)) {
1633
+											$data = '//' . ltrim($data, ':/');
1634
+					}
1559 1635
 				},
1560 1636
 			),
1561 1637
 			array(
@@ -1566,13 +1642,14 @@  discard block
 block discarded – undo
1566 1642
 				'after' => '</a>',
1567 1643
 				'validate' => function (&$tag, &$data, $disabled)
1568 1644
 				{
1569
-					if (substr($data, 0, 1) == '#')
1570
-						$data = '#post_' . substr($data, 1);
1571
-					else
1645
+					if (substr($data, 0, 1) == '#') {
1646
+											$data = '#post_' . substr($data, 1);
1647
+					} else
1572 1648
 					{
1573 1649
 						$scheme = parse_url($data, PHP_URL_SCHEME);
1574
-						if (empty($scheme))
1575
-							$data = '//' . ltrim($data, ':/');
1650
+						if (empty($scheme)) {
1651
+													$data = '//' . ltrim($data, ':/');
1652
+						}
1576 1653
 					}
1577 1654
 				},
1578 1655
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
@@ -1663,8 +1740,9 @@  discard block
 block discarded – undo
1663 1740
 					{
1664 1741
 						$add_begin = substr(trim($data), 0, 5) != '&lt;?';
1665 1742
 						$data = highlight_php_code($add_begin ? '&lt;?php ' . $data . '?&gt;' : $data);
1666
-						if ($add_begin)
1667
-							$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1743
+						if ($add_begin) {
1744
+													$data = preg_replace(array('~^(.+?)&lt;\?.{0,40}?php(?:&nbsp;|\s)~', '~\?&gt;((?:</(font|span)>)*)$~'), '$1', $data, 2);
1745
+						}
1668 1746
 					}
1669 1747
 				},
1670 1748
 				'block_level' => false,
@@ -1777,20 +1855,17 @@  discard block
 block discarded – undo
1777 1855
 					: function(&$tag, &$data, $disabled)
1778 1856
 					{
1779 1857
 
1780
-						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50))
1781
-							$data[1] = '0 -2px 1px';
1782
-
1783
-						elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100))
1784
-							$data[1] = '2px 0 1px';
1785
-
1786
-						elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190))
1787
-							$data[1] = '0 2px 1px';
1788
-
1789
-						elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280))
1790
-							$data[1] = '-2px 0 1px';
1791
-
1792
-						else
1793
-							$data[1] = '1px 1px 1px';
1858
+						if ($data[1] == 'top' || (is_numeric($data[1]) && $data[1] < 50)) {
1859
+													$data[1] = '0 -2px 1px';
1860
+						} elseif ($data[1] == 'right' || (is_numeric($data[1]) && $data[1] < 100)) {
1861
+													$data[1] = '2px 0 1px';
1862
+						} elseif ($data[1] == 'bottom' || (is_numeric($data[1]) && $data[1] < 190)) {
1863
+													$data[1] = '0 2px 1px';
1864
+						} elseif ($data[1] == 'left' || (is_numeric($data[1]) && $data[1] < 280)) {
1865
+													$data[1] = '-2px 0 1px';
1866
+						} else {
1867
+													$data[1] = '1px 1px 1px';
1868
+						}
1794 1869
 					},
1795 1870
 			),
1796 1871
 			array(
@@ -1846,10 +1921,11 @@  discard block
 block discarded – undo
1846 1921
 				'content' => '$1',
1847 1922
 				'validate' => function (&$tag, &$data, $disabled)
1848 1923
 				{
1849
-					if (is_numeric($data))
1850
-						$data = timeformat($data);
1851
-					else
1852
-						$tag['content'] = '[time]$1[/time]';
1924
+					if (is_numeric($data)) {
1925
+											$data = timeformat($data);
1926
+					} else {
1927
+											$tag['content'] = '[time]$1[/time]';
1928
+					}
1853 1929
 				},
1854 1930
 			),
1855 1931
 			array(
@@ -1881,8 +1957,9 @@  discard block
 block discarded – undo
1881 1957
 				{
1882 1958
 					$data = strtr($data, array('<br>' => ''));
1883 1959
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1884
-					if (empty($scheme))
1885
-						$data = '//' . ltrim($data, ':/');
1960
+					if (empty($scheme)) {
1961
+											$data = '//' . ltrim($data, ':/');
1962
+					}
1886 1963
 				},
1887 1964
 			),
1888 1965
 			array(
@@ -1894,8 +1971,9 @@  discard block
 block discarded – undo
1894 1971
 				'validate' => function (&$tag, &$data, $disabled)
1895 1972
 				{
1896 1973
 					$scheme = parse_url($data, PHP_URL_SCHEME);
1897
-					if (empty($scheme))
1898
-						$data = '//' . ltrim($data, ':/');
1974
+					if (empty($scheme)) {
1975
+											$data = '//' . ltrim($data, ':/');
1976
+					}
1899 1977
 				},
1900 1978
 				'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
1901 1979
 				'disabled_after' => ' ($1)',
@@ -1915,12 +1993,13 @@  discard block
 block discarded – undo
1915 1993
 		);
1916 1994
 
1917 1995
 		// Handle legacy bbc codes.
1918
-		foreach ($context['legacy_bbc'] as $bbc)
1919
-			$codes[] = array(
1996
+		foreach ($context['legacy_bbc'] as $bbc) {
1997
+					$codes[] = array(
1920 1998
 				'tag' => $bbc,
1921 1999
 				'before' => '',
1922 2000
 				'after' => '',
1923 2001
 			);
2002
+		}
1924 2003
 
1925 2004
 		// Let mods add new BBC without hassle.
1926 2005
 		call_integration_hook('integrate_bbc_codes', array(&$codes, &$no_autolink_tags));
@@ -1928,8 +2007,9 @@  discard block
 block discarded – undo
1928 2007
 		// This is mainly for the bbc manager, so it's easy to add tags above.  Custom BBC should be added above this line.
1929 2008
 		if ($message === false)
1930 2009
 		{
1931
-			if (isset($temp_bbc))
1932
-				$bbc_codes = $temp_bbc;
2010
+			if (isset($temp_bbc)) {
2011
+							$bbc_codes = $temp_bbc;
2012
+			}
1933 2013
 			usort($codes, function ($a, $b) {
1934 2014
 				return strcmp($a['tag'], $b['tag']);
1935 2015
 			});
@@ -1949,8 +2029,9 @@  discard block
 block discarded – undo
1949 2029
 		);
1950 2030
 		if (!isset($disabled['li']) && !isset($disabled['list']))
1951 2031
 		{
1952
-			foreach ($itemcodes as $c => $dummy)
1953
-				$bbc_codes[$c] = array();
2032
+			foreach ($itemcodes as $c => $dummy) {
2033
+							$bbc_codes[$c] = array();
2034
+			}
1954 2035
 		}
1955 2036
 
1956 2037
 		// Shhhh!
@@ -1971,12 +2052,14 @@  discard block
 block discarded – undo
1971 2052
 		foreach ($codes as $code)
1972 2053
 		{
1973 2054
 			// Make it easier to process parameters later
1974
-			if (!empty($code['parameters']))
1975
-				ksort($code['parameters'], SORT_STRING);
2055
+			if (!empty($code['parameters'])) {
2056
+							ksort($code['parameters'], SORT_STRING);
2057
+			}
1976 2058
 
1977 2059
 			// If we are not doing every tag only do ones we are interested in.
1978
-			if (empty($parse_tags) || in_array($code['tag'], $parse_tags))
1979
-				$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2060
+			if (empty($parse_tags) || in_array($code['tag'], $parse_tags)) {
2061
+							$bbc_codes[substr($code['tag'], 0, 1)][] = $code;
2062
+			}
1980 2063
 		}
1981 2064
 		$codes = null;
1982 2065
 	}
@@ -1987,8 +2070,9 @@  discard block
 block discarded – undo
1987 2070
 		// It's likely this will change if the message is modified.
1988 2071
 		$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']);
1989 2072
 
1990
-		if (($temp = cache_get_data($cache_key, 240)) != null)
1991
-			return $temp;
2073
+		if (($temp = cache_get_data($cache_key, 240)) != null) {
2074
+					return $temp;
2075
+		}
1992 2076
 
1993 2077
 		$cache_t = microtime();
1994 2078
 	}
@@ -2020,8 +2104,9 @@  discard block
 block discarded – undo
2020 2104
 		$disabled['flash'] = true;
2021 2105
 
2022 2106
 		// @todo Change maybe?
2023
-		if (!isset($_GET['images']))
2024
-			$disabled['img'] = true;
2107
+		if (!isset($_GET['images'])) {
2108
+					$disabled['img'] = true;
2109
+		}
2025 2110
 
2026 2111
 		// @todo Interface/setting to add more?
2027 2112
 	}
@@ -2032,8 +2117,9 @@  discard block
 block discarded – undo
2032 2117
 	$alltags = array();
2033 2118
 	foreach ($bbc_codes as $section)
2034 2119
 	{
2035
-		foreach ($section as $code)
2036
-			$alltags[] = $code['tag'];
2120
+		foreach ($section as $code) {
2121
+					$alltags[] = $code['tag'];
2122
+		}
2037 2123
 	}
2038 2124
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
2039 2125
 
@@ -2045,8 +2131,9 @@  discard block
 block discarded – undo
2045 2131
 		$pos = isset($matches[0][1]) ? $matches[0][1] : false;
2046 2132
 
2047 2133
 		// Failsafe.
2048
-		if ($pos === false || $last_pos > $pos)
2049
-			$pos = strlen($message) + 1;
2134
+		if ($pos === false || $last_pos > $pos) {
2135
+					$pos = strlen($message) + 1;
2136
+		}
2050 2137
 
2051 2138
 		// Can't have a one letter smiley, URL, or email! (sorry.)
2052 2139
 		if ($last_pos < $pos - 1)
@@ -2064,8 +2151,9 @@  discard block
 block discarded – undo
2064 2151
 
2065 2152
 				// <br> should be empty.
2066 2153
 				$empty_tags = array('br', 'hr');
2067
-				foreach ($empty_tags as $tag)
2068
-					$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2154
+				foreach ($empty_tags as $tag) {
2155
+									$data = str_replace(array('&lt;' . $tag . '&gt;', '&lt;' . $tag . '/&gt;', '&lt;' . $tag . ' /&gt;'), '<' . $tag . '>', $data);
2156
+				}
2069 2157
 
2070 2158
 				// b, u, i, s, pre... basic tags.
2071 2159
 				$closable_tags = array('b', 'u', 'i', 's', 'em', 'ins', 'del', 'pre', 'blockquote', 'strong');
@@ -2074,8 +2162,9 @@  discard block
 block discarded – undo
2074 2162
 					$diff = substr_count($data, '&lt;' . $tag . '&gt;') - substr_count($data, '&lt;/' . $tag . '&gt;');
2075 2163
 					$data = strtr($data, array('&lt;' . $tag . '&gt;' => '<' . $tag . '>', '&lt;/' . $tag . '&gt;' => '</' . $tag . '>'));
2076 2164
 
2077
-					if ($diff > 0)
2078
-						$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2165
+					if ($diff > 0) {
2166
+											$data = substr($data, 0, -1) . str_repeat('</' . $tag . '>', $diff) . substr($data, -1);
2167
+					}
2079 2168
 				}
2080 2169
 
2081 2170
 				// Do <img ...> - with security... action= -> action-.
@@ -2088,8 +2177,9 @@  discard block
 block discarded – undo
2088 2177
 						$alt = empty($matches[3][$match]) ? '' : ' alt=' . preg_replace('~^&quot;|&quot;$~', '', $matches[3][$match]);
2089 2178
 
2090 2179
 						// Remove action= from the URL - no funny business, now.
2091
-						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0)
2092
-							$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2180
+						if (preg_match('~action(=|%3d)(?!dlattach)~i', $imgtag) != 0) {
2181
+													$imgtag = preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $imgtag);
2182
+						}
2093 2183
 
2094 2184
 						$replaces[$matches[0][$match]] = '[img' . $alt . ']' . $imgtag . '[/img]';
2095 2185
 					}
@@ -2104,16 +2194,18 @@  discard block
 block discarded – undo
2104 2194
 				$no_autolink_area = false;
2105 2195
 				if (!empty($open_tags))
2106 2196
 				{
2107
-					foreach ($open_tags as $open_tag)
2108
-						if (in_array($open_tag['tag'], $no_autolink_tags))
2197
+					foreach ($open_tags as $open_tag) {
2198
+											if (in_array($open_tag['tag'], $no_autolink_tags))
2109 2199
 							$no_autolink_area = true;
2200
+					}
2110 2201
 				}
2111 2202
 
2112 2203
 				// Don't go backwards.
2113 2204
 				// @todo Don't think is the real solution....
2114 2205
 				$lastAutoPos = isset($lastAutoPos) ? $lastAutoPos : 0;
2115
-				if ($pos < $lastAutoPos)
2116
-					$no_autolink_area = true;
2206
+				if ($pos < $lastAutoPos) {
2207
+									$no_autolink_area = true;
2208
+				}
2117 2209
 				$lastAutoPos = $pos;
2118 2210
 
2119 2211
 				if (!$no_autolink_area)
@@ -2218,29 +2310,33 @@  discard block
 block discarded – undo
2218 2310
 							$url = array_shift($matches);
2219 2311
 
2220 2312
 							// If this isn't a clean URL, bail out
2221
-							if ($url != sanitize_iri($url))
2222
-								return $url;
2313
+							if ($url != sanitize_iri($url)) {
2314
+															return $url;
2315
+							}
2223 2316
 
2224 2317
 							$scheme = parse_url($url, PHP_URL_SCHEME);
2225 2318
 
2226 2319
 							if ($scheme == 'mailto')
2227 2320
 							{
2228 2321
 								$email_address = str_replace('mailto:', '', $url);
2229
-								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false)
2230
-									return '[email=' . $email_address . ']' . $url . '[/email]';
2231
-								else
2232
-									return $url;
2322
+								if (!isset($disabled['email']) && filter_var($email_address, FILTER_VALIDATE_EMAIL) !== false) {
2323
+																	return '[email=' . $email_address . ']' . $url . '[/email]';
2324
+								} else {
2325
+																	return $url;
2326
+								}
2233 2327
 							}
2234 2328
 
2235 2329
 							// Are we linking a schemeless URL or naked domain name (e.g. "example.com")?
2236
-							if (empty($scheme))
2237
-								$fullUrl = '//' . ltrim($url, ':/');
2238
-							else
2239
-								$fullUrl = $url;
2330
+							if (empty($scheme)) {
2331
+															$fullUrl = '//' . ltrim($url, ':/');
2332
+							} else {
2333
+															$fullUrl = $url;
2334
+							}
2240 2335
 
2241 2336
 							// Make sure that $fullUrl really is valid
2242
-							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false)
2243
-								return $url;
2337
+							if (validate_iri((strpos($fullUrl, '//') === 0 ? 'http:' : '' ) . $fullUrl) === false) {
2338
+															return $url;
2339
+							}
2244 2340
 
2245 2341
 							return '[url=&quot;' . str_replace(array('[', ']'), array('&#91;', '&#93;'), $fullUrl) . '&quot;]' . $url . '[/url]';
2246 2342
 						}, $data);
@@ -2289,22 +2385,25 @@  discard block
 block discarded – undo
2289 2385
 		}
2290 2386
 
2291 2387
 		// Are we there yet?  Are we there yet?
2292
-		if ($pos >= strlen($message) - 1)
2293
-			break;
2388
+		if ($pos >= strlen($message) - 1) {
2389
+					break;
2390
+		}
2294 2391
 
2295 2392
 		$tags = strtolower($message[$pos + 1]);
2296 2393
 
2297 2394
 		if ($tags == '/' && !empty($open_tags))
2298 2395
 		{
2299 2396
 			$pos2 = strpos($message, ']', $pos + 1);
2300
-			if ($pos2 == $pos + 2)
2301
-				continue;
2397
+			if ($pos2 == $pos + 2) {
2398
+							continue;
2399
+			}
2302 2400
 
2303 2401
 			$look_for = strtolower(substr($message, $pos + 2, $pos2 - $pos - 2));
2304 2402
 
2305 2403
 			// A closing tag that doesn't match any open tags? Skip it.
2306
-			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags)))
2307
-				continue;
2404
+			if (!in_array($look_for, array_map(function($code){return $code['tag'];}, $open_tags))) {
2405
+							continue;
2406
+			}
2308 2407
 
2309 2408
 			$to_close = array();
2310 2409
 			$block_level = null;
@@ -2312,8 +2411,9 @@  discard block
 block discarded – undo
2312 2411
 			do
2313 2412
 			{
2314 2413
 				$tag = array_pop($open_tags);
2315
-				if (!$tag)
2316
-					break;
2414
+				if (!$tag) {
2415
+									break;
2416
+				}
2317 2417
 
2318 2418
 				if (!empty($tag['block_level']))
2319 2419
 				{
@@ -2327,10 +2427,11 @@  discard block
 block discarded – undo
2327 2427
 					// The idea is, if we are LOOKING for a block level tag, we can close them on the way.
2328 2428
 					if (strlen($look_for) > 0 && isset($bbc_codes[$look_for[0]]))
2329 2429
 					{
2330
-						foreach ($bbc_codes[$look_for[0]] as $temp)
2331
-							if ($temp['tag'] == $look_for)
2430
+						foreach ($bbc_codes[$look_for[0]] as $temp) {
2431
+													if ($temp['tag'] == $look_for)
2332 2432
 							{
2333 2433
 								$block_level = !empty($temp['block_level']);
2434
+						}
2334 2435
 								break;
2335 2436
 							}
2336 2437
 					}
@@ -2352,15 +2453,15 @@  discard block
 block discarded – undo
2352 2453
 			{
2353 2454
 				$open_tags = $to_close;
2354 2455
 				continue;
2355
-			}
2356
-			elseif (!empty($to_close) && $tag['tag'] != $look_for)
2456
+			} elseif (!empty($to_close) && $tag['tag'] != $look_for)
2357 2457
 			{
2358 2458
 				if ($block_level === null && isset($look_for[0], $bbc_codes[$look_for[0]]))
2359 2459
 				{
2360
-					foreach ($bbc_codes[$look_for[0]] as $temp)
2361
-						if ($temp['tag'] == $look_for)
2460
+					foreach ($bbc_codes[$look_for[0]] as $temp) {
2461
+											if ($temp['tag'] == $look_for)
2362 2462
 						{
2363 2463
 							$block_level = !empty($temp['block_level']);
2464
+					}
2364 2465
 							break;
2365 2466
 						}
2366 2467
 				}
@@ -2368,8 +2469,9 @@  discard block
 block discarded – undo
2368 2469
 				// We're not looking for a block level tag (or maybe even a tag that exists...)
2369 2470
 				if (!$block_level)
2370 2471
 				{
2371
-					foreach ($to_close as $tag)
2372
-						array_push($open_tags, $tag);
2472
+					foreach ($to_close as $tag) {
2473
+											array_push($open_tags, $tag);
2474
+					}
2373 2475
 					continue;
2374 2476
 				}
2375 2477
 			}
@@ -2382,14 +2484,17 @@  discard block
 block discarded – undo
2382 2484
 
2383 2485
 				// See the comment at the end of the big loop - just eating whitespace ;).
2384 2486
 				$whitespace_regex = '';
2385
-				if (!empty($tag['block_level']))
2386
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2487
+				if (!empty($tag['block_level'])) {
2488
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2489
+				}
2387 2490
 				// Trim one line of whitespace after unnested tags, but all of it after nested ones
2388
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2389
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2491
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2492
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2493
+				}
2390 2494
 
2391
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2392
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2495
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2496
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2497
+				}
2393 2498
 			}
2394 2499
 
2395 2500
 			if (!empty($to_close))
@@ -2402,8 +2507,9 @@  discard block
 block discarded – undo
2402 2507
 		}
2403 2508
 
2404 2509
 		// No tags for this character, so just keep going (fastest possible course.)
2405
-		if (!isset($bbc_codes[$tags]))
2406
-			continue;
2510
+		if (!isset($bbc_codes[$tags])) {
2511
+					continue;
2512
+		}
2407 2513
 
2408 2514
 		$inside = empty($open_tags) ? null : $open_tags[count($open_tags) - 1];
2409 2515
 		$tag = null;
@@ -2412,48 +2518,57 @@  discard block
 block discarded – undo
2412 2518
 			$pt_strlen = strlen($possible['tag']);
2413 2519
 
2414 2520
 			// Not a match?
2415
-			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag'])
2416
-				continue;
2521
+			if (strtolower(substr($message, $pos + 1, $pt_strlen)) != $possible['tag']) {
2522
+							continue;
2523
+			}
2417 2524
 
2418 2525
 			$next_c = isset($message[$pos + 1 + $pt_strlen]) ? $message[$pos + 1 + $pt_strlen] : '';
2419 2526
 
2420 2527
 			// A tag is the last char maybe
2421
-			if ($next_c == '')
2422
-				break;
2528
+			if ($next_c == '') {
2529
+							break;
2530
+			}
2423 2531
 
2424 2532
 			// A test validation?
2425
-			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0)
2426
-				continue;
2533
+			if (isset($possible['test']) && preg_match('~^' . $possible['test'] . '~', substr($message, $pos + 1 + $pt_strlen + 1)) === 0) {
2534
+							continue;
2535
+			}
2427 2536
 			// Do we want parameters?
2428 2537
 			elseif (!empty($possible['parameters']))
2429 2538
 			{
2430
-				if ($next_c != ' ')
2431
-					continue;
2432
-			}
2433
-			elseif (isset($possible['type']))
2539
+				if ($next_c != ' ') {
2540
+									continue;
2541
+				}
2542
+			} elseif (isset($possible['type']))
2434 2543
 			{
2435 2544
 				// Do we need an equal sign?
2436
-				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=')
2437
-					continue;
2545
+				if (in_array($possible['type'], array('unparsed_equals', 'unparsed_commas', 'unparsed_commas_content', 'unparsed_equals_content', 'parsed_equals')) && $next_c != '=') {
2546
+									continue;
2547
+				}
2438 2548
 				// Maybe we just want a /...
2439
-				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]')
2440
-					continue;
2549
+				if ($possible['type'] == 'closed' && $next_c != ']' && substr($message, $pos + 1 + $pt_strlen, 2) != '/]' && substr($message, $pos + 1 + $pt_strlen, 3) != ' /]') {
2550
+									continue;
2551
+				}
2441 2552
 				// An immediate ]?
2442
-				if ($possible['type'] == 'unparsed_content' && $next_c != ']')
2443
-					continue;
2553
+				if ($possible['type'] == 'unparsed_content' && $next_c != ']') {
2554
+									continue;
2555
+				}
2444 2556
 			}
2445 2557
 			// No type means 'parsed_content', which demands an immediate ] without parameters!
2446
-			elseif ($next_c != ']')
2447
-				continue;
2558
+			elseif ($next_c != ']') {
2559
+							continue;
2560
+			}
2448 2561
 
2449 2562
 			// Check allowed tree?
2450
-			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents'])))
2451
-				continue;
2452
-			elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children']))
2453
-				continue;
2563
+			if (isset($possible['require_parents']) && ($inside === null || !in_array($inside['tag'], $possible['require_parents']))) {
2564
+							continue;
2565
+			} elseif (isset($inside['require_children']) && !in_array($possible['tag'], $inside['require_children'])) {
2566
+							continue;
2567
+			}
2454 2568
 			// If this is in the list of disallowed child tags, don't parse it.
2455
-			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children']))
2456
-				continue;
2569
+			elseif (isset($inside['disallow_children']) && in_array($possible['tag'], $inside['disallow_children'])) {
2570
+							continue;
2571
+			}
2457 2572
 
2458 2573
 			$pos1 = $pos + 1 + $pt_strlen + 1;
2459 2574
 
@@ -2465,8 +2580,9 @@  discard block
 block discarded – undo
2465 2580
 				foreach ($open_tags as $open_quote)
2466 2581
 				{
2467 2582
 					// Every parent quote this quote has flips the styling
2468
-					if ($open_quote['tag'] == 'quote')
2469
-						$quote_alt = !$quote_alt;
2583
+					if ($open_quote['tag'] == 'quote') {
2584
+											$quote_alt = !$quote_alt;
2585
+					}
2470 2586
 				}
2471 2587
 				// Add a class to the quote to style alternating blockquotes
2472 2588
 				$possible['before'] = strtr($possible['before'], array('<blockquote>' => '<blockquote class="bbc_' . ($quote_alt ? 'alternate' : 'standard') . '_quote">'));
@@ -2477,8 +2593,9 @@  discard block
 block discarded – undo
2477 2593
 			{
2478 2594
 				// Build a regular expression for each parameter for the current tag.
2479 2595
 				$preg = array();
2480
-				foreach ($possible['parameters'] as $p => $info)
2481
-					$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2596
+				foreach ($possible['parameters'] as $p => $info) {
2597
+									$preg[] = '(\s+' . $p . '=' . (empty($info['quoted']) ? '' : '&quot;') . (isset($info['match']) ? $info['match'] : '(.+?)') . (empty($info['quoted']) ? '' : '&quot;') . '\s*)' . (empty($info['optional']) ? '' : '?');
2598
+				}
2482 2599
 
2483 2600
 				// Extract the string that potentially holds our parameters.
2484 2601
 				$blob = preg_split('~\[/?(?:' . $alltags_regex . ')~i', substr($message, $pos));
@@ -2497,24 +2614,27 @@  discard block
 block discarded – undo
2497 2614
 
2498 2615
 					$match = preg_match('~^' . implode('', $preg) . '$~i', implode(' ', $given_params), $matches) !== 0;
2499 2616
 
2500
-					if ($match)
2501
-						$blob_counter = count($blobs) + 1;
2617
+					if ($match) {
2618
+											$blob_counter = count($blobs) + 1;
2619
+					}
2502 2620
 				}
2503 2621
 
2504 2622
 				// Didn't match our parameter list, try the next possible.
2505
-				if (!$match)
2506
-					continue;
2623
+				if (!$match) {
2624
+									continue;
2625
+				}
2507 2626
 
2508 2627
 				$params = array();
2509 2628
 				for ($i = 1, $n = count($matches); $i < $n; $i += 2)
2510 2629
 				{
2511 2630
 					$key = strtok(ltrim($matches[$i]), '=');
2512
-					if (isset($possible['parameters'][$key]['value']))
2513
-						$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2514
-					elseif (isset($possible['parameters'][$key]['validate']))
2515
-						$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2516
-					else
2517
-						$params['{' . $key . '}'] = $matches[$i + 1];
2631
+					if (isset($possible['parameters'][$key]['value'])) {
2632
+											$params['{' . $key . '}'] = strtr($possible['parameters'][$key]['value'], array('$1' => $matches[$i + 1]));
2633
+					} elseif (isset($possible['parameters'][$key]['validate'])) {
2634
+											$params['{' . $key . '}'] = $possible['parameters'][$key]['validate']($matches[$i + 1]);
2635
+					} else {
2636
+											$params['{' . $key . '}'] = $matches[$i + 1];
2637
+					}
2518 2638
 
2519 2639
 					// Just to make sure: replace any $ or { so they can't interpolate wrongly.
2520 2640
 					$params['{' . $key . '}'] = strtr($params['{' . $key . '}'], array('$' => '&#036;', '{' => '&#123;'));
@@ -2522,23 +2642,26 @@  discard block
 block discarded – undo
2522 2642
 
2523 2643
 				foreach ($possible['parameters'] as $p => $info)
2524 2644
 				{
2525
-					if (!isset($params['{' . $p . '}']))
2526
-						$params['{' . $p . '}'] = '';
2645
+					if (!isset($params['{' . $p . '}'])) {
2646
+											$params['{' . $p . '}'] = '';
2647
+					}
2527 2648
 				}
2528 2649
 
2529 2650
 				$tag = $possible;
2530 2651
 
2531 2652
 				// Put the parameters into the string.
2532
-				if (isset($tag['before']))
2533
-					$tag['before'] = strtr($tag['before'], $params);
2534
-				if (isset($tag['after']))
2535
-					$tag['after'] = strtr($tag['after'], $params);
2536
-				if (isset($tag['content']))
2537
-					$tag['content'] = strtr($tag['content'], $params);
2653
+				if (isset($tag['before'])) {
2654
+									$tag['before'] = strtr($tag['before'], $params);
2655
+				}
2656
+				if (isset($tag['after'])) {
2657
+									$tag['after'] = strtr($tag['after'], $params);
2658
+				}
2659
+				if (isset($tag['content'])) {
2660
+									$tag['content'] = strtr($tag['content'], $params);
2661
+				}
2538 2662
 
2539 2663
 				$pos1 += strlen($given_param_string);
2540
-			}
2541
-			else
2664
+			} else
2542 2665
 			{
2543 2666
 				$tag = $possible;
2544 2667
 				$params = array();
@@ -2549,8 +2672,9 @@  discard block
 block discarded – undo
2549 2672
 		// Item codes are complicated buggers... they are implicit [li]s and can make [list]s!
2550 2673
 		if ($smileys !== false && $tag === null && isset($itemcodes[$message[$pos + 1]]) && $message[$pos + 2] == ']' && !isset($disabled['list']) && !isset($disabled['li']))
2551 2674
 		{
2552
-			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>')))
2553
-				continue;
2675
+			if ($message[$pos + 1] == '0' && !in_array($message[$pos - 1], array(';', ' ', "\t", "\n", '>'))) {
2676
+							continue;
2677
+			}
2554 2678
 
2555 2679
 			$tag = $itemcodes[$message[$pos + 1]];
2556 2680
 
@@ -2571,9 +2695,9 @@  discard block
 block discarded – undo
2571 2695
 			{
2572 2696
 				array_pop($open_tags);
2573 2697
 				$code = '</li>';
2698
+			} else {
2699
+							$code = '';
2574 2700
 			}
2575
-			else
2576
-				$code = '';
2577 2701
 
2578 2702
 			// Now we open a new tag.
2579 2703
 			$open_tags[] = array(
@@ -2620,12 +2744,14 @@  discard block
 block discarded – undo
2620 2744
 		}
2621 2745
 
2622 2746
 		// No tag?  Keep looking, then.  Silly people using brackets without actual tags.
2623
-		if ($tag === null)
2624
-			continue;
2747
+		if ($tag === null) {
2748
+					continue;
2749
+		}
2625 2750
 
2626 2751
 		// Propagate the list to the child (so wrapping the disallowed tag won't work either.)
2627
-		if (isset($inside['disallow_children']))
2628
-			$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2752
+		if (isset($inside['disallow_children'])) {
2753
+					$tag['disallow_children'] = isset($tag['disallow_children']) ? array_unique(array_merge($tag['disallow_children'], $inside['disallow_children'])) : $inside['disallow_children'];
2754
+		}
2629 2755
 
2630 2756
 		// Is this tag disabled?
2631 2757
 		if (isset($disabled[$tag['tag']]))
@@ -2635,14 +2761,13 @@  discard block
 block discarded – undo
2635 2761
 				$tag['before'] = !empty($tag['block_level']) ? '<div>' : '';
2636 2762
 				$tag['after'] = !empty($tag['block_level']) ? '</div>' : '';
2637 2763
 				$tag['content'] = isset($tag['type']) && $tag['type'] == 'closed' ? '' : (!empty($tag['block_level']) ? '<div>$1</div>' : '$1');
2638
-			}
2639
-			elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2764
+			} elseif (isset($tag['disabled_before']) || isset($tag['disabled_after']))
2640 2765
 			{
2641 2766
 				$tag['before'] = isset($tag['disabled_before']) ? $tag['disabled_before'] : (!empty($tag['block_level']) ? '<div>' : '');
2642 2767
 				$tag['after'] = isset($tag['disabled_after']) ? $tag['disabled_after'] : (!empty($tag['block_level']) ? '</div>' : '');
2768
+			} else {
2769
+							$tag['content'] = $tag['disabled_content'];
2643 2770
 			}
2644
-			else
2645
-				$tag['content'] = $tag['disabled_content'];
2646 2771
 		}
2647 2772
 
2648 2773
 		// we use this a lot
@@ -2652,8 +2777,9 @@  discard block
 block discarded – undo
2652 2777
 		if (!empty($tag['block_level']) && $tag['tag'] != 'html' && empty($inside['block_level']))
2653 2778
 		{
2654 2779
 			$n = count($open_tags) - 1;
2655
-			while (empty($open_tags[$n]['block_level']) && $n >= 0)
2656
-				$n--;
2780
+			while (empty($open_tags[$n]['block_level']) && $n >= 0) {
2781
+							$n--;
2782
+			}
2657 2783
 
2658 2784
 			// Close all the non block level tags so this tag isn't surrounded by them.
2659 2785
 			for ($i = count($open_tags) - 1; $i > $n; $i--)
@@ -2665,12 +2791,15 @@  discard block
 block discarded – undo
2665 2791
 
2666 2792
 				// Trim or eat trailing stuff... see comment at the end of the big loop.
2667 2793
 				$whitespace_regex = '';
2668
-				if (!empty($tag['block_level']))
2669
-					$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2670
-				if (!empty($tag['trim']) && $tag['trim'] != 'inside')
2671
-					$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2672
-				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0)
2673
-					$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2794
+				if (!empty($tag['block_level'])) {
2795
+									$whitespace_regex .= '(&nbsp;|\s)*(<br>)?';
2796
+				}
2797
+				if (!empty($tag['trim']) && $tag['trim'] != 'inside') {
2798
+									$whitespace_regex .= empty($tag['require_parents']) ? '(&nbsp;|\s)*' : '(<br>|&nbsp;|\s)*';
2799
+				}
2800
+				if (!empty($whitespace_regex) && preg_match('~' . $whitespace_regex . '~', substr($message, $pos), $matches) != 0) {
2801
+									$message = substr($message, 0, $pos) . substr($message, $pos + strlen($matches[0]));
2802
+				}
2674 2803
 
2675 2804
 				array_pop($open_tags);
2676 2805
 			}
@@ -2691,16 +2820,19 @@  discard block
 block discarded – undo
2691 2820
 		elseif ($tag['type'] == 'unparsed_content')
2692 2821
 		{
2693 2822
 			$pos2 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos1);
2694
-			if ($pos2 === false)
2695
-				continue;
2823
+			if ($pos2 === false) {
2824
+							continue;
2825
+			}
2696 2826
 
2697 2827
 			$data = substr($message, $pos1, $pos2 - $pos1);
2698 2828
 
2699
-			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>')
2700
-				$data = substr($data, 4);
2829
+			if (!empty($tag['block_level']) && substr($data, 0, 4) == '<br>') {
2830
+							$data = substr($data, 4);
2831
+			}
2701 2832
 
2702
-			if (isset($tag['validate']))
2703
-				$tag['validate']($tag, $data, $disabled, $params);
2833
+			if (isset($tag['validate'])) {
2834
+							$tag['validate']($tag, $data, $disabled, $params);
2835
+			}
2704 2836
 
2705 2837
 			$code = strtr($tag['content'], array('$1' => $data));
2706 2838
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 3 + $tag_strlen);
@@ -2715,34 +2847,40 @@  discard block
 block discarded – undo
2715 2847
 			if (isset($tag['quoted']))
2716 2848
 			{
2717 2849
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2718
-				if ($tag['quoted'] != 'optional' && !$quoted)
2719
-					continue;
2850
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2851
+									continue;
2852
+				}
2720 2853
 
2721
-				if ($quoted)
2722
-					$pos1 += 6;
2854
+				if ($quoted) {
2855
+									$pos1 += 6;
2856
+				}
2857
+			} else {
2858
+							$quoted = false;
2723 2859
 			}
2724
-			else
2725
-				$quoted = false;
2726 2860
 
2727 2861
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2728
-			if ($pos2 === false)
2729
-				continue;
2862
+			if ($pos2 === false) {
2863
+							continue;
2864
+			}
2730 2865
 
2731 2866
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2732
-			if ($pos3 === false)
2733
-				continue;
2867
+			if ($pos3 === false) {
2868
+							continue;
2869
+			}
2734 2870
 
2735 2871
 			$data = array(
2736 2872
 				substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
2737 2873
 				substr($message, $pos1, $pos2 - $pos1)
2738 2874
 			);
2739 2875
 
2740
-			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>')
2741
-				$data[0] = substr($data[0], 4);
2876
+			if (!empty($tag['block_level']) && substr($data[0], 0, 4) == '<br>') {
2877
+							$data[0] = substr($data[0], 4);
2878
+			}
2742 2879
 
2743 2880
 			// Validation for my parking, please!
2744
-			if (isset($tag['validate']))
2745
-				$tag['validate']($tag, $data, $disabled, $params);
2881
+			if (isset($tag['validate'])) {
2882
+							$tag['validate']($tag, $data, $disabled, $params);
2883
+			}
2746 2884
 
2747 2885
 			$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
2748 2886
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
@@ -2759,23 +2897,27 @@  discard block
 block discarded – undo
2759 2897
 		elseif ($tag['type'] == 'unparsed_commas_content')
2760 2898
 		{
2761 2899
 			$pos2 = strpos($message, ']', $pos1);
2762
-			if ($pos2 === false)
2763
-				continue;
2900
+			if ($pos2 === false) {
2901
+							continue;
2902
+			}
2764 2903
 
2765 2904
 			$pos3 = stripos($message, '[/' . substr($message, $pos + 1, $tag_strlen) . ']', $pos2);
2766
-			if ($pos3 === false)
2767
-				continue;
2905
+			if ($pos3 === false) {
2906
+							continue;
2907
+			}
2768 2908
 
2769 2909
 			// We want $1 to be the content, and the rest to be csv.
2770 2910
 			$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
2771 2911
 			$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);
2772 2912
 
2773
-			if (isset($tag['validate']))
2774
-				$tag['validate']($tag, $data, $disabled, $params);
2913
+			if (isset($tag['validate'])) {
2914
+							$tag['validate']($tag, $data, $disabled, $params);
2915
+			}
2775 2916
 
2776 2917
 			$code = $tag['content'];
2777
-			foreach ($data as $k => $d)
2778
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2918
+			foreach ($data as $k => $d) {
2919
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2920
+			}
2779 2921
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + $tag_strlen);
2780 2922
 			$pos += strlen($code) - 1 + 2;
2781 2923
 		}
@@ -2783,24 +2925,28 @@  discard block
 block discarded – undo
2783 2925
 		elseif ($tag['type'] == 'unparsed_commas')
2784 2926
 		{
2785 2927
 			$pos2 = strpos($message, ']', $pos1);
2786
-			if ($pos2 === false)
2787
-				continue;
2928
+			if ($pos2 === false) {
2929
+							continue;
2930
+			}
2788 2931
 
2789 2932
 			$data = explode(',', substr($message, $pos1, $pos2 - $pos1));
2790 2933
 
2791
-			if (isset($tag['validate']))
2792
-				$tag['validate']($tag, $data, $disabled, $params);
2934
+			if (isset($tag['validate'])) {
2935
+							$tag['validate']($tag, $data, $disabled, $params);
2936
+			}
2793 2937
 
2794 2938
 			// Fix after, for disabled code mainly.
2795
-			foreach ($data as $k => $d)
2796
-				$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2939
+			foreach ($data as $k => $d) {
2940
+							$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));
2941
+			}
2797 2942
 
2798 2943
 			$open_tags[] = $tag;
2799 2944
 
2800 2945
 			// Replace them out, $1, $2, $3, $4, etc.
2801 2946
 			$code = $tag['before'];
2802
-			foreach ($data as $k => $d)
2803
-				$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2947
+			foreach ($data as $k => $d) {
2948
+							$code = strtr($code, array('$' . ($k + 1) => trim($d)));
2949
+			}
2804 2950
 			$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
2805 2951
 			$pos += strlen($code) - 1 + 2;
2806 2952
 		}
@@ -2811,28 +2957,33 @@  discard block
 block discarded – undo
2811 2957
 			if (isset($tag['quoted']))
2812 2958
 			{
2813 2959
 				$quoted = substr($message, $pos1, 6) == '&quot;';
2814
-				if ($tag['quoted'] != 'optional' && !$quoted)
2815
-					continue;
2960
+				if ($tag['quoted'] != 'optional' && !$quoted) {
2961
+									continue;
2962
+				}
2816 2963
 
2817
-				if ($quoted)
2818
-					$pos1 += 6;
2964
+				if ($quoted) {
2965
+									$pos1 += 6;
2966
+				}
2967
+			} else {
2968
+							$quoted = false;
2819 2969
 			}
2820
-			else
2821
-				$quoted = false;
2822 2970
 
2823 2971
 			$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
2824
-			if ($pos2 === false)
2825
-				continue;
2972
+			if ($pos2 === false) {
2973
+							continue;
2974
+			}
2826 2975
 
2827 2976
 			$data = substr($message, $pos1, $pos2 - $pos1);
2828 2977
 
2829 2978
 			// Validation for my parking, please!
2830
-			if (isset($tag['validate']))
2831
-				$tag['validate']($tag, $data, $disabled, $params);
2979
+			if (isset($tag['validate'])) {
2980
+							$tag['validate']($tag, $data, $disabled, $params);
2981
+			}
2832 2982
 
2833 2983
 			// For parsed content, we must recurse to avoid security problems.
2834
-			if ($tag['type'] != 'unparsed_equals')
2835
-				$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2984
+			if ($tag['type'] != 'unparsed_equals') {
2985
+							$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());
2986
+			}
2836 2987
 
2837 2988
 			$tag['after'] = strtr($tag['after'], array('$1' => $data));
2838 2989
 
@@ -2844,34 +2995,40 @@  discard block
 block discarded – undo
2844 2995
 		}
2845 2996
 
2846 2997
 		// If this is block level, eat any breaks after it.
2847
-		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>')
2848
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
2998
+		if (!empty($tag['block_level']) && substr($message, $pos + 1, 4) == '<br>') {
2999
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 5);
3000
+		}
2849 3001
 
2850 3002
 		// Are we trimming outside this tag?
2851
-		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0)
2852
-			$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
3003
+		if (!empty($tag['trim']) && $tag['trim'] != 'outside' && preg_match('~(<br>|&nbsp;|\s)*~', substr($message, $pos + 1), $matches) != 0) {
3004
+					$message = substr($message, 0, $pos + 1) . substr($message, $pos + 1 + strlen($matches[0]));
3005
+		}
2853 3006
 	}
2854 3007
 
2855 3008
 	// Close any remaining tags.
2856
-	while ($tag = array_pop($open_tags))
2857
-		$message .= "\n" . $tag['after'] . "\n";
3009
+	while ($tag = array_pop($open_tags)) {
3010
+			$message .= "\n" . $tag['after'] . "\n";
3011
+	}
2858 3012
 
2859 3013
 	// Parse the smileys within the parts where it can be done safely.
2860 3014
 	if ($smileys === true)
2861 3015
 	{
2862 3016
 		$message_parts = explode("\n", $message);
2863
-		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2)
2864
-			parsesmileys($message_parts[$i]);
3017
+		for ($i = 0, $n = count($message_parts); $i < $n; $i += 2) {
3018
+					parsesmileys($message_parts[$i]);
3019
+		}
2865 3020
 
2866 3021
 		$message = implode('', $message_parts);
2867 3022
 	}
2868 3023
 
2869 3024
 	// No smileys, just get rid of the markers.
2870
-	else
2871
-		$message = strtr($message, array("\n" => ''));
3025
+	else {
3026
+			$message = strtr($message, array("\n" => ''));
3027
+	}
2872 3028
 
2873
-	if ($message !== '' && $message[0] === ' ')
2874
-		$message = '&nbsp;' . substr($message, 1);
3029
+	if ($message !== '' && $message[0] === ' ') {
3030
+			$message = '&nbsp;' . substr($message, 1);
3031
+	}
2875 3032
 
2876 3033
 	// Cleanup whitespace.
2877 3034
 	$message = strtr($message, array('  ' => ' &nbsp;', "\r" => '', "\n" => '<br>', '<br> ' => '<br>&nbsp;', '&#13;' => "\n"));
@@ -2880,15 +3037,16 @@  discard block
 block discarded – undo
2880 3037
 	call_integration_hook('integrate_post_parsebbc', array(&$message, &$smileys, &$cache_id, &$parse_tags));
2881 3038
 
2882 3039
 	// Cache the output if it took some time...
2883
-	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05)
2884
-		cache_put_data($cache_key, $message, 240);
3040
+	if (isset($cache_key, $cache_t) && array_sum(explode(' ', microtime())) - array_sum(explode(' ', $cache_t)) > 0.05) {
3041
+			cache_put_data($cache_key, $message, 240);
3042
+	}
2885 3043
 
2886 3044
 	// If this was a force parse revert if needed.
2887 3045
 	if (!empty($parse_tags))
2888 3046
 	{
2889
-		if (empty($temp_bbc))
2890
-			$bbc_codes = array();
2891
-		else
3047
+		if (empty($temp_bbc)) {
3048
+					$bbc_codes = array();
3049
+		} else
2892 3050
 		{
2893 3051
 			$bbc_codes = $temp_bbc;
2894 3052
 			unset($temp_bbc);
@@ -2915,8 +3073,9 @@  discard block
 block discarded – undo
2915 3073
 	static $smileyPregSearch = null, $smileyPregReplacements = array();
2916 3074
 
2917 3075
 	// No smiley set at all?!
2918
-	if ($user_info['smiley_set'] == 'none' || trim($message) == '')
2919
-		return;
3076
+	if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
3077
+			return;
3078
+	}
2920 3079
 
2921 3080
 	// Maybe a mod wants to implement an alternative method (e.g. emojis instead of images)
2922 3081
 	call_integration_hook('integrate_smileys', array(&$smileyPregSearch, &$smileyPregReplacements));
@@ -2930,8 +3089,7 @@  discard block
 block discarded – undo
2930 3089
 			$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
2931 3090
 			$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');
2932 3091
 			$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'], '', '', '', '');
2933
-		}
2934
-		else
3092
+		} else
2935 3093
 		{
2936 3094
 			// Load the smileys in reverse order by length so they don't get parsed wrong.
2937 3095
 			if (($temp = cache_get_data('parsing_smileys', 480)) == null)
@@ -2955,9 +3113,9 @@  discard block
 block discarded – undo
2955 3113
 				$smcFunc['db_free_result']($result);
2956 3114
 
2957 3115
 				cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
3116
+			} else {
3117
+							list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2958 3118
 			}
2959
-			else
2960
-				list ($smileysfrom, $smileysto, $smileysdescs) = $temp;
2961 3119
 		}
2962 3120
 
2963 3121
 		// The non-breaking-space is a complex thing...
@@ -2979,16 +3137,18 @@  discard block
 block discarded – undo
2979 3137
 				$alt_images = glob($smileys_dir . $fname .  '.{' . (implode(',', $exts)) . '}', GLOB_BRACE);
2980 3138
 				if (!empty($alt_images))
2981 3139
 				{
2982
-					foreach ($exts as $ext)
2983
-						if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
3140
+					foreach ($exts as $ext) {
3141
+											if (in_array($smileys_dir . $fname . '.' . $ext, $alt_images))
2984 3142
 						{
2985 3143
 							$smileysto[$i] = $fname . '.' . $ext;
3144
+					}
2986 3145
 							break;
2987 3146
 						}
2988 3147
 				}
2989 3148
 				// If we have no image, just leave the text version in place
2990
-				else
2991
-					continue;
3149
+				else {
3150
+									continue;
3151
+				}
2992 3152
 			}
2993 3153
 
2994 3154
 			$specialChars = $smcFunc['htmlspecialchars']($smileysfrom[$i], ENT_QUOTES);
@@ -3056,12 +3216,14 @@  discard block
 block discarded – undo
3056 3216
 	global $boardurl, $image_proxy_enabled, $image_proxy_secret;
3057 3217
 
3058 3218
 	// Only use the proxy if enabled and necessary
3059
-	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https')
3060
-		return $url;
3219
+	if (empty($image_proxy_enabled) || parse_url($url, PHP_URL_SCHEME) === 'https') {
3220
+			return $url;
3221
+	}
3061 3222
 
3062 3223
 	// We don't need to proxy our own resources
3063
-	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0)
3064
-		return strtr($url, array('http://' => 'https://'));
3224
+	if (strpos(strtr($url, array('http://' => 'https://')), strtr($boardurl, array('http://' => 'https://'))) === 0) {
3225
+			return strtr($url, array('http://' => 'https://'));
3226
+	}
3065 3227
 
3066 3228
 	// By default, use SMF's own image proxy script
3067 3229
 	$proxied_url = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($url) . '&hash=' . md5($url . $image_proxy_secret);
@@ -3086,35 +3248,41 @@  discard block
 block discarded – undo
3086 3248
 	global $scripturl, $context, $modSettings, $db_show_debug, $db_cache;
3087 3249
 
3088 3250
 	// In case we have mail to send, better do that - as obExit doesn't always quite make it...
3089
-	if (!empty($context['flush_mail']))
3090
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3251
+	if (!empty($context['flush_mail'])) {
3252
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3091 3253
 		AddMailQueue(true);
3254
+	}
3092 3255
 
3093 3256
 	$add = preg_match('~^(ftp|http)[s]?://~', $setLocation) == 0 && substr($setLocation, 0, 6) != 'about:';
3094 3257
 
3095
-	if ($add)
3096
-		$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3258
+	if ($add) {
3259
+			$setLocation = $scripturl . ($setLocation != '' ? '?' . $setLocation : '');
3260
+	}
3097 3261
 
3098 3262
 	// Put the session ID in.
3099
-	if (defined('SID') && SID != '')
3100
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3263
+	if (defined('SID') && SID != '') {
3264
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '(?!\?' . preg_quote(SID, '/') . ')\\??/', $scripturl . '?' . SID . ';', $setLocation);
3265
+	}
3101 3266
 	// Keep that debug in their for template debugging!
3102
-	elseif (isset($_GET['debug']))
3103
-		$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3267
+	elseif (isset($_GET['debug'])) {
3268
+			$setLocation = preg_replace('/^' . preg_quote($scripturl, '/') . '\\??/', $scripturl . '?debug;', $setLocation);
3269
+	}
3104 3270
 
3105 3271
 	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'])))
3106 3272
 	{
3107
-		if (defined('SID') && SID != '')
3108
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3273
+		if (defined('SID') && SID != '') {
3274
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?(?:' . SID . '(?:;|&|&amp;))((?:board|topic)=[^#]+?)(#[^"]*?)?$~',
3109 3275
 				function ($m) use ($scripturl)
3110 3276
 				{
3111 3277
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html?' . SID. (isset($m[2]) ? "$m[2]" : "");
3278
+		}
3112 3279
 				}, $setLocation);
3113
-		else
3114
-			$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3280
+		else {
3281
+					$setLocation = preg_replace_callback('~^' . preg_quote($scripturl, '~') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?$~',
3115 3282
 				function ($m) use ($scripturl)
3116 3283
 				{
3117 3284
 					return $scripturl . '/' . strtr("$m[1]", '&;=', '//,') . '.html' . (isset($m[2]) ? "$m[2]" : "");
3285
+		}
3118 3286
 				}, $setLocation);
3119 3287
 	}
3120 3288
 
@@ -3125,8 +3293,9 @@  discard block
 block discarded – undo
3125 3293
 	header('location: ' . str_replace(' ', '%20', $setLocation), true, $permanent ? 301 : 302);
3126 3294
 
3127 3295
 	// Debugging.
3128
-	if (isset($db_show_debug) && $db_show_debug === true)
3129
-		$_SESSION['debug_redirect'] = $db_cache;
3296
+	if (isset($db_show_debug) && $db_show_debug === true) {
3297
+			$_SESSION['debug_redirect'] = $db_cache;
3298
+	}
3130 3299
 
3131 3300
 	obExit(false);
3132 3301
 }
@@ -3145,51 +3314,60 @@  discard block
 block discarded – undo
3145 3314
 
3146 3315
 	// Attempt to prevent a recursive loop.
3147 3316
 	++$level;
3148
-	if ($level > 1 && !$from_fatal_error && !$has_fatal_error)
3149
-		exit;
3150
-	if ($from_fatal_error)
3151
-		$has_fatal_error = true;
3317
+	if ($level > 1 && !$from_fatal_error && !$has_fatal_error) {
3318
+			exit;
3319
+	}
3320
+	if ($from_fatal_error) {
3321
+			$has_fatal_error = true;
3322
+	}
3152 3323
 
3153 3324
 	// Clear out the stat cache.
3154 3325
 	trackStats();
3155 3326
 
3156 3327
 	// If we have mail to send, send it.
3157
-	if (!empty($context['flush_mail']))
3158
-		// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3328
+	if (!empty($context['flush_mail'])) {
3329
+			// @todo this relies on 'flush_mail' being only set in AddMailQueue itself... :\
3159 3330
 		AddMailQueue(true);
3331
+	}
3160 3332
 
3161 3333
 	$do_header = $header === null ? !$header_done : $header;
3162
-	if ($do_footer === null)
3163
-		$do_footer = $do_header;
3334
+	if ($do_footer === null) {
3335
+			$do_footer = $do_header;
3336
+	}
3164 3337
 
3165 3338
 	// Has the template/header been done yet?
3166 3339
 	if ($do_header)
3167 3340
 	{
3168 3341
 		// Was the page title set last minute? Also update the HTML safe one.
3169
-		if (!empty($context['page_title']) && empty($context['page_title_html_safe']))
3170
-			$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3342
+		if (!empty($context['page_title']) && empty($context['page_title_html_safe'])) {
3343
+					$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
3344
+		}
3171 3345
 
3172 3346
 		// Start up the session URL fixer.
3173 3347
 		ob_start('ob_sessrewrite');
3174 3348
 
3175
-		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers']))
3176
-			$buffers = explode(',', $settings['output_buffers']);
3177
-		elseif (!empty($settings['output_buffers']))
3178
-			$buffers = $settings['output_buffers'];
3179
-		else
3180
-			$buffers = array();
3349
+		if (!empty($settings['output_buffers']) && is_string($settings['output_buffers'])) {
3350
+					$buffers = explode(',', $settings['output_buffers']);
3351
+		} elseif (!empty($settings['output_buffers'])) {
3352
+					$buffers = $settings['output_buffers'];
3353
+		} else {
3354
+					$buffers = array();
3355
+		}
3181 3356
 
3182
-		if (isset($modSettings['integrate_buffer']))
3183
-			$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3357
+		if (isset($modSettings['integrate_buffer'])) {
3358
+					$buffers = array_merge(explode(',', $modSettings['integrate_buffer']), $buffers);
3359
+		}
3184 3360
 
3185
-		if (!empty($buffers))
3186
-			foreach ($buffers as $function)
3361
+		if (!empty($buffers)) {
3362
+					foreach ($buffers as $function)
3187 3363
 			{
3188 3364
 				$call = call_helper($function, true);
3365
+		}
3189 3366
 
3190 3367
 				// Is it valid?
3191
-				if (!empty($call))
3192
-					ob_start($call);
3368
+				if (!empty($call)) {
3369
+									ob_start($call);
3370
+				}
3193 3371
 			}
3194 3372
 
3195 3373
 		// Display the screen in the logical order.
@@ -3201,8 +3379,9 @@  discard block
 block discarded – undo
3201 3379
 		loadSubTemplate(isset($context['sub_template']) ? $context['sub_template'] : 'main');
3202 3380
 
3203 3381
 		// Anything special to put out?
3204
-		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml']))
3205
-			echo $context['insert_after_template'];
3382
+		if (!empty($context['insert_after_template']) && !isset($_REQUEST['xml'])) {
3383
+					echo $context['insert_after_template'];
3384
+		}
3206 3385
 
3207 3386
 		// Just so we don't get caught in an endless loop of errors from the footer...
3208 3387
 		if (!$footer_done)
@@ -3211,14 +3390,16 @@  discard block
 block discarded – undo
3211 3390
 			template_footer();
3212 3391
 
3213 3392
 			// (since this is just debugging... it's okay that it's after </html>.)
3214
-			if (!isset($_REQUEST['xml']))
3215
-				displayDebug();
3393
+			if (!isset($_REQUEST['xml'])) {
3394
+							displayDebug();
3395
+			}
3216 3396
 		}
3217 3397
 	}
3218 3398
 
3219 3399
 	// Remember this URL in case someone doesn't like sending HTTP_REFERER.
3220
-	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false)
3221
-		$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3400
+	if (strpos($_SERVER['REQUEST_URL'], 'action=dlattach') === false && strpos($_SERVER['REQUEST_URL'], 'action=viewsmfile') === false) {
3401
+			$_SESSION['old_url'] = $_SERVER['REQUEST_URL'];
3402
+	}
3222 3403
 
3223 3404
 	// For session check verification.... don't switch browsers...
3224 3405
 	$_SESSION['USER_AGENT'] = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
@@ -3227,9 +3408,10 @@  discard block
 block discarded – undo
3227 3408
 	call_integration_hook('integrate_exit', array($do_footer));
3228 3409
 
3229 3410
 	// Don't exit if we're coming from index.php; that will pass through normally.
3230
-	if (!$from_index)
3231
-		exit;
3232
-}
3411
+	if (!$from_index) {
3412
+			exit;
3413
+	}
3414
+	}
3233 3415
 
3234 3416
 /**
3235 3417
  * Get the size of a specified image with better error handling.
@@ -3248,8 +3430,9 @@  discard block
 block discarded – undo
3248 3430
 	$url = str_replace(' ', '%20', $url);
3249 3431
 
3250 3432
 	// Can we pull this from the cache... please please?
3251
-	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null)
3252
-		return $temp;
3433
+	if (($temp = cache_get_data('url_image_size-' . md5($url), 240)) !== null) {
3434
+			return $temp;
3435
+	}
3253 3436
 	$t = microtime();
3254 3437
 
3255 3438
 	// Get the host to pester...
@@ -3259,12 +3442,10 @@  discard block
 block discarded – undo
3259 3442
 	if ($url == '' || $url == 'http://' || $url == 'https://')
3260 3443
 	{
3261 3444
 		return false;
3262
-	}
3263
-	elseif (!isset($match[1]))
3445
+	} elseif (!isset($match[1]))
3264 3446
 	{
3265 3447
 		$size = @getimagesize($url);
3266
-	}
3267
-	else
3448
+	} else
3268 3449
 	{
3269 3450
 		// Try to connect to the server... give it half a second.
3270 3451
 		$temp = 0;
@@ -3301,12 +3482,14 @@  discard block
 block discarded – undo
3301 3482
 	}
3302 3483
 
3303 3484
 	// If we didn't get it, we failed.
3304
-	if (!isset($size))
3305
-		$size = false;
3485
+	if (!isset($size)) {
3486
+			$size = false;
3487
+	}
3306 3488
 
3307 3489
 	// If this took a long time, we may never have to do it again, but then again we might...
3308
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8)
3309
-		cache_put_data('url_image_size-' . md5($url), $size, 240);
3490
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.8) {
3491
+			cache_put_data('url_image_size-' . md5($url), $size, 240);
3492
+	}
3310 3493
 
3311 3494
 	// Didn't work.
3312 3495
 	return $size;
@@ -3324,8 +3507,9 @@  discard block
 block discarded – undo
3324 3507
 
3325 3508
 	// Under SSI this function can be called more then once.  That can cause some problems.
3326 3509
 	//   So only run the function once unless we are forced to run it again.
3327
-	if ($loaded && !$forceload)
3328
-		return;
3510
+	if ($loaded && !$forceload) {
3511
+			return;
3512
+	}
3329 3513
 
3330 3514
 	$loaded = true;
3331 3515
 
@@ -3337,14 +3521,16 @@  discard block
 block discarded – undo
3337 3521
 	$context['news_lines'] = array_filter(explode("\n", str_replace("\r", '', trim(addslashes($modSettings['news'])))));
3338 3522
 	for ($i = 0, $n = count($context['news_lines']); $i < $n; $i++)
3339 3523
 	{
3340
-		if (trim($context['news_lines'][$i]) == '')
3341
-			continue;
3524
+		if (trim($context['news_lines'][$i]) == '') {
3525
+					continue;
3526
+		}
3342 3527
 
3343 3528
 		// Clean it up for presentation ;).
3344 3529
 		$context['news_lines'][$i] = parse_bbc(stripslashes(trim($context['news_lines'][$i])), true, 'news' . $i);
3345 3530
 	}
3346
-	if (!empty($context['news_lines']))
3347
-		$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3531
+	if (!empty($context['news_lines'])) {
3532
+			$context['random_news_line'] = $context['news_lines'][mt_rand(0, count($context['news_lines']) - 1)];
3533
+	}
3348 3534
 
3349 3535
 	if (!$user_info['is_guest'])
3350 3536
 	{
@@ -3353,40 +3539,48 @@  discard block
 block discarded – undo
3353 3539
 		$context['user']['alerts'] = &$user_info['alerts'];
3354 3540
 
3355 3541
 		// Personal message popup...
3356
-		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0))
3357
-			$context['user']['popup_messages'] = true;
3358
-		else
3359
-			$context['user']['popup_messages'] = false;
3542
+		if ($user_info['unread_messages'] > (isset($_SESSION['unread_messages']) ? $_SESSION['unread_messages'] : 0)) {
3543
+					$context['user']['popup_messages'] = true;
3544
+		} else {
3545
+					$context['user']['popup_messages'] = false;
3546
+		}
3360 3547
 		$_SESSION['unread_messages'] = $user_info['unread_messages'];
3361 3548
 
3362
-		if (allowedTo('moderate_forum'))
3363
-			$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3549
+		if (allowedTo('moderate_forum')) {
3550
+					$context['unapproved_members'] = (!empty($modSettings['registration_method']) && ($modSettings['registration_method'] == 2 || (!empty($modSettings['coppaType']) && $modSettings['coppaType'] == 2))) || !empty($modSettings['approveAccountDeletion']) ? $modSettings['unapprovedMembers'] : 0;
3551
+		}
3364 3552
 
3365 3553
 		$context['user']['avatar'] = array();
3366 3554
 
3367 3555
 		// Check for gravatar first since we might be forcing them...
3368 3556
 		if (($modSettings['gravatarEnabled'] && substr($user_info['avatar']['url'], 0, 11) == 'gravatar://') || !empty($modSettings['gravatarOverride']))
3369 3557
 		{
3370
-			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11)
3371
-				$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3372
-			else
3373
-				$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3558
+			if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($user_info['avatar']['url'], 'gravatar://') && strlen($user_info['avatar']['url']) > 11) {
3559
+							$context['user']['avatar']['href'] = get_gravatar_url($smcFunc['substr']($user_info['avatar']['url'], 11));
3560
+			} else {
3561
+							$context['user']['avatar']['href'] = get_gravatar_url($user_info['email']);
3562
+			}
3374 3563
 		}
3375 3564
 		// Uploaded?
3376
-		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach']))
3377
-			$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';
3565
+		elseif ($user_info['avatar']['url'] == '' && !empty($user_info['avatar']['id_attach'])) {
3566
+					$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';
3567
+		}
3378 3568
 		// Full URL?
3379
-		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0)
3380
-			$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3569
+		elseif (strpos($user_info['avatar']['url'], 'http://') === 0 || strpos($user_info['avatar']['url'], 'https://') === 0) {
3570
+					$context['user']['avatar']['href'] = $user_info['avatar']['url'];
3571
+		}
3381 3572
 		// Otherwise we assume it's server stored.
3382
-		elseif ($user_info['avatar']['url'] != '')
3383
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3573
+		elseif ($user_info['avatar']['url'] != '') {
3574
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/' . $smcFunc['htmlspecialchars']($user_info['avatar']['url']);
3575
+		}
3384 3576
 		// No avatar at all? Fine, we have a big fat default avatar ;)
3385
-		else
3386
-			$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3577
+		else {
3578
+					$context['user']['avatar']['href'] = $modSettings['avatar_url'] . '/default.png';
3579
+		}
3387 3580
 
3388
-		if (!empty($context['user']['avatar']))
3389
-			$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3581
+		if (!empty($context['user']['avatar'])) {
3582
+					$context['user']['avatar']['image'] = '<img src="' . $context['user']['avatar']['href'] . '" alt="" class="avatar">';
3583
+		}
3390 3584
 
3391 3585
 		// Figure out how long they've been logged in.
3392 3586
 		$context['user']['total_time_logged_in'] = array(
@@ -3394,8 +3588,7 @@  discard block
 block discarded – undo
3394 3588
 			'hours' => floor(($user_info['total_time_logged_in'] % 86400) / 3600),
3395 3589
 			'minutes' => floor(($user_info['total_time_logged_in'] % 3600) / 60)
3396 3590
 		);
3397
-	}
3398
-	else
3591
+	} else
3399 3592
 	{
3400 3593
 		$context['user']['messages'] = 0;
3401 3594
 		$context['user']['unread_messages'] = 0;
@@ -3403,12 +3596,14 @@  discard block
 block discarded – undo
3403 3596
 		$context['user']['total_time_logged_in'] = array('days' => 0, 'hours' => 0, 'minutes' => 0);
3404 3597
 		$context['user']['popup_messages'] = false;
3405 3598
 
3406
-		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1)
3407
-			$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3599
+		if (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1) {
3600
+					$txt['welcome_guest'] .= $txt['welcome_guest_activate'];
3601
+		}
3408 3602
 
3409 3603
 		// If we've upgraded recently, go easy on the passwords.
3410
-		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime']))
3411
-			$context['disable_login_hashing'] = true;
3604
+		if (!empty($modSettings['disableHashTime']) && ($modSettings['disableHashTime'] == 1 || time() < $modSettings['disableHashTime'])) {
3605
+					$context['disable_login_hashing'] = true;
3606
+		}
3412 3607
 	}
3413 3608
 
3414 3609
 	// Setup the main menu items.
@@ -3421,8 +3616,8 @@  discard block
 block discarded – undo
3421 3616
 	$context['show_pm_popup'] = $context['user']['popup_messages'] && !empty($options['popup_messages']) && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'pm');
3422 3617
 
3423 3618
 	// 2.1+: Add the PM popup here instead. Theme authors can still override it simply by editing/removing the 'fPmPopup' in the array.
3424
-	if ($context['show_pm_popup'])
3425
-		addInlineJavaScript('
3619
+	if ($context['show_pm_popup']) {
3620
+			addInlineJavaScript('
3426 3621
 		jQuery(document).ready(function($) {
3427 3622
 			new smc_Popup({
3428 3623
 				heading: ' . JavaScriptEscape($txt['show_personal_messages_heading']) . ',
@@ -3430,24 +3625,28 @@  discard block
 block discarded – undo
3430 3625
 				icon_class: \'generic_icons mail_new\'
3431 3626
 			});
3432 3627
 		});');
3628
+	}
3433 3629
 
3434 3630
 	// Add a generic "Are you sure?" confirmation message.
3435 3631
 	addInlineJavaScript('
3436 3632
 	var smf_you_sure =' . JavaScriptEscape($txt['quickmod_confirm']) .';');
3437 3633
 
3438 3634
 	// Now add the capping code for avatars.
3439
-	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')
3440
-		addInlineCss('
3635
+	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') {
3636
+			addInlineCss('
3441 3637
 	img.avatar { max-width: ' . $modSettings['avatar_max_width_external'] . 'px; max-height: ' . $modSettings['avatar_max_height_external'] . 'px; }');
3638
+	}
3442 3639
 
3443 3640
 	// Add max image limits
3444
-	if (!empty($modSettings['max_image_width']))
3445
-		addInlineCss('
3641
+	if (!empty($modSettings['max_image_width'])) {
3642
+			addInlineCss('
3446 3643
 	.postarea .bbc_img { max-width: ' . $modSettings['max_image_width'] . 'px; }');
3644
+	}
3447 3645
 
3448
-	if (!empty($modSettings['max_image_height']))
3449
-		addInlineCss('
3646
+	if (!empty($modSettings['max_image_height'])) {
3647
+			addInlineCss('
3450 3648
 	.postarea .bbc_img { max-height: ' . $modSettings['max_image_height'] . 'px; }');
3649
+	}
3451 3650
 
3452 3651
 	// This looks weird, but it's because BoardIndex.php references the variable.
3453 3652
 	$context['common_stats']['latest_member'] = array(
@@ -3464,11 +3663,13 @@  discard block
 block discarded – undo
3464 3663
 	);
3465 3664
 	$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']);
3466 3665
 
3467
-	if (empty($settings['theme_version']))
3468
-		addJavaScriptVar('smf_scripturl', $scripturl);
3666
+	if (empty($settings['theme_version'])) {
3667
+			addJavaScriptVar('smf_scripturl', $scripturl);
3668
+	}
3469 3669
 
3470
-	if (!isset($context['page_title']))
3471
-		$context['page_title'] = '';
3670
+	if (!isset($context['page_title'])) {
3671
+			$context['page_title'] = '';
3672
+	}
3472 3673
 
3473 3674
 	// Set some specific vars.
3474 3675
 	$context['page_title_html_safe'] = $smcFunc['htmlspecialchars'](un_htmlspecialchars($context['page_title'])) . (!empty($context['current_page']) ? ' - ' . $txt['page'] . ' ' . ($context['current_page'] + 1) : '');
@@ -3478,21 +3679,23 @@  discard block
 block discarded – undo
3478 3679
 	$context['meta_tags'][] = array('property' => 'og:site_name', 'content' => $context['forum_name']);
3479 3680
 	$context['meta_tags'][] = array('property' => 'og:title', 'content' => $context['page_title_html_safe']);
3480 3681
 
3481
-	if (!empty($context['meta_keywords']))
3482
-		$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3682
+	if (!empty($context['meta_keywords'])) {
3683
+			$context['meta_tags'][] = array('name' => 'keywords', 'content' => $context['meta_keywords']);
3684
+	}
3483 3685
 
3484
-	if (!empty($context['canonical_url']))
3485
-		$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3686
+	if (!empty($context['canonical_url'])) {
3687
+			$context['meta_tags'][] = array('property' => 'og:url', 'content' => $context['canonical_url']);
3688
+	}
3486 3689
 
3487
-	if (!empty($settings['og_image']))
3488
-		$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3690
+	if (!empty($settings['og_image'])) {
3691
+			$context['meta_tags'][] = array('property' => 'og:image', 'content' => $settings['og_image']);
3692
+	}
3489 3693
 
3490 3694
 	if (!empty($context['meta_description']))
3491 3695
 	{
3492 3696
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['meta_description']);
3493 3697
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['meta_description']);
3494
-	}
3495
-	else
3698
+	} else
3496 3699
 	{
3497 3700
 		$context['meta_tags'][] = array('property' => 'og:description', 'content' => $context['page_title_html_safe']);
3498 3701
 		$context['meta_tags'][] = array('name' => 'description', 'content' => $context['page_title_html_safe']);
@@ -3517,8 +3720,9 @@  discard block
 block discarded – undo
3517 3720
 	$memory_needed = memoryReturnBytes($needed);
3518 3721
 
3519 3722
 	// should we account for how much is currently being used?
3520
-	if ($in_use)
3521
-		$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3723
+	if ($in_use) {
3724
+			$memory_needed += function_exists('memory_get_usage') ? memory_get_usage() : (2 * 1048576);
3725
+	}
3522 3726
 
3523 3727
 	// if more is needed, request it
3524 3728
 	if ($memory_current < $memory_needed)
@@ -3541,8 +3745,9 @@  discard block
 block discarded – undo
3541 3745
  */
3542 3746
 function memoryReturnBytes($val)
3543 3747
 {
3544
-	if (is_integer($val))
3545
-		return $val;
3748
+	if (is_integer($val)) {
3749
+			return $val;
3750
+	}
3546 3751
 
3547 3752
 	// Separate the number from the designator
3548 3753
 	$val = trim($val);
@@ -3578,10 +3783,11 @@  discard block
 block discarded – undo
3578 3783
 		header('last-modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
3579 3784
 
3580 3785
 		// Are we debugging the template/html content?
3581
-		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie'))
3582
-			header('content-type: application/xhtml+xml');
3583
-		elseif (!isset($_REQUEST['xml']))
3584
-			header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3786
+		if (!isset($_REQUEST['xml']) && isset($_GET['debug']) && !isBrowser('ie')) {
3787
+					header('content-type: application/xhtml+xml');
3788
+		} elseif (!isset($_REQUEST['xml'])) {
3789
+					header('content-type: text/html; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
3790
+		}
3585 3791
 	}
3586 3792
 
3587 3793
 	header('content-type: text/' . (isset($_REQUEST['xml']) ? 'xml' : 'html') . '; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set']));
@@ -3590,8 +3796,9 @@  discard block
 block discarded – undo
3590 3796
 	if ($context['in_maintenance'] && $context['user']['is_admin'])
3591 3797
 	{
3592 3798
 		$position = array_search('body', $context['template_layers']);
3593
-		if ($position === false)
3594
-			$position = array_search('main', $context['template_layers']);
3799
+		if ($position === false) {
3800
+					$position = array_search('main', $context['template_layers']);
3801
+		}
3595 3802
 
3596 3803
 		if ($position !== false)
3597 3804
 		{
@@ -3619,23 +3826,25 @@  discard block
 block discarded – undo
3619 3826
 
3620 3827
 			foreach ($securityFiles as $i => $securityFile)
3621 3828
 			{
3622
-				if (!file_exists($boarddir . '/' . $securityFile))
3623
-					unset($securityFiles[$i]);
3829
+				if (!file_exists($boarddir . '/' . $securityFile)) {
3830
+									unset($securityFiles[$i]);
3831
+				}
3624 3832
 			}
3625 3833
 
3626 3834
 			// We are already checking so many files...just few more doesn't make any difference! :P
3627
-			if (!empty($modSettings['currentAttachmentUploadDir']))
3628
-				$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3629
-
3630
-			else
3631
-				$path = $modSettings['attachmentUploadDir'];
3835
+			if (!empty($modSettings['currentAttachmentUploadDir'])) {
3836
+							$path = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']];
3837
+			} else {
3838
+							$path = $modSettings['attachmentUploadDir'];
3839
+			}
3632 3840
 
3633 3841
 			secureDirectory($path, true);
3634 3842
 			secureDirectory($cachedir);
3635 3843
 
3636 3844
 			// If agreement is enabled, at least the english version shall exists
3637
-			if ($modSettings['requireAgreement'])
3638
-				$agreement = !file_exists($boarddir . '/agreement.txt');
3845
+			if ($modSettings['requireAgreement']) {
3846
+							$agreement = !file_exists($boarddir . '/agreement.txt');
3847
+			}
3639 3848
 
3640 3849
 			if (!empty($securityFiles) || (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) || !empty($agreement))
3641 3850
 			{
@@ -3650,18 +3859,21 @@  discard block
 block discarded – undo
3650 3859
 					echo '
3651 3860
 				', $txt['not_removed'], '<strong>', $securityFile, '</strong>!<br>';
3652 3861
 
3653
-					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~')
3654
-						echo '
3862
+					if ($securityFile == 'Settings.php~' || $securityFile == 'Settings_bak.php~') {
3863
+											echo '
3655 3864
 				', sprintf($txt['not_removed_extra'], $securityFile, substr($securityFile, 0, -1)), '<br>';
3865
+					}
3656 3866
 				}
3657 3867
 
3658
-				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir))
3659
-					echo '
3868
+				if (!empty($modSettings['cache_enable']) && !is_writable($cachedir)) {
3869
+									echo '
3660 3870
 				<strong>', $txt['cache_writable'], '</strong><br>';
3871
+				}
3661 3872
 
3662
-				if (!empty($agreement))
3663
-					echo '
3873
+				if (!empty($agreement)) {
3874
+									echo '
3664 3875
 				<strong>', $txt['agreement_missing'], '</strong><br>';
3876
+				}
3665 3877
 
3666 3878
 				echo '
3667 3879
 			</p>
@@ -3676,16 +3888,18 @@  discard block
 block discarded – undo
3676 3888
 				<div class="windowbg alert" style="margin: 2ex; padding: 2ex; border: 2px dashed red;">
3677 3889
 					', sprintf($txt['you_are_post_banned'], $user_info['is_guest'] ? $txt['guest_title'] : $user_info['name']);
3678 3890
 
3679
-			if (!empty($_SESSION['ban']['cannot_post']['reason']))
3680
-				echo '
3891
+			if (!empty($_SESSION['ban']['cannot_post']['reason'])) {
3892
+							echo '
3681 3893
 					<div style="padding-left: 4ex; padding-top: 1ex;">', $_SESSION['ban']['cannot_post']['reason'], '</div>';
3894
+			}
3682 3895
 
3683
-			if (!empty($_SESSION['ban']['expire_time']))
3684
-				echo '
3896
+			if (!empty($_SESSION['ban']['expire_time'])) {
3897
+							echo '
3685 3898
 					<div>', sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)), '</div>';
3686
-			else
3687
-				echo '
3899
+			} else {
3900
+							echo '
3688 3901
 					<div>', $txt['your_ban_expires_never'], '</div>';
3902
+			}
3689 3903
 
3690 3904
 			echo '
3691 3905
 				</div>';
@@ -3701,8 +3915,9 @@  discard block
 block discarded – undo
3701 3915
 	global $forum_copyright, $software_year, $forum_version;
3702 3916
 
3703 3917
 	// Don't display copyright for things like SSI.
3704
-	if (!isset($forum_version) || !isset($software_year))
3705
-		return;
3918
+	if (!isset($forum_version) || !isset($software_year)) {
3919
+			return;
3920
+	}
3706 3921
 
3707 3922
 	// Put in the version...
3708 3923
 	printf($forum_copyright, $forum_version, $software_year);
@@ -3720,9 +3935,10 @@  discard block
 block discarded – undo
3720 3935
 	$context['load_time'] = round(microtime(true) - $time_start, 3);
3721 3936
 	$context['load_queries'] = $db_count;
3722 3937
 
3723
-	foreach (array_reverse($context['template_layers']) as $layer)
3724
-		loadSubTemplate($layer . '_below', true);
3725
-}
3938
+	foreach (array_reverse($context['template_layers']) as $layer) {
3939
+			loadSubTemplate($layer . '_below', true);
3940
+	}
3941
+	}
3726 3942
 
3727 3943
 /**
3728 3944
  * Output the Javascript files
@@ -3756,8 +3972,7 @@  discard block
 block discarded – undo
3756 3972
 			{
3757 3973
 				echo '
3758 3974
 		var ', $key, ';';
3759
-			}
3760
-			else
3975
+			} else
3761 3976
 			{
3762 3977
 				echo '
3763 3978
 		var ', $key, ' = ', $value, ';';
@@ -3776,27 +3991,29 @@  discard block
 block discarded – undo
3776 3991
 		foreach ($context['javascript_files'] as $id => $js_file)
3777 3992
 		{
3778 3993
 			// Last minute call! allow theme authors to disable single files.
3779
-			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3780
-				continue;
3994
+			if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
3995
+							continue;
3996
+			}
3781 3997
 
3782 3998
 			// By default files don't get minimized unless the file explicitly says so!
3783 3999
 			if (!empty($js_file['options']['minimize']) && !empty($modSettings['minimize_files']))
3784 4000
 			{
3785
-				if (!empty($js_file['options']['async']))
3786
-					$toMinify['async'][] = $js_file;
3787
-				elseif (!empty($js_file['options']['defer']))
3788
-					$toMinify['defer'][] = $js_file;
3789
-				else
3790
-					$toMinify['standard'][] = $js_file;
4001
+				if (!empty($js_file['options']['async'])) {
4002
+									$toMinify['async'][] = $js_file;
4003
+				} elseif (!empty($js_file['options']['defer'])) {
4004
+									$toMinify['defer'][] = $js_file;
4005
+				} else {
4006
+									$toMinify['standard'][] = $js_file;
4007
+				}
3791 4008
 
3792 4009
 				// Grab a random seed.
3793
-				if (!isset($minSeed) && isset($js_file['options']['seed']))
3794
-					$minSeed = $js_file['options']['seed'];
3795
-			}
3796
-
3797
-			else
3798
-				echo '
4010
+				if (!isset($minSeed) && isset($js_file['options']['seed'])) {
4011
+									$minSeed = $js_file['options']['seed'];
4012
+				}
4013
+			} else {
4014
+							echo '
3799 4015
 	<script src="', $js_file['fileUrl'], '"', !empty($js_file['options']['async']) ? ' async' : '', !empty($js_file['options']['defer']) ? ' defer' : '', '></script>';
4016
+			}
3800 4017
 		}
3801 4018
 
3802 4019
 		foreach ($toMinify as $js_files)
@@ -3807,9 +4024,10 @@  discard block
 block discarded – undo
3807 4024
 
3808 4025
 				$minSuccessful = array_keys($result) === array('smf_minified');
3809 4026
 
3810
-				foreach ($result as $minFile)
3811
-					echo '
4027
+				foreach ($result as $minFile) {
4028
+									echo '
3812 4029
 	<script src="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '"', !empty($minFile['options']['async']) ? ' async' : '', !empty($minFile['options']['defer']) ? ' defer' : '', '></script>';
4030
+				}
3813 4031
 			}
3814 4032
 		}
3815 4033
 	}
@@ -3823,8 +4041,9 @@  discard block
 block discarded – undo
3823 4041
 <script>
3824 4042
 window.addEventListener("DOMContentLoaded", function() {';
3825 4043
 
3826
-			foreach ($context['javascript_inline']['defer'] as $js_code)
3827
-				echo $js_code;
4044
+			foreach ($context['javascript_inline']['defer'] as $js_code) {
4045
+							echo $js_code;
4046
+			}
3828 4047
 
3829 4048
 			echo '
3830 4049
 });
@@ -3836,8 +4055,9 @@  discard block
 block discarded – undo
3836 4055
 			echo '
3837 4056
 	<script>';
3838 4057
 
3839
-			foreach ($context['javascript_inline']['standard'] as $js_code)
3840
-				echo $js_code;
4058
+			foreach ($context['javascript_inline']['standard'] as $js_code) {
4059
+							echo $js_code;
4060
+			}
3841 4061
 
3842 4062
 			echo '
3843 4063
 	</script>';
@@ -3865,23 +4085,26 @@  discard block
 block discarded – undo
3865 4085
 	foreach ($context['css_files'] as $id => $file)
3866 4086
 	{
3867 4087
 		// Last minute call! allow theme authors to disable single files.
3868
-		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files']))
3869
-			continue;
4088
+		if (!empty($settings['disable_files']) && in_array($id, $settings['disable_files'])) {
4089
+					continue;
4090
+		}
3870 4091
 
3871 4092
 		// Files are minimized unless they explicitly opt out.
3872
-		if (!isset($file['options']['minimize']))
3873
-			$file['options']['minimize'] = true;
4093
+		if (!isset($file['options']['minimize'])) {
4094
+					$file['options']['minimize'] = true;
4095
+		}
3874 4096
 
3875 4097
 		if (!empty($file['options']['minimize']) && !empty($modSettings['minimize_files']))
3876 4098
 		{
3877 4099
 			$toMinify[] = $file;
3878 4100
 
3879 4101
 			// Grab a random seed.
3880
-			if (!isset($minSeed) && isset($file['options']['seed']))
3881
-				$minSeed = $file['options']['seed'];
4102
+			if (!isset($minSeed) && isset($file['options']['seed'])) {
4103
+							$minSeed = $file['options']['seed'];
4104
+			}
4105
+		} else {
4106
+					$normal[] = $file['fileUrl'];
3882 4107
 		}
3883
-		else
3884
-			$normal[] = $file['fileUrl'];
3885 4108
 	}
3886 4109
 
3887 4110
 	if (!empty($toMinify))
@@ -3890,23 +4113,26 @@  discard block
 block discarded – undo
3890 4113
 
3891 4114
 		$minSuccessful = array_keys($result) === array('smf_minified');
3892 4115
 
3893
-		foreach ($result as $minFile)
3894
-			echo '
4116
+		foreach ($result as $minFile) {
4117
+					echo '
3895 4118
 	<link rel="stylesheet" href="', $minFile['fileUrl'], $minSuccessful && isset($minSeed) ? $minSeed : '', '">';
4119
+		}
3896 4120
 	}
3897 4121
 
3898 4122
 	// Print the rest after the minified files.
3899
-	if (!empty($normal))
3900
-		foreach ($normal as $nf)
4123
+	if (!empty($normal)) {
4124
+			foreach ($normal as $nf)
3901 4125
 			echo '
3902 4126
 	<link rel="stylesheet" href="', $nf ,'">';
4127
+	}
3903 4128
 
3904 4129
 	if ($db_show_debug === true)
3905 4130
 	{
3906 4131
 		// Try to keep only what's useful.
3907 4132
 		$repl = array($boardurl . '/Themes/' => '', $boardurl . '/' => '');
3908
-		foreach ($context['css_files'] as $file)
3909
-			$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4133
+		foreach ($context['css_files'] as $file) {
4134
+					$context['debug']['sheets'][] = strtr($file['fileName'], $repl);
4135
+		}
3910 4136
 	}
3911 4137
 
3912 4138
 	if (!empty($context['css_header']))
@@ -3914,9 +4140,10 @@  discard block
 block discarded – undo
3914 4140
 		echo '
3915 4141
 	<style>';
3916 4142
 
3917
-		foreach ($context['css_header'] as $css)
3918
-			echo $css .'
4143
+		foreach ($context['css_header'] as $css) {
4144
+					echo $css .'
3919 4145
 	';
4146
+		}
3920 4147
 
3921 4148
 		echo'
3922 4149
 	</style>';
@@ -3939,8 +4166,9 @@  discard block
 block discarded – undo
3939 4166
 	$type = !empty($type) && in_array($type, $types) ? $type : false;
3940 4167
 	$data = is_array($data) ? $data : array();
3941 4168
 
3942
-	if (empty($type) || empty($data))
3943
-		return $data;
4169
+	if (empty($type) || empty($data)) {
4170
+			return $data;
4171
+	}
3944 4172
 
3945 4173
 	// Different pages include different files, so we use a hash to label the different combinations
3946 4174
 	$hash = md5(implode(' ', array_map(function($file) { return $file['filePath'] . (int) @filesize($file['filePath']) . (int) @filemtime($file['filePath']); }, $data)));
@@ -3949,13 +4177,14 @@  discard block
 block discarded – undo
3949 4177
 	list($toCache, $async, $defer) = array_pad((array) cache_get_data('minimized_' . $settings['theme_id'] . '_' . $type . '_' . $hash, 86400), 3, null);
3950 4178
 
3951 4179
 	// Already done?
3952
-	if (!empty($toCache))
3953
-		return array('smf_minified' => array(
4180
+	if (!empty($toCache)) {
4181
+			return array('smf_minified' => array(
3954 4182
 			'fileUrl' => $settings['theme_url'] . '/' . ($type == 'css' ? 'css' : 'scripts') . '/' . basename($toCache),
3955 4183
 			'filePath' => $toCache,
3956 4184
 			'fileName' => basename($toCache),
3957 4185
 			'options' => array('async' => !empty($async), 'defer' => !empty($defer)),
3958 4186
 		));
4187
+	}
3959 4188
 
3960 4189
 
3961 4190
 	// No namespaces, sorry!
@@ -3985,9 +4214,9 @@  discard block
 block discarded – undo
3985 4214
 
3986 4215
 	foreach ($data as $id => $file)
3987 4216
 	{
3988
-		if (empty($file['filePath']))
3989
-			$toAdd = false;
3990
-		else
4217
+		if (empty($file['filePath'])) {
4218
+					$toAdd = false;
4219
+		} else
3991 4220
 		{
3992 4221
 			$seed = isset($file['options']['seed']) ? $file['options']['seed'] : '';
3993 4222
 			$tempFile = str_replace($seed, '', $file['filePath']);
@@ -3995,12 +4224,14 @@  discard block
 block discarded – undo
3995 4224
 		}
3996 4225
 
3997 4226
 		// A minified script should only be loaded asynchronously if all its components wanted to be.
3998
-		if (empty($file['options']['async']))
3999
-			$async = false;
4227
+		if (empty($file['options']['async'])) {
4228
+					$async = false;
4229
+		}
4000 4230
 
4001 4231
 		// A minified script should only be deferred if all its components wanted to be.
4002
-		if (empty($file['options']['defer']))
4003
-			$defer = false;
4232
+		if (empty($file['options']['defer'])) {
4233
+					$defer = false;
4234
+		}
4004 4235
 
4005 4236
 		// The file couldn't be located so it won't be added. Log this error.
4006 4237
 		if (empty($toAdd))
@@ -4066,12 +4297,14 @@  discard block
 block discarded – undo
4066 4297
 			foreach (glob(rtrim($theme['dir'], '/') . '/' . ($type == 'css' ? 'css' : 'scripts') . '/minified*.' . $type) as $filename)
4067 4298
 			{
4068 4299
 				// Remove the cache entry
4069
-				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches))
4070
-					cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4300
+				if (preg_match('~([a-zA-Z0-9]+)\.' . $type . '$~', $filename, $matches)) {
4301
+									cache_put_data('minimized_' . $theme['id'] . '_' . $type . '_' . $matches[1], null);
4302
+				}
4071 4303
 
4072 4304
 				// Try to delete the file. Add it to our error list if it fails.
4073
-				if (!@unlink($filename))
4074
-					$not_deleted[] = $filename;
4305
+				if (!@unlink($filename)) {
4306
+									$not_deleted[] = $filename;
4307
+				}
4075 4308
 			}
4076 4309
 		}
4077 4310
 	}
@@ -4103,8 +4336,9 @@  discard block
 block discarded – undo
4103 4336
 	global $modSettings, $smcFunc;
4104 4337
 
4105 4338
 	// Just make up a nice hash...
4106
-	if ($new)
4107
-		return sha1(md5($filename . time()) . mt_rand());
4339
+	if ($new) {
4340
+			return sha1(md5($filename . time()) . mt_rand());
4341
+	}
4108 4342
 
4109 4343
 	// Just make sure that attachment id is only a int
4110 4344
 	$attachment_id = (int) $attachment_id;
@@ -4121,23 +4355,25 @@  discard block
 block discarded – undo
4121 4355
 				'id_attach' => $attachment_id,
4122 4356
 			));
4123 4357
 
4124
-		if ($smcFunc['db_num_rows']($request) === 0)
4125
-			return false;
4358
+		if ($smcFunc['db_num_rows']($request) === 0) {
4359
+					return false;
4360
+		}
4126 4361
 
4127 4362
 		list ($file_hash) = $smcFunc['db_fetch_row']($request);
4128 4363
 		$smcFunc['db_free_result']($request);
4129 4364
 	}
4130 4365
 
4131 4366
 	// Still no hash? mmm...
4132
-	if (empty($file_hash))
4133
-		$file_hash = sha1(md5($filename . time()) . mt_rand());
4367
+	if (empty($file_hash)) {
4368
+			$file_hash = sha1(md5($filename . time()) . mt_rand());
4369
+	}
4134 4370
 
4135 4371
 	// Are we using multiple directories?
4136
-	if (is_array($modSettings['attachmentUploadDir']))
4137
-		$path = $modSettings['attachmentUploadDir'][$dir];
4138
-
4139
-	else
4140
-		$path = $modSettings['attachmentUploadDir'];
4372
+	if (is_array($modSettings['attachmentUploadDir'])) {
4373
+			$path = $modSettings['attachmentUploadDir'][$dir];
4374
+	} else {
4375
+			$path = $modSettings['attachmentUploadDir'];
4376
+	}
4141 4377
 
4142 4378
 	return $path . '/' . $attachment_id . '_' . $file_hash .'.dat';
4143 4379
 }
@@ -4152,8 +4388,9 @@  discard block
 block discarded – undo
4152 4388
 function ip2range($fullip)
4153 4389
 {
4154 4390
 	// Pretend that 'unknown' is 255.255.255.255. (since that can't be an IP anyway.)
4155
-	if ($fullip == 'unknown')
4156
-		$fullip = '255.255.255.255';
4391
+	if ($fullip == 'unknown') {
4392
+			$fullip = '255.255.255.255';
4393
+	}
4157 4394
 
4158 4395
 	$ip_parts = explode('-', $fullip);
4159 4396
 	$ip_array = array();
@@ -4177,10 +4414,11 @@  discard block
 block discarded – undo
4177 4414
 		$ip_array['low'] = $ip_parts[0];
4178 4415
 		$ip_array['high'] = $ip_parts[1];
4179 4416
 		return $ip_array;
4180
-	}
4181
-	elseif (count($ip_parts) == 2) // if ip 22.22.*-22.22.*
4417
+	} elseif (count($ip_parts) == 2) {
4418
+		// if ip 22.22.*-22.22.*
4182 4419
 	{
4183 4420
 		$valid_low = isValidIP($ip_parts[0]);
4421
+	}
4184 4422
 		$valid_high = isValidIP($ip_parts[1]);
4185 4423
 		$count = 0;
4186 4424
 		$mode = (preg_match('/:/',$ip_parts[0]) > 0 ? ':' : '.');
@@ -4195,7 +4433,9 @@  discard block
 block discarded – undo
4195 4433
 				$ip_parts[0] .= $mode . $min;
4196 4434
 				$valid_low = isValidIP($ip_parts[0]);
4197 4435
 				$count++;
4198
-				if ($count > 9) break;
4436
+				if ($count > 9) {
4437
+					break;
4438
+				}
4199 4439
 			}
4200 4440
 		}
4201 4441
 
@@ -4209,7 +4449,9 @@  discard block
 block discarded – undo
4209 4449
 				$ip_parts[1] .= $mode . $max;
4210 4450
 				$valid_high = isValidIP($ip_parts[1]);
4211 4451
 				$count++;
4212
-				if ($count > 9) break;
4452
+				if ($count > 9) {
4453
+					break;
4454
+				}
4213 4455
 			}
4214 4456
 		}
4215 4457
 
@@ -4233,46 +4475,54 @@  discard block
 block discarded – undo
4233 4475
 {
4234 4476
 	global $modSettings;
4235 4477
 
4236
-	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null)
4237
-		return $host;
4478
+	if (($host = cache_get_data('hostlookup-' . $ip, 600)) !== null) {
4479
+			return $host;
4480
+	}
4238 4481
 	$t = microtime();
4239 4482
 
4240 4483
 	// Try the Linux host command, perhaps?
4241 4484
 	if (!isset($host) && (strpos(strtolower(PHP_OS), 'win') === false || strpos(strtolower(PHP_OS), 'darwin') !== false) && mt_rand(0, 1) == 1)
4242 4485
 	{
4243
-		if (!isset($modSettings['host_to_dis']))
4244
-			$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4245
-		else
4246
-			$test = @shell_exec('host ' . @escapeshellarg($ip));
4486
+		if (!isset($modSettings['host_to_dis'])) {
4487
+					$test = @shell_exec('host -W 1 ' . @escapeshellarg($ip));
4488
+		} else {
4489
+					$test = @shell_exec('host ' . @escapeshellarg($ip));
4490
+		}
4247 4491
 
4248 4492
 		// Did host say it didn't find anything?
4249
-		if (strpos($test, 'not found') !== false)
4250
-			$host = '';
4493
+		if (strpos($test, 'not found') !== false) {
4494
+					$host = '';
4495
+		}
4251 4496
 		// Invalid server option?
4252
-		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis']))
4253
-			updateSettings(array('host_to_dis' => 1));
4497
+		elseif ((strpos($test, 'invalid option') || strpos($test, 'Invalid query name 1')) && !isset($modSettings['host_to_dis'])) {
4498
+					updateSettings(array('host_to_dis' => 1));
4499
+		}
4254 4500
 		// Maybe it found something, after all?
4255
-		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1)
4256
-			$host = $match[1];
4501
+		elseif (preg_match('~\s([^\s]+?)\.\s~', $test, $match) == 1) {
4502
+					$host = $match[1];
4503
+		}
4257 4504
 	}
4258 4505
 
4259 4506
 	// This is nslookup; usually only Windows, but possibly some Unix?
4260 4507
 	if (!isset($host) && stripos(PHP_OS, 'win') !== false && strpos(strtolower(PHP_OS), 'darwin') === false && mt_rand(0, 1) == 1)
4261 4508
 	{
4262 4509
 		$test = @shell_exec('nslookup -timeout=1 ' . @escapeshellarg($ip));
4263
-		if (strpos($test, 'Non-existent domain') !== false)
4264
-			$host = '';
4265
-		elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1)
4266
-			$host = $match[1];
4510
+		if (strpos($test, 'Non-existent domain') !== false) {
4511
+					$host = '';
4512
+		} elseif (preg_match('~Name:\s+([^\s]+)~', $test, $match) == 1) {
4513
+					$host = $match[1];
4514
+		}
4267 4515
 	}
4268 4516
 
4269 4517
 	// This is the last try :/.
4270
-	if (!isset($host) || $host === false)
4271
-		$host = @gethostbyaddr($ip);
4518
+	if (!isset($host) || $host === false) {
4519
+			$host = @gethostbyaddr($ip);
4520
+	}
4272 4521
 
4273 4522
 	// It took a long time, so let's cache it!
4274
-	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5)
4275
-		cache_put_data('hostlookup-' . $ip, $host, 600);
4523
+	if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $t)) > 0.5) {
4524
+			cache_put_data('hostlookup-' . $ip, $host, 600);
4525
+	}
4276 4526
 
4277 4527
 	return $host;
4278 4528
 }
@@ -4308,20 +4558,21 @@  discard block
 block discarded – undo
4308 4558
 			{
4309 4559
 				$encrypted = substr(crypt($word, 'uk'), 2, $max_chars);
4310 4560
 				$total = 0;
4311
-				for ($i = 0; $i < $max_chars; $i++)
4312
-					$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4561
+				for ($i = 0; $i < $max_chars; $i++) {
4562
+									$total += $possible_chars[ord($encrypted{$i})] * pow(63, $i);
4563
+				}
4313 4564
 				$returned_ints[] = $max_chars == 4 ? min($total, 16777215) : $total;
4314 4565
 			}
4315 4566
 		}
4316 4567
 		return array_unique($returned_ints);
4317
-	}
4318
-	else
4568
+	} else
4319 4569
 	{
4320 4570
 		// Trim characters before and after and add slashes for database insertion.
4321 4571
 		$returned_words = array();
4322
-		foreach ($words as $word)
4323
-			if (($word = trim($word, '-_\'')) !== '')
4572
+		foreach ($words as $word) {
4573
+					if (($word = trim($word, '-_\'')) !== '')
4324 4574
 				$returned_words[] = $max_chars === null ? $word : substr($word, 0, $max_chars);
4575
+		}
4325 4576
 
4326 4577
 		// Filter out all words that occur more than once.
4327 4578
 		return array_unique($returned_words);
@@ -4343,16 +4594,18 @@  discard block
 block discarded – undo
4343 4594
 	global $settings, $txt;
4344 4595
 
4345 4596
 	// Does the current loaded theme have this and we are not forcing the usage of this function?
4346
-	if (function_exists('template_create_button') && !$force_use)
4347
-		return template_create_button($name, $alt, $label = '', $custom = '');
4597
+	if (function_exists('template_create_button') && !$force_use) {
4598
+			return template_create_button($name, $alt, $label = '', $custom = '');
4599
+	}
4348 4600
 
4349
-	if (!$settings['use_image_buttons'])
4350
-		return $txt[$alt];
4351
-	elseif (!empty($settings['use_buttons']))
4352
-		return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4353
-	else
4354
-		return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4355
-}
4601
+	if (!$settings['use_image_buttons']) {
4602
+			return $txt[$alt];
4603
+	} elseif (!empty($settings['use_buttons'])) {
4604
+			return '<span class="generic_icons ' . $name . '" alt="' . $txt[$alt] . '"></span>' . ($label != '' ? '&nbsp;<strong>' . $txt[$label] . '</strong>' : '');
4605
+	} else {
4606
+			return '<img src="' . $settings['lang_images_url'] . '/' . $name . '" alt="' . $txt[$alt] . '" ' . $custom . '>';
4607
+	}
4608
+	}
4356 4609
 
4357 4610
 /**
4358 4611
  * Sets up all of the top menu buttons
@@ -4395,9 +4648,10 @@  discard block
 block discarded – undo
4395 4648
 	var user_menus = new smc_PopupMenu();
4396 4649
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");
4397 4650
 	user_menus.add("alerts", "' . $scripturl . '?action=profile;area=alerts_popup;u='. $context['user']['id'] .'");', true);
4398
-		if ($context['allow_pm'])
4399
-			addInlineJavaScript('
4651
+		if ($context['allow_pm']) {
4652
+					addInlineJavaScript('
4400 4653
 	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
4654
+		}
4401 4655
 
4402 4656
 		if (!empty($modSettings['enable_ajax_alerts']))
4403 4657
 		{
@@ -4557,88 +4811,96 @@  discard block
 block discarded – undo
4557 4811
 
4558 4812
 		// Now we put the buttons in the context so the theme can use them.
4559 4813
 		$menu_buttons = array();
4560
-		foreach ($buttons as $act => $button)
4561
-			if (!empty($button['show']))
4814
+		foreach ($buttons as $act => $button) {
4815
+					if (!empty($button['show']))
4562 4816
 			{
4563 4817
 				$button['active_button'] = false;
4818
+		}
4564 4819
 
4565 4820
 				// This button needs some action.
4566
-				if (isset($button['action_hook']))
4567
-					$needs_action_hook = true;
4821
+				if (isset($button['action_hook'])) {
4822
+									$needs_action_hook = true;
4823
+				}
4568 4824
 
4569 4825
 				// Make sure the last button truly is the last button.
4570 4826
 				if (!empty($button['is_last']))
4571 4827
 				{
4572
-					if (isset($last_button))
4573
-						unset($menu_buttons[$last_button]['is_last']);
4828
+					if (isset($last_button)) {
4829
+											unset($menu_buttons[$last_button]['is_last']);
4830
+					}
4574 4831
 					$last_button = $act;
4575 4832
 				}
4576 4833
 
4577 4834
 				// Go through the sub buttons if there are any.
4578
-				if (!empty($button['sub_buttons']))
4579
-					foreach ($button['sub_buttons'] as $key => $subbutton)
4835
+				if (!empty($button['sub_buttons'])) {
4836
+									foreach ($button['sub_buttons'] as $key => $subbutton)
4580 4837
 					{
4581 4838
 						if (empty($subbutton['show']))
4582 4839
 							unset($button['sub_buttons'][$key]);
4840
+				}
4583 4841
 
4584 4842
 						// 2nd level sub buttons next...
4585 4843
 						if (!empty($subbutton['sub_buttons']))
4586 4844
 						{
4587 4845
 							foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2)
4588 4846
 							{
4589
-								if (empty($sub_button2['show']))
4590
-									unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4847
+								if (empty($sub_button2['show'])) {
4848
+																	unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
4849
+								}
4591 4850
 							}
4592 4851
 						}
4593 4852
 					}
4594 4853
 
4595 4854
 				// Does this button have its own icon?
4596
-				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon']))
4597
-					$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4598
-				elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon']))
4599
-					$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4600
-				elseif (isset($button['icon']))
4601
-					$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4602
-				else
4603
-					$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4855
+				if (isset($button['icon']) && file_exists($settings['theme_dir'] . '/images/' . $button['icon'])) {
4856
+									$button['icon'] = '<img src="' . $settings['images_url'] . '/' . $button['icon'] . '" alt="">';
4857
+				} elseif (isset($button['icon']) && file_exists($settings['default_theme_dir'] . '/images/' . $button['icon'])) {
4858
+									$button['icon'] = '<img src="' . $settings['default_images_url'] . '/' . $button['icon'] . '" alt="">';
4859
+				} elseif (isset($button['icon'])) {
4860
+									$button['icon'] = '<span class="generic_icons ' . $button['icon'] . '"></span>';
4861
+				} else {
4862
+									$button['icon'] = '<span class="generic_icons ' . $act . '"></span>';
4863
+				}
4604 4864
 
4605 4865
 				$menu_buttons[$act] = $button;
4606 4866
 			}
4607 4867
 
4608
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
4609
-			cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4868
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
4869
+					cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
4870
+		}
4610 4871
 	}
4611 4872
 
4612 4873
 	$context['menu_buttons'] = $menu_buttons;
4613 4874
 
4614 4875
 	// Logging out requires the session id in the url.
4615
-	if (isset($context['menu_buttons']['logout']))
4616
-		$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4876
+	if (isset($context['menu_buttons']['logout'])) {
4877
+			$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
4878
+	}
4617 4879
 
4618 4880
 	// Figure out which action we are doing so we can set the active tab.
4619 4881
 	// Default to home.
4620 4882
 	$current_action = 'home';
4621 4883
 
4622
-	if (isset($context['menu_buttons'][$context['current_action']]))
4623
-		$current_action = $context['current_action'];
4624
-	elseif ($context['current_action'] == 'search2')
4625
-		$current_action = 'search';
4626
-	elseif ($context['current_action'] == 'theme')
4627
-		$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4628
-	elseif ($context['current_action'] == 'register2')
4629
-		$current_action = 'register';
4630
-	elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder'))
4631
-		$current_action = 'login';
4632
-	elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center'])
4633
-		$current_action = 'moderate';
4884
+	if (isset($context['menu_buttons'][$context['current_action']])) {
4885
+			$current_action = $context['current_action'];
4886
+	} elseif ($context['current_action'] == 'search2') {
4887
+			$current_action = 'search';
4888
+	} elseif ($context['current_action'] == 'theme') {
4889
+			$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
4890
+	} elseif ($context['current_action'] == 'register2') {
4891
+			$current_action = 'register';
4892
+	} elseif ($context['current_action'] == 'login2' || ($user_info['is_guest'] && $context['current_action'] == 'reminder')) {
4893
+			$current_action = 'login';
4894
+	} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
4895
+			$current_action = 'moderate';
4896
+	}
4634 4897
 
4635 4898
 	// There are certain exceptions to the above where we don't want anything on the menu highlighted.
4636 4899
 	if ($context['current_action'] == 'profile' && !empty($context['user']['is_owner']))
4637 4900
 	{
4638 4901
 		$current_action = !empty($_GET['area']) && $_GET['area'] == 'showalerts' ? 'self_alerts' : 'self_profile';
4639 4902
 		$context[$current_action] = true;
4640
-	}
4641
-	elseif ($context['current_action'] == 'pm')
4903
+	} elseif ($context['current_action'] == 'pm')
4642 4904
 	{
4643 4905
 		$current_action = 'self_pm';
4644 4906
 		$context['self_pm'] = true;
@@ -4695,12 +4957,14 @@  discard block
 block discarded – undo
4695 4957
 	}
4696 4958
 
4697 4959
 	// Not all actions are simple.
4698
-	if (!empty($needs_action_hook))
4699
-		call_integration_hook('integrate_current_action', array(&$current_action));
4960
+	if (!empty($needs_action_hook)) {
4961
+			call_integration_hook('integrate_current_action', array(&$current_action));
4962
+	}
4700 4963
 
4701
-	if (isset($context['menu_buttons'][$current_action]))
4702
-		$context['menu_buttons'][$current_action]['active_button'] = true;
4703
-}
4964
+	if (isset($context['menu_buttons'][$current_action])) {
4965
+			$context['menu_buttons'][$current_action]['active_button'] = true;
4966
+	}
4967
+	}
4704 4968
 
4705 4969
 /**
4706 4970
  * Generate a random seed and ensure it's stored in settings.
@@ -4724,30 +4988,35 @@  discard block
 block discarded – undo
4724 4988
 	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
4725 4989
 	global $context, $txt;
4726 4990
 
4727
-	if ($db_show_debug === true)
4728
-		$context['debug']['hooks'][] = $hook;
4991
+	if ($db_show_debug === true) {
4992
+			$context['debug']['hooks'][] = $hook;
4993
+	}
4729 4994
 
4730 4995
 	// Need to have some control.
4731
-	if (!isset($context['instances']))
4732
-		$context['instances'] = array();
4996
+	if (!isset($context['instances'])) {
4997
+			$context['instances'] = array();
4998
+	}
4733 4999
 
4734 5000
 	$results = array();
4735
-	if (empty($modSettings[$hook]))
4736
-		return $results;
5001
+	if (empty($modSettings[$hook])) {
5002
+			return $results;
5003
+	}
4737 5004
 
4738 5005
 	$functions = explode(',', $modSettings[$hook]);
4739 5006
 	// Loop through each function.
4740 5007
 	foreach ($functions as $function)
4741 5008
 	{
4742 5009
 		// Hook has been marked as "disabled". Skip it!
4743
-		if (strpos($function, '!') !== false)
4744
-			continue;
5010
+		if (strpos($function, '!') !== false) {
5011
+					continue;
5012
+		}
4745 5013
 
4746 5014
 		$call = call_helper($function, true);
4747 5015
 
4748 5016
 		// Is it valid?
4749
-		if (!empty($call))
4750
-			$results[$function] = call_user_func_array($call, $parameters);
5017
+		if (!empty($call)) {
5018
+					$results[$function] = call_user_func_array($call, $parameters);
5019
+		}
4751 5020
 
4752 5021
 		// Whatever it was suppose to call, it failed :(
4753 5022
 		elseif (!empty($function))
@@ -4763,8 +5032,9 @@  discard block
 block discarded – undo
4763 5032
 			}
4764 5033
 
4765 5034
 			// "Assume" the file resides on $boarddir somewhere...
4766
-			else
4767
-				log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5035
+			else {
5036
+							log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
5037
+			}
4768 5038
 		}
4769 5039
 	}
4770 5040
 
@@ -4786,12 +5056,14 @@  discard block
 block discarded – undo
4786 5056
 	global $smcFunc, $modSettings;
4787 5057
 
4788 5058
 	// Any objects?
4789
-	if ($object)
4790
-		$function = $function . '#';
5059
+	if ($object) {
5060
+			$function = $function . '#';
5061
+	}
4791 5062
 
4792 5063
 	// Any files  to load?
4793
-	if (!empty($file) && is_string($file))
4794
-		$function = $file . (!empty($function) ? '|' . $function : '');
5064
+	if (!empty($file) && is_string($file)) {
5065
+			$function = $file . (!empty($function) ? '|' . $function : '');
5066
+	}
4795 5067
 
4796 5068
 	// Get the correct string.
4797 5069
 	$integration_call = $function;
@@ -4813,13 +5085,14 @@  discard block
 block discarded – undo
4813 5085
 		if (!empty($current_functions))
4814 5086
 		{
4815 5087
 			$current_functions = explode(',', $current_functions);
4816
-			if (in_array($integration_call, $current_functions))
4817
-				return;
5088
+			if (in_array($integration_call, $current_functions)) {
5089
+							return;
5090
+			}
4818 5091
 
4819 5092
 			$permanent_functions = array_merge($current_functions, array($integration_call));
5093
+		} else {
5094
+					$permanent_functions = array($integration_call);
4820 5095
 		}
4821
-		else
4822
-			$permanent_functions = array($integration_call);
4823 5096
 
4824 5097
 		updateSettings(array($hook => implode(',', $permanent_functions)));
4825 5098
 	}
@@ -4828,8 +5101,9 @@  discard block
 block discarded – undo
4828 5101
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4829 5102
 
4830 5103
 	// Do nothing, if it's already there.
4831
-	if (in_array($integration_call, $functions))
4832
-		return;
5104
+	if (in_array($integration_call, $functions)) {
5105
+			return;
5106
+	}
4833 5107
 
4834 5108
 	$functions[] = $integration_call;
4835 5109
 	$modSettings[$hook] = implode(',', $functions);
@@ -4852,12 +5126,14 @@  discard block
 block discarded – undo
4852 5126
 	global $smcFunc, $modSettings;
4853 5127
 
4854 5128
 	// Any objects?
4855
-	if ($object)
4856
-		$function = $function . '#';
5129
+	if ($object) {
5130
+			$function = $function . '#';
5131
+	}
4857 5132
 
4858 5133
 	// Any files  to load?
4859
-	if (!empty($file) && is_string($file))
4860
-		$function = $file . '|' . $function;
5134
+	if (!empty($file) && is_string($file)) {
5135
+			$function = $file . '|' . $function;
5136
+	}
4861 5137
 
4862 5138
 	// Get the correct string.
4863 5139
 	$integration_call = $function;
@@ -4878,16 +5154,18 @@  discard block
 block discarded – undo
4878 5154
 	{
4879 5155
 		$current_functions = explode(',', $current_functions);
4880 5156
 
4881
-		if (in_array($integration_call, $current_functions))
4882
-			updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5157
+		if (in_array($integration_call, $current_functions)) {
5158
+					updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call)))));
5159
+		}
4883 5160
 	}
4884 5161
 
4885 5162
 	// Turn the function list into something usable.
4886 5163
 	$functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]);
4887 5164
 
4888 5165
 	// You can only remove it if it's available.
4889
-	if (!in_array($integration_call, $functions))
4890
-		return;
5166
+	if (!in_array($integration_call, $functions)) {
5167
+			return;
5168
+	}
4891 5169
 
4892 5170
 	$functions = array_diff($functions, array($integration_call));
4893 5171
 	$modSettings[$hook] = implode(',', $functions);
@@ -4908,17 +5186,20 @@  discard block
 block discarded – undo
4908 5186
 	global $context, $smcFunc, $txt, $db_show_debug;
4909 5187
 
4910 5188
 	// Really?
4911
-	if (empty($string))
4912
-		return false;
5189
+	if (empty($string)) {
5190
+			return false;
5191
+	}
4913 5192
 
4914 5193
 	// An array? should be a "callable" array IE array(object/class, valid_callable).
4915 5194
 	// A closure? should be a callable one.
4916
-	if (is_array($string) || $string instanceof Closure)
4917
-		return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5195
+	if (is_array($string) || $string instanceof Closure) {
5196
+			return $return ? $string : (is_callable($string) ? call_user_func($string) : false);
5197
+	}
4918 5198
 
4919 5199
 	// No full objects, sorry! pass a method or a property instead!
4920
-	if (is_object($string))
4921
-		return false;
5200
+	if (is_object($string)) {
5201
+			return false;
5202
+	}
4922 5203
 
4923 5204
 	// Stay vitaminized my friends...
4924 5205
 	$string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string));
@@ -4927,8 +5208,9 @@  discard block
 block discarded – undo
4927 5208
 	$string = load_file($string);
4928 5209
 
4929 5210
 	// Loaded file failed
4930
-	if (empty($string))
4931
-		return false;
5211
+	if (empty($string)) {
5212
+			return false;
5213
+	}
4932 5214
 
4933 5215
 	// Found a method.
4934 5216
 	if (strpos($string, '::') !== false)
@@ -4949,8 +5231,9 @@  discard block
 block discarded – undo
4949 5231
 				// Add another one to the list.
4950 5232
 				if ($db_show_debug === true)
4951 5233
 				{
4952
-					if (!isset($context['debug']['instances']))
4953
-						$context['debug']['instances'] = array();
5234
+					if (!isset($context['debug']['instances'])) {
5235
+											$context['debug']['instances'] = array();
5236
+					}
4954 5237
 
4955 5238
 					$context['debug']['instances'][$class] = $class;
4956 5239
 				}
@@ -4960,13 +5243,15 @@  discard block
 block discarded – undo
4960 5243
 		}
4961 5244
 
4962 5245
 		// Right then. This is a call to a static method.
4963
-		else
4964
-			$func = array($class, $method);
5246
+		else {
5247
+					$func = array($class, $method);
5248
+		}
4965 5249
 	}
4966 5250
 
4967 5251
 	// Nope! just a plain regular function.
4968
-	else
4969
-		$func = $string;
5252
+	else {
5253
+			$func = $string;
5254
+	}
4970 5255
 
4971 5256
 	// Right, we got what we need, time to do some checks.
4972 5257
 	if (!is_callable($func, false, $callable_name))
@@ -4982,17 +5267,18 @@  discard block
 block discarded – undo
4982 5267
 	else
4983 5268
 	{
4984 5269
 		// What are we gonna do about it?
4985
-		if ($return)
4986
-			return $func;
5270
+		if ($return) {
5271
+					return $func;
5272
+		}
4987 5273
 
4988 5274
 		// If this is a plain function, avoid the heat of calling call_user_func().
4989 5275
 		else
4990 5276
 		{
4991
-			if (is_array($func))
4992
-				call_user_func($func);
4993
-
4994
-			else
4995
-				$func();
5277
+			if (is_array($func)) {
5278
+							call_user_func($func);
5279
+			} else {
5280
+							$func();
5281
+			}
4996 5282
 		}
4997 5283
 	}
4998 5284
 }
@@ -5009,31 +5295,34 @@  discard block
 block discarded – undo
5009 5295
 {
5010 5296
 	global $sourcedir, $txt, $boarddir, $settings;
5011 5297
 
5012
-	if (empty($string))
5013
-		return false;
5298
+	if (empty($string)) {
5299
+			return false;
5300
+	}
5014 5301
 
5015 5302
 	if (strpos($string, '|') !== false)
5016 5303
 	{
5017 5304
 		list ($file, $string) = explode('|', $string);
5018 5305
 
5019 5306
 		// Match the wildcards to their regular vars.
5020
-		if (empty($settings['theme_dir']))
5021
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5022
-
5023
-		else
5024
-			$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5307
+		if (empty($settings['theme_dir'])) {
5308
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir));
5309
+		} else {
5310
+					$absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
5311
+		}
5025 5312
 
5026 5313
 		// Load the file if it can be loaded.
5027
-		if (file_exists($absPath))
5028
-			require_once($absPath);
5314
+		if (file_exists($absPath)) {
5315
+					require_once($absPath);
5316
+		}
5029 5317
 
5030 5318
 		// No? try a fallback to $sourcedir
5031 5319
 		else
5032 5320
 		{
5033 5321
 			$absPath = $sourcedir .'/'. $file;
5034 5322
 
5035
-			if (file_exists($absPath))
5036
-				require_once($absPath);
5323
+			if (file_exists($absPath)) {
5324
+							require_once($absPath);
5325
+			}
5037 5326
 
5038 5327
 			// Sorry, can't do much for you at this point.
5039 5328
 			else
@@ -5072,8 +5361,9 @@  discard block
 block discarded – undo
5072 5361
 	preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match);
5073 5362
 
5074 5363
 	// No scheme? No data for you!
5075
-	if (empty($match[1]))
5076
-		return false;
5364
+	if (empty($match[1])) {
5365
+			return false;
5366
+	}
5077 5367
 
5078 5368
 	// An FTP url. We should try connecting and RETRieving it...
5079 5369
 	elseif ($match[1] == 'ftp')
@@ -5083,23 +5373,26 @@  discard block
 block discarded – undo
5083 5373
 
5084 5374
 		// Establish a connection and attempt to enable passive mode.
5085 5375
 		$ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email);
5086
-		if ($ftp->error !== false || !$ftp->passive())
5087
-			return false;
5376
+		if ($ftp->error !== false || !$ftp->passive()) {
5377
+					return false;
5378
+		}
5088 5379
 
5089 5380
 		// I want that one *points*!
5090 5381
 		fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n");
5091 5382
 
5092 5383
 		// Since passive mode worked (or we would have returned already!) open the connection.
5093 5384
 		$fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5);
5094
-		if (!$fp)
5095
-			return false;
5385
+		if (!$fp) {
5386
+					return false;
5387
+		}
5096 5388
 
5097 5389
 		// The server should now say something in acknowledgement.
5098 5390
 		$ftp->check_response(150);
5099 5391
 
5100 5392
 		$data = '';
5101
-		while (!feof($fp))
5102
-			$data .= fread($fp, 4096);
5393
+		while (!feof($fp)) {
5394
+					$data .= fread($fp, 4096);
5395
+		}
5103 5396
 		fclose($fp);
5104 5397
 
5105 5398
 		// All done, right?  Good.
@@ -5111,8 +5404,9 @@  discard block
 block discarded – undo
5111 5404
 	elseif (isset($match[1]) && $match[1] == 'http')
5112 5405
 	{
5113 5406
 		// First try to use fsockopen, because it is fastest.
5114
-		if ($keep_alive && $match[3] == $keep_alive_dom)
5115
-			$fp = $keep_alive_fp;
5407
+		if ($keep_alive && $match[3] == $keep_alive_dom) {
5408
+					$fp = $keep_alive_fp;
5409
+		}
5116 5410
 		if (empty($fp))
5117 5411
 		{
5118 5412
 			// Open the socket on the port we want...
@@ -5132,20 +5426,21 @@  discard block
 block discarded – undo
5132 5426
 				fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n");
5133 5427
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5134 5428
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5135
-				if ($keep_alive)
5136
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5137
-				else
5138
-					fwrite($fp, 'connection: close' . "\r\n\r\n");
5139
-			}
5140
-			else
5429
+				if ($keep_alive) {
5430
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n\r\n");
5431
+				} else {
5432
+									fwrite($fp, 'connection: close' . "\r\n\r\n");
5433
+				}
5434
+			} else
5141 5435
 			{
5142 5436
 				fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n");
5143 5437
 				fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n");
5144 5438
 				fwrite($fp, 'user-agent: PHP/SMF' . "\r\n");
5145
-				if ($keep_alive)
5146
-					fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5147
-				else
5148
-					fwrite($fp, 'connection: close' . "\r\n");
5439
+				if ($keep_alive) {
5440
+									fwrite($fp, 'connection: Keep-Alive' . "\r\n");
5441
+				} else {
5442
+									fwrite($fp, 'connection: close' . "\r\n");
5443
+				}
5149 5444
 				fwrite($fp, 'content-type: application/x-www-form-urlencoded' . "\r\n");
5150 5445
 				fwrite($fp, 'content-length: ' . strlen($post_data) . "\r\n\r\n");
5151 5446
 				fwrite($fp, $post_data);
@@ -5158,30 +5453,33 @@  discard block
 block discarded – undo
5158 5453
 			{
5159 5454
 				$header = '';
5160 5455
 				$location = '';
5161
-				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5162
-					if (strpos($header, 'location:') !== false)
5456
+				while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') {
5457
+									if (strpos($header, 'location:') !== false)
5163 5458
 						$location = trim(substr($header, strpos($header, ':') + 1));
5459
+				}
5164 5460
 
5165
-				if (empty($location))
5166
-					return false;
5167
-				else
5461
+				if (empty($location)) {
5462
+									return false;
5463
+				} else
5168 5464
 				{
5169
-					if (!$keep_alive)
5170
-						fclose($fp);
5465
+					if (!$keep_alive) {
5466
+											fclose($fp);
5467
+					}
5171 5468
 					return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1);
5172 5469
 				}
5173 5470
 			}
5174 5471
 
5175 5472
 			// Make sure we get a 200 OK.
5176
-			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0)
5177
-				return false;
5473
+			elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) {
5474
+							return false;
5475
+			}
5178 5476
 
5179 5477
 			// Skip the headers...
5180 5478
 			while (!feof($fp) && trim($header = fgets($fp, 4096)) != '')
5181 5479
 			{
5182
-				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0)
5183
-					$content_length = $match[1];
5184
-				elseif (preg_match('~connection:\s*close~i', $header) != 0)
5480
+				if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) {
5481
+									$content_length = $match[1];
5482
+				} elseif (preg_match('~connection:\s*close~i', $header) != 0)
5185 5483
 				{
5186 5484
 					$keep_alive_dom = null;
5187 5485
 					$keep_alive = false;
@@ -5193,17 +5491,19 @@  discard block
 block discarded – undo
5193 5491
 			$data = '';
5194 5492
 			if (isset($content_length))
5195 5493
 			{
5196
-				while (!feof($fp) && strlen($data) < $content_length)
5197
-					$data .= fread($fp, $content_length - strlen($data));
5198
-			}
5199
-			else
5494
+				while (!feof($fp) && strlen($data) < $content_length) {
5495
+									$data .= fread($fp, $content_length - strlen($data));
5496
+				}
5497
+			} else
5200 5498
 			{
5201
-				while (!feof($fp))
5202
-					$data .= fread($fp, 4096);
5499
+				while (!feof($fp)) {
5500
+									$data .= fread($fp, 4096);
5501
+				}
5203 5502
 			}
5204 5503
 
5205
-			if (!$keep_alive)
5206
-				fclose($fp);
5504
+			if (!$keep_alive) {
5505
+							fclose($fp);
5506
+			}
5207 5507
 		}
5208 5508
 
5209 5509
 		// If using fsockopen didn't work, try to use cURL if available.
@@ -5216,17 +5516,18 @@  discard block
 block discarded – undo
5216 5516
 			$fetch_data->get_url_data($url, $post_data);
5217 5517
 
5218 5518
 			// no errors and a 200 result, then we have a good dataset, well we at least have data. ;)
5219
-			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error'))
5220
-				$data = $fetch_data->result('body');
5221
-			else
5222
-				return false;
5519
+			if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) {
5520
+							$data = $fetch_data->result('body');
5521
+			} else {
5522
+							return false;
5523
+			}
5223 5524
 		}
5224 5525
 
5225 5526
 		// Neither fsockopen nor curl are available. Well, phooey.
5226
-		else
5227
-			return false;
5228
-	}
5229
-	else
5527
+		else {
5528
+					return false;
5529
+		}
5530
+	} else
5230 5531
 	{
5231 5532
 		// Umm, this shouldn't happen?
5232 5533
 		trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE);
@@ -5246,8 +5547,9 @@  discard block
 block discarded – undo
5246 5547
 	global $user_info, $smcFunc;
5247 5548
 
5248 5549
 	// Make sure we have something to work with.
5249
-	if (empty($topic))
5250
-		return array();
5550
+	if (empty($topic)) {
5551
+			return array();
5552
+	}
5251 5553
 
5252 5554
 
5253 5555
 	// We already know the number of likes per message, we just want to know whether the current user liked it or not.
@@ -5270,8 +5572,9 @@  discard block
 block discarded – undo
5270 5572
 				'topic' => $topic,
5271 5573
 			)
5272 5574
 		);
5273
-		while ($row = $smcFunc['db_fetch_assoc']($request))
5274
-			$temp[] = (int) $row['content_id'];
5575
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
5576
+					$temp[] = (int) $row['content_id'];
5577
+		}
5275 5578
 
5276 5579
 		cache_put_data($cache_key, $temp, $ttl);
5277 5580
 	}
@@ -5292,8 +5595,9 @@  discard block
 block discarded – undo
5292 5595
 {
5293 5596
 	global $context;
5294 5597
 
5295
-	if (empty($string))
5296
-		return $string;
5598
+	if (empty($string)) {
5599
+			return $string;
5600
+	}
5297 5601
 
5298 5602
 	// UTF-8 occurences of MS special characters
5299 5603
 	$findchars_utf8 = array(
@@ -5334,10 +5638,11 @@  discard block
 block discarded – undo
5334 5638
 		'--',	// &mdash;
5335 5639
 	);
5336 5640
 
5337
-	if ($context['utf8'])
5338
-		$string = str_replace($findchars_utf8, $replacechars, $string);
5339
-	else
5340
-		$string = str_replace($findchars_iso, $replacechars, $string);
5641
+	if ($context['utf8']) {
5642
+			$string = str_replace($findchars_utf8, $replacechars, $string);
5643
+	} else {
5644
+			$string = str_replace($findchars_iso, $replacechars, $string);
5645
+	}
5341 5646
 
5342 5647
 	return $string;
5343 5648
 }
@@ -5356,49 +5661,59 @@  discard block
 block discarded – undo
5356 5661
 {
5357 5662
 	global $context;
5358 5663
 
5359
-	if (!isset($matches[2]))
5360
-		return '';
5664
+	if (!isset($matches[2])) {
5665
+			return '';
5666
+	}
5361 5667
 
5362 5668
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5363 5669
 
5364 5670
 	// remove left to right / right to left overrides
5365
-	if ($num === 0x202D || $num === 0x202E)
5366
-		return '';
5671
+	if ($num === 0x202D || $num === 0x202E) {
5672
+			return '';
5673
+	}
5367 5674
 
5368 5675
 	// Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced
5369
-	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E)))
5370
-		return '&#' . $num . ';';
5676
+	if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) {
5677
+			return '&#' . $num . ';';
5678
+	}
5371 5679
 
5372 5680
 	if (empty($context['utf8']))
5373 5681
 	{
5374 5682
 		// no control characters
5375
-		if ($num < 0x20)
5376
-			return '';
5683
+		if ($num < 0x20) {
5684
+					return '';
5685
+		}
5377 5686
 		// text is text
5378
-		elseif ($num < 0x80)
5379
-			return chr($num);
5687
+		elseif ($num < 0x80) {
5688
+					return chr($num);
5689
+		}
5380 5690
 		// all others get html-ised
5381
-		else
5382
-			return '&#' . $matches[2] . ';';
5383
-	}
5384
-	else
5691
+		else {
5692
+					return '&#' . $matches[2] . ';';
5693
+		}
5694
+	} else
5385 5695
 	{
5386 5696
 		// <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set
5387 5697
 		// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text)
5388
-		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF))
5389
-			return '';
5698
+		if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) {
5699
+					return '';
5700
+		}
5390 5701
 		// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5391
-		elseif ($num < 0x80)
5392
-			return chr($num);
5702
+		elseif ($num < 0x80) {
5703
+					return chr($num);
5704
+		}
5393 5705
 		// <0x800 (2048)
5394
-		elseif ($num < 0x800)
5395
-			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5706
+		elseif ($num < 0x800) {
5707
+					return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5708
+		}
5396 5709
 		// < 0x10000 (65536)
5397
-		elseif ($num < 0x10000)
5398
-			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5710
+		elseif ($num < 0x10000) {
5711
+					return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5712
+		}
5399 5713
 		// <= 0x10FFFF (1114111)
5400
-		else
5401
-			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5714
+		else {
5715
+					return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5716
+		}
5402 5717
 	}
5403 5718
 }
5404 5719
 
@@ -5414,28 +5729,34 @@  discard block
 block discarded – undo
5414 5729
  */
5415 5730
 function fixchar__callback($matches)
5416 5731
 {
5417
-	if (!isset($matches[1]))
5418
-		return '';
5732
+	if (!isset($matches[1])) {
5733
+			return '';
5734
+	}
5419 5735
 
5420 5736
 	$num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1];
5421 5737
 
5422 5738
 	// <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set
5423 5739
 	// 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides
5424
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E)
5425
-		return '';
5740
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) {
5741
+			return '';
5742
+	}
5426 5743
 	// <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation
5427
-	elseif ($num < 0x80)
5428
-		return chr($num);
5744
+	elseif ($num < 0x80) {
5745
+			return chr($num);
5746
+	}
5429 5747
 	// <0x800 (2048)
5430
-	elseif ($num < 0x800)
5431
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5748
+	elseif ($num < 0x800) {
5749
+			return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
5750
+	}
5432 5751
 	// < 0x10000 (65536)
5433
-	elseif ($num < 0x10000)
5434
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5752
+	elseif ($num < 0x10000) {
5753
+			return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5754
+	}
5435 5755
 	// <= 0x10FFFF (1114111)
5436
-	else
5437
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5438
-}
5756
+	else {
5757
+			return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
5758
+	}
5759
+	}
5439 5760
 
5440 5761
 /**
5441 5762
  * Strips out invalid html entities, replaces others with html style &#123; codes
@@ -5448,17 +5769,19 @@  discard block
 block discarded – undo
5448 5769
  */
5449 5770
 function entity_fix__callback($matches)
5450 5771
 {
5451
-	if (!isset($matches[2]))
5452
-		return '';
5772
+	if (!isset($matches[2])) {
5773
+			return '';
5774
+	}
5453 5775
 
5454 5776
 	$num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2];
5455 5777
 
5456 5778
 	// we don't allow control characters, characters out of range, byte markers, etc
5457
-	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E)
5458
-		return '';
5459
-	else
5460
-		return '&#' . $num . ';';
5461
-}
5779
+	if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) {
5780
+			return '';
5781
+	} else {
5782
+			return '&#' . $num . ';';
5783
+	}
5784
+	}
5462 5785
 
5463 5786
 /**
5464 5787
  * Return a Gravatar URL based on
@@ -5482,18 +5805,23 @@  discard block
 block discarded – undo
5482 5805
 		$ratings = array('G', 'PG', 'R', 'X');
5483 5806
 		$defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank');
5484 5807
 		$url_params = array();
5485
-		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings))
5486
-			$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5487
-		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults))
5488
-			$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5489
-		if (!empty($modSettings['avatar_max_width_external']))
5490
-			$size_string = (int) $modSettings['avatar_max_width_external'];
5491
-		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string))
5492
-			if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5808
+		if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) {
5809
+					$url_params[] = 'rating=' . $modSettings['gravatarMaxRating'];
5810
+		}
5811
+		if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) {
5812
+					$url_params[] = 'default=' . $modSettings['gravatarDefault'];
5813
+		}
5814
+		if (!empty($modSettings['avatar_max_width_external'])) {
5815
+					$size_string = (int) $modSettings['avatar_max_width_external'];
5816
+		}
5817
+		if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) {
5818
+					if ((int) $modSettings['avatar_max_height_external'] < $size_string)
5493 5819
 				$size_string = $modSettings['avatar_max_height_external'];
5820
+		}
5494 5821
 
5495
-		if (!empty($size_string))
5496
-			$url_params[] = 's=' . $size_string;
5822
+		if (!empty($size_string)) {
5823
+					$url_params[] = 's=' . $size_string;
5824
+		}
5497 5825
 	}
5498 5826
 	$http_method = !empty($modSettings['force_ssl']) ? 'https://secure' : 'http://www';
5499 5827
 
@@ -5512,22 +5840,26 @@  discard block
 block discarded – undo
5512 5840
 	static $timezones = null, $lastwhen = null;
5513 5841
 
5514 5842
 	// No point doing this over if we already did it once
5515
-	if (!empty($timezones) && $when == $lastwhen)
5516
-		return $timezones;
5517
-	else
5518
-		$lastwhen = $when;
5843
+	if (!empty($timezones) && $when == $lastwhen) {
5844
+			return $timezones;
5845
+	} else {
5846
+			$lastwhen = $when;
5847
+	}
5519 5848
 
5520 5849
 	// Parseable datetime string?
5521
-	if (is_int($timestamp = strtotime($when)))
5522
-		$when = $timestamp;
5850
+	if (is_int($timestamp = strtotime($when))) {
5851
+			$when = $timestamp;
5852
+	}
5523 5853
 
5524 5854
 	// A Unix timestamp?
5525
-	elseif (is_numeric($when))
5526
-		$when = intval($when);
5855
+	elseif (is_numeric($when)) {
5856
+			$when = intval($when);
5857
+	}
5527 5858
 
5528 5859
 	// Invalid value? Just get current Unix timestamp.
5529
-	else
5530
-		$when = time();
5860
+	else {
5861
+			$when = time();
5862
+	}
5531 5863
 
5532 5864
 	// We'll need these too
5533 5865
 	$date_when = date_create('@' . $when);
@@ -5542,8 +5874,9 @@  discard block
 block discarded – undo
5542 5874
 	foreach ($priority_countries as $country)
5543 5875
 	{
5544 5876
 		$country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country)));
5545
-		if (!empty($country_tzids))
5546
-			$priority_tzids = array_merge($priority_tzids, $country_tzids);
5877
+		if (!empty($country_tzids)) {
5878
+					$priority_tzids = array_merge($priority_tzids, $country_tzids);
5879
+		}
5547 5880
 	}
5548 5881
 
5549 5882
 	// Antarctic research stations should be listed last, unless you're running a penguin forum
@@ -5557,8 +5890,9 @@  discard block
 block discarded – undo
5557 5890
 	foreach ($tzids as $tzid)
5558 5891
 	{
5559 5892
 		// We don't want UTC right now
5560
-		if ($tzid == 'UTC')
5561
-			continue;
5893
+		if ($tzid == 'UTC') {
5894
+					continue;
5895
+		}
5562 5896
 
5563 5897
 		$tz = timezone_open($tzid);
5564 5898
 
@@ -5579,13 +5913,14 @@  discard block
 block discarded – undo
5579 5913
 		}
5580 5914
 
5581 5915
 		// A time zone from a prioritized country?
5582
-		if (in_array($tzid, $priority_tzids))
5583
-			$priority_zones[$tzkey] = true;
5916
+		if (in_array($tzid, $priority_tzids)) {
5917
+					$priority_zones[$tzkey] = true;
5918
+		}
5584 5919
 
5585 5920
 		// Keep track of the location and offset for this tzid
5586
-		if (!empty($txt[$tzid]))
5587
-			$zones[$tzkey]['locations'][] = $txt[$tzid];
5588
-		else
5921
+		if (!empty($txt[$tzid])) {
5922
+					$zones[$tzkey]['locations'][] = $txt[$tzid];
5923
+		} else
5589 5924
 		{
5590 5925
 			$tzid_parts = explode('/', $tzid);
5591 5926
 			$zones[$tzkey]['locations'][] = str_replace(array('St_', '_'), array('St. ', ' '), array_pop($tzid_parts));
@@ -5605,23 +5940,27 @@  discard block
 block discarded – undo
5605 5940
 		date_timezone_set($date_when, timezone_open($tzvalue['tzid']));
5606 5941
 
5607 5942
 		// Use the custom description, if there is one
5608
-		if (!empty($tztxt[$tzvalue['tzid']]))
5609
-			$desc = $tztxt[$tzvalue['tzid']];
5943
+		if (!empty($tztxt[$tzvalue['tzid']])) {
5944
+					$desc = $tztxt[$tzvalue['tzid']];
5945
+		}
5610 5946
 		// Otherwise, use the list of locations (max 5, so things don't get silly)
5611
-		else
5612
-			$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5947
+		else {
5948
+					$desc = implode(', ', array_slice(array_unique($tzvalue['locations']), 0, 5)) . (count($tzvalue['locations']) > 5 ? ', ' . $txt['etc'] : '');
5949
+		}
5613 5950
 
5614 5951
 		// Show the UTC offset and the abbreviation, if it's something like 'MST' and not '-06'
5615 5952
 		$desc = '[UTC' . date_format($date_when, 'P') . '] - ' . (!strspn($tzvalue['abbr'], '+-') ? $tzvalue['abbr'] . ' - ' : '') . $desc;
5616 5953
 
5617
-		if (isset($priority_zones[$tzkey]))
5618
-			$priority_timezones[$tzvalue['tzid']] = $desc;
5619
-		else
5620
-			$timezones[$tzvalue['tzid']] = $desc;
5954
+		if (isset($priority_zones[$tzkey])) {
5955
+					$priority_timezones[$tzvalue['tzid']] = $desc;
5956
+		} else {
5957
+					$timezones[$tzvalue['tzid']] = $desc;
5958
+		}
5621 5959
 	}
5622 5960
 
5623
-	if (!empty($priority_timezones))
5624
-		$priority_timezones[] = '-----';
5961
+	if (!empty($priority_timezones)) {
5962
+			$priority_timezones[] = '-----';
5963
+	}
5625 5964
 
5626 5965
 	$timezones = array_merge(
5627 5966
 		$priority_timezones,
@@ -5638,8 +5977,9 @@  discard block
 block discarded – undo
5638 5977
  */
5639 5978
 function inet_ptod($ip_address)
5640 5979
 {
5641
-	if (!isValidIP($ip_address))
5642
-		return $ip_address;
5980
+	if (!isValidIP($ip_address)) {
5981
+			return $ip_address;
5982
+	}
5643 5983
 
5644 5984
 	$bin = inet_pton($ip_address);
5645 5985
 	return $bin;
@@ -5651,13 +5991,15 @@  discard block
 block discarded – undo
5651 5991
  */
5652 5992
 function inet_dtop($bin)
5653 5993
 {
5654
-	if(empty($bin))
5655
-		return '';
5994
+	if(empty($bin)) {
5995
+			return '';
5996
+	}
5656 5997
 
5657 5998
 	global $db_type;
5658 5999
 
5659
-	if ($db_type == 'postgresql')
5660
-		return $bin;
6000
+	if ($db_type == 'postgresql') {
6001
+			return $bin;
6002
+	}
5661 6003
 
5662 6004
 	$ip_address = inet_ntop($bin);
5663 6005
 
@@ -5682,26 +6024,32 @@  discard block
 block discarded – undo
5682 6024
  */
5683 6025
 function _safe_serialize($value)
5684 6026
 {
5685
-	if(is_null($value))
5686
-		return 'N;';
6027
+	if(is_null($value)) {
6028
+			return 'N;';
6029
+	}
5687 6030
 
5688
-	if(is_bool($value))
5689
-		return 'b:'. (int) $value .';';
6031
+	if(is_bool($value)) {
6032
+			return 'b:'. (int) $value .';';
6033
+	}
5690 6034
 
5691
-	if(is_int($value))
5692
-		return 'i:'. $value .';';
6035
+	if(is_int($value)) {
6036
+			return 'i:'. $value .';';
6037
+	}
5693 6038
 
5694
-	if(is_float($value))
5695
-		return 'd:'. str_replace(',', '.', $value) .';';
6039
+	if(is_float($value)) {
6040
+			return 'd:'. str_replace(',', '.', $value) .';';
6041
+	}
5696 6042
 
5697
-	if(is_string($value))
5698
-		return 's:'. strlen($value) .':"'. $value .'";';
6043
+	if(is_string($value)) {
6044
+			return 's:'. strlen($value) .':"'. $value .'";';
6045
+	}
5699 6046
 
5700 6047
 	if(is_array($value))
5701 6048
 	{
5702 6049
 		$out = '';
5703
-		foreach($value as $k => $v)
5704
-			$out .= _safe_serialize($k) . _safe_serialize($v);
6050
+		foreach($value as $k => $v) {
6051
+					$out .= _safe_serialize($k) . _safe_serialize($v);
6052
+		}
5705 6053
 
5706 6054
 		return 'a:'. count($value) .':{'. $out .'}';
5707 6055
 	}
@@ -5727,8 +6075,9 @@  discard block
 block discarded – undo
5727 6075
 
5728 6076
 	$out = _safe_serialize($value);
5729 6077
 
5730
-	if (isset($mbIntEnc))
5731
-		mb_internal_encoding($mbIntEnc);
6078
+	if (isset($mbIntEnc)) {
6079
+			mb_internal_encoding($mbIntEnc);
6080
+	}
5732 6081
 
5733 6082
 	return $out;
5734 6083
 }
@@ -5745,8 +6094,9 @@  discard block
 block discarded – undo
5745 6094
 function _safe_unserialize($str)
5746 6095
 {
5747 6096
 	// Input  is not a string.
5748
-	if(empty($str) || !is_string($str))
5749
-		return false;
6097
+	if(empty($str) || !is_string($str)) {
6098
+			return false;
6099
+	}
5750 6100
 
5751 6101
 	$stack = array();
5752 6102
 	$expected = array();
@@ -5762,43 +6112,38 @@  discard block
 block discarded – undo
5762 6112
 	while($state != 1)
5763 6113
 	{
5764 6114
 		$type = isset($str[0]) ? $str[0] : '';
5765
-		if($type == '}')
5766
-			$str = substr($str, 1);
5767
-
5768
-		else if($type == 'N' && $str[1] == ';')
6115
+		if($type == '}') {
6116
+					$str = substr($str, 1);
6117
+		} else if($type == 'N' && $str[1] == ';')
5769 6118
 		{
5770 6119
 			$value = null;
5771 6120
 			$str = substr($str, 2);
5772
-		}
5773
-		else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
6121
+		} else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches))
5774 6122
 		{
5775 6123
 			$value = $matches[1] == '1' ? true : false;
5776 6124
 			$str = substr($str, 4);
5777
-		}
5778
-		else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
6125
+		} else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches))
5779 6126
 		{
5780 6127
 			$value = (int)$matches[1];
5781 6128
 			$str = $matches[2];
5782
-		}
5783
-		else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
6129
+		} else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches))
5784 6130
 		{
5785 6131
 			$value = (float)$matches[1];
5786 6132
 			$str = $matches[3];
5787
-		}
5788
-		else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
6133
+		} else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";')
5789 6134
 		{
5790 6135
 			$value = substr($matches[2], 0, (int)$matches[1]);
5791 6136
 			$str = substr($matches[2], (int)$matches[1] + 2);
5792
-		}
5793
-		else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
6137
+		} else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches))
5794 6138
 		{
5795 6139
 			$expectedLength = (int)$matches[1];
5796 6140
 			$str = $matches[2];
5797 6141
 		}
5798 6142
 
5799 6143
 		// Object or unknown/malformed type.
5800
-		else
5801
-			return false;
6144
+		else {
6145
+					return false;
6146
+		}
5802 6147
 
5803 6148
 		switch($state)
5804 6149
 		{
@@ -5826,8 +6171,9 @@  discard block
 block discarded – undo
5826 6171
 				if($type == '}')
5827 6172
 				{
5828 6173
 					// Array size is less than expected.
5829
-					if(count($list) < end($expected))
5830
-						return false;
6174
+					if(count($list) < end($expected)) {
6175
+											return false;
6176
+					}
5831 6177
 
5832 6178
 					unset($list);
5833 6179
 					$list = &$stack[count($stack)-1];
@@ -5836,8 +6182,9 @@  discard block
 block discarded – undo
5836 6182
 					// Go to terminal state if we're at the end of the root array.
5837 6183
 					array_pop($expected);
5838 6184
 
5839
-					if(count($expected) == 0)
5840
-						$state = 1;
6185
+					if(count($expected) == 0) {
6186
+											$state = 1;
6187
+					}
5841 6188
 
5842 6189
 					break;
5843 6190
 				}
@@ -5845,8 +6192,9 @@  discard block
 block discarded – undo
5845 6192
 				if($type == 'i' || $type == 's')
5846 6193
 				{
5847 6194
 					// Array size exceeds expected length.
5848
-					if(count($list) >= end($expected))
5849
-						return false;
6195
+					if(count($list) >= end($expected)) {
6196
+											return false;
6197
+					}
5850 6198
 
5851 6199
 					$key = $value;
5852 6200
 					$state = 3;
@@ -5880,8 +6228,9 @@  discard block
 block discarded – undo
5880 6228
 	}
5881 6229
 
5882 6230
 	// Trailing data in input.
5883
-	if(!empty($str))
5884
-		return false;
6231
+	if(!empty($str)) {
6232
+			return false;
6233
+	}
5885 6234
 
5886 6235
 	return $data;
5887 6236
 }
@@ -5904,8 +6253,9 @@  discard block
 block discarded – undo
5904 6253
 
5905 6254
 	$out = _safe_unserialize($str);
5906 6255
 
5907
-	if (isset($mbIntEnc))
5908
-		mb_internal_encoding($mbIntEnc);
6256
+	if (isset($mbIntEnc)) {
6257
+			mb_internal_encoding($mbIntEnc);
6258
+	}
5909 6259
 
5910 6260
 	return $out;
5911 6261
 }
@@ -5920,12 +6270,14 @@  discard block
 block discarded – undo
5920 6270
 function smf_chmod($file, $value = 0)
5921 6271
 {
5922 6272
 	// No file? no checks!
5923
-	if (empty($file))
5924
-		return false;
6273
+	if (empty($file)) {
6274
+			return false;
6275
+	}
5925 6276
 
5926 6277
 	// Already writable?
5927
-	if (is_writable($file))
5928
-		return true;
6278
+	if (is_writable($file)) {
6279
+			return true;
6280
+	}
5929 6281
 
5930 6282
 	// Do we have a file or a dir?
5931 6283
 	$isDir = is_dir($file);
@@ -5941,10 +6293,9 @@  discard block
 block discarded – undo
5941 6293
 		{
5942 6294
 			$isWritable = true;
5943 6295
 			break;
6296
+		} else {
6297
+					@chmod($file, $val);
5944 6298
 		}
5945
-
5946
-		else
5947
-			@chmod($file, $val);
5948 6299
 	}
5949 6300
 
5950 6301
 	return $isWritable;
@@ -5963,8 +6314,9 @@  discard block
 block discarded – undo
5963 6314
 	global $txt;
5964 6315
 
5965 6316
 	// Come on...
5966
-	if (empty($json) || !is_string($json))
5967
-		return array();
6317
+	if (empty($json) || !is_string($json)) {
6318
+			return array();
6319
+	}
5968 6320
 
5969 6321
 	$returnArray = @json_decode($json, $returnAsArray);
5970 6322
 
@@ -6002,11 +6354,11 @@  discard block
 block discarded – undo
6002 6354
 		$jsonDebug = $jsonDebug[0];
6003 6355
 		loadLanguage('Errors');
6004 6356
 
6005
-		if (!empty($jsonDebug))
6006
-			log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6007
-
6008
-		else
6009
-			log_error($txt['json_'. $jsonError], 'critical');
6357
+		if (!empty($jsonDebug)) {
6358
+					log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']);
6359
+		} else {
6360
+					log_error($txt['json_'. $jsonError], 'critical');
6361
+		}
6010 6362
 
6011 6363
 		// Everyone expects an array.
6012 6364
 		return array();
@@ -6040,8 +6392,9 @@  discard block
 block discarded – undo
6040 6392
 	global $db_show_debug, $modSettings;
6041 6393
 
6042 6394
 	// Defensive programming anyone?
6043
-	if (empty($data))
6044
-		return false;
6395
+	if (empty($data)) {
6396
+			return false;
6397
+	}
6045 6398
 
6046 6399
 	// Don't need extra stuff...
6047 6400
 	$db_show_debug = false;
@@ -6049,11 +6402,11 @@  discard block
 block discarded – undo
6049 6402
 	// Kill anything else.
6050 6403
 	ob_end_clean();
6051 6404
 
6052
-	if (!empty($modSettings['CompressedOutput']))
6053
-		@ob_start('ob_gzhandler');
6054
-
6055
-	else
6056
-		ob_start();
6405
+	if (!empty($modSettings['CompressedOutput'])) {
6406
+			@ob_start('ob_gzhandler');
6407
+	} else {
6408
+			ob_start();
6409
+	}
6057 6410
 
6058 6411
 	// Set the header.
6059 6412
 	header($type);
@@ -6085,8 +6438,9 @@  discard block
 block discarded – undo
6085 6438
 	static $done = false;
6086 6439
 
6087 6440
 	// If we don't need to do anything, don't
6088
-	if (!$update && $done)
6089
-		return;
6441
+	if (!$update && $done) {
6442
+			return;
6443
+	}
6090 6444
 
6091 6445
 	// Should we get a new copy of the official list of TLDs?
6092 6446
 	if ($update)
@@ -6098,8 +6452,9 @@  discard block
 block discarded – undo
6098 6452
 		// marauding bandits roaming on the surface. We don't want to waste precious electricity on
6099 6453
 		// pointlessly repeating background tasks, so we'll wait until the next regularly scheduled
6100 6454
 		// update to see if civilization has been restored.
6101
-		if ($tlds === false)
6102
-			$postapocalypticNightmare = true;
6455
+		if ($tlds === false) {
6456
+					$postapocalypticNightmare = true;
6457
+		}
6103 6458
 	}
6104 6459
 	// If we aren't updating and the regex is valid, we're done
6105 6460
 	elseif (!empty($modSettings['tld_regex']) && @preg_match('~' . $modSettings['tld_regex'] . '~', null) !== false)
@@ -6114,10 +6469,11 @@  discard block
 block discarded – undo
6114 6469
 		// Clean $tlds and convert it to an array
6115 6470
 		$tlds = array_filter(explode("\n", strtolower($tlds)), function($line) {
6116 6471
 			$line = trim($line);
6117
-			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false)
6118
-				return false;
6119
-			else
6120
-				return true;
6472
+			if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) {
6473
+							return false;
6474
+			} else {
6475
+							return true;
6476
+			}
6121 6477
 		});
6122 6478
 
6123 6479
 		// Convert Punycode to Unicode
@@ -6209,8 +6565,7 @@  discard block
 block discarded – undo
6209 6565
 
6210 6566
 		$strlen = 'mb_strlen';
6211 6567
 		$substr = 'mb_substr';
6212
-	}
6213
-	else
6568
+	} else
6214 6569
 	{
6215 6570
 		$strlen = $smcFunc['strlen'];
6216 6571
 		$substr = $smcFunc['substr'];
@@ -6224,20 +6579,21 @@  discard block
 block discarded – undo
6224 6579
 
6225 6580
 		$first = $substr($string, 0, 1);
6226 6581
 
6227
-		if (empty($index[$first]))
6228
-			$index[$first] = array();
6582
+		if (empty($index[$first])) {
6583
+					$index[$first] = array();
6584
+		}
6229 6585
 
6230 6586
 		if ($strlen($string) > 1)
6231 6587
 		{
6232 6588
 			// Sanity check on recursion
6233
-			if ($depth > 99)
6234
-				$index[$first][$substr($string, 1)] = '';
6235
-
6236
-			else
6237
-				$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6589
+			if ($depth > 99) {
6590
+							$index[$first][$substr($string, 1)] = '';
6591
+			} else {
6592
+							$index[$first] = $add_string_to_index($substr($string, 1), $index[$first]);
6593
+			}
6594
+		} else {
6595
+					$index[$first][''] = '';
6238 6596
 		}
6239
-		else
6240
-			$index[$first][''] = '';
6241 6597
 
6242 6598
 		$depth--;
6243 6599
 		return $index;
@@ -6260,9 +6616,9 @@  discard block
 block discarded – undo
6260 6616
 			$key_regex = preg_quote($key, $delim);
6261 6617
 			$new_key = $key;
6262 6618
 
6263
-			if (empty($value))
6264
-				$sub_regex = '';
6265
-			else
6619
+			if (empty($value)) {
6620
+							$sub_regex = '';
6621
+			} else
6266 6622
 			{
6267 6623
 				$sub_regex = $index_to_regex($value, $delim);
6268 6624
 
@@ -6270,22 +6626,22 @@  discard block
 block discarded – undo
6270 6626
 				{
6271 6627
 					$new_key_array = explode('(?'.'>', $sub_regex);
6272 6628
 					$new_key .= $new_key_array[0];
6629
+				} else {
6630
+									$sub_regex = '(?'.'>' . $sub_regex . ')';
6273 6631
 				}
6274
-				else
6275
-					$sub_regex = '(?'.'>' . $sub_regex . ')';
6276 6632
 			}
6277 6633
 
6278
-			if ($depth > 1)
6279
-				$regex[$new_key] = $key_regex . $sub_regex;
6280
-			else
6634
+			if ($depth > 1) {
6635
+							$regex[$new_key] = $key_regex . $sub_regex;
6636
+			} else
6281 6637
 			{
6282 6638
 				if (($length += strlen($key_regex) + 1) < $max_length || empty($regex))
6283 6639
 				{
6284 6640
 					$regex[$new_key] = $key_regex . $sub_regex;
6285 6641
 					unset($index[$key]);
6642
+				} else {
6643
+									break;
6286 6644
 				}
6287
-				else
6288
-					break;
6289 6645
 			}
6290 6646
 		}
6291 6647
 
@@ -6294,10 +6650,11 @@  discard block
 block discarded – undo
6294 6650
 			$l1 = $strlen($k1);
6295 6651
 			$l2 = $strlen($k2);
6296 6652
 
6297
-			if ($l1 == $l2)
6298
-				return strcmp($k1, $k2) > 0 ? 1 : -1;
6299
-			else
6300
-				return $l1 > $l2 ? -1 : 1;
6653
+			if ($l1 == $l2) {
6654
+							return strcmp($k1, $k2) > 0 ? 1 : -1;
6655
+			} else {
6656
+							return $l1 > $l2 ? -1 : 1;
6657
+			}
6301 6658
 		});
6302 6659
 
6303 6660
 		$depth--;
@@ -6308,21 +6665,24 @@  discard block
 block discarded – undo
6308 6665
 	$index = array();
6309 6666
 	$regex = '';
6310 6667
 
6311
-	foreach ($strings as $string)
6312
-		$index = $add_string_to_index($string, $index);
6668
+	foreach ($strings as $string) {
6669
+			$index = $add_string_to_index($string, $index);
6670
+	}
6313 6671
 
6314 6672
 	if ($returnArray === true)
6315 6673
 	{
6316 6674
 		$regex = array();
6317
-		while (!empty($index))
6318
-			$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6675
+		while (!empty($index)) {
6676
+					$regex[] = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6677
+		}
6678
+	} else {
6679
+			$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6319 6680
 	}
6320
-	else
6321
-		$regex = '(?'.'>' . $index_to_regex($index, $delim) . ')';
6322 6681
 
6323 6682
 	// Restore PHP's internal character encoding to whatever it was originally
6324
-	if (!empty($current_encoding))
6325
-		mb_internal_encoding($current_encoding);
6683
+	if (!empty($current_encoding)) {
6684
+			mb_internal_encoding($current_encoding);
6685
+	}
6326 6686
 
6327 6687
 	return $regex;
6328 6688
 }
@@ -6365,13 +6725,15 @@  discard block
 block discarded – undo
6365 6725
 	// Need to add the trailing slash, or it puts it there & thinks there's a redirect when there isn't...
6366 6726
 	$url = str_ireplace('https://', 'http://', $url) . '/';
6367 6727
 	$headers = @get_headers($url);
6368
-	if ($headers === false)
6369
-		return false;
6728
+	if ($headers === false) {
6729
+			return false;
6730
+	}
6370 6731
 
6371 6732
 	// Now to see if it came back https...
6372 6733
 	// First check for a redirect status code in first row (301, 302, 307)
6373
-	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false)
6374
-		return false;
6734
+	if (strstr($headers[0], '301') === false && strstr($headers[0], '302') === false && strstr($headers[0], '307') === false) {
6735
+			return false;
6736
+	}
6375 6737
 
6376 6738
 	// Search for the location entry to confirm https
6377 6739
 	$result = false;
@@ -6409,8 +6771,7 @@  discard block
 block discarded – undo
6409 6771
 		$is_admin = $user_info['is_admin'];
6410 6772
 		$mod_cache = !empty($user_info['mod_cache']) ? $user_info['mod_cache'] : null;
6411 6773
 		$ignoreboards = !empty($user_info['ignoreboards']) ? $user_info['ignoreboards'] : null;
6412
-	}
6413
-	else
6774
+	} else
6414 6775
 	{
6415 6776
 		$request = $smcFunc['db_query']('', '
6416 6777
 				SELECT mem.ignore_boards, mem.id_group, mem.additional_groups, mem.id_post_group
@@ -6424,17 +6785,19 @@  discard block
 block discarded – undo
6424 6785
 
6425 6786
 		$row = $smcFunc['db_fetch_assoc']($request);
6426 6787
 
6427
-		if (empty($row['additional_groups']))
6428
-			$groups = array($row['id_group'], $row['id_post_group']);
6429
-		else
6430
-			$groups = array_merge(
6788
+		if (empty($row['additional_groups'])) {
6789
+					$groups = array($row['id_group'], $row['id_post_group']);
6790
+		} else {
6791
+					$groups = array_merge(
6431 6792
 					array($row['id_group'], $row['id_post_group']),
6432 6793
 					explode(',', $row['additional_groups'])
6433 6794
 			);
6795
+		}
6434 6796
 
6435 6797
 		// Because history has proven that it is possible for groups to go bad - clean up in case.
6436
-		foreach ($groups as $k => $v)
6437
-			$groups[$k] = (int) $v;
6798
+		foreach ($groups as $k => $v) {
6799
+					$groups[$k] = (int) $v;
6800
+		}
6438 6801
 
6439 6802
 		$is_admin = in_array(1, $groups);
6440 6803
 
@@ -6451,8 +6814,9 @@  discard block
 block discarded – undo
6451 6814
 				'current_member' => $userid,
6452 6815
 			)
6453 6816
 		);
6454
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6455
-			$boards_mod[] = $row['id_board'];
6817
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6818
+					$boards_mod[] = $row['id_board'];
6819
+		}
6456 6820
 		$smcFunc['db_free_result']($request);
6457 6821
 
6458 6822
 		// Can any of the groups they're in moderate any of the boards?
@@ -6464,8 +6828,9 @@  discard block
 block discarded – undo
6464 6828
 				'groups' => $groups,
6465 6829
 			)
6466 6830
 		);
6467
-		while ($row = $smcFunc['db_fetch_assoc']($request))
6468
-			$boards_mod[] = $row['id_board'];
6831
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
6832
+					$boards_mod[] = $row['id_board'];
6833
+		}
6469 6834
 		$smcFunc['db_free_result']($request);
6470 6835
 
6471 6836
 		// Just in case we've got duplicates here...
@@ -6475,21 +6840,25 @@  discard block
 block discarded – undo
6475 6840
 	}
6476 6841
 
6477 6842
 	// Just build this here, it makes it easier to change/use - administrators can see all boards.
6478
-	if ($is_admin)
6479
-		$query_part['query_see_board'] = '1=1';
6843
+	if ($is_admin) {
6844
+			$query_part['query_see_board'] = '1=1';
6845
+	}
6480 6846
 	// Otherwise just the groups in $user_info['groups'].
6481
-	else
6482
-		$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'] : '') . ')';
6847
+	else {
6848
+			$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'] : '') . ')';
6849
+	}
6483 6850
 
6484 6851
 	// Build the list of boards they WANT to see.
6485 6852
 	// This will take the place of query_see_boards in certain spots, so it better include the boards they can see also
6486 6853
 
6487 6854
 	// If they aren't ignoring any boards then they want to see all the boards they can see
6488
-	if (empty($ignoreboards))
6489
-		$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6855
+	if (empty($ignoreboards)) {
6856
+			$query_part['query_wanna_see_board'] = $query_part['query_see_board'];
6857
+	}
6490 6858
 	// Ok I guess they don't want to see all the boards
6491
-	else
6492
-		$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6859
+	else {
6860
+			$query_part['query_wanna_see_board'] = '(' . $query_part['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $ignoreboards) . '))';
6861
+	}
6493 6862
 
6494 6863
 	return $query_part;
6495 6864
 }
@@ -6503,10 +6872,11 @@  discard block
 block discarded – undo
6503 6872
 {
6504 6873
 	$secure = false;
6505 6874
 
6506
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
6507
-		$secure = true;
6508
-	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')
6509
-		$secure = true;
6875
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
6876
+			$secure = true;
6877
+	} 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') {
6878
+			$secure = true;
6879
+	}
6510 6880
 
6511 6881
 	return $secure;
6512 6882
 }
@@ -6523,11 +6893,12 @@  discard block
 block discarded – undo
6523 6893
 {
6524 6894
 	$url = iri_to_url($iri);
6525 6895
 
6526
-	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false)
6527
-		return $iri;
6528
-	else
6529
-		return false;
6530
-}
6896
+	if (filter_var($url, FILTER_VALIDATE_URL, $flags) !== false) {
6897
+			return $iri;
6898
+	} else {
6899
+			return false;
6900
+	}
6901
+	}
6531 6902
 
6532 6903
 /**
6533 6904
  * A wrapper for `filter_var($url, FILTER_SANITIZE_URL)` that can handle URLs
@@ -6570,8 +6941,9 @@  discard block
 block discarded – undo
6570 6941
 
6571 6942
 	$host = parse_url((strpos($iri, '://') === false ? 'http://' : '') . ltrim($iri, ':/'), PHP_URL_HOST);
6572 6943
 
6573
-	if (empty($host))
6574
-		return $iri;
6944
+	if (empty($host)) {
6945
+			return $iri;
6946
+	}
6575 6947
 
6576 6948
 	// Convert the domain using the Punycode algorithm
6577 6949
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6607,8 +6979,9 @@  discard block
 block discarded – undo
6607 6979
 
6608 6980
 	$host = parse_url((strpos($url, '://') === false ? 'http://' : '') . ltrim($url, ':/'), PHP_URL_HOST);
6609 6981
 
6610
-	if (empty($host))
6611
-		return $url;
6982
+	if (empty($host)) {
6983
+			return $url;
6984
+	}
6612 6985
 
6613 6986
 	// Decode the domain from Punycode
6614 6987
 	require_once($sourcedir . '/Class-Punycode.php');
@@ -6634,8 +7007,9 @@  discard block
 block discarded – undo
6634 7007
 {
6635 7008
 	global $user_info, $modSettings, $smcFunc, $txt;
6636 7009
 
6637
-	if (empty($modSettings['cron_last_checked']))
6638
-		$modSettings['cron_last_checked'] = 0;
7010
+	if (empty($modSettings['cron_last_checked'])) {
7011
+			$modSettings['cron_last_checked'] = 0;
7012
+	}
6639 7013
 
6640 7014
 	if (!empty($modSettings['cron_is_real_cron']) && time() - $modSettings['cron_last_checked'] > 84600)
6641 7015
 	{
@@ -6655,9 +7029,9 @@  discard block
 block discarded – undo
6655 7029
 			loadLanguage('ManageScheduledTasks');
6656 7030
 			log_error($txt['cron_not_working']);
6657 7031
 			updateSettings(array('cron_is_real_cron' => 0));
7032
+		} else {
7033
+					updateSettings(array('cron_last_checked' => time()));
6658 7034
 		}
6659
-		else
6660
-			updateSettings(array('cron_last_checked' => time()));
6661 7035
 	}
6662 7036
 }
6663 7037
 
Please login to merge, or discard this patch.