Completed
Pull Request — release-2.1 (#4990)
by Mathias
10:06 queued 03:52
created
other/install.php 1 patch
Braces   +470 added lines, -350 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;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting for fatal errors.
154 160
 	error_reporting(E_ERROR | E_PARSE);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -230,10 +239,11 @@  discard block
 block discarded – undo
230 239
 		// Now just redirect to a blank.png...
231 240
 		$secure = false;
232 241
 
233
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
234
-			$secure = true;
235
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
236
-			$secure = true;
242
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
243
+					$secure = true;
244
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
245
+					$secure = true;
246
+		}
237 247
 
238 248
 		header('location: http' . ($secure ? 's' : '') . '://' . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']) . dirname($_SERVER['PHP_SELF']) . '/Themes/default/images/blank.png');
239 249
 		exit;
@@ -244,10 +254,11 @@  discard block
 block discarded – undo
244 254
 	{
245 255
 		// Get PHP's default timezone, if set
246 256
 		$ini_tz = ini_get('date.timezone');
247
-		if (!empty($ini_tz))
248
-			$timezone_id = $ini_tz;
249
-		else
250
-			$timezone_id = '';
257
+		if (!empty($ini_tz)) {
258
+					$timezone_id = $ini_tz;
259
+		} else {
260
+					$timezone_id = '';
261
+		}
251 262
 
252 263
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
253 264
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -277,8 +288,9 @@  discard block
 block discarded – undo
277 288
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
278 289
 		while ($entry = $dir->read())
279 290
 		{
280
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
281
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
291
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
292
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
293
+			}
282 294
 		}
283 295
 		$dir->close();
284 296
 	}
@@ -325,10 +337,11 @@  discard block
 block discarded – undo
325 337
 	}
326 338
 
327 339
 	// Override the language file?
328
-	if (isset($_GET['lang_file']))
329
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
330
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
331
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
340
+	if (isset($_GET['lang_file'])) {
341
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
342
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
343
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
344
+	}
332 345
 
333 346
 	// Make sure it exists, if it doesn't reset it.
334 347
 	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']))
@@ -337,8 +350,9 @@  discard block
 block discarded – undo
337 350
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
338 351
 
339 352
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
340
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
341
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
353
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
354
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
355
+		}
342 356
 	}
343 357
 
344 358
 	// And now include the actual language file itself.
@@ -355,15 +369,18 @@  discard block
 block discarded – undo
355 369
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings;
356 370
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist;
357 371
 
358
-	if (empty($sourcedir))
359
-		$sourcedir = dirname(__FILE__) . '/Sources';
372
+	if (empty($sourcedir)) {
373
+			$sourcedir = dirname(__FILE__) . '/Sources';
374
+	}
360 375
 
361 376
 	// Need this to check whether we need the database password.
362 377
 	require(dirname(__FILE__) . '/Settings.php');
363
-	if (!defined('SMF'))
364
-		define('SMF', 1);
365
-	if (empty($smcFunc))
366
-		$smcFunc = array();
378
+	if (!defined('SMF')) {
379
+			define('SMF', 1);
380
+	}
381
+	if (empty($smcFunc)) {
382
+			$smcFunc = array();
383
+	}
367 384
 
368 385
 	$modSettings['disableQueryCheck'] = true;
369 386
 
@@ -381,19 +398,20 @@  discard block
 block discarded – undo
381 398
 			if ($db_type == 'mysql')
382 399
 			{
383 400
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
384
-			}
385
-			elseif ($db_type == 'postgresql')
401
+			} elseif ($db_type == 'postgresql')
386 402
 			{
387 403
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
388 404
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
389 405
 			}
390 406
 		}
391 407
 
392
-		if (!empty($port))
393
-			$db_options['port'] = $port;
408
+		if (!empty($port)) {
409
+					$db_options['port'] = $port;
410
+		}
394 411
 
395
-		if (!$db_connection)
396
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
412
+		if (!$db_connection) {
413
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
414
+		}
397 415
 	}
398 416
 }
399 417
 
@@ -421,8 +439,9 @@  discard block
 block discarded – undo
421 439
 		// @todo REMOVE THIS!!
422 440
 		else
423 441
 		{
424
-			if (function_exists('doStep' . $_GET['step']))
425
-				call_user_func('doStep' . $_GET['step']);
442
+			if (function_exists('doStep' . $_GET['step'])) {
443
+							call_user_func('doStep' . $_GET['step']);
444
+			}
426 445
 		}
427 446
 		// Show the footer.
428 447
 		template_install_below();
@@ -440,8 +459,9 @@  discard block
 block discarded – undo
440 459
 	$incontext['sub_template'] = 'welcome_message';
441 460
 
442 461
 	// Done the submission?
443
-	if (isset($_POST['contbutt']))
444
-		return true;
462
+	if (isset($_POST['contbutt'])) {
463
+			return true;
464
+	}
445 465
 
446 466
 	// See if we think they have already installed it?
447 467
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -449,14 +469,17 @@  discard block
 block discarded – undo
449 469
 		$probably_installed = 0;
450 470
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
451 471
 		{
452
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
453
-				$probably_installed++;
454
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
455
-				$probably_installed++;
472
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
473
+							$probably_installed++;
474
+			}
475
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
476
+							$probably_installed++;
477
+			}
456 478
 		}
457 479
 
458
-		if ($probably_installed == 2)
459
-			$incontext['warning'] = $txt['error_already_installed'];
480
+		if ($probably_installed == 2) {
481
+					$incontext['warning'] = $txt['error_already_installed'];
482
+		}
460 483
 	}
461 484
 
462 485
 	// Is some database support even compiled in?
@@ -471,45 +494,54 @@  discard block
 block discarded – undo
471 494
 				$databases[$key]['supported'] = false;
472 495
 				$notFoundSQLFile = true;
473 496
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
497
+			} else {
498
+							$incontext['supported_databases'][] = $db;
474 499
 			}
475
-			else
476
-				$incontext['supported_databases'][] = $db;
477 500
 		}
478 501
 	}
479 502
 
480 503
 	// Check the PHP version.
481
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
482
-		$error = 'error_php_too_low';
504
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
505
+			$error = 'error_php_too_low';
506
+	}
483 507
 	// Make sure we have a supported database
484
-	elseif (empty($incontext['supported_databases']))
485
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
508
+	elseif (empty($incontext['supported_databases'])) {
509
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
510
+	}
486 511
 	// How about session support?  Some crazy sysadmin remove it?
