Completed
Push — release-2.1 ( ba902c...c8d41f )
by
unknown
08:46
created
other/install.php 1 patch
Braces   +441 added lines, -328 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.
154 160
 	error_reporting(E_ALL);
@@ -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
 
@@ -237,10 +246,11 @@  discard block
 block discarded – undo
237 246
 	{
238 247
 		// Get PHP's default timezone, if set
239 248
 		$ini_tz = ini_get('date.timezone');
240
-		if (!empty($ini_tz))
241
-			$timezone_id = $ini_tz;
242
-		else
243
-			$timezone_id = '';
249
+		if (!empty($ini_tz)) {
250
+					$timezone_id = $ini_tz;
251
+		} else {
252
+					$timezone_id = '';
253
+		}
244 254
 
245 255
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
246 256
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -270,8 +280,9 @@  discard block
 block discarded – undo
270 280
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
271 281
 		while ($entry = $dir->read())
272 282
 		{
273
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
274
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
283
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
284
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
285
+			}
275 286
 		}
276 287
 		$dir->close();
277 288
 	}
@@ -306,10 +317,11 @@  discard block
 block discarded – undo
306 317
 	}
307 318
 
308 319
 	// Override the language file?
309
-	if (isset($_GET['lang_file']))
310
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
311
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
312
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
320
+	if (isset($_GET['lang_file'])) {
321
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
322
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
323
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
324
+	}
313 325
 
314 326
 	// Make sure it exists, if it doesn't reset it.
315 327
 	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']))
@@ -318,8 +330,9 @@  discard block
 block discarded – undo
318 330
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
319 331
 
320 332
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
321
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
322
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
333
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
334
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
335
+		}
323 336
 	}
324 337
 
325 338
 	// And now include the actual language file itself.
@@ -332,15 +345,18 @@  discard block
 block discarded – undo
332 345
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings;
333 346
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist;
334 347
 
335
-	if (empty($sourcedir))
336
-		$sourcedir = dirname(__FILE__) . '/Sources';
348
+	if (empty($sourcedir)) {
349
+			$sourcedir = dirname(__FILE__) . '/Sources';
350
+	}
337 351
 
338 352
 	// Need this to check whether we need the database password.
339 353
 	require(dirname(__FILE__) . '/Settings.php');
340
-	if (!defined('SMF'))
341
-		define('SMF', 1);
342
-	if (empty($smcFunc))
343
-		$smcFunc = array();
354
+	if (!defined('SMF')) {
355
+			define('SMF', 1);
356
+	}
357
+	if (empty($smcFunc)) {
358
+			$smcFunc = array();
359
+	}
344 360
 
345 361
 	$modSettings['disableQueryCheck'] = true;
346 362
 
@@ -348,8 +364,9 @@  discard block
 block discarded – undo
348 364
 	if (!$db_connection)
349 365
 	{
350 366
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
351
-		if (version_compare(PHP_VERSION, '5', '<'))
352
-			require_once($sourcedir . '/Subs-Compat.php');
367
+		if (version_compare(PHP_VERSION, '5', '<')) {
368
+					require_once($sourcedir . '/Subs-Compat.php');
369
+		}
353 370
 
354 371
 		$db_options = array('persist' => $db_persist);
355 372
 		$port = '';
@@ -360,19 +377,20 @@  discard block
 block discarded – undo
360 377
 			if ($db_type == 'mysql')
361 378
 			{
362 379
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
363
-			}
364
-			elseif ($db_type == 'postgresql')
380
+			} elseif ($db_type == 'postgresql')
365 381
 			{
366 382
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
367 383
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
368 384
 			}
369 385
 		}
370 386
 
371
-		if (!empty($port))
372
-			$db_options['port'] = $port;
387
+		if (!empty($port)) {
388
+					$db_options['port'] = $port;
389
+		}
373 390
 
374
-		if (!$db_connection)
375
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
391
+		if (!$db_connection) {
392
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
393
+		}
376 394
 	}
377 395
 }
378 396
 
@@ -400,8 +418,9 @@  discard block
 block discarded – undo
400 418
 		// @todo REMOVE THIS!!
401 419
 		else
402 420
 		{
403
-			if (function_exists('doStep' . $_GET['step']))
404
-				call_user_func('doStep' . $_GET['step']);
421
+			if (function_exists('doStep' . $_GET['step'])) {
422
+							call_user_func('doStep' . $_GET['step']);
423
+			}
405 424
 		}
406 425
 		// Show the footer.
407 426
 		template_install_below();
@@ -419,8 +438,9 @@  discard block
 block discarded – undo
419 438
 	$incontext['sub_template'] = 'welcome_message';
420 439
 
421 440
 	// Done the submission?
422
-	if (isset($_POST['contbutt']))
423
-		return true;
441
+	if (isset($_POST['contbutt'])) {
442
+			return true;
443
+	}
424 444
 
425 445
 	// See if we think they have already installed it?
426 446
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -428,14 +448,17 @@  discard block
 block discarded – undo
428 448
 		$probably_installed = 0;
429 449
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
430 450
 		{
431
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
432
-				$probably_installed++;
433
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
434
-				$probably_installed++;
451
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
452
+							$probably_installed++;
453
+			}
454
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
455
+							$probably_installed++;
456
+			}
435 457
 		}
436 458
 
437
-		if ($probably_installed == 2)
438
-			$incontext['warning'] = $txt['error_already_installed'];
459
+		if ($probably_installed == 2) {
460
+					$incontext['warning'] = $txt['error_already_installed'];
461
+		}
439 462
 	}
440 463
 
441 464
 	// Is some database support even compiled in?
@@ -450,41 +473,49 @@  discard block
 block discarded – undo
450 473
 				$databases[$key]['supported'] = false;
451 474
 				$notFoundSQLFile = true;
452 475
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
476
+			} else {
477
+							$incontext['supported_databases'][] = $db;
453 478
 			}
454
-			else
455
-				$incontext['supported_databases'][] = $db;
456 479
 		}
457 480
 	}
458 481
 
459 482
 	// Check the PHP version.
460
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
461
-		$error = 'error_php_too_low';
483
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
484
+			$error = 'error_php_too_low';
485
+	}
462 486
 	// Make sure we have a supported database
463
-	elseif (empty($incontext['supported_databases']))
464
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
487
+	elseif (empty($incontext['supported_databases'])) {
488
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
489
+	}
465 490
 	// How about session support?  Some crazy sysadmin remove it?
466
-	elseif (!function_exists('session_start'))
467
-		$error = 'error_session_missing';
491
+	elseif (!function_exists('session_start')) {
492
+			$error = 'error_session_missing';
493
+	}
468 494
 	// Make sure they uploaded all the files.
469
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
470
-		$error = 'error_missing_files';
495
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
496
+			$error = 'error_missing_files';
497
+	}
471 498
 	// Very simple check on the session.save_path for Windows.
472 499
 	// @todo Move this down later if they don't use database-driven sessions?
473
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
474
-		$error = 'error_session_save_path';
500
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
501
+			$error = 'error_session_save_path';
502
+	}
475 503
 
476 504
 	// Since each of the three messages would look the same, anyway...
477
-	if (isset($error))
478
-		$incontext['error'] = $txt[$error];
505
+	if (isset($error)) {
506
+			$incontext['error'] = $txt[$error];
507
+	}
479 508
 
480 509
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
481
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
482
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
510
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
511
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
512
+	}
483 513
 
484 514
 	// Check for https stream support.
485 515
 	$supported_streams = stream_get_wrappers();
486
-	if (!in_array('https', $supported_streams))
487
-		$incontext['warning'] = $txt['install_no_https'];
516
+	if (!in_array('https', $supported_streams)) {
517
+			$incontext['warning'] = $txt['install_no_https'];
518
+	}
488 519
 
489 520
 	return false;
490 521
 }
@@ -510,12 +541,14 @@  discard block
 block discarded – undo
510 541
 		'db_last_error.php',
511 542
 	);
512 543
 
513
-	foreach ($incontext['detected_languages'] as $lang => $temp)
514
-		$extra_files[] = 'Themes/default/languages/' . $lang;
544
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
545
+			$extra_files[] = 'Themes/default/languages/' . $lang;
546
+	}
515 547
 
516 548
 	// With mod_security installed, we could attempt to fix it with .htaccess.
517
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
518
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
549
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
550
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
551
+	}
519 552
 
520 553
 	$failed_files = array();
521 554
 
@@ -531,12 +564,14 @@  discard block
 block discarded – undo
531 564
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
532 565
 
533 566
 				// Well, 755 hopefully worked... if not, try 777.
534
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
535
-					$failed_files[] = $file;
567
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
568
+									$failed_files[] = $file;
569
+				}
536 570
 			}
537 571
 		}
538
-		foreach ($extra_files as $file)
539
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
572
+		foreach ($extra_files as $file) {
573
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
574
+		}
540 575
 	}
541 576
 	// Windows is trickier.  Let's try opening for r+...
542 577
 	else
@@ -546,30 +581,35 @@  discard block
 block discarded – undo
546 581
 		foreach ($writable_files as $file)
547 582
 		{
548 583
 			// Folders can't be opened for write... but the index.php in them can ;)
549
-			if (is_dir(dirname(__FILE__) . '/' . $file))
550
-				$file .= '/index.php';
584
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
585
+							$file .= '/index.php';
586
+			}
551 587
 
552 588
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
553 589
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
554 590
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
555 591
 
556 592
 			// Hmm, okay, try just for write in that case...
557
-			if (!is_resource($fp))
558
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
593
+			if (!is_resource($fp)) {
594
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
595
+			}
559 596
 
560
-			if (!is_resource($fp))
561
-				$failed_files[] = $file;
597
+			if (!is_resource($fp)) {
598
+							$failed_files[] = $file;
599
+			}
562 600
 
563 601
 			@fclose($fp);
564 602
 		}
565
-		foreach ($extra_files as $file)
566
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
603
+		foreach ($extra_files as $file) {
604
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
605
+		}
567 606
 	}
568 607
 
569 608
 	$failure = count($failed_files) >= 1;
570 609
 
571
-	if (!isset($_SERVER))
572
-		return !$failure;
610
+	if (!isset($_SERVER)) {
611
+			return !$failure;
612
+	}
573 613
 
574 614
 	// Put the list into context.
575 615
 	$incontext['failed_files'] = $failed_files;
@@ -617,19 +657,23 @@  discard block
 block discarded – undo
617 657
 
618 658
 		if (!isset($ftp) || $ftp->error !== false)
619 659
 		{
620
-			if (!isset($ftp))
621
-				$ftp = new ftp_connection(null);
660
+			if (!isset($ftp)) {
661
+							$ftp = new ftp_connection(null);
662
+			}
622 663
 			// Save the error so we can mess with listing...
623
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
624
-				$incontext['ftp_errors'][] = $ftp->last_message;
664
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
665
+							$incontext['ftp_errors'][] = $ftp->last_message;
666
+			}
625 667
 
626 668
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
627 669
 
628
-			if (empty($_POST['ftp_path']) && $found_path)
629
-				$_POST['ftp_path'] = $detect_path;
670
+			if (empty($_POST['ftp_path']) && $found_path) {
671
+							$_POST['ftp_path'] = $detect_path;
672
+			}
630 673
 
631
-			if (!isset($_POST['ftp_username']))
632
-				$_POST['ftp_username'] = $username;
674
+			if (!isset($_POST['ftp_username'])) {
675
+							$_POST['ftp_username'] = $username;
676
+			}
633 677
 
634 678
 			// Set the username etc, into context.
635 679
 			$incontext['ftp'] = array(
@@ -641,8 +685,7 @@  discard block
 block discarded – undo
641 685
 			);
642 686
 
643 687
 			return false;
644
-		}
645
-		else
688
+		} else
646 689
 		{
647 690
 			$_SESSION['installer_temp_ftp'] = array(
648 691
 				'server' => $_POST['ftp_server'],
@@ -656,10 +699,12 @@  discard block
 block discarded – undo
656 699
 
657 700
 			foreach ($failed_files as $file)
658 701
 			{
659
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
660
-					$ftp->chmod($file, 0755);
661
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
662
-					$ftp->chmod($file, 0777);
702
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
703
+									$ftp->chmod($file, 0755);
704
+				}
705
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
706
+									$ftp->chmod($file, 0777);
707
+				}
663 708
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
664 709
 				{
665 710
 					$failed_files_updated[] = $file;
@@ -715,15 +760,17 @@  discard block
 block discarded – undo
715 760
 
716 761
 			if (!$foundOne)
717 762
 			{
718
-				if (isset($db['default_host']))
719
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
763
+				if (isset($db['default_host'])) {
764
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
765
+				}
720 766
 				if (isset($db['default_user']))
721 767
 				{
722 768
 					$incontext['db']['user'] = ini_get($db['default_user']);
723 769
 					$incontext['db']['name'] = ini_get($db['default_user']);
724 770
 				}
725
-				if (isset($db['default_password']))
726
-					$incontext['db']['pass'] = ini_get($db['default_password']);
771
+				if (isset($db['default_password'])) {
772
+									$incontext['db']['pass'] = ini_get($db['default_password']);
773
+				}
727 774
 
728 775
 				// For simplicity and less confusion, leave the port blank by default
729 776
 				$incontext['db']['port'] = '';
@@ -742,10 +789,10 @@  discard block
 block discarded – undo
742 789
 		$incontext['db']['server'] = $_POST['db_server'];
743 790
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
744 791
 
745
-		if (!empty($_POST['db_port']))
746
-			$incontext['db']['port'] = $_POST['db_port'];
747
-	}
748
-	else
792
+		if (!empty($_POST['db_port'])) {
793
+					$incontext['db']['port'] = $_POST['db_port'];
794
+		}
795
+	} else
749 796
 	{
750 797
 		$incontext['db']['prefix'] = 'smf_';
751 798
 	}
@@ -781,10 +828,11 @@  discard block
 block discarded – undo
781 828
 		if (!empty($_POST['db_port']))
782 829
 		{
783 830
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
784
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
785
-				$vars['db_port'] = (int) $_POST['db_port'];
786
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
787
-				$vars['db_port'] = (int) $_POST['db_port'];
831
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
832
+							$vars['db_port'] = (int) $_POST['db_port'];
833
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
834
+							$vars['db_port'] = (int) $_POST['db_port'];
835
+			}
788 836
 		}
789 837
 
790 838
 		// God I hope it saved!
@@ -797,8 +845,9 @@  discard block
 block discarded – undo
797 845
 		// Make sure it works.
798 846
 		require(dirname(__FILE__) . '/Settings.php');
799 847
 
800
-		if (empty($sourcedir))
801
-			$sourcedir = dirname(__FILE__) . '/Sources';
848
+		if (empty($sourcedir)) {
849
+					$sourcedir = dirname(__FILE__) . '/Sources';
850
+		}
802 851
 
803 852
 		// Better find the database file!
804 853
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -808,18 +857,21 @@  discard block
 block discarded – undo
808 857
 		}
809 858
 
810 859
 		// Now include it for database functions!
811
-		if (!defined('SMF'))
812
-			define('SMF', 1);
860
+		if (!defined('SMF')) {
861
+					define('SMF', 1);
862
+		}
813 863
 
814 864
 		$modSettings['disableQueryCheck'] = true;
815
-		if (empty($smcFunc))
816
-			$smcFunc = array();
865
+		if (empty($smcFunc)) {
866
+					$smcFunc = array();
867
+		}
817 868
 
818 869
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
819 870
 
820 871
 		// What - running PHP4? The shame!
821
-		if (version_compare(PHP_VERSION, '5', '<'))
822
-			require_once($sourcedir . '/Subs-Compat.php');
872
+		if (version_compare(PHP_VERSION, '5', '<')) {
873
+					require_once($sourcedir . '/Subs-Compat.php');
874
+		}
823 875
 
824 876
 		// Attempt a connection.
825 877
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -907,12 +959,14 @@  discard block
 block discarded – undo
907 959
 	$incontext['page_title'] = $txt['install_settings'];
908 960
 
909 961
 	// Let's see if we got the database type correct.
910
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
911
-		$db_type = $_POST['db_type'];
962
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
963
+			$db_type = $_POST['db_type'];
964
+	}
912 965
 
913 966
 	// Else we'd better be able to get the connection.
914
-	else
915
-		load_database();
967
+	else {
968
+			load_database();
969
+	}
916 970
 
917 971
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
918 972
 
@@ -932,12 +986,14 @@  discard block
 block discarded – undo
932 986
 	// Submitting?
933 987
 	if (isset($_POST['boardurl']))
934 988
 	{
935
-		if (substr($_POST['boardurl'], -10) == '/index.php')
936
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
937
-		elseif (substr($_POST['boardurl'], -1) == '/')
938
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
939
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
940
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
989
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
990
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
991
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
992
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
993
+		}
994
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
995
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
996
+		}
941 997
 
942 998
 		// Save these variables.
943 999
 		$vars = array(
@@ -976,10 +1032,10 @@  discard block
 block discarded – undo
976 1032
 			{
977 1033
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
978 1034
 				return false;
979
-			}
980
-			else
981
-				// Set the character set here.
1035
+			} else {
1036
+							// Set the character set here.
982 1037
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1038
+			}
983 1039
 		}
984 1040
 
985 1041
 		// Good, skip on.
@@ -999,8 +1055,9 @@  discard block
 block discarded – undo
999 1055
 	$incontext['continue'] = 1;
1000 1056
 
1001 1057
 	// Already done?
1002
-	if (isset($_POST['pop_done']))
1003
-		return true;
1058
+	if (isset($_POST['pop_done'])) {
1059
+			return true;
1060
+	}
1004 1061
 
1005 1062
 	// Reload settings.
1006 1063
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1018,8 +1075,9 @@  discard block
 block discarded – undo
1018 1075
 	$modSettings = array();
1019 1076
 	if ($result !== false)
1020 1077
 	{
1021
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1022
-			$modSettings[$row['variable']] = $row['value'];
1078
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1079
+					$modSettings[$row['variable']] = $row['value'];
1080
+		}
1023 1081
 		$smcFunc['db_free_result']($result);
1024 1082
 
1025 1083
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1032,20 +1090,22 @@  discard block
 block discarded – undo
1032 1090
 	$modSettings['disableQueryCheck'] = true;
1033 1091
 
1034 1092
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1035
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1036
-		$smcFunc['db_query']('', '
1093
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1094
+			$smcFunc['db_query']('', '
1037 1095
 			SET NAMES {string:utf8}',
1038 1096
 			array(
1039 1097
 				'db_error_skip' => true,
1040 1098
 				'utf8' => 'utf8',
1041 1099
 			)
1042 1100
 		);
1101
+	}
1043 1102
 
1044 1103
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1045
-	if (substr(__DIR__, -1) == '\\')
1046
-		$attachdir = __DIR__ . 'attachments';
1047
-	else
1048
-		$attachdir = __DIR__ . '/attachments';
1104
+	if (substr(__DIR__, -1) == '\\') {
1105
+			$attachdir = __DIR__ . 'attachments';
1106
+	} else {
1107
+			$attachdir = __DIR__ . '/attachments';
1108
+	}
1049 1109
 
1050 1110
 	$replaces = array(
1051 1111
 		'{$db_prefix}' => $db_prefix,
@@ -1062,8 +1122,9 @@  discard block
 block discarded – undo
1062 1122
 
1063 1123
 	foreach ($txt as $key => $value)
1064 1124
 	{
1065
-		if (substr($key, 0, 8) == 'default_')
1066
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1125
+		if (substr($key, 0, 8) == 'default_') {
1126
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1127
+		}
1067 1128
 	}
1068 1129
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1069 1130
 
@@ -1078,8 +1139,9 @@  discard block
 block discarded – undo
1078 1139
 
1079 1140
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1080 1141
 		{
1081
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1082
-				$engines[] = $row['Engine'];
1142
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1143
+							$engines[] = $row['Engine'];
1144
+			}
1083 1145
 		}
1084 1146
 
1085 1147
 		// Done with this now
@@ -1103,8 +1165,7 @@  discard block
 block discarded – undo
1103 1165
 			$replaces['START TRANSACTION;'] = '';
1104 1166
 			$replaces['COMMIT;'] = '';
1105 1167
 		}
1106
-	}
1107
-	else
1168
+	} else
1108 1169
 	{
1109 1170
 		$has_innodb = false;
1110 1171
 	}
@@ -1126,21 +1187,24 @@  discard block
 block discarded – undo
1126 1187
 	foreach ($sql_lines as $count => $line)
1127 1188
 	{
1128 1189
 		// No comments allowed!
1129
-		if (substr(trim($line), 0, 1) != '#')
1130
-			$current_statement .= "\n" . rtrim($line);
1190
+		if (substr(trim($line), 0, 1) != '#') {
1191
+					$current_statement .= "\n" . rtrim($line);
1192
+		}
1131 1193
 
1132 1194
 		// Is this the end of the query string?
1133
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1134
-			continue;
1195
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1196
+					continue;
1197
+		}
1135 1198
 
1136 1199
 		// Does this table already exist?  If so, don't insert more data into it!
1137 1200
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1138 1201
 		{
1139 1202
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1140
-			if (!empty($matches[0]))
1141
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1142
-			else
1143
-				$incontext['sql_results']['insert_dups']++;
1203
+			if (!empty($matches[0])) {
1204
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1205
+			} else {
1206
+							$incontext['sql_results']['insert_dups']++;
1207
+			}
1144 1208
 
1145 1209
 			$current_statement = '';
1146 1210
 			continue;
@@ -1149,8 +1213,9 @@  discard block
 block discarded – undo
1149 1213
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1150 1214
 		{
1151 1215
 			// Use the appropriate function based on the DB type
1152
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1153
-				$db_errorno = $db_type . '_errno';
1216
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1217
+							$db_errorno = $db_type . '_errno';
1218
+			}
1154 1219
 
1155 1220
 			// Error 1050: Table already exists!
1156 1221
 			// @todo Needs to be made better!
@@ -1165,18 +1230,18 @@  discard block
 block discarded – undo
1165 1230
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1166 1231
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1167 1232
 			}
1168
-		}
1169
-		else
1233
+		} else
1170 1234
 		{
1171
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1172
-				$incontext['sql_results']['tables']++;
1173
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1235
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1236
+							$incontext['sql_results']['tables']++;
1237
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1174 1238
 			{
1175 1239
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1176
-				if (!empty($matches[0]))
1177
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1178
-				else
1179
-					$incontext['sql_results']['inserts']++;
1240
+				if (!empty($matches[0])) {
1241
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1242
+				} else {
1243
+									$incontext['sql_results']['inserts']++;
1244
+				}
1180 1245
 			}
1181 1246
 		}
1182 1247
 
@@ -1189,15 +1254,17 @@  discard block
 block discarded – undo
1189 1254
 	// Sort out the context for the SQL.
1190 1255
 	foreach ($incontext['sql_results'] as $key => $number)
1191 1256
 	{
1192
-		if ($number == 0)
1193
-			unset($incontext['sql_results'][$key]);
1194
-		else
1195
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1257
+		if ($number == 0) {
1258
+					unset($incontext['sql_results'][$key]);
1259
+		} else {
1260
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1261
+		}
1196 1262
 	}
1197 1263
 
1198 1264
 	// Make sure UTF will be used globally.
1199
-	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'])))
1200
-		$newSettings[] = array('global_character_set', 'UTF-8');
1265
+	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']))) {
1266
+			$newSettings[] = array('global_character_set', 'UTF-8');
1267
+	}
1201 1268
 
1202 1269
 	// Maybe we can auto-detect better cookie settings?
1203 1270
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1208,16 +1275,20 @@  discard block
 block discarded – undo
1208 1275
 		$globalCookies = false;
1209 1276
 
1210 1277
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1211
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1212
-			$globalCookies = true;
1278
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1279
+					$globalCookies = true;
1280
+		}
1213 1281
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1214
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1215
-			$localCookies = true;
1282
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1283
+					$localCookies = true;
1284
+		}
1216 1285
 
1217
-		if ($globalCookies)
1218
-			$newSettings[] = array('globalCookies', '1');
1219
-		if ($localCookies)
1220
-			$newSettings[] = array('localCookies', '1');
1286
+		if ($globalCookies) {
1287
+					$newSettings[] = array('globalCookies', '1');
1288
+		}
1289
+		if ($localCookies) {
1290
+					$newSettings[] = array('localCookies', '1');
1291
+		}
1221 1292
 	}
1222 1293
 
1223 1294
 	// Are we allowing stat collection?
@@ -1235,16 +1306,17 @@  discard block
 block discarded – undo
1235 1306
 			fwrite($fp, $out);
1236 1307
 
1237 1308
 			$return_data = '';
1238
-			while (!feof($fp))
1239
-				$return_data .= fgets($fp, 128);
1309
+			while (!feof($fp)) {
1310
+							$return_data .= fgets($fp, 128);
1311
+			}
1240 1312
 
1241 1313
 			fclose($fp);
1242 1314
 
1243 1315
 			// Get the unique site ID.
1244 1316
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1245 1317
 
1246
-			if (!empty($ID[1]))
1247
-				$smcFunc['db_insert']('replace',
1318
+			if (!empty($ID[1])) {
1319
+							$smcFunc['db_insert']('replace',
1248 1320
 					$db_prefix . 'settings',
1249 1321
 					array('variable' => 'string', 'value' => 'string'),
1250 1322
 					array(
@@ -1253,11 +1325,12 @@  discard block
 block discarded – undo
1253 1325
 					),
1254 1326
 					array('variable')
1255 1327
 				);
1328
+			}
1256 1329
 		}
1257 1330
 	}
1258 1331
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1259
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1260
-		$smcFunc['db_query']('', '
1332
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1333
+			$smcFunc['db_query']('', '
1261 1334
 			DELETE FROM {db_prefix}settings
1262 1335
 			WHERE variable = {string:enable_sm_stats}',
1263 1336
 			array(
@@ -1265,20 +1338,23 @@  discard block
 block discarded – undo
1265 1338
 				'db_error_skip' => true,
1266 1339
 			)
1267 1340
 		);
1341
+	}
1268 1342
 
1269 1343
 	// Are we enabling SSL?
1270
-	if (!empty($_POST['force_ssl']))
1271
-		$newSettings[] = array('force_ssl', 2);
1344
+	if (!empty($_POST['force_ssl'])) {
1345
+			$newSettings[] = array('force_ssl', 2);
1346
+	}
1272 1347
 
1273 1348
 	// Setting a timezone is required.
1274 1349
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1275 1350
 	{
1276 1351
 		// Get PHP's default timezone, if set
1277 1352
 		$ini_tz = ini_get('date.timezone');
1278
-		if (!empty($ini_tz))
1279
-			$timezone_id = $ini_tz;
1280
-		else
1281
-			$timezone_id = '';
1353
+		if (!empty($ini_tz)) {
1354
+					$timezone_id = $ini_tz;
1355
+		} else {
1356
+					$timezone_id = '';
1357
+		}
1282 1358
 
1283 1359
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1284 1360
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1287,8 +1363,9 @@  discard block
 block discarded – undo
1287 1363
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1288 1364
 		}
1289 1365
 
1290
-		if (date_default_timezone_set($timezone_id))
1291
-			$newSettings[] = array('default_timezone', $timezone_id);
1366
+		if (date_default_timezone_set($timezone_id)) {
1367
+					$newSettings[] = array('default_timezone', $timezone_id);
1368
+		}
1292 1369
 	}
1293 1370
 
1294 1371
 	if (!empty($newSettings))
@@ -1319,16 +1396,18 @@  discard block
 block discarded – undo
1319 1396
 	}
1320 1397
 
1321 1398
 	// MySQL specific stuff
1322
-	if (substr($db_type, 0, 5) != 'mysql')
1323
-		return false;
1399
+	if (substr($db_type, 0, 5) != 'mysql') {
1400
+			return false;
1401
+	}
1324 1402
 
1325 1403
 	// Find database user privileges.
1326 1404
 	$privs = array();
1327 1405
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1328 1406
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1329 1407
 	{
1330
-		if ($row['Privilege'] == 'Alter')
1331
-			$privs[] = $row['Privilege'];
1408
+		if ($row['Privilege'] == 'Alter') {
1409
+					$privs[] = $row['Privilege'];
1410
+		}
1332 1411
 	}
1333 1412
 	$smcFunc['db_free_result']($get_privs);
1334 1413
 
@@ -1358,8 +1437,9 @@  discard block
 block discarded – undo
1358 1437
 	$incontext['continue'] = 1;
1359 1438
 
1360 1439
 	// Skipping?
1361
-	if (!empty($_POST['skip']))
1362
-		return true;
1440
+	if (!empty($_POST['skip'])) {
1441
+			return true;
1442
+	}
1363 1443
 
1364 1444
 	// Need this to check whether we need the database password.
1365 1445
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1376,18 +1456,22 @@  discard block
 block discarded – undo
1376 1456
 	// We need this to properly hash the password for Admin
1377 1457
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1378 1458
 			global $sourcedir;
1379
-			if (function_exists('mb_strtolower'))
1380
-				return mb_strtolower($string, 'UTF-8');
1459
+			if (function_exists('mb_strtolower')) {
1460
+							return mb_strtolower($string, 'UTF-8');
1461
+			}
1381 1462
 			require_once($sourcedir . '/Subs-Charset.php');
1382 1463
 			return utf8_strtolower($string);
1383 1464
 		};
1384 1465
 
1385
-	if (!isset($_POST['username']))
1386
-		$_POST['username'] = '';
1387
-	if (!isset($_POST['email']))
1388
-		$_POST['email'] = '';
1389
-	if (!isset($_POST['server_email']))
1390
-		$_POST['server_email'] = '';
1466
+	if (!isset($_POST['username'])) {
1467
+			$_POST['username'] = '';
1468
+	}
1469
+	if (!isset($_POST['email'])) {
1470
+			$_POST['email'] = '';
1471
+	}
1472
+	if (!isset($_POST['server_email'])) {
1473
+			$_POST['server_email'] = '';
1474
+	}
1391 1475
 
1392 1476
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1393 1477
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1406,8 +1490,9 @@  discard block
 block discarded – undo
1406 1490
 			'admin_group' => 1,
1407 1491
 		)
1408 1492
 	);
1409
-	if ($smcFunc['db_num_rows']($request) != 0)
1410
-		$incontext['skip'] = 1;
1493
+	if ($smcFunc['db_num_rows']($request) != 0) {
1494
+			$incontext['skip'] = 1;
1495
+	}
1411 1496
 	$smcFunc['db_free_result']($request);
1412 1497
 
1413 1498
 	// Trying to create an account?
@@ -1438,8 +1523,9 @@  discard block
 block discarded – undo
1438 1523
 		}
1439 1524
 
1440 1525
 		// Update the webmaster's email?
1441
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1442
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1526
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1527
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1528
+		}
1443 1529
 
1444 1530
 		// Work out whether we're going to have dodgy characters and remove them.
1445 1531
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1462,32 +1548,27 @@  discard block
 block discarded – undo
1462 1548
 			$smcFunc['db_free_result']($result);
1463 1549
 
1464 1550
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1465
-		}
1466
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1551
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1467 1552
 		{
1468 1553
 			// Try the previous step again.
1469 1554
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1470 1555
 			return false;
1471
-		}
1472
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1556
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1473 1557
 		{
1474 1558
 			// Try the previous step again.
1475 1559
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1476 1560
 			return false;
1477
-		}
1478
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1561
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1479 1562
 		{
1480 1563
 			// One step back, this time fill out a proper admin email address.
1481 1564
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1482 1565
 			return false;
1483
-		}
1484
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1566
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1485 1567
 		{
1486 1568
 			// One step back, this time fill out a proper admin email address.
1487 1569
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1488 1570
 			return false;
1489
-		}
1490
-		elseif ($_POST['username'] != '')
1571
+		} elseif ($_POST['username'] != '')
1491 1572
 		{
1492 1573
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1493 1574
 
@@ -1555,17 +1636,19 @@  discard block
 block discarded – undo
1555 1636
 	reloadSettings();
1556 1637
 
1557 1638
 	// Bring a warning over.
1558
-	if (!empty($incontext['account_existed']))
1559
-		$incontext['warning'] = $incontext['account_existed'];
1639
+	if (!empty($incontext['account_existed'])) {
1640
+			$incontext['warning'] = $incontext['account_existed'];
1641
+	}
1560 1642
 
1561
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1562
-		$smcFunc['db_query']('', '
1643
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1644
+			$smcFunc['db_query']('', '
1563 1645
 			SET NAMES {string:db_character_set}',
1564 1646
 			array(
1565 1647
 				'db_character_set' => $db_character_set,
1566 1648
 				'db_error_skip' => true,
1567 1649
 			)
1568 1650
 		);
1651
+	}
1569 1652
 
1570 1653
 	// As track stats is by default enabled let's add some activity.
1571 1654
 	$smcFunc['db_insert']('ignore',
@@ -1586,14 +1669,16 @@  discard block
 block discarded – undo
1586 1669
 	// Only proceed if we can load the data.
1587 1670
 	if ($request)
1588 1671
 	{
1589
-		while ($row = $smcFunc['db_fetch_row']($request))
1590
-			$modSettings[$row[0]] = $row[1];
1672
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1673
+					$modSettings[$row[0]] = $row[1];
1674
+		}
1591 1675
 		$smcFunc['db_free_result']($request);
1592 1676
 	}
1593 1677
 
1594 1678
 	// Automatically log them in ;)
1595
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1596
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1679
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1680
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1681
+	}
1597 1682
 
1598 1683
 	$result = $smcFunc['db_query']('', '
1599 1684
 		SELECT value
@@ -1604,13 +1689,14 @@  discard block
 block discarded – undo
1604 1689
 			'db_error_skip' => true,
1605 1690
 		)
1606 1691
 	);
1607
-	if ($smcFunc['db_num_rows']($result) != 0)
1608
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1692
+	if ($smcFunc['db_num_rows']($result) != 0) {
1693
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1694
+	}
1609 1695
 	$smcFunc['db_free_result']($result);
1610 1696
 
1611
-	if (empty($db_sessions))
1612
-		$_SESSION['admin_time'] = time();
1613
-	else
1697
+	if (empty($db_sessions)) {
1698
+			$_SESSION['admin_time'] = time();
1699
+	} else
1614 1700
 	{
1615 1701
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1616 1702
 
@@ -1634,8 +1720,9 @@  discard block
 block discarded – undo
1634 1720
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1635 1721
 		function($string){
1636 1722
 			global $sourcedir;
1637
-			if (function_exists('mb_strtolower'))
1638
-				return mb_strtolower($string, 'UTF-8');
1723
+			if (function_exists('mb_strtolower')) {
1724
+							return mb_strtolower($string, 'UTF-8');
1725
+			}
1639 1726
 			require_once($sourcedir . '/Subs-Charset.php');
1640 1727
 			return utf8_strtolower($string);
1641 1728
 		};
@@ -1651,8 +1738,9 @@  discard block
 block discarded – undo
1651 1738
 		)
1652 1739
 	);
1653 1740
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1654
-	if ($smcFunc['db_num_rows']($request) > 0)
1655
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1741
+	if ($smcFunc['db_num_rows']($request) > 0) {
1742
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1743
+	}
1656 1744
 	$smcFunc['db_free_result']($request);
1657 1745
 
1658 1746
 	// Now is the perfect time to fetch the SM files.
@@ -1671,8 +1759,9 @@  discard block
 block discarded – undo
1671 1759
 
1672 1760
 	// Check if we need some stupid MySQL fix.
1673 1761
 	$server_version = $smcFunc['db_server_info']();
1674
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1675
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1762
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1763
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1764
+	}
1676 1765
 
1677 1766
 	// Some final context for the template.
1678 1767
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1692,8 +1781,9 @@  discard block
 block discarded – undo
1692 1781
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1693 1782
 
1694 1783
 	// @todo Do we just want to read the file in clean, and split it this way always?
1695
-	if (count($settingsArray) == 1)
1696
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1784
+	if (count($settingsArray) == 1) {
1785
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1786
+	}
1697 1787
 
1698 1788
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1699 1789
 	{
@@ -1708,19 +1798,22 @@  discard block
 block discarded – undo
1708 1798
 			continue;
1709 1799
 		}
1710 1800
 
1711
-		if (trim($settingsArray[$i]) == '?' . '>')
1712
-			$settingsArray[$i] = '';
1801
+		if (trim($settingsArray[$i]) == '?' . '>') {
1802
+					$settingsArray[$i] = '';
1803
+		}
1713 1804
 
1714 1805
 		// Don't trim or bother with it if it's not a variable.
1715
-		if (substr($settingsArray[$i], 0, 1) != '$')
1716
-			continue;
1806
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1807
+					continue;
1808
+		}
1717 1809
 
1718 1810
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1719 1811
 
1720
-		foreach ($vars as $var => $val)
1721
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1812
+		foreach ($vars as $var => $val) {
1813
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1722 1814
 			{
1723 1815
 				$comment = strstr($settingsArray[$i], '#');
1816
+		}
1724 1817
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1725 1818
 				unset($vars[$var]);
1726 1819
 			}
@@ -1730,36 +1823,41 @@  discard block
 block discarded – undo
1730 1823
 	if (!empty($vars))
1731 1824
 	{
1732 1825
 		$settingsArray[$i++] = '';
1733
-		foreach ($vars as $var => $val)
1734
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1826
+		foreach ($vars as $var => $val) {
1827
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1828
+		}
1735 1829
 	}
1736 1830
 
1737 1831
 	// Blank out the file - done to fix a oddity with some servers.
1738 1832
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1739
-	if (!$fp)
1740
-		return false;
1833
+	if (!$fp) {
1834
+			return false;
1835
+	}
1741 1836
 	fclose($fp);
1742 1837
 
1743 1838
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1744 1839
 
1745 1840
 	// Gotta have one of these ;)
1746
-	if (trim($settingsArray[0]) != '<?php')
1747
-		fwrite($fp, "<?php\n");
1841
+	if (trim($settingsArray[0]) != '<?php') {
1842
+			fwrite($fp, "<?php\n");
1843
+	}
1748 1844
 
1749 1845
 	$lines = count($settingsArray);
1750 1846
 	for ($i = 0; $i < $lines - 1; $i++)
1751 1847
 	{
1752 1848
 		// Don't just write a bunch of blank lines.
1753
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1754
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1849
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1850
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1851
+		}
1755 1852
 	}
1756 1853
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1757 1854
 	fclose($fp);
1758 1855
 
1759 1856
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1760 1857
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1761
-	if (function_exists('opcache_invalidate'))
1762
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1858
+	if (function_exists('opcache_invalidate')) {
1859
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1860
+	}
1763 1861
 
1764 1862
 	return true;
1765 1863
 }
@@ -1784,9 +1882,9 @@  discard block
 block discarded – undo
1784 1882
 	SecFilterScanPOST Off
1785 1883
 </IfModule>';
1786 1884
 
1787
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1788
-		return true;
1789
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1885
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1886
+			return true;
1887
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1790 1888
 	{
1791 1889
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1792 1890
 
@@ -1798,29 +1896,28 @@  discard block
 block discarded – undo
1798 1896
 				fwrite($ht_handle, $htaccess_addition);
1799 1897
 				fclose($ht_handle);
1800 1898
 				return true;
1899
+			} else {
1900
+							return false;
1801 1901
 			}
1802
-			else
1803
-				return false;
1902
+		} else {
1903
+					return true;
1804 1904
 		}
1805
-		else
1806
-			return true;
1807
-	}
1808
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1809
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1810
-	elseif (is_writable(dirname(__FILE__)))
1905
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1906
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1907
+	} elseif (is_writable(dirname(__FILE__)))
1811 1908
 	{
1812 1909
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1813 1910
 		{
1814 1911
 			fwrite($ht_handle, $htaccess_addition);
1815 1912
 			fclose($ht_handle);
1816 1913
 			return true;
1914
+		} else {
1915
+					return false;
1817 1916
 		}
1818
-		else
1917
+	} else {
1819 1918
 			return false;
1820 1919
 	}
1821
-	else
1822
-		return false;
1823
-}
1920
+	}
1824 1921
 
1825 1922
 function template_install_above()
1826 1923
 {
@@ -1858,9 +1955,10 @@  discard block
 block discarded – undo
1858 1955
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1859 1956
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1860 1957
 
1861
-		foreach ($incontext['detected_languages'] as $lang => $name)
1862
-			echo '
1958
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1959
+					echo '
1863 1960
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1961
+		}
1864 1962
 
1865 1963
 		echo '
1866 1964
 								</select>
@@ -1880,9 +1978,10 @@  discard block
 block discarded – undo
1880 1978
 						<h2>', $txt['upgrade_progress'], '</h2>
1881 1979
 						<ul>';
1882 1980
 
1883
-	foreach ($incontext['steps'] as $num => $step)
1884
-		echo '
1981
+	foreach ($incontext['steps'] as $num => $step) {
1982
+			echo '
1885 1983
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1984
+	}
1886 1985
 
1887 1986
 	echo '
1888 1987
 						</ul>
@@ -1907,20 +2006,23 @@  discard block
 block discarded – undo
1907 2006
 		echo '
1908 2007
 								<div>';
1909 2008
 
1910
-		if (!empty($incontext['continue']))
1911
-			echo '
2009
+		if (!empty($incontext['continue'])) {
2010
+					echo '
1912 2011
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1913
-		if (!empty($incontext['skip']))
1914
-			echo '
2012
+		}
2013
+		if (!empty($incontext['skip'])) {
2014
+					echo '
1915 2015
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
2016
+		}
1916 2017
 		echo '
1917 2018
 								</div>';
1918 2019
 	}
1919 2020
 
1920 2021
 	// Show the closing form tag and other data only if not in the last step
1921
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1922
-		echo '
2022
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2023
+			echo '
1923 2024
 							</form>';
2025
+	}
1924 2026
 
1925 2027
 	echo '
1926 2028
 						</div>
@@ -1955,13 +2057,15 @@  discard block
 block discarded – undo
1955 2057
 		</div>';
1956 2058
 
1957 2059
 	// Show the warnings, or not.
1958
-	if (template_warning_divs())
1959
-		echo '
2060
+	if (template_warning_divs()) {
2061
+			echo '
1960 2062
 		<h3>', $txt['install_all_lovely'], '</h3>';
2063
+	}
1961 2064
 
1962 2065
 	// Say we want the continue button!
1963
-	if (empty($incontext['error']))
1964
-		$incontext['continue'] = 1;
2066
+	if (empty($incontext['error'])) {
2067
+			$incontext['continue'] = 1;
2068
+	}
1965 2069
 
1966 2070
 	// For the latest version stuff.
1967 2071
 	echo '
@@ -1995,8 +2099,8 @@  discard block
 block discarded – undo
1995 2099
 	global $txt, $incontext;
1996 2100
 
1997 2101
 	// Errors are very serious..
1998
-	if (!empty($incontext['error']))
1999
-		echo '
2102
+	if (!empty($incontext['error'])) {
2103
+			echo '
2000 2104
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2001 2105
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2002 2106
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -2004,9 +2108,10 @@  discard block
 block discarded – undo
2004 2108
 				', $incontext['error'], '
2005 2109
 			</div>
2006 2110
 		</div>';
2111
+	}
2007 2112
 	// A warning message?
2008
-	elseif (!empty($incontext['warning']))
2009
-		echo '
2113
+	elseif (!empty($incontext['warning'])) {
2114
+			echo '
2010 2115
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
2011 2116
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2012 2117
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2014,6 +2119,7 @@  discard block
 block discarded – undo
2014 2119
 				', $incontext['warning'], '
2015 2120
 			</div>
2016 2121
 		</div>';
2122
+	}
2017 2123
 
2018 2124
 	return empty($incontext['error']) && empty($incontext['warning']);
2019 2125
 }
@@ -2029,27 +2135,30 @@  discard block
 block discarded – undo
2029 2135
 			<li>', $incontext['failed_files']), '</li>
2030 2136
 		</ul>';
2031 2137
 
2032
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2033
-		echo '
2138
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2139
+			echo '
2034 2140
 		<hr>
2035 2141
 		<p>', $txt['chmod_linux_info'], '</p>
2036 2142
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2143
+	}
2037 2144
 
2038 2145
 	// This is serious!
2039
-	if (!template_warning_divs())
2040
-		return;
2146
+	if (!template_warning_divs()) {
2147
+			return;
2148
+	}
2041 2149
 
2042 2150
 	echo '
2043 2151
 		<hr>
2044 2152
 		<p>', $txt['ftp_setup_info'], '</p>';
2045 2153
 
2046
-	if (!empty($incontext['ftp_errors']))
2047
-		echo '
2154
+	if (!empty($incontext['ftp_errors'])) {
2155
+			echo '
2048 2156
 		<div class="error_message">
2049 2157
 			', $txt['error_ftp_no_connect'], '<br><br>
2050 2158
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2051 2159
 		</div>
2052 2160
 		<br>';
2161
+	}
2053 2162
 
2054 2163
 	echo '
2055 2164
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2109,17 +2218,17 @@  discard block
 block discarded – undo
2109 2218
 				<td>
2110 2219
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2111 2220
 
2112
-	foreach ($incontext['supported_databases'] as $key => $db)
2113
-			echo '
2221
+	foreach ($incontext['supported_databases'] as $key => $db) {
2222
+				echo '
2114 2223
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2224
+	}
2115 2225
 
2116 2226
 	echo '
2117 2227
 					</select>
2118 2228
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2119 2229
 				</td>
2120 2230
 			</tr>';
2121
-	}
2122
-	else
2231
+	} else
2123 2232
 	{
2124 2233
 		echo '
2125 2234
 			<tr style="display: none;">
@@ -2311,9 +2420,10 @@  discard block
 block discarded – undo
2311 2420
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2312 2421
 				<ul>';
2313 2422
 
2314
-		foreach ($incontext['failures'] as $line => $fail)
2315
-			echo '
2423
+		foreach ($incontext['failures'] as $line => $fail) {
2424
+					echo '
2316 2425
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2426
+		}
2317 2427
 
2318 2428
 		echo '
2319 2429
 				</ul>';
@@ -2374,15 +2484,16 @@  discard block
 block discarded – undo
2374 2484
 			</tr>
2375 2485
 		</table>';
2376 2486
 
2377
-	if ($incontext['require_db_confirm'])
2378
-		echo '
2487
+	if ($incontext['require_db_confirm']) {
2488
+			echo '
2379 2489
 		<h2>', $txt['user_settings_database'], '</h2>
2380 2490
 		<p>', $txt['user_settings_database_info'], '</p>
2381 2491
 
2382 2492
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2383 2493
 			<input type="password" name="password3" size="30" class="input_password" />
2384 2494
 		</div>';
2385
-}
2495
+	}
2496
+	}
2386 2497
 
2387 2498
 // Tell them it's done, and to delete.
2388 2499
 function template_delete_install()
@@ -2395,14 +2506,15 @@  discard block
 block discarded – undo
2395 2506
 	template_warning_divs();
2396 2507
 
2397 2508
 	// Install directory still writable?
2398
-	if ($incontext['dir_still_writable'])
2399
-		echo '
2509
+	if ($incontext['dir_still_writable']) {
2510
+			echo '
2400 2511
 		<em>', $txt['still_writable'], '</em><br>
2401 2512
 		<br>';
2513
+	}
2402 2514
 
2403 2515
 	// Don't show the box if it's like 99% sure it won't work :P.
2404
-	if ($incontext['probably_delete_install'])
2405
-		echo '
2516
+	if ($incontext['probably_delete_install']) {
2517
+			echo '
2406 2518
 		<div style="margin: 1ex; font-weight: bold;">
2407 2519
 			<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>
2408 2520
 		</div>
@@ -2418,6 +2530,7 @@  discard block
 block discarded – undo
2418 2530
 			}
2419 2531
 		</script>
2420 2532
 		<br>';
2533
+	}
2421 2534
 
2422 2535
 	echo '
2423 2536
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.