Completed
Pull Request — release-2.1 (#5077)
by Mathias
06:33
created
other/upgrade.php 1 patch
Braces   +935 added lines, -690 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
 	// Show the upgrade time for CLI when we are completely done, if in debug mode.
@@ -403,12 +424,13 @@  discard block
 block discarded – undo
403 424
 		$seconds = intval($active % 60);
404 425
 
405 426
 		$totalTime = '';
406
-		if ($hours > 0)
407
-			echo "\n" . '', sprintf($txt['upgrade_completed_time_hms'], $hours, $minutes, $seconds), '' . "\n";
408
-		elseif ($minutes > 0)
409
-			echo "\n" . '', sprintf($txt['upgrade_completed_time_ms'], $minutes, $seconds), '' . "\n";
410
-		elseif ($seconds > 0)
411
-			echo "\n" . '', sprintf($txt['upgrade_completed_time_s'], $seconds), '' . "\n";
427
+		if ($hours > 0) {
428
+					echo "\n" . '', sprintf($txt['upgrade_completed_time_hms'], $hours, $minutes, $seconds), '' . "\n";
429
+		} elseif ($minutes > 0) {
430
+					echo "\n" . '', sprintf($txt['upgrade_completed_time_ms'], $minutes, $seconds), '' . "\n";
431
+		} elseif ($seconds > 0) {
432
+					echo "\n" . '', sprintf($txt['upgrade_completed_time_s'], $seconds), '' . "\n";
433
+		}
412 434
 	}
413 435
 
414 436
 	// Bang - gone!
@@ -429,8 +451,9 @@  discard block
 block discarded – undo
429 451
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
430 452
 		while ($entry = $dir->read())
431 453
 		{
432
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
433
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
454
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
455
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
456
+			}
434 457
 		}
435 458
 		$dir->close();
436 459
 	}
@@ -474,10 +497,11 @@  discard block
 block discarded – undo
474 497
 	}
475 498
 
476 499
 	// Override the language file?
477
-	if (isset($_GET['lang_file']))
478
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
479
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
480
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
500
+	if (isset($_GET['lang_file'])) {
501
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
502
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
503
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
504
+	}
481 505
 
482 506
 	// Make sure it exists, if it doesn't reset it.
483 507
 	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']))
@@ -486,12 +510,14 @@  discard block
 block discarded – undo
486 510
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
487 511
 
488 512
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
489
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
490
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
513
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
514
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
515
+		}
491 516
 
492 517
 		// For backup we load the english at first -> second language overwrite the english one
493
-		if (count($incontext['detected_languages']) > 1)
494
-			require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
518
+		if (count($incontext['detected_languages']) > 1) {
519
+					require_once(dirname(__FILE__) . '/Themes/default/languages/Install.english.php');
520
+		}
495 521
 	}
496 522
 
497 523
 	// And now include the actual language file itself.
@@ -499,11 +525,12 @@  discard block
 block discarded – undo
499 525
 
500 526
 	// Which language did we load? Assume that he likes his language.
501 527
 	preg_match('~^Install\.(.+[^-utf8])\.php$~', $_SESSION['installer_temp_lang'], $matches);
502
-	if (empty($matches[1]))
503
-		$matches = [
528
+	if (empty($matches[1])) {
529
+			$matches = [
504 530
 			0 => 'nothing',
505 531
 			1 => 'english',
506 532
 		];
533
+	}
507 534
 	$user_info['language'] = $matches[1];
508 535
 }
509 536
 
@@ -513,8 +540,9 @@  discard block
 block discarded – undo
513 540
 	global $upgradeurl, $upcontext, $command_line;
514 541
 
515 542
 	// Command line users can't be redirected.
516
-	if ($command_line)
517
-		upgradeExit(true);
543
+	if ($command_line) {
544
+			upgradeExit(true);
545
+	}
518 546
 
519 547
 	// Are we providing the core info?
520 548
 	if ($addForm)
@@ -540,12 +568,14 @@  discard block
 block discarded – undo
540 568
 	define('SMF', 1);
541 569
 
542 570
 	// Start the session.
543
-	if (@ini_get('session.save_handler') == 'user')
544
-		@ini_set('session.save_handler', 'files');
571
+	if (@ini_get('session.save_handler') == 'user') {
572
+			@ini_set('session.save_handler', 'files');
573
+	}
545 574
 	@session_start();
546 575
 
547
-	if (empty($smcFunc))
548
-		$smcFunc = array();
576
+	if (empty($smcFunc)) {
577
+			$smcFunc = array();
578
+	}
549 579
 
550 580
 	// We need this for authentication and some upgrade code
551 581
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -576,30 +606,34 @@  discard block
 block discarded – undo
576 606
 		{
577 607
 			$options = array('non_fatal' => true);
578 608
 			// Add in the port if needed
579
-			if (!empty($db_port))
580
-				$options['port'] = $db_port;
609
+			if (!empty($db_port)) {
610
+							$options['port'] = $db_port;
611
+			}
581 612
 			
582
-			if (!empty($db_mb4))
583
-				$options['db_mb4'] = $db_mb4;
613
+			if (!empty($db_mb4)) {
614
+							$options['db_mb4'] = $db_mb4;
615
+			}
584 616
 			
585 617
 			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
586
-		}
587
-		else
588
-			// If we've returned here, ping/reconnect to be safe
618
+		} else {
619
+					// If we've returned here, ping/reconnect to be safe
589 620
 			$smcFunc['db_ping']($db_connection);
621
+		}
590 622
 
591 623
 		// Oh dear god!!
592
-		if ($db_connection === null)
593
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
624
+		if ($db_connection === null) {
625
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
626
+		}
594 627
 
595
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
596
-			$smcFunc['db_query']('', '
628
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
629
+					$smcFunc['db_query']('', '
597 630
 			SET NAMES {string:db_character_set}',
598 631
 			array(
599 632
 				'db_error_skip' => true,
600 633
 				'db_character_set' => $db_character_set,
601 634
 			)
602 635
 		);
636
+		}
603 637
 
604 638
 		// Load the modSettings data...
605 639
 		$request = $smcFunc['db_query']('', '
@@ -610,11 +644,11 @@  discard block
 block discarded – undo
610 644
 			)
611 645
 		);
612 646
 		$modSettings = array();
613
-		while ($row = $smcFunc['db_fetch_assoc']($request))
614
-			$modSettings[$row['variable']] = $row['value'];
647
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
648
+					$modSettings[$row['variable']] = $row['value'];
649
+		}
615 650
 		$smcFunc['db_free_result']($request);
616
-	}
617
-	else
651
+	} else
618 652
 	{
619 653
 		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.');
620 654
 	}
@@ -628,9 +662,10 @@  discard block
 block discarded – undo
628 662
 		cleanRequest();
629 663
 	}
630 664
 
631
-	if (!isset($_GET['substep']))
632
-		$_GET['substep'] = 0;
633
-}
665
+	if (!isset($_GET['substep'])) {
666
+			$_GET['substep'] = 0;
667
+	}
668
+	}
634 669
 
635 670
 function initialize_inputs()
636 671
 {
@@ -660,8 +695,9 @@  discard block
 block discarded – undo
660 695
 		$dh = opendir(dirname(__FILE__));
661 696
 		while ($file = readdir($dh))
662 697
 		{
663
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
664
-				@unlink(dirname(__FILE__) . '/' . $file);
698
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
699
+							@unlink(dirname(__FILE__) . '/' . $file);
700
+			}
665 701
 		}
666 702
 		closedir($dh);
667 703
 
@@ -690,8 +726,9 @@  discard block
 block discarded – undo
690 726
 	$temp = 'upgrade_php?step';
691 727
 	while (strlen($temp) > 4)
692 728
 	{
693
-		if (isset($_GET[$temp]))
694
-			unset($_GET[$temp]);
729
+		if (isset($_GET[$temp])) {
730
+					unset($_GET[$temp]);
731
+		}
695 732
 		$temp = substr($temp, 1);
696 733
 	}
697 734
 
@@ -718,32 +755,39 @@  discard block
 block discarded – undo
718 755
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
719 756
 
720 757
 	// Need legacy scripts?
721
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
722
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
723
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
724
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
725
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
726
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
758
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
759
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
760
+	}
761
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
762
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
763
+	}
764
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
765
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
766
+	}
727 767
 
728 768
 	// We don't need "-utf8" files anymore...
729 769
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
730 770
 
731 771
 	// This needs to exist!
732
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
733
-		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>]');
734
-	else
735
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
772
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
773
+			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>]');
774
+	} else {
775
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
776
+	}
736 777
 
737
-	if (!$check)
738
-		// 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.
778
+	if (!$check) {
779
+			// 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.
739 780
 		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.');
781
+	}
740 782
 
741 783
 	// Do they meet the install requirements?
742
-	if (!php_version_check())
743
-		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.');
784
+	if (!php_version_check()) {
785
+			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.');
786
+	}
744 787
 
745
-	if (!db_version_check())
746
-		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.');
788
+	if (!db_version_check()) {
789
+			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.');
790
+	}
747 791
 
748 792
 	// Do some checks to make sure they have proper privileges
749 793
 	db_extend('packages');
@@ -758,14 +802,16 @@  discard block
 block discarded – undo
758 802
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
759 803
 
760 804
 	// Sorry... we need CREATE, ALTER and DROP
761
-	if (!$create || !$alter || !$drop)
762
-		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.');
805
+	if (!$create || !$alter || !$drop) {
806
+			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.');
807
+	}
763 808
 
764 809
 	// Do a quick version spot check.
765 810
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
766 811
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
767
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
768
-		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.');
812
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
813
+			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.');
814
+	}
769 815
 
770 816
 	// What absolutely needs to be writable?
771 817
 	$writable_files = array(
@@ -774,12 +820,13 @@  discard block
 block discarded – undo
774 820
 	);
775 821
 
776 822
 	// Only check for minified writable files if we have it enabled or not set.
777
-	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files']))
778
-		$writable_files += array(
823
+	if (!empty($modSettings['minimize_files']) || !isset($modSettings['minimize_files'])) {
824
+			$writable_files += array(
779 825
 			$modSettings['theme_dir'] . '/css/minified.css',
780 826
 			$modSettings['theme_dir'] . '/scripts/minified.js',
781 827
 			$modSettings['theme_dir'] . '/scripts/minified_deferred.js',
782 828
 		);
829
+	}
783 830
 
784 831
 	// Do we need to add this setting?
785 832
 	$need_settings_update = empty($modSettings['custom_avatar_dir']);
@@ -791,12 +838,13 @@  discard block
 block discarded – undo
791 838
 	quickFileWritable($custom_av_dir);
792 839
 
793 840
 	// Are we good now?
794
-	if (!is_writable($custom_av_dir))
795
-		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));
796
-	elseif ($need_settings_update)
841
+	if (!is_writable($custom_av_dir)) {
842
+			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));
843
+	} elseif ($need_settings_update)
797 844
 	{
798
-		if (!function_exists('cache_put_data'))
799
-			require_once($sourcedir . '/Load.php');
845
+		if (!function_exists('cache_put_data')) {
846
+					require_once($sourcedir . '/Load.php');
847
+		}
800 848
 
801 849
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
802 850
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
@@ -806,29 +854,34 @@  discard block
 block discarded – undo
806 854
 
807 855
 	// Check the cache directory.
808 856
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
809
-	if (!file_exists($cachedir_temp))
810
-		@mkdir($cachedir_temp);
857
+	if (!file_exists($cachedir_temp)) {
858
+			@mkdir($cachedir_temp);
859
+	}
811 860
 
812
-	if (!file_exists($cachedir_temp))
813
-		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.');
861
+	if (!file_exists($cachedir_temp)) {
862
+			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.');
863
+	}
814 864
 
815
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
816
-		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>.');
817
-	elseif (!isset($_GET['skiplang']))
865
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
866
+			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>.');
867
+	} elseif (!isset($_GET['skiplang']))
818 868
 	{
819 869
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
820 870
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
821 871
 
822
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
823
-			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>]');
872
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
873
+					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>]');
874
+		}
824 875
 	}
825 876
 
826
-	if (!makeFilesWritable($writable_files))
827
-		return false;
877
+	if (!makeFilesWritable($writable_files)) {
878
+			return false;
879
+	}
828 880
 
829 881
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
830
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
831
-		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.');
882
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
883
+			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.');
884
+	}
832 885
 
833 886
 	// Upgrade the agreement.
834 887
 	elseif (isset($modSettings['agreement']))
@@ -839,8 +892,8 @@  discard block
 block discarded – undo
839 892
 	}
840 893
 
841 894
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
842
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
843
-		$upcontext['warning'] = '
895
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
896
+			$upcontext['warning'] = '
844 897
 			'. sprintf($txt['upgrade_boarddir_settings'], $boarddir, dirname(__FILE__)) .'<br>
845 898
 			<ul>
846 899
 				<li>'. $txt['upgrade_boarddir'] .'  ' . $boarddir . '</li>
@@ -848,19 +901,23 @@  discard block
 block discarded – undo
848 901
 				<li>'. $txt['upgrade_cachedir'] .'  ' . $cachedir_temp . '</li>
849 902
 			</ul>
850 903
 			'. $txt['upgrade_incorrect_settings'] .'';
904
+	}
851 905
 
852 906
 	// Confirm mbstring is loaded...
853
-	if (!extension_loaded('mbstring'))
854
-		return throw_error($txt['install_no_mbstring']);
907
+	if (!extension_loaded('mbstring')) {
908
+			return throw_error($txt['install_no_mbstring']);
909
+	}
855 910
 
856 911
 	// Check for https stream support.
857 912
 	$supported_streams = stream_get_wrappers();
858
-	if (!in_array('https', $supported_streams))
859
-		$upcontext['custom_warning'] = $txt['install_no_https'];
913
+	if (!in_array('https', $supported_streams)) {
914
+			$upcontext['custom_warning'] = $txt['install_no_https'];
915
+	}
860 916
 
861 917
 	// Either we're logged in or we're going to present the login.
862
-	if (checkLogin())
863
-		return true;
918
+	if (checkLogin()) {
919
+			return true;
920
+	}
864 921
 
865 922
 	$upcontext += createToken('login');
866 923
 
@@ -874,15 +931,17 @@  discard block
 block discarded – undo
874 931
 	global $smcFunc, $db_type, $support_js;
875 932
 
876 933
 	// Don't bother if the security is disabled.
877
-	if ($disable_security)
878
-		return true;
934
+	if ($disable_security) {
935
+			return true;
936
+	}
879 937
 
880 938
 	// Are we trying to login?
881 939
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
882 940
 	{
883 941
 		// If we've disabled security pick a suitable name!
884
-		if (empty($_POST['user']))
885
-			$_POST['user'] = 'Administrator';
942
+		if (empty($_POST['user'])) {
943
+					$_POST['user'] = 'Administrator';
944
+		}
886 945
 
887 946
 		// Before 2.0 these column names were different!
888 947
 		$oldDB = false;
@@ -897,16 +956,17 @@  discard block
 block discarded – undo
897 956
 					'db_error_skip' => true,
898 957
 				)
899 958
 			);
900
-			if ($smcFunc['db_num_rows']($request) != 0)
901
-				$oldDB = true;
959
+			if ($smcFunc['db_num_rows']($request) != 0) {
960
+							$oldDB = true;
961
+			}
902 962
 			$smcFunc['db_free_result']($request);
903 963
 		}
904 964
 
905 965
 		// Get what we believe to be their details.
906 966
 		if (!$disable_security)
907 967
 		{
908
-			if ($oldDB)
909
-				$request = $smcFunc['db_query']('', '
968
+			if ($oldDB) {
969
+							$request = $smcFunc['db_query']('', '
910 970
 					SELECT id_member, memberName AS member_name, passwd, id_group,
911 971
 					additionalGroups AS additional_groups, lngfile
912 972
 					FROM {db_prefix}members
@@ -916,8 +976,8 @@  discard block
 block discarded – undo
916 976
 						'db_error_skip' => true,
917 977
 					)
918 978
 				);
919
-			else
920
-				$request = $smcFunc['db_query']('', '
979
+			} else {
980
+							$request = $smcFunc['db_query']('', '
921 981
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
922 982
 					FROM {db_prefix}members
923 983
 					WHERE member_name = {string:member_name}',
@@ -926,6 +986,7 @@  discard block
 block discarded – undo
926 986
 						'db_error_skip' => true,
927 987
 					)
928 988
 				);
989
+			}
929 990
 			if ($smcFunc['db_num_rows']($request) != 0)
930 991
 			{
931 992
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -933,16 +994,17 @@  discard block
 block discarded – undo
933 994
 				$groups = explode(',', $addGroups);
934 995
 				$groups[] = $id_group;
935 996
 
936
-				foreach ($groups as $k => $v)
937
-					$groups[$k] = (int) $v;
997
+				foreach ($groups as $k => $v) {
998
+									$groups[$k] = (int) $v;
999
+				}
938 1000
 
939 1001
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
940 1002
 
941 1003
 				// We don't use "-utf8" anymore...
942 1004
 				$user_language = str_ireplace('-utf8', '', $user_language);
1005
+			} else {
1006
+							$upcontext['username_incorrect'] = true;
943 1007
 			}
944
-			else
945
-				$upcontext['username_incorrect'] = true;
946 1008
 
947 1009
 			$smcFunc['db_free_result']($request);
948 1010
 		}
@@ -953,13 +1015,14 @@  discard block
 block discarded – undo
953 1015
 		{
954 1016
 			$upcontext['upgrade_status']['js'] = 1;
955 1017
 			$support_js = 1;
1018
+		} else {
1019
+					$support_js = 0;
956 1020
 		}
957
-		else
958
-			$support_js = 0;
959 1021
 
960 1022
 		// Note down the version we are coming from.
961
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
962
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
1023
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
1024
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
1025
+		}
963 1026
 
964 1027
 		// Didn't get anywhere?
965 1028
 		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']))
@@ -993,15 +1056,15 @@  discard block
 block discarded – undo
993 1056
 							'db_error_skip' => true,
994 1057
 						)
995 1058
 					);
996
-					if ($smcFunc['db_num_rows']($request) == 0)
997
-						return throw_error('You need to be an admin to perform an upgrade!');
1059
+					if ($smcFunc['db_num_rows']($request) == 0) {
1060
+											return throw_error('You need to be an admin to perform an upgrade!');
1061
+					}
998 1062
 					$smcFunc['db_free_result']($request);
999 1063
 				}
1000 1064
 
1001 1065
 				$upcontext['user']['id'] = $id_member;
1002 1066
 				$upcontext['user']['name'] = $name;
1003
-			}
1004
-			else
1067
+			} else
1005 1068
 			{
1006 1069
 				$upcontext['user']['id'] = 1;
1007 1070
 				$upcontext['user']['name'] = 'Administrator';
@@ -1017,11 +1080,11 @@  discard block
 block discarded – undo
1017 1080
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
1018 1081
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
1019 1082
 
1020
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
1021
-					$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'] . '.';
1022
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
1023
-					$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'] . '.';
1024
-				else
1083
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
1084
+									$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'] . '.';
1085
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
1086
+									$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'] . '.';
1087
+				} else
1025 1088
 				{
1026 1089
 					// Set this as the new language.
1027 1090
 					$upcontext['language'] = $user_language;
@@ -1068,8 +1131,9 @@  discard block
 block discarded – undo
1068 1131
 	$upcontext['migrateSettingsNeeded'] = detectSettingsFileMigrationNeeded() ? 1 : 0;
1069 1132
 
1070 1133
 	// If we've not submitted then we're done.
1071
-	if (empty($_POST['upcont']))
1072
-		return false;
1134
+	if (empty($_POST['upcont'])) {
1135
+			return false;
1136
+	}
1073 1137
 
1074 1138
 	// Firstly, if they're enabling SM stat collection just do it.
1075 1139
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -1089,16 +1153,17 @@  discard block
 block discarded – undo
1089 1153
 				fwrite($fp, $out);
1090 1154
 
1091 1155
 				$return_data = '';
1092
-				while (!feof($fp))
1093
-					$return_data .= fgets($fp, 128);
1156
+				while (!feof($fp)) {
1157
+									$return_data .= fgets($fp, 128);
1158
+				}
1094 1159
 
1095 1160
 				fclose($fp);
1096 1161
 
1097 1162
 				// Get the unique site ID.
1098 1163
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1099 1164
 
1100
-				if (!empty($ID[1]))
1101
-					$smcFunc['db_insert']('replace',
1165
+				if (!empty($ID[1])) {
1166
+									$smcFunc['db_insert']('replace',
1102 1167
 						$db_prefix . 'settings',
1103 1168
 						array('variable' => 'string', 'value' => 'string'),
1104 1169
 						array(
@@ -1107,9 +1172,9 @@  discard block
 block discarded – undo
1107 1172
 						),
1108 1173
 						array('variable')
1109 1174
 					);
1175
+				}
1110 1176
 			}
1111
-		}
1112
-		else
1177
+		} else
1113 1178
 		{
1114 1179
 			$smcFunc['db_insert']('replace',
1115 1180
 				$db_prefix . 'settings',
@@ -1120,8 +1185,8 @@  discard block
 block discarded – undo
1120 1185
 		}
1121 1186
 	}
1122 1187
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1123
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1124
-		$smcFunc['db_query']('', '
1188
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1189
+			$smcFunc['db_query']('', '
1125 1190
 			DELETE FROM {db_prefix}settings
1126 1191
 			WHERE variable = {string:enable_sm_stats}',
1127 1192
 			array(
@@ -1129,6 +1194,7 @@  discard block
 block discarded – undo
1129 1194
 				'db_error_skip' => true,
1130 1195
 			)
1131 1196
 		);
1197
+	}
1132 1198
 
1133 1199
 	// Deleting old karma stuff?
1134 1200
 	if (!empty($_POST['delete_karma']))
@@ -1143,20 +1209,22 @@  discard block
 block discarded – undo
1143 1209
 		);
1144 1210
 
1145 1211
 		// Cleaning up old karma member settings.
1146
-		if ($upcontext['karma_installed']['good'])
1147
-			$smcFunc['db_query']('', '
1212
+		if ($upcontext['karma_installed']['good']) {
1213
+					$smcFunc['db_query']('', '
1148 1214
 				ALTER TABLE {db_prefix}members
1149 1215
 				DROP karma_good',
1150 1216
 				array()
1151 1217
 			);
1218
+		}
1152 1219
 
1153 1220
 		// Does karma bad was enable?
1154
-		if ($upcontext['karma_installed']['bad'])
1155
-			$smcFunc['db_query']('', '
1221
+		if ($upcontext['karma_installed']['bad']) {
1222
+					$smcFunc['db_query']('', '
1156 1223
 				ALTER TABLE {db_prefix}members
1157 1224
 				DROP karma_bad',
1158 1225
 				array()
1159 1226
 			);
1227
+		}
1160 1228
 
1161 1229
 		// Cleaning up old karma permissions.
1162 1230
 		$smcFunc['db_query']('', '
@@ -1174,32 +1242,37 @@  discard block
 block discarded – undo
1174 1242
 	}
1175 1243
 
1176 1244
 	// Emptying the error log?
1177
-	if (!empty($_POST['empty_error']))
1178
-		$smcFunc['db_query']('truncate_table', '
1245
+	if (!empty($_POST['empty_error'])) {
1246
+			$smcFunc['db_query']('truncate_table', '
1179 1247
 			TRUNCATE {db_prefix}log_errors',
1180 1248
 			array(
1181 1249
 			)
1182 1250
 		);
1251
+	}
1183 1252
 
1184 1253
 	$changes = array();
1185 1254
 
1186 1255
 	// Add proxy settings.
1187
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1188
-		$changes += array(
1256
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1257
+			$changes += array(
1189 1258
 			'image_proxy_secret' => '\'' . substr(sha1(random_int(0, PHP_INT_MAX)), 0, 20) . '\'',
1190 1259
 			'image_proxy_maxsize' => 5190,
1191 1260
 			'image_proxy_enabled' => 0,
1192 1261
 		);
1262
+	}
1193 1263
 
1194 1264
 	// If $boardurl reflects https, set force_ssl
1195
-	if (!function_exists('cache_put_data'))
1196
-		require_once($sourcedir . '/Load.php');
1197
-	if (stripos($boardurl, 'https://') !== false)
1198
-		updateSettings(array('force_ssl' => '1'));
1265
+	if (!function_exists('cache_put_data')) {
1266
+			require_once($sourcedir . '/Load.php');
1267
+	}
1268
+	if (stripos($boardurl, 'https://') !== false) {
1269
+			updateSettings(array('force_ssl' => '1'));
1270
+	}
1199 1271
 
1200 1272
 	// If we're overriding the language follow it through.
1201
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1202
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1273
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1274
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1275
+	}
1203 1276
 
1204 1277
 	if (!empty($_POST['maint']))
1205 1278
 	{
@@ -1211,26 +1284,29 @@  discard block
 block discarded – undo
1211 1284
 		{
1212 1285
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1213 1286
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1214
-		}
1215
-		else
1287
+		} else
1216 1288
 		{
1217 1289
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1218 1290
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1219 1291
 		}
1220 1292
 	}
1221 1293
 
1222
-	if ($command_line)
1223
-		echo ' * Updating Settings.php...';
1294
+	if ($command_line) {
1295
+			echo ' * Updating Settings.php...';
1296
+	}
1224 1297
 
1225 1298
 	// Fix some old paths.
1226
-	if (substr($boarddir, 0, 1) == '.')
1227
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1299
+	if (substr($boarddir, 0, 1) == '.') {
1300
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1301
+	}
1228 1302
 
1229
-	if (substr($sourcedir, 0, 1) == '.')
1230
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1303
+	if (substr($sourcedir, 0, 1) == '.') {
1304
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1305
+	}
1231 1306
 
1232
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1233
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1307
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1308
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1309
+	}
1234 1310
 