487
-	elseif (!function_exists('session_start'))
488
-		$error = 'error_session_missing';
512
+	elseif (!function_exists('session_start')) {
513
+			$error = 'error_session_missing';
514
+	}
489 515
 	// Make sure they uploaded all the files.
490
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
491
-		$error = 'error_missing_files';
516
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
517
+			$error = 'error_missing_files';
518
+	}
492 519
 	// Very simple check on the session.save_path for Windows.
493 520
 	// @todo Move this down later if they don't use database-driven sessions?
494
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
495
-		$error = 'error_session_save_path';
521
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
522
+			$error = 'error_session_save_path';
523
+	}
496 524
 
497 525
 	// Since each of the three messages would look the same, anyway...
498
-	if (isset($error))
499
-		$incontext['error'] = $txt[$error];
526
+	if (isset($error)) {
527
+			$incontext['error'] = $txt[$error];
528
+	}
500 529
 
501 530
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
502
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
503
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
531
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
532
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
533
+	}
504 534
 
505 535
 	// Confirm mbstring is loaded...
506
-	if (!extension_loaded('mbstring'))
507
-		$incontext['error'] = $txt['install_no_mbstring'];
536
+	if (!extension_loaded('mbstring')) {
537
+			$incontext['error'] = $txt['install_no_mbstring'];
538
+	}
508 539
 
509 540
 	// Check for https stream support.
510 541
 	$supported_streams = stream_get_wrappers();
511
-	if (!in_array('https', $supported_streams))
512
-		$incontext['warning'] = $txt['install_no_https'];
542
+	if (!in_array('https', $supported_streams)) {
543
+			$incontext['warning'] = $txt['install_no_https'];
544
+	}
513 545
 
514 546
 	return false;
515 547
 }
@@ -534,12 +566,14 @@  discard block
 block discarded – undo
534 566
 		'Settings_bak.php',
535 567
 	);
536 568
 
537
-	foreach ($incontext['detected_languages'] as $lang => $temp)
538
-		$extra_files[] = 'Themes/default/languages/' . $lang;
569
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
570
+			$extra_files[] = 'Themes/default/languages/' . $lang;
571
+	}
539 572
 
540 573
 	// With mod_security installed, we could attempt to fix it with .htaccess.
541
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
542
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
574
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
575
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
576
+	}
543 577
 
544 578
 	$failed_files = array();
545 579
 
@@ -551,20 +585,23 @@  discard block
 block discarded – undo
551 585
 		foreach ($writable_files as $file)
552 586
 		{
553 587
 			// Some files won't exist, try to address up front
554
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
555
-				@touch(dirname(__FILE__) . '/' . $file);
588
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
589
+							@touch(dirname(__FILE__) . '/' . $file);
590
+			}
556 591
 			// NOW do the writable check...
557 592
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
558 593
 			{
559 594
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
560 595
 
561 596
 				// Well, 755 hopefully worked... if not, try 777.
562
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
563
-					$failed_files[] = $file;
597
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
598
+									$failed_files[] = $file;
599
+				}
564 600
 			}
565 601
 		}
566
-		foreach ($extra_files as $file)
567
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
602
+		foreach ($extra_files as $file) {
603
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
604
+		}
568 605
 	}
569 606
 	// Windows is trickier.  Let's try opening for r+...
570 607
 	else
@@ -574,30 +611,35 @@  discard block
 block discarded – undo
574 611
 		foreach ($writable_files as $file)
575 612
 		{
576 613
 			// Folders can't be opened for write... but the index.php in them can ;)
577
-			if (is_dir(dirname(__FILE__) . '/' . $file))
578
-				$file .= '/index.php';
614
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
615
+							$file .= '/index.php';
616
+			}
579 617
 
580 618
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
581 619
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
582 620
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
583 621
 
584 622
 			// Hmm, okay, try just for write in that case...
585
-			if (!is_resource($fp))
586
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
623
+			if (!is_resource($fp)) {
624
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
625
+			}
587 626
 
588
-			if (!is_resource($fp))
589
-				$failed_files[] = $file;
627
+			if (!is_resource($fp)) {
628
+							$failed_files[] = $file;
629
+			}
590 630
 
591 631
 			@fclose($fp);
592 632
 		}
593
-		foreach ($extra_files as $file)
594
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
633
+		foreach ($extra_files as $file) {
634
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
635
+		}
595 636
 	}
596 637
 
597 638
 	$failure = count($failed_files) >= 1;
598 639
 
599
-	if (!isset($_SERVER))
600
-		return !$failure;
640
+	if (!isset($_SERVER)) {
641
+			return !$failure;
642
+	}
601 643
 
602 644
 	// Put the list into context.
603 645
 	$incontext['failed_files'] = $failed_files;
@@ -645,19 +687,23 @@  discard block
 block discarded – undo
645 687
 
646 688
 		if (!isset($ftp) || $ftp->error !== false)
647 689
 		{
648
-			if (!isset($ftp))
649
-				$ftp = new ftp_connection(null);
690
+			if (!isset($ftp)) {
691
+							$ftp = new ftp_connection(null);
692
+			}
650 693
 			// Save the error so we can mess with listing...
651
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
652
-				$incontext['ftp_errors'][] = $ftp->last_message;
694
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
695
+							$incontext['ftp_errors'][] = $ftp->last_message;
696
+			}
653 697
 
654 698
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
655 699
 
656
-			if (empty($_POST['ftp_path']) && $found_path)
657
-				$_POST['ftp_path'] = $detect_path;
700
+			if (empty($_POST['ftp_path']) && $found_path) {
701
+							$_POST['ftp_path'] = $detect_path;
702
+			}
658 703
 
659
-			if (!isset($_POST['ftp_username']))
660
-				$_POST['ftp_username'] = $username;
704
+			if (!isset($_POST['ftp_username'])) {
705
+							$_POST['ftp_username'] = $username;
706
+			}
661 707
 
662 708
 			// Set the username etc, into context.
663 709
 			$incontext['ftp'] = array(
@@ -669,8 +715,7 @@  discard block
 block discarded – undo
669 715
 			);
670 716
 
671 717
 			return false;
672
-		}
673
-		else
718
+		} else
674 719
 		{
675 720
 			$_SESSION['installer_temp_ftp'] = array(
676 721
 				'server' => $_POST['ftp_server'],
@@ -684,10 +729,12 @@  discard block
 block discarded – undo
684 729
 
685 730
 			foreach ($failed_files as $file)
686 731
 			{
687
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
688
-					$ftp->chmod($file, 0755);
689
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
690
-					$ftp->chmod($file, 0777);
732
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
733
+									$ftp->chmod($file, 0755);
734
+				}
735
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
736
+									$ftp->chmod($file, 0777);
737
+				}
691 738
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
692 739
 				{
693 740
 					$failed_files_updated[] = $file;
@@ -743,15 +790,17 @@  discard block
 block discarded – undo
743 790
 
744 791
 			if (!$foundOne)
745 792
 			{
746
-				if (isset($db['default_host']))
747
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
793
+				if (isset($db['default_host'])) {
794
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
795
+				}
748 796
 				if (isset($db['default_user']))
749 797
 				{
750 798
 					$incontext['db']['user'] = ini_get($db['default_user']);
751 799
 					$incontext['db']['name'] = ini_get($db['default_user']);
752 800
 				}
753
-				if (isset($db['default_password']))
754
-					$incontext['db']['pass'] = ini_get($db['default_password']);
801
+				if (isset($db['default_password'])) {
802
+									$incontext['db']['pass'] = ini_get($db['default_password']);
803
+				}
755 804
 
756 805
 				// For simplicity and less confusion, leave the port blank by default
757 806
 				$incontext['db']['port'] = '';
@@ -770,10 +819,10 @@  discard block
 block discarded – undo
770 819
 		$incontext['db']['server'] = $_POST['db_server'];
771 820
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
772 821
 
773
-		if (!empty($_POST['db_port']))
774
-			$incontext['db']['port'] = $_POST['db_port'];
775
-	}
776
-	else
822
+		if (!empty($_POST['db_port'])) {
823
+					$incontext['db']['port'] = $_POST['db_port'];
824
+		}
825
+	} else
777 826
 	{
778 827
 		$incontext['db']['prefix'] = 'smf_';
779 828
 	}
@@ -809,10 +858,11 @@  discard block
 block discarded – undo
809 858
 		if (!empty($_POST['db_port']))
810 859
 		{
811 860
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
812
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
813
-				$vars['db_port'] = (int) $_POST['db_port'];
814
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
815
-				$vars['db_port'] = (int) $_POST['db_port'];
861
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
862
+							$vars['db_port'] = (int) $_POST['db_port'];
863
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
864
+							$vars['db_port'] = (int) $_POST['db_port'];
865
+			}
816 866
 		}
817 867
 
818 868
 		// God I hope it saved!
@@ -825,8 +875,9 @@  discard block
 block discarded – undo
825 875
 		// Make sure it works.
826 876
 		require(dirname(__FILE__) . '/Settings.php');
827 877
 
828
-		if (empty($sourcedir))
829
-			$sourcedir = dirname(__FILE__) . '/Sources';
878
+		if (empty($sourcedir)) {
879
+					$sourcedir = dirname(__FILE__) . '/Sources';
880
+		}
830 881
 
831 882
 		// Better find the database file!
832 883
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -836,12 +887,14 @@  discard block
 block discarded – undo
836 887
 		}
837 888
 
838 889
 		// Now include it for database functions!
839
-		if (!defined('SMF'))
840
-			define('SMF', 1);
890
+		if (!defined('SMF')) {
891
+					define('SMF', 1);
892
+		}
841 893
 
842 894
 		$modSettings['disableQueryCheck'] = true;
843
-		if (empty($smcFunc))
844
-			$smcFunc = array();
895
+		if (empty($smcFunc)) {
896
+					$smcFunc = array();
897
+		}
845 898
 
846 899
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
847 900
 
@@ -850,11 +903,13 @@  discard block
 block discarded – undo
850 903
 
851 904
 		$options = array('non_fatal' => true, 'dont_select_db' => !$needsDB);
852 905
 		// Add in the port if needed
853
-		if (!empty($db_port))
854
-			$options['port'] = $db_port;
906
+		if (!empty($db_port)) {
907
+					$options['port'] = $db_port;
908
+		}
855 909
 		
856
-		if (!empty($db_mb4))
857
-			$options['db_mb4'] = $db_mb4;
910
+		if (!empty($db_mb4)) {
911
+					$options['db_mb4'] = $db_mb4;
912
+		}
858 913
 
859 914
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
860 915
 
@@ -940,12 +995,14 @@  discard block
 block discarded – undo
940 995
 	$incontext['page_title'] = $txt['install_settings'];
941 996
 
942 997
 	// Let's see if we got the database type correct.
943
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
944
-		$db_type = $_POST['db_type'];
998
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
999
+			$db_type = $_POST['db_type'];
1000
+	}
945 1001
 
946 1002
 	// Else we'd better be able to get the connection.
947
-	else
948
-		load_database();
1003
+	else {
1004
+			load_database();
1005
+	}
949 1006
 
950 1007
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
951 1008
 
@@ -954,10 +1011,11 @@  discard block
 block discarded – undo
954 1011
 
955 1012
 		$secure = false;
956 1013
 
957
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
958
-			$secure = true;
959
-		elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
960
-			$secure = true;
1014
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1015
+					$secure = true;
1016
+		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
1017
+					$secure = true;
1018
+		}
961 1019
 
962 1020
 	// Now, to put what we've learned together... and add a path.
963 1021
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -989,18 +1047,21 @@  discard block
 block discarded – undo
989 1047
 	// Submitting?
990 1048
 	if (isset($_POST['boardurl']))
991 1049
 	{
992
-		if (substr($_POST['boardurl'], -10) == '/index.php')
993
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
994
-		elseif (substr($_POST['boardurl'], -1) == '/')
995
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
996
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
997
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1050
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1051
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1052
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1053
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1054
+		}
1055
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1056
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1057
+		}
998 1058
 
999 1059
 		//Make sure boardurl is aligned with ssl setting
1000
-		if (empty($_POST['force_ssl']))
1001
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1002
-		else
1003
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1060
+		if (empty($_POST['force_ssl'])) {
1061
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1062
+		} else {
1063
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1064
+		}
1004 1065
 
1005 1066
 		// Save these variables.
1006 1067
 		$vars = array(
@@ -1039,10 +1100,10 @@  discard block
 block discarded – undo
1039 1100
 			{
1040 1101
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1041 1102
 				return false;
1042
-			}
1043
-			else
1044
-				// Set the character set here.
1103
+			} else {
1104
+							// Set the character set here.
1045 1105
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1106
+			}
1046 1107
 		}
1047 1108
 
1048 1109
 		// Good, skip on.
@@ -1062,8 +1123,9 @@  discard block
 block discarded – undo
1062 1123
 	$incontext['continue'] = 1;
1063 1124
 
1064 1125
 	// Already done?
1065
-	if (isset($_POST['pop_done']))
1066
-		return true;
1126
+	if (isset($_POST['pop_done'])) {
1127
+			return true;
1128
+	}
1067 1129
 
1068 1130
 	// Reload settings.
1069 1131
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1081,8 +1143,9 @@  discard block
 block discarded – undo
1081 1143
 	$modSettings = array();
1082 1144
 	if ($result !== false)
1083 1145
 	{
1084
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1085
-			$modSettings[$row['variable']] = $row['value'];
1146
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1147
+					$modSettings[$row['variable']] = $row['value'];
1148
+		}
1086 1149
 		$smcFunc['db_free_result']($result);
1087 1150
 
1088 1151
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1095,20 +1158,22 @@  discard block
 block discarded – undo
1095 1158
 	$modSettings['disableQueryCheck'] = true;
1096 1159
 
1097 1160
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1098
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1099
-		$smcFunc['db_query']('', '
1161
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1162
+			$smcFunc['db_query']('', '
1100 1163
 			SET NAMES {string:utf8}',
1101 1164
 			array(
1102 1165
 				'db_error_skip' => true,
1103 1166
 				'utf8' => 'utf8',
1104 1167
 			)
1105 1168
 		);
1169
+	}
1106 1170
 
1107 1171
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1108
-	if (substr(__DIR__, -1) == '\\')
1109
-		$attachdir = __DIR__ . 'attachments';
1110
-	else
1111
-		$attachdir = __DIR__ . '/attachments';
1172
+	if (substr(__DIR__, -1) == '\\') {
1173
+			$attachdir = __DIR__ . 'attachments';
1174
+	} else {
1175
+			$attachdir = __DIR__ . '/attachments';
1176
+	}
1112 1177
 
1113 1178
 	$replaces = array(
1114 1179
 		'{$db_prefix}' => $db_prefix,
@@ -1125,8 +1190,9 @@  discard block
 block discarded – undo
1125 1190
 
1126 1191
 	foreach ($txt as $key => $value)
1127 1192
 	{
1128
-		if (substr($key, 0, 8) == 'default_')
1129
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1193
+		if (substr($key, 0, 8) == 'default_') {
1194
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1195
+		}
1130 1196
 	}
1131 1197
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1132 1198
 
@@ -1141,8 +1207,9 @@  discard block
 block discarded – undo
1141 1207
 
1142 1208
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1143 1209
 		{
1144
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1145
-				$engines[] = $row['Engine'];
1210
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1211
+							$engines[] = $row['Engine'];
1212
+			}
1146 1213
 		}
1147 1214
 
1148 1215
 		// Done with this now
@@ -1166,8 +1233,7 @@  discard block
 block discarded – undo
1166 1233
 			$replaces['START TRANSACTION;'] = '';
1167 1234
 			$replaces['COMMIT;'] = '';
1168 1235
 		}
1169
-	}
1170
-	else
1236
+	} else
1171 1237
 	{
1172 1238
 		$has_innodb = false;
1173 1239
 	}
@@ -1189,21 +1255,24 @@  discard block
 block discarded – undo
1189 1255
 	foreach ($sql_lines as $count => $line)
1190 1256
 	{
1191 1257
 		// No comments allowed!
1192
-		if (substr(trim($line), 0, 1) != '#')
1193
-			$current_statement .= "\n" . rtrim($line);
1258
+		if (substr(trim($line), 0, 1) != '#') {
1259
+					$current_statement .= "\n" . rtrim($line);
1260
+		}
1194 1261
 
1195 1262
 		// Is this the end of the query string?
1196
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1197
-			continue;
1263
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1264
+					continue;
1265
+		}
1198 1266
 
1199 1267
 		// Does this table already exist?  If so, don't insert more data into it!
1200 1268
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1201 1269
 		{
1202 1270
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1203
-			if (!empty($matches[0]))
1204
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1205
-			else
1206
-				$incontext['sql_results']['insert_dups']++;
1271
+			if (!empty($matches[0])) {
1272
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1273
+			} else {
1274
+							$incontext['sql_results']['insert_dups']++;
1275
+			}
1207 1276
 
1208 1277
 			$current_statement = '';
1209 1278
 			continue;
@@ -1212,8 +1281,9 @@  discard block
 block discarded – undo
1212 1281
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1213 1282
 		{
1214 1283
 			// Use the appropriate function based on the DB type
1215
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1216
-				$db_errorno = $db_type . '_errno';
1284
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1285
+							$db_errorno = $db_type . '_errno';
1286
+			}
1217 1287
 
1218 1288
 			// Error 1050: Table already exists!
1219 1289
 			// @todo Needs to be made better!
@@ -1228,18 +1298,18 @@  discard block
 block discarded – undo
1228 1298
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1229 1299
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1230 1300
 			}
1231
-		}
1232
-		else
1301
+		} else
1233 1302
 		{
1234
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1235
-				$incontext['sql_results']['tables']++;
1236
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1303
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1304
+							$incontext['sql_results']['tables']++;
1305
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1237 1306
 			{
1238 1307
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1239
-				if (!empty($matches[0]))
1240
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1241
-				else
1242
-					$incontext['sql_results']['inserts']++;
1308
+				if (!empty($matches[0])) {
1309
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1310
+				} else {
1311
+									$incontext['sql_results']['inserts']++;
1312
+				}
1243 1313
 			}
1244 1314
 		}
1245 1315
 
@@ -1252,15 +1322,17 @@  discard block
 block discarded – undo
1252 1322
 	// Sort out the context for the SQL.
1253 1323
 	foreach ($incontext['sql_results'] as $key => $number)
1254 1324
 	{
1255
-		if ($number == 0)
1256
-			unset($incontext['sql_results'][$key]);
1257
-		else
1258
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1325
+		if ($number == 0) {
1326
+					unset($incontext['sql_results'][$key]);
1327
+		} else {
1328
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1329
+		}
1259 1330
 	}
1260 1331
 
1261 1332
 	// Make sure UTF will be used globally.
1262
-	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'])))
1263
-		$newSettings[] = array('global_character_set', 'UTF-8');
1333
+	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']))) {
1334
+			$newSettings[] = array('global_character_set', 'UTF-8');
1335
+	}
1264 1336
 
1265 1337
 	// Auto-detect local & global cookie settings
1266 1338
 	$url_parts = parse_url($boardurl);
@@ -1289,15 +1361,19 @@  discard block
 block discarded – undo
1289 1361
 
1290 1362
 		// Look for subfolder, if found, set localCookie
1291 1363
 		// Checking for len > 1 ensures you don't have just a slash...
1292
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1293
-			$localCookies = '1';
1364
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1365
+					$localCookies = '1';
1366
+		}
1294 1367
 
1295
-		if (isset($globalCookies))
1296
-			$newSettings[] = array('globalCookies', $globalCookies);
1297
-		if (isset($globalCookiesDomain))
1298
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1299
-		if (isset($localCookies))
1300
-			$newSettings[] = array('localCookies', $localCookies);
1368
+		if (isset($globalCookies)) {
1369
+					$newSettings[] = array('globalCookies', $globalCookies);
1370
+		}
1371
+		if (isset($globalCookiesDomain)) {
1372
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1373
+		}
1374
+		if (isset($localCookies)) {
1375
+					$newSettings[] = array('localCookies', $localCookies);
1376
+		}
1301 1377
 	}
1302 1378
 
1303 1379
 	// Are we allowing stat collection?
@@ -1315,16 +1391,17 @@  discard block
 block discarded – undo
1315 1391
 			fwrite($fp, $out);
1316 1392
 
1317 1393
 			$return_data = '';
1318
-			while (!feof($fp))
1319
-				$return_data .= fgets($fp, 128);
1394
+			while (!feof($fp)) {
1395
+							$return_data .= fgets($fp, 128);
1396
+			}
1320 1397
 
1321 1398
 			fclose($fp);
1322 1399
 
1323 1400
 			// Get the unique site ID.
1324 1401
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1325 1402
 
1326
-			if (!empty($ID[1]))
1327
-				$smcFunc['db_insert']('replace',
1403
+			if (!empty($ID[1])) {
1404
+							$smcFunc['db_insert']('replace',
1328 1405
 					$db_prefix . 'settings',
1329 1406
 					array('variable' => 'string', 'value' => 'string'),
1330 1407
 					array(
@@ -1333,11 +1410,12 @@  discard block
 block discarded – undo
1333 1410
 					),
1334 1411
 					array('variable')
1335 1412
 				);
1413
+			}
1336 1414
 		}
1337 1415
 	}
1338 1416
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1339
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1340
-		$smcFunc['db_query']('', '
1417
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1418
+			$smcFunc['db_query']('', '
1341 1419
 			DELETE FROM {db_prefix}settings
1342 1420
 			WHERE variable = {string:enable_sm_stats}',
1343 1421
 			array(
@@ -1345,20 +1423,23 @@  discard block
 block discarded – undo
1345 1423
 				'db_error_skip' => true,
1346 1424
 			)
1347 1425
 		);
1426
+	}
1348 1427
 
1349 1428
 	// Are we enabling SSL?
1350
-	if (!empty($_POST['force_ssl']))
1351
-		$newSettings[] = array('force_ssl', 1);
1429
+	if (!empty($_POST['force_ssl'])) {
1430
+			$newSettings[] = array('force_ssl', 1);
1431
+	}
1352 1432
 
1353 1433
 	// Setting a timezone is required.
1354 1434
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1355 1435
 	{
1356 1436
 		// Get PHP's default timezone, if set
1357 1437
 		$ini_tz = ini_get('date.timezone');
1358
-		if (!empty($ini_tz))
1359
-			$timezone_id = $ini_tz;
1360
-		else
1361
-			$timezone_id = '';
1438
+		if (!empty($ini_tz)) {
1439
+					$timezone_id = $ini_tz;
1440
+		} else {
1441
+					$timezone_id = '';
1442
+		}
1362 1443
 
1363 1444
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1364 1445
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1367,8 +1448,9 @@  discard block
 block discarded – undo
1367 1448
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1368 1449
 		}
1369 1450
 
1370
-		if (date_default_timezone_set($timezone_id))
1371
-			$newSettings[] = array('default_timezone', $timezone_id);
1451
+		if (date_default_timezone_set($timezone_id)) {
1452
+					$newSettings[] = array('default_timezone', $timezone_id);
1453
+		}
1372 1454
 	}
1373 1455
 
1374 1456
 	if (!empty($newSettings))
@@ -1399,16 +1481,18 @@  discard block
 block discarded – undo
1399 1481
 	}
1400 1482
 
1401 1483
 	// MySQL specific stuff
1402
-	if (substr($db_type, 0, 5) != 'mysql')
1403
-		return false;
1484
+	if (substr($db_type, 0, 5) != 'mysql') {
1485
+			return false;
1486
+	}
1404 1487
 
1405 1488
 	// Find database user privileges.
1406 1489
 	$privs = array();
1407 1490
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1408 1491
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1409 1492
 	{
1410
-		if ($row['Privilege'] == 'Alter')
1411
-			$privs[] = $row['Privilege'];
1493
+		if ($row['Privilege'] == 'Alter') {
1494
+					$privs[] = $row['Privilege'];
1495
+		}
1412 1496
 	}
1413 1497
 	$smcFunc['db_free_result']($get_privs);
1414 1498
 
@@ -1438,8 +1522,9 @@  discard block
 block discarded – undo
1438 1522
 	$incontext['continue'] = 1;
1439 1523
 
1440 1524
 	// Skipping?
1441
-	if (!empty($_POST['skip']))
1442
-		return true;
1525
+	if (!empty($_POST['skip'])) {
1526
+			return true;
1527
+	}
1443 1528
 
1444 1529
 	// Need this to check whether we need the database password.
1445 1530
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1456,18 +1541,22 @@  discard block
 block discarded – undo
1456 1541
 	// We need this to properly hash the password for Admin
1457 1542
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1458 1543
 			global $sourcedir;
1459
-			if (function_exists('mb_strtolower'))
1460
-				return mb_strtolower($string, 'UTF-8');
1544
+			if (function_exists('mb_strtolower')) {
1545
+							return mb_strtolower($string, 'UTF-8');
1546
+			}
1461 1547
 			require_once($sourcedir . '/Subs-Charset.php');
1462 1548
 			return utf8_strtolower($string);
1463 1549
 		};
1464 1550
 
1465
-	if (!isset($_POST['username']))
1466
-		$_POST['username'] = '';
1467
-	if (!isset($_POST['email']))
1468
-		$_POST['email'] = '';
1469
-	if (!isset($_POST['server_email']))
1470
-		$_POST['server_email'] = '';
1551
+	if (!isset($_POST['username'])) {
1552
+			$_POST['username'] = '';
1553
+	}
1554
+	if (!isset($_POST['email'])) {
1555
+			$_POST['email'] = '';
1556
+	}
1557
+	if (!isset($_POST['server_email'])) {
1558
+			$_POST['server_email'] = '';
1559
+	}
1471 1560
 
1472 1561
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1473 1562
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1486,8 +1575,9 @@  discard block
 block discarded – undo
1486 1575
 			'admin_group' => 1,
1487 1576
 		)
1488 1577
 	);
1489
-	if ($smcFunc['db_num_rows']($request) != 0)
1490
-		$incontext['skip'] = 1;
1578
+	if ($smcFunc['db_num_rows']($request) != 0) {
1579
+			$incontext['skip'] = 1;
1580
+	}
1491 1581
 	$smcFunc['db_free_result']($request);
1492 1582
 
1493 1583
 	// Trying to create an account?
@@ -1518,8 +1608,9 @@  discard block
 block discarded – undo
1518 1608
 		}
1519 1609
 
1520 1610
 		// Update the webmaster's email?
1521
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1522
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1611
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1612
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1613
+		}
1523 1614
 
1524 1615
 		// Work out whether we're going to have dodgy characters and remove them.
1525 1616
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1542,32 +1633,27 @@  discard block
 block discarded – undo
1542 1633
 			$smcFunc['db_free_result']($result);
1543 1634
 
1544 1635
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1545
-		}
1546
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1636
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1547 1637
 		{
1548 1638
 			// Try the previous step again.
1549 1639
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1550 1640
 			return false;
1551
-		}
1552
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1641
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1553 1642
 		{
1554 1643
 			// Try the previous step again.
1555 1644
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1556 1645
 			return false;
1557
-		}
1558
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1646
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1559 1647
 		{
1560 1648
 			// One step back, this time fill out a proper admin email address.
1561 1649
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1562 1650
 			return false;
1563
-		}
1564
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1651
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1565 1652
 		{
1566 1653
 			// One step back, this time fill out a proper admin email address.
1567 1654
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1568 1655
 			return false;
1569
-		}
1570
-		elseif ($_POST['username'] != '')
1656
+		} elseif ($_POST['username'] != '')
1571 1657
 		{
1572 1658
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1573 1659
 
@@ -1635,17 +1721,19 @@  discard block
 block discarded – undo
1635 1721
 	reloadSettings();
1636 1722
 
1637 1723
 	// Bring a warning over.
1638
-	if (!empty($incontext['account_existed']))
1639
-		$incontext['warning'] = $incontext['account_existed'];
1724
+	if (!empty($incontext['account_existed'])) {
1725
+			$incontext['warning'] = $incontext['account_existed'];
1726
+	}
1640 1727
 
1641
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1642
-		$smcFunc['db_query']('', '
1728
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1729
+			$smcFunc['db_query']('', '
1643 1730
 			SET NAMES {string:db_character_set}',
1644 1731
 			array(
1645 1732
 				'db_character_set' => $db_character_set,
1646 1733
 				'db_error_skip' => true,
1647 1734
 			)
1648 1735
 		);
1736
+	}
1649 1737
 
1650 1738
 	// As track stats is by default enabled let's add some activity.
1651 1739
 	$smcFunc['db_insert']('ignore',
@@ -1666,14 +1754,16 @@  discard block
 block discarded – undo
1666 1754
 	// Only proceed if we can load the data.
1667 1755
 	if ($request)
1668 1756
 	{
1669
-		while ($row = $smcFunc['db_fetch_row']($request))
1670
-			$modSettings[$row[0]] = $row[1];
1757
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1758
+					$modSettings[$row[0]] = $row[1];
1759
+		}
1671 1760
 		$smcFunc['db_free_result']($request);
1672 1761
 	}
1673 1762
 
1674 1763
 	// Automatically log them in ;)
1675
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1676
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1764
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1765
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1766
+	}
1677 1767
 
1678 1768
 	$result = $smcFunc['db_query']('', '
1679 1769
 		SELECT value
@@ -1684,13 +1774,14 @@  discard block
 block discarded – undo
1684 1774
 			'db_error_skip' => true,
1685 1775
 		)
1686 1776
 	);
1687
-	if ($smcFunc['db_num_rows']($result) != 0)
1688
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1777
+	if ($smcFunc['db_num_rows']($result) != 0) {
1778
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1779
+	}
1689 1780
 	$smcFunc['db_free_result']($result);
1690 1781
 
1691
-	if (empty($db_sessions))
1692
-		$_SESSION['admin_time'] = time();
1693
-	else
1782
+	if (empty($db_sessions)) {
1783
+			$_SESSION['admin_time'] = time();
1784
+	} else
1694 1785
 	{
1695 1786
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1696 1787
 
@@ -1714,8 +1805,9 @@  discard block
 block discarded – undo
1714 1805
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1715 1806
 		function($string){
1716 1807
 			global $sourcedir;
1717
-			if (function_exists('mb_strtolower'))
1718
-				return mb_strtolower($string, 'UTF-8');
1808
+			if (function_exists('mb_strtolower')) {
1809
+							return mb_strtolower($string, 'UTF-8');
1810
+			}
1719 1811
 			require_once($sourcedir . '/Subs-Charset.php');
1720 1812
 			return utf8_strtolower($string);
1721 1813
 		};
@@ -1731,8 +1823,9 @@  discard block
 block discarded – undo
1731 1823
 		)
1732 1824
 	);
1733 1825
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1734
-	if ($smcFunc['db_num_rows']($request) > 0)
1735
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1826
+	if ($smcFunc['db_num_rows']($request) > 0) {
1827
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1828
+	}
1736 1829
 	$smcFunc['db_free_result']($request);
1737 1830
 
1738 1831
 	// Now is the perfect time to fetch the SM files.
@@ -1751,8 +1844,9 @@  discard block
 block discarded – undo
1751 1844
 
1752 1845
 	// Check if we need some stupid MySQL fix.
1753 1846
 	$server_version = $smcFunc['db_server_info']();
1754
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1755
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1847
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1848
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1849
+	}
1756 1850
 
1757 1851
 	// Some final context for the template.
1758 1852
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1772,8 +1866,9 @@  discard block
 block discarded – undo
1772 1866
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1773 1867
 
1774 1868
 	// @todo Do we just want to read the file in clean, and split it this way always?
1775
-	if (count($settingsArray) == 1)
1776
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1869
+	if (count($settingsArray) == 1) {
1870
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1871
+	}
1777 1872
 
1778 1873
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1779 1874
 	{
@@ -1781,25 +1876,29 @@  discard block
 block discarded – undo
1781 1876
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1782 1877
 		{
1783 1878
 			// Set the ten lines to nothing.
1784
-			for ($j=0; $j < 10; $j++)
1785
-				$settingsArray[$i++] = '';
1879
+			for ($j=0; $j < 10; $j++) {
1880
+							$settingsArray[$i++] = '';
1881
+			}
1786 1882
 
1787 1883
 			continue;
1788 1884
 		}
1789 1885
 
1790
-		if (trim($settingsArray[$i]) == '?' . '>')
1791
-			$settingsArray[$i] = '';
1886
+		if (trim($settingsArray[$i]) == '?' . '>') {
1887
+					$settingsArray[$i] = '';
1888
+		}
1792 1889
 
1793 1890
 		// Don't trim or bother with it if it's not a variable.
1794
-		if (substr($settingsArray[$i], 0, 1) != '$')
1795
-			continue;
1891
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1892
+					continue;
1893
+		}
1796 1894
 
1797 1895
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1798 1896
 
1799
-		foreach ($vars as $var => $val)
1800
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1897
+		foreach ($vars as $var => $val) {
1898
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1801 1899
 			{
1802 1900
 				$comment = strstr($settingsArray[$i], '#');
1901
+		}
1803 1902
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1804 1903
 				unset($vars[$var]);
1805 1904
 			}
@@ -1809,36 +1908,41 @@  discard block
 block discarded – undo
1809 1908
 	if (!empty($vars))
1810 1909
 	{
1811 1910
 		$settingsArray[$i++] = '';
1812
-		foreach ($vars as $var => $val)
1813
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1911
+		foreach ($vars as $var => $val) {
1912
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1913
+		}
1814 1914
 	}
1815 1915
 
1816 1916
 	// Blank out the file - done to fix a oddity with some servers.
1817 1917
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1818
-	if (!$fp)
1819
-		return false;
1918
+	if (!$fp) {
1919
+			return false;
1920
+	}
1820 1921
 	fclose($fp);
1821 1922
 
1822 1923
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1823 1924
 
1824 1925
 	// Gotta have one of these ;)
1825
-	if (trim($settingsArray[0]) != '<?php')
1826
-		fwrite($fp, "<?php\n");
1926
+	if (trim($settingsArray[0]) != '<?php') {
1927
+			fwrite($fp, "<?php\n");
1928
+	}
1827 1929
 
1828 1930
 	$lines = count($settingsArray);
1829 1931
 	for ($i = 0; $i < $lines - 1; $i++)
1830 1932
 	{
1831 1933
 		// Don't just write a bunch of blank lines.
1832
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1833
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1934
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1935
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1936
+		}
1834 1937
 	}
1835 1938
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1836 1939
 	fclose($fp);
1837 1940
 
1838 1941
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1839 1942
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1840
-	if (function_exists('opcache_invalidate'))
1841
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1943
+	if (function_exists('opcache_invalidate')) {
1944
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1945
+	}
1842 1946
 
1843 1947
 	return true;
1844 1948
 }
@@ -1848,10 +1952,11 @@  discard block
 block discarded – undo
1848 1952
 	global $cachedir;
1849 1953
 
1850 1954
 	// Write out the db_last_error file with the error timestamp
1851
-	if (!empty($cachedir) && is_writable($cachedir))
1852
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1853
-	else
1854
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1955
+	if (!empty($cachedir) && is_writable($cachedir)) {
1956
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1957
+	} else {
1958
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1959
+	}
1855 1960
 
1856 1961
 	return true;
1857 1962
 }
@@ -1868,9 +1973,9 @@  discard block
 block discarded – undo
1868 1973
 	SecFilterScanPOST Off
1869 1974
 </IfModule>';
1870 1975
 
1871
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1872
-		return true;
1873
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1976
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1977
+			return true;
1978
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1874 1979
 	{
1875 1980
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1876 1981
 
@@ -1882,29 +1987,28 @@  discard block
 block discarded – undo
1882 1987
 				fwrite($ht_handle, $htaccess_addition);
1883 1988
 				fclose($ht_handle);
1884 1989
 				return true;
1990
+			} else {
1991
+							return false;
1885 1992
 			}
1886
-			else
1887
-				return false;
1993
+		} else {
1994
+					return true;
1888 1995
 		}
1889
-		else
1890
-			return true;
1891
-	}
1892
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1893
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1894
-	elseif (is_writable(dirname(__FILE__)))
1996
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1997
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1998
+	} elseif (is_writable(dirname(__FILE__)))
1895 1999
 	{
1896 2000
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1897 2001
 		{
1898 2002
 			fwrite($ht_handle, $htaccess_addition);
1899 2003
 			fclose($ht_handle);
1900 2004
 			return true;
2005
+		} else {
2006
+					return false;
1901 2007
 		}
1902
-		else
2008
+	} else {
1903 2009
 			return false;
1904 2010
 	}
1905
-	else
1906
-		return false;
1907
-}
2011
+	}
1908 2012
 
1909 2013
 function template_install_above()
1910 2014
 {
@@ -1943,9 +2047,10 @@  discard block
 block discarded – undo
1943 2047
 							<label for="installer_language">', $txt['installer_language'], ':</label>
1944 2048
 							<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1945 2049
 
1946
-		foreach ($incontext['detected_languages'] as $lang => $name)
1947
-			echo '
2050
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2051
+					echo '
1948 2052
 								<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2053
+		}
1949 2054
 
1950 2055
 		echo '
1951 2056
 							</select>
@@ -1965,9 +2070,10 @@  discard block
 block discarded – undo
1965 2070
 					<h2>', $txt['upgrade_progress'], '</h2>
1966 2071
 					<ul>';
1967 2072
 
1968
-	foreach ($incontext['steps'] as $num => $step)
1969
-		echo '
2073
+	foreach ($incontext['steps'] as $num => $step) {
2074
+			echo '
1970 2075
 						<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2076
+	}
1971 2077
 
1972 2078
 	echo '
1973 2079
 					</ul>
@@ -1993,20 +2099,23 @@  discard block
 block discarded – undo
1993 2099
 		echo '
1994 2100
 							<div class="floatright">';
1995 2101
 
1996
-		if (!empty($incontext['continue']))
1997
-			echo '
2102
+		if (!empty($incontext['continue'])) {
2103
+					echo '
1998 2104
 								<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">';
1999
-		if (!empty($incontext['skip']))
2000
-			echo '
2105
+		}
2106
+		if (!empty($incontext['skip'])) {
2107
+					echo '
2001 2108
 								<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">';
2109
+		}
2002 2110
 		echo '
2003 2111
 							</div>';
2004 2112
 	}
2005 2113
 
2006 2114
 	// Show the closing form tag and other data only if not in the last step
2007
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
2008
-		echo '
2115
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2116
+			echo '
2009 2117
 						</form>';
2118
+	}
2010 2119
 
2011 2120
 	echo '
2012 2121
 					</div><!-- .panel -->
@@ -2039,13 +2148,15 @@  discard block
 block discarded – undo
2039 2148
 		</div>';
2040 2149
 
2041 2150
 	// Show the warnings, or not.
2042
-	if (template_warning_divs())
2043
-		echo '
2151
+	if (template_warning_divs()) {
2152
+			echo '
2044 2153
 		<h3>', $txt['install_all_lovely'], '</h3>';
2154
+	}
2045 2155
 
2046 2156
 	// Say we want the continue button!
2047
-	if (empty($incontext['error']))
2048
-		$incontext['continue'] = 1;
2157
+	if (empty($incontext['error'])) {
2158
+			$incontext['continue'] = 1;
2159
+	}
2049 2160
 
2050 2161
 	// For the latest version stuff.
2051 2162
 	echo '
@@ -2079,19 +2190,21 @@  discard block
 block discarded – undo
2079 2190
 	global $txt, $incontext;
2080 2191
 
2081 2192
 	// Errors are very serious..
2082
-	if (!empty($incontext['error']))
2083
-		echo '
2193
+	if (!empty($incontext['error'])) {
2194
+			echo '
2084 2195
 		<div class="errorbox">
2085 2196
 			<h3>', $txt['upgrade_critical_error'], '</h3>
2086 2197
 			', $incontext['error'], '
2087 2198
 		</div>';
2199
+	}
2088 2200
 	// A warning message?
2089
-	elseif (!empty($incontext['warning']))
2090
-		echo '
2201
+	elseif (!empty($incontext['warning'])) {
2202
+			echo '
2091 2203
 		<div class="errorbox">
2092 2204
 			<h3>', $txt['upgrade_warning'], '</h3>
2093 2205
 			', $incontext['warning'], '
2094 2206
 		</div>';
2207
+	}
2095 2208
 
2096 2209
 	return empty($incontext['error']) && empty($incontext['warning']);
2097 2210
 }
@@ -2107,26 +2220,29 @@  discard block
 block discarded – undo
2107 2220
 			<li>', $incontext['failed_files']), '</li>
2108 2221
 		</ul>';
2109 2222
 
2110
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2111
-		echo '
2223
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2224
+			echo '
2112 2225
 		<hr>
2113 2226
 		<p>', $txt['chmod_linux_info'], '</p>
2114 2227
 		<samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>';
2228
+	}
2115 2229
 
2116 2230
 	// This is serious!
2117
-	if (!template_warning_divs())
2118
-		return;
2231
+	if (!template_warning_divs()) {
2232
+			return;
2233
+	}
2119 2234
 
2120 2235
 	echo '
2121 2236
 		<hr>
2122 2237
 		<p>', $txt['ftp_setup_info'], '</p>';
2123 2238
 
2124
-	if (!empty($incontext['ftp_errors']))
2125
-		echo '
2239
+	if (!empty($incontext['ftp_errors'])) {
2240
+			echo '
2126 2241
 		<div class="error_message">
2127 2242
 			', $txt['error_ftp_no_connect'], '<br><br>
2128 2243
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2129 2244
 		</div>';
2245
+	}
2130 2246
 
2131 2247
 	echo '
2132 2248
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2195,16 +2311,16 @@  discard block
 block discarded – undo
2195 2311
 			<dd>
2196 2312
 				<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2197 2313
 
2198
-	foreach ($incontext['supported_databases'] as $key => $db)
2199
-			echo '
2314
+	foreach ($incontext['supported_databases'] as $key => $db) {
2315
+				echo '
2200 2316
 					<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2317
+	}
2201 2318
 
2202 2319
 	echo '
2203 2320
 				</select>
2204 2321
 				<div class="smalltext">', $txt['db_settings_type_info'], '</div>
2205 2322
 			</dd>';
2206
-	}
2207
-	else
2323
+	} else
2208 2324
 	{
2209 2325
 		echo '
2210 2326
 			<dd>
@@ -2372,9 +2488,10 @@  discard block
 block discarded – undo
2372 2488
 		<div class="red">', $txt['error_db_queries'], '</div>
2373 2489
 		<ul>';
2374 2490
 
2375
-		foreach ($incontext['failures'] as $line => $fail)
2376
-			echo '
2491
+		foreach ($incontext['failures'] as $line => $fail) {
2492
+					echo '
2377 2493
 			<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2494
+		}
2378 2495
 
2379 2496
 		echo '
2380 2497
 		</ul>';
@@ -2439,15 +2556,16 @@  discard block
 block discarded – undo
2439 2556
 			</dd>
2440 2557
 		</dl>';
2441 2558
 
2442
-	if ($incontext['require_db_confirm'])
2443
-		echo '
2559
+	if ($incontext['require_db_confirm']) {
2560
+			echo '
2444 2561
 		<h2>', $txt['user_settings_database'], '</h2>
2445 2562
 		<p>', $txt['user_settings_database_info'], '</p>
2446 2563
 
2447 2564
 		<div class="lefttext">
2448 2565
 			<input type="password" name="password3" size="30">
2449 2566
 		</div>';
2450
-}
2567
+	}
2568
+	}
2451 2569
 
2452 2570
 // Tell them it's done, and to delete.
2453 2571
 function template_delete_install()
@@ -2460,13 +2578,14 @@  discard block
 block discarded – undo
2460 2578
 	template_warning_divs();
2461 2579
 
2462 2580
 	// Install directory still writable?
2463
-	if ($incontext['dir_still_writable'])
2464
-		echo '
2581
+	if ($incontext['dir_still_writable']) {
2582
+			echo '
2465 2583
 		<p><em>', $txt['still_writable'], '</em></p>';
2584
+	}
2466 2585
 
2467 2586
 	// Don't show the box if it's like 99% sure it won't work :P.
2468
-	if ($incontext['probably_delete_install'])
2469
-		echo '
2587
+	if ($incontext['probably_delete_install']) {
2588
+			echo '
2470 2589
 		<label>
2471 2590
 			<input type="checkbox" id="delete_self" onclick="doTheDelete();">
2472 2591
 			<strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong>
@@ -2482,6 +2601,7 @@  discard block
 block discarded – undo
2482 2601
 				theCheck.disabled = true;
2483 2602
 			}
2484 2603
 		</script>';
2604
+	}
2485 2605
 
2486 2606
 	echo '
2487 2607
 		<p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p>
Please login to merge, or discard this patch.