Completed
Pull Request — release-2.1 (#4016)
by Jeremy
07:23
created
other/install.php 1 patch
Braces   +438 added lines, -326 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 			
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 			
66
-			if ($charcode == 'UTF8')			
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -74,12 +76,14 @@  discard block
 block discarded – undo
74 76
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
75 77
 
76 78
 			// Is it reserved?
77
-			if ($value == 'pg_')
78
-				return $txt['error_db_prefix_reserved'];
79
+			if ($value == 'pg_') {
80
+							return $txt['error_db_prefix_reserved'];
81
+			}
79 82
 
80 83
 			// Is the prefix numeric?
81
-			if (preg_match('~^\d~', $value))
82
-				return $txt['error_db_prefix_numeric'];
84
+			if (preg_match('~^\d~', $value)) {
85
+							return $txt['error_db_prefix_numeric'];
86
+			}
83 87
 
84 88
 			return true;
85 89
 		},
@@ -124,10 +128,11 @@  discard block
 block discarded – undo
124 128
 		$incontext['skip'] = false;
125 129
 
126 130
 		// Call the step and if it returns false that means pause!
127
-		if (function_exists($step[2]) && $step[2]() === false)
128
-			break;
129
-		elseif (function_exists($step[2]))
130
-			$incontext['current_step']++;
131
+		if (function_exists($step[2]) && $step[2]() === false) {
132
+					break;
133
+		} elseif (function_exists($step[2])) {
134
+					$incontext['current_step']++;
135
+		}
131 136
 
132 137
 		// No warnings pass on.
133 138
 		$incontext['warning'] = '';
@@ -143,12 +148,14 @@  discard block
 block discarded – undo
143 148
 	global $databases, $incontext;
144 149
 
145 150
 	// Just so people using older versions of PHP aren't left in the cold.
146
-	if (!isset($_SERVER['PHP_SELF']))
147
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
151
+	if (!isset($_SERVER['PHP_SELF'])) {
152
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
153
+	}
148 154
 
149 155
 	// Turn off magic quotes runtime and enable error reporting.
150
-	if (function_exists('set_magic_quotes_runtime'))
151
-		@set_magic_quotes_runtime(0);
156
+	if (function_exists('set_magic_quotes_runtime')) {
157
+			@set_magic_quotes_runtime(0);
158
+	}
152 159
 	error_reporting(E_ALL);
153 160
 
154 161
 	// Fun.  Low PHP version...
@@ -162,21 +169,23 @@  discard block
 block discarded – undo
162 169
 	{
163 170
 		ob_start();
164 171
 
165
-		if (ini_get('session.save_handler') == 'user')
166
-			@ini_set('session.save_handler', 'files');
167
-		if (function_exists('session_start'))
168
-			@session_start();
169
-	}
170
-	else
172
+		if (ini_get('session.save_handler') == 'user') {
173
+					@ini_set('session.save_handler', 'files');
174
+		}
175
+		if (function_exists('session_start')) {
176
+					@session_start();
177
+		}
178
+	} else
171 179
 	{
172 180
 		ob_start('ob_gzhandler');
173 181
 
174
-		if (ini_get('session.save_handler') == 'user')
175
-			@ini_set('session.save_handler', 'files');
182
+		if (ini_get('session.save_handler') == 'user') {
183
+					@ini_set('session.save_handler', 'files');
184
+		}
176 185
 		session_start();
177 186
 
178
-		if (!headers_sent())
179
-			echo '<!DOCTYPE html>
187
+		if (!headers_sent()) {
188
+					echo '<!DOCTYPE html>
180 189
 <html>
181 190
 	<head>
182 191
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -185,14 +194,16 @@  discard block
 block discarded – undo
185 194
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
186 195
 	</body>
187 196
 </html>';
197
+		}
188 198
 		exit;
189 199
 	}
190 200
 
191 201
 	// Add slashes, as long as they aren't already being added.
192
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
193
-		foreach ($_POST as $k => $v)
202
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
203
+			foreach ($_POST as $k => $v)
194 204
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
195 205
 				$_POST[$k] = addslashes($v);
206
+	}
196 207
 
197 208
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
198 209
 	if (isset($_GET['delete']))
@@ -213,8 +224,7 @@  discard block
 block discarded – undo
213 224
 			$ftp->close();
214 225
 
215 226
 			unset($_SESSION['installer_temp_ftp']);
216
-		}
217
-		else
227
+		} else
218 228
 		{
219 229
 			@unlink(__FILE__);
220 230
 
@@ -235,10 +245,11 @@  discard block
 block discarded – undo
235 245
 	{
236 246
 		// Get PHP's default timezone, if set
237 247
 		$ini_tz = ini_get('date.timezone');
238
-		if (!empty($ini_tz))
239
-			$timezone_id = $ini_tz;
240
-		else
241
-			$timezone_id = '';
248
+		if (!empty($ini_tz)) {
249
+					$timezone_id = $ini_tz;
250
+		} else {
251
+					$timezone_id = '';
252
+		}
242 253
 
243 254
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
244 255
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -268,8 +279,9 @@  discard block
 block discarded – undo
268 279
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
269 280
 		while ($entry = $dir->read())
270 281
 		{
271
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
272
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
282
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
283
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
284
+			}
273 285
 		}
274 286
 		$dir->close();
275 287
 	}
@@ -304,10 +316,11 @@  discard block
 block discarded – undo
304 316
 	}
305 317
 
306 318
 	// Override the language file?
307
-	if (isset($_GET['lang_file']))
308
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
309
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
310
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
319
+	if (isset($_GET['lang_file'])) {
320
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
321
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
322
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
323
+	}
311 324
 
312 325
 	// Make sure it exists, if it doesn't reset it.
313 326
 	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']))
@@ -316,8 +329,9 @@  discard block
 block discarded – undo
316 329
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
317 330
 
318 331
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
319
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
320
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
332
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
333
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
334
+		}
321 335
 	}
322 336
 
323 337
 	// And now include the actual language file itself.
@@ -330,15 +344,18 @@  discard block
 block discarded – undo
330 344
 	global $db_prefix, $db_connection, $sourcedir;
331 345
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
332 346
 
333
-	if (empty($sourcedir))
334
-		$sourcedir = dirname(__FILE__) . '/Sources';
347
+	if (empty($sourcedir)) {
348
+			$sourcedir = dirname(__FILE__) . '/Sources';
349
+	}
335 350
 
336 351
 	// Need this to check whether we need the database password.
337 352
 	require(dirname(__FILE__) . '/Settings.php');
338
-	if (!defined('SMF'))
339
-		define('SMF', 1);
340
-	if (empty($smcFunc))
341
-		$smcFunc = array();
353
+	if (!defined('SMF')) {
354
+			define('SMF', 1);
355
+	}
356
+	if (empty($smcFunc)) {
357
+			$smcFunc = array();
358
+	}
342 359
 
343 360
 	$modSettings['disableQueryCheck'] = true;
344 361
 
@@ -346,8 +363,9 @@  discard block
 block discarded – undo
346 363
 	if (!$db_connection)
347 364
 	{
348 365
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
349
-		if (version_compare(PHP_VERSION, '5', '<'))
350
-			require_once($sourcedir . '/Subs-Compat.php');
366
+		if (version_compare(PHP_VERSION, '5', '<')) {
367
+					require_once($sourcedir . '/Subs-Compat.php');
368
+		}
351 369
 
352 370
 		$db_options = array('persist' => $db_persist);
353 371
 		$port = '';
@@ -358,19 +376,20 @@  discard block
 block discarded – undo
358 376
 			if ($db_type == 'mysql')
359 377
 			{
360 378
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
361
-			}
362
-			elseif ($db_type == 'postgresql')
379
+			} elseif ($db_type == 'postgresql')
363 380
 			{
364 381
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
365 382
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
366 383
 			}
367 384
 		}
368 385
 
369
-		if (!empty($port))
370
-			$db_options['port'] = $port;
386
+		if (!empty($port)) {
387
+					$db_options['port'] = $port;
388
+		}
371 389
 
372
-		if (!$db_connection)
373
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
390
+		if (!$db_connection) {
391
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
392
+		}
374 393
 	}
375 394
 }
376 395
 
@@ -398,8 +417,9 @@  discard block
 block discarded – undo
398 417
 		// @todo REMOVE THIS!!
399 418
 		else
400 419
 		{
401
-			if (function_exists('doStep' . $_GET['step']))
402
-				call_user_func('doStep' . $_GET['step']);
420
+			if (function_exists('doStep' . $_GET['step'])) {
421
+							call_user_func('doStep' . $_GET['step']);
422
+			}
403 423
 		}
404 424
 		// Show the footer.
405 425
 		template_install_below();
@@ -417,8 +437,9 @@  discard block
 block discarded – undo
417 437
 	$incontext['sub_template'] = 'welcome_message';
418 438
 
419 439
 	// Done the submission?
420
-	if (isset($_POST['contbutt']))
421
-		return true;
440
+	if (isset($_POST['contbutt'])) {
441
+			return true;
442
+	}
422 443
 
423 444
 	// See if we think they have already installed it?
424 445
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -426,14 +447,17 @@  discard block
 block discarded – undo
426 447
 		$probably_installed = 0;
427 448
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
428 449
 		{
429
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
430
-				$probably_installed++;
431
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
432
-				$probably_installed++;
450
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
451
+							$probably_installed++;
452
+			}
453
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
454
+							$probably_installed++;
455
+			}
433 456
 		}
434 457
 
435
-		if ($probably_installed == 2)
436
-			$incontext['warning'] = $txt['error_already_installed'];
458
+		if ($probably_installed == 2) {
459
+					$incontext['warning'] = $txt['error_already_installed'];
460
+		}
437 461
 	}
438 462
 
439 463
 	// Is some database support even compiled in?
@@ -448,36 +472,43 @@  discard block
 block discarded – undo
448 472
 				$databases[$key]['supported'] = false;
449 473
 				$notFoundSQLFile = true;
450 474
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
475
+			} else {
476
+							$incontext['supported_databases'][] = $db;
451 477
 			}
452
-			else
453
-				$incontext['supported_databases'][] = $db;
454 478
 		}
455 479
 	}
456 480
 
457 481
 	// Check the PHP version.
458
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
459
-		$error = 'error_php_too_low';
482
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
483
+			$error = 'error_php_too_low';
484
+	}
460 485
 	// Make sure we have a supported database
461
-	elseif (empty($incontext['supported_databases']))
462
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
486
+	elseif (empty($incontext['supported_databases'])) {
487
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
488
+	}
463 489
 	// How about session support?  Some crazy sysadmin remove it?
464
-	elseif (!function_exists('session_start'))
465
-		$error = 'error_session_missing';
490
+	elseif (!function_exists('session_start')) {
491
+			$error = 'error_session_missing';
492
+	}
466 493
 	// Make sure they uploaded all the files.
467
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
468
-		$error = 'error_missing_files';
494
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
495
+			$error = 'error_missing_files';
496
+	}
469 497
 	// Very simple check on the session.save_path for Windows.
470 498
 	// @todo Move this down later if they don't use database-driven sessions?
471
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
472
-		$error = 'error_session_save_path';
499
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
500
+			$error = 'error_session_save_path';
501
+	}
473 502
 
474 503
 	// Since each of the three messages would look the same, anyway...
475
-	if (isset($error))
476
-		$incontext['error'] = $txt[$error];
504
+	if (isset($error)) {
505
+			$incontext['error'] = $txt[$error];
506
+	}
477 507
 
478 508
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
479
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
480
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
509
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
510
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
511
+	}
481 512
 
482 513
 	return false;
483 514
 }
@@ -503,12 +534,14 @@  discard block
 block discarded – undo
503 534
 		'db_last_error.php',
504 535
 	);
505 536
 
506
-	foreach ($incontext['detected_languages'] as $lang => $temp)
507
-		$extra_files[] = 'Themes/default/languages/' . $lang;
537
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
538
+			$extra_files[] = 'Themes/default/languages/' . $lang;
539
+	}
508 540
 
509 541
 	// With mod_security installed, we could attempt to fix it with .htaccess.
510
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
511
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
542
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
543
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
544
+	}
512 545
 
513 546
 	$failed_files = array();
514 547
 
@@ -524,12 +557,14 @@  discard block
 block discarded – undo
524 557
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
525 558
 
526 559
 				// Well, 755 hopefully worked... if not, try 777.
527
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
528
-					$failed_files[] = $file;
560
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
561
+									$failed_files[] = $file;
562
+				}
529 563
 			}
530 564
 		}
531
-		foreach ($extra_files as $file)
532
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
565
+		foreach ($extra_files as $file) {
566
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
567
+		}
533 568
 	}
534 569
 	// Windows is trickier.  Let's try opening for r+...
535 570
 	else
@@ -539,30 +574,35 @@  discard block
 block discarded – undo
539 574
 		foreach ($writable_files as $file)
540 575
 		{
541 576
 			// Folders can't be opened for write... but the index.php in them can ;)
542
-			if (is_dir(dirname(__FILE__) . '/' . $file))
543
-				$file .= '/index.php';
577
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
578
+							$file .= '/index.php';
579
+			}
544 580
 
545 581
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
546 582
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
547 583
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
548 584
 
549 585
 			// Hmm, okay, try just for write in that case...
550
-			if (!is_resource($fp))
551
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
586
+			if (!is_resource($fp)) {
587
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
588
+			}
552 589
 
553
-			if (!is_resource($fp))
554
-				$failed_files[] = $file;
590
+			if (!is_resource($fp)) {
591
+							$failed_files[] = $file;
592
+			}
555 593
 
556 594
 			@fclose($fp);
557 595
 		}
558
-		foreach ($extra_files as $file)
559
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
596
+		foreach ($extra_files as $file) {
597
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
598
+		}
560 599
 	}
561 600
 
562 601
 	$failure = count($failed_files) >= 1;
563 602
 
564
-	if (!isset($_SERVER))
565
-		return !$failure;
603
+	if (!isset($_SERVER)) {
604
+			return !$failure;
605
+	}
566 606
 
567 607
 	// Put the list into context.
568 608
 	$incontext['failed_files'] = $failed_files;
@@ -610,19 +650,23 @@  discard block
 block discarded – undo
610 650
 
611 651
 		if (!isset($ftp) || $ftp->error !== false)
612 652
 		{
613
-			if (!isset($ftp))
614
-				$ftp = new ftp_connection(null);
653
+			if (!isset($ftp)) {
654
+							$ftp = new ftp_connection(null);
655
+			}
615 656
 			// Save the error so we can mess with listing...
616
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
617
-				$incontext['ftp_errors'][] = $ftp->last_message;
657
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
658
+							$incontext['ftp_errors'][] = $ftp->last_message;
659
+			}
618 660
 
619 661
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
620 662
 
621
-			if (empty($_POST['ftp_path']) && $found_path)
622
-				$_POST['ftp_path'] = $detect_path;
663
+			if (empty($_POST['ftp_path']) && $found_path) {
664
+							$_POST['ftp_path'] = $detect_path;
665
+			}
623 666
 
624
-			if (!isset($_POST['ftp_username']))
625
-				$_POST['ftp_username'] = $username;
667
+			if (!isset($_POST['ftp_username'])) {
668
+							$_POST['ftp_username'] = $username;
669
+			}
626 670
 
627 671
 			// Set the username etc, into context.
628 672
 			$incontext['ftp'] = array(
@@ -634,8 +678,7 @@  discard block
 block discarded – undo
634 678
 			);
635 679
 
636 680
 			return false;
637
-		}
638
-		else
681
+		} else
639 682
 		{
640 683
 			$_SESSION['installer_temp_ftp'] = array(
641 684
 				'server' => $_POST['ftp_server'],
@@ -649,10 +692,12 @@  discard block
 block discarded – undo
649 692
 
650 693
 			foreach ($failed_files as $file)
651 694
 			{
652
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
653
-					$ftp->chmod($file, 0755);
654
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
655
-					$ftp->chmod($file, 0777);
695
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
696
+									$ftp->chmod($file, 0755);
697
+				}
698
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
699
+									$ftp->chmod($file, 0777);
700
+				}
656 701
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
657 702
 				{
658 703
 					$failed_files_updated[] = $file;
@@ -707,15 +752,17 @@  discard block
 block discarded – undo
707 752
 
708 753
 			if (!$foundOne)
709 754
 			{
710
-				if (isset($db['default_host']))
711
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
755
+				if (isset($db['default_host'])) {
756
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
757
+				}
712 758
 				if (isset($db['default_user']))
713 759
 				{
714 760
 					$incontext['db']['user'] = ini_get($db['default_user']);
715 761
 					$incontext['db']['name'] = ini_get($db['default_user']);
716 762
 				}
717
-				if (isset($db['default_password']))
718
-					$incontext['db']['pass'] = ini_get($db['default_password']);
763
+				if (isset($db['default_password'])) {
764
+									$incontext['db']['pass'] = ini_get($db['default_password']);
765
+				}
719 766
 
720 767
 				// For simplicity and less confusion, leave the port blank by default
721 768
 				$incontext['db']['port'] = '';
@@ -734,10 +781,10 @@  discard block
 block discarded – undo
734 781
 		$incontext['db']['server'] = $_POST['db_server'];
735 782
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
736 783
 
737
-		if (!empty($_POST['db_port']))
738
-			$incontext['db']['port'] = $_POST['db_port'];
739
-	}
740
-	else
784
+		if (!empty($_POST['db_port'])) {
785
+					$incontext['db']['port'] = $_POST['db_port'];
786
+		}
787
+	} else
741 788
 	{
742 789
 		$incontext['db']['prefix'] = 'smf_';
743 790
 	}
@@ -773,10 +820,11 @@  discard block
 block discarded – undo
773 820
 		if (!empty($_POST['db_port']))
774 821
 		{
775 822
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
776
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
777
-				$vars['db_port'] = (int) $_POST['db_port'];
778
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
779
-				$vars['db_port'] = (int) $_POST['db_port'];
823
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
824
+							$vars['db_port'] = (int) $_POST['db_port'];
825
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
826
+							$vars['db_port'] = (int) $_POST['db_port'];
827
+			}
780 828
 		}
781 829
 
782 830
 		// God I hope it saved!
@@ -789,8 +837,9 @@  discard block
 block discarded – undo
789 837
 		// Make sure it works.
790 838
 		require(dirname(__FILE__) . '/Settings.php');
791 839
 
792
-		if (empty($sourcedir))
793
-			$sourcedir = dirname(__FILE__) . '/Sources';
840
+		if (empty($sourcedir)) {
841
+					$sourcedir = dirname(__FILE__) . '/Sources';
842
+		}
794 843
 
795 844
 		// Better find the database file!
796 845
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -800,18 +849,21 @@  discard block
 block discarded – undo
800 849
 		}
801 850
 
802 851
 		// Now include it for database functions!
803
-		if (!defined('SMF'))
804
-			define('SMF', 1);
852
+		if (!defined('SMF')) {
853
+					define('SMF', 1);
854
+		}
805 855
 
806 856
 		$modSettings['disableQueryCheck'] = true;
807
-		if (empty($smcFunc))
808
-			$smcFunc = array();
857
+		if (empty($smcFunc)) {
858
+					$smcFunc = array();
859
+		}
809 860
 
810 861
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
811 862
 
812 863
 		// What - running PHP4? The shame!
813
-		if (version_compare(PHP_VERSION, '5', '<'))
814
-			require_once($sourcedir . '/Subs-Compat.php');
864
+		if (version_compare(PHP_VERSION, '5', '<')) {
865
+					require_once($sourcedir . '/Subs-Compat.php');
866
+		}
815 867
 
816 868
 		// Attempt a connection.
817 869
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -899,12 +951,14 @@  discard block
 block discarded – undo
899 951
 	$incontext['page_title'] = $txt['install_settings'];
900 952
 
901 953
 	// Let's see if we got the database type correct.