1235 1311
 	// If they have a "host:port" setup for the host, split that into separate values
1236 1312
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1241,32 +1317,36 @@  discard block
 block discarded – undo
1241 1317
 		$changes['db_server'] = '\'' . $db_server . '\'';
1242 1318
 
1243 1319
 		// Only set this if we're not using the default port
1244
-		if ($db_port != ini_get('mysqli.default_port'))
1245
-			$changes['db_port'] = (int) $db_port;
1246
-	}
1247
-	elseif (!empty($db_port))
1320
+		if ($db_port != ini_get('mysqli.default_port')) {
1321
+					$changes['db_port'] = (int) $db_port;
1322
+		}
1323
+	} elseif (!empty($db_port))
1248 1324
 	{
1249 1325
 		// If db_port is set and is the same as the default, set it to ''
1250 1326
 		if ($db_type == 'mysql')
1251 1327
 		{
1252
-			if ($db_port == ini_get('mysqli.default_port'))
1253
-				$changes['db_port'] = '\'\'';
1254
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1255
-				$changes['db_port'] = '\'\'';
1328
+			if ($db_port == ini_get('mysqli.default_port')) {
1329
+							$changes['db_port'] = '\'\'';
1330
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1331
+							$changes['db_port'] = '\'\'';
1332
+			}
1256 1333
 		}
1257 1334
 	}
1258 1335
 
1259 1336
 	// Maybe we haven't had this option yet?
1260
-	if (empty($packagesdir))
1261
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1337
+	if (empty($packagesdir)) {
1338
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1339
+	}
1262 1340
 
1263 1341
 	// Add support for $tasksdir var.
1264
-	if (empty($tasksdir))
1265
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1342
+	if (empty($tasksdir)) {
1343
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1344
+	}
1266 1345
 
1267 1346
 	// Make sure we fix the language as well.
1268
-	if (stristr($language, '-utf8'))
1269
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1347
+	if (stristr($language, '-utf8')) {
1348
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1349
+	}
1270 1350
 
1271 1351
 	// @todo Maybe change the cookie name if going to 1.1, too?
1272 1352
 
@@ -1277,8 +1357,7 @@  discard block
 block discarded – undo
1277 1357
 		$changes['upgradeData'] = '"' . base64_encode(json_encode($upcontext['user'])) . '"';
1278 1358
 
1279 1359
 		migrateSettingsFile($changes);
1280
-	}
1281
-	else
1360
+	} else
1282 1361
 	{
1283 1362
 		// Update Settings.php with the new settings.
1284 1363
 		require_once($sourcedir . '/Subs-Admin.php');
@@ -1288,8 +1367,9 @@  discard block
 block discarded – undo
1288 1367
 		move_db_last_error_to_cachedir();
1289 1368
 	}
1290 1369
 
1291
-	if ($command_line)
1292
-		echo ' Successful.' . "\n";
1370
+	if ($command_line) {
1371
+			echo ' Successful.' . "\n";
1372
+	}
1293 1373
 
1294 1374
 	// Are we doing debug?
1295 1375
 	if (isset($_POST['debug']))
@@ -1299,8 +1379,9 @@  discard block
 block discarded – undo
1299 1379
 	}
1300 1380
 
1301 1381
 	// If we're not backing up then jump one.
1302
-	if (empty($_POST['backup']))
1303
-		$upcontext['current_step']++;
1382
+	if (empty($_POST['backup'])) {
1383
+			$upcontext['current_step']++;
1384
+	}
1304 1385
 
1305 1386
 	// If we've got here then let's proceed to the next step!
1306 1387
 	return true;
@@ -1315,8 +1396,9 @@  discard block
 block discarded – undo
1315 1396
 	$upcontext['page_title'] = $txt['backup_database'];
1316 1397
 
1317 1398
 	// Done it already - js wise?
1318
-	if (!empty($_POST['backup_done']))
1319
-		return true;
1399
+	if (!empty($_POST['backup_done'])) {
1400
+			return true;
1401
+	}
1320 1402
 
1321 1403
 	// Some useful stuff here.
1322 1404
 	db_extend();
@@ -1330,9 +1412,10 @@  discard block
 block discarded – undo
1330 1412
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1331 1413
 
1332 1414
 	$table_names = array();
1333
-	foreach ($tables as $table)
1334
-		if (substr($table, 0, 7) !== 'backup_')
1415
+	foreach ($tables as $table) {
1416
+			if (substr($table, 0, 7) !== 'backup_')
1335 1417
 			$table_names[] = $table;
1418
+	}
1336 1419
 
1337 1420
 	$upcontext['table_count'] = count($table_names);
1338 1421
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1342,12 +1425,14 @@  discard block
 block discarded – undo
1342 1425
 	$file_steps = $upcontext['table_count'];
1343 1426
 
1344 1427
 	// What ones have we already done?
1345
-	foreach ($table_names as $id => $table)
1346
-		if ($id < $_GET['substep'])
1428
+	foreach ($table_names as $id => $table) {
1429
+			if ($id < $_GET['substep'])
1347 1430
 			$upcontext['previous_tables'][] = $table;
1431
+	}
1348 1432
 
1349
-	if ($command_line)
1350
-		echo 'Backing Up Tables.';
1433
+	if ($command_line) {
1434
+			echo 'Backing Up Tables.';
1435
+	}
1351 1436
 
1352 1437
 	// If we don't support javascript we backup here.
1353 1438
 	if (!$support_js || isset($_GET['xml']))
@@ -1366,8 +1451,9 @@  discard block
 block discarded – undo
1366 1451
 			backupTable($table_names[$substep]);
1367 1452
 
1368 1453
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1369
-			if (isset($_GET['xml']))
1370
-				return upgradeExit();
1454
+			if (isset($_GET['xml'])) {
1455
+							return upgradeExit();
1456
+			}
1371 1457
 		}
1372 1458
 
1373 1459
 		if ($command_line)
@@ -1400,9 +1486,10 @@  discard block
 block discarded – undo
1400 1486
 
1401 1487
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1402 1488
 
1403
-	if ($command_line)
1404
-		echo ' done.';
1405
-}
1489
+	if ($command_line) {
1490
+			echo ' done.';
1491
+	}
1492
+	}
1406 1493
 
1407 1494
 // Step 2: Everything.
1408 1495
 function DatabaseChanges()
@@ -1411,8 +1498,9 @@  discard block
 block discarded – undo
1411 1498
 	global $upcontext, $support_js, $db_type;
1412 1499
 
1413 1500
 	// Have we just completed this?
1414
-	if (!empty($_POST['database_done']))
1415
-		return true;
1501
+	if (!empty($_POST['database_done'])) {
1502
+			return true;
1503
+	}
1416 1504
 
1417 1505
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1418 1506
 	$upcontext['page_title'] = $txt['database_changes'];
@@ -1427,15 +1515,16 @@  discard block
 block discarded – undo
1427 1515
 	);
1428 1516
 
1429 1517
 	// How many files are there in total?
1430
-	if (isset($_GET['filecount']))
1431
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1432
-	else
1518
+	if (isset($_GET['filecount'])) {
1519
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1520
+	} else
1433 1521
 	{
1434 1522
 		$upcontext['file_count'] = 0;
1435 1523
 		foreach ($files as $file)
1436 1524
 		{
1437
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1438
-				$upcontext['file_count']++;
1525
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1526
+							$upcontext['file_count']++;
1527
+			}
1439 1528
 		}
1440 1529
 	}
1441 1530
 
@@ -1445,9 +1534,9 @@  discard block
 block discarded – undo
1445 1534
 	$upcontext['cur_file_num'] = 0;
1446 1535
 	foreach ($files as $file)
1447 1536
 	{
1448
-		if ($did_not_do)
1449
-			$did_not_do--;
1450
-		else
1537
+		if ($did_not_do) {
1538
+					$did_not_do--;
1539
+		} else
1451 1540
 		{
1452 1541
 			$upcontext['cur_file_num']++;
1453 1542
 			$upcontext['cur_file_name'] = $file[0];
@@ -1474,12 +1563,13 @@  discard block
 block discarded – undo
1474 1563
 					// Flag to move on to the next.
1475 1564
 					$upcontext['completed_step'] = true;
1476 1565
 					// Did we complete the whole file?
1477
-					if ($nextFile)
1478
-						$upcontext['current_debug_item_num'] = -1;
1566
+					if ($nextFile) {
1567
+											$upcontext['current_debug_item_num'] = -1;
1568
+					}
1479 1569
 					return upgradeExit();
1570
+				} elseif ($support_js) {
1571
+									break;
1480 1572
 				}
1481
-				elseif ($support_js)
1482
-					break;
1483 1573
 			}
1484 1574
 			// Set the progress bar to be right as if we had - even if we hadn't...
1485 1575
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1505,8 +1595,9 @@  discard block
 block discarded – undo
1505 1595
 	global $user_info, $maintenance, $smcFunc, $db_type, $txt, $settings;
1506 1596
 
1507 1597
 	// Now it's nice to have some of the basic SMF source files.
1508
-	if (!isset($_GET['ssi']) && !$command_line)
1509
-		redirectLocation('&ssi=1');
1598
+	if (!isset($_GET['ssi']) && !$command_line) {
1599
+			redirectLocation('&ssi=1');
1600
+	}
1510 1601
 
1511 1602
 	$upcontext['sub_template'] = 'upgrade_complete';
1512 1603
 	$upcontext['page_title'] = $txt['upgrade_complete'];
@@ -1522,14 +1613,16 @@  discard block
 block discarded – undo
1522 1613
 	// Are we in maintenance mode?
1523 1614
 	if (isset($upcontext['user']['main']))
1524 1615
 	{
1525
-		if ($command_line)
1526
-			echo ' * ';
1616
+		if ($command_line) {
1617
+					echo ' * ';
1618
+		}
1527 1619
 		$upcontext['removed_maintenance'] = true;
1528 1620
 		$changes['maintenance'] = $upcontext['user']['main'];
1529 1621
 	}
1530 1622
 	// Otherwise if somehow we are in 2 let's go to 1.
1531
-	elseif (!empty($maintenance) && $maintenance == 2)
1532
-		$changes['maintenance'] = 1;
1623
+	elseif (!empty($maintenance) && $maintenance == 2) {
1624
+			$changes['maintenance'] = 1;
1625
+	}
1533 1626
 
1534 1627
 	// Wipe this out...
1535 1628
 	$upcontext['user'] = array();
@@ -1544,21 +1637,23 @@  discard block
 block discarded – undo
1544 1637
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1545 1638
 
1546 1639
 	// Now is the perfect time to fetch the SM files.
1547
-	if ($command_line)
1548
-		cli_scheduled_fetchSMfiles();
1549
-	else
1640
+	if ($command_line) {
1641
+			cli_scheduled_fetchSMfiles();
1642
+	} else
1550 1643
 	{
1551 1644
 		require_once($sourcedir . '/ScheduledTasks.php');
1552 1645
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
1553 1646
 		scheduled_fetchSMfiles(); // Now go get those files!
1554 1647
 		// This is needed in case someone invokes the upgrader using https when upgrading an http forum
1555
-		if (httpsOn())
1556
-			$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
1648
+		if (httpsOn()) {
1649
+					$settings['default_theme_url'] = strtr($settings['default_theme_url'], array('http://' => 'https://'));
1650
+		}
1557 1651
 	}
1558 1652
 
1559 1653
 	// Log what we've done.
1560
-	if (empty($user_info['id']))
1561
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1654
+	if (empty($user_info['id'])) {
1655
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1656
+	}
1562 1657
 
1563 1658
 	// Log the action manually, so CLI still works.
1564 1659
 	$smcFunc['db_insert']('',
@@ -1577,8 +1672,9 @@  discard block
 block discarded – undo
1577 1672
 
1578 1673
 	// Save the current database version.
1579 1674
 	$server_version = $smcFunc['db_server_info']();
1580
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1581
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1675
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1676
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1677
+	}
1582 1678
 
1583 1679
 	if ($command_line)
1584 1680
 	{
@@ -1590,8 +1686,9 @@  discard block
 block discarded – undo
1590 1686
 
1591 1687
 	// Make sure it says we're done.
1592 1688
 	$upcontext['overall_percent'] = 100;
1593
-	if (isset($upcontext['step_progress']))
1594
-		unset($upcontext['step_progress']);
1689
+	if (isset($upcontext['step_progress'])) {
1690
+			unset($upcontext['step_progress']);
1691
+	}
1595 1692
 
1596 1693
 	$_GET['substep'] = 0;
1597 1694
 	return false;
@@ -1602,8 +1699,9 @@  discard block
 block discarded – undo
1602 1699
 {
1603 1700
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1604 1701
 
1605
-	if (empty($modSettings['time_format']))
1606
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1702
+	if (empty($modSettings['time_format'])) {
1703
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1704
+	}
1607 1705
 
1608 1706
 	// What files do we want to get
1609 1707
 	$request = $smcFunc['db_query']('', '
@@ -1637,8 +1735,9 @@  discard block
 block discarded – undo
1637 1735
 		$file_data = fetch_web_data($url);
1638 1736
 
1639 1737
 		// If we got an error - give up - the site might be down.
1640
-		if ($file_data === false)
1641
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1738
+		if ($file_data === false) {
1739
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1740
+		}
1642 1741
 
1643 1742
 		// Save the file to the database.
1644 1743
 		$smcFunc['db_query']('substring', '
@@ -1680,8 +1779,9 @@  discard block
 block discarded – undo
1680 1779
 	$themeData = array();
1681 1780
 	foreach ($values as $variable => $value)
1682 1781
 	{
1683
-		if (!isset($value) || $value === null)
1684
-			$value = 0;
1782
+		if (!isset($value) || $value === null) {
1783
+					$value = 0;
1784
+		}
1685 1785
 
1686 1786
 		$themeData[] = array(0, 1, $variable, $value);
1687 1787
 	}
@@ -1710,8 +1810,9 @@  discard block
 block discarded – undo
1710 1810
 
1711 1811
 	foreach ($values as $variable => $value)
1712 1812
 	{
1713
-		if (empty($modSettings[$value[0]]))
1714
-			continue;
1813
+		if (empty($modSettings[$value[0]])) {
1814
+					continue;
1815
+		}
1715 1816
 
1716 1817
 		$smcFunc['db_query']('', '
1717 1818
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1797,19 +1898,21 @@  discard block
 block discarded – undo
1797 1898
 	set_error_handler(
1798 1899
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1799 1900
 		{
1800
-			if ($support_js)
1801
-				return true;
1802
-			else
1803
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1901
+			if ($support_js) {
1902
+							return true;
1903
+			} else {
1904
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1905
+			}
1804 1906
 		}
1805 1907
 	);
1806 1908
 
1807 1909
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1808 1910
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1809
-	if ($db_type == 'mysql')
1810
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1811
-	else
1812
-		$db_collation = '';
1911
+	if ($db_type == 'mysql') {
1912
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1913
+	} else {
1914
+			$db_collation = '';
1915
+	}
1813 1916
 
1814 1917
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1815 1918
 
@@ -1821,8 +1924,9 @@  discard block
 block discarded – undo
1821 1924
 	$last_step = '';
1822 1925
 
1823 1926
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1824
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1825
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1927
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1928
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1929
+	}
1826 1930
 
1827 1931
 	// Count the total number of steps within this file - for progress.
1828 1932
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1842,15 +1946,18 @@  discard block
 block discarded – undo
1842 1946
 		$do_current = $substep >= $_GET['substep'];
1843 1947
 
1844 1948
 		// Get rid of any comments in the beginning of the line...
1845
-		if (substr(trim($line), 0, 2) === '/*')
1846
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1949
+		if (substr(trim($line), 0, 2) === '/*') {
1950
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1951
+		}
1847 1952
 
1848 1953
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1849
-		if ($is_debug && !$support_js && $command_line)
1850
-			flush();
1954
+		if ($is_debug && !$support_js && $command_line) {
1955
+					flush();
1956
+		}
1851 1957
 
1852
-		if (trim($line) === '')
1853
-			continue;
1958
+		if (trim($line) === '') {
1959
+					continue;
1960
+		}
1854 1961
 
1855 1962
 		if (trim(substr($line, 0, 3)) === '---')
1856 1963
 		{
@@ -1860,8 +1967,9 @@  discard block
 block discarded – undo
1860 1967
 			if (trim($current_data) != '' && $type !== '}')
1861 1968
 			{
1862 1969
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1863
-				if ($command_line)
1864
-					echo $upcontext['error_message'];
1970
+				if ($command_line) {
1971
+									echo $upcontext['error_message'];
1972
+				}
1865 1973
 			}
1866 1974
 
1867 1975
 			if ($type == ' ')
@@ -1879,17 +1987,18 @@  discard block
 block discarded – undo
1879 1987
 				if ($do_current)
1880 1988
 				{
1881 1989
 					$upcontext['actioned_items'][] = $last_step;
1882
-					if ($command_line)
1883
-						echo ' * ';
1990
+					if ($command_line) {
1991
+											echo ' * ';
1992
+					}
1884 1993
 				}
1885
-			}
1886
-			elseif ($type == '#')
1994
+			} elseif ($type == '#')
1887 1995
 			{
1888 1996
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1889 1997
 
1890 1998
 				$upcontext['current_debug_item_num']++;
1891
-				if (trim($line) != '---#')
1892
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1999
+				if (trim($line) != '---#') {
2000
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
2001
+				}
1893 2002
 
1894 2003
 				// Have we already done something?
1895 2004
 				if (isset($_GET['xml']) && $done_something)
@@ -1900,34 +2009,36 @@  discard block
 block discarded – undo
1900 2009
 
1901 2010
 				if ($do_current)
1902 2011
 				{
1903
-					if (trim($line) == '---#' && $command_line)
1904
-						echo ' done.', $endl;
1905
-					elseif ($command_line)
1906
-						echo ' +++ ', rtrim(substr($line, 4));
1907
-					elseif (trim($line) != '---#')
2012
+					if (trim($line) == '---#' && $command_line) {
2013
+											echo ' done.', $endl;
2014
+					} elseif ($command_line) {
2015
+											echo ' +++ ', rtrim(substr($line, 4));
2016
+					} elseif (trim($line) != '---#')
1908 2017
 					{
1909
-						if ($is_debug)
1910
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2018
+						if ($is_debug) {
2019
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
2020
+						}
1911 2021
 					}
1912 2022
 				}
1913 2023
 
1914 2024
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1915 2025
 				{
1916
-					if ($command_line)
1917
-						echo ' * ';
1918
-					else
1919
-						$upcontext['actioned_items'][] = $last_step;
2026
+					if ($command_line) {
2027
+											echo ' * ';
2028
+					} else {
2029
+											$upcontext['actioned_items'][] = $last_step;
2030
+					}
1920 2031
 				}
1921 2032
 
1922 2033
 				// Small step - only if we're actually doing stuff.
1923
-				if ($do_current)
1924
-					nextSubstep(++$substep);
1925
-				else
1926
-					$substep++;
1927
-			}
1928
-			elseif ($type == '{')
1929
-				$current_type = 'code';
1930
-			elseif ($type == '}')
2034
+				if ($do_current) {
2035
+									nextSubstep(++$substep);
2036
+				} else {
2037
+									$substep++;
2038
+				}
2039
+			} elseif ($type == '{') {
2040
+							$current_type = 'code';
2041
+			} elseif ($type == '}')
1931 2042
 			{
1932 2043
 				$current_type = 'sql';
1933 2044
 
@@ -1940,8 +2051,9 @@  discard block
 block discarded – undo
1940 2051
 				if (eval('global $db_prefix, $modSettings, $smcFunc, $txt; ' . $current_data) === false)
1941 2052
 				{
1942 2053
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1943
-					if ($command_line)
1944
-						echo $upcontext['error_message'];
2054
+					if ($command_line) {
2055
+											echo $upcontext['error_message'];
2056
+					}
1945 2057
 				}
1946 2058
 
1947 2059
 				// Done with code!
@@ -2029,8 +2141,9 @@  discard block
 block discarded – undo
2029 2141
 	$db_unbuffered = false;
2030 2142
 
2031 2143
 	// Failure?!
2032
-	if ($result !== false)
2033
-		return $result;
2144
+	if ($result !== false) {
2145
+			return $result;
2146
+	}
2034 2147
 
2035 2148
 	$db_error_message = $smcFunc['db_error']($db_connection);
2036 2149
 	// If MySQL we do something more clever.
@@ -2058,54 +2171,61 @@  discard block
 block discarded – undo
2058 2171
 			{
2059 2172
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
2060 2173
 				$result = mysqli_query($db_connection, $string);
2061
-				if ($result !== false)
2062
-					return $result;
2174
+				if ($result !== false) {
2175
+									return $result;
2176
+				}
2063 2177
 			}
2064
-		}
2065
-		elseif ($mysqli_errno == 2013)
2178
+		} elseif ($mysqli_errno == 2013)
2066 2179
 		{
2067 2180
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
2068 2181
 			mysqli_select_db($db_connection, $db_name);
2069 2182
 			if ($db_connection)
2070 2183
 			{
2071 2184
 				$result = mysqli_query($db_connection, $string);
2072
-				if ($result !== false)
2073
-					return $result;
2185
+				if ($result !== false) {
2186
+									return $result;
2187
+				}
2074 2188
 			}
2075 2189
 		}
2076 2190
 		// Duplicate column name... should be okay ;).
2077
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
2078
-			return false;
2191
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2192
+					return false;
2193
+		}
2079 2194
 		// Duplicate insert... make sure it's the proper type of query ;).
2080
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
2081
-			return false;
2195
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2196
+					return false;
2197
+		}
2082 2198
 		// Creating an index on a non-existent column.
2083
-		elseif ($mysqli_errno == 1072)
2084
-			return false;
2085
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
2086
-			return false;
2199
+		elseif ($mysqli_errno == 1072) {
2200
+					return false;
2201
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2202
+					return false;
2203
+		}
2087 2204
 	}
2088 2205
 	// If a table already exists don't go potty.
2089 2206
 	else
2090 2207
 	{
2091 2208
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
2092 2209
 		{
2093
-			if (strpos($db_error_message, 'exist') !== false)
2094
-				return true;
2095
-		}
2096
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2210
+			if (strpos($db_error_message, 'exist') !== false) {
2211
+							return true;
2212
+			}
2213
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
2097 2214
 		{
2098
-			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error)
2099
-				return true;
2215
+			if (strpos($db_error_message, 'duplicate') !== false || $ignore_insert_error) {
2216
+							return true;
2217
+			}
2100 2218
 		}
2101 2219
 	}
2102 2220
 
2103 2221
 	// Get the query string so we pass everything.
2104 2222
 	$query_string = '';
2105
-	foreach ($_GET as $k => $v)
2106
-		$query_string .= ';' . $k . '=' . $v;
2107
-	if (strlen($query_string) != 0)
2108
-		$query_string = '?' . substr($query_string, 1);
2223
+	foreach ($_GET as $k => $v) {
2224
+			$query_string .= ';' . $k . '=' . $v;
2225
+	}
2226
+	if (strlen($query_string) != 0) {
2227
+			$query_string = '?' . substr($query_string, 1);
2228
+	}
2109 2229
 
2110 2230
 	if ($command_line)
2111 2231
 	{
@@ -2160,16 +2280,18 @@  discard block
 block discarded – undo
2160 2280
 			{
2161 2281
 				$found |= 1;
2162 2282
 				// Do some checks on the data if we have it set.
2163
-				if (isset($change['col_type']))
2164
-					$found &= $change['col_type'] === $column['type'];
2165
-				if (isset($change['null_allowed']))
2166
-					$found &= $column['null'] == $change['null_allowed'];
2167
-				if (isset($change['default']))
2168
-					$found &= $change['default'] === $column['default'];
2283
+				if (isset($change['col_type'])) {
2284
+									$found &= $change['col_type'] === $column['type'];
2285
+				}
2286
+				if (isset($change['null_allowed'])) {
2287
+									$found &= $column['null'] == $change['null_allowed'];
2288
+				}
2289
+				if (isset($change['default'])) {
2290
+									$found &= $change['default'] === $column['default'];
2291
+				}
2169 2292
 			}
2170 2293
 		}
2171
-	}
2172
-	elseif ($change['type'] === 'index')
2294
+	} elseif ($change['type'] === 'index')
2173 2295
 	{
2174 2296
 		$request = upgrade_query('
2175 2297
 			SHOW INDEX
@@ -2178,9 +2300,10 @@  discard block
 block discarded – undo
2178 2300
 		{
2179 2301
 			$cur_index = array();
2180 2302
 
2181
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2182
-				if ($row['Key_name'] === $change['name'])
2303
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2304
+							if ($row['Key_name'] === $change['name'])
2183 2305
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2306
+			}
2184 2307
 
2185 2308
 			ksort($cur_index, SORT_NUMERIC);
2186 2309
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2190,14 +2313,17 @@  discard block
 block discarded – undo
2190 2313
 	}
2191 2314
 
2192 2315
 	// If we're trying to add and it's added, we're done.
2193
-	if ($found && in_array($change['method'], array('add', 'change')))
2194
-		return true;
2316
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2317
+			return true;
2318
+	}
2195 2319
 	// Otherwise if we're removing and it wasn't found we're also done.
2196
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2197
-		return true;
2320
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2321
+			return true;
2322
+	}
2198 2323
 	// Otherwise is it just a test?
2199
-	elseif ($is_test)
2200
-		return false;
2324
+	elseif ($is_test) {
2325
+			return false;
2326
+	}
2201 2327
 
2202 2328
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2203 2329
 	$running = false;
@@ -2208,8 +2334,9 @@  discard block
 block discarded – undo
2208 2334
 			SHOW FULL PROCESSLIST');
2209 2335
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2210 2336
 		{
2211
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2212
-				$found = true;
2337
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2338
+							$found = true;
2339
+			}
2213 2340
 		}
2214 2341
 
2215 2342
 		// Can't find it? Then we need to run it fools!
@@ -2221,8 +2348,9 @@  discard block
 block discarded – undo
2221 2348
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2222 2349
 				' . $change['text'], true) !== false;
2223 2350
 
2224
-			if (!$success)
2225
-				return false;
2351
+			if (!$success) {
2352
+							return false;
2353
+			}
2226 2354
 
2227 2355
 			// Return
2228 2356
 			$running = true;
@@ -2264,8 +2392,9 @@  discard block
 block discarded – undo
2264 2392
 			'db_error_skip' => true,
2265 2393
 		)
2266 2394
 	);
2267
-	if ($smcFunc['db_num_rows']($request) === 0)
2268
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2395
+	if ($smcFunc['db_num_rows']($request) === 0) {
2396
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2397
+	}
2269 2398
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2270 2399
 	$smcFunc['db_free_result']($request);
2271 2400
 
@@ -2287,18 +2416,19 @@  discard block
 block discarded – undo
2287 2416
 			)
2288 2417
 		);
2289 2418
 		// No results? Just forget it all together.
2290
-		if ($smcFunc['db_num_rows']($request) === 0)
2291
-			unset($table_row['Collation']);
2292
-		else
2293
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2419
+		if ($smcFunc['db_num_rows']($request) === 0) {
2420
+					unset($table_row['Collation']);
2421
+		} else {
2422
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2423
+		}
2294 2424
 		$smcFunc['db_free_result']($request);
2295 2425
 	}
2296 2426
 
2297 2427
 	if ($column_fix)
2298 2428
 	{
2299 2429
 		// Make sure there are no NULL's left.
2300
-		if ($null_fix)
2301
-			$smcFunc['db_query']('', '
2430
+		if ($null_fix) {
2431
+					$smcFunc['db_query']('', '
2302 2432
 				UPDATE {db_prefix}' . $change['table'] . '
2303 2433
 				SET ' . $change['column'] . ' = {string:default}
2304 2434
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2307,6 +2437,7 @@  discard block
 block discarded – undo
2307 2437
 					'db_error_skip' => true,
2308 2438
 				)
2309 2439
 			);
2440
+		}
2310 2441
 
2311 2442
 		// Do the actual alteration.
2312 2443
 		$smcFunc['db_query']('', '
@@ -2335,8 +2466,9 @@  discard block
 block discarded – undo
2335 2466
 	}
2336 2467
 
2337 2468
 	// Not a column we need to check on?
2338
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2339
-		return;
2469
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2470
+			return;
2471
+	}
2340 2472
 
2341 2473
 	// Break it up you (six|seven).
2342 2474
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2355,13 +2487,13 @@  discard block
 block discarded – undo
2355 2487
 				'new_name' => $temp[2],
2356 2488
 		));
2357 2489
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2358
-		if ($smcFunc['db_num_rows'] != 1)
2359
-			return;
2490
+		if ($smcFunc['db_num_rows'] != 1) {
2491
+					return;
2492
+		}
2360 2493
 
2361 2494
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2362 2495
 		$smcFunc['db_free_result']($request);
2363
-	}
2364
-	else
2496
+	} else
2365 2497
 	{
2366 2498
 		// Do this the old fashion, sure method way.
2367 2499
 		$request = $smcFunc['db_query']('', '
@@ -2372,21 +2504,24 @@  discard block
 block discarded – undo
2372 2504
 		));
2373 2505
 		// Mayday!
2374 2506
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2375
-		if ($smcFunc['db_num_rows'] == 0)
2376
-			return;
2507
+		if ($smcFunc['db_num_rows'] == 0) {
2508
+					return;
2509
+		}
2377 2510
 
2378 2511
 		// Oh where, oh where has my little field gone. Oh where can it be...
2379
-		while ($row = $smcFunc['db_query']($request))
2380
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2512
+		while ($row = $smcFunc['db_query']($request)) {
2513
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2381 2514
 			{
2382 2515
 				$current_type = $row['Type'];
2516
+		}
2383 2517
 				break;
2384 2518
 			}
2385 2519
 	}
2386 2520
 
2387 2521
 	// If this doesn't match, the column may of been altered for a reason.
2388
-	if (trim($current_type) != trim($temp[3]))
2389
-		$temp[3] = $current_type;
2522
+	if (trim($current_type) != trim($temp[3])) {
2523
+			$temp[3] = $current_type;
2524
+	}
2390 2525
 
2391 2526
 	// Piece this back together.
2392 2527
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2398,8 +2533,9 @@  discard block
 block discarded – undo
2398 2533
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2399 2534
 	global $step_progress, $is_debug, $upcontext;
2400 2535
 
2401
-	if ($_GET['substep'] < $substep)
2402
-		$_GET['substep'] = $substep;
2536
+	if ($_GET['substep'] < $substep) {
2537
+			$_GET['substep'] = $substep;
2538
+	}
2403 2539
 
2404 2540
 	if ($command_line)
2405 2541
 	{
@@ -2412,29 +2548,33 @@  discard block
 block discarded – undo
2412 2548
 	}
2413 2549
 
2414 2550
 	@set_time_limit(300);
2415
-	if (function_exists('apache_reset_timeout'))
2416
-		@apache_reset_timeout();
2551
+	if (function_exists('apache_reset_timeout')) {
2552
+			@apache_reset_timeout();
2553
+	}
2417 2554
 
2418
-	if (time() - $start_time <= $timeLimitThreshold)
2419
-		return;
2555
+	if (time() - $start_time <= $timeLimitThreshold) {
2556
+			return;
2557
+	}
2420 2558
 
2421 2559
 	// Do we have some custom step progress stuff?
2422 2560
 	if (!empty($step_progress))
2423 2561
 	{
2424 2562
 		$upcontext['substep_progress'] = 0;
2425 2563
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2426
-		if ($step_progress['current'] > $step_progress['total'])
2427
-			$upcontext['substep_progress'] = 99.9;
2428
-		else
2429
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2564
+		if ($step_progress['current'] > $step_progress['total']) {
2565
+					$upcontext['substep_progress'] = 99.9;
2566
+		} else {
2567
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2568
+		}
2430 2569
 
2431 2570
 		// Make it nicely rounded.
2432 2571
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2433 2572
 	}
2434 2573
 
2435 2574
 	// If this is XML we just exit right away!
2436
-	if (isset($_GET['xml']))
2437
-		return upgradeExit();
2575
+	if (isset($_GET['xml'])) {
2576
+			return upgradeExit();
2577
+	}
2438 2578
 
2439 2579
 	// We're going to pause after this!
2440 2580
 	$upcontext['pause'] = true;
@@ -2442,13 +2582,15 @@  discard block
 block discarded – undo
2442 2582
 	$upcontext['query_string'] = '';
2443 2583
 	foreach ($_GET as $k => $v)
2444 2584
 	{
2445
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2446
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2585
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2586
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2587
+		}
2447 2588
 	}
2448 2589
 
2449 2590
 	// Custom warning?
2450
-	if (!empty($custom_warning))
2451
-		$upcontext['custom_warning'] = $custom_warning;
2591
+	if (!empty($custom_warning)) {
2592
+			$upcontext['custom_warning'] = $custom_warning;
2593
+	}
2452 2594
 
2453 2595
 	upgradeExit();
2454 2596
 }
@@ -2463,25 +2605,26 @@  discard block
 block discarded – undo
2463 2605
 	ob_implicit_flush(true);
2464 2606
 	@set_time_limit(600);
2465 2607
 
2466
-	if (!isset($_SERVER['argv']))
2467
-		$_SERVER['argv'] = array();
2608
+	if (!isset($_SERVER['argv'])) {
2609
+			$_SERVER['argv'] = array();
2610
+	}
2468 2611
 	$_GET['maint'] = 1;
2469 2612
 
2470 2613
 	foreach ($_SERVER['argv'] as $i => $arg)
2471 2614
 	{
2472
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2473
-			$_GET['lang'] = $match[1];
2474
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2475
-			continue;
2476
-		elseif ($arg == '--no-maintenance')
2477
-			$_GET['maint'] = 0;
2478
-		elseif ($arg == '--debug')
2479
-			$is_debug = true;
2480
-		elseif ($arg == '--backup')
2481
-			$_POST['backup'] = 1;
2482
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2483
-			$_GET['conv'] = 1;
2484
-		elseif ($i != 0)
2615
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2616
+					$_GET['lang'] = $match[1];
2617
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2618
+					continue;
2619
+		} elseif ($arg == '--no-maintenance') {
2620
+					$_GET['maint'] = 0;
2621
+		} elseif ($arg == '--debug') {
2622
+					$is_debug = true;
2623
+		} elseif ($arg == '--backup') {
2624
+					$_POST['backup'] = 1;
2625
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2626
+					$_GET['conv'] = 1;
2627
+		} elseif ($i != 0)
2485 2628
 		{
2486 2629
 			echo 'SMF Command-line Upgrader
2487 2630
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2495,10 +2638,12 @@  discard block
 block discarded – undo
2495 2638
 		}
2496 2639
 	}
2497 2640
 
2498
-	if (!php_version_check())
2499
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2500
-	if (!db_version_check())
2501
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2641
+	if (!php_version_check()) {
2642
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2643
+	}
2644
+	if (!db_version_check()) {
2645
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2646
+	}
2502 2647
 
2503 2648
 	// Do some checks to make sure they have proper privileges
2504 2649
 	db_extend('packages');
@@ -2513,34 +2658,39 @@  discard block
 block discarded – undo
2513 2658
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2514 2659
 
2515 2660
 	// Sorry... we need CREATE, ALTER and DROP
2516
-	if (!$create || !$alter || !$drop)
2517
-		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);
2661
+	if (!$create || !$alter || !$drop) {
2662
+			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);
2663
+	}
2518 2664
 
2519 2665
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2520 2666
 		&& @file_exists($sourcedir . '/QueryString.php')
2521 2667
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2522
-	if (!$check && !isset($modSettings['smfVersion']))
2523
-		print_error('Error: Some files are missing or out-of-date.', true);
2668
+	if (!$check && !isset($modSettings['smfVersion'])) {
2669
+			print_error('Error: Some files are missing or out-of-date.', true);
2670
+	}
2524 2671
 
2525 2672
 	// Do a quick version spot check.
2526 2673
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2527 2674
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2528
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2529
-		print_error('Error: Some files have not yet been updated properly.');
2675
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2676
+			print_error('Error: Some files have not yet been updated properly.');
2677
+	}
2530 2678
 
2531 2679
 	// Make sure Settings.php is writable.
2532 2680
 	quickFileWritable($boarddir . '/Settings.php');
2533
-	if (!is_writable($boarddir . '/Settings.php'))
2534
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2681
+	if (!is_writable($boarddir . '/Settings.php')) {
2682
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2683
+	}
2535 2684
 
2536 2685
 	// Make sure Settings_bak.php is writable.
2537 2686
 	quickFileWritable($boarddir . '/Settings_bak.php');
2538
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2539
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2687
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2688
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2689
+	}
2540 2690
 
2541
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2542
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2543
-	elseif (isset($modSettings['agreement']))
2691
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2692
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2693
+	} elseif (isset($modSettings['agreement']))
2544 2694
 	{
2545 2695
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2546 2696
 		fwrite($fp, $modSettings['agreement']);
@@ -2550,36 +2700,42 @@  discard block
 block discarded – undo
2550 2700
 	// Make sure Themes is writable.
2551 2701
 	quickFileWritable($modSettings['theme_dir']);
2552 2702
 
2553
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2554
-		print_error('Error: Unable to obtain write access to "Themes".');
2703
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2704
+			print_error('Error: Unable to obtain write access to "Themes".');
2705
+	}
2555 2706
 
2556 2707
 	// Make sure cache directory exists and is writable!
2557 2708
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2558
-	if (!file_exists($cachedir_temp))
2559
-		@mkdir($cachedir_temp);
2709
+	if (!file_exists($cachedir_temp)) {
2710
+			@mkdir($cachedir_temp);
2711
+	}
2560 2712
 
2561 2713
 	// Make sure the cache temp dir is writable.
2562 2714
 	quickFileWritable($cachedir_temp);
2563 2715
 
2564
-	if (!is_writable($cachedir_temp))
2565
-		print_error('Error: Unable to obtain write access to "cache".', true);
2716
+	if (!is_writable($cachedir_temp)) {
2717
+			print_error('Error: Unable to obtain write access to "cache".', true);
2718
+	}
2566 2719
 
2567 2720
 	// Make sure db_last_error.php is writable.
2568 2721
 	quickFileWritable($cachedir_temp . '/db_last_error.php');
2569
-	if (!is_writable($cachedir_temp . '/db_last_error.php'))
2570
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2722
+	if (!is_writable($cachedir_temp . '/db_last_error.php')) {
2723
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2724
+	}
2571 2725
 
2572
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2573
-		print_error('Error: Unable to find language files!', true);
2574
-	else
2726
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2727
+			print_error('Error: Unable to find language files!', true);
2728
+	} else
2575 2729
 	{
2576 2730
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2577 2731
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2578 2732
 
2579
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2580
-			print_error('Error: Language files out of date.', true);
2581
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2582
-			print_error('Error: Install language is missing for selected language.', true);
2733
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2734
+					print_error('Error: Language files out of date.', true);
2735
+		}
2736
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2737
+					print_error('Error: Install language is missing for selected language.', true);
2738
+		}
2583 2739
 
2584 2740
 		// Otherwise include it!
2585 2741
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2599,8 +2755,9 @@  discard block
 block discarded – undo
2599 2755
 	global $db_prefix, $db_type, $command_line, $support_js, $txt;
2600 2756
 
2601 2757
 	// Done it already?
2602
-	if (!empty($_POST['utf8_done']))
2603
-		return true;
2758
+	if (!empty($_POST['utf8_done'])) {
2759
+			return true;
2760
+	}
2604 2761
 
2605 2762
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2606 2763
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2613,8 +2770,7 @@  discard block
 block discarded – undo
2613 2770
 		);
2614 2771
 
2615 2772
 		return true;
2616
-	}
2617
-	else
2773
+	} else
2618 2774
 	{
2619 2775
 		$upcontext['page_title'] = $txt['converting_utf8'];
2620 2776
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2658,8 +2814,9 @@  discard block
 block discarded – undo
2658 2814
 			)
2659 2815
 		);
2660 2816
 		$db_charsets = array();
2661
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2662
-			$db_charsets[] = $row['Charset'];
2817
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2818
+					$db_charsets[] = $row['Charset'];
2819
+		}
2663 2820
 
2664 2821
 		$smcFunc['db_free_result']($request);
2665 2822
 
@@ -2695,13 +2852,15 @@  discard block
 block discarded – undo
2695 2852
 		// If there's a fulltext index, we need to drop it first...
2696 2853
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2697 2854
 		{
2698
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2699
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2855
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2856
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2700 2857
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2858
+			}
2701 2859
 			$smcFunc['db_free_result']($request);
2702 2860
 
2703
-			if (isset($upcontext['fulltext_index']))
2704
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2861
+			if (isset($upcontext['fulltext_index'])) {
2862
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2863
+			}
2705 2864
 		}
2706 2865
 
2707 2866
 		// Drop it and make a note...
@@ -2891,8 +3050,9 @@  discard block
 block discarded – undo
2891 3050
 			$replace = '%field%';
2892 3051
 
2893 3052
 			// Build a huge REPLACE statement...
2894
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2895
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3053
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
3054
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
3055
+			}
2896 3056
 		}
2897 3057
 
2898 3058
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2902,9 +3062,10 @@  discard block
 block discarded – undo
2902 3062
 		$upcontext['table_count'] = count($queryTables);
2903 3063
 
2904 3064
 		// What ones have we already done?
2905
-		foreach ($queryTables as $id => $table)
2906
-			if ($id < $_GET['substep'])
3065
+		foreach ($queryTables as $id => $table) {
3066
+					if ($id < $_GET['substep'])
2907 3067
 				$upcontext['previous_tables'][] = $table;
3068
+		}
2908 3069
 
2909 3070
 		$upcontext['cur_table_num'] = $_GET['substep'];
2910 3071
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2941,8 +3102,9 @@  discard block
 block discarded – undo
2941 3102
 			nextSubstep($substep);
2942 3103
 
2943 3104
 			// Just to make sure it doesn't time out.
2944
-			if (function_exists('apache_reset_timeout'))
2945
-				@apache_reset_timeout();
3105
+			if (function_exists('apache_reset_timeout')) {
3106
+							@apache_reset_timeout();
3107
+			}
2946 3108
 
2947 3109
 			$table_charsets = array();
2948 3110
 
@@ -2965,8 +3127,9 @@  discard block
 block discarded – undo
2965 3127
 
2966 3128
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2967 3129
 						if ($charset != 'utf8') {
2968
-							if (!isset($table_charsets[$charset]))
2969
-								$table_charsets[$charset] = array();
3130
+							if (!isset($table_charsets[$charset])) {
3131
+															$table_charsets[$charset] = array();
3132
+							}
2970 3133
 
2971 3134
 							$table_charsets[$charset][] = $column_info;
2972 3135
 						}
@@ -3007,10 +3170,11 @@  discard block
 block discarded – undo
3007 3170
 				if (isset($translation_tables[$upcontext['charset_detected']]))
3008 3171
 				{
3009 3172
 					$update = '';
3010
-					foreach ($table_charsets as $charset => $columns)
3011
-						foreach ($columns as $column)
3173
+					foreach ($table_charsets as $charset => $columns) {
3174
+											foreach ($columns as $column)
3012 3175
 							$update .= '
3013 3176
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3177
+					}
3014 3178
 
3015 3179
 					$smcFunc['db_query']('', '
3016 3180
 						UPDATE {raw:table_name}
@@ -3035,8 +3199,9 @@  discard block
 block discarded – undo
3035 3199
 			// Now do the actual conversion (if still needed).
3036 3200
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
3037 3201
 			{
3038
-				if ($command_line)
3039
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3202
+				if ($command_line) {
3203
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3204
+				}
3040 3205
 
3041 3206
 				$smcFunc['db_query']('', '
3042 3207
 					ALTER TABLE {raw:table_name}
@@ -3046,12 +3211,14 @@  discard block
 block discarded – undo
3046 3211
 					)
3047 3212
 				);
3048 3213
 
3049
-				if ($command_line)
3050
-					echo " done.\n";
3214
+				if ($command_line) {
3215
+									echo " done.\n";
3216
+				}
3051 3217
 			}
3052 3218
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3053
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
3054
-				return upgradeExit();
3219
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3220
+							return upgradeExit();
3221
+			}
3055 3222
 		}
3056 3223
 
3057 3224
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -3080,8 +3247,8 @@  discard block
 block discarded – undo
3080 3247
 		);
3081 3248
 		while ($row = $smcFunc['db_fetch_assoc']($request))
3082 3249
 		{
3083
-			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)
3084
-				$smcFunc['db_query']('', '
3250
+			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) {
3251
+							$smcFunc['db_query']('', '
3085 3252
 					UPDATE {db_prefix}log_actions
3086 3253
 					SET extra = {string:extra}
3087 3254
 					WHERE id_action = {int:current_action}',
@@ -3090,6 +3257,7 @@  discard block
 block discarded – undo
3090 3257
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
3091 3258
 					)
3092 3259
 				);
3260
+			}
3093 3261
 		}
3094 3262
 		$smcFunc['db_free_result']($request);
3095 3263
 
@@ -3111,15 +3279,17 @@  discard block
 block discarded – undo
3111 3279
 	// First thing's first - did we already do this?
3112 3280
 	if (!empty($modSettings['json_done']))
3113 3281
 	{
3114
-		if ($command_line)
3115
-			return DeleteUpgrade();
3116
-		else
3117
-			return true;
3282
+		if ($command_line) {
3283
+					return DeleteUpgrade();
3284
+		} else {
3285
+					return true;
3286
+		}
3118 3287
 	}
3119 3288
 
3120 3289
 	// Done it already - js wise?
3121
-	if (!empty($_POST['json_done']))
3122
-		return true;
3290
+	if (!empty($_POST['json_done'])) {
3291
+			return true;
3292
+	}
3123 3293
 
3124 3294
 	// List of tables affected by this function
3125 3295
 	// name => array('key', col1[,col2|true[,col3]])
@@ -3151,12 +3321,14 @@  discard block
 block discarded – undo
3151 3321
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3152 3322
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3153 3323
 
3154
-	foreach ($keys as $id => $table)
3155
-		if ($id < $_GET['substep'])
3324
+	foreach ($keys as $id => $table) {
3325
+			if ($id < $_GET['substep'])
3156 3326
 			$upcontext['previous_tables'][] = $table;
3327
+	}
3157 3328
 
3158
-	if ($command_line)
3159
-		echo 'Converting data from serialize() to json_encode().';
3329
+	if ($command_line) {
3330
+			echo 'Converting data from serialize() to json_encode().';
3331
+	}
3160 3332
 
3161 3333
 	if (!$support_js || isset($_GET['xml']))
3162 3334
 	{
@@ -3196,8 +3368,9 @@  discard block
 block discarded – undo
3196 3368
 
3197 3369
 				// Loop through and fix these...
3198 3370
 				$new_settings = array();
3199
-				if ($command_line)
3200
-					echo "\n" . 'Fixing some settings...';
3371
+				if ($command_line) {
3372
+									echo "\n" . 'Fixing some settings...';
3373
+				}
3201 3374
 
3202 3375
 				foreach ($serialized_settings as $var)
3203 3376
 				{
@@ -3205,22 +3378,24 @@  discard block
 block discarded – undo
3205 3378
 					{
3206 3379
 						// Attempt to unserialize the setting
3207 3380
 						$temp = @safe_unserialize($modSettings[$var]);
3208
-						if (!$temp && $command_line)
3209
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3210
-						elseif ($temp !== false)
3211
-							$new_settings[$var] = json_encode($temp);
3381
+						if (!$temp && $command_line) {
3382
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3383
+						} elseif ($temp !== false) {
3384
+													$new_settings[$var] = json_encode($temp);
3385
+						}
3212 3386
 					}
3213 3387
 				}
3214 3388
 
3215 3389
 				// Update everything at once
3216
-				if (!function_exists('cache_put_data'))
3217
-					require_once($sourcedir . '/Load.php');
3390
+				if (!function_exists('cache_put_data')) {
3391
+									require_once($sourcedir . '/Load.php');
3392
+				}
3218 3393
 				updateSettings($new_settings, true);
3219 3394
 
3220
-				if ($command_line)
3221
-					echo ' done.';
3222
-			}
3223
-			elseif ($table == 'themes')
3395
+				if ($command_line) {
3396
+									echo ' done.';
3397
+				}
3398
+			} elseif ($table == 'themes')
3224 3399
 			{
3225 3400
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3226 3401
 				$query = $smcFunc['db_query']('', '
@@ -3239,10 +3414,11 @@  discard block
 block discarded – undo
3239 3414
 
3240 3415
 						if ($command_line)
3241 3416
 						{
3242
-							if ($temp === false)
3243
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3244
-							else
3245
-								echo "\n" . 'Fixing admin preferences...';
3417
+							if ($temp === false) {
3418
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3419
+							} else {
3420
+															echo "\n" . 'Fixing admin preferences...';
3421
+							}
3246 3422
 						}
3247 3423
 
3248 3424
 						if ($temp !== false)
@@ -3264,15 +3440,15 @@  discard block
 block discarded – undo
3264 3440
 								)
3265 3441
 							);
3266 3442
 
3267
-							if ($command_line)
3268
-								echo ' done.';
3443
+							if ($command_line) {
3444
+															echo ' done.';
3445
+							}
3269 3446
 						}
3270 3447
 					}
3271 3448
 
3272 3449
 					$smcFunc['db_free_result']($query);
3273 3450
 				}
3274
-			}
3275
-			else
3451
+			} else
3276 3452
 			{
3277 3453
 				// First item is always the key...
3278 3454
 				$key = $info[0];
@@ -3283,8 +3459,7 @@  discard block
 block discarded – undo
3283 3459
 				{
3284 3460
 					$col_select = $info[1];
3285 3461
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3286
-				}
3287
-				else
3462
+				} else
3288 3463
 				{
3289 3464
 					$col_select = implode(', ', $info);
3290 3465
 				}
@@ -3317,8 +3492,7 @@  discard block
 block discarded – undo
3317 3492
 								if ($temp === false && $command_line)
3318 3493
 								{
3319 3494
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3320
-								}
3321
-								else
3495
+								} else
3322 3496
 								{
3323 3497
 									$row[$col] = json_encode($temp);
3324 3498
 
@@ -3343,16 +3517,18 @@  discard block
 block discarded – undo
3343 3517
 						}
3344 3518
 					}
3345 3519
 
3346
-					if ($command_line)
3347
-						echo ' done.';
3520
+					if ($command_line) {
3521
+											echo ' done.';
3522
+					}
3348 3523
 
3349 3524
 					// Free up some memory...
3350 3525
 					$smcFunc['db_free_result']($query);
3351 3526
 				}
3352 3527
 			}
3353 3528
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3354
-			if (isset($_GET['xml']))
3355
-				return upgradeExit();
3529
+			if (isset($_GET['xml'])) {
3530
+							return upgradeExit();
3531
+			}
3356 3532
 		}
3357 3533
 
3358 3534
 		if ($command_line)
@@ -3367,8 +3543,9 @@  discard block
 block discarded – undo
3367 3543
 
3368 3544
 		$_GET['substep'] = 0;
3369 3545
 		// Make sure we move on!
3370
-		if ($command_line)
3371
-			return DeleteUpgrade();
3546
+		if ($command_line) {
3547
+					return DeleteUpgrade();
3548
+		}
3372 3549
 
3373 3550
 		return true;
3374 3551
 	}
@@ -3425,14 +3602,16 @@  discard block
 block discarded – undo
3425 3602
 	global $upcontext, $txt, $settings;
3426 3603
 
3427 3604
 	// Don't call me twice!
3428
-	if (!empty($upcontext['chmod_called']))
3429
-		return;
3605
+	if (!empty($upcontext['chmod_called'])) {
3606
+			return;
3607
+	}
3430 3608
 
3431 3609
 	$upcontext['chmod_called'] = true;
3432 3610
 
3433 3611
 	// Nothing?
3434
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3435
-		return;
3612
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3613
+			return;
3614
+	}
3436 3615
 
3437 3616
 	// Was it a problem with Windows?
3438 3617
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3464,11 +3643,12 @@  discard block
 block discarded – undo
3464 3643
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>', $txt['upgrade_ftp_files'], '</h4>\n\t\t\t\');
3465 3644
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3466 3645
 
3467
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3468
-		echo '
3646
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3647
+			echo '
3469 3648
 					content.write(\'<hr>\n\t\t\t\');
3470 3649
 					content.write(\'<p>', $txt['upgrade_ftp_shell'], '</p>\n\t\t\t\');
3471 3650
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3651
+	}
3472 3652
 
3473 3653
 	echo '
3474 3654
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3476,16 +3656,18 @@  discard block
 block discarded – undo
3476 3656
 				}
3477 3657
 			</script>';
3478 3658
 
3479
-	if (!empty($upcontext['chmod']['ftp_error']))
3480
-		echo '
3659
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3660
+			echo '
3481 3661
 			<div class="error_message red">
3482 3662
 				<p>', $txt['upgrade_ftp_error'], '<p>
3483 3663
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3484 3664
 			</div>';
3665
+	}
3485 3666
 
3486
-	if (empty($upcontext['chmod_in_form']))
3487
-		echo '
3667
+	if (empty($upcontext['chmod_in_form'])) {
3668
+			echo '
3488 3669
 			<form action="', $upcontext['form_url'], '" method="post">';
3670
+	}
3489 3671
 
3490 3672
 	echo '
3491 3673
 				<dl class="settings">
@@ -3527,9 +3709,10 @@  discard block
 block discarded – undo
3527 3709
 					<input type="submit" value="', $txt['ftp_connect'], '" class="button">
3528 3710
 				</div>';
3529 3711
 
3530
-	if (empty($upcontext['chmod_in_form']))
3531
-		echo '
3712
+	if (empty($upcontext['chmod_in_form'])) {
3713
+			echo '
3532 3714
 			</form>';
3715
+	}
3533 3716
 
3534 3717
 	echo '
3535 3718
 		</div><!-- .panel -->';
@@ -3593,9 +3776,10 @@  discard block
 block discarded – undo
3593 3776
 					<h2>', $txt['upgrade_progress'], '</h2>
3594 3777
 					<ul>';
3595 3778
 
3596
-	foreach ($upcontext['steps'] as $num => $step)
3597
-		echo '
3779
+	foreach ($upcontext['steps'] as $num => $step) {
3780
+			echo '
3598 3781
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3782
+	}
3599 3783
 
3600 3784
 	echo '
3601 3785
 					</ul>
@@ -3608,13 +3792,14 @@  discard block
 block discarded – undo
3608 3792
 						<span id="overall_text">', $upcontext['overall_percent'], '%</span>
3609 3793
 					</div>';
3610 3794
 
3611
-	if (isset($upcontext['step_progress']))
3612
-		echo '
3795
+	if (isset($upcontext['step_progress'])) {
3796
+			echo '
3613 3797
 					<div id="progress_bar_step" class="progress_bar progress_yellow">
3614 3798
 						<h3>', $txt['upgrade_step_progress'], '</h3>
3615 3799
 						<div id="step_progress" class="bar" style="width: ', $upcontext['step_progress'], '%;"></div>
3616 3800
 						<span id="step_text">', $upcontext['step_progress'], '%</span>
3617 3801
 					</div>';
3802
+	}
3618 3803
 
3619 3804
 	echo '
3620 3805
 					<div id="substep_bar_div" class="progress_bar ', isset($upcontext['substep_progress']) ? '' : 'hidden', '">
@@ -3645,31 +3830,35 @@  discard block
 block discarded – undo
3645 3830
 {
3646 3831
 	global $upcontext, $txt;
3647 3832
 
3648
-	if (!empty($upcontext['pause']))
3649
-		echo '
3833
+	if (!empty($upcontext['pause'])) {
3834
+			echo '
3650 3835
 					<em>', $txt['upgrade_incomplete'], '.</em><br>
3651 3836
 
3652 3837
 					<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3653 3838
 					<h3>
3654 3839
 						', $txt['upgrade_paused_overload'], '
3655 3840
 					</h3>';
3841
+	}
3656 3842
 
3657
-	if (!empty($upcontext['custom_warning']))
3658
-		echo '
3843
+	if (!empty($upcontext['custom_warning'])) {
3844
+			echo '
3659 3845
 					<div class="errorbox">
3660 3846
 						<h3>', $txt['upgrade_note'], '</h3>
3661 3847
 						', $upcontext['custom_warning'], '
3662 3848
 					</div>';
3849
+	}
3663 3850
 
3664 3851
 	echo '
3665 3852
 					<div class="righttext" style="margin: 1ex;">';
3666 3853
 
3667
-	if (!empty($upcontext['continue']))
3668
-		echo '
3854
+	if (!empty($upcontext['continue'])) {
3855
+			echo '
3669 3856
 						<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3670
-	if (!empty($upcontext['skip']))
3671
-		echo '
3857
+	}
3858
+	if (!empty($upcontext['skip'])) {
3859
+			echo '
3672 3860
 						<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3861
+	}
3673 3862
 
3674 3863
 	echo '
3675 3864
 					</div>
@@ -3720,11 +3909,12 @@  discard block
 block discarded – undo
3720 3909
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3721 3910
 	<smf>';
3722 3911
 
3723
-	if (!empty($upcontext['get_data']))
3724
-		foreach ($upcontext['get_data'] as $k => $v)
3912
+	if (!empty($upcontext['get_data'])) {
3913
+			foreach ($upcontext['get_data'] as $k => $v)
3725 3914
 			echo '
3726 3915
 		<get key="', $k, '">', $v, '</get>';
3727
-}
3916
+	}
3917
+	}
3728 3918
 
3729 3919
 function template_xml_below()
3730 3920
 {
@@ -3764,20 +3954,22 @@  discard block
 block discarded – undo
3764 3954
 	template_chmod();
3765 3955
 
3766 3956
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3767
-	if ($upcontext['is_large_forum'])
3768
-		echo '
3957
+	if ($upcontext['is_large_forum']) {
3958
+			echo '
3769 3959
 					<div class="errorbox">
3770 3960
 						<h3>', $txt['upgrade_warning'], '</h3>
3771 3961
 						', $txt['upgrade_warning_lots_data'], '
3772 3962
 					</div>';
3963
+	}
3773 3964
 
3774 3965
 	// A warning message?
3775
-	if (!empty($upcontext['warning']))
3776
-		echo '
3966
+	if (!empty($upcontext['warning'])) {
3967
+			echo '
3777 3968
 					<div class="errorbox">
3778 3969
 						<h3>', $txt['upgrade_warning'], '</h3>
3779 3970
 						', $upcontext['warning'], '
3780 3971
 					</div>';
3972
+	}
3781 3973
 
3782 3974
 	// Paths are incorrect?
3783 3975
 	echo '
@@ -3808,16 +4000,18 @@  discard block
 block discarded – undo
3808 4000
 						<p>', sprintf($txt[$agoTxt],  $ago_seconds, $ago_minutes, $ago_hours), '</p>
3809 4001
 						<p>', sprintf($txt[$updatedTxt], $updated_seconds, $updated_minutes, $updated_hours), '</p>';
3810 4002
 
3811
-		if ($updated < 600)
3812
-			echo '
4003
+		if ($updated < 600) {
4004
+					echo '
3813 4005
 						<p>', $txt['upgrade_run_script'], ' ', $upcontext['user']['name'],' ', $txt['upgrade_run_script2'], '</p>';
4006
+		}
3814 4007
 
3815
-		if ($updated > $upcontext['inactive_timeout'])
3816
-			echo '
4008
+		if ($updated > $upcontext['inactive_timeout']) {
4009
+					echo '
3817 4010
 						<p>',$txt['upgrade_run'], '</p>';
3818
-		else
3819
-			echo '
4011
+		} else {
4012
+					echo '
3820 4013
 						<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>';
4014
+		}
3821 4015
 
3822 4016
 		echo '
3823 4017
 					</div>';
@@ -3833,9 +4027,10 @@  discard block
 block discarded – undo
3833 4027
 						<dd>
3834 4028
 							<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3835 4029
 
3836
-	if (!empty($upcontext['username_incorrect']))
3837
-		echo '
4030
+	if (!empty($upcontext['username_incorrect'])) {
4031
+			echo '
3838 4032
 							<div class="smalltext red">', $txt['upgrade_wrong_username'], '</div>';
4033
+	}
3839 4034
 
3840 4035
 	echo '
3841 4036
 						</dd>
@@ -3846,9 +4041,10 @@  discard block
 block discarded – undo
3846 4041
 							<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3847 4042
 							<input type="hidden" name="hash_passwrd" value="">';
3848 4043
 
3849
-	if (!empty($upcontext['password_failed']))
3850
-		echo '
4044
+	if (!empty($upcontext['password_failed'])) {
4045
+			echo '
3851 4046
 							<div class="smalltext red">', $txt['upgrade_wrong_password'], '</div>';
4047
+	}
3852 4048
 
3853 4049
 	echo '
3854 4050
 						</dd>';
@@ -3916,12 +4112,13 @@  discard block
 block discarded – undo
3916 4112
 				<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3917 4113
 
3918 4114
 	// Warning message?
3919
-	if (!empty($upcontext['upgrade_options_warning']))
3920
-		echo '
4115
+	if (!empty($upcontext['upgrade_options_warning'])) {
4116
+			echo '
3921 4117
 				<div class="errorbox">
3922 4118
 					<h3>', $txt['upgrade_warning'] ,'</h3>
3923 4119
 					', $upcontext['upgrade_options_warning'], '
3924 4120
 				</div>';
4121
+	}
3925 4122
 
3926 4123
 	echo '
3927 4124
 				<ul class="upgrade_settings">
@@ -3950,12 +4147,13 @@  discard block
 block discarded – undo
3950 4147
 						<label for="empty_error">', $txt['upgrade_empty_errlog'], '</label>
3951 4148
 					</li>';
3952 4149
 
3953
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3954
-		echo '
4150
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
4151
+			echo '
3955 4152
 					<li>
3956 4153
 						<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
3957 4154
 						<label for="delete_karma">', $txt['upgrade_delete_karma'], '</label>
3958 4155
 					</li>';
4156
+	}
3959 4157
 
3960 4158
 	echo '
3961 4159
 					<li>
@@ -3995,10 +4193,11 @@  discard block
 block discarded – undo
3995 4193
 					</div>';
3996 4194
 
3997 4195
 	// Dont any tables so far?
3998
-	if (!empty($upcontext['previous_tables']))
3999
-		foreach ($upcontext['previous_tables'] as $table)
4196
+	if (!empty($upcontext['previous_tables'])) {
4197
+			foreach ($upcontext['previous_tables'] as $table)
4000 4198
 			echo '
4001 4199
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4200
+	}
4002 4201
 
4003 4202
 	echo '
4004 4203
 					<h3 id="current_tab">
@@ -4037,12 +4236,13 @@  discard block
 block discarded – undo
4037 4236
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4038 4237
 
4039 4238
 		// If debug flood the screen.
4040
-		if ($is_debug)
4041
-			echo '
4239
+		if ($is_debug) {
4240
+					echo '
4042 4241
 							setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4043 4242
 
4044 4243
 							if (document.getElementById(\'debug_section\').scrollHeight)
4045 4244
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4245
+		}
4046 4246
 
4047 4247
 		echo '
4048 4248
 							// Get the next update...
@@ -4075,8 +4275,9 @@  discard block
 block discarded – undo
4075 4275
 {
4076 4276
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold, $txt;
4077 4277
 
4078
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
4079
-		$is_debug = true;
4278
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4279
+			$is_debug = true;
4280
+	}
4080 4281
 
4081 4282
 	echo '
4082 4283
 				<h3>', $txt['upgrade_db_changes'], '</h3>
@@ -4091,8 +4292,9 @@  discard block
 block discarded – undo
4091 4292
 	{
4092 4293
 		foreach ($upcontext['actioned_items'] as $num => $item)
4093 4294
 		{
4094
-			if ($num != 0)
4095
-				echo ' Successful!';
4295
+			if ($num != 0) {
4296
+							echo ' Successful!';
4297
+			}
4096 4298
 			echo '<br>' . $item;
4097 4299
 		}
4098 4300
 
@@ -4107,20 +4309,20 @@  discard block
 block discarded – undo
4107 4309
 				$seconds = intval($active % 60);
4108 4310
 
4109 4311
 				echo '', sprintf($txt['upgrade_success_time_db'], $seconds, $minutes, $hours), '<br>';
4312
+			} else {
4313
+							echo '', $txt['upgrade_success'], '<br>';
4110 4314
 			}
4111
-			else
4112
-				echo '', $txt['upgrade_success'], '<br>';
4113 4315
 
4114 4316
 			echo '
4115 4317
 					<p id="commess">', $txt['upgrade_db_complete'], '</p>';
4116 4318
 		}
4117
-	}
4118
-	else
4319
+	} else
4119 4320
 	{
4120 4321
 		// Tell them how many files we have in total.
4121
-		if ($upcontext['file_count'] > 1)
4122
-			echo '
4322
+		if ($upcontext['file_count'] > 1) {
4323
+					echo '
4123 4324
 					<strong id="info1">', $txt['upgrade_script'], ' <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4325
+		}
4124 4326
 
4125 4327
 		echo '
4126 4328
 					<h3 id="info2">
@@ -4140,10 +4342,10 @@  discard block
 block discarded – undo
4140 4342
 
4141 4343
 				echo '
4142 4344
 					<p id="upgradeCompleted">', sprintf($txt['upgrade_success_time_db'], $seconds, $minutes, $hours), '</p>';
4143
-			}
4144
-			else
4145
-				echo '
4345
+			} else {
4346
+							echo '
4146 4347
 					<p id="upgradeCompleted"></p>';
4348
+			}
4147 4349
 
4148 4350
 			echo '
4149 4351
 					<div id="debug_section">
@@ -4179,9 +4381,10 @@  discard block
 block discarded – undo
4179 4381
 						var getData = "";
4180 4382
 						var debugItems = ', $upcontext['debug_items'], ';';
4181 4383
 
4182
-		if ($is_debug)
4183
-			echo '
4384
+		if ($is_debug) {
4385
+					echo '
4184 4386
 						var upgradeStartTime = ' . $upcontext['started'] . ';';
4387
+		}
4185 4388
 
4186 4389
 		echo '
4187 4390
 						function getNextItem()
@@ -4221,9 +4424,10 @@  discard block
 block discarded – undo
4221 4424
 									document.getElementById("error_block").classList.remove("hidden");
4222 4425
 									setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4223 4426
 
4224
-	if ($is_debug)
4225
-		echo '
4427
+	if ($is_debug) {
4428
+			echo '
4226 4429
 									setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4430
+	}
4227 4431
 
4228 4432
 	echo '
4229 4433
 								}
@@ -4244,9 +4448,10 @@  discard block
 block discarded – undo
4244 4448
 									document.getElementById("error_block").classList.remove("hidden");
4245 4449
 									setInnerHTML(document.getElementById("error_message"), "', $txt['upgrade_loop'], '" + sDebugName);';
4246 4450
 
4247
-	if ($is_debug)
4248
-		echo '
4451
+	if ($is_debug) {
4452
+			echo '
4249 4453
 									setOuterHTML(document.getElementById(\'debuginfo\'), \'<span class="red">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4454
+	}
4250 4455
 
4251 4456
 	echo '
4252 4457
 								}
@@ -4304,8 +4509,8 @@  discard block
 block discarded – undo
4304 4509
 							{';
4305 4510
 
4306 4511
 		// Database Changes, tell us how much time we spen to do this.  If this gets updated via JS.
4307
-		if ($is_debug)
4308
-			echo '
4512
+		if ($is_debug) {
4513
+					echo '
4309 4514
 								document.getElementById(\'debug_section\').classList.add("hidden");
4310 4515
 
4311 4516
 								var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4320,6 +4525,7 @@  discard block
 block discarded – undo
4320 4525
 								completedTxt = completedTxt.replace("%1$d", diffSeconds).replace("%2$d", diffMinutes).replace("%3$d", diffHours);
4321 4526
 console.log(completedTxt, upgradeFinishedTime, diffTime, diffHours, diffMinutes, diffSeconds);
4322 4527
 								setInnerHTML(document.getElementById("upgradeCompleted"), completedTxt);';
4528
+		}
4323 4529
 
4324 4530
 		echo '
4325 4531
 
@@ -4327,9 +4533,10 @@  discard block
 block discarded – undo
4327 4533
 								document.getElementById(\'contbutt\').disabled = 0;
4328 4534
 								document.getElementById(\'database_done\').value = 1;';
4329 4535
 
4330
-		if ($upcontext['file_count'] > 1)
4331
-			echo '
4536
+		if ($upcontext['file_count'] > 1) {
4537
+					echo '
4332 4538
 								document.getElementById(\'info1\').classList.add(\'hidden\');';
4539
+		}
4333 4540
 
4334 4541
 		echo '
4335 4542
 								document.getElementById(\'info2\').classList.add(\'hidden\');
@@ -4342,9 +4549,10 @@  discard block
 block discarded – undo
4342 4549
 								lastItem = 0;
4343 4550
 								prevFile = curFile;';
4344 4551
 
4345
-		if ($is_debug)
4346
-			echo '
4552
+		if ($is_debug) {
4553
+					echo '
4347 4554
 								setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4555
+		}
4348 4556
 
4349 4557
 		echo '
4350 4558
 								getNextItem();
@@ -4352,8 +4560,8 @@  discard block
 block discarded – undo
4352 4560
 							}';
4353 4561
 
4354 4562
 		// If debug scroll the screen.
4355
-		if ($is_debug)
4356
-			echo '
4563
+		if ($is_debug) {
4564
+					echo '
4357 4565
 							if (iLastSubStepProgress == -1)
4358 4566
 							{
4359 4567
 								// Give it consistent dots.
@@ -4372,6 +4580,7 @@  discard block
 block discarded – undo
4372 4580
 
4373 4581
 							if (document.getElementById(\'debug_section\').scrollHeight)
4374 4582
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4583
+		}
4375 4584
 
4376 4585
 		echo '
4377 4586
 							// Update the page.
@@ -4432,9 +4641,10 @@  discard block
 block discarded – undo
4432 4641
 						}';
4433 4642
 
4434 4643
 		// Start things off assuming we've not errored.
4435
-		if (empty($upcontext['error_message']))
4436
-			echo '
4644
+		if (empty($upcontext['error_message'])) {
4645
+					echo '
4437 4646
 						getNextItem();';
4647
+		}
4438 4648
 
4439 4649
 		echo '
4440 4650
 					//# sourceURL=dynamicScript-dbch.js
@@ -4452,18 +4662,21 @@  discard block
 block discarded – undo
4452 4662
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4453 4663
 	<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>';
4454 4664
 
4455
-	if (!empty($upcontext['error_message']))
4456
-		echo '
4665
+	if (!empty($upcontext['error_message'])) {
4666
+			echo '
4457 4667
 	<error>', $upcontext['error_message'], '</error>';
4668
+	}
4458 4669
 
4459
-	if (!empty($upcontext['error_string']))
4460
-		echo '
4670
+	if (!empty($upcontext['error_string'])) {
4671
+			echo '
4461 4672
 	<sql>', $upcontext['error_string'], '</sql>';
4673
+	}
4462 4674
 
4463
-	if ($is_debug)
4464
-		echo '
4675
+	if ($is_debug) {
4676
+			echo '
4465 4677
 	<curtime>', time(), '</curtime>';
4466
-}
4678
+	}
4679
+	}
4467 4680
 
4468 4681
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4469 4682
 function template_convert_utf8()
@@ -4480,10 +4693,11 @@  discard block
 block discarded – undo
4480 4693
 					</div>';
4481 4694
 
4482 4695
 	// Done any tables so far?
4483
-	if (!empty($upcontext['previous_tables']))
4484
-		foreach ($upcontext['previous_tables'] as $table)
4696
+	if (!empty($upcontext['previous_tables'])) {
4697
+			foreach ($upcontext['previous_tables'] as $table)
4485 4698
 			echo '
4486 4699
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4700
+	}
4487 4701
 
4488 4702
 	echo '
4489 4703
 					<h3 id="current_tab">
@@ -4491,9 +4705,10 @@  discard block
 block discarded – undo
4491 4705
 					</h3>';
4492 4706
 
4493 4707
 	// If we dropped their index, let's let them know
4494
-	if ($upcontext['dropping_index'])
4495
-		echo '
4708
+	if ($upcontext['dropping_index']) {
4709
+			echo '
4496 4710
 					<p id="indexmsg" class="', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline_block' : 'hidden', ' style="font-weight: bold; font-style: italic">', $txt['upgrade_fulltext'], '</p>';
4711
+	}
4497 4712
 
4498 4713
 	// Completion notification
4499 4714
 	echo '
@@ -4530,12 +4745,13 @@  discard block
 block discarded – undo
4530 4745
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4531 4746
 
4532 4747
 		// If debug flood the screen.
4533
-		if ($is_debug)
4534
-			echo '
4748
+		if ($is_debug) {
4749
+					echo '
4535 4750
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4536 4751
 
4537 4752
 						if (document.getElementById(\'debug_section\').scrollHeight)
4538 4753
 							document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4754
+		}
4539 4755
 
4540 4756
 		echo '
4541 4757
 						// Get the next update...
@@ -4581,10 +4797,11 @@  discard block
 block discarded – undo
4581 4797
 					</div>';
4582 4798
 
4583 4799
 	// Dont any tables so far?
4584
-	if (!empty($upcontext['previous_tables']))
4585
-		foreach ($upcontext['previous_tables'] as $table)
4800
+	if (!empty($upcontext['previous_tables'])) {
4801
+			foreach ($upcontext['previous_tables'] as $table)
4586 4802
 			echo '
4587 4803
 					<br>', $txt['upgrade_completed_table'], ' &quot;', $table, '&quot;.';
4804
+	}
4588 4805
 
4589 4806
 	echo '
4590 4807
 					<h3 id="current_tab">
@@ -4593,9 +4810,10 @@  discard block
 block discarded – undo
4593 4810
 					<p id="commess" class="', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline_block' : 'hidden', '">', $txt['upgrade_json_completed'], '</p>';
4594 4811
 
4595 4812
 	// Try to make sure substep was reset.
4596
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4597
-		echo '
4813
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4814
+			echo '
4598 4815
 					<input type="hidden" name="substep" id="substep" value="0">';
4816
+	}
4599 4817
 
4600 4818
 	// Continue please!
4601 4819
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4628,12 +4846,13 @@  discard block
 block discarded – undo
4628 4846
 							updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4629 4847
 
4630 4848
 		// If debug flood the screen.
4631
-		if ($is_debug)
4632
-			echo '
4849
+		if ($is_debug) {
4850
+					echo '
4633 4851
 							setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>', $txt['upgrade_completed_table'], ' &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4634 4852
 
4635 4853
 							if (document.getElementById(\'debug_section\').scrollHeight)
4636 4854
 								document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4855
+		}
4637 4856
 
4638 4857
 		echo '
4639 4858
 							// Get the next update...
@@ -4669,8 +4888,8 @@  discard block
 block discarded – undo
4669 4888
 				<h3>', $txt['upgrade_done'], ' <a href="', $boardurl, '/index.php">', $txt['upgrade_done2'], '</a>.  ', $txt['upgrade_done3'], '</h3>
4670 4889
 				<form action="', $boardurl, '/index.php">';
4671 4890
 
4672
-	if (!empty($upcontext['can_delete_script']))
4673
-		echo '
4891
+	if (!empty($upcontext['can_delete_script'])) {
4892
+			echo '
4674 4893
 					<label>
4675 4894
 						<input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> ', $txt['upgrade_delete_now'], '
4676 4895
 					</label>
@@ -4684,6 +4903,7 @@  discard block
 block discarded – undo
4684 4903
 						}
4685 4904
 					</script>
4686 4905
 					<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4906
+	}
4687 4907
 
4688 4908
 	// Show Upgrade time in debug mode when we completed the upgrade process totatly
4689 4909
 	if ($is_debug)
@@ -4693,12 +4913,13 @@  discard block
 block discarded – undo
4693 4913
 		$minutes = intval(($active / 60) % 60);
4694 4914
 		$seconds = intval($active % 60);
4695 4915
 
4696
-		if ($hours > 0)
4697
-			echo '', sprintf($txt['upgrade_completed_time_hms'], $seconds, $minutes, $hours), '';
4698
-		elseif ($minutes > 0)
4699
-			echo '', sprintf($txt['upgrade_completed_time_ms'], $seconds, $minutes), '';
4700
-		elseif ($seconds > 0)
4701
-			echo '', sprintf($txt['upgrade_completed_time_s'], $seconds), '';
4916
+		if ($hours > 0) {
4917
+					echo '', sprintf($txt['upgrade_completed_time_hms'], $seconds, $minutes, $hours), '';
4918
+		} elseif ($minutes > 0) {
4919
+					echo '', sprintf($txt['upgrade_completed_time_ms'], $seconds, $minutes), '';
4920
+		} elseif ($seconds > 0) {
4921
+					echo '', sprintf($txt['upgrade_completed_time_s'], $seconds), '';
4922
+		}
4702 4923
 	}
4703 4924
 
4704 4925
 	echo '
@@ -4728,8 +4949,9 @@  discard block
 block discarded – undo
4728 4949
 
4729 4950
 	$current_substep = $_GET['substep'];
4730 4951
 
4731
-	if (empty($_GET['a']))
4732
-		$_GET['a'] = 0;
4952
+	if (empty($_GET['a'])) {
4953
+			$_GET['a'] = 0;
4954
+	}
4733 4955
 	$step_progress['name'] = 'Converting ips';
4734 4956
 	$step_progress['current'] = $_GET['a'];
4735 4957
 
@@ -4772,16 +4994,19 @@  discard block
 block discarded – undo
4772 4994
 				'empty' => '',
4773 4995
 				'limit' => $limit,
4774 4996
 		));
4775
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4776
-			$arIp[] = $row[$oldCol];
4997
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4998
+					$arIp[] = $row[$oldCol];
4999
+		}
4777 5000
 		$smcFunc['db_free_result']($request);
4778 5001
 
4779 5002
 		// Special case, null ip could keep us in a loop.
4780
-		if (is_null($arIp[0]))
4781
-			unset($arIp[0]);
5003
+		if (is_null($arIp[0])) {
5004
+					unset($arIp[0]);
5005
+		}
4782 5006
 
4783
-		if (empty($arIp))
4784
-			$is_done = true;
5007
+		if (empty($arIp)) {
5008
+					$is_done = true;
5009
+		}
4785 5010
 
4786 5011
 		$updates = array();
4787 5012
 		$cases = array();
@@ -4790,16 +5015,18 @@  discard block
 block discarded – undo
4790 5015
 		{
4791 5016
 			$arIp[$i] = trim($arIp[$i]);
4792 5017
 
4793
-			if (empty($arIp[$i]))
4794
-				continue;
5018
+			if (empty($arIp[$i])) {
5019
+							continue;
5020
+			}
4795 5021
 
4796 5022
 			$updates['ip' . $i] = $arIp[$i];
4797 5023
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4798 5024
 
4799 5025
 			if ($setSize > 0 && $i % $setSize === 0)
4800 5026
 			{
4801
-				if (count($updates) == 1)
4802
-					continue;
5027
+				if (count($updates) == 1) {
5028
+									continue;
5029
+				}
4803 5030
 
4804 5031
 				$updates['whereSet'] = array_values($updates);
4805 5032
 				$smcFunc['db_query']('', '
@@ -4833,8 +5060,7 @@  discard block
 block discarded – undo
4833 5060
 							'ip' => $ip
4834 5061
 					));
4835 5062
 				}
4836
-			}
4837
-			else
5063
+			} else
4838 5064
 			{
4839 5065
 				$updates['whereSet'] = array_values($updates);
4840 5066
 				$smcFunc['db_query']('', '
@@ -4848,9 +5074,9 @@  discard block
 block discarded – undo
4848 5074
 					$updates
4849 5075
 				);
4850 5076
 			}
5077
+		} else {
5078
+					$is_done = true;
4851 5079
 		}
4852
-		else
4853
-			$is_done = true;
4854 5080
 
4855 5081
 		$_GET['a'] += $limit;
4856 5082
 		$step_progress['current'] = $_GET['a'];
@@ -4876,11 +5102,12 @@  discard block
 block discarded – undo
4876 5102
 
4877 5103
 	$columns = $smcFunc['db_list_columns']($targetTable, true);
4878 5104
 
4879
-	if (isset($columns[$column]))
4880
-		return $columns[$column];
4881
-	else
4882
-		return null;
4883
-}
5105
+	if (isset($columns[$column])) {
5106
+			return $columns[$column];
5107
+	} else {
5108
+			return null;
5109
+	}
5110
+	}
4884 5111
 
4885 5112
 /**
4886 5113
  * Takes the changes to be made during the upgradeOptions step, grabs all known Settings data from Settings.php, then runs
@@ -5159,18 +5386,20 @@  discard block
 block discarded – undo
5159 5386
 		global $$setVar;
5160 5387
 
5161 5388
 		// Find the setting.
5162
-		if ($setType == 'string' || $setType == 'string_fatal')
5163
-			$original[$setVar] = isset($$setVar) ? '\'' . addslashes($$setVar) . '\'' : (strpos('fatal', $setType) ? null : '\'\'');
5164
-		elseif ($setType == 'int' || $setType == 'int_fatal')
5165
-			$original[$setVar] = isset($$setVar) ? (int) $$setVar : (strpos('fatal', $setType) ? null : 0);
5166
-		elseif ($setType == 'bool' || $setType == 'bool_fatal')
5167
-			$original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'false');
5168
-		elseif ($setType == 'null' || $setType == 'null_fatal')
5169
-			$original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'null');
5389
+		if ($setType == 'string' || $setType == 'string_fatal') {
5390
+					$original[$setVar] = isset($$setVar) ? '\'' . addslashes($$setVar) . '\'' : (strpos('fatal', $setType) ? null : '\'\'');
5391
+		} elseif ($setType == 'int' || $setType == 'int_fatal') {
5392
+					$original[$setVar] = isset($$setVar) ? (int) $$setVar : (strpos('fatal', $setType) ? null : 0);
5393
+		} elseif ($setType == 'bool' || $setType == 'bool_fatal') {
5394
+					$original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'false');
5395
+		} elseif ($setType == 'null' || $setType == 'null_fatal') {
5396
+					$original[$setVar] = isset($$setVar) && in_array($$setVar, array(1, true)) ? 'true' : (strpos('fatal', $setType) ? null : 'null');
5397
+		}
5170 5398
 
5171 5399
 		// Well this isn't good.  Do we fix it or bail?
5172
-		if (is_null($original) && $setType != 'null' && strpos('fatal', $setType) > -1)
5173
-			return throw_error('The upgrader could not copy a setting (' . $setVar . ') from your Settings file.  Unable to migrate your Settings file to a new version.');
5400
+		if (is_null($original) && $setType != 'null' && strpos('fatal', $setType) > -1) {
5401
+					return throw_error('The upgrader could not copy a setting (' . $setVar . ') from your Settings file.  Unable to migrate your Settings file to a new version.');
5402
+		}
5174 5403
 	}
5175 5404
 
5176 5405
 	// Finally, merge the changes with the new ones.
@@ -5178,8 +5407,9 @@  discard block
 block discarded – undo
5178 5407
 	foreach ($changes as $setVar => $value)
5179 5408
 	{
5180 5409
 		// Nothing needed here.
5181
-		if ($setVar != 'upgradeData' && $config_vars[$setVar] == $changes[$setVar])
5182
-			continue;
5410
+		if ($setVar != 'upgradeData' && $config_vars[$setVar] == $changes[$setVar]) {
5411
+					continue;
5412
+		}
5183 5413
 
5184 5414
 		$config_vars[$setVar] = $value;
5185 5415
 	}
@@ -5192,15 +5422,17 @@  discard block
 block discarded – undo
5192 5422
 	$last_settings_change = filemtime($boarddir . '/Settings.php');
5193 5423
 
5194 5424
 	// remove any /r's that made there way in here
5195
-	foreach ($settingsArray as $k => $dummy)
5196
-		$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
5425
+	foreach ($settingsArray as $k => $dummy) {
5426
+			$settingsArray[$k] = strtr($dummy, array("\r" => '')) . "\n";
5427
+	}
5197 5428
 
5198 5429
 	// go line by line and see whats changing
5199 5430
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
5200 5431
 	{
5201 5432
 		// Don't trim or bother with it if it's not a variable.
5202
-		if (substr($settingsArray[$i], 0, 1) != '$')
5203
-			continue;
5433
+		if (substr($settingsArray[$i], 0, 1) != '$') {
5434
+					continue;
5435
+		}
5204 5436
 
5205 5437
 		$settingsArray[$i] = trim($settingsArray[$i]) . "\n";
5206 5438
 
@@ -5208,9 +5440,9 @@  discard block
 block discarded – undo
5208 5440
 		foreach ($config_vars as $var => $val)
5209 5441
 		{
5210 5442
 			// be sure someone is not updating db_last_error this with a group
5211
-			if ($var === 'db_last_error')
5212
-				unset($config_vars[$var]);
5213
-			elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
5443
+			if ($var === 'db_last_error') {
5444
+							unset($config_vars[$var]);
5445
+			} elseif (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
5214 5446
 			{
5215 5447
 				$comment = strstr(substr($settingsArray[$i], strpos($settingsArray[$i], ';')), '#');
5216 5448
 				$settingsArray[$i] = '$' . $var . ' = ' . $val . ';' . ($comment == '' ? '' : "\t\t" . rtrim($comment)) . "\n";
@@ -5221,34 +5453,39 @@  discard block
 block discarded – undo
5221 5453
 		}
5222 5454
 
5223 5455
 		// End of the file ... maybe
5224
-		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>')
5225
-			$end = $i;
5456
+		if (substr(trim($settingsArray[$i]), 0, 2) == '?' . '>') {
5457
+					$end = $i;
5458
+		}
5226 5459
 	}
5227 5460
 
5228 5461
 	// This should never happen, but apparently it is happening.
5229
-	if (empty($end) || $end < 10)
5230
-		$end = count($settingsArray) - 1;
5462
+	if (empty($end) || $end < 10) {
5463
+			$end = count($settingsArray) - 1;
5464
+	}
5231 5465
 
5232 5466
 	// Still more variables to go?  Then lets add them at the end.
5233 5467
 	if (!empty($config_vars))
5234 5468
 	{
5235
-		if (trim($settingsArray[$end]) == '?' . '>')
5236
-			$settingsArray[$end++] = '';
5237
-		else
5238
-			$end++;
5469
+		if (trim($settingsArray[$end]) == '?' . '>') {
5470
+					$settingsArray[$end++] = '';
5471
+		} else {
5472
+					$end++;
5473
+		}
5239 5474
 
5240 5475
 		// Add in any newly defined vars that were passed
5241
-		foreach ($config_vars as $var => $val)
5242
-			$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
5476
+		foreach ($config_vars as $var => $val) {
5477
+					$settingsArray[$end++] = '$' . $var . ' = ' . $val . ';' . "\n";
5478
+		}
5243 5479
 
5244 5480
 		$settingsArray[$end] = '?' . '>';
5481
+	} else {
5482
+			$settingsArray[$end] = trim($settingsArray[$end]);
5245 5483
 	}
5246
-	else
5247
-		$settingsArray[$end] = trim($settingsArray[$end]);
5248 5484
 
5249 5485
 	// Sanity error checking: the file needs to be at least 12 lines.
5250
-	if (count($settingsArray) < 12)
5251
-		return throw_error('The upgrader could not process your Settings file for updates.  Unable to migrate your Settings file to a new version.');
5486
+	if (count($settingsArray) < 12) {
5487
+			return throw_error('The upgrader could not process your Settings file for updates.  Unable to migrate your Settings file to a new version.');
5488
+	}
5252 5489
 
5253 5490
 	// Try to avoid a few pitfalls:
5254 5491
 	//  - like a possible race condition,
@@ -5256,8 +5493,9 @@  discard block
 block discarded – undo
5256 5493
 	//
5257 5494
 	// Check before you act: if cache is enabled, we can do a simple write test
5258 5495
 	// to validate that we even write things on this filesystem.
5259
-	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
5260
-		$cachedir = $boarddir . '/cache';
5496
+	if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
5497
+			$cachedir = $boarddir . '/cache';
5498
+	}
5261 5499
 
5262 5500
 	$test_fp = @fopen($cachedir . '/settings_update.tmp', "w+");
5263 5501
 	if ($test_fp)
@@ -5268,8 +5506,9 @@  discard block
 block discarded – undo
5268 5506
 
5269 5507
 		// Oops. Low disk space, perhaps. Don't mess with Settings.php then.
5270 5508
 		// No means no. :P
5271
-		if ($written_bytes !== 4)
5272
-			return throw_error('The upgrader could not write a test file, perhaps not enough storage?  Unable to migrate your Settings file to a new version.');
5509
+		if ($written_bytes !== 4) {
5510
+					return throw_error('The upgrader could not write a test file, perhaps not enough storage?  Unable to migrate your Settings file to a new version.');
5511
+		}
5273 5512
 	}
5274 5513
 
5275 5514
 	// Protect me from what I want! :P
@@ -5287,8 +5526,9 @@  discard block
 block discarded – undo
5287 5526
 		// survey says ...
5288 5527
 		if ($written_bytes !== strlen($write_settings) && !$settings_backup_fail)
5289 5528
 		{
5290
-			if (file_exists($boarddir . '/Settings_bak.php'))
5291
-				@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
5529
+			if (file_exists($boarddir . '/Settings_bak.php')) {
5530
+							@copy($boarddir . '/Settings_bak.php', $boarddir . '/Settings.php');
5531
+			}
5292 5532
 
5293 5533
 			return throw_error('The upgrader detected a bad Settings file and reverted the changes.  Unable to migrate your Settings file to a new version.');
5294 5534
 		}
@@ -5296,9 +5536,10 @@  discard block
 block discarded – undo
5296 5536
 
5297 5537
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
5298 5538
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
5299
-	if (function_exists('opcache_invalidate'))
5300
-		opcache_invalidate($boarddir . '/Settings.php', true);
5301
-}
5539
+	if (function_exists('opcache_invalidate')) {
5540
+			opcache_invalidate($boarddir . '/Settings.php', true);
5541
+	}
5542
+	}
5302 5543
 
5303 5544
 /**
5304 5545
  * Determine if we should auto select the migrate Settings file.  This is determined by a variety of missing settings.
@@ -5315,23 +5556,27 @@  discard block
 block discarded – undo
5315 5556
 	global $boarddir, $packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled, $db_show_debug;
5316 5557
 
5317 5558
 	// We should not migrate if db_show_debug is in there, some dev stuff going on here.
5318
-	if (isset($db_show_debug))
5319
-		return false;
5559
+	if (isset($db_show_debug)) {
5560
+			return false;
5561
+	}
5320 5562
 
5321 5563
 	$file_contents = file_get_contents($boarddir . '/Settings.php');
5322 5564
 
5323 5565
 	// Is there a include statement somewhere in there? Some advanced handling of the variables elsewhere?
5324 5566
 	// Try our best to stay away from the cachedir match.
5325
-	if (preg_match('~\sinclude\((?:(?!\(isset\(\$cachedir))~im', $file_contents))
5326
-		return false;
5567
+	if (preg_match('~\sinclude\((?:(?!\(isset\(\$cachedir))~im', $file_contents)) {
5568
+			return false;
5569
+	}
5327 5570
 
5328 5571
 	// If we find a mention of $GLOBALS, there may be a integration going on.
5329
-	if (preg_match('~\$GLOBALS\[~im', $file_contents))
5330
-		return false;
5572
+	if (preg_match('~\$GLOBALS\[~im', $file_contents)) {
5573
+			return false;
5574
+	}
5331 5575
 
5332 5576
 	// If these are not set, it makes us a canidate to migrate.
5333
-	if (!isset($packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled))
5334
-		return true;
5577
+	if (!isset($packagesdir, $tasksdir, $db_server, $db_type, $image_proxy_enabled)) {
5578
+			return true;
5579
+	}
5335 5580
 
5336 5581
 	return false;
5337 5582
 }
Please login to merge, or discard this patch.
SSI.php 1 patch
Braces   +430 added lines, -308 removed lines patch added patch discarded remove patch
@@ -12,8 +12,9 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Don't do anything if SMF is already loaded.
15
-if (defined('SMF'))
15
+if (defined('SMF')) {
16 16
 	return true;
17
+}
17 18
 
18 19
 define('SMF', 'SSI');
19 20
 
@@ -28,16 +29,18 @@  discard block
 block discarded – undo
28 29
 $time_start = microtime(true);
29 30
 
30 31
 // Just being safe...
31
-foreach (array('db_character_set', 'cachedir') as $variable)
32
+foreach (array('db_character_set', 'cachedir') as $variable) {
32 33
 	if (isset($GLOBALS[$variable]))
33 34
 		unset($GLOBALS[$variable]);
35
+}
34 36
 
35 37
 // Get the forum's settings for database and file paths.
36 38
 require_once(dirname(__FILE__) . '/Settings.php');
37 39
 
38 40
 // Make absolutely sure the cache directory is defined.
39
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
41
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
40 42
 	$cachedir = $boarddir . '/cache';
43
+}
41 44
 
42 45
 $ssi_error_reporting = error_reporting(E_ALL);
43 46
 /* Set this to one of three values depending on what you want to happen in the case of a fatal error.
@@ -48,12 +51,14 @@  discard block
 block discarded – undo
48 51
 $ssi_on_error_method = false;
49 52
 
50 53
 // Don't do john didley if the forum's been shut down completely.
51
-if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true))
54
+if ($maintenance == 2 && (!isset($ssi_maintenance_off) || $ssi_maintenance_off !== true)) {
52 55
 	die($mmessage);
56
+}
53 57
 
54 58
 // Fix for using the current directory as a path.
55
-if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
59
+if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') {
56 60
 	$sourcedir = dirname(__FILE__) . substr($sourcedir, 1);
61
+}
57 62
 
58 63
 // Load the important includes.
59 64
 require_once($sourcedir . '/QueryString.php');
@@ -78,26 +83,30 @@  discard block
 block discarded – undo
78 83
 cleanRequest();
79 84
 
80 85
 // Seed the random generator?
81
-if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69)
86
+if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69) {
82 87
 	smf_seed_generator();
88
+}
83 89
 
84 90
 // Check on any hacking attempts.
85
-if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']))
91
+if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) {
86 92
 	die('No direct access...');
87
-elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme)
93
+} elseif (isset($_REQUEST['ssi_theme']) && (int) $_REQUEST['ssi_theme'] == (int) $ssi_theme) {
88 94
 	die('No direct access...');
89
-elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme)
95
+} elseif (isset($_COOKIE['ssi_theme']) && (int) $_COOKIE['ssi_theme'] == (int) $ssi_theme) {
90 96
 	die('No direct access...');
91
-elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers)
97
+} elseif (isset($_REQUEST['ssi_layers'], $ssi_layers) && (@get_magic_quotes_gpc() ? stripslashes($_REQUEST['ssi_layers']) : $_REQUEST['ssi_layers']) == $ssi_layers) {
92 98
 	die('No direct access...');
93
-if (isset($_REQUEST['context']))
99
+}
100
+if (isset($_REQUEST['context'])) {
94 101
 	die('No direct access...');
102
+}
95 103
 
96 104
 // Gzip output? (because it must be boolean and true, this can't be hacked.)
97
-if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>='))
105
+if (isset($ssi_gzip) && $ssi_gzip === true && ini_get('zlib.output_compression') != '1' && ini_get('output_handler') != 'ob_gzhandler' && version_compare(PHP_VERSION, '4.2.0', '>=')) {
98 106
 	ob_start('ob_gzhandler');
99
-else
107
+} else {
100 108
 	$modSettings['enableCompressedOutput'] = '0';
109
+}
101 110
 
102 111
 /**
103 112
  * An autoloader for certain classes.
@@ -146,9 +155,9 @@  discard block
 block discarded – undo
146 155
 ob_start('ob_sessrewrite');
147 156
 
148 157
 // Start the session... known to scramble SSI includes in cases...
149
-if (!headers_sent())
158
+if (!headers_sent()) {
150 159
 	loadSession();
151
-else
160
+} else
152 161
 {
153 162
 	if (isset($_COOKIE[session_name()]) || isset($_REQUEST[session_name()]))
154 163
 	{
@@ -182,12 +191,14 @@  discard block
 block discarded – undo
182 191
 loadTheme(isset($ssi_theme) ? (int) $ssi_theme : 0);
183 192
 
184 193
 // @todo: probably not the best place, but somewhere it should be set...
185
-if (!headers_sent())
194
+if (!headers_sent()) {
186 195
 	header('content-type: text/html; charset=' . (empty($modSettings['global_character_set']) ? (empty($txt['lang_character_set']) ? 'ISO-8859-1' : $txt['lang_character_set']) : $modSettings['global_character_set']));
196
+}
187 197
 
188 198
 // Take care of any banning that needs to be done.
189
-if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true))
199
+if (isset($_REQUEST['ssi_ban']) || (isset($ssi_ban) && $ssi_ban === true)) {
190 200
 	is_not_banned();
201
+}
191 202
 
192 203
 // Do we allow guests in here?
193 204
 if (empty($ssi_guest_access) && empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && basename($_SERVER['PHP_SELF']) != 'SSI.php')
@@ -202,17 +213,19 @@  discard block
 block discarded – undo
202 213
 {
203 214
 	$context['template_layers'] = $ssi_layers;
204 215
 	template_header();
205
-}
206
-else
216
+} else {
207 217
 	setupThemeContext();
218
+}
208 219
 
209 220
 // Make sure they didn't muss around with the settings... but only if it's not cli.
210
-if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '')
221
+if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '') {
211 222
 	trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);
223
+}
212 224
 
213 225
 // Without visiting the forum this session variable might not be set on submit.
214
-if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote'))
226
+if (!isset($_SESSION['USER_AGENT']) && (!isset($_GET['ssi_function']) || $_GET['ssi_function'] !== 'pollVote')) {
215 227
 	$_SESSION['USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
228
+}
216 229
 
217 230
 // Have the ability to easily add functions to SSI.
218 231
 call_integration_hook('integrate_SSI');
@@ -221,11 +234,13 @@  discard block
 block discarded – undo
221 234
 if (basename($_SERVER['PHP_SELF']) == 'SSI.php')
222 235
 {
223 236
 	// You shouldn't just access SSI.php directly by URL!!
224
-	if (!isset($_GET['ssi_function']))
225
-		die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
237
+	if (!isset($_GET['ssi_function'])) {
238
+			die(sprintf($txt['ssi_not_direct'], $user_info['is_admin'] ? '\'' . addslashes(__FILE__) . '\'' : '\'SSI.php\''));
239
+	}
226 240
 	// Call a function passed by GET.
227
-	if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest']))
228
-		call_user_func('ssi_' . $_GET['ssi_function']);
241
+	if (function_exists('ssi_' . $_GET['ssi_function']) && (!empty($modSettings['allow_guestAccess']) || !$user_info['is_guest'])) {
242
+			call_user_func('ssi_' . $_GET['ssi_function']);
243
+	}
229 244
 	exit;
230 245
 }
231 246
 
@@ -242,9 +257,10 @@  discard block
 block discarded – undo
242 257
  */
243 258
 function ssi_shutdown()
244 259
 {
245
-	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown')
246
-		template_footer();
247
-}
260
+	if (!isset($_GET['ssi_function']) || $_GET['ssi_function'] != 'shutdown') {
261
+			template_footer();
262
+	}
263
+	}
248 264
 
249 265
 /**
250 266
  * Display a welcome message, like: Hey, User, you have 0 messages, 0 are new.
@@ -257,15 +273,17 @@  discard block
 block discarded – undo
257 273
 
258 274
 	if ($output_method == 'echo')
259 275
 	{
260
-		if ($context['user']['is_guest'])
261
-			echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
262
-		else
263
-			echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
276
+		if ($context['user']['is_guest']) {
277
+					echo sprintf($txt[$context['can_register'] ? 'welcome_guest_register' : 'welcome_guest'], $txt['guest_title'], $context['forum_name_html_safe'], $scripturl . '?action=login', 'return reqOverlayDiv(this.href, ' . JavaScriptEscape($txt['login']) . ');', $scripturl . '?action=signup');
278
+		} else {
279
+					echo $txt['hello_member'], ' <strong>', $context['user']['name'], '</strong>', allowedTo('pm_read') ? ', ' . (empty($context['user']['messages']) ? $txt['msg_alert_no_messages'] : (($context['user']['messages'] == 1 ? sprintf($txt['msg_alert_one_message'], $scripturl . '?action=pm') : sprintf($txt['msg_alert_many_message'], $scripturl . '?action=pm', $context['user']['messages'])) . ', ' . ($context['user']['unread_messages'] == 1 ? $txt['msg_alert_one_new'] : sprintf($txt['msg_alert_many_new'], $context['user']['unread_messages'])))) : '';
280
+		}
264 281
 	}
265 282
 	// Don't echo... then do what?!
266
-	else
267
-		return $context['user'];
268
-}
283
+	else {
284
+			return $context['user'];
285
+	}
286
+	}
269 287
 
270 288
 /**
271 289
  * Display a menu bar, like is displayed at the top of the forum.
@@ -276,12 +294,14 @@  discard block
 block discarded – undo
276 294
 {
277 295
 	global $context;
278 296
 
279
-	if ($output_method == 'echo')
280
-		template_menu();
297
+	if ($output_method == 'echo') {
298
+			template_menu();
299
+	}
281 300
 	// What else could this do?
282
-	else
283
-		return $context['menu_buttons'];
284
-}
301
+	else {
302
+			return $context['menu_buttons'];
303
+	}
304
+	}
285 305
 
286 306
 /**
287 307
  * Show a logout link.
@@ -293,20 +313,23 @@  discard block
 block discarded – undo
293 313
 {
294 314
 	global $context, $txt, $scripturl;
295 315
 
296
-	if ($redirect_to != '')
297
-		$_SESSION['logout_url'] = $redirect_to;
316
+	if ($redirect_to != '') {
317
+			$_SESSION['logout_url'] = $redirect_to;
318
+	}
298 319
 
299 320
 	// Guests can't log out.
300
-	if ($context['user']['is_guest'])
301
-		return false;
321
+	if ($context['user']['is_guest']) {
322
+			return false;
323
+	}
302 324
 
303 325
 	$link = '<a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '">' . $txt['logout'] . '</a>';
304 326
 
305
-	if ($output_method == 'echo')
306
-		echo $link;
307
-	else
308
-		return $link;
309
-}
327
+	if ($output_method == 'echo') {
328
+			echo $link;
329
+	} else {
330
+			return $link;
331
+	}
332
+	}
310 333
 
311 334
 /**
312 335
  * Recent post list:   [board] Subject by Poster    Date
@@ -322,17 +345,17 @@  discard block
 block discarded – undo
322 345
 	global $modSettings, $context;
323 346
 
324 347
 	// Excluding certain boards...
325
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
326
-		$exclude_boards = array($modSettings['recycle_board']);
327
-	else
328
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
348
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
349
+			$exclude_boards = array($modSettings['recycle_board']);
350
+	} else {
351
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
352
+	}
329 353
 
330 354
 	// What about including certain boards - note we do some protection here as pre-2.0 didn't have this parameter.
331 355
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
332 356
 	{
333 357
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
334
-	}
335
-	elseif ($include_boards != null)
358
+	} elseif ($include_boards != null)
336 359
 	{
337 360
 		$include_boards = array();
338 361
 	}
@@ -369,8 +392,9 @@  discard block
 block discarded – undo
369 392
 {
370 393
 	global $modSettings;
371 394
 
372
-	if (empty($post_ids))
373
-		return;
395
+	if (empty($post_ids)) {
396
+			return;
397
+	}
374 398
 
375 399
 	// Allow the user to request more than one - why not?
376 400
 	$post_ids = is_array($post_ids) ? $post_ids : array($post_ids);
@@ -405,8 +429,9 @@  discard block
 block discarded – undo
405 429
 	global $scripturl, $txt, $user_info;
406 430
 	global $modSettings, $smcFunc, $context;
407 431
 
408
-	if (!empty($modSettings['enable_likes']))
409
-		$context['can_like'] = allowedTo('likes_like');
432
+	if (!empty($modSettings['enable_likes'])) {
433
+			$context['can_like'] = allowedTo('likes_like');
434
+	}
410 435
 
411 436
 	// Find all the posts. Newer ones will have higher IDs.
412 437
 	$request = $smcFunc['db_query']('substring', '
@@ -472,12 +497,13 @@  discard block
 block discarded – undo
472 497
 		);
473 498
 
474 499
 		// Get the likes for each message.
475
-		if (!empty($modSettings['enable_likes']))
476
-			$posts[$row['id_msg']]['likes'] = array(
500
+		if (!empty($modSettings['enable_likes'])) {
501
+					$posts[$row['id_msg']]['likes'] = array(
477 502
 				'count' => $row['likes'],
478 503
 				'you' => in_array($row['id_msg'], prepareLikesContext($row['id_topic'])),
479 504
 				'can_like' => !$context['user']['is_guest'] && $row['id_member'] != $context['user']['id'] && !empty($context['can_like']),
480 505
 			);
506
+		}
481 507
 	}
482 508
 	$smcFunc['db_free_result']($request);
483 509
 
@@ -485,13 +511,14 @@  discard block
 block discarded – undo
485 511
 	call_integration_hook('integrate_ssi_queryPosts', array(&$posts));
486 512
 
487 513
 	// Just return it.
488
-	if ($output_method != 'echo' || empty($posts))
489
-		return $posts;
514
+	if ($output_method != 'echo' || empty($posts)) {
515
+			return $posts;
516
+	}
490 517
 
491 518
 	echo '
492 519
 		<table style="border: none" class="ssi_table">';
493
-	foreach ($posts as $post)
494
-		echo '
520
+	foreach ($posts as $post) {
521
+			echo '
495 522
 			<tr>
496 523
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
497 524
 					[', $post['board']['link'], ']
@@ -505,6 +532,7 @@  discard block
 block discarded – undo
505 532
 					', $post['time'], '
506 533
 				</td>
507 534
 			</tr>';
535
+	}
508 536
 	echo '
509 537
 		</table>';
510 538
 }
@@ -522,25 +550,26 @@  discard block
 block discarded – undo
522 550
 	global $settings, $scripturl, $txt, $user_info;
523 551
 	global $modSettings, $smcFunc, $context;
524 552
 
525
-	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
526
-		$exclude_boards = array($modSettings['recycle_board']);
527
-	else
528
-		$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
553
+	if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) {
554
+			$exclude_boards = array($modSettings['recycle_board']);
555
+	} else {
556
+			$exclude_boards = empty($exclude_boards) ? array() : (is_array($exclude_boards) ? $exclude_boards : array($exclude_boards));
557
+	}
529 558
 
530 559
 	// Only some boards?.
531 560
 	if (is_array($include_boards) || (int) $include_boards === $include_boards)
532 561
 	{
533 562
 		$include_boards = is_array($include_boards) ? $include_boards : array($include_boards);
534
-	}
535
-	elseif ($include_boards != null)
563
+	} elseif ($include_boards != null)
536 564
 	{
537 565
 		$output_method = $include_boards;
538 566
 		$include_boards = array();
539 567
 	}
540 568
 
541 569
 	$icon_sources = array();
542
-	foreach ($context['stable_icons'] as $icon)
543
-		$icon_sources[$icon] = 'images_url';
570
+	foreach ($context['stable_icons'] as $icon) {
571
+			$icon_sources[$icon] = 'images_url';
572
+	}
544 573
 
545 574
 	// Find all the posts in distinct topics.  Newer ones will have higher IDs.
546 575
 	$request = $smcFunc['db_query']('substring', '
@@ -565,13 +594,15 @@  discard block
 block discarded – undo
565 594
 		)
566 595
 	);
567 596
 	$topics = array();
568
-	while ($row = $smcFunc['db_fetch_assoc']($request))
569
-		$topics[$row['id_topic']] = $row;
597
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
598
+			$topics[$row['id_topic']] = $row;
599
+	}
570 600
 	$smcFunc['db_free_result']($request);
571 601
 
572 602
 	// Did we find anything? If not, bail.
573
-	if (empty($topics))
574
-		return array();
603
+	if (empty($topics)) {
604
+			return array();
605
+	}
575 606
 
576 607
 	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
577 608
 
@@ -599,21 +630,24 @@  discard block
 block discarded – undo
599 630
 	while ($row = $smcFunc['db_fetch_assoc']($request))
600 631
 	{
601 632
 		$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => '&#10;')));
602
-		if ($smcFunc['strlen']($row['body']) > 128)
603
-			$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
633
+		if ($smcFunc['strlen']($row['body']) > 128) {
634
+					$row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...';
635
+		}
604 636
 
605 637
 		// Censor the subject.
606 638
 		censorText($row['subject']);
607 639
 		censorText($row['body']);
608 640
 
609 641
 		// Recycled icon
610
-		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board'])
611
-			$row['icon'] = 'recycled';
642
+		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board']) {
643
+					$row['icon'] = 'recycled';
644
+		}
612 645
 
613
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
614
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
615
-		elseif (!isset($icon_sources[$row['icon']]))
616
-			$icon_sources[$row['icon']] = 'images_url';
646
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
647
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
648
+		} elseif (!isset($icon_sources[$row['icon']])) {
649
+					$icon_sources[$row['icon']] = 'images_url';
650
+		}
617 651
 
618 652
 		// Build the array.
619 653
 		$posts[] = array(
@@ -652,13 +686,14 @@  discard block
 block discarded – undo
652 686
 	call_integration_hook('integrate_ssi_recentTopics', array(&$posts));
653 687
 
654 688
 	// Just return it.
655
-	if ($output_method != 'echo' || empty($posts))
656
-		return $posts;
689
+	if ($output_method != 'echo' || empty($posts)) {
690
+			return $posts;
691
+	}
657 692
 
658 693
 	echo '
659 694
 		<table style="border: none" class="ssi_table">';
660
-	foreach ($posts as $post)
661
-		echo '
695
+	foreach ($posts as $post) {
696
+			echo '
662 697
 			<tr>
663 698
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
664 699
 					[', $post['board']['link'], ']
@@ -672,6 +707,7 @@  discard block
 block discarded – undo
672 707
 					', $post['time'], '
673 708
 				</td>
674 709
 			</tr>';
710
+	}
675 711
 	echo '
676 712
 		</table>';
677 713
 }
@@ -696,27 +732,30 @@  discard block
 block discarded – undo
696 732
 		)
697 733
 	);
698 734
 	$return = array();
699
-	while ($row = $smcFunc['db_fetch_assoc']($request))
700
-		$return[] = array(
735
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
736
+			$return[] = array(
701 737
 			'id' => $row['id_member'],
702 738
 			'name' => $row['real_name'],
703 739
 			'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
704 740
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
705 741
 			'posts' => $row['posts']
706 742
 		);
743
+	}
707 744
 	$smcFunc['db_free_result']($request);
708 745
 
709 746
 	// If mods want to do somthing with this list of members, let them do that now.
710 747
 	call_integration_hook('integrate_ssi_topPoster', array(&$return));
711 748
 
712 749
 	// Just return all the top posters.
713
-	if ($output_method != 'echo')
714
-		return $return;
750
+	if ($output_method != 'echo') {
751
+			return $return;
752
+	}
715 753
 
716 754
 	// Make a quick array to list the links in.
717 755
 	$temp_array = array();
718
-	foreach ($return as $member)
719
-		$temp_array[] = $member['link'];
756
+	foreach ($return as $member) {
757
+			$temp_array[] = $member['link'];
758
+	}
720 759
 
721 760
 	echo implode(', ', $temp_array);
722 761
 }
@@ -748,8 +787,8 @@  discard block
 block discarded – undo
748 787
 		)
749 788
 	);
750 789
 	$boards = array();
751
-	while ($row = $smcFunc['db_fetch_assoc']($request))
752
-		$boards[] = array(
790
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
791
+			$boards[] = array(
753 792
 			'id' => $row['id_board'],
754 793
 			'num_posts' => $row['num_posts'],
755 794
 			'num_topics' => $row['num_topics'],
@@ -758,14 +797,16 @@  discard block
 block discarded – undo
758 797
 			'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
759 798
 			'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['name'] . '</a>'
760 799
 		);
800
+	}
761 801
 	$smcFunc['db_free_result']($request);
762 802
 
763 803
 	// If mods want to do somthing with this list of boards, let them do that now.
764 804
 	call_integration_hook('integrate_ssi_topBoards', array(&$boards));
765 805
 
766 806
 	// If we shouldn't output or have nothing to output, just jump out.
767
-	if ($output_method != 'echo' || empty($boards))
768
-		return $boards;
807
+	if ($output_method != 'echo' || empty($boards)) {
808
+			return $boards;
809
+	}
769 810
 
770 811
 	echo '
771 812
 		<table class="ssi_table">
@@ -774,13 +815,14 @@  discard block
 block discarded – undo
774 815
 				<th style="text-align: left">', $txt['board_topics'], '</th>
775 816
 				<th style="text-align: left">', $txt['posts'], '</th>
776 817
 			</tr>';
777
-	foreach ($boards as $sBoard)
778
-		echo '
818
+	foreach ($boards as $sBoard) {
819
+			echo '
779 820
 			<tr>
780 821
 				<td>', $sBoard['link'], $sBoard['new'] ? ' <a href="' . $sBoard['href'] . '" class="new_posts">' . $txt['new'] . '</a>' : '', '</td>
781 822
 				<td style="text-align: right">', comma_format($sBoard['num_topics']), '</td>
782 823
 				<td style="text-align: right">', comma_format($sBoard['num_posts']), '</td>
783 824
 			</tr>';
825
+	}
784 826
 	echo '
785 827
 		</table>';
786 828
 }
@@ -813,12 +855,13 @@  discard block
 block discarded – undo
813 855
 			)
814 856
 		);
815 857
 		$topic_ids = array();
816
-		while ($row = $smcFunc['db_fetch_assoc']($request))
817
-			$topic_ids[] = $row['id_topic'];
858
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
859
+					$topic_ids[] = $row['id_topic'];
860
+		}
818 861
 		$smcFunc['db_free_result']($request);
862
+	} else {
863
+			$topic_ids = array();
819 864
 	}
820
-	else
821
-		$topic_ids = array();
822 865
 
823 866
 	$request = $smcFunc['db_query']('', '
824 867
 		SELECT m.subject, m.id_topic, t.num_views, t.num_replies
@@ -857,8 +900,9 @@  discard block
 block discarded – undo
857 900
 	// If mods want to do somthing with this list of topics, let them do that now.
858 901
 	call_integration_hook('integrate_ssi_topTopics', array(&$topics, $type));
859 902
 
860
-	if ($output_method != 'echo' || empty($topics))
861
-		return $topics;
903
+	if ($output_method != 'echo' || empty($topics)) {
904
+			return $topics;
905
+	}
862 906
 
863 907
 	echo '
864 908
 		<table class="ssi_table">
@@ -867,8 +911,8 @@  discard block
 block discarded – undo
867 911
 				<th style="text-align: left">', $txt['views'], '</th>
868 912
 				<th style="text-align: left">', $txt['replies'], '</th>
869 913
 			</tr>';
870
-	foreach ($topics as $sTopic)
871
-		echo '
914
+	foreach ($topics as $sTopic) {
915
+			echo '
872 916
 			<tr>
873 917
 				<td style="text-align: left">
874 918
 					', $sTopic['link'], '
@@ -876,6 +920,7 @@  discard block
 block discarded – undo
876 920
 				<td style="text-align: right">', comma_format($sTopic['num_views']), '</td>
877 921
 				<td style="text-align: right">', comma_format($sTopic['num_replies']), '</td>
878 922
 			</tr>';
923
+	}
879 924
 	echo '
880 925
 		</table>';
881 926
 }
@@ -911,12 +956,13 @@  discard block
 block discarded – undo
911 956
 {
912 957
 	global $txt, $context;
913 958
 
914
-	if ($output_method == 'echo')
915
-		echo '
959
+	if ($output_method == 'echo') {
960
+			echo '
916 961
 	', sprintf($txt['welcome_newest_member'], $context['common_stats']['latest_member']['link']), '<br>';
917
-	else
918
-		return $context['common_stats']['latest_member'];
919
-}
962
+	} else {
963
+			return $context['common_stats']['latest_member'];
964
+	}
965
+	}
920 966
 
921 967
 /**
922 968
  * Fetches a random member.
@@ -965,8 +1011,9 @@  discard block
 block discarded – undo
965 1011
 	}
966 1012
 
967 1013
 	// Just to be sure put the random generator back to something... random.
968
-	if ($random_type != '')
969
-		mt_srand(time());
1014
+	if ($random_type != '') {
1015
+			mt_srand(time());
1016
+	}
970 1017
 
971 1018
 	return $result;
972 1019
 }
@@ -979,8 +1026,9 @@  discard block
 block discarded – undo
979 1026
  */
980 1027
 function ssi_fetchMember($member_ids = array(), $output_method = 'echo')
981 1028
 {
982
-	if (empty($member_ids))
983
-		return;
1029
+	if (empty($member_ids)) {
1030
+			return;
1031
+	}
984 1032
 
985 1033
 	// Can have more than one member if you really want...
986 1034
 	$member_ids = is_array($member_ids) ? $member_ids : array($member_ids);
@@ -1005,8 +1053,9 @@  discard block
 block discarded – undo
1005 1053
  */
1006 1054
 function ssi_fetchGroupMembers($group_id = null, $output_method = 'echo')
1007 1055
 {
1008
-	if ($group_id === null)
1009
-		return;
1056
+	if ($group_id === null) {
1057
+			return;
1058
+	}
1010 1059
 
1011 1060
 	$query_where = '
1012 1061
 		id_group = {int:id_group}
@@ -1033,8 +1082,9 @@  discard block
 block discarded – undo
1033 1082
 {
1034 1083
 	global $smcFunc, $memberContext;
1035 1084
 
1036
-	if ($query_where === null)
1037
-		return;
1085
+	if ($query_where === null) {
1086
+			return;
1087
+	}
1038 1088
 
1039 1089
 	// Fetch the members in question.
1040 1090
 	$request = $smcFunc['db_query']('', '
@@ -1047,12 +1097,14 @@  discard block
 block discarded – undo
1047 1097
 		))
1048 1098
 	);
1049 1099
 	$members = array();
1050
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1051
-		$members[] = $row['id_member'];
1100
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
1101
+			$members[] = $row['id_member'];
1102
+	}
1052 1103
 	$smcFunc['db_free_result']($request);
1053 1104
 
1054
-	if (empty($members))
1055
-		return array();
1105
+	if (empty($members)) {
1106
+			return array();
1107
+	}
1056 1108
 
1057 1109
 	// If mods want to do somthing with this list of members, let them do that now.
1058 1110
 	call_integration_hook('integrate_ssi_queryMembers', array(&$members));
@@ -1061,23 +1113,25 @@  discard block
 block discarded – undo
1061 1113
 	loadMemberData($members);
1062 1114
 
1063 1115
 	// Draw the table!
1064
-	if ($output_method == 'echo')
1065
-		echo '
1116
+	if ($output_method == 'echo') {
1117
+			echo '
1066 1118
 		<table style="border: none" class="ssi_table">';
1119
+	}
1067 1120
 
1068 1121
 	$query_members = array();
1069 1122
 	foreach ($members as $member)
1070 1123
 	{
1071 1124
 		// Load their context data.
1072
-		if (!loadMemberContext($member))
1073
-			continue;
1125
+		if (!loadMemberContext($member)) {
1126
+					continue;
1127
+		}
1074 1128
 
1075 1129
 		// Store this member's information.
1076 1130
 		$query_members[$member] = $memberContext[$member];
1077 1131
 
1078 1132
 		// Only do something if we're echo'ing.
1079
-		if ($output_method == 'echo')
1080
-			echo '
1133
+		if ($output_method == 'echo') {
1134
+					echo '
1081 1135
 			<tr>
1082 1136
 				<td style="text-align: right; vertical-align: top; white-space: nowrap">
1083 1137
 					', $query_members[$member]['link'], '
@@ -1085,12 +1139,14 @@  discard block
 block discarded – undo
1085 1139
 					<br>', $query_members[$member]['avatar']['image'], '
1086 1140
 				</td>
1087 1141
 			</tr>';
1142
+		}
1088 1143
 	}
1089 1144
 
1090 1145
 	// End the table if appropriate.
1091
-	if ($output_method == 'echo')
1092
-		echo '
1146
+	if ($output_method == 'echo') {
1147
+			echo '
1093 1148
 		</table>';
1149
+	}
1094 1150
 
1095 1151
 	// Send back the data.
1096 1152
 	return $query_members;
@@ -1105,8 +1161,9 @@  discard block
 block discarded – undo
1105 1161
 {
1106 1162
 	global $txt, $scripturl, $modSettings, $smcFunc;
1107 1163
 
1108
-	if (!allowedTo('view_stats'))
1109
-		return;
1164
+	if (!allowedTo('view_stats')) {
1165
+			return;
1166
+	}
1110 1167
 
1111 1168
 	$totals = array(
1112 1169
 		'members' => $modSettings['totalMembers'],
@@ -1135,8 +1192,9 @@  discard block
 block discarded – undo
1135 1192
 	// If mods want to do somthing with the board stats, let them do that now.
1136 1193
 	call_integration_hook('integrate_ssi_boardStats', array(&$totals));
1137 1194
 
1138
-	if ($output_method != 'echo')
1139
-		return $totals;
1195
+	if ($output_method != 'echo') {
1196
+			return $totals;
1197
+	}
1140 1198
 
1141 1199
 	echo '
1142 1200
 		', $txt['total_members'], ': <a href="', $scripturl . '?action=mlist">', comma_format($totals['members']), '</a><br>
@@ -1165,8 +1223,8 @@  discard block
 block discarded – undo
1165 1223
 	call_integration_hook('integrate_ssi_whosOnline', array(&$return));
1166 1224
 
1167 1225
 	// Add some redundancy for backwards compatibility reasons.
1168
-	if ($output_method != 'echo')
1169
-		return $return + array(
1226
+	if ($output_method != 'echo') {
1227
+			return $return + array(
1170 1228
 			'users' => $return['users_online'],
1171 1229
 			'guests' => $return['num_guests'],
1172 1230
 			'hidden' => $return['num_users_hidden'],
@@ -1174,29 +1232,35 @@  discard block
 block discarded – undo
1174 1232
 			'num_users' => $return['num_users_online'],
1175 1233
 			'total_users' => $return['num_users_online'] + $return['num_guests'],
1176 1234
 		);
1235
+	}
1177 1236
 
1178 1237
 	echo '
1179 1238
 		', comma_format($return['num_guests']), ' ', $return['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', comma_format($return['num_users_online']), ' ', $return['num_users_online'] == 1 ? $txt['user'] : $txt['users'];
1180 1239
 
1181 1240
 	$bracketList = array();
1182
-	if (!empty($user_info['buddies']))
1183
-		$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1184
-	if (!empty($return['num_spiders']))
1185
-		$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1186
-	if (!empty($return['num_users_hidden']))
1187
-		$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1241
+	if (!empty($user_info['buddies'])) {
1242
+			$bracketList[] = comma_format($return['num_buddies']) . ' ' . ($return['num_buddies'] == 1 ? $txt['buddy'] : $txt['buddies']);
1243
+	}
1244
+	if (!empty($return['num_spiders'])) {
1245
+			$bracketList[] = comma_format($return['num_spiders']) . ' ' . ($return['num_spiders'] == 1 ? $txt['spider'] : $txt['spiders']);
1246
+	}
1247
+	if (!empty($return['num_users_hidden'])) {
1248
+			$bracketList[] = comma_format($return['num_users_hidden']) . ' ' . $txt['hidden'];
1249
+	}
1188 1250
 
1189
-	if (!empty($bracketList))
1190
-		echo ' (' . implode(', ', $bracketList) . ')';
1251
+	if (!empty($bracketList)) {
1252
+			echo ' (' . implode(', ', $bracketList) . ')';
1253
+	}
1191 1254
 
1192 1255
 	echo '<br>
1193 1256
 			', implode(', ', $return['list_users_online']);
1194 1257
 
1195 1258
 	// Showing membergroups?
1196
-	if (!empty($settings['show_group_key']) && !empty($return['membergroups']))
1197
-		echo '<br>
1259
+	if (!empty($settings['show_group_key']) && !empty($return['membergroups'])) {
1260
+			echo '<br>
1198 1261
 			[' . implode(']&nbsp;&nbsp;[', $return['membergroups']) . ']';
1199
-}
1262
+	}
1263
+	}
1200 1264
 
1201 1265
 /**
1202 1266
  * Just like whosOnline except it also logs the online presence.
@@ -1207,11 +1271,12 @@  discard block
 block discarded – undo
1207 1271
 {
1208 1272
 	writeLog();
1209 1273
 
1210
-	if ($output_method != 'echo')
1211
-		return ssi_whosOnline($output_method);
1212
-	else
1213
-		ssi_whosOnline($output_method);
1214
-}
1274
+	if ($output_method != 'echo') {
1275
+			return ssi_whosOnline($output_method);
1276
+	} else {
1277
+			ssi_whosOnline($output_method);
1278
+	}
1279
+	}
1215 1280
 
1216 1281
 // Shows a login box.
1217 1282
 /**
@@ -1224,11 +1289,13 @@  discard block
 block discarded – undo
1224 1289
 {
1225 1290
 	global $scripturl, $txt, $user_info, $context;
1226 1291
 
1227
-	if ($redirect_to != '')
1228
-		$_SESSION['login_url'] = $redirect_to;
1292
+	if ($redirect_to != '') {
1293
+			$_SESSION['login_url'] = $redirect_to;
1294
+	}
1229 1295
 
1230
-	if ($output_method != 'echo' || !$user_info['is_guest'])
1231
-		return $user_info['is_guest'];
1296
+	if ($output_method != 'echo' || !$user_info['is_guest']) {
1297
+			return $user_info['is_guest'];
1298
+	}
1232 1299
 
1233 1300
 	// Create a login token
1234 1301
 	createToken('login');
@@ -1280,8 +1347,9 @@  discard block
 block discarded – undo
1280 1347
 
1281 1348
 	$boardsAllowed = array_intersect(boardsAllowedTo('poll_view'), boardsAllowedTo('poll_vote'));
1282 1349
 
1283
-	if (empty($boardsAllowed))
1284
-		return array();
1350
+	if (empty($boardsAllowed)) {
1351
+			return array();
1352
+	}
1285 1353
 
1286 1354
 	$request = $smcFunc['db_query']('', '
1287 1355
 		SELECT p.id_poll, p.question, t.id_topic, p.max_votes, p.guest_vote, p.hide_results, p.expire_time
@@ -1314,12 +1382,14 @@  discard block
 block discarded – undo
1314 1382
 	$smcFunc['db_free_result']($request);
1315 1383
 
1316 1384
 	// This user has voted on all the polls.
1317
-	if (empty($row) || !is_array($row))
1318
-		return array();
1385
+	if (empty($row) || !is_array($row)) {
1386
+			return array();
1387
+	}
1319 1388
 
1320 1389
 	// If this is a guest who's voted we'll through ourselves to show poll to show the results.
1321
-	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))))
1322
-		return ssi_showPoll($row['id_topic'], $output_method);
1390
+	if ($user_info['is_guest'] && (!$row['guest_vote'] || (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))))) {
1391
+			return ssi_showPoll($row['id_topic'], $output_method);
1392
+	}
1323 1393
 
1324 1394
 	$request = $smcFunc['db_query']('', '
1325 1395
 		SELECT COUNT(DISTINCT id_member)
@@ -1383,8 +1453,9 @@  discard block
 block discarded – undo
1383 1453
 	// If mods want to do somthing with this list of polls, let them do that now.
1384 1454
 	call_integration_hook('integrate_ssi_recentPoll', array(&$return, $topPollInstead));
1385 1455
 
1386
-	if ($output_method != 'echo')
1387
-		return $return;
1456
+	if ($output_method != 'echo') {
1457
+			return $return;
1458
+	}
1388 1459
 
1389 1460
 	if ($allow_view_results)
1390 1461
 	{
@@ -1393,19 +1464,20 @@  discard block
 block discarded – undo
1393 1464
 			<strong>', $return['question'], '</strong><br>
1394 1465
 			', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1395 1466
 
1396
-		foreach ($return['options'] as $option)
1397
-			echo '
1467
+		foreach ($return['options'] as $option) {
1468
+					echo '
1398 1469
 			<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1470
+		}
1399 1471
 
1400 1472
 		echo '
1401 1473
 			<input type="submit" value="', $txt['poll_vote'], '" class="button">
1402 1474
 			<input type="hidden" name="poll" value="', $return['id'], '">
1403 1475
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1404 1476
 		</form>';
1477
+	} else {
1478
+			echo $txt['poll_cannot_see'];
1479
+	}
1405 1480
 	}
1406
-	else
1407
-		echo $txt['poll_cannot_see'];
1408
-}
1409 1481
 
1410 1482
 /**
1411 1483
  * Shows the poll from the specified topic
@@ -1419,13 +1491,15 @@  discard block
 block discarded – undo
1419 1491
 
1420 1492
 	$boardsAllowed = boardsAllowedTo('poll_view');
1421 1493
 
1422
-	if (empty($boardsAllowed))
1423
-		return array();
1494
+	if (empty($boardsAllowed)) {
1495
+			return array();
1496
+	}
1424 1497
 
1425
-	if ($topic === null && isset($_REQUEST['ssi_topic']))
1426
-		$topic = (int) $_REQUEST['ssi_topic'];
1427
-	else
1428
-		$topic = (int) $topic;
1498
+	if ($topic === null && isset($_REQUEST['ssi_topic'])) {
1499
+			$topic = (int) $_REQUEST['ssi_topic'];
1500
+	} else {
1501
+			$topic = (int) $topic;
1502
+	}
1429 1503
 
1430 1504
 	$request = $smcFunc['db_query']('', '
1431 1505
 		SELECT
@@ -1446,17 +1520,18 @@  discard block
 block discarded – undo
1446 1520
 	);
1447 1521
 
1448 1522
 	// Either this topic has no poll, or the user cannot view it.
1449
-	if ($smcFunc['db_num_rows']($request) == 0)
1450
-		return array();
1523
+	if ($smcFunc['db_num_rows']($request) == 0) {
1524
+			return array();
1525
+	}
1451 1526
 
1452 1527
 	$row = $smcFunc['db_fetch_assoc']($request);
1453 1528
 	$smcFunc['db_free_result']($request);
1454 1529
 
1455 1530
 	// Check if they can vote.
1456 1531
 	$already_voted = false;
1457
-	if (!empty($row['expire_time']) && $row['expire_time'] < time())
1458
-		$allow_vote = false;
1459
-	elseif ($user_info['is_guest'])
1532
+	if (!empty($row['expire_time']) && $row['expire_time'] < time()) {
1533
+			$allow_vote = false;
1534
+	} elseif ($user_info['is_guest'])
1460 1535
 	{
1461 1536
 		// There's a difference between "allowed to vote" and "already voted"...
1462 1537
 		$allow_vote = $row['guest_vote'];
@@ -1466,10 +1541,9 @@  discard block
 block discarded – undo
1466 1541
 		{
1467 1542
 			$already_voted = true;
1468 1543
 		}
1469
-	}
1470
-	elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board']))
1471
-		$allow_vote = false;
1472
-	else
1544
+	} elseif (!empty($row['voting_locked']) || !allowedTo('poll_vote', $row['id_board'])) {
1545
+			$allow_vote = false;
1546
+	} else
1473 1547
 	{
1474 1548
 		$request = $smcFunc['db_query']('', '
1475 1549
 			SELECT id_member
@@ -1551,8 +1625,9 @@  discard block
 block discarded – undo
1551 1625
 	// If mods want to do somthing with this poll, let them do that now.
1552 1626
 	call_integration_hook('integrate_ssi_showPoll', array(&$return));
1553 1627
 
1554
-	if ($output_method != 'echo')
1555
-		return $return;
1628
+	if ($output_method != 'echo') {
1629
+			return $return;
1630
+	}
1556 1631
 
1557 1632
 	if ($return['allow_vote'])
1558 1633
 	{
@@ -1561,17 +1636,17 @@  discard block
 block discarded – undo
1561 1636
 				<strong>', $return['question'], '</strong><br>
1562 1637
 				', !empty($return['allowed_warning']) ? $return['allowed_warning'] . '<br>' : '';
1563 1638
 
1564
-		foreach ($return['options'] as $option)
1565
-			echo '
1639
+		foreach ($return['options'] as $option) {
1640
+					echo '
1566 1641
 				<label for="', $option['id'], '">', $option['vote_button'], ' ', $option['option'], '</label><br>';
1642
+		}
1567 1643
 
1568 1644
 		echo '
1569 1645
 				<input type="submit" value="', $txt['poll_vote'], '" class="button">
1570 1646
 				<input type="hidden" name="poll" value="', $return['id'], '">
1571 1647
 				<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
1572 1648
 			</form>';
1573
-	}
1574
-	else
1649
+	} else
1575 1650
 	{
1576 1651
 		echo '
1577 1652
 			<div class="ssi_poll">
@@ -1651,27 +1726,32 @@  discard block
 block discarded – undo
1651 1726
 			'is_approved' => 1,
1652 1727
 		)
1653 1728
 	);
1654
-	if ($smcFunc['db_num_rows']($request) == 0)
1655
-		die;
1729
+	if ($smcFunc['db_num_rows']($request) == 0) {
1730
+			die;
1731
+	}
1656 1732
 	$row = $smcFunc['db_fetch_assoc']($request);
1657 1733
 	$smcFunc['db_free_result']($request);
1658 1734
 
1659
-	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time']))
1660
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1735
+	if (!empty($row['voting_locked']) || ($row['selected'] != -1 && !$user_info['is_guest']) || (!empty($row['expire_time']) && time() > $row['expire_time'])) {
1736
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1737
+	}
1661 1738
 
1662 1739
 	// Too many options checked?
1663
-	if (count($_REQUEST['options']) > $row['max_votes'])
1664
-		redirectexit('topic=' . $row['id_topic'] . '.0');
1740
+	if (count($_REQUEST['options']) > $row['max_votes']) {
1741
+			redirectexit('topic=' . $row['id_topic'] . '.0');
1742
+	}
1665 1743
 
1666 1744
 	// It's a guest who has already voted?
1667 1745
 	if ($user_info['is_guest'])
1668 1746
 	{
1669 1747
 		// Guest voting disabled?
1670
-		if (!$row['guest_vote'])
1671
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1748
+		if (!$row['guest_vote']) {
1749
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1750
+		}
1672 1751
 		// Already voted?
1673
-		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote'])))
1674
-			redirectexit('topic=' . $row['id_topic'] . '.0');
1752
+		elseif (isset($_COOKIE['guest_poll_vote']) && in_array($row['id_poll'], explode(',', $_COOKIE['guest_poll_vote']))) {
1753
+					redirectexit('topic=' . $row['id_topic'] . '.0');
1754
+		}
1675 1755
 	}
1676 1756
 
1677 1757
 	$sOptions = array();
@@ -1725,11 +1805,13 @@  discard block
 block discarded – undo
1725 1805
 {
1726 1806
 	global $scripturl, $txt, $context;
1727 1807
 
1728
-	if (!allowedTo('search_posts'))
1729
-		return;
1808
+	if (!allowedTo('search_posts')) {
1809
+			return;
1810
+	}
1730 1811
 
1731
-	if ($output_method != 'echo')
1732
-		return $scripturl . '?action=search';
1812
+	if ($output_method != 'echo') {
1813
+			return $scripturl . '?action=search';
1814
+	}
1733 1815
 
1734 1816
 	echo '
1735 1817
 		<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
@@ -1751,8 +1833,9 @@  discard block
 block discarded – undo
1751 1833
 	// If mods want to do somthing with the news, let them do that now. Don't need to pass the news line itself, since it is already in $context.
1752 1834
 	call_integration_hook('integrate_ssi_news');
1753 1835
 
1754
-	if ($output_method != 'echo')
1755
-		return $context['random_news_line'];
1836
+	if ($output_method != 'echo') {
1837
+			return $context['random_news_line'];
1838
+	}
1756 1839
 
1757 1840
 	echo $context['random_news_line'];
1758 1841
 }
@@ -1766,8 +1849,9 @@  discard block
 block discarded – undo
1766 1849
 {
1767 1850
 	global $scripturl, $modSettings, $user_info;
1768 1851
 
1769
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view'))
1770
-		return;
1852
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view') || !allowedTo('profile_view')) {
1853
+			return;
1854
+	}
1771 1855
 
1772 1856
 	$eventOptions = array(
1773 1857
 		'include_birthdays' => true,
@@ -1778,13 +1862,15 @@  discard block
 block discarded – undo
1778 1862
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1779 1863
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1780 1864
 
1781
-	if ($output_method != 'echo')
1782
-		return $return['calendar_birthdays'];
1865
+	if ($output_method != 'echo') {
1866
+			return $return['calendar_birthdays'];
1867
+	}
1783 1868
 
1784
-	foreach ($return['calendar_birthdays'] as $member)
1785
-		echo '
1869
+	foreach ($return['calendar_birthdays'] as $member) {
1870
+			echo '
1786 1871
 			<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">' . $member['name'] . '</span>' . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>' . (!$member['is_last'] ? ', ' : '');
1787
-}
1872
+	}
1873
+	}
1788 1874
 
1789 1875
 /**
1790 1876
  * Shows today's holidays.
@@ -1795,8 +1881,9 @@  discard block
 block discarded – undo
1795 1881
 {
1796 1882
 	global $modSettings, $user_info;
1797 1883
 
1798
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1799
-		return;
1884
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1885
+			return;
1886
+	}
1800 1887
 
1801 1888
 	$eventOptions = array(
1802 1889
 		'include_holidays' => true,
@@ -1807,8 +1894,9 @@  discard block
 block discarded – undo
1807 1894
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1808 1895
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1809 1896
 
1810
-	if ($output_method != 'echo')
1811
-		return $return['calendar_holidays'];
1897
+	if ($output_method != 'echo') {
1898
+			return $return['calendar_holidays'];
1899
+	}
1812 1900
 
1813 1901
 	echo '
1814 1902
 		', implode(', ', $return['calendar_holidays']);
@@ -1822,8 +1910,9 @@  discard block
 block discarded – undo
1822 1910
 {
1823 1911
 	global $modSettings, $user_info;
1824 1912
 
1825
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1826
-		return;
1913
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1914
+			return;
1915
+	}
1827 1916
 
1828 1917
 	$eventOptions = array(
1829 1918
 		'include_events' => true,
@@ -1834,14 +1923,16 @@  discard block
 block discarded – undo
1834 1923
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1835 1924
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1836 1925
 
1837
-	if ($output_method != 'echo')
1838
-		return $return['calendar_events'];
1926
+	if ($output_method != 'echo') {
1927
+			return $return['calendar_events'];
1928
+	}
1839 1929
 
1840 1930
 	foreach ($return['calendar_events'] as $event)
1841 1931
 	{
1842
-		if ($event['can_edit'])
1843
-			echo '
1932
+		if ($event['can_edit']) {
1933
+					echo '
1844 1934
 	<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1935
+		}
1845 1936
 		echo '
1846 1937
 	' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1847 1938
 	}
@@ -1856,8 +1947,9 @@  discard block
 block discarded – undo
1856 1947
 {
1857 1948
 	global $modSettings, $txt, $scripturl, $user_info;
1858 1949
 
1859
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
1860
-		return;
1950
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
1951
+			return;
1952
+	}
1861 1953
 
1862 1954
 	$eventOptions = array(
1863 1955
 		'include_birthdays' => allowedTo('profile_view'),
@@ -1870,19 +1962,22 @@  discard block
 block discarded – undo
1870 1962
 	// The ssi_todaysCalendar variants all use the same hook and just pass on $eventOptions so the hooked code can distinguish different cases if necessary
1871 1963
 	call_integration_hook('integrate_ssi_calendar', array(&$return, $eventOptions));
1872 1964
 
1873
-	if ($output_method != 'echo')
1874
-		return $return;
1965
+	if ($output_method != 'echo') {
1966
+			return $return;
1967
+	}
1875 1968
 
1876
-	if (!empty($return['calendar_holidays']))
1877
-		echo '
1969
+	if (!empty($return['calendar_holidays'])) {
1970
+			echo '
1878 1971
 			<span class="holiday">' . $txt['calendar_prompt'] . ' ' . implode(', ', $return['calendar_holidays']) . '<br></span>';
1972
+	}
1879 1973
 	if (!empty($return['calendar_birthdays']))
1880 1974
 	{
1881 1975
 		echo '
1882 1976
 			<span class="birthday">' . $txt['birthdays_upcoming'] . '</span> ';
1883
-		foreach ($return['calendar_birthdays'] as $member)
1884
-			echo '
1977
+		foreach ($return['calendar_birthdays'] as $member) {
1978
+					echo '
1885 1979
 			<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', !$member['is_last'] ? ', ' : '';
1980
+		}
1886 1981
 		echo '
1887 1982
 			<br>';
1888 1983
 	}
@@ -1892,9 +1987,10 @@  discard block
 block discarded – undo
1892 1987
 			<span class="event">' . $txt['events_upcoming'] . '</span> ';
1893 1988
 		foreach ($return['calendar_events'] as $event)
1894 1989
 		{
1895
-			if ($event['can_edit'])
1896
-				echo '
1990
+			if ($event['can_edit']) {
1991
+							echo '
1897 1992
 			<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
1993
+			}
1898 1994
 			echo '
1899 1995
 			' . $event['link'] . (!$event['is_last'] ? ', ' : '');
1900 1996
 		}
@@ -1918,25 +2014,29 @@  discard block
 block discarded – undo
1918 2014
 	loadLanguage('Stats');
1919 2015
 
1920 2016
 	// Must be integers....
1921
-	if ($limit === null)
1922
-		$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
1923
-	else
1924
-		$limit = (int) $limit;
1925
-
1926
-	if ($start === null)
1927
-		$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
1928
-	else
1929
-		$start = (int) $start;
1930
-
1931
-	if ($board !== null)
1932
-		$board = (int) $board;
1933
-	elseif (isset($_GET['board']))
1934
-		$board = (int) $_GET['board'];
1935
-
1936
-	if ($length === null)
1937
-		$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
1938
-	else
1939
-		$length = (int) $length;
2017
+	if ($limit === null) {
2018
+			$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
2019
+	} else {
2020
+			$limit = (int) $limit;
2021
+	}
2022
+
2023
+	if ($start === null) {
2024
+			$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
2025
+	} else {
2026
+			$start = (int) $start;
2027
+	}
2028
+
2029
+	if ($board !== null) {
2030
+			$board = (int) $board;
2031
+	} elseif (isset($_GET['board'])) {
2032
+			$board = (int) $_GET['board'];
2033
+	}
2034
+
2035
+	if ($length === null) {
2036
+			$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
2037
+	} else {
2038
+			$length = (int) $length;
2039
+	}
1940 2040
 
1941 2041
 	$limit = max(0, $limit);
1942 2042
 	$start = max(0, $start);
@@ -1954,17 +2054,19 @@  discard block
 block discarded – undo
1954 2054
 	);
1955 2055
 	if ($smcFunc['db_num_rows']($request) == 0)
1956 2056
 	{
1957
-		if ($output_method == 'echo')
1958
-			die($txt['ssi_no_guests']);
1959
-		else
1960
-			return array();
2057
+		if ($output_method == 'echo') {
2058
+					die($txt['ssi_no_guests']);
2059
+		} else {
2060
+					return array();
2061
+		}
1961 2062
 	}
1962 2063
 	list ($board) = $smcFunc['db_fetch_row']($request);
1963 2064
 	$smcFunc['db_free_result']($request);
1964 2065
 
1965 2066
 	$icon_sources = array();
1966
-	foreach ($context['stable_icons'] as $icon)
1967
-		$icon_sources[$icon] = 'images_url';
2067
+	foreach ($context['stable_icons'] as $icon) {
2068
+			$icon_sources[$icon] = 'images_url';
2069
+	}
1968 2070
 
1969 2071
 	if (!empty($modSettings['enable_likes']))
1970 2072
 	{
@@ -1987,12 +2089,14 @@  discard block
 block discarded – undo
1987 2089
 		)
1988 2090
 	);
1989 2091
 	$posts = array();
1990
-	while ($row = $smcFunc['db_fetch_assoc']($request))
1991
-		$posts[] = $row['id_first_msg'];
2092
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2093
+			$posts[] = $row['id_first_msg'];
2094
+	}
1992 2095
 	$smcFunc['db_free_result']($request);
1993 2096
 
1994
-	if (empty($posts))
1995
-		return array();
2097
+	if (empty($posts)) {
2098
+			return array();
2099
+	}
1996 2100
 
1997 2101
 	// Find the posts.
1998 2102
 	$request = $smcFunc['db_query']('', '
@@ -2022,26 +2126,30 @@  discard block
 block discarded – undo
2022 2126
 			$last_space = strrpos($row['body'], ' ');
2023 2127
 			$last_open = strrpos($row['body'], '<');
2024 2128
 			$last_close = strrpos($row['body'], '>');
2025
-			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6)
2026
-				$cutoff = $last_open;
2027
-			elseif (empty($last_close) || $last_close < $last_open)
2028
-				$cutoff = $last_space;
2129
+			if (empty($last_space) || ($last_space == $last_open + 3 && (empty($last_close) || (!empty($last_close) && $last_close < $last_open))) || $last_space < $last_open || $last_open == $length - 6) {
2130
+							$cutoff = $last_open;
2131
+			} elseif (empty($last_close) || $last_close < $last_open) {
2132
+							$cutoff = $last_space;
2133
+			}
2029 2134
 
2030
-			if ($cutoff !== false)
2031
-				$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2135
+			if ($cutoff !== false) {
2136
+							$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
2137
+			}
2032 2138
 			$row['body'] .= '...';
2033 2139
 		}
2034 2140
 
2035 2141
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
2036 2142
 
2037
-		if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
2038
-			$row['icon'] = 'recycled';
2143
+		if (!empty($recycle_board) && $row['id_board'] == $recycle_board) {
2144
+					$row['icon'] = 'recycled';
2145
+		}
2039 2146
 
2040 2147
 		// Check that this message icon is there...
2041
-		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
2042
-			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2043
-		elseif (!isset($icon_sources[$row['icon']]))
2044
-			$icon_sources[$row['icon']] = 'images_url';
2148
+		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']])) {
2149
+					$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
2150
+		} elseif (!isset($icon_sources[$row['icon']])) {
2151
+					$icon_sources[$row['icon']] = 'images_url';
2152
+		}
2045 2153
 
2046 2154
 		censorText($row['subject']);
2047 2155
 		censorText($row['body']);
@@ -2078,16 +2186,18 @@  discard block
 block discarded – undo
2078 2186
 	}
2079 2187
 	$smcFunc['db_free_result']($request);
2080 2188
 
2081
-	if (empty($return))
2082
-		return $return;
2189
+	if (empty($return)) {
2190
+			return $return;
2191
+	}
2083 2192
 
2084 2193
 	$return[count($return) - 1]['is_last'] = true;
2085 2194
 
2086 2195
 	// If mods want to do somthing with this list of posts, let them do that now.
2087 2196
 	call_integration_hook('integrate_ssi_boardNews', array(&$return));
2088 2197
 
2089
-	if ($output_method != 'echo')
2090
-		return $return;
2198
+	if ($output_method != 'echo') {
2199
+			return $return;
2200
+	}
2091 2201
 
2092 2202
 	foreach ($return as $news)
2093 2203
 	{
@@ -2139,9 +2249,10 @@  discard block
 block discarded – undo
2139 2249
 		echo '
2140 2250
 			</div>';
2141 2251
 
2142
-		if (!$news['is_last'])
2143
-			echo '
2252
+		if (!$news['is_last']) {
2253
+					echo '
2144 2254
 			<hr>';
2255
+		}
2145 2256
 	}
2146 2257
 }
2147 2258
 
@@ -2155,8 +2266,9 @@  discard block
 block discarded – undo
2155 2266
 {
2156 2267
 	global $user_info, $scripturl, $modSettings, $txt, $context, $smcFunc;
2157 2268
 
2158
-	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view'))
2159
-		return;
2269
+	if (empty($modSettings['cal_enabled']) || !allowedTo('calendar_view')) {
2270
+			return;
2271
+	}
2160 2272
 
2161 2273
 	// Find all events which are happening in the near future that the member can see.
2162 2274
 	$request = $smcFunc['db_query']('', '
@@ -2182,20 +2294,23 @@  discard block
 block discarded – undo
2182 2294
 	while ($row = $smcFunc['db_fetch_assoc']($request))
2183 2295
 	{
2184 2296
 		// Check if we've already come by an event linked to this same topic with the same title... and don't display it if we have.
2185
-		if (!empty($duplicates[$row['title'] . $row['id_topic']]))
2186
-			continue;
2297
+		if (!empty($duplicates[$row['title'] . $row['id_topic']])) {
2298
+					continue;
2299
+		}
2187 2300
 
2188 2301
 		// Censor the title.
2189 2302
 		censorText($row['title']);
2190 2303
 
2191
-		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false)))
2192
-			$date = strftime('%Y-%m-%d', forum_time(false));
2193
-		else
2194
-			$date = $row['start_date'];
2304
+		if ($row['start_date'] < strftime('%Y-%m-%d', forum_time(false))) {
2305
+					$date = strftime('%Y-%m-%d', forum_time(false));
2306
+		} else {
2307
+					$date = $row['start_date'];
2308
+		}
2195 2309
 
2196 2310
 		// If the topic it is attached to is not approved then don't link it.
2197
-		if (!empty($row['id_first_msg']) && !$row['approved'])
2198
-			$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2311
+		if (!empty($row['id_first_msg']) && !$row['approved']) {
2312
+					$row['id_board'] = $row['id_topic'] = $row['id_first_msg'] = 0;
2313
+		}
2199 2314
 
2200 2315
 		$allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false;
2201 2316
 
@@ -2221,24 +2336,27 @@  discard block
 block discarded – undo
2221 2336
 	}
2222 2337
 	$smcFunc['db_free_result']($request);
2223 2338
 
2224
-	foreach ($return as $mday => $array)
2225
-		$return[$mday][count($array) - 1]['is_last'] = true;
2339
+	foreach ($return as $mday => $array) {
2340
+			$return[$mday][count($array) - 1]['is_last'] = true;
2341
+	}
2226 2342
 
2227 2343
 	// If mods want to do somthing with this list of events, let them do that now.
2228 2344
 	call_integration_hook('integrate_ssi_recentEvents', array(&$return));
2229 2345
 
2230
-	if ($output_method != 'echo' || empty($return))
2231
-		return $return;
2346
+	if ($output_method != 'echo' || empty($return)) {
2347
+			return $return;
2348
+	}
2232 2349
 
2233 2350
 	// Well the output method is echo.
2234 2351
 	echo '
2235 2352
 			<span class="event">' . $txt['events'] . '</span> ';
2236
-	foreach ($return as $mday => $array)
2237
-		foreach ($array as $event)
2353
+	foreach ($return as $mday => $array) {
2354
+			foreach ($array as $event)
2238 2355
 		{
2239 2356
 			if ($event['can_edit'])
2240 2357
 				echo '
2241 2358
 				<a href="' . $event['modify_href'] . '" style="color: #ff0000;">*</a> ';
2359
+	}
2242 2360
 
2243 2361
 			echo '
2244 2362
 				' . $event['link'] . (!$event['is_last'] ? ', ' : '');
@@ -2257,8 +2375,9 @@  discard block
 block discarded – undo
2257 2375
 	global $smcFunc;
2258 2376
 
2259 2377
 	// If $id is null, this was most likely called from a query string and should do nothing.
2260
-	if ($id === null)
2261
-		return;
2378
+	if ($id === null) {
2379
+			return;
2380
+	}
2262 2381
 
2263 2382
 	$request = $smcFunc['db_query']('', '
2264 2383
 		SELECT passwd, member_name, is_activated
@@ -2290,8 +2409,9 @@  discard block
 block discarded – undo
2290 2409
 	$attachments_boards = boardsAllowedTo('view_attachments');
2291 2410
 
2292 2411
 	// No boards?  Adios amigo.
2293
-	if (empty($attachments_boards))
2294
-		return array();
2412
+	if (empty($attachments_boards)) {
2413
+			return array();
2414
+	}
2295 2415
 
2296 2416
 	// Is it an array?
2297 2417
 	$attachment_ext = (array) $attachment_ext;
@@ -2375,8 +2495,9 @@  discard block
 block discarded – undo
2375 2495
 	call_integration_hook('integrate_ssi_recentAttachments', array(&$attachments));
2376 2496
 
2377 2497
 	// So you just want an array?  Here you can have it.
2378
-	if ($output_method == 'array' || empty($attachments))
2379
-		return $attachments;
2498
+	if ($output_method == 'array' || empty($attachments)) {
2499
+			return $attachments;
2500
+	}
2380 2501
 
2381 2502
 	// Give them the default.
2382 2503
 	echo '
@@ -2387,14 +2508,15 @@  discard block
 block discarded – undo
2387 2508
 				<th style="text-align: left; padding: 2">', $txt['downloads'], '</th>
2388 2509
 				<th style="text-align: left; padding: 2">', $txt['filesize'], '</th>
2389 2510
 			</tr>';
2390
-	foreach ($attachments as $attach)
2391
-		echo '
2511
+	foreach ($attachments as $attach) {
2512
+			echo '
2392 2513
 			<tr>
2393 2514
 				<td>', $attach['file']['link'], '</td>
2394 2515
 				<td>', $attach['member']['link'], '</td>
2395 2516
 				<td style="text-align: center">', $attach['file']['downloads'], '</td>
2396 2517
 				<td>', $attach['file']['filesize'], '</td>
2397 2518
 			</tr>';
2519
+	}
2398 2520
 	echo '
2399 2521
 		</table>';
2400 2522
 }
Please login to merge, or discard this patch.
Sources/Subs-Compat.php 1 patch
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -177,206 +177,206 @@
 block discarded – undo
177 177
 }
178 178
 
179 179
 if (!is_callable('random_int')) {
180
-    /**
181
-     * Random_* Compatibility Library
182
-     * for using the new PHP 7 random_* API in PHP 5 projects
183
-     *
184
-     * The MIT License (MIT)
185
-     *
186
-     * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
187
-     *
188
-     * Permission is hereby granted, free of charge, to any person obtaining a copy
189
-     * of this software and associated documentation files (the "Software"), to deal
190
-     * in the Software without restriction, including without limitation the rights
191
-     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
192
-     * copies of the Software, and to permit persons to whom the Software is
193
-     * furnished to do so, subject to the following conditions:
194
-     *
195
-     * The above copyright notice and this permission notice shall be included in
196
-     * all copies or substantial portions of the Software.
197
-     *
198
-     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
199
-     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
200
-     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
201
-     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
202
-     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
203
-     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
204
-     * SOFTWARE.
205
-     */
206
-
207
-    /**
208
-     * Fetch a random integer between $min and $max inclusive
209
-     *
210
-     * @param int $min
211
-     * @param int $max
212
-     *
213
-     * @throws Exception
214
-     *
215
-     * @return int
216
-     */
217
-    function random_int($min, $max)
218
-    {
219
-        /**
220
-         * Type and input logic checks
221
-         *
222
-         * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX)
223
-         * (non-inclusive), it will sanely cast it to an int. If you it's equal to
224
-         * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats
225
-         * lose precision, so the <= and => operators might accidentally let a float
226
-         * through.
227
-         */
228
-
229
-        try {
230
-            /** @var int $min */
231
-            $min = RandomCompat_intval($min);
232
-        } catch (TypeError $ex) {
233
-            throw new TypeError(
234
-                'random_int(): $min must be an integer'
235
-            );
236
-        }
237
-
238
-        try {
239
-            /** @var int $max */
240
-            $max = RandomCompat_intval($max);
241
-        } catch (TypeError $ex) {
242
-            throw new TypeError(
243
-                'random_int(): $max must be an integer'
244
-            );
245
-        }
246
-
247
-        /**
248
-         * Now that we've verified our weak typing system has given us an integer,
249
-         * let's validate the logic then we can move forward with generating random
250
-         * integers along a given range.
251
-         */
252
-        if ($min > $max) {
253
-            throw new Error(
254
-                'Minimum value must be less than or equal to the maximum value'
255
-            );
256
-        }
257
-
258
-        if ($max === $min) {
259
-            return (int) $min;
260
-        }
261
-
262
-        /**
263
-         * Initialize variables to 0
264
-         *
265
-         * We want to store:
266
-         * $bytes => the number of random bytes we need
267
-         * $mask => an integer bitmask (for use with the &) operator
268
-         *          so we can minimize the number of discards
269
-         */
270
-        $attempts = $bits = $bytes = $mask = $valueShift = 0;
271
-        /** @var int $attempts */
272
-        /** @var int $bits */
273
-        /** @var int $bytes */
274
-        /** @var int $mask */
275
-        /** @var int $valueShift */
276
-
277
-        /**
278
-         * At this point, $range is a positive number greater than 0. It might
279
-         * overflow, however, if $max - $min > PHP_INT_MAX. PHP will cast it to
280
-         * a float and we will lose some precision.
281
-         *
282
-         * @var int|float $range
283
-         */
284
-        $range = $max - $min;
285
-
286
-        /**
287
-         * Test for integer overflow:
288
-         */
289
-        if (!is_int($range)) {
290
-
291
-            /**
292
-             * Still safely calculate wider ranges.
293
-             * Provided by @CodesInChaos, @oittaa
294
-             *
295
-             * @ref https://gist.github.com/CodesInChaos/03f9ea0b58e8b2b8d435
296
-             *
297
-             * We use ~0 as a mask in this case because it generates all 1s
298
-             *
299
-             * @ref https://eval.in/400356 (32-bit)
300
-             * @ref http://3v4l.org/XX9r5  (64-bit)
301
-             */
302
-            $bytes = PHP_INT_SIZE;
303
-            /** @var int $mask */
304
-            $mask = ~0;
305
-
306
-        } else {
307
-
308
-            /**
309
-             * $bits is effectively ceil(log($range, 2)) without dealing with
310
-             * type juggling
311
-             */
312
-            while ($range > 0) {
313
-                if ($bits % 8 === 0) {
314
-                    ++$bytes;
315
-                }
316
-                ++$bits;
317
-                $range >>= 1;
318
-                /** @var int $mask */
319
-                $mask = $mask << 1 | 1;
320
-            }
321
-            $valueShift = $min;
322
-        }
323
-
324
-        /** @var int $val */
325
-        $val = 0;
326
-        /**
327
-         * Now that we have our parameters set up, let's begin generating
328
-         * random integers until one falls between $min and $max
329
-         */
330
-        /** @psalm-suppress RedundantCondition */
331
-        do {
332
-            /**
333
-             * The rejection probability is at most 0.5, so this corresponds
334
-             * to a failure probability of 2^-128 for a working RNG
335
-             */
336
-            if ($attempts > 128) {
337
-                throw new Exception(
338
-                    'random_int: RNG is broken - too many rejections'
339
-                );
340
-            }
341
-
342
-            /**
343
-             * Let's grab the necessary number of random bytes
344
-             */
345
-            $randomByteString = random_bytes($bytes);
346
-
347
-            /**
348
-             * Let's turn $randomByteString into an integer
349
-             *
350
-             * This uses bitwise operators (<< and |) to build an integer
351
-             * out of the values extracted from ord()
352
-             *
353
-             * Example: [9F] | [6D] | [32] | [0C] =>
354
-             *   159 + 27904 + 3276800 + 201326592 =>
355
-             *   204631455
356
-             */
357
-            $val &= 0;
358
-            for ($i = 0; $i < $bytes; ++$i) {
359
-                $val |= ord($randomByteString[$i]) << ($i * 8);
360
-            }
361
-            /** @var int $val */
362
-
363
-            /**
364
-             * Apply mask
365
-             */
366
-            $val &= $mask;
367
-            $val += $valueShift;
368
-
369
-            ++$attempts;
370
-            /**
371
-             * If $val overflows to a floating point number,
372
-             * ... or is larger than $max,
373
-             * ... or smaller than $min,
374
-             * then try again.
375
-             */
376
-        } while (!is_int($val) || $val > $max || $val < $min);
377
-
378
-        return (int) $val;
379
-    }
180
+	/**
181
+	 * Random_* Compatibility Library
182
+	 * for using the new PHP 7 random_* API in PHP 5 projects
183
+	 *
184
+	 * The MIT License (MIT)
185
+	 *
186
+	 * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises
187
+	 *
188
+	 * Permission is hereby granted, free of charge, to any person obtaining a copy
189
+	 * of this software and associated documentation files (the "Software"), to deal
190
+	 * in the Software without restriction, including without limitation the rights
191
+	 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
192
+	 * copies of the Software, and to permit persons to whom the Software is
193
+	 * furnished to do so, subject to the following conditions:
194
+	 *
195
+	 * The above copyright notice and this permission notice shall be included in
196
+	 * all copies or substantial portions of the Software.
197
+	 *
198
+	 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
199
+	 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
200
+	 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
201
+	 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
202
+	 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
203
+	 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
204
+	 * SOFTWARE.
205
+	 */
206
+
207
+	/**
208
+	 * Fetch a random integer between $min and $max inclusive
209
+	 *
210
+	 * @param int $min
211
+	 * @param int $max
212
+	 *
213
+	 * @throws Exception
214
+	 *
215
+	 * @return int
216
+	 */
217
+	function random_int($min, $max)
218
+	{
219
+		/**
220
+		 * Type and input logic checks
221
+		 *
222
+		 * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX)
223
+		 * (non-inclusive), it will sanely cast it to an int. If you it's equal to
224
+		 * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats
225
+		 * lose precision, so the <= and => operators might accidentally let a float
226
+		 * through.
227
+		 */
228
+
229
+		try {
230
+			/** @var int $min */
231
+			$min = RandomCompat_intval($min);
232
+		} catch (TypeError $ex) {
233
+			throw new TypeError(
234
+				'random_int(): $min must be an integer'
235
+			);
236
+		}
237
+
238
+		try {
239
+			/** @var int $max */
240
+			$max = RandomCompat_intval($max);
241
+		} catch (TypeError $ex) {
242
+			throw new TypeError(
243
+				'random_int(): $max must be an integer'
244
+			);
245
+		}
246
+
247
+		/**
248
+		 * Now that we've verified our weak typing system has given us an integer,
249
+		 * let's validate the logic then we can move forward with generating random
250
+		 * integers along a given range.
251
+		 */
252
+		if ($min > $max) {
253
+			throw new Error(
254
+				'Minimum value must be less than or equal to the maximum value'
255
+			);
256
+		}
257
+
258
+		if ($max === $min) {
259
+			return (int) $min;
260
+		}
261
+
262
+		/**
263
+		 * Initialize variables to 0
264
+		 *
265
+		 * We want to store:
266
+		 * $bytes => the number of random bytes we need
267
+		 * $mask => an integer bitmask (for use with the &) operator
268
+		 *          so we can minimize the number of discards
269
+		 */
270
+		$attempts = $bits = $bytes = $mask = $valueShift = 0;
271
+		/** @var int $attempts */
272
+		/** @var int $bits */
273
+		/** @var int $bytes */
274
+		/** @var int $mask */
275
+		/** @var int $valueShift */
276
+
277
+		/**
278
+		 * At this point, $range is a positive number greater than 0. It might
279
+		 * overflow, however, if $max - $min > PHP_INT_MAX. PHP will cast it to
280
+		 * a float and we will lose some precision.
281
+		 *
282
+		 * @var int|float $range
283
+		 */
284
+		$range = $max - $min;
285
+
286
+		/**
287
+		 * Test for integer overflow:
288
+		 */
289
+		if (!is_int($range)) {
290
+
291
+			/**
292
+			 * Still safely calculate wider ranges.
293
+			 * Provided by @CodesInChaos, @oittaa
294
+			 *
295
+			 * @ref https://gist.github.com/CodesInChaos/03f9ea0b58e8b2b8d435
296
+			 *
297
+			 * We use ~0 as a mask in this case because it generates all 1s
298
+			 *
299
+			 * @ref https://eval.in/400356 (32-bit)
300
+			 * @ref http://3v4l.org/XX9r5  (64-bit)
301
+			 */
302
+			$bytes = PHP_INT_SIZE;
303
+			/** @var int $mask */
304
+			$mask = ~0;
305
+
306
+		} else {
307
+
308
+			/**
309
+			 * $bits is effectively ceil(log($range, 2)) without dealing with
310
+			 * type juggling
311
+			 */
312
+			while ($range > 0) {
313
+				if ($bits % 8 === 0) {
314
+					++$bytes;
315
+				}
316
+				++$bits;
317
+				$range >>= 1;
318
+				/** @var int $mask */
319
+				$mask = $mask << 1 | 1;
320
+			}
321
+			$valueShift = $min;
322
+		}
323
+
324
+		/** @var int $val */
325
+		$val = 0;
326
+		/**
327
+		 * Now that we have our parameters set up, let's begin generating
328
+		 * random integers until one falls between $min and $max
329
+		 */
330
+		/** @psalm-suppress RedundantCondition */
331
+		do {
332
+			/**
333
+			 * The rejection probability is at most 0.5, so this corresponds
334
+			 * to a failure probability of 2^-128 for a working RNG
335
+			 */
336
+			if ($attempts > 128) {
337
+				throw new Exception(
338
+					'random_int: RNG is broken - too many rejections'
339
+				);
340
+			}
341
+
342
+			/**
343
+			 * Let's grab the necessary number of random bytes
344
+			 */
345
+			$randomByteString = random_bytes($bytes);
346
+
347
+			/**
348
+			 * Let's turn $randomByteString into an integer
349
+			 *
350
+			 * This uses bitwise operators (<< and |) to build an integer
351
+			 * out of the values extracted from ord()
352
+			 *
353
+			 * Example: [9F] | [6D] | [32] | [0C] =>
354
+			 *   159 + 27904 + 3276800 + 201326592 =>
355
+			 *   204631455
356
+			 */
357
+			$val &= 0;
358
+			for ($i = 0; $i < $bytes; ++$i) {
359
+				$val |= ord($randomByteString[$i]) << ($i * 8);
360
+			}
361
+			/** @var int $val */
362
+
363
+			/**
364
+			 * Apply mask
365
+			 */
366
+			$val &= $mask;
367
+			$val += $valueShift;
368
+
369
+			++$attempts;
370
+			/**
371
+			 * If $val overflows to a floating point number,
372
+			 * ... or is larger than $max,
373
+			 * ... or smaller than $min,
374
+			 * then try again.
375
+			 */
376
+		} while (!is_int($val) || $val > $max || $val < $min);
377
+
378
+		return (int) $val;
379
+	}
380 380
 }
381 381
 
382 382
 
Please login to merge, or discard this patch.
index.php 1 patch
Braces   +38 added lines, -26 removed lines patch added patch discarded remove patch
@@ -32,16 +32,18 @@  discard block
 block discarded – undo
32 32
 ob_start();
33 33
 
34 34
 // Do some cleaning, just in case.
35
-foreach (array('db_character_set', 'cachedir') as $variable)
35
+foreach (array('db_character_set', 'cachedir') as $variable) {
36 36
 	if (isset($GLOBALS[$variable]))
37 37
 		unset($GLOBALS[$variable], $GLOBALS[$variable]);
38
+}
38 39
 
39 40
 // Load the settings...
40 41
 require_once(dirname(__FILE__) . '/Settings.php');
41 42
 
42 43
 // Make absolutely sure the cache directory is defined.
43
-if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache'))
44
+if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) {
44 45
 	$cachedir = $boarddir . '/cache';
46
+}
45 47
 
46 48
 // Without those we can't go anywhere
47 49
 require_once($sourcedir . '/QueryString.php');
@@ -51,8 +53,9 @@  discard block
 block discarded – undo
51 53
 require_once($sourcedir . '/Load.php');
52 54
 
53 55
 // If $maintenance is set specifically to 2, then we're upgrading or something.
54
-if (!empty($maintenance) && $maintenance == 2)
56
+if (!empty($maintenance) && $maintenance == 2) {
55 57
 	display_maintenance_message();
58
+}
56 59
 
57 60
 // Create a variable to store some SMF specific functions in.
58 61
 $smcFunc = array();
@@ -67,8 +70,9 @@  discard block
 block discarded – undo
67 70
 cleanRequest();
68 71
 
69 72
 // Seed the random generator.
70
-if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69)
73
+if (empty($modSettings['rand_seed']) || random_int(1, 250) == 69) {
71 74
 	smf_seed_generator();
75
+}
72 76
 
73 77
 // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out!
74 78
 if (isset($_GET['scheduled']))
@@ -88,9 +92,9 @@  discard block
 block discarded – undo
88 92
 if (!empty($modSettings['enableCompressedOutput']) && !headers_sent())
89 93
 {
90 94
 	// If zlib is being used, turn off output compression.
91
-	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler')
92
-		$modSettings['enableCompressedOutput'] = '0';
93
-	else
95
+	if (ini_get('zlib.output_compression') >= 1 || ini_get('output_handler') == 'ob_gzhandler') {
96
+			$modSettings['enableCompressedOutput'] = '0';
97
+	} else
94 98
 	{
95 99
 		ob_end_clean();
96 100
 		ob_start('ob_gzhandler');
@@ -182,18 +186,21 @@  discard block
 block discarded – undo
182 186
 	loadPermissions();
183 187
 
184 188
 	// Attachments don't require the entire theme to be loaded.
185
-	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach')
186
-		detectBrowser();
189
+	if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach') {
190
+			detectBrowser();
191
+	}
187 192
 	// Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
188
-	else
189
-		loadTheme();
193
+	else {
194
+			loadTheme();
195
+	}
190 196
 
191 197
 	// Check if the user should be disallowed access.
192 198
 	is_not_banned();
193 199
 
194 200
 	// If we are in a topic and don't have permission to approve it then duck out now.
195
-	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest']))
196
-		fatal_lang_error('not_a_topic', false);
201
+	if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) {
202
+			fatal_lang_error('not_a_topic', false);
203
+	}
197 204
 
198 205
 	$no_stat_actions = array('clock', 'dlattach', 'findmember', 'jsoption', 'likes', 'loadeditorlocale', 'modifycat', 'requestmembers', 'smstats', 'suggest', 'about:unknown', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile');
199 206
 	call_integration_hook('integrate_pre_log_stats', array(&$no_stat_actions));
@@ -204,8 +211,9 @@  discard block
 block discarded – undo
204 211
 		writeLog();
205 212
 
206 213
 		// Track forum statistics and hits...?
207
-		if (!empty($modSettings['hitStats']))
208
-			trackStats(array('hits' => '+'));
214
+		if (!empty($modSettings['hitStats'])) {
215
+					trackStats(array('hits' => '+'));
216
+		}
209 217
 	}
210 218
 	unset($no_stat_actions);
211 219
 
@@ -222,13 +230,14 @@  discard block
 block discarded – undo
222 230
 			return ($_REQUEST['action'] == 'login2' ? 'Login2' : ($_REQUEST['action'] == 'logintfa' ? 'LoginTFA' : 'Logout'));
223 231
 		}
224 232
 		// Don't even try it, sonny.
225
-		else
226
-			return 'InMaintenance';
233
+		else {
234
+					return 'InMaintenance';
235
+		}
227 236
 	}
228 237
 	// If guest access is off, a guest can only do one of the very few following actions.
229
-	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2'))))
230
-		return 'KickGuest';
231
-	elseif (empty($_REQUEST['action']))
238
+	elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'logintfa', 'reminder', 'activate', 'help', 'helpadmin', 'smstats', 'verificationcode', 'signup', 'signup2')))) {
239
+			return 'KickGuest';
240
+	} elseif (empty($_REQUEST['action']))
232 241
 	{
233 242
 		// Action and board are both empty... BoardIndex! Unless someone else wants to do something different.
234 243
 		if (empty($board) && empty($topic))
@@ -242,8 +251,9 @@  discard block
 block discarded – undo
242 251
 
243 252
 				$call = call_helper($defaultAction, true);
244 253
 
245
-				if (!empty($call))
246
-					return $call;
254
+				if (!empty($call)) {
255
+									return $call;
256
+				}
247 257
 			}
248 258
 
249 259
 			// No default action huh? then go to our good old BoardIndex.
@@ -373,8 +383,9 @@  discard block
 block discarded – undo
373 383
 
374 384
 			$call = call_helper($fallbackAction, true);
375 385
 
376
-			if (!empty($call))
377
-				return $call;
386
+			if (!empty($call)) {
387
+							return $call;
388
+			}
378 389
 		}
379 390
 
380 391
 		// No fallback action, huh?
@@ -385,8 +396,9 @@  discard block
 block discarded – undo
385 396
 	}
386 397
 
387 398
 	// Otherwise, it was set - so let's go to that action.
388
-	if (!empty($actionArray[$_REQUEST['action']][0]))
389
-		require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]);
399
+	if (!empty($actionArray[$_REQUEST['action']][0])) {
400
+			require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]);
401
+	}
390 402
 
391 403
 	// Do the right thing.
392 404
 	return call_helper($actionArray[$_REQUEST['action']][1], true);
Please login to merge, or discard this patch.