902
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
903
-		$db_type = $_POST['db_type'];
954
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
955
+			$db_type = $_POST['db_type'];
956
+	}
904 957
 
905 958
 	// Else we'd better be able to get the connection.
906
-	else
907
-		load_database();
959
+	else {
960
+			load_database();
961
+	}
908 962
 
909 963
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
910 964
 
@@ -924,12 +978,14 @@  discard block
 block discarded – undo
924 978
 	// Submitting?
925 979
 	if (isset($_POST['boardurl']))
926 980
 	{
927
-		if (substr($_POST['boardurl'], -10) == '/index.php')
928
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
929
-		elseif (substr($_POST['boardurl'], -1) == '/')
930
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
931
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
932
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
981
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
982
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
983
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
984
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
985
+		}
986
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
987
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
988
+		}
933 989
 
934 990
 		// Save these variables.
935 991
 		$vars = array(
@@ -966,10 +1022,10 @@  discard block
 block discarded – undo
966 1022
 			{
967 1023
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
968 1024
 				return false;
969
-			}
970
-			else
971
-				// Set the character set here.
1025
+			} else {
1026
+							// Set the character set here.
972 1027
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1028
+			}
973 1029
 		}
974 1030
 
975 1031
 		// Good, skip on.
@@ -989,8 +1045,9 @@  discard block
 block discarded – undo
989 1045
 	$incontext['continue'] = 1;
990 1046
 
991 1047
 	// Already done?
992
-	if (isset($_POST['pop_done']))
993
-		return true;
1048
+	if (isset($_POST['pop_done'])) {
1049
+			return true;
1050
+	}
994 1051
 
995 1052
 	// Reload settings.
996 1053
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1008,8 +1065,9 @@  discard block
 block discarded – undo
1008 1065
 	$modSettings = array();
1009 1066
 	if ($result !== false)
1010 1067
 	{
1011
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1012
-			$modSettings[$row['variable']] = $row['value'];
1068
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1069
+					$modSettings[$row['variable']] = $row['value'];
1070
+		}
1013 1071
 		$smcFunc['db_free_result']($result);
1014 1072
 
1015 1073
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1022,20 +1080,22 @@  discard block
 block discarded – undo
1022 1080
 	$modSettings['disableQueryCheck'] = true;
1023 1081
 
1024 1082
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1025
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1026
-		$smcFunc['db_query']('', '
1083
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1084
+			$smcFunc['db_query']('', '
1027 1085
 			SET NAMES {string:utf8}',
1028 1086
 			array(
1029 1087
 				'db_error_skip' => true,
1030 1088
 				'utf8' => 'utf8',
1031 1089
 			)
1032 1090
 		);
1091
+	}
1033 1092
 
1034 1093
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1035
-	if (substr(__DIR__, -1) == '\\')
1036
-		$attachdir = __DIR__ . 'attachments';
1037
-	else
1038
-		$attachdir = __DIR__ . '/attachments';
1094
+	if (substr(__DIR__, -1) == '\\') {
1095
+			$attachdir = __DIR__ . 'attachments';
1096
+	} else {
1097
+			$attachdir = __DIR__ . '/attachments';
1098
+	}
1039 1099
 
1040 1100
 	$replaces = array(
1041 1101
 		'{$db_prefix}' => $db_prefix,
@@ -1052,8 +1112,9 @@  discard block
 block discarded – undo
1052 1112
 
1053 1113
 	foreach ($txt as $key => $value)
1054 1114
 	{
1055
-		if (substr($key, 0, 8) == 'default_')
1056
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1115
+		if (substr($key, 0, 8) == 'default_') {
1116
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1117
+		}
1057 1118
 	}
1058 1119
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1059 1120
 
@@ -1068,8 +1129,9 @@  discard block
 block discarded – undo
1068 1129
 
1069 1130
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1070 1131
 		{
1071
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1072
-				$engines[] = $row['Engine'];
1132
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1133
+							$engines[] = $row['Engine'];
1134
+			}
1073 1135
 		}
1074 1136
 
1075 1137
 		// Done with this now
@@ -1093,8 +1155,7 @@  discard block
 block discarded – undo
1093 1155
 			$replaces['START TRANSACTION;'] = '';
1094 1156
 			$replaces['COMMIT;'] = '';
1095 1157
 		}
1096
-	}
1097
-	else
1158
+	} else
1098 1159
 	{
1099 1160
 		$has_innodb = false;
1100 1161
 	}
@@ -1116,21 +1177,24 @@  discard block
 block discarded – undo
1116 1177
 	foreach ($sql_lines as $count => $line)
1117 1178
 	{
1118 1179
 		// No comments allowed!
1119
-		if (substr(trim($line), 0, 1) != '#')
1120
-			$current_statement .= "\n" . rtrim($line);
1180
+		if (substr(trim($line), 0, 1) != '#') {
1181
+					$current_statement .= "\n" . rtrim($line);
1182
+		}
1121 1183
 
1122 1184
 		// Is this the end of the query string?
1123
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1124
-			continue;
1185
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1186
+					continue;
1187
+		}
1125 1188
 
1126 1189
 		// Does this table already exist?  If so, don't insert more data into it!
1127 1190
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1128 1191
 		{
1129 1192
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1130
-			if (!empty($matches[0]))
1131
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1132
-			else
1133
-				$incontext['sql_results']['insert_dups']++;
1193
+			if (!empty($matches[0])) {
1194
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1195
+			} else {
1196
+							$incontext['sql_results']['insert_dups']++;
1197
+			}
1134 1198
 
1135 1199
 			$current_statement = '';
1136 1200
 			continue;
@@ -1139,8 +1203,9 @@  discard block
 block discarded – undo
1139 1203
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1140 1204
 		{
1141 1205
 			// Use the appropriate function based on the DB type
1142
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1143
-				$db_errorno = $db_type . '_errno';
1206
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1207
+							$db_errorno = $db_type . '_errno';
1208
+			}
1144 1209
 
1145 1210
 			// Error 1050: Table already exists!
1146 1211
 			// @todo Needs to be made better!
@@ -1155,18 +1220,18 @@  discard block
 block discarded – undo
1155 1220
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1156 1221
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1157 1222
 			}
1158
-		}
1159
-		else
1223
+		} else
1160 1224
 		{
1161
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1162
-				$incontext['sql_results']['tables']++;
1163
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1225
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1226
+							$incontext['sql_results']['tables']++;
1227
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1164 1228
 			{
1165 1229
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1166
-				if (!empty($matches[0]))
1167
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1168
-				else
1169
-					$incontext['sql_results']['inserts']++;
1230
+				if (!empty($matches[0])) {
1231
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1232
+				} else {
1233
+									$incontext['sql_results']['inserts']++;
1234
+				}
1170 1235
 			}
1171 1236
 		}
1172 1237
 
@@ -1179,15 +1244,17 @@  discard block
 block discarded – undo
1179 1244
 	// Sort out the context for the SQL.
1180 1245
 	foreach ($incontext['sql_results'] as $key => $number)
1181 1246
 	{
1182
-		if ($number == 0)
1183
-			unset($incontext['sql_results'][$key]);
1184
-		else
1185
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1247
+		if ($number == 0) {
1248
+					unset($incontext['sql_results'][$key]);
1249
+		} else {
1250
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1251
+		}
1186 1252
 	}
1187 1253
 
1188 1254
 	// Make sure UTF will be used globally.
1189
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1190
-		$newSettings[] = array('global_character_set', 'UTF-8');
1255
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1256
+			$newSettings[] = array('global_character_set', 'UTF-8');
1257
+	}
1191 1258
 
1192 1259
 	// Maybe we can auto-detect better cookie settings?
1193 1260
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1198,16 +1265,20 @@  discard block
 block discarded – undo
1198 1265
 		$globalCookies = false;
1199 1266
 
1200 1267
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1201
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1202
-			$globalCookies = true;
1268
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1269
+					$globalCookies = true;
1270
+		}
1203 1271
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1204
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1205
-			$localCookies = true;
1272
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1273
+					$localCookies = true;
1274
+		}
1206 1275
 
1207
-		if ($globalCookies)
1208
-			$newSettings[] = array('globalCookies', '1');
1209
-		if ($localCookies)
1210
-			$newSettings[] = array('localCookies', '1');
1276
+		if ($globalCookies) {
1277
+					$newSettings[] = array('globalCookies', '1');
1278
+		}
1279
+		if ($localCookies) {
1280
+					$newSettings[] = array('localCookies', '1');
1281
+		}
1211 1282
 	}
1212 1283
 
1213 1284
 	// Are we allowing stat collection?
@@ -1223,32 +1294,36 @@  discard block
 block discarded – undo
1223 1294
 			fwrite($fp, $out);
1224 1295
 
1225 1296
 			$return_data = '';
1226
-			while (!feof($fp))
1227
-				$return_data .= fgets($fp, 128);
1297
+			while (!feof($fp)) {
1298
+							$return_data .= fgets($fp, 128);
1299
+			}
1228 1300
 
1229 1301
 			fclose($fp);
1230 1302
 
1231 1303
 			// Get the unique site ID.
1232 1304
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1233 1305
 
1234
-			if (!empty($ID[1]))
1235
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1306
+			if (!empty($ID[1])) {
1307
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1308
+			}
1236 1309
 		}
1237 1310
 	}
1238 1311
 
1239 1312
 	// Are we enabling SSL?
1240
-	if (!empty($_POST['force_ssl']))
1241
-		$newSettings[] = array('force_ssl', 2);
1313
+	if (!empty($_POST['force_ssl'])) {
1314
+			$newSettings[] = array('force_ssl', 2);
1315
+	}
1242 1316
 
1243 1317
 	// Setting a timezone is required.
1244 1318
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1245 1319
 	{
1246 1320
 		// Get PHP's default timezone, if set
1247 1321
 		$ini_tz = ini_get('date.timezone');
1248
-		if (!empty($ini_tz))
1249
-			$timezone_id = $ini_tz;
1250
-		else
1251
-			$timezone_id = '';
1322
+		if (!empty($ini_tz)) {
1323
+					$timezone_id = $ini_tz;
1324
+		} else {
1325
+					$timezone_id = '';
1326
+		}
1252 1327
 
1253 1328
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1254 1329
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1257,8 +1332,9 @@  discard block
 block discarded – undo
1257 1332
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1258 1333
 		}
1259 1334
 
1260
-		if (date_default_timezone_set($timezone_id))
1261
-			$newSettings[] = array('default_timezone', $timezone_id);
1335
+		if (date_default_timezone_set($timezone_id)) {
1336
+					$newSettings[] = array('default_timezone', $timezone_id);
1337
+		}
1262 1338
 	}
1263 1339
 
1264 1340
 	if (!empty($newSettings))
@@ -1289,16 +1365,18 @@  discard block
 block discarded – undo
1289 1365
 	}
1290 1366
 
1291 1367
 	// MySQL specific stuff
1292
-	if (substr($db_type, 0, 5) != 'mysql')
1293
-		return false;
1368
+	if (substr($db_type, 0, 5) != 'mysql') {
1369
+			return false;
1370
+	}
1294 1371
 
1295 1372
 	// Find database user privileges.
1296 1373
 	$privs = array();
1297 1374
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1298 1375
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1299 1376
 	{
1300
-		if ($row['Privilege'] == 'Alter')
1301
-			$privs[] = $row['Privilege'];
1377
+		if ($row['Privilege'] == 'Alter') {
1378
+					$privs[] = $row['Privilege'];
1379
+		}
1302 1380
 	}
1303 1381
 	$smcFunc['db_free_result']($get_privs);
1304 1382
 
@@ -1328,8 +1406,9 @@  discard block
 block discarded – undo
1328 1406
 	$incontext['continue'] = 1;
1329 1407
 
1330 1408
 	// Skipping?
1331
-	if (!empty($_POST['skip']))
1332
-		return true;
1409
+	if (!empty($_POST['skip'])) {
1410
+			return true;
1411
+	}
1333 1412
 
1334 1413
 	// Need this to check whether we need the database password.
1335 1414
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1342,18 +1421,22 @@  discard block
 block discarded – undo
1342 1421
 	// We need this to properly hash the password for Admin
1343 1422
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1344 1423
 			global $sourcedir;
1345
-			if (function_exists('mb_strtolower'))
1346
-				return mb_strtolower($string, 'UTF-8');
1424
+			if (function_exists('mb_strtolower')) {
1425
+							return mb_strtolower($string, 'UTF-8');
1426
+			}
1347 1427
 			require_once($sourcedir . '/Subs-Charset.php');
1348 1428
 			return utf8_strtolower($string);
1349 1429
 		};
1350 1430
 
1351
-	if (!isset($_POST['username']))
1352
-		$_POST['username'] = '';
1353
-	if (!isset($_POST['email']))
1354
-		$_POST['email'] = '';
1355
-	if (!isset($_POST['server_email']))
1356
-		$_POST['server_email'] = '';
1431
+	if (!isset($_POST['username'])) {
1432
+			$_POST['username'] = '';
1433
+	}
1434
+	if (!isset($_POST['email'])) {
1435
+			$_POST['email'] = '';
1436
+	}
1437
+	if (!isset($_POST['server_email'])) {
1438
+			$_POST['server_email'] = '';
1439
+	}
1357 1440
 
1358 1441
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1359 1442
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1372,8 +1455,9 @@  discard block
 block discarded – undo
1372 1455
 			'admin_group' => 1,
1373 1456
 		)
1374 1457
 	);
1375
-	if ($smcFunc['db_num_rows']($request) != 0)
1376
-		$incontext['skip'] = 1;
1458
+	if ($smcFunc['db_num_rows']($request) != 0) {
1459
+			$incontext['skip'] = 1;
1460
+	}
1377 1461
 	$smcFunc['db_free_result']($request);
1378 1462
 
1379 1463
 	// Trying to create an account?
@@ -1404,8 +1488,9 @@  discard block
 block discarded – undo
1404 1488
 		}
1405 1489
 
1406 1490
 		// Update the webmaster's email?
1407
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1408
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1491
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1492
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1493
+		}
1409 1494
 
1410 1495
 		// Work out whether we're going to have dodgy characters and remove them.
1411 1496
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1428,32 +1513,27 @@  discard block
 block discarded – undo
1428 1513
 			$smcFunc['db_free_result']($result);
1429 1514
 
1430 1515
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1431
-		}
1432
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1516
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1433 1517
 		{
1434 1518
 			// Try the previous step again.
1435 1519
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1436 1520
 			return false;
1437
-		}
1438
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1521
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1439 1522
 		{
1440 1523
 			// Try the previous step again.
1441 1524
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1442 1525
 			return false;
1443
-		}
1444
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1526
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1445 1527
 		{
1446 1528
 			// One step back, this time fill out a proper admin email address.
1447 1529
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1448 1530
 			return false;
1449
-		}
1450
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1531
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1451 1532
 		{
1452 1533
 			// One step back, this time fill out a proper admin email address.
1453 1534
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1454 1535
 			return false;
1455
-		}
1456
-		elseif ($_POST['username'] != '')
1536
+		} elseif ($_POST['username'] != '')
1457 1537
 		{
1458 1538
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1459 1539
 
@@ -1519,17 +1599,19 @@  discard block
 block discarded – undo
1519 1599
 	require_once($sourcedir . '/Subs-Auth.php');
1520 1600
 
1521 1601
 	// Bring a warning over.
1522
-	if (!empty($incontext['account_existed']))
1523
-		$incontext['warning'] = $incontext['account_existed'];
1602
+	if (!empty($incontext['account_existed'])) {
1603
+			$incontext['warning'] = $incontext['account_existed'];
1604
+	}
1524 1605
 
1525
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1526
-		$smcFunc['db_query']('', '
1606
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1607
+			$smcFunc['db_query']('', '
1527 1608
 			SET NAMES {string:db_character_set}',
1528 1609
 			array(
1529 1610
 				'db_character_set' => $db_character_set,
1530 1611
 				'db_error_skip' => true,
1531 1612
 			)
1532 1613
 		);
1614
+	}
1533 1615
 
1534 1616
 	// As track stats is by default enabled let's add some activity.
1535 1617
 	$smcFunc['db_insert']('ignore',
@@ -1550,14 +1632,16 @@  discard block
 block discarded – undo
1550 1632
 	// Only proceed if we can load the data.
1551 1633
 	if ($request)
1552 1634
 	{
1553
-		while ($row = $smcFunc['db_fetch_row']($request))
1554
-			$modSettings[$row[0]] = $row[1];
1635
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1636
+					$modSettings[$row[0]] = $row[1];
1637
+		}
1555 1638
 		$smcFunc['db_free_result']($request);
1556 1639
 	}
1557 1640
 
1558 1641
 	// Automatically log them in ;)
1559
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1560
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1642
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1643
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1644
+	}
1561 1645
 
1562 1646
 	$result = $smcFunc['db_query']('', '
1563 1647
 		SELECT value
@@ -1568,13 +1652,14 @@  discard block
 block discarded – undo
1568 1652
 			'db_error_skip' => true,
1569 1653
 		)
1570 1654
 	);
1571
-	if ($smcFunc['db_num_rows']($result) != 0)
1572
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1655
+	if ($smcFunc['db_num_rows']($result) != 0) {
1656
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1657
+	}
1573 1658
 	$smcFunc['db_free_result']($result);
1574 1659
 
1575
-	if (empty($db_sessions))
1576
-		$_SESSION['admin_time'] = time();
1577
-	else
1660
+	if (empty($db_sessions)) {
1661
+			$_SESSION['admin_time'] = time();
1662
+	} else
1578 1663
 	{
1579 1664
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1580 1665
 
@@ -1598,8 +1683,9 @@  discard block
 block discarded – undo
1598 1683
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1599 1684
 		function($string){
1600 1685
 			global $sourcedir;
1601
-			if (function_exists('mb_strtolower'))
1602
-				return mb_strtolower($string, 'UTF-8');
1686
+			if (function_exists('mb_strtolower')) {
1687
+							return mb_strtolower($string, 'UTF-8');
1688
+			}
1603 1689
 			require_once($sourcedir . '/Subs-Charset.php');
1604 1690
 			return utf8_strtolower($string);
1605 1691
 		};
@@ -1615,8 +1701,9 @@  discard block
 block discarded – undo
1615 1701
 		)
1616 1702
 	);
1617 1703
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1618
-	if ($smcFunc['db_num_rows']($request) > 0)
1619
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1704
+	if ($smcFunc['db_num_rows']($request) > 0) {
1705
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1706
+	}
1620 1707
 	$smcFunc['db_free_result']($request);
1621 1708
 
1622 1709
 	// Now is the perfect time to fetch the SM files.
@@ -1635,8 +1722,9 @@  discard block
 block discarded – undo
1635 1722
 
1636 1723
 	// Check if we need some stupid MySQL fix.
1637 1724
 	$server_version = $smcFunc['db_server_info']();
1638
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1639
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1725
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1726
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1727
+	}
1640 1728
 
1641 1729
 	// Some final context for the template.
1642 1730
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1656,8 +1744,9 @@  discard block
 block discarded – undo
1656 1744
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1657 1745
 
1658 1746
 	// @todo Do we just want to read the file in clean, and split it this way always?
1659
-	if (count($settingsArray) == 1)
1660
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1747
+	if (count($settingsArray) == 1) {
1748
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1749
+	}
1661 1750
 
1662 1751
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1663 1752
 	{
@@ -1672,19 +1761,22 @@  discard block
 block discarded – undo
1672 1761
 			continue;
1673 1762
 		}
1674 1763
 
1675
-		if (trim($settingsArray[$i]) == '?' . '>')
1676
-			$settingsArray[$i] = '';
1764
+		if (trim($settingsArray[$i]) == '?' . '>') {
1765
+					$settingsArray[$i] = '';
1766
+		}
1677 1767
 
1678 1768
 		// Don't trim or bother with it if it's not a variable.
1679
-		if (substr($settingsArray[$i], 0, 1) != '$')
1680
-			continue;
1769
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1770
+					continue;
1771
+		}
1681 1772
 
1682 1773
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1683 1774
 
1684
-		foreach ($vars as $var => $val)
1685
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1775
+		foreach ($vars as $var => $val) {
1776
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1686 1777
 			{
1687 1778
 				$comment = strstr($settingsArray[$i], '#');
1779
+		}
1688 1780
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1689 1781
 				unset($vars[$var]);
1690 1782
 			}
@@ -1694,36 +1786,41 @@  discard block
 block discarded – undo
1694 1786
 	if (!empty($vars))
1695 1787
 	{
1696 1788
 		$settingsArray[$i++] = '';
1697
-		foreach ($vars as $var => $val)
1698
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1789
+		foreach ($vars as $var => $val) {
1790
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1791
+		}
1699 1792
 	}
1700 1793
 
1701 1794
 	// Blank out the file - done to fix a oddity with some servers.
1702 1795
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1703
-	if (!$fp)
1704
-		return false;
1796
+	if (!$fp) {
1797
+			return false;
1798
+	}
1705 1799
 	fclose($fp);
1706 1800
 
1707 1801
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1708 1802
 
1709 1803
 	// Gotta have one of these ;)
1710
-	if (trim($settingsArray[0]) != '<?php')
1711
-		fwrite($fp, "<?php\n");
1804
+	if (trim($settingsArray[0]) != '<?php') {
1805
+			fwrite($fp, "<?php\n");
1806
+	}
1712 1807
 
1713 1808
 	$lines = count($settingsArray);
1714 1809
 	for ($i = 0; $i < $lines - 1; $i++)
1715 1810
 	{
1716 1811
 		// Don't just write a bunch of blank lines.
1717
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1718
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1812
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1813
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1814
+		}
1719 1815
 	}
1720 1816
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1721 1817
 	fclose($fp);
1722 1818
 
1723 1819
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1724 1820
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1725
-	if (function_exists('opcache_invalidate'))
1726
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1821
+	if (function_exists('opcache_invalidate')) {
1822
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1823
+	}
1727 1824
 
1728 1825
 	return true;
1729 1826
 }
@@ -1748,9 +1845,9 @@  discard block
 block discarded – undo
1748 1845
 	SecFilterScanPOST Off
1749 1846
 </IfModule>';
1750 1847
 
1751
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1752
-		return true;
1753
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1848
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1849
+			return true;
1850
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1754 1851
 	{
1755 1852
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1756 1853
 
@@ -1762,29 +1859,28 @@  discard block
 block discarded – undo
1762 1859
 				fwrite($ht_handle, $htaccess_addition);
1763 1860
 				fclose($ht_handle);
1764 1861
 				return true;
1862
+			} else {
1863
+							return false;
1765 1864
 			}
1766
-			else
1767
-				return false;
1865
+		} else {
1866
+					return true;
1768 1867
 		}
1769
-		else
1770
-			return true;
1771
-	}
1772
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1773
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1774
-	elseif (is_writable(dirname(__FILE__)))
1868
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1869
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1870
+	} elseif (is_writable(dirname(__FILE__)))
1775 1871
 	{
1776 1872
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1777 1873
 		{
1778 1874
 			fwrite($ht_handle, $htaccess_addition);
1779 1875
 			fclose($ht_handle);
1780 1876
 			return true;
1877
+		} else {
1878
+					return false;
1781 1879
 		}
1782
-		else
1880
+	} else {
1783 1881
 			return false;
1784 1882
 	}
1785
-	else
1786
-		return false;
1787
-}
1883
+	}
1788 1884
 
1789 1885
 function template_install_above()
1790 1886
 {
@@ -1822,9 +1918,10 @@  discard block
 block discarded – undo
1822 1918
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1823 1919
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1824 1920
 
1825
-		foreach ($incontext['detected_languages'] as $lang => $name)
1826
-			echo '
1921
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1922
+					echo '
1827 1923
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1924
+		}
1828 1925
 
1829 1926
 		echo '
1830 1927
 								</select>
@@ -1844,9 +1941,10 @@  discard block
 block discarded – undo
1844 1941
 						<h2>', $txt['upgrade_progress'], '</h2>
1845 1942
 						<ul>';
1846 1943
 
1847
-	foreach ($incontext['steps'] as $num => $step)
1848
-		echo '
1944
+	foreach ($incontext['steps'] as $num => $step) {
1945
+			echo '
1849 1946
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1947
+	}
1850 1948
 
1851 1949
 	echo '
1852 1950
 						</ul>
@@ -1871,20 +1969,23 @@  discard block
 block discarded – undo
1871 1969
 		echo '
1872 1970
 								<div>';
1873 1971
 
1874
-		if (!empty($incontext['continue']))
1875
-			echo '
1972
+		if (!empty($incontext['continue'])) {
1973
+					echo '
1876 1974
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1877
-		if (!empty($incontext['skip']))
1878
-			echo '
1975
+		}
1976
+		if (!empty($incontext['skip'])) {
1977
+					echo '
1879 1978
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1979
+		}
1880 1980
 		echo '
1881 1981
 								</div>';
1882 1982
 	}
1883 1983
 
1884 1984
 	// Show the closing form tag and other data only if not in the last step
1885
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1886
-		echo '
1985
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
1986
+			echo '
1887 1987
 							</form>';
1988
+	}
1888 1989
 
1889 1990
 	echo '
1890 1991
 						</div>
@@ -1919,13 +2020,15 @@  discard block
 block discarded – undo
1919 2020
 		</div>';
1920 2021
 
1921 2022
 	// Show the warnings, or not.
1922
-	if (template_warning_divs())
1923
-		echo '
2023
+	if (template_warning_divs()) {
2024
+			echo '
1924 2025
 		<h3>', $txt['install_all_lovely'], '</h3>';
2026
+	}
1925 2027
 
1926 2028
 	// Say we want the continue button!
1927
-	if (empty($incontext['error']))
1928
-		$incontext['continue'] = 1;
2029
+	if (empty($incontext['error'])) {
2030
+			$incontext['continue'] = 1;
2031
+	}
1929 2032
 
1930 2033
 	// For the latest version stuff.
1931 2034
 	echo '
@@ -1959,8 +2062,8 @@  discard block
 block discarded – undo
1959 2062
 	global $txt, $incontext;
1960 2063
 
1961 2064
 	// Errors are very serious..
1962
-	if (!empty($incontext['error']))
1963
-		echo '
2065
+	if (!empty($incontext['error'])) {
2066
+			echo '
1964 2067
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1965 2068
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1966 2069
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1968,9 +2071,10 @@  discard block
 block discarded – undo
1968 2071
 				', $incontext['error'], '
1969 2072
 			</div>
1970 2073
 		</div>';
2074
+	}
1971 2075
 	// A warning message?
1972
-	elseif (!empty($incontext['warning']))
1973
-		echo '
2076
+	elseif (!empty($incontext['warning'])) {
2077
+			echo '
1974 2078
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1975 2079
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1976 2080
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -1978,6 +2082,7 @@  discard block
 block discarded – undo
1978 2082
 				', $incontext['warning'], '
1979 2083
 			</div>
1980 2084
 		</div>';
2085
+	}
1981 2086
 
1982 2087
 	return empty($incontext['error']) && empty($incontext['warning']);
1983 2088
 }
@@ -1993,27 +2098,30 @@  discard block
 block discarded – undo
1993 2098
 			<li>', $incontext['failed_files']), '</li>
1994 2099
 		</ul>';
1995 2100
 
1996
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
1997
-		echo '
2101
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2102
+			echo '
1998 2103
 		<hr>
1999 2104
 		<p>', $txt['chmod_linux_info'], '</p>
2000 2105
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2106
+	}
2001 2107
 
2002 2108
 	// This is serious!
2003
-	if (!template_warning_divs())
2004
-		return;
2109
+	if (!template_warning_divs()) {
2110
+			return;
2111
+	}
2005 2112
 
2006 2113
 	echo '
2007 2114
 		<hr>
2008 2115
 		<p>', $txt['ftp_setup_info'], '</p>';
2009 2116
 
2010
-	if (!empty($incontext['ftp_errors']))
2011
-		echo '
2117
+	if (!empty($incontext['ftp_errors'])) {
2118
+			echo '
2012 2119
 		<div class="error_message">
2013 2120
 			', $txt['error_ftp_no_connect'], '<br><br>
2014 2121
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2015 2122
 		</div>
2016 2123
 		<br>';
2124
+	}
2017 2125
 
2018 2126
 	echo '
2019 2127
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2073,17 +2181,17 @@  discard block
 block discarded – undo
2073 2181
 				<td>
2074 2182
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2075 2183
 
2076
-	foreach ($incontext['supported_databases'] as $key => $db)
2077
-			echo '
2184
+	foreach ($incontext['supported_databases'] as $key => $db) {
2185
+				echo '
2078 2186
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2187
+	}
2079 2188
 
2080 2189
 	echo '
2081 2190
 					</select>
2082 2191
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2083 2192
 				</td>
2084 2193
 			</tr>';
2085
-	}
2086
-	else
2194
+	} else
2087 2195
 	{
2088 2196
 		echo '
2089 2197
 			<tr style="display: none;">
@@ -2275,9 +2383,10 @@  discard block
 block discarded – undo
2275 2383
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2276 2384
 				<ul>';
2277 2385
 
2278
-		foreach ($incontext['failures'] as $line => $fail)
2279
-			echo '
2386
+		foreach ($incontext['failures'] as $line => $fail) {
2387
+					echo '
2280 2388
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2389
+		}
2281 2390
 
2282 2391
 		echo '
2283 2392
 				</ul>';
@@ -2338,15 +2447,16 @@  discard block
 block discarded – undo
2338 2447
 			</tr>
2339 2448
 		</table>';
2340 2449
 
2341
-	if ($incontext['require_db_confirm'])
2342
-		echo '
2450
+	if ($incontext['require_db_confirm']) {
2451
+			echo '
2343 2452
 		<h2>', $txt['user_settings_database'], '</h2>
2344 2453
 		<p>', $txt['user_settings_database_info'], '</p>
2345 2454
 
2346 2455
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2347 2456
 			<input type="password" name="password3" size="30" class="input_password" />
2348 2457
 		</div>';
2349
-}
2458
+	}
2459
+	}
2350 2460
 
2351 2461
 // Tell them it's done, and to delete.
2352 2462
 function template_delete_install()
@@ -2359,14 +2469,15 @@  discard block
 block discarded – undo
2359 2469
 	template_warning_divs();
2360 2470
 
2361 2471
 	// Install directory still writable?
2362
-	if ($incontext['dir_still_writable'])
2363
-		echo '
2472
+	if ($incontext['dir_still_writable']) {
2473
+			echo '
2364 2474
 		<em>', $txt['still_writable'], '</em><br>
2365 2475
 		<br>';
2476
+	}
2366 2477
 
2367 2478
 	// Don't show the box if it's like 99% sure it won't work :P.
2368
-	if ($incontext['probably_delete_install'])
2369
-		echo '
2479
+	if ($incontext['probably_delete_install']) {
2480
+			echo '
2370 2481
 		<div style="margin: 1ex; font-weight: bold;">
2371 2482
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2372 2483
 		</div>
@@ -2382,6 +2493,7 @@  discard block
 block discarded – undo
2382 2493
 			}
2383 2494
 		</script>
2384 2495
 		<br>';
2496
+	}
2385 2497
 
2386 2498
 	echo '
2387 2499
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +867 added lines, -635 removed lines patch added patch discarded remove patch
@@ -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
 
@@ -100,11 +101,14 @@  discard block
 block discarded – undo
100 101
 	ini_set('default_socket_timeout', 900);
101 102
 }
102 103
 // Clean the upgrade path if this is from the client.
103
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
104
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
104
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
105
+	for ($i = 1;
106
+}
107
+$i < $_SERVER['argc']; $i++)
105 108
 	{
106
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
107
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
109
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
110
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
111
+		}
108 112
 	}
109 113
 
110 114
 // Are we from the client?
@@ -112,16 +116,17 @@  discard block
 block discarded – undo
112 116
 {
113 117
 	$command_line = true;
114 118
 	$disable_security = true;
115
-}
116
-else
119
+} else {
117 120
 	$command_line = false;
121
+}
118 122
 
119 123
 // Load this now just because we can.
120 124
 require_once($upgrade_path . '/Settings.php');
121 125
 
122 126
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
123
-if (isset($language))
127
+if (isset($language)) {
124 128
 	$language = str_ireplace('-utf8', '', $language);
129
+}
125 130
 
126 131
 // Are we logged in?
127 132
 if (isset($upgradeData))
@@ -129,10 +134,12 @@  discard block
 block discarded – undo
129 134
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
130 135
 
131 136
 	// Check for sensible values.
132
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
133
-		$upcontext['user']['started'] = time();
134
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
135
-		$upcontext['user']['updated'] = 0;
137
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
138
+			$upcontext['user']['started'] = time();
139
+	}
140
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
141
+			$upcontext['user']['updated'] = 0;
142
+	}
136 143
 
137 144
 	$upcontext['started'] = $upcontext['user']['started'];
138 145
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -190,8 +197,9 @@  discard block
 block discarded – undo
190 197
 			'db_error_skip' => true,
191 198
 		)
192 199
 	);
193
-	while ($row = $smcFunc['db_fetch_assoc']($request))
194
-		$modSettings[$row['variable']] = $row['value'];
200
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
201
+			$modSettings[$row['variable']] = $row['value'];
202
+	}
195 203
 	$smcFunc['db_free_result']($request);
196 204
 }
197 205
 
@@ -201,10 +209,12 @@  discard block
 block discarded – undo
201 209
 	$modSettings['theme_url'] = 'Themes/default';
202 210
 	$modSettings['images_url'] = 'Themes/default/images';
203 211
 }
204
-if (!isset($settings['default_theme_url']))
212
+if (!isset($settings['default_theme_url'])) {
205 213
 	$settings['default_theme_url'] = $modSettings['theme_url'];
206
-if (!isset($settings['default_theme_dir']))
214
+}
215
+if (!isset($settings['default_theme_dir'])) {
207 216
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
217
+}
208 218
 
209 219
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
210 220
 // Default title...
@@ -222,13 +232,15 @@  discard block
 block discarded – undo
222 232
 	$support_js = $upcontext['upgrade_status']['js'];
223 233
 
224 234
 	// Only set this if the upgrader status says so.
225
-	if (empty($is_debug))
226
-		$is_debug = $upcontext['upgrade_status']['debug'];
235
+	if (empty($is_debug)) {
236
+			$is_debug = $upcontext['upgrade_status']['debug'];
237
+	}
227 238
 
228 239
 	// Load the language.
229
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
230
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
231
-}
240
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
241
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
242
+	}
243
+	}
232 244
 // Set the defaults.
233 245
 else
234 246
 {
@@ -246,15 +258,18 @@  discard block
 block discarded – undo
246 258
 }
247 259
 
248 260
 // If this isn't the first stage see whether they are logging in and resuming.
249
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
261
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
250 262
 	checkLogin();
263
+}
251 264
 
252
-if ($command_line)
265
+if ($command_line) {
253 266
 	cmdStep0();
267
+}
254 268
 
255 269
 // Don't error if we're using xml.
256
-if (isset($_GET['xml']))
270
+if (isset($_GET['xml'])) {
257 271
 	$upcontext['return_error'] = true;
272
+}
258 273
 
259 274
 // Loop through all the steps doing each one as required.
260 275
 $upcontext['overall_percent'] = 0;
@@ -275,10 +290,11 @@  discard block
 block discarded – undo
275 290
 		}
276 291
 
277 292
 		// Call the step and if it returns false that means pause!
278
-		if (function_exists($step[2]) && $step[2]() === false)
279
-			break;
280
-		elseif (function_exists($step[2]))
281
-			$upcontext['current_step']++;
293
+		if (function_exists($step[2]) && $step[2]() === false) {
294
+					break;
295
+		} elseif (function_exists($step[2])) {
296
+					$upcontext['current_step']++;
297
+		}
282 298
 	}
283 299
 	$upcontext['overall_percent'] += $step[3];
284 300
 }
@@ -317,17 +333,18 @@  discard block
 block discarded – undo
317 333
 		// This should not happen my dear... HELP ME DEVELOPERS!!
318 334
 		if (!empty($command_line))
319 335
 		{
320
-			if (function_exists('debug_print_backtrace'))
321
-				debug_print_backtrace();
336
+			if (function_exists('debug_print_backtrace')) {
337
+							debug_print_backtrace();
338
+			}
322 339
 
323 340
 			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.';
324 341
 			flush();
325 342
 			die();
326 343
 		}
327 344
 
328
-		if (!isset($_GET['xml']))
329
-			template_upgrade_above();
330
-		else
345
+		if (!isset($_GET['xml'])) {
346
+					template_upgrade_above();
347
+		} else
331 348
 		{
332 349
 			header('Content-Type: text/xml; charset=UTF-8');
333 350
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -349,21 +366,24 @@  discard block
 block discarded – undo
349 366
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
350 367
 
351 368
 			// Custom stuff to pass back?
352
-			if (!empty($upcontext['query_string']))
353
-				$upcontext['form_url'] .= $upcontext['query_string'];
369
+			if (!empty($upcontext['query_string'])) {
370
+							$upcontext['form_url'] .= $upcontext['query_string'];
371
+			}
354 372
 
355 373
 			call_user_func('template_' . $upcontext['sub_template']);
356 374
 		}
357 375
 
358 376
 		// Was there an error?
359
-		if (!empty($upcontext['forced_error_message']))
360
-			echo $upcontext['forced_error_message'];
377
+		if (!empty($upcontext['forced_error_message'])) {
378
+					echo $upcontext['forced_error_message'];
379
+		}
361 380
 
362 381
 		// Show the footer.
363
-		if (!isset($_GET['xml']))
364
-			template_upgrade_below();
365
-		else
366
-			template_xml_below();
382
+		if (!isset($_GET['xml'])) {
383
+					template_upgrade_below();
384
+		} else {
385
+					template_xml_below();
386
+		}
367 387
 	}
368 388
 
369 389
 
@@ -375,15 +395,19 @@  discard block
 block discarded – undo
375 395
 		$seconds = intval($active % 60);
376 396
 
377 397
 		$totalTime = '';
378
-		if ($hours > 0)
379
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
380
-		if ($minutes > 0)
381
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
382
-		if ($seconds > 0)
383
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
398
+		if ($hours > 0) {
399
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
400
+		}
401
+		if ($minutes > 0) {
402
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
403
+		}
404
+		if ($seconds > 0) {
405
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
406
+		}
384 407
 
385
-		if (!empty($totalTime))
386
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
408
+		if (!empty($totalTime)) {
409
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
410
+		}
387 411
 	}
388 412
 
389 413
 	// Bang - gone!
@@ -396,8 +420,9 @@  discard block
 block discarded – undo
396 420
 	global $upgradeurl, $upcontext, $command_line;
397 421
 
398 422
 	// Command line users can't be redirected.
399
-	if ($command_line)
400
-		upgradeExit(true);
423
+	if ($command_line) {
424
+			upgradeExit(true);
425
+	}
401 426
 
402 427
 	// Are we providing the core info?
403 428
 	if ($addForm)
@@ -420,19 +445,22 @@  discard block
 block discarded – undo
420 445
 	global $modSettings, $sourcedir, $smcFunc;
421 446
 
422 447
 	// Do the non-SSI stuff...
423
-	if (function_exists('set_magic_quotes_runtime'))
424
-		@set_magic_quotes_runtime(0);
448
+	if (function_exists('set_magic_quotes_runtime')) {
449
+			@set_magic_quotes_runtime(0);
450
+	}
425 451
 
426 452
 	error_reporting(E_ALL);
427 453
 	define('SMF', 1);
428 454
 
429 455
 	// Start the session.
430
-	if (@ini_get('session.save_handler') == 'user')
431
-		@ini_set('session.save_handler', 'files');
456
+	if (@ini_get('session.save_handler') == 'user') {
457
+			@ini_set('session.save_handler', 'files');
458
+	}
432 459
 	@session_start();
433 460
 
434
-	if (empty($smcFunc))
435
-		$smcFunc = array();
461
+	if (empty($smcFunc)) {
462
+			$smcFunc = array();
463
+	}
436 464
 
437 465
 	// We need this for authentication and some upgrade code
438 466
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -444,8 +472,9 @@  discard block
 block discarded – undo
444 472
 	initialize_inputs();
445 473
 
446 474
 	// Get the database going!
447
-	if (empty($db_type) || $db_type == 'mysqli')
448
-		$db_type = 'mysql';
475
+	if (empty($db_type) || $db_type == 'mysqli') {
476
+			$db_type = 'mysql';
477
+	}
449 478
 
450 479
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
451 480
 	{
@@ -455,17 +484,19 @@  discard block
 block discarded – undo
455 484
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
456 485
 
457 486
 		// Oh dear god!!
458
-		if ($db_connection === null)
459
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
487
+		if ($db_connection === null) {
488
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
489
+		}
460 490
 
461
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
462
-			$smcFunc['db_query']('', '
491
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
492
+					$smcFunc['db_query']('', '
463 493
 			SET NAMES {string:db_character_set}',
464 494
 			array(
465 495
 				'db_error_skip' => true,
466 496
 				'db_character_set' => $db_character_set,
467 497
 			)
468 498
 		);
499
+		}
469 500
 
470 501
 		// Load the modSettings data...
471 502
 		$request = $smcFunc['db_query']('', '
@@ -476,11 +507,11 @@  discard block
 block discarded – undo
476 507
 			)
477 508
 		);
478 509
 		$modSettings = array();
479
-		while ($row = $smcFunc['db_fetch_assoc']($request))
480
-			$modSettings[$row['variable']] = $row['value'];
510
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
511
+					$modSettings[$row['variable']] = $row['value'];
512
+		}
481 513
 		$smcFunc['db_free_result']($request);
482
-	}
483
-	else
514
+	} else
484 515
 	{
485 516
 		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.');
486 517
 	}
@@ -494,9 +525,10 @@  discard block
 block discarded – undo
494 525
 		cleanRequest();
495 526
 	}
496 527
 
497
-	if (!isset($_GET['substep']))
498
-		$_GET['substep'] = 0;
499
-}
528
+	if (!isset($_GET['substep'])) {
529
+			$_GET['substep'] = 0;
530
+	}
531
+	}
500 532
 
501 533
 function initialize_inputs()
502 534
 {
@@ -526,8 +558,9 @@  discard block
 block discarded – undo
526 558
 		$dh = opendir(dirname(__FILE__));
527 559
 		while ($file = readdir($dh))
528 560
 		{
529
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
530
-				@unlink(dirname(__FILE__) . '/' . $file);
561
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
562
+							@unlink(dirname(__FILE__) . '/' . $file);
563
+			}
531 564
 		}
532 565
 		closedir($dh);
533 566
 
@@ -556,8 +589,9 @@  discard block
 block discarded – undo
556 589
 	$temp = 'upgrade_php?step';
557 590
 	while (strlen($temp) > 4)
558 591
 	{
559
-		if (isset($_GET[$temp]))
560
-			unset($_GET[$temp]);
592
+		if (isset($_GET[$temp])) {
593
+					unset($_GET[$temp]);
594
+		}
561 595
 		$temp = substr($temp, 1);
562 596
 	}
563 597
 
@@ -584,32 +618,39 @@  discard block
 block discarded – undo
584 618
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
585 619
 
586 620
 	// Need legacy scripts?
587
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
588
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
589
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
590
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
591
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
592
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
621
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
622
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
623
+	}
624
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
625
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
626
+	}
627
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
628
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
629
+	}
593 630
 
594 631
 	// We don't need "-utf8" files anymore...
595 632
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
596 633
 
597 634
 	// This needs to exist!
598
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
599
-		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>]');
600
-	else
601
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
635
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
636
+			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>]');
637
+	} else {
638
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
639
+	}
602 640
 
603
-	if (!$check)
604
-		// 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.
641
+	if (!$check) {
642
+			// 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.
605 643
 		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.');
644
+	}
606 645
 
607 646
 	// Do they meet the install requirements?
608
-	if (!php_version_check())
609
-		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.');
647
+	if (!php_version_check()) {
648
+			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.');
649
+	}
610 650
 
611
-	if (!db_version_check())
612
-		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.');
651
+	if (!db_version_check()) {
652
+			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.');
653
+	}
613 654
 
614 655
 	// Do some checks to make sure they have proper privileges
615 656
 	db_extend('packages');
@@ -624,14 +665,16 @@  discard block
 block discarded – undo
624 665
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
625 666
 
626 667
 	// Sorry... we need CREATE, ALTER and DROP
627
-	if (!$create || !$alter || !$drop)
628
-		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.');
668
+	if (!$create || !$alter || !$drop) {
669
+			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.');
670
+	}
629 671
 
630 672
 	// Do a quick version spot check.
631 673
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
632 674
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
633
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
634
-		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.');
675
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
676
+			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.');
677
+	}
635 678
 
636 679
 	// What absolutely needs to be writable?
637 680
 	$writable_files = array(
@@ -653,12 +696,13 @@  discard block
 block discarded – undo
653 696
 	quickFileWritable($custom_av_dir);
654 697
 
655 698
 	// Are we good now?
656
-	if (!is_writable($custom_av_dir))
657
-		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));
658
-	elseif ($need_settings_update)
699
+	if (!is_writable($custom_av_dir)) {
700
+			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));
701
+	} elseif ($need_settings_update)
659 702
 	{
660
-		if (!function_exists('cache_put_data'))
661
-			require_once($sourcedir . '/Load.php');
703
+		if (!function_exists('cache_put_data')) {
704
+					require_once($sourcedir . '/Load.php');
705
+		}
662 706
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
663 707
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
664 708
 	}
@@ -667,28 +711,33 @@  discard block
 block discarded – undo
667 711
 
668 712
 	// Check the cache directory.
669 713
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
670
-	if (!file_exists($cachedir_temp))
671
-		@mkdir($cachedir_temp);
672
-	if (!file_exists($cachedir_temp))
673
-		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.');
674
-
675
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
676
-		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>.');
677
-	elseif (!isset($_GET['skiplang']))
714
+	if (!file_exists($cachedir_temp)) {
715
+			@mkdir($cachedir_temp);
716
+	}
717
+	if (!file_exists($cachedir_temp)) {
718
+			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.');
719
+	}
720
+
721
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
722
+			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>.');
723
+	} elseif (!isset($_GET['skiplang']))
678 724
 	{
679 725
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
680 726
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
681 727
 
682
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
683
-			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>]');
728
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
729
+					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>]');
730
+		}
684 731
 	}
685 732
 
686
-	if (!makeFilesWritable($writable_files))
687
-		return false;
733
+	if (!makeFilesWritable($writable_files)) {
734
+			return false;
735
+	}
688 736
 
689 737
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
690
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
691
-		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.');
738
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
739
+			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.');
740
+	}
692 741
 
693 742
 	// Upgrade the agreement.
694 743
 	elseif (isset($modSettings['agreement']))
@@ -699,8 +748,8 @@  discard block
 block discarded – undo
699 748
 	}
700 749
 
701 750
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
702
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
703
-		$upcontext['warning'] = '
751
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
752
+			$upcontext['warning'] = '
704 753
 			It looks as if your board directory settings <em>might</em> be incorrect. Your board directory is currently set to &quot;' . $boarddir . '&quot; but should probably be &quot;' . dirname(__FILE__) . '&quot;. Settings.php currently lists your paths as:<br>
705 754
 			<ul>
706 755
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -708,10 +757,12 @@  discard block
 block discarded – undo
708 757
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
709 758
 			</ul>
710 759
 			If these seem incorrect please open Settings.php in a text editor before proceeding with this upgrade. If they are incorrect due to you moving your forum to a new location please download and execute the <a href="https://download.simplemachines.org/?tools">Repair Settings</a> tool from the Simple Machines website before continuing.';
760
+	}
711 761
 
712 762
 	// Either we're logged in or we're going to present the login.
713
-	if (checkLogin())
714
-		return true;
763
+	if (checkLogin()) {
764
+			return true;
765
+	}
715 766
 
716 767
 	$upcontext += createToken('login');
717 768
 
@@ -725,15 +776,17 @@  discard block
 block discarded – undo
725 776
 	global $smcFunc, $db_type, $support_js;
726 777
 
727 778
 	// Don't bother if the security is disabled.
728
-	if ($disable_security)
729
-		return true;
779
+	if ($disable_security) {
780
+			return true;
781
+	}
730 782
 
731 783
 	// Are we trying to login?
732 784
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
733 785
 	{
734 786
 		// If we've disabled security pick a suitable name!
735
-		if (empty($_POST['user']))
736
-			$_POST['user'] = 'Administrator';
787
+		if (empty($_POST['user'])) {
788
+					$_POST['user'] = 'Administrator';
789
+		}
737 790
 
738 791
 		// Before 2.0 these column names were different!
739 792
 		$oldDB = false;
@@ -748,16 +801,17 @@  discard block
 block discarded – undo
748 801
 					'db_error_skip' => true,
749 802
 				)
750 803
 			);
751
-			if ($smcFunc['db_num_rows']($request) != 0)
752
-				$oldDB = true;
804
+			if ($smcFunc['db_num_rows']($request) != 0) {
805
+							$oldDB = true;
806
+			}
753 807
 			$smcFunc['db_free_result']($request);
754 808
 		}
755 809
 
756 810
 		// Get what we believe to be their details.
757 811
 		if (!$disable_security)
758 812
 		{
759
-			if ($oldDB)
760
-				$request = $smcFunc['db_query']('', '
813
+			if ($oldDB) {
814
+							$request = $smcFunc['db_query']('', '
761 815
 					SELECT id_member, memberName AS member_name, passwd, id_group,
762 816
 					additionalGroups AS additional_groups, lngfile
763 817
 					FROM {db_prefix}members
@@ -767,8 +821,8 @@  discard block
 block discarded – undo
767 821
 						'db_error_skip' => true,
768 822
 					)
769 823
 				);
770
-			else
771
-				$request = $smcFunc['db_query']('', '
824
+			} else {
825
+							$request = $smcFunc['db_query']('', '
772 826
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
773 827
 					FROM {db_prefix}members
774 828
 					WHERE member_name = {string:member_name}',
@@ -777,6 +831,7 @@  discard block
 block discarded – undo
777 831
 						'db_error_skip' => true,
778 832
 					)
779 833
 				);
834
+			}
780 835
 			if ($smcFunc['db_num_rows']($request) != 0)
781 836
 			{
782 837
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -784,16 +839,17 @@  discard block
 block discarded – undo
784 839
 				$groups = explode(',', $addGroups);
785 840
 				$groups[] = $id_group;
786 841
 
787
-				foreach ($groups as $k => $v)
788
-					$groups[$k] = (int) $v;
842
+				foreach ($groups as $k => $v) {
843
+									$groups[$k] = (int) $v;
844
+				}
789 845
 
790 846
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
791 847
 
792 848
 				// We don't use "-utf8" anymore...
793 849
 				$user_language = str_ireplace('-utf8', '', $user_language);
850
+			} else {
851
+							$upcontext['username_incorrect'] = true;
794 852
 			}
795
-			else
796
-				$upcontext['username_incorrect'] = true;
797 853
 			$smcFunc['db_free_result']($request);
798 854
 		}
799 855
 		$upcontext['username'] = $_POST['user'];
@@ -803,13 +859,14 @@  discard block
 block discarded – undo
803 859
 		{
804 860
 			$upcontext['upgrade_status']['js'] = 1;
805 861
 			$support_js = 1;
862
+		} else {
863
+					$support_js = 0;
806 864
 		}
807
-		else
808
-			$support_js = 0;
809 865
 
810 866
 		// Note down the version we are coming from.
811
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
812
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
867
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
868
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
869
+		}
813 870
 
814 871
 		// Didn't get anywhere?
815 872
 		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']))
@@ -843,15 +900,15 @@  discard block
 block discarded – undo
843 900
 							'db_error_skip' => true,
844 901
 						)
845 902
 					);
846
-					if ($smcFunc['db_num_rows']($request) == 0)
847
-						return throw_error('You need to be an admin to perform an upgrade!');
903
+					if ($smcFunc['db_num_rows']($request) == 0) {
904
+											return throw_error('You need to be an admin to perform an upgrade!');
905
+					}
848 906
 					$smcFunc['db_free_result']($request);
849 907
 				}
850 908
 
851 909
 				$upcontext['user']['id'] = $id_member;
852 910
 				$upcontext['user']['name'] = $name;
853
-			}
854
-			else
911
+			} else
855 912
 			{
856 913
 				$upcontext['user']['id'] = 1;
857 914
 				$upcontext['user']['name'] = 'Administrator';
@@ -867,11 +924,11 @@  discard block
 block discarded – undo
867 924
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
868 925
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
869 926
 
870
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
871
-					$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'] . '.';
872
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
873
-					$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'] . '.';
874
-				else
927
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
928
+									$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'] . '.';
929
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
930
+									$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'] . '.';
931
+				} else
875 932
 				{
876 933
 					// Set this as the new language.
877 934
 					$upcontext['language'] = $user_language;
@@ -915,8 +972,9 @@  discard block
 block discarded – undo
915 972
 	unset($member_columns);
916 973
 
917 974
 	// If we've not submitted then we're done.
918
-	if (empty($_POST['upcont']))
919
-		return false;
975
+	if (empty($_POST['upcont'])) {
976
+			return false;
977
+	}
920 978
 
921 979
 	// Firstly, if they're enabling SM stat collection just do it.
922 980
 	if (!empty($_POST['stats']) && (substr($boardurl, 0, 16) != 'http://localhost' || substr($boardurl, 0, 16) != 'https://localhost') && empty($modSettings['allow_sm_stats']))
@@ -931,25 +989,26 @@  discard block
 block discarded – undo
931 989
 			fwrite($fp, $out);
932 990
 
933 991
 			$return_data = '';
934
-			while (!feof($fp))
935
-				$return_data .= fgets($fp, 128);
992
+			while (!feof($fp)) {
993
+							$return_data .= fgets($fp, 128);
994
+			}
936 995
 
937 996
 			fclose($fp);
938 997
 
939 998
 			// Get the unique site ID.
940 999
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
941 1000
 
942
-			if (!empty($ID[1]))
943
-				$smcFunc['db_insert']('replace',
1001
+			if (!empty($ID[1])) {
1002
+							$smcFunc['db_insert']('replace',
944 1003
 					$db_prefix . 'settings',
945 1004
 					array('variable' => 'string', 'value' => 'string'),
946 1005
 					array('allow_sm_stats', $ID[1]),
947 1006
 					array('variable')
948 1007
 				);
1008
+			}
949 1009
 		}
950
-	}
951
-	else
952
-		$smcFunc['db_query']('', '
1010
+	} else {
1011
+			$smcFunc['db_query']('', '
953 1012
 			DELETE FROM {db_prefix}settings
954 1013
 			WHERE variable = {string:allow_sm_stats}',
955 1014
 			array(
@@ -957,6 +1016,7 @@  discard block
 block discarded – undo
957 1016
 				'db_error_skip' => true,
958 1017
 			)
959 1018
 		);
1019
+	}
960 1020
 
961 1021
 	// Deleting old karma stuff?
962 1022
 	if (!empty($_POST['delete_karma']))
@@ -971,20 +1031,22 @@  discard block
 block discarded – undo
971 1031
 		);
972 1032
 
973 1033
 		// Cleaning up old karma member settings.
974
-		if ($upcontext['karma_installed']['good'])
975
-			$smcFunc['db_query']('', '
1034
+		if ($upcontext['karma_installed']['good']) {
1035
+					$smcFunc['db_query']('', '
976 1036
 				ALTER TABLE {db_prefix}members
977 1037
 				DROP karma_good',
978 1038
 				array()
979 1039
 			);
1040
+		}
980 1041
 
981 1042
 		// Does karma bad was enable?
982
-		if ($upcontext['karma_installed']['bad'])
983
-			$smcFunc['db_query']('', '
1043
+		if ($upcontext['karma_installed']['bad']) {
1044
+					$smcFunc['db_query']('', '
984 1045
 				ALTER TABLE {db_prefix}members
985 1046
 				DROP karma_bad',
986 1047
 				array()
987 1048
 			);
1049
+		}
988 1050
 
989 1051
 		// Cleaning up old karma permissions.
990 1052
 		$smcFunc['db_query']('', '
@@ -997,26 +1059,29 @@  discard block
 block discarded – undo
997 1059
 	}
998 1060
 
999 1061
 	// Emptying the error log?
1000
-	if (!empty($_POST['empty_error']))
1001
-		$smcFunc['db_query']('truncate_table', '
1062
+	if (!empty($_POST['empty_error'])) {
1063
+			$smcFunc['db_query']('truncate_table', '
1002 1064
 			TRUNCATE {db_prefix}log_errors',
1003 1065
 			array(
1004 1066
 			)
1005 1067
 		);
1068
+	}
1006 1069
 
1007 1070
 	$changes = array();
1008 1071
 
1009 1072
 	// Add proxy settings.
1010
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1011
-		$changes += array(
1073
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1074
+			$changes += array(
1012 1075
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1013 1076
 			'image_proxy_maxsize' => 5190,
1014 1077
 			'image_proxy_enabled' => 0,
1015 1078
 		);
1079
+	}
1016 1080
 
1017 1081
 	// If we're overriding the language follow it through.
1018
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1019
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1082
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1083
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1084
+	}
1020 1085
 
1021 1086
 	if (!empty($_POST['maint']))
1022 1087
 	{
@@ -1028,30 +1093,34 @@  discard block
 block discarded – undo
1028 1093
 		{
1029 1094
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1030 1095
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1031
-		}
1032
-		else
1096
+		} else
1033 1097
 		{
1034 1098
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1035 1099
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1036 1100
 		}
1037 1101
 	}
1038 1102
 
1039
-	if ($command_line)
1040
-		echo ' * Updating Settings.php...';
1103
+	if ($command_line) {
1104
+			echo ' * Updating Settings.php...';
1105
+	}
1041 1106
 
1042 1107
 	// Fix some old paths.
1043
-	if (substr($boarddir, 0, 1) == '.')
1044
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1108
+	if (substr($boarddir, 0, 1) == '.') {
1109
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1110
+	}
1045 1111
 
1046
-	if (substr($sourcedir, 0, 1) == '.')
1047
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1112
+	if (substr($sourcedir, 0, 1) == '.') {
1113
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1114
+	}
1048 1115
 
1049
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1050
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1116
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1117
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1118
+	}
1051 1119
 
1052 1120
 	// Not had the database type added before?
1053
-	if (empty($db_type))
1054
-		$changes['db_type'] = 'mysql';
1121
+	if (empty($db_type)) {
1122
+			$changes['db_type'] = 'mysql';
1123
+	}
1055 1124
 
1056 1125
 	// If they have a "host:port" setup for the host, split that into separate values
1057 1126
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1062,32 +1131,36 @@  discard block
 block discarded – undo
1062 1131
 		$changes['db_server'] = '\'' . $db_server . '\'';
1063 1132
 
1064 1133
 		// Only set this if we're not using the default port
1065
-		if ($db_port != ini_get('mysqli.default_port'))
1066
-			$changes['db_port'] = (int) $db_port;
1067
-	}
1068
-	elseif (!empty($db_port))
1134
+		if ($db_port != ini_get('mysqli.default_port')) {
1135
+					$changes['db_port'] = (int) $db_port;
1136
+		}
1137
+	} elseif (!empty($db_port))
1069 1138
 	{
1070 1139
 		// If db_port is set and is the same as the default, set it to ''
1071 1140
 		if ($db_type == 'mysql')
1072 1141
 		{
1073
-			if ($db_port == ini_get('mysqli.default_port'))
1074
-				$changes['db_port'] = '\'\'';
1075
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1076
-				$changes['db_port'] = '\'\'';
1142
+			if ($db_port == ini_get('mysqli.default_port')) {
1143
+							$changes['db_port'] = '\'\'';
1144
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1145
+							$changes['db_port'] = '\'\'';
1146
+			}
1077 1147
 		}
1078 1148
 	}
1079 1149
 
1080 1150
 	// Maybe we haven't had this option yet?
1081
-	if (empty($packagesdir))
1082
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1151
+	if (empty($packagesdir)) {
1152
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1153
+	}
1083 1154
 
1084 1155
 	// Add support for $tasksdir var.
1085
-	if (empty($tasksdir))
1086
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1156
+	if (empty($tasksdir)) {
1157
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1158
+	}
1087 1159
 
1088 1160
 	// Make sure we fix the language as well.
1089
-	if (stristr($language, '-utf8'))
1090
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1161
+	if (stristr($language, '-utf8')) {
1162
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1163
+	}
1091 1164
 
1092 1165
 	// @todo Maybe change the cookie name if going to 1.1, too?
1093 1166
 
@@ -1095,8 +1168,9 @@  discard block
 block discarded – undo
1095 1168
 	require_once($sourcedir . '/Subs-Admin.php');
1096 1169
 	updateSettingsFile($changes);
1097 1170
 
1098
-	if ($command_line)
1099
-		echo ' Successful.' . "\n";
1171
+	if ($command_line) {
1172
+			echo ' Successful.' . "\n";
1173
+	}
1100 1174
 
1101 1175
 	// Are we doing debug?
1102 1176
 	if (isset($_POST['debug']))
@@ -1106,8 +1180,9 @@  discard block
 block discarded – undo
1106 1180
 	}
1107 1181
 
1108 1182
 	// If we're not backing up then jump one.
1109
-	if (empty($_POST['backup']))
1110
-		$upcontext['current_step']++;
1183
+	if (empty($_POST['backup'])) {
1184
+			$upcontext['current_step']++;
1185
+	}
1111 1186
 
1112 1187
 	// If we've got here then let's proceed to the next step!
1113 1188
 	return true;
@@ -1122,8 +1197,9 @@  discard block
 block discarded – undo
1122 1197
 	$upcontext['page_title'] = 'Backup Database';
1123 1198
 
1124 1199
 	// Done it already - js wise?
1125
-	if (!empty($_POST['backup_done']))
1126
-		return true;
1200
+	if (!empty($_POST['backup_done'])) {
1201
+			return true;
1202
+	}
1127 1203
 
1128 1204
 	// Some useful stuff here.
1129 1205
 	db_extend();
@@ -1137,9 +1213,10 @@  discard block
 block discarded – undo
1137 1213
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1138 1214
 
1139 1215
 	$table_names = array();
1140
-	foreach ($tables as $table)
1141
-		if (substr($table, 0, 7) !== 'backup_')
1216
+	foreach ($tables as $table) {
1217
+			if (substr($table, 0, 7) !== 'backup_')
1142 1218
 			$table_names[] = $table;
1219
+	}
1143 1220
 
1144 1221
 	$upcontext['table_count'] = count($table_names);
1145 1222
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1149,12 +1226,14 @@  discard block
 block discarded – undo
1149 1226
 	$file_steps = $upcontext['table_count'];
1150 1227
 
1151 1228
 	// What ones have we already done?
1152
-	foreach ($table_names as $id => $table)
1153
-		if ($id < $_GET['substep'])
1229
+	foreach ($table_names as $id => $table) {
1230
+			if ($id < $_GET['substep'])
1154 1231
 			$upcontext['previous_tables'][] = $table;
1232
+	}
1155 1233
 
1156
-	if ($command_line)
1157
-		echo 'Backing Up Tables.';
1234
+	if ($command_line) {
1235
+			echo 'Backing Up Tables.';
1236
+	}
1158 1237
 
1159 1238
 	// If we don't support javascript we backup here.
1160 1239
 	if (!$support_js || isset($_GET['xml']))
@@ -1173,8 +1252,9 @@  discard block
 block discarded – undo
1173 1252
 			backupTable($table_names[$substep]);
1174 1253
 
1175 1254
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1176
-			if (isset($_GET['xml']))
1177
-				return upgradeExit();
1255
+			if (isset($_GET['xml'])) {
1256
+							return upgradeExit();
1257
+			}
1178 1258
 		}
1179 1259
 
1180 1260
 		if ($command_line)
@@ -1207,9 +1287,10 @@  discard block
 block discarded – undo
1207 1287
 
1208 1288
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1209 1289
 
1210
-	if ($command_line)
1211
-		echo ' done.';
1212
-}
1290
+	if ($command_line) {
1291
+			echo ' done.';
1292
+	}
1293
+	}
1213 1294
 
1214 1295
 // Step 2: Everything.
1215 1296
 function DatabaseChanges()
@@ -1218,8 +1299,9 @@  discard block
 block discarded – undo
1218 1299
 	global $upcontext, $support_js, $db_type;
1219 1300
 
1220 1301
 	// Have we just completed this?
1221
-	if (!empty($_POST['database_done']))
1222
-		return true;
1302
+	if (!empty($_POST['database_done'])) {
1303
+			return true;
1304
+	}
1223 1305
 
1224 1306
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1225 1307
 	$upcontext['page_title'] = 'Database Changes';
@@ -1234,15 +1316,16 @@  discard block
 block discarded – undo
1234 1316
 	);
1235 1317
 
1236 1318
 	// How many files are there in total?
1237
-	if (isset($_GET['filecount']))
1238
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1239
-	else
1319
+	if (isset($_GET['filecount'])) {
1320
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1321
+	} else
1240 1322
 	{
1241 1323
 		$upcontext['file_count'] = 0;
1242 1324
 		foreach ($files as $file)
1243 1325
 		{
1244
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1245
-				$upcontext['file_count']++;
1326
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1327
+							$upcontext['file_count']++;
1328
+			}
1246 1329
 		}
1247 1330
 	}
1248 1331
 
@@ -1252,9 +1335,9 @@  discard block
 block discarded – undo
1252 1335
 	$upcontext['cur_file_num'] = 0;
1253 1336
 	foreach ($files as $file)
1254 1337
 	{
1255
-		if ($did_not_do)
1256
-			$did_not_do--;
1257
-		else
1338
+		if ($did_not_do) {
1339
+					$did_not_do--;
1340
+		} else
1258 1341
 		{
1259 1342
 			$upcontext['cur_file_num']++;
1260 1343
 			$upcontext['cur_file_name'] = $file[0];
@@ -1281,12 +1364,13 @@  discard block
 block discarded – undo
1281 1364
 					// Flag to move on to the next.
1282 1365
 					$upcontext['completed_step'] = true;
1283 1366
 					// Did we complete the whole file?
1284
-					if ($nextFile)
1285
-						$upcontext['current_debug_item_num'] = -1;
1367
+					if ($nextFile) {
1368
+											$upcontext['current_debug_item_num'] = -1;
1369
+					}
1286 1370
 					return upgradeExit();
1371
+				} elseif ($support_js) {
1372
+									break;
1287 1373
 				}
1288
-				elseif ($support_js)
1289
-					break;
1290 1374
 			}
1291 1375
 			// Set the progress bar to be right as if we had - even if we hadn't...
1292 1376
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1311,8 +1395,9 @@  discard block
 block discarded – undo
1311 1395
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1312 1396
 
1313 1397
 	// Now it's nice to have some of the basic SMF source files.
1314
-	if (!isset($_GET['ssi']) && !$command_line)
1315
-		redirectLocation('&ssi=1');
1398
+	if (!isset($_GET['ssi']) && !$command_line) {
1399
+			redirectLocation('&ssi=1');
1400
+	}
1316 1401
 
1317 1402
 	$upcontext['sub_template'] = 'upgrade_complete';
1318 1403
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1328,14 +1413,16 @@  discard block
 block discarded – undo
1328 1413
 	// Are we in maintenance mode?
1329 1414
 	if (isset($upcontext['user']['main']))
1330 1415
 	{
1331
-		if ($command_line)
1332
-			echo ' * ';
1416
+		if ($command_line) {
1417
+					echo ' * ';
1418
+		}
1333 1419
 		$upcontext['removed_maintenance'] = true;
1334 1420
 		$changes['maintenance'] = $upcontext['user']['main'];
1335 1421
 	}
1336 1422
 	// Otherwise if somehow we are in 2 let's go to 1.
1337
-	elseif (!empty($maintenance) && $maintenance == 2)
1338
-		$changes['maintenance'] = 1;
1423
+	elseif (!empty($maintenance) && $maintenance == 2) {
1424
+			$changes['maintenance'] = 1;
1425
+	}
1339 1426
 
1340 1427
 	// Wipe this out...
1341 1428
 	$upcontext['user'] = array();
@@ -1350,9 +1437,9 @@  discard block
 block discarded – undo
1350 1437
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1351 1438
 
1352 1439
 	// Now is the perfect time to fetch the SM files.
1353
-	if ($command_line)
1354
-		cli_scheduled_fetchSMfiles();
1355
-	else
1440
+	if ($command_line) {
1441
+			cli_scheduled_fetchSMfiles();
1442
+	} else
1356 1443
 	{
1357 1444
 		require_once($sourcedir . '/ScheduledTasks.php');
1358 1445
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1360,8 +1447,9 @@  discard block
 block discarded – undo
1360 1447
 	}
1361 1448
 
1362 1449
 	// Log what we've done.
1363
-	if (empty($user_info['id']))
1364
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1450
+	if (empty($user_info['id'])) {
1451
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1452
+	}
1365 1453
 
1366 1454
 	// Log the action manually, so CLI still works.
1367 1455
 	$smcFunc['db_insert']('',
@@ -1380,8 +1468,9 @@  discard block
 block discarded – undo
1380 1468
 
1381 1469
 	// Save the current database version.
1382 1470
 	$server_version = $smcFunc['db_server_info']();
1383
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1384
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1471
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1472
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1473
+	}
1385 1474
 
1386 1475
 	if ($command_line)
1387 1476
 	{
@@ -1393,8 +1482,9 @@  discard block
 block discarded – undo
1393 1482
 
1394 1483
 	// Make sure it says we're done.
1395 1484
 	$upcontext['overall_percent'] = 100;
1396
-	if (isset($upcontext['step_progress']))
1397
-		unset($upcontext['step_progress']);
1485
+	if (isset($upcontext['step_progress'])) {
1486
+			unset($upcontext['step_progress']);
1487
+	}
1398 1488
 
1399 1489
 	$_GET['substep'] = 0;
1400 1490
 	return false;
@@ -1405,8 +1495,9 @@  discard block
 block discarded – undo
1405 1495
 {
1406 1496
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1407 1497
 
1408
-	if (empty($modSettings['time_format']))
1409
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1498
+	if (empty($modSettings['time_format'])) {
1499
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1500
+	}
1410 1501
 
1411 1502
 	// What files do we want to get
1412 1503
 	$request = $smcFunc['db_query']('', '
@@ -1440,8 +1531,9 @@  discard block
 block discarded – undo
1440 1531
 		$file_data = fetch_web_data($url);
1441 1532
 
1442 1533
 		// If we got an error - give up - the site might be down.
1443
-		if ($file_data === false)
1444
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1534
+		if ($file_data === false) {
1535
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1536
+		}
1445 1537
 
1446 1538
 		// Save the file to the database.
1447 1539
 		$smcFunc['db_query']('substring', '
@@ -1483,8 +1575,9 @@  discard block
 block discarded – undo
1483 1575
 	$themeData = array();
1484 1576
 	foreach ($values as $variable => $value)
1485 1577
 	{
1486
-		if (!isset($value) || $value === null)
1487
-			$value = 0;
1578
+		if (!isset($value) || $value === null) {
1579
+					$value = 0;
1580
+		}
1488 1581
 
1489 1582
 		$themeData[] = array(0, 1, $variable, $value);
1490 1583
 	}
@@ -1513,8 +1606,9 @@  discard block
 block discarded – undo
1513 1606
 
1514 1607
 	foreach ($values as $variable => $value)
1515 1608
 	{
1516
-		if (empty($modSettings[$value[0]]))
1517
-			continue;
1609
+		if (empty($modSettings[$value[0]])) {
1610
+					continue;
1611
+		}
1518 1612
 
1519 1613
 		$smcFunc['db_query']('', '
1520 1614
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1600,10 +1694,11 @@  discard block
 block discarded – undo
1600 1694
 	set_error_handler(
1601 1695
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1602 1696
 		{
1603
-			if ($support_js)
1604
-				return true;
1605
-			else
1606
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1697
+			if ($support_js) {
1698
+							return true;
1699
+			} else {
1700
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1701
+			}
1607 1702
 		}
1608 1703
 	);
1609 1704
 
@@ -1618,8 +1713,9 @@  discard block
 block discarded – undo
1618 1713
 				'db_error_skip' => true,
1619 1714
 			)
1620 1715
 		);
1621
-		if ($smcFunc['db_num_rows']($request) === 0)
1622
-			die('Unable to find members table!');
1716
+		if ($smcFunc['db_num_rows']($request) === 0) {
1717
+					die('Unable to find members table!');
1718
+		}
1623 1719
 		$table_status = $smcFunc['db_fetch_assoc']($request);
1624 1720
 		$smcFunc['db_free_result']($request);
1625 1721
 
@@ -1634,17 +1730,20 @@  discard block
 block discarded – undo
1634 1730
 				)
1635 1731
 			);
1636 1732
 			// Got something?
1637
-			if ($smcFunc['db_num_rows']($request) !== 0)
1638
-				$collation_info = $smcFunc['db_fetch_assoc']($request);
1733
+			if ($smcFunc['db_num_rows']($request) !== 0) {
1734
+							$collation_info = $smcFunc['db_fetch_assoc']($request);
1735
+			}
1639 1736
 			$smcFunc['db_free_result']($request);
1640 1737
 
1641 1738
 			// Excellent!
1642
-			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset']))
1643
-				$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1739
+			if (!empty($collation_info['Collation']) && !empty($collation_info['Charset'])) {
1740
+							$db_collation = ' CHARACTER SET ' . $collation_info['Charset'] . ' COLLATE ' . $collation_info['Collation'];
1741
+			}
1644 1742
 		}
1645 1743
 	}
1646
-	if (empty($db_collation))
1647
-		$db_collation = '';
1744
+	if (empty($db_collation)) {
1745
+			$db_collation = '';
1746
+	}
1648 1747
 
1649 1748
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1650 1749
 
@@ -1656,8 +1755,9 @@  discard block
 block discarded – undo
1656 1755
 	$last_step = '';
1657 1756
 
1658 1757
 	// Make sure all newly created tables will have the proper characters set.
1659
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1660
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1758
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1759
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1760
+	}
1661 1761
 
1662 1762
 	// Count the total number of steps within this file - for progress.
1663 1763
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1677,15 +1777,18 @@  discard block
 block discarded – undo
1677 1777
 		$do_current = $substep >= $_GET['substep'];
1678 1778
 
1679 1779
 		// Get rid of any comments in the beginning of the line...
1680
-		if (substr(trim($line), 0, 2) === '/*')
1681
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1780
+		if (substr(trim($line), 0, 2) === '/*') {
1781
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1782
+		}
1682 1783
 
1683 1784
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1684
-		if ($is_debug && !$support_js && $command_line)
1685
-			flush();
1785
+		if ($is_debug && !$support_js && $command_line) {
1786
+					flush();
1787
+		}
1686 1788
 
1687
-		if (trim($line) === '')
1688
-			continue;
1789
+		if (trim($line) === '') {
1790
+					continue;
1791
+		}
1689 1792
 
1690 1793
 		if (trim(substr($line, 0, 3)) === '---')
1691 1794
 		{
@@ -1695,8 +1798,9 @@  discard block
 block discarded – undo
1695 1798
 			if (trim($current_data) != '' && $type !== '}')
1696 1799
 			{
1697 1800
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1698
-				if ($command_line)
1699
-					echo $upcontext['error_message'];
1801
+				if ($command_line) {
1802
+									echo $upcontext['error_message'];
1803
+				}
1700 1804
 			}
1701 1805
 
1702 1806
 			if ($type == ' ')
@@ -1714,17 +1818,18 @@  discard block
 block discarded – undo
1714 1818
 				if ($do_current)
1715 1819
 				{
1716 1820
 					$upcontext['actioned_items'][] = $last_step;
1717
-					if ($command_line)
1718
-						echo ' * ';
1821
+					if ($command_line) {
1822
+											echo ' * ';
1823
+					}
1719 1824
 				}
1720
-			}
1721
-			elseif ($type == '#')
1825
+			} elseif ($type == '#')
1722 1826
 			{
1723 1827
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1724 1828
 
1725 1829
 				$upcontext['current_debug_item_num']++;
1726
-				if (trim($line) != '---#')
1727
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1830
+				if (trim($line) != '---#') {
1831
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1832
+				}
1728 1833
 
1729 1834
 				// Have we already done something?
1730 1835
 				if (isset($_GET['xml']) && $done_something)
@@ -1735,34 +1840,36 @@  discard block
 block discarded – undo
1735 1840
 
1736 1841
 				if ($do_current)
1737 1842
 				{
1738
-					if (trim($line) == '---#' && $command_line)
1739
-						echo ' done.', $endl;
1740
-					elseif ($command_line)
1741
-						echo ' +++ ', rtrim(substr($line, 4));
1742
-					elseif (trim($line) != '---#')
1843
+					if (trim($line) == '---#' && $command_line) {
1844
+											echo ' done.', $endl;
1845
+					} elseif ($command_line) {
1846
+											echo ' +++ ', rtrim(substr($line, 4));
1847
+					} elseif (trim($line) != '---#')
1743 1848
 					{
1744
-						if ($is_debug)
1745
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1849
+						if ($is_debug) {
1850
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1851
+						}
1746 1852
 					}
1747 1853
 				}
1748 1854
 
1749 1855
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1750 1856
 				{
1751
-					if ($command_line)
1752
-						echo ' * ';
1753
-					else
1754
-						$upcontext['actioned_items'][] = $last_step;
1857
+					if ($command_line) {
1858
+											echo ' * ';
1859
+					} else {
1860
+											$upcontext['actioned_items'][] = $last_step;
1861
+					}
1755 1862
 				}
1756 1863
 
1757 1864
 				// Small step - only if we're actually doing stuff.
1758
-				if ($do_current)
1759
-					nextSubstep(++$substep);
1760
-				else
1761
-					$substep++;
1762
-			}
1763
-			elseif ($type == '{')
1764
-				$current_type = 'code';
1765
-			elseif ($type == '}')
1865
+				if ($do_current) {
1866
+									nextSubstep(++$substep);
1867
+				} else {
1868
+									$substep++;
1869
+				}
1870
+			} elseif ($type == '{') {
1871
+							$current_type = 'code';
1872
+			} elseif ($type == '}')
1766 1873
 			{
1767 1874
 				$current_type = 'sql';
1768 1875
 
@@ -1775,8 +1882,9 @@  discard block
 block discarded – undo
1775 1882
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1776 1883
 				{
1777 1884
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1778
-					if ($command_line)
1779
-						echo $upcontext['error_message'];
1885
+					if ($command_line) {
1886
+											echo $upcontext['error_message'];
1887
+					}
1780 1888
 				}
1781 1889
 
1782 1890
 				// Done with code!
@@ -1856,8 +1964,9 @@  discard block
 block discarded – undo
1856 1964
 	$db_unbuffered = false;
1857 1965
 
1858 1966
 	// Failure?!
1859
-	if ($result !== false)
1860
-		return $result;
1967
+	if ($result !== false) {
1968
+			return $result;
1969
+	}
1861 1970
 
1862 1971
 	$db_error_message = $smcFunc['db_error']($db_connection);
1863 1972
 	// If MySQL we do something more clever.
@@ -1885,54 +1994,61 @@  discard block
 block discarded – undo
1885 1994
 			{
1886 1995
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1887 1996
 				$result = mysqli_query($db_connection, $string);
1888
-				if ($result !== false)
1889
-					return $result;
1997
+				if ($result !== false) {
1998
+									return $result;
1999
+				}
1890 2000
 			}
1891
-		}
1892
-		elseif ($mysqli_errno == 2013)
2001
+		} elseif ($mysqli_errno == 2013)
1893 2002
 		{
1894 2003
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1895 2004
 			mysqli_select_db($db_connection, $db_name);
1896 2005
 			if ($db_connection)
1897 2006
 			{
1898 2007
 				$result = mysqli_query($db_connection, $string);
1899
-				if ($result !== false)
1900
-					return $result;
2008
+				if ($result !== false) {
2009
+									return $result;
2010
+				}
1901 2011
 			}
1902 2012
 		}
1903 2013
 		// Duplicate column name... should be okay ;).
1904
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1905
-			return false;
2014
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2015
+					return false;
2016
+		}
1906 2017
 		// Duplicate insert... make sure it's the proper type of query ;).
1907
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1908
-			return false;
2018
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2019
+					return false;
2020
+		}
1909 2021
 		// Creating an index on a non-existent column.
1910
-		elseif ($mysqli_errno == 1072)
1911
-			return false;
1912
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1913
-			return false;
2022
+		elseif ($mysqli_errno == 1072) {
2023
+					return false;
2024
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2025
+					return false;
2026
+		}
1914 2027
 	}
1915 2028
 	// If a table already exists don't go potty.
1916 2029
 	else
1917 2030
 	{
1918 2031
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1919 2032
 		{
1920
-			if (strpos($db_error_message, 'exist') !== false)
1921
-				return true;
1922
-		}
1923
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2033
+			if (strpos($db_error_message, 'exist') !== false) {
2034
+							return true;
2035
+			}
2036
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1924 2037
 		{
1925
-			if (strpos($db_error_message, 'duplicate') !== false)
1926
-				return true;
2038
+			if (strpos($db_error_message, 'duplicate') !== false) {
2039
+							return true;
2040
+			}
1927 2041
 		}
1928 2042
 	}
1929 2043
 
1930 2044
 	// Get the query string so we pass everything.
1931 2045
 	$query_string = '';
1932
-	foreach ($_GET as $k => $v)
1933
-		$query_string .= ';' . $k . '=' . $v;
1934
-	if (strlen($query_string) != 0)
1935
-		$query_string = '?' . substr($query_string, 1);
2046
+	foreach ($_GET as $k => $v) {
2047
+			$query_string .= ';' . $k . '=' . $v;
2048
+	}
2049
+	if (strlen($query_string) != 0) {
2050
+			$query_string = '?' . substr($query_string, 1);
2051
+	}
1936 2052
 
1937 2053
 	if ($command_line)
1938 2054
 	{
@@ -1987,16 +2103,18 @@  discard block
 block discarded – undo
1987 2103
 			{
1988 2104
 				$found |= 1;
1989 2105
 				// Do some checks on the data if we have it set.
1990
-				if (isset($change['col_type']))
1991
-					$found &= $change['col_type'] === $column['type'];
1992
-				if (isset($change['null_allowed']))
1993
-					$found &= $column['null'] == $change['null_allowed'];
1994
-				if (isset($change['default']))
1995
-					$found &= $change['default'] === $column['default'];
2106
+				if (isset($change['col_type'])) {
2107
+									$found &= $change['col_type'] === $column['type'];
2108
+				}
2109
+				if (isset($change['null_allowed'])) {
2110
+									$found &= $column['null'] == $change['null_allowed'];
2111
+				}
2112
+				if (isset($change['default'])) {
2113
+									$found &= $change['default'] === $column['default'];
2114
+				}
1996 2115
 			}
1997 2116
 		}
1998
-	}
1999
-	elseif ($change['type'] === 'index')
2117
+	} elseif ($change['type'] === 'index')
2000 2118
 	{
2001 2119
 		$request = upgrade_query('
2002 2120
 			SHOW INDEX
@@ -2005,9 +2123,10 @@  discard block
 block discarded – undo
2005 2123
 		{
2006 2124
 			$cur_index = array();
2007 2125
 
2008
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2009
-				if ($row['Key_name'] === $change['name'])
2126
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2127
+							if ($row['Key_name'] === $change['name'])
2010 2128
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2129
+			}
2011 2130
 
2012 2131
 			ksort($cur_index, SORT_NUMERIC);
2013 2132
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2017,14 +2136,17 @@  discard block
 block discarded – undo
2017 2136
 	}
2018 2137
 
2019 2138
 	// If we're trying to add and it's added, we're done.
2020
-	if ($found && in_array($change['method'], array('add', 'change')))
2021
-		return true;
2139
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2140
+			return true;
2141
+	}
2022 2142
 	// Otherwise if we're removing and it wasn't found we're also done.
2023
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2024
-		return true;
2143
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2144
+			return true;
2145
+	}
2025 2146
 	// Otherwise is it just a test?
2026
-	elseif ($is_test)
2027
-		return false;
2147
+	elseif ($is_test) {
2148
+			return false;
2149
+	}
2028 2150
 
2029 2151
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2030 2152
 	$running = false;
@@ -2035,8 +2157,9 @@  discard block
 block discarded – undo
2035 2157
 			SHOW FULL PROCESSLIST');
2036 2158
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2037 2159
 		{
2038
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2039
-				$found = true;
2160
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2161
+							$found = true;
2162
+			}
2040 2163
 		}
2041 2164
 
2042 2165
 		// Can't find it? Then we need to run it fools!
@@ -2048,8 +2171,9 @@  discard block
 block discarded – undo
2048 2171
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2049 2172
 				' . $change['text'], true) !== false;
2050 2173
 
2051
-			if (!$success)
2052
-				return false;
2174
+			if (!$success) {
2175
+							return false;
2176
+			}
2053 2177
 
2054 2178
 			// Return
2055 2179
 			$running = true;
@@ -2091,8 +2215,9 @@  discard block
 block discarded – undo
2091 2215
 			'db_error_skip' => true,
2092 2216
 		)
2093 2217
 	);
2094
-	if ($smcFunc['db_num_rows']($request) === 0)
2095
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2218
+	if ($smcFunc['db_num_rows']($request) === 0) {
2219
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2220
+	}
2096 2221
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2097 2222
 	$smcFunc['db_free_result']($request);
2098 2223
 
@@ -2114,18 +2239,19 @@  discard block
 block discarded – undo
2114 2239
 			)
2115 2240
 		);
2116 2241
 		// No results? Just forget it all together.
2117
-		if ($smcFunc['db_num_rows']($request) === 0)
2118
-			unset($table_row['Collation']);
2119
-		else
2120
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2242
+		if ($smcFunc['db_num_rows']($request) === 0) {
2243
+					unset($table_row['Collation']);
2244
+		} else {
2245
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2246
+		}
2121 2247
 		$smcFunc['db_free_result']($request);
2122 2248
 	}
2123 2249
 
2124 2250
 	if ($column_fix)
2125 2251
 	{
2126 2252
 		// Make sure there are no NULL's left.
2127
-		if ($null_fix)
2128
-			$smcFunc['db_query']('', '
2253
+		if ($null_fix) {
2254
+					$smcFunc['db_query']('', '
2129 2255
 				UPDATE {db_prefix}' . $change['table'] . '
2130 2256
 				SET ' . $change['column'] . ' = {string:default}
2131 2257
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2134,6 +2260,7 @@  discard block
 block discarded – undo
2134 2260
 					'db_error_skip' => true,
2135 2261
 				)
2136 2262
 			);
2263
+		}
2137 2264
 
2138 2265
 		// Do the actual alteration.
2139 2266
 		$smcFunc['db_query']('', '
@@ -2162,8 +2289,9 @@  discard block
 block discarded – undo
2162 2289
 	}
2163 2290
 
2164 2291
 	// Not a column we need to check on?
2165
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2166
-		return;
2292
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2293
+			return;
2294
+	}
2167 2295
 
2168 2296
 	// Break it up you (six|seven).
2169 2297
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2182,13 +2310,13 @@  discard block
 block discarded – undo
2182 2310
 				'new_name' => $temp[2],
2183 2311
 		));
2184 2312
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2185
-		if ($smcFunc['db_num_rows'] != 1)
2186
-			return;
2313
+		if ($smcFunc['db_num_rows'] != 1) {
2314
+					return;
2315
+		}
2187 2316
 
2188 2317
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2189 2318
 		$smcFunc['db_free_result']($request);
2190
-	}
2191
-	else
2319
+	} else
2192 2320
 	{
2193 2321
 		// Do this the old fashion, sure method way.
2194 2322
 		$request = $smcFunc['db_query']('', '
@@ -2199,21 +2327,24 @@  discard block
 block discarded – undo
2199 2327
 		));
2200 2328
 		// Mayday!
2201 2329
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2202
-		if ($smcFunc['db_num_rows'] == 0)
2203
-			return;
2330
+		if ($smcFunc['db_num_rows'] == 0) {
2331
+					return;
2332
+		}
2204 2333
 
2205 2334
 		// Oh where, oh where has my little field gone. Oh where can it be...
2206
-		while ($row = $smcFunc['db_query']($request))
2207
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2335
+		while ($row = $smcFunc['db_query']($request)) {
2336
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2208 2337
 			{
2209 2338
 				$current_type = $row['Type'];
2339
+		}
2210 2340
 				break;
2211 2341
 			}
2212 2342
 	}
2213 2343
 
2214 2344
 	// If this doesn't match, the column may of been altered for a reason.
2215
-	if (trim($current_type) != trim($temp[3]))
2216
-		$temp[3] = $current_type;
2345
+	if (trim($current_type) != trim($temp[3])) {
2346
+			$temp[3] = $current_type;
2347
+	}
2217 2348
 
2218 2349
 	// Piece this back together.
2219 2350
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2225,8 +2356,9 @@  discard block
 block discarded – undo
2225 2356
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2226 2357
 	global $step_progress, $is_debug, $upcontext;
2227 2358
 
2228
-	if ($_GET['substep'] < $substep)
2229
-		$_GET['substep'] = $substep;
2359
+	if ($_GET['substep'] < $substep) {
2360
+			$_GET['substep'] = $substep;
2361
+	}
2230 2362
 
2231 2363
 	if ($command_line)
2232 2364
 	{
@@ -2239,29 +2371,33 @@  discard block
 block discarded – undo
2239 2371
 	}
2240 2372
 
2241 2373
 	@set_time_limit(300);
2242
-	if (function_exists('apache_reset_timeout'))
2243
-		@apache_reset_timeout();
2374
+	if (function_exists('apache_reset_timeout')) {
2375
+			@apache_reset_timeout();
2376
+	}
2244 2377
 
2245
-	if (time() - $start_time <= $timeLimitThreshold)
2246
-		return;
2378
+	if (time() - $start_time <= $timeLimitThreshold) {
2379
+			return;
2380
+	}
2247 2381
 
2248 2382
 	// Do we have some custom step progress stuff?
2249 2383
 	if (!empty($step_progress))
2250 2384
 	{
2251 2385
 		$upcontext['substep_progress'] = 0;
2252 2386
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2253
-		if ($step_progress['current'] > $step_progress['total'])
2254
-			$upcontext['substep_progress'] = 99.9;
2255
-		else
2256
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2387
+		if ($step_progress['current'] > $step_progress['total']) {
2388
+					$upcontext['substep_progress'] = 99.9;
2389
+		} else {
2390
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2391
+		}
2257 2392
 
2258 2393
 		// Make it nicely rounded.
2259 2394
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2260 2395
 	}
2261 2396
 
2262 2397
 	// If this is XML we just exit right away!
2263
-	if (isset($_GET['xml']))
2264
-		return upgradeExit();
2398
+	if (isset($_GET['xml'])) {
2399
+			return upgradeExit();
2400
+	}
2265 2401
 
2266 2402
 	// We're going to pause after this!
2267 2403
 	$upcontext['pause'] = true;
@@ -2269,13 +2405,15 @@  discard block
 block discarded – undo
2269 2405
 	$upcontext['query_string'] = '';
2270 2406
 	foreach ($_GET as $k => $v)
2271 2407
 	{
2272
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2273
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2408
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2409
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2410
+		}
2274 2411
 	}
2275 2412
 
2276 2413
 	// Custom warning?
2277
-	if (!empty($custom_warning))
2278
-		$upcontext['custom_warning'] = $custom_warning;
2414
+	if (!empty($custom_warning)) {
2415
+			$upcontext['custom_warning'] = $custom_warning;
2416
+	}
2279 2417
 
2280 2418
 	upgradeExit();
2281 2419
 }
@@ -2290,25 +2428,26 @@  discard block
 block discarded – undo
2290 2428
 	ob_implicit_flush(true);
2291 2429
 	@set_time_limit(600);
2292 2430
 
2293
-	if (!isset($_SERVER['argv']))
2294
-		$_SERVER['argv'] = array();
2431
+	if (!isset($_SERVER['argv'])) {
2432
+			$_SERVER['argv'] = array();
2433
+	}
2295 2434
 	$_GET['maint'] = 1;
2296 2435
 
2297 2436
 	foreach ($_SERVER['argv'] as $i => $arg)
2298 2437
 	{
2299
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2300
-			$_GET['lang'] = $match[1];
2301
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2302
-			continue;
2303
-		elseif ($arg == '--no-maintenance')
2304
-			$_GET['maint'] = 0;
2305
-		elseif ($arg == '--debug')
2306
-			$is_debug = true;
2307
-		elseif ($arg == '--backup')
2308
-			$_POST['backup'] = 1;
2309
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2310
-			$_GET['conv'] = 1;
2311
-		elseif ($i != 0)
2438
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2439
+					$_GET['lang'] = $match[1];
2440
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2441
+					continue;
2442
+		} elseif ($arg == '--no-maintenance') {
2443
+					$_GET['maint'] = 0;
2444
+		} elseif ($arg == '--debug') {
2445
+					$is_debug = true;
2446
+		} elseif ($arg == '--backup') {
2447
+					$_POST['backup'] = 1;
2448
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2449
+					$_GET['conv'] = 1;
2450
+		} elseif ($i != 0)
2312 2451
 		{
2313 2452
 			echo 'SMF Command-line Upgrader
2314 2453
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2322,10 +2461,12 @@  discard block
 block discarded – undo
2322 2461
 		}
2323 2462
 	}
2324 2463
 
2325
-	if (!php_version_check())
2326
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2327
-	if (!db_version_check())
2328
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2464
+	if (!php_version_check()) {
2465
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2466
+	}
2467
+	if (!db_version_check()) {
2468
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2469
+	}
2329 2470
 
2330 2471
 	// Do some checks to make sure they have proper privileges
2331 2472
 	db_extend('packages');
@@ -2340,34 +2481,39 @@  discard block
 block discarded – undo
2340 2481
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2341 2482
 
2342 2483
 	// Sorry... we need CREATE, ALTER and DROP
2343
-	if (!$create || !$alter || !$drop)
2344
-		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);
2484
+	if (!$create || !$alter || !$drop) {
2485
+			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);
2486
+	}
2345 2487
 
2346 2488
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2347 2489
 		&& @file_exists($sourcedir . '/QueryString.php')
2348 2490
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2349
-	if (!$check && !isset($modSettings['smfVersion']))
2350
-		print_error('Error: Some files are missing or out-of-date.', true);
2491
+	if (!$check && !isset($modSettings['smfVersion'])) {
2492
+			print_error('Error: Some files are missing or out-of-date.', true);
2493
+	}
2351 2494
 
2352 2495
 	// Do a quick version spot check.
2353 2496
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2354 2497
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2355
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2356
-		print_error('Error: Some files have not yet been updated properly.');
2498
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2499
+			print_error('Error: Some files have not yet been updated properly.');
2500
+	}
2357 2501
 
2358 2502
 	// Make sure Settings.php is writable.
2359 2503
 		quickFileWritable($boarddir . '/Settings.php');
2360
-	if (!is_writable($boarddir . '/Settings.php'))
2361
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2504
+	if (!is_writable($boarddir . '/Settings.php')) {
2505
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2506
+	}
2362 2507
 
2363 2508
 	// Make sure Settings_bak.php is writable.
2364 2509
 		quickFileWritable($boarddir . '/Settings_bak.php');
2365
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2366
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2510
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2511
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2512
+	}
2367 2513
 
2368
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2369
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2370
-	elseif (isset($modSettings['agreement']))
2514
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2515
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2516
+	} elseif (isset($modSettings['agreement']))
2371 2517
 	{
2372 2518
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2373 2519
 		fwrite($fp, $modSettings['agreement']);
@@ -2377,31 +2523,36 @@  discard block
 block discarded – undo
2377 2523
 	// Make sure Themes is writable.
2378 2524
 	quickFileWritable($modSettings['theme_dir']);
2379 2525
 
2380
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2381
-		print_error('Error: Unable to obtain write access to "Themes".');
2526
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2527
+			print_error('Error: Unable to obtain write access to "Themes".');
2528
+	}
2382 2529
 
2383 2530
 	// Make sure cache directory exists and is writable!
2384 2531
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2385
-	if (!file_exists($cachedir_temp))
2386
-		@mkdir($cachedir_temp);
2532
+	if (!file_exists($cachedir_temp)) {
2533
+			@mkdir($cachedir_temp);
2534
+	}
2387 2535
 
2388 2536
 	// Make sure the cache temp dir is writable.
2389 2537
 	quickFileWritable($cachedir_temp);
2390 2538
 
2391
-	if (!is_writable($cachedir_temp))
2392
-		print_error('Error: Unable to obtain write access to "cache".', true);
2539
+	if (!is_writable($cachedir_temp)) {
2540
+			print_error('Error: Unable to obtain write access to "cache".', true);
2541
+	}
2393 2542
 
2394
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2395
-		print_error('Error: Unable to find language files!', true);
2396
-	else
2543
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2544
+			print_error('Error: Unable to find language files!', true);
2545
+	} else
2397 2546
 	{
2398 2547
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2399 2548
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2400 2549
 
2401
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2402
-			print_error('Error: Language files out of date.', true);
2403
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2404
-			print_error('Error: Install language is missing for selected language.', true);
2550
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2551
+					print_error('Error: Language files out of date.', true);
2552
+		}
2553
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2554
+					print_error('Error: Install language is missing for selected language.', true);
2555
+		}
2405 2556
 
2406 2557
 		// Otherwise include it!
2407 2558
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2430,8 +2581,7 @@  discard block
 block discarded – undo
2430 2581
 		);
2431 2582
 
2432 2583
 		return true;
2433
-	}
2434
-	else
2584
+	} else
2435 2585
 	{
2436 2586
 		$upcontext['page_title'] = 'Converting to UTF8';
2437 2587
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2475,8 +2625,9 @@  discard block
 block discarded – undo
2475 2625
 			)
2476 2626
 		);
2477 2627
 		$db_charsets = array();
2478
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2479
-			$db_charsets[] = $row['Charset'];
2628
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2629
+					$db_charsets[] = $row['Charset'];
2630
+		}
2480 2631
 
2481 2632
 		$smcFunc['db_free_result']($request);
2482 2633
 
@@ -2512,13 +2663,15 @@  discard block
 block discarded – undo
2512 2663
 		// If there's a fulltext index, we need to drop it first...
2513 2664
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2514 2665
 		{
2515
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2516
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2666
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2667
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2517 2668
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2669
+			}
2518 2670
 			$smcFunc['db_free_result']($request);
2519 2671
 
2520
-			if (isset($upcontext['fulltext_index']))
2521
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2672
+			if (isset($upcontext['fulltext_index'])) {
2673
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2674
+			}
2522 2675
 		}
2523 2676
 
2524 2677
 		// Drop it and make a note...
@@ -2708,8 +2861,9 @@  discard block
 block discarded – undo
2708 2861
 			$replace = '%field%';
2709 2862
 
2710 2863
 			// Build a huge REPLACE statement...
2711
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2712
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2864
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2865
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2866
+			}
2713 2867
 		}
2714 2868
 
2715 2869
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2743,8 +2897,9 @@  discard block
 block discarded – undo
2743 2897
 			$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2744 2898
 
2745 2899
 			// Just to make sure it doesn't time out.
2746
-			if (function_exists('apache_reset_timeout'))
2747
-				@apache_reset_timeout();
2900
+			if (function_exists('apache_reset_timeout')) {
2901
+							@apache_reset_timeout();
2902
+			}
2748 2903
 
2749 2904
 			$table_charsets = array();
2750 2905
 
@@ -2765,8 +2920,9 @@  discard block
 block discarded – undo
2765 2920
 					{
2766 2921
 						list($charset) = explode('_', $collation);
2767 2922
 
2768
-						if (!isset($table_charsets[$charset]))
2769
-							$table_charsets[$charset] = array();
2923
+						if (!isset($table_charsets[$charset])) {
2924
+													$table_charsets[$charset] = array();
2925
+						}
2770 2926
 
2771 2927
 						$table_charsets[$charset][] = $column_info;
2772 2928
 					}
@@ -2806,10 +2962,11 @@  discard block
 block discarded – undo
2806 2962
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2807 2963
 				{
2808 2964
 					$update = '';
2809
-					foreach ($table_charsets as $charset => $columns)
2810
-						foreach ($columns as $column)
2965
+					foreach ($table_charsets as $charset => $columns) {
2966
+											foreach ($columns as $column)
2811 2967
 							$update .= '
2812 2968
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2969
+					}
2813 2970
 
2814 2971
 					$smcFunc['db_query']('', '
2815 2972
 						UPDATE {raw:table_name}
@@ -2834,8 +2991,9 @@  discard block
 block discarded – undo
2834 2991
 			// Now do the actual conversion (if still needed).
2835 2992
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2836 2993
 			{
2837
-				if ($command_line)
2838
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
2994
+				if ($command_line) {
2995
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
2996
+				}
2839 2997
 
2840 2998
 				$smcFunc['db_query']('', '
2841 2999
 					ALTER TABLE {raw:table_name}
@@ -2845,8 +3003,9 @@  discard block
 block discarded – undo
2845 3003
 					)
2846 3004
 				);
2847 3005
 
2848
-				if ($command_line)
2849
-					echo " done.\n";
3006
+				if ($command_line) {
3007
+									echo " done.\n";
3008
+				}
2850 3009
 			}
2851 3010
 		}
2852 3011
 
@@ -2876,8 +3035,8 @@  discard block
 block discarded – undo
2876 3035
 		);
2877 3036
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2878 3037
 		{
2879
-			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)
2880
-				$smcFunc['db_query']('', '
3038
+			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) {
3039
+							$smcFunc['db_query']('', '
2881 3040
 					UPDATE {db_prefix}log_actions
2882 3041
 					SET extra = {string:extra}
2883 3042
 					WHERE id_action = {int:current_action}',
@@ -2886,6 +3045,7 @@  discard block
 block discarded – undo
2886 3045
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2887 3046
 					)
2888 3047
 				);
3048
+			}
2889 3049
 		}
2890 3050
 		$smcFunc['db_free_result']($request);
2891 3051
 
@@ -2907,15 +3067,17 @@  discard block
 block discarded – undo
2907 3067
 	// First thing's first - did we already do this?
2908 3068
 	if (!empty($modSettings['json_done']))
2909 3069
 	{
2910
-		if ($command_line)
2911
-			return DeleteUpgrade();
2912
-		else
2913
-			return true;
3070
+		if ($command_line) {
3071
+					return DeleteUpgrade();
3072
+		} else {
3073
+					return true;
3074
+		}
2914 3075
 	}
2915 3076
 
2916 3077
 	// Done it already - js wise?
2917
-	if (!empty($_POST['json_done']))
2918
-		return true;
3078
+	if (!empty($_POST['json_done'])) {
3079
+			return true;
3080
+	}
2919 3081
 
2920 3082
 	// List of tables affected by this function
2921 3083
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2947,12 +3109,14 @@  discard block
 block discarded – undo
2947 3109
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2948 3110
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2949 3111
 
2950
-	foreach ($keys as $id => $table)
2951
-		if ($id < $_GET['substep'])
3112
+	foreach ($keys as $id => $table) {
3113
+			if ($id < $_GET['substep'])
2952 3114
 			$upcontext['previous_tables'][] = $table;
3115
+	}
2953 3116
 
2954
-	if ($command_line)
2955
-		echo 'Converting data from serialize() to json_encode().';
3117
+	if ($command_line) {
3118
+			echo 'Converting data from serialize() to json_encode().';
3119
+	}
2956 3120
 
2957 3121
 	if (!$support_js || isset($_GET['xml']))
2958 3122
 	{
@@ -2992,8 +3156,9 @@  discard block
 block discarded – undo
2992 3156
 
2993 3157
 				// Loop through and fix these...
2994 3158
 				$new_settings = array();
2995
-				if ($command_line)
2996
-					echo "\n" . 'Fixing some settings...';
3159
+				if ($command_line) {
3160
+									echo "\n" . 'Fixing some settings...';
3161
+				}
2997 3162
 
2998 3163
 				foreach ($serialized_settings as $var)
2999 3164
 				{
@@ -3001,22 +3166,24 @@  discard block
 block discarded – undo
3001 3166
 					{
3002 3167
 						// Attempt to unserialize the setting
3003 3168
 						$temp = @safe_unserialize($modSettings[$var]);
3004
-						if (!$temp && $command_line)
3005
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3006
-						elseif ($temp !== false)
3007
-							$new_settings[$var] = json_encode($temp);
3169
+						if (!$temp && $command_line) {
3170
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3171
+						} elseif ($temp !== false) {
3172
+													$new_settings[$var] = json_encode($temp);
3173
+						}
3008 3174
 					}
3009 3175
 				}
3010 3176
 
3011 3177
 				// Update everything at once
3012
-				if (!function_exists('cache_put_data'))
3013
-					require_once($sourcedir . '/Load.php');
3178
+				if (!function_exists('cache_put_data')) {
3179
+									require_once($sourcedir . '/Load.php');
3180
+				}
3014 3181
 				updateSettings($new_settings, true);
3015 3182
 
3016
-				if ($command_line)
3017
-					echo ' done.';
3018
-			}
3019
-			elseif ($table == 'themes')
3183
+				if ($command_line) {
3184
+									echo ' done.';
3185
+				}
3186
+			} elseif ($table == 'themes')
3020 3187
 			{
3021 3188
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3022 3189
 				$query = $smcFunc['db_query']('', '
@@ -3035,10 +3202,11 @@  discard block
 block discarded – undo
3035 3202
 
3036 3203
 						if ($command_line)
3037 3204
 						{
3038
-							if ($temp === false)
3039
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3040
-							else
3041
-								echo "\n" . 'Fixing admin preferences...';
3205
+							if ($temp === false) {
3206
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3207
+							} else {
3208
+															echo "\n" . 'Fixing admin preferences...';
3209
+							}
3042 3210
 						}
3043 3211
 
3044 3212
 						if ($temp !== false)
@@ -3060,15 +3228,15 @@  discard block
 block discarded – undo
3060 3228
 								)
3061 3229
 							);
3062 3230
 
3063
-							if ($command_line)
3064
-								echo ' done.';
3231
+							if ($command_line) {
3232
+															echo ' done.';
3233
+							}
3065 3234
 						}
3066 3235
 					}
3067 3236
 
3068 3237
 					$smcFunc['db_free_result']($query);
3069 3238
 				}
3070
-			}
3071
-			else
3239
+			} else
3072 3240
 			{
3073 3241
 				// First item is always the key...
3074 3242
 				$key = $info[0];
@@ -3079,8 +3247,7 @@  discard block
 block discarded – undo
3079 3247
 				{
3080 3248
 					$col_select = $info[1];
3081 3249
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3082
-				}
3083
-				else
3250
+				} else
3084 3251
 				{
3085 3252
 					$col_select = implode(', ', $info);
3086 3253
 				}
@@ -3113,8 +3280,7 @@  discard block
 block discarded – undo
3113 3280
 								if ($temp === false && $command_line)
3114 3281
 								{
3115 3282
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3116
-								}
3117
-								else
3283
+								} else
3118 3284
 								{
3119 3285
 									$row[$col] = json_encode($temp);
3120 3286
 
@@ -3139,16 +3305,18 @@  discard block
 block discarded – undo
3139 3305
 						}
3140 3306
 					}
3141 3307
 
3142
-					if ($command_line)
3143
-						echo ' done.';
3308
+					if ($command_line) {
3309
+											echo ' done.';
3310
+					}
3144 3311
 
3145 3312
 					// Free up some memory...
3146 3313
 					$smcFunc['db_free_result']($query);
3147 3314
 				}
3148 3315
 			}
3149 3316
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3150
-			if (isset($_GET['xml']))
3151
-				return upgradeExit();
3317
+			if (isset($_GET['xml'])) {
3318
+							return upgradeExit();
3319
+			}
3152 3320
 		}
3153 3321
 
3154 3322
 		if ($command_line)
@@ -3163,8 +3331,9 @@  discard block
 block discarded – undo
3163 3331
 
3164 3332
 		$_GET['substep'] = 0;
3165 3333
 		// Make sure we move on!
3166
-		if ($command_line)
3167
-			return DeleteUpgrade();
3334
+		if ($command_line) {
3335
+					return DeleteUpgrade();
3336
+		}
3168 3337
 
3169 3338
 		return true;
3170 3339
 	}
@@ -3184,14 +3353,16 @@  discard block
 block discarded – undo
3184 3353
 	global $upcontext, $txt, $settings;
3185 3354
 
3186 3355
 	// Don't call me twice!
3187
-	if (!empty($upcontext['chmod_called']))
3188
-		return;
3356
+	if (!empty($upcontext['chmod_called'])) {
3357
+			return;
3358
+	}
3189 3359
 
3190 3360
 	$upcontext['chmod_called'] = true;
3191 3361
 
3192 3362
 	// Nothing?
3193
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3194
-		return;
3363
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3364
+			return;
3365
+	}
3195 3366
 
3196 3367
 	// Was it a problem with Windows?
3197 3368
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3223,11 +3394,12 @@  discard block
 block discarded – undo
3223 3394
 					content.write(\'<div class="windowbg description">\n\t\t\t<h4>The following files needs to be made writable to continue:</h4>\n\t\t\t\');
3224 3395
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3225 3396
 
3226
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3227
-		echo '
3397
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3398
+			echo '
3228 3399
 					content.write(\'<hr>\n\t\t\t\');
3229 3400
 					content.write(\'<p>If you have a shell account, the convenient below command can automatically correct permissions on these files</p>\n\t\t\t\');
3230 3401
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3402
+	}
3231 3403
 
3232 3404
 	echo '
3233 3405
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3235,17 +3407,19 @@  discard block
 block discarded – undo
3235 3407
 				}
3236 3408
 		</script>';
3237 3409
 
3238
-	if (!empty($upcontext['chmod']['ftp_error']))
3239
-		echo '
3410
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3411
+			echo '
3240 3412
 			<div class="error_message red">
3241 3413
 				The following error was encountered when trying to connect:<br><br>
3242 3414
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3243 3415
 			</div>
3244 3416
 			<br>';
3417
+	}
3245 3418
 
3246
-	if (empty($upcontext['chmod_in_form']))
3247
-		echo '
3419
+	if (empty($upcontext['chmod_in_form'])) {
3420
+			echo '
3248 3421
 	<form action="', $upcontext['form_url'], '" method="post">';
3422
+	}
3249 3423
 
3250 3424
 	echo '
3251 3425
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3280,10 +3454,11 @@  discard block
 block discarded – undo
3280 3454
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3281 3455
 	</div>';
3282 3456
 
3283
-	if (empty($upcontext['chmod_in_form']))
3284
-		echo '
3457
+	if (empty($upcontext['chmod_in_form'])) {
3458
+			echo '
3285 3459
 	</form>';
3286
-}
3460
+	}
3461
+	}
3287 3462
 
3288 3463
 function template_upgrade_above()
3289 3464
 {
@@ -3343,9 +3518,10 @@  discard block
 block discarded – undo
3343 3518
 				<h2>', $txt['upgrade_progress'], '</h2>
3344 3519
 				<ul>';
3345 3520
 
3346
-	foreach ($upcontext['steps'] as $num => $step)
3347
-		echo '
3521
+	foreach ($upcontext['steps'] as $num => $step) {
3522
+			echo '
3348 3523
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3524
+	}
3349 3525
 
3350 3526
 	echo '
3351 3527
 					</ul>
@@ -3358,8 +3534,8 @@  discard block
 block discarded – undo
3358 3534
 				</div>
3359 3535
 			</div>';
3360 3536
 
3361
-	if (isset($upcontext['step_progress']))
3362
-		echo '
3537
+	if (isset($upcontext['step_progress'])) {
3538
+			echo '
3363 3539
 				<br>
3364 3540
 				<br>
3365 3541
 				<div id="progress_bar_step">
@@ -3368,6 +3544,7 @@  discard block
 block discarded – undo
3368 3544
 						<span>', $txt['upgrade_step_progress'], '</span>
3369 3545
 					</div>
3370 3546
 				</div>';
3547
+	}
3371 3548
 
3372 3549
 	echo '
3373 3550
 				<div id="substep_bar_div" class="smalltext" style="float: left;width: 50%;margin-top: 0.6em;display: ', isset($upcontext['substep_progress']) ? '' : 'none', ';">', isset($upcontext['substep_progress_name']) ? trim(strtr($upcontext['substep_progress_name'], array('.' => ''))) : '', ':</div>
@@ -3398,32 +3575,36 @@  discard block
 block discarded – undo
3398 3575
 {
3399 3576
 	global $upcontext, $txt;
3400 3577
 
3401
-	if (!empty($upcontext['pause']))
3402
-		echo '
3578
+	if (!empty($upcontext['pause'])) {
3579
+			echo '
3403 3580
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3404 3581
 
3405 3582
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3406 3583
 								<h3>
3407 3584
 									', $txt['upgrade_paused_overload'], '
3408 3585
 								</h3>';
3586
+	}
3409 3587
 
3410
-	if (!empty($upcontext['custom_warning']))
3411
-		echo '
3588
+	if (!empty($upcontext['custom_warning'])) {
3589
+			echo '
3412 3590
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3413 3591
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3414 3592
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3415 3593
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3416 3594
 								</div>';
3595
+	}
3417 3596
 
3418 3597
 	echo '
3419 3598
 								<div class="righttext" style="margin: 1ex;">';
3420 3599
 
3421
-	if (!empty($upcontext['continue']))
3422
-		echo '
3600
+	if (!empty($upcontext['continue'])) {
3601
+			echo '
3423 3602
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3424
-	if (!empty($upcontext['skip']))
3425
-		echo '
3603
+	}
3604
+	if (!empty($upcontext['skip'])) {
3605
+			echo '
3426 3606
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3607
+	}
3427 3608
 
3428 3609
 	echo '
3429 3610
 								</div>
@@ -3473,11 +3654,12 @@  discard block
 block discarded – undo
3473 3654
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3474 3655
 	<smf>';
3475 3656
 
3476
-	if (!empty($upcontext['get_data']))
3477
-		foreach ($upcontext['get_data'] as $k => $v)
3657
+	if (!empty($upcontext['get_data'])) {
3658
+			foreach ($upcontext['get_data'] as $k => $v)
3478 3659
 			echo '
3479 3660
 		<get key="', $k, '">', $v, '</get>';
3480
-}
3661
+	}
3662
+	}
3481 3663
 
3482 3664
 function template_xml_below()
3483 3665
 {
@@ -3518,8 +3700,8 @@  discard block
 block discarded – undo
3518 3700
 	template_chmod();
3519 3701
 
3520 3702
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3521
-	if ($upcontext['is_large_forum'])
3522
-		echo '
3703
+	if ($upcontext['is_large_forum']) {
3704
+			echo '
3523 3705
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3524 3706
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3525 3707
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3527,10 +3709,11 @@  discard block
 block discarded – undo
3527 3709
 				', $txt['upgrade_warning_lots_data'], '
3528 3710
 			</div>
3529 3711
 		</div>';
3712
+	}
3530 3713
 
3531 3714
 	// A warning message?
3532
-	if (!empty($upcontext['warning']))
3533
-		echo '
3715
+	if (!empty($upcontext['warning'])) {
3716
+			echo '
3534 3717
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3535 3718
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3536 3719
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3538,6 +3721,7 @@  discard block
 block discarded – undo
3538 3721
 				', $upcontext['warning'], '
3539 3722
 			</div>
3540 3723
 		</div>';
3724
+	}
3541 3725
 
3542 3726
 	// Paths are incorrect?
3543 3727
 	echo '
@@ -3553,20 +3737,22 @@  discard block
 block discarded – undo
3553 3737
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3554 3738
 	{
3555 3739
 		$ago = time() - $upcontext['started'];
3556
-		if ($ago < 60)
3557
-			$ago = $ago . ' seconds';
3558
-		elseif ($ago < 3600)
3559
-			$ago = (int) ($ago / 60) . ' minutes';
3560
-		else
3561
-			$ago = (int) ($ago / 3600) . ' hours';
3740
+		if ($ago < 60) {
3741
+					$ago = $ago . ' seconds';
3742
+		} elseif ($ago < 3600) {
3743
+					$ago = (int) ($ago / 60) . ' minutes';
3744
+		} else {
3745
+					$ago = (int) ($ago / 3600) . ' hours';
3746
+		}
3562 3747
 
3563 3748
 		$active = time() - $upcontext['updated'];
3564
-		if ($active < 60)
3565
-			$updated = $active . ' seconds';
3566
-		elseif ($active < 3600)
3567
-			$updated = (int) ($active / 60) . ' minutes';
3568
-		else
3569
-			$updated = (int) ($active / 3600) . ' hours';
3749
+		if ($active < 60) {
3750
+					$updated = $active . ' seconds';
3751
+		} elseif ($active < 3600) {
3752
+					$updated = (int) ($active / 60) . ' minutes';
3753
+		} else {
3754
+					$updated = (int) ($active / 3600) . ' hours';
3755
+		}
3570 3756
 
3571 3757
 		echo '
3572 3758
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3575,16 +3761,18 @@  discard block
 block discarded – undo
3575 3761
 			<div style="padding-left: 6ex;">
3576 3762
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3577 3763
 
3578
-		if ($active < 600)
3579
-			echo '
3764
+		if ($active < 600) {
3765
+					echo '
3580 3766
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3767
+		}
3581 3768
 
3582
-		if ($active > $upcontext['inactive_timeout'])
3583
-			echo '
3769
+		if ($active > $upcontext['inactive_timeout']) {
3770
+					echo '
3584 3771
 				<br><br>You can choose to either run the upgrade again from the beginning - or alternatively continue from the last step reached during the last upgrade.';
3585
-		else
3586
-			echo '
3772
+		} else {
3773
+					echo '
3587 3774
 				<br><br>This upgrade script cannot be run until ', $upcontext['user']['name'], ' has been inactive for at least ', ($upcontext['inactive_timeout'] > 120 ? round($upcontext['inactive_timeout'] / 60, 1) . ' minutes!' : $upcontext['inactive_timeout'] . ' seconds!');
3775
+		}
3588 3776
 
3589 3777
 		echo '
3590 3778
 			</div>
@@ -3600,9 +3788,10 @@  discard block
 block discarded – undo
3600 3788
 					<td>
3601 3789
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3602 3790
 
3603
-	if (!empty($upcontext['username_incorrect']))
3604
-		echo '
3791
+	if (!empty($upcontext['username_incorrect'])) {
3792
+			echo '
3605 3793
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3794
+	}
3606 3795
 
3607 3796
 	echo '
3608 3797
 					</td>
@@ -3613,9 +3802,10 @@  discard block
 block discarded – undo
3613 3802
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3614 3803
 						<input type="hidden" name="hash_passwrd" value="">';
3615 3804
 
3616
-	if (!empty($upcontext['password_failed']))
3617
-		echo '
3805
+	if (!empty($upcontext['password_failed'])) {
3806
+			echo '
3618 3807
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3808
+	}
3619 3809
 
3620 3810
 	echo '
3621 3811
 					</td>
@@ -3686,8 +3876,8 @@  discard block
 block discarded – undo
3686 3876
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3687 3877
 
3688 3878
 	// Warning message?
3689
-	if (!empty($upcontext['upgrade_options_warning']))
3690
-		echo '
3879
+	if (!empty($upcontext['upgrade_options_warning'])) {
3880
+			echo '
3691 3881
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3692 3882
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3693 3883
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3695,6 +3885,7 @@  discard block
 block discarded – undo
3695 3885
 				', $upcontext['upgrade_options_warning'], '
3696 3886
 			</div>
3697 3887
 		</div>';
3888
+	}
3698 3889
 
3699 3890
 	echo '
3700 3891
 				<table>
@@ -3737,8 +3928,8 @@  discard block
 block discarded – undo
3737 3928
 						</td>
3738 3929
 					</tr>';
3739 3930
 
3740
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3741
-		echo '
3931
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3932
+			echo '
3742 3933
 					<tr valign="top">
3743 3934
 						<td width="2%">
3744 3935
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3747,6 +3938,7 @@  discard block
 block discarded – undo
3747 3938
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3748 3939
 						</td>
3749 3940
 					</tr>';
3941
+	}
3750 3942
 
3751 3943
 	echo '
3752 3944
 					<tr valign="top">
@@ -3784,10 +3976,11 @@  discard block
 block discarded – undo
3784 3976
 			</div>';
3785 3977
 
3786 3978
 	// Dont any tables so far?
3787
-	if (!empty($upcontext['previous_tables']))
3788
-		foreach ($upcontext['previous_tables'] as $table)
3979
+	if (!empty($upcontext['previous_tables'])) {
3980
+			foreach ($upcontext['previous_tables'] as $table)
3789 3981
 			echo '
3790 3982
 			<br>Completed Table: &quot;', $table, '&quot;.';
3983
+	}
3791 3984
 
3792 3985
 	echo '
3793 3986
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3824,12 +4017,13 @@  discard block
 block discarded – undo
3824 4017
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3825 4018
 
3826 4019
 		// If debug flood the screen.
3827
-		if ($is_debug)
3828
-			echo '
4020
+		if ($is_debug) {
4021
+					echo '
3829 4022
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3830 4023
 
3831 4024
 				if (document.getElementById(\'debug_section\').scrollHeight)
3832 4025
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4026
+		}
3833 4027
 
3834 4028
 		echo '
3835 4029
 				// Get the next update...
@@ -3861,8 +4055,9 @@  discard block
 block discarded – undo
3861 4055
 {
3862 4056
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3863 4057
 
3864
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3865
-		$is_debug = true;
4058
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4059
+			$is_debug = true;
4060
+	}
3866 4061
 
3867 4062
 	echo '
3868 4063
 		<h3>Executing database changes</h3>
@@ -3877,8 +4072,9 @@  discard block
 block discarded – undo
3877 4072
 	{
3878 4073
 		foreach ($upcontext['actioned_items'] as $num => $item)
3879 4074
 		{
3880
-			if ($num != 0)
3881
-				echo ' Successful!';
4075
+			if ($num != 0) {
4076
+							echo ' Successful!';
4077
+			}
3882 4078
 			echo '<br>' . $item;
3883 4079
 		}
3884 4080
 		if (!empty($upcontext['changes_complete']))
@@ -3891,28 +4087,32 @@  discard block
 block discarded – undo
3891 4087
 				$seconds = intval($active % 60);
3892 4088
 
3893 4089
 				$totalTime = '';
3894
-				if ($hours > 0)
3895
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3896
-				if ($minutes > 0)
3897
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3898
-				if ($seconds > 0)
3899
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4090
+				if ($hours > 0) {
4091
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4092
+				}
4093
+				if ($minutes > 0) {
4094
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4095
+				}
4096
+				if ($seconds > 0) {
4097
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4098
+				}
3900 4099
 			}
3901 4100
 
3902
-			if ($is_debug && !empty($totalTime))
3903
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3904
-			else
3905
-				echo ' Successful!<br><br>';
4101
+			if ($is_debug && !empty($totalTime)) {
4102
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4103
+			} else {
4104
+							echo ' Successful!<br><br>';
4105
+			}
3906 4106
 
3907 4107
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3908 4108
 		}
3909
-	}
3910
-	else
4109
+	} else
3911 4110
 	{
3912 4111
 		// Tell them how many files we have in total.
3913
-		if ($upcontext['file_count'] > 1)
3914
-			echo '
4112
+		if ($upcontext['file_count'] > 1) {
4113
+					echo '
3915 4114
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4115
+		}
3916 4116
 
3917 4117
 		echo '
3918 4118
 		<h3 id="info2"><strong>Executing:</strong> &quot;<span id="cur_item_name">', $upcontext['current_item_name'], '</span>&quot; (<span id="item_num">', $upcontext['current_item_num'], '</span> of <span id="total_items"><span id="item_count">', $upcontext['total_items'], '</span>', $upcontext['file_count'] > 1 ? ' - of this script' : '', ')</span></h3>
@@ -3928,19 +4128,23 @@  discard block
 block discarded – undo
3928 4128
 				$seconds = intval($active % 60);
3929 4129
 
3930 4130
 				$totalTime = '';
3931
-				if ($hours > 0)
3932
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3933
-				if ($minutes > 0)
3934
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3935
-				if ($seconds > 0)
3936
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4131
+				if ($hours > 0) {
4132
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4133
+				}
4134
+				if ($minutes > 0) {
4135
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4136
+				}
4137
+				if ($seconds > 0) {
4138
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4139
+				}
3937 4140
 			}
3938 4141
 
3939 4142
 			echo '
3940 4143
 			<br><span id="upgradeCompleted">';
3941 4144
 
3942
-			if (!empty($totalTime))
3943
-				echo 'Completed in ', $totalTime, '<br>';
4145
+			if (!empty($totalTime)) {
4146
+							echo 'Completed in ', $totalTime, '<br>';
4147
+			}
3944 4148
 
3945 4149
 			echo '</span>
3946 4150
 			<div id="debug_section" style="height: 200px; overflow: auto;">
@@ -3977,9 +4181,10 @@  discard block
 block discarded – undo
3977 4181
 			var getData = "";
3978 4182
 			var debugItems = ', $upcontext['debug_items'], ';';
3979 4183
 
3980
-		if ($is_debug)
3981
-			echo '
4184
+		if ($is_debug) {
4185
+					echo '
3982 4186
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4187
+		}
3983 4188
 
3984 4189
 		echo '
3985 4190
 			function getNextItem()
@@ -4019,9 +4224,10 @@  discard block
 block discarded – undo
4019 4224
 						document.getElementById("error_block").style.display = "";
4020 4225
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4021 4226
 
4022
-	if ($is_debug)
4023
-		echo '
4227
+	if ($is_debug) {
4228
+			echo '
4024 4229
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4230
+	}
4025 4231
 
4026 4232
 	echo '
4027 4233
 					}
@@ -4042,9 +4248,10 @@  discard block
 block discarded – undo
4042 4248
 						document.getElementById("error_block").style.display = "";
4043 4249
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4044 4250
 
4045
-	if ($is_debug)
4046
-		echo '
4251
+	if ($is_debug) {
4252
+			echo '
4047 4253
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4254
+	}
4048 4255
 
4049 4256
 	echo '
4050 4257
 					}
@@ -4103,8 +4310,8 @@  discard block
 block discarded – undo
4103 4310
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4104 4311
 				{';
4105 4312
 
4106
-		if ($is_debug)
4107
-			echo '
4313
+		if ($is_debug) {
4314
+					echo '
4108 4315
 					document.getElementById(\'debug_section\').style.display = "none";
4109 4316
 
4110 4317
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4122,6 +4329,7 @@  discard block
 block discarded – undo
4122 4329
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4123 4330
 
4124 4331
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4332
+		}
4125 4333
 
4126 4334
 		echo '
4127 4335
 
@@ -4129,9 +4337,10 @@  discard block
 block discarded – undo
4129 4337
 					document.getElementById(\'contbutt\').disabled = 0;
4130 4338
 					document.getElementById(\'database_done\').value = 1;';
4131 4339
 
4132
-		if ($upcontext['file_count'] > 1)
4133
-			echo '
4340
+		if ($upcontext['file_count'] > 1) {
4341
+					echo '
4134 4342
 					document.getElementById(\'info1\').style.display = "none";';
4343
+		}
4135 4344
 
4136 4345
 		echo '
4137 4346
 					document.getElementById(\'info2\').style.display = "none";
@@ -4144,9 +4353,10 @@  discard block
 block discarded – undo
4144 4353
 					lastItem = 0;
4145 4354
 					prevFile = curFile;';
4146 4355
 
4147
-		if ($is_debug)
4148
-			echo '
4356
+		if ($is_debug) {
4357
+					echo '
4149 4358
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4359
+		}
4150 4360
 
4151 4361
 		echo '
4152 4362
 					getNextItem();
@@ -4154,8 +4364,8 @@  discard block
 block discarded – undo
4154 4364
 				}';
4155 4365
 
4156 4366
 		// If debug scroll the screen.
4157
-		if ($is_debug)
4158
-			echo '
4367
+		if ($is_debug) {
4368
+					echo '
4159 4369
 				if (iLastSubStepProgress == -1)
4160 4370
 				{
4161 4371
 					// Give it consistent dots.
@@ -4174,6 +4384,7 @@  discard block
 block discarded – undo
4174 4384
 
4175 4385
 				if (document.getElementById(\'debug_section\').scrollHeight)
4176 4386
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4387
+		}
4177 4388
 
4178 4389
 		echo '
4179 4390
 				// Update the page.
@@ -4234,9 +4445,10 @@  discard block
 block discarded – undo
4234 4445
 			}';
4235 4446
 
4236 4447
 		// Start things off assuming we've not errored.
4237
-		if (empty($upcontext['error_message']))
4238
-			echo '
4448
+		if (empty($upcontext['error_message'])) {
4449
+					echo '
4239 4450
 			getNextItem();';
4451
+		}
4240 4452
 
4241 4453
 		echo '
4242 4454
 		</script>';
@@ -4253,18 +4465,21 @@  discard block
 block discarded – undo
4253 4465
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4254 4466
 	<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>';
4255 4467
 
4256
-	if (!empty($upcontext['error_message']))
4257
-		echo '
4468
+	if (!empty($upcontext['error_message'])) {
4469
+			echo '
4258 4470
 	<error>', $upcontext['error_message'], '</error>';
4471
+	}
4259 4472
 
4260
-	if (!empty($upcontext['error_string']))
4261
-		echo '
4473
+	if (!empty($upcontext['error_string'])) {
4474
+			echo '
4262 4475
 	<sql>', $upcontext['error_string'], '</sql>';
4476
+	}
4263 4477
 
4264
-	if ($is_debug)
4265
-		echo '
4478
+	if ($is_debug) {
4479
+			echo '
4266 4480
 	<curtime>', time(), '</curtime>';
4267
-}
4481
+	}
4482
+	}
4268 4483
 
4269 4484
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4270 4485
 function template_convert_utf8()
@@ -4281,18 +4496,20 @@  discard block
 block discarded – undo
4281 4496
 			<span id="debuginfo"></span>';
4282 4497
 
4283 4498
 	// Done any tables so far?
4284
-	if (!empty($upcontext['previous_tables']))
4285
-		foreach ($upcontext['previous_tables'] as $table)
4499
+	if (!empty($upcontext['previous_tables'])) {
4500
+			foreach ($upcontext['previous_tables'] as $table)
4286 4501
 			echo '
4287 4502
 			<br>Completed Table: &quot;', $table, '&quot;.';
4503
+	}
4288 4504
 
4289 4505
 	echo '
4290 4506
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4291 4507
 
4292 4508
 	// If we dropped their index, let's let them know
4293
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4294
-		echo '
4509
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4510
+			echo '
4295 4511
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4512
+	}
4296 4513
 
4297 4514
 	echo '
4298 4515
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Conversion Complete! Click Continue to Proceed.</span>';
@@ -4328,9 +4545,10 @@  discard block
 block discarded – undo
4328 4545
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4329 4546
 
4330 4547
 		// If debug flood the screen.
4331
-		if ($is_debug)
4332
-			echo '
4548
+		if ($is_debug) {
4549
+					echo '
4333 4550
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4551
+		}
4334 4552
 
4335 4553
 		echo '
4336 4554
 				// Get the next update...
@@ -4372,19 +4590,21 @@  discard block
 block discarded – undo
4372 4590
 			<span id="debuginfo"></span>';
4373 4591
 
4374 4592
 	// Dont any tables so far?
4375
-	if (!empty($upcontext['previous_tables']))
4376
-		foreach ($upcontext['previous_tables'] as $table)
4593
+	if (!empty($upcontext['previous_tables'])) {
4594
+			foreach ($upcontext['previous_tables'] as $table)
4377 4595
 			echo '
4378 4596
 			<br>Completed Table: &quot;', $table, '&quot;.';
4597
+	}
4379 4598
 
4380 4599
 	echo '
4381 4600
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4382 4601
 			<br><span id="commess" style="font-weight: bold; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Convert to JSON Complete! Click Continue to Proceed.</span>';
4383 4602
 
4384 4603
 	// Try to make sure substep was reset.
4385
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4386
-		echo '
4604
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4605
+			echo '
4387 4606
 			<input type="hidden" name="substep" id="substep" value="0">';
4607
+	}
4388 4608
 
4389 4609
 	// Continue please!
4390 4610
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4417,9 +4637,10 @@  discard block
 block discarded – undo
4417 4637
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4418 4638
 
4419 4639
 		// If debug flood the screen.
4420
-		if ($is_debug)
4421
-			echo '
4640
+		if ($is_debug) {
4641
+					echo '
4422 4642
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');';
4643
+		}
4423 4644
 
4424 4645
 		echo '
4425 4646
 				// Get the next update...
@@ -4454,8 +4675,8 @@  discard block
 block discarded – undo
4454 4675
 	<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>
4455 4676
 	<form action="', $boardurl, '/index.php">';
4456 4677
 
4457
-	if (!empty($upcontext['can_delete_script']))
4458
-		echo '
4678
+	if (!empty($upcontext['can_delete_script'])) {
4679
+			echo '
4459 4680
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" class="input_check"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4460 4681
 			<script>
4461 4682
 				function doTheDelete(theCheck)
@@ -4467,6 +4688,7 @@  discard block
 block discarded – undo
4467 4688
 				}
4468 4689
 			</script>
4469 4690
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4691
+	}
4470 4692
 
4471 4693
 	$active = time() - $upcontext['started'];
4472 4694
 	$hours = floor($active / 3600);
@@ -4476,16 +4698,20 @@  discard block
 block discarded – undo
4476 4698
 	if ($is_debug)
4477 4699
 	{
4478 4700
 		$totalTime = '';
4479
-		if ($hours > 0)
4480
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4481
-		if ($minutes > 0)
4482
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4483
-		if ($seconds > 0)
4484
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4701
+		if ($hours > 0) {
4702
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4703
+		}
4704
+		if ($minutes > 0) {
4705
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4706
+		}
4707
+		if ($seconds > 0) {
4708
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4709
+		}
4485 4710
 	}
4486 4711
 
4487
-	if ($is_debug && !empty($totalTime))
4488
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4712
+	if ($is_debug && !empty($totalTime)) {
4713
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4714
+	}
4489 4715
 
4490 4716
 	echo '<br>
4491 4717
 			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="https://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br>
@@ -4512,8 +4738,9 @@  discard block
 block discarded – undo
4512 4738
 
4513 4739
 	$current_substep = $_GET['substep'];
4514 4740
 
4515
-	if (empty($_GET['a']))
4516
-		$_GET['a'] = 0;
4741
+	if (empty($_GET['a'])) {
4742
+			$_GET['a'] = 0;
4743
+	}
4517 4744
 	$step_progress['name'] = 'Converting ips';
4518 4745
 	$step_progress['current'] = $_GET['a'];
4519 4746
 
@@ -4556,16 +4783,19 @@  discard block
 block discarded – undo
4556 4783
 				'empty' => '',
4557 4784
 				'limit' => $limit,
4558 4785
 		));
4559
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4560
-			$arIp[] = $row[$oldCol];
4786
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4787
+					$arIp[] = $row[$oldCol];
4788
+		}
4561 4789
 		$smcFunc['db_free_result']($request);
4562 4790
 
4563 4791
 		// Special case, null ip could keep us in a loop.
4564
-		if (is_null($arIp[0]))
4565
-			unset($arIp[0]);
4792
+		if (is_null($arIp[0])) {
4793
+					unset($arIp[0]);
4794
+		}
4566 4795
 
4567
-		if (empty($arIp))
4568
-			$is_done = true;
4796
+		if (empty($arIp)) {
4797
+					$is_done = true;
4798
+		}
4569 4799
 
4570 4800
 		$updates = array();
4571 4801
 		$cases = array();
@@ -4574,16 +4804,18 @@  discard block
 block discarded – undo
4574 4804
 		{
4575 4805
 			$arIp[$i] = trim($arIp[$i]);
4576 4806
 
4577
-			if (empty($arIp[$i]))
4578
-				continue;
4807
+			if (empty($arIp[$i])) {
4808
+							continue;
4809
+			}
4579 4810
 
4580 4811
 			$updates['ip' . $i] = $arIp[$i];
4581 4812
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4582 4813
 
4583 4814
 			if ($setSize > 0 && $i % $setSize === 0)
4584 4815
 			{
4585
-				if (count($updates) == 1)
4586
-					continue;
4816
+				if (count($updates) == 1) {
4817
+									continue;
4818
+				}
4587 4819
 
4588 4820
 				$updates['whereSet'] = array_values($updates);
4589 4821
 				$smcFunc['db_query']('', '
@@ -4617,8 +4849,7 @@  discard block
 block discarded – undo
4617 4849
 							'ip' => $ip
4618 4850
 					));
4619 4851
 				}
4620
-			}
4621
-			else
4852
+			} else
4622 4853
 			{
4623 4854
 				$updates['whereSet'] = array_values($updates);
4624 4855
 				$smcFunc['db_query']('', '
@@ -4632,9 +4863,9 @@  discard block
 block discarded – undo
4632 4863
 					$updates
4633 4864
 				);
4634 4865
 			}
4866
+		} else {
4867
+					$is_done = true;
4635 4868
 		}
4636
-		else
4637
-			$is_done = true;
4638 4869
 
4639 4870
 		$_GET['a'] += $limit;
4640 4871
 		$step_progress['current'] = $_GET['a'];
@@ -4660,10 +4891,11 @@  discard block
 block discarded – undo
4660 4891
  
4661 4892
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4662 4893
 
4663
-	if (isset($columns[$column]))
4664
-		return $columns[$column];
4665
-	else
4666
-		return null;
4667
-}
4894
+	if (isset($columns[$column])) {
4895
+			return $columns[$column];
4896
+	} else {
4897
+			return null;
4898
+	}
4899
+	}
4668 4900
 
4669 4901
 ?>
4670 4902
\ No newline at end of file
Please login to merge, or discard this patch.