Completed
Push — release-2.1 ( b31e7f...1ca3a6 )
by Jeremy
06:13
created
other/install.php 1 patch
Braces   +476 added lines, -354 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
 
@@ -371,8 +388,9 @@  discard block
 block discarded – undo
371 388
 	if (!$db_connection)
372 389
 	{
373 390
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
374
-		if (version_compare(PHP_VERSION, '5', '<'))
375
-			require_once($sourcedir . '/Subs-Compat.php');
391
+		if (version_compare(PHP_VERSION, '5', '<')) {
392
+					require_once($sourcedir . '/Subs-Compat.php');
393
+		}
376 394
 
377 395
 		$db_options = array('persist' => $db_persist);
378 396
 		$port = '';
@@ -383,19 +401,20 @@  discard block
 block discarded – undo
383 401
 			if ($db_type == 'mysql')
384 402
 			{
385 403
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
386
-			}
387
-			elseif ($db_type == 'postgresql')
404
+			} elseif ($db_type == 'postgresql')
388 405
 			{
389 406
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
390 407
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
391 408
 			}
392 409
 		}
393 410
 
394
-		if (!empty($port))
395
-			$db_options['port'] = $port;
411
+		if (!empty($port)) {
412
+					$db_options['port'] = $port;
413
+		}
396 414
 
397
-		if (!$db_connection)
398
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
415
+		if (!$db_connection) {
416
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
417
+		}
399 418
 	}
400 419
 }
401 420
 
@@ -423,8 +442,9 @@  discard block
 block discarded – undo
423 442
 		// @todo REMOVE THIS!!
424 443
 		else
425 444
 		{
426
-			if (function_exists('doStep' . $_GET['step']))
427
-				call_user_func('doStep' . $_GET['step']);
445
+			if (function_exists('doStep' . $_GET['step'])) {
446
+							call_user_func('doStep' . $_GET['step']);
447
+			}
428 448
 		}
429 449
 		// Show the footer.
430 450
 		template_install_below();
@@ -442,8 +462,9 @@  discard block
 block discarded – undo
442 462
 	$incontext['sub_template'] = 'welcome_message';
443 463
 
444 464
 	// Done the submission?
445
-	if (isset($_POST['contbutt']))
446
-		return true;
465
+	if (isset($_POST['contbutt'])) {
466
+			return true;
467
+	}
447 468
 
448 469
 	// See if we think they have already installed it?
449 470
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -451,14 +472,17 @@  discard block
 block discarded – undo
451 472
 		$probably_installed = 0;
452 473
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
453 474
 		{
454
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
455
-				$probably_installed++;
456
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
457
-				$probably_installed++;
475
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
476
+							$probably_installed++;
477
+			}
478
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
479
+							$probably_installed++;
480
+			}
458 481
 		}
459 482
 
460
-		if ($probably_installed == 2)
461
-			$incontext['warning'] = $txt['error_already_installed'];
483
+		if ($probably_installed == 2) {
484
+					$incontext['warning'] = $txt['error_already_installed'];
485
+		}
462 486
 	}
463 487
 
464 488
 	// Is some database support even compiled in?
@@ -473,45 +497,54 @@  discard block
 block discarded – undo
473 497
 				$databases[$key]['supported'] = false;
474 498
 				$notFoundSQLFile = true;
475 499
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
500
+			} else {
501
+							$incontext['supported_databases'][] = $db;
476 502
 			}
477
-			else
478
-				$incontext['supported_databases'][] = $db;
479 503
 		}
480 504
 	}
481 505
 
482 506
 	// Check the PHP version.
483
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>=')))
484
-		$error = 'error_php_too_low';
507
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>='))) {
508
+			$error = 'error_php_too_low';
509
+	}
485 510
 	// Make sure we have a supported database
486
-	elseif (empty($incontext['supported_databases']))
487
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
511
+	elseif (empty($incontext['supported_databases'])) {
512
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
513
+	}
488 514
 	// How about session support?  Some crazy sysadmin remove it?
489
-	elseif (!function_exists('session_start'))
490
-		$error = 'error_session_missing';
515
+	elseif (!function_exists('session_start')) {
516
+			$error = 'error_session_missing';
517
+	}
491 518
 	// Make sure they uploaded all the files.
492
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
493
-		$error = 'error_missing_files';
519
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
520
+			$error = 'error_missing_files';
521
+	}
494 522
 	// Very simple check on the session.save_path for Windows.
495 523
 	// @todo Move this down later if they don't use database-driven sessions?
496
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
497
-		$error = 'error_session_save_path';
524
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
525
+			$error = 'error_session_save_path';
526
+	}
498 527
 
499 528
 	// Since each of the three messages would look the same, anyway...
500
-	if (isset($error))
501
-		$incontext['error'] = $txt[$error];
529
+	if (isset($error)) {
530
+			$incontext['error'] = $txt[$error];
531
+	}
502 532
 
503 533
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
504
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
505
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
534
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
535
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
536
+	}
506 537
 
507 538
 	// Confirm mbstring is loaded...
508
-	if (!extension_loaded('mbstring'))
509
-		$incontext['error'] = $txt['install_no_mbstring'];
539
+	if (!extension_loaded('mbstring')) {
540
+			$incontext['error'] = $txt['install_no_mbstring'];
541
+	}
510 542
 
511 543
 	// Check for https stream support.
512 544
 	$supported_streams = stream_get_wrappers();
513
-	if (!in_array('https', $supported_streams))
514
-		$incontext['warning'] = $txt['install_no_https'];
545
+	if (!in_array('https', $supported_streams)) {
546
+			$incontext['warning'] = $txt['install_no_https'];
547
+	}
515 548
 
516 549
 	return false;
517 550
 }
@@ -536,12 +569,14 @@  discard block
 block discarded – undo
536 569
 		'Settings_bak.php',
537 570
 	);
538 571
 
539
-	foreach ($incontext['detected_languages'] as $lang => $temp)
540
-		$extra_files[] = 'Themes/default/languages/' . $lang;
572
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
573
+			$extra_files[] = 'Themes/default/languages/' . $lang;
574
+	}
541 575
 
542 576
 	// With mod_security installed, we could attempt to fix it with .htaccess.
543
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
544
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
577
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
578
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
579
+	}
545 580
 
546 581
 	$failed_files = array();
547 582
 
@@ -553,20 +588,23 @@  discard block
 block discarded – undo
553 588
 		foreach ($writable_files as $file)
554 589
 		{
555 590
 			// Some files won't exist, try to address up front
556
-			if (!file_exists(dirname(__FILE__) . '/' . $file))
557
-				@touch(dirname(__FILE__) . '/' . $file);
591
+			if (!file_exists(dirname(__FILE__) . '/' . $file)) {
592
+							@touch(dirname(__FILE__) . '/' . $file);
593
+			}
558 594
 			// NOW do the writable check...
559 595
 			if (!is_writable(dirname(__FILE__) . '/' . $file))
560 596
 			{
561 597
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
562 598
 
563 599
 				// Well, 755 hopefully worked... if not, try 777.
564
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
565
-					$failed_files[] = $file;
600
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
601
+									$failed_files[] = $file;
602
+				}
566 603
 			}
567 604
 		}
568
-		foreach ($extra_files as $file)
569
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
605
+		foreach ($extra_files as $file) {
606
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
607
+		}
570 608
 	}
571 609
 	// Windows is trickier.  Let's try opening for r+...
572 610
 	else
@@ -576,30 +614,35 @@  discard block
 block discarded – undo
576 614
 		foreach ($writable_files as $file)
577 615
 		{
578 616
 			// Folders can't be opened for write... but the index.php in them can ;)
579
-			if (is_dir(dirname(__FILE__) . '/' . $file))
580
-				$file .= '/index.php';
617
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
618
+							$file .= '/index.php';
619
+			}
581 620
 
582 621
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
583 622
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
584 623
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
585 624
 
586 625
 			// Hmm, okay, try just for write in that case...
587
-			if (!is_resource($fp))
588
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
626
+			if (!is_resource($fp)) {
627
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
628
+			}
589 629
 
590
-			if (!is_resource($fp))
591
-				$failed_files[] = $file;
630
+			if (!is_resource($fp)) {
631
+							$failed_files[] = $file;
632
+			}
592 633
 
593 634
 			@fclose($fp);
594 635
 		}
595
-		foreach ($extra_files as $file)
596
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
636
+		foreach ($extra_files as $file) {
637
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
638
+		}
597 639
 	}
598 640
 
599 641
 	$failure = count($failed_files) >= 1;
600 642
 
601
-	if (!isset($_SERVER))
602
-		return !$failure;
643
+	if (!isset($_SERVER)) {
644
+			return !$failure;
645
+	}
603 646
 
604 647
 	// Put the list into context.
605 648
 	$incontext['failed_files'] = $failed_files;
@@ -647,19 +690,23 @@  discard block
 block discarded – undo
647 690
 
648 691
 		if (!isset($ftp) || $ftp->error !== false)
649 692
 		{
650
-			if (!isset($ftp))
651
-				$ftp = new ftp_connection(null);
693
+			if (!isset($ftp)) {
694
+							$ftp = new ftp_connection(null);
695
+			}
652 696
 			// Save the error so we can mess with listing...
653
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
654
-				$incontext['ftp_errors'][] = $ftp->last_message;
697
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
698
+							$incontext['ftp_errors'][] = $ftp->last_message;
699
+			}
655 700
 
656 701
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
657 702
 
658
-			if (empty($_POST['ftp_path']) && $found_path)
659
-				$_POST['ftp_path'] = $detect_path;
703
+			if (empty($_POST['ftp_path']) && $found_path) {
704
+							$_POST['ftp_path'] = $detect_path;
705
+			}
660 706
 
661
-			if (!isset($_POST['ftp_username']))
662
-				$_POST['ftp_username'] = $username;
707
+			if (!isset($_POST['ftp_username'])) {
708
+							$_POST['ftp_username'] = $username;
709
+			}
663 710
 
664 711
 			// Set the username etc, into context.
665 712
 			$incontext['ftp'] = array(
@@ -671,8 +718,7 @@  discard block
 block discarded – undo
671 718
 			);
672 719
 
673 720
 			return false;
674
-		}
675
-		else
721
+		} else
676 722
 		{
677 723
 			$_SESSION['installer_temp_ftp'] = array(
678 724
 				'server' => $_POST['ftp_server'],
@@ -686,10 +732,12 @@  discard block
 block discarded – undo
686 732
 
687 733
 			foreach ($failed_files as $file)
688 734
 			{
689
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
690
-					$ftp->chmod($file, 0755);
691
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
692
-					$ftp->chmod($file, 0777);
735
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
736
+									$ftp->chmod($file, 0755);
737
+				}
738
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
739
+									$ftp->chmod($file, 0777);
740
+				}
693 741
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
694 742
 				{
695 743
 					$failed_files_updated[] = $file;
@@ -745,15 +793,17 @@  discard block
 block discarded – undo
745 793
 
746 794
 			if (!$foundOne)
747 795
 			{
748
-				if (isset($db['default_host']))
749
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
796
+				if (isset($db['default_host'])) {
797
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
798
+				}
750 799
 				if (isset($db['default_user']))
751 800
 				{
752 801
 					$incontext['db']['user'] = ini_get($db['default_user']);
753 802
 					$incontext['db']['name'] = ini_get($db['default_user']);
754 803
 				}
755
-				if (isset($db['default_password']))
756
-					$incontext['db']['pass'] = ini_get($db['default_password']);
804
+				if (isset($db['default_password'])) {
805
+									$incontext['db']['pass'] = ini_get($db['default_password']);
806
+				}
757 807
 
758 808
 				// For simplicity and less confusion, leave the port blank by default
759 809
 				$incontext['db']['port'] = '';
@@ -772,10 +822,10 @@  discard block
 block discarded – undo
772 822
 		$incontext['db']['server'] = $_POST['db_server'];
773 823
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
774 824
 
775
-		if (!empty($_POST['db_port']))
776
-			$incontext['db']['port'] = $_POST['db_port'];
777
-	}
778
-	else
825
+		if (!empty($_POST['db_port'])) {
826
+					$incontext['db']['port'] = $_POST['db_port'];
827
+		}
828
+	} else
779 829
 	{
780 830
 		$incontext['db']['prefix'] = 'smf_';
781 831
 	}
@@ -811,10 +861,11 @@  discard block
 block discarded – undo
811 861
 		if (!empty($_POST['db_port']))
812 862
 		{
813 863
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
814
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
815
-				$vars['db_port'] = (int) $_POST['db_port'];
816
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
817
-				$vars['db_port'] = (int) $_POST['db_port'];
864
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
865
+							$vars['db_port'] = (int) $_POST['db_port'];
866
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
867
+							$vars['db_port'] = (int) $_POST['db_port'];
868
+			}
818 869
 		}
819 870
 
820 871
 		// God I hope it saved!
@@ -827,8 +878,9 @@  discard block
 block discarded – undo
827 878
 		// Make sure it works.
828 879
 		require(dirname(__FILE__) . '/Settings.php');
829 880
 
830
-		if (empty($sourcedir))
831
-			$sourcedir = dirname(__FILE__) . '/Sources';
881
+		if (empty($sourcedir)) {
882
+					$sourcedir = dirname(__FILE__) . '/Sources';
883
+		}
832 884
 
833 885
 		// Better find the database file!
834 886
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -838,29 +890,34 @@  discard block
 block discarded – undo
838 890
 		}
839 891
 
840 892
 		// Now include it for database functions!
841
-		if (!defined('SMF'))
842
-			define('SMF', 1);
893
+		if (!defined('SMF')) {
894
+					define('SMF', 1);
895
+		}
843 896
 
844 897
 		$modSettings['disableQueryCheck'] = true;
845
-		if (empty($smcFunc))
846
-			$smcFunc = array();
898
+		if (empty($smcFunc)) {
899
+					$smcFunc = array();
900
+		}
847 901
 
848 902
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
849 903
 
850 904
 		// What - running PHP4? The shame!
851
-		if (version_compare(PHP_VERSION, '5', '<'))
852
-			require_once($sourcedir . '/Subs-Compat.php');
905
+		if (version_compare(PHP_VERSION, '5', '<')) {
906
+					require_once($sourcedir . '/Subs-Compat.php');
907
+		}
853 908
 
854 909
 		// Attempt a connection.
855 910
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
856 911
 
857 912
 		$options = array('non_fatal' => true, 'dont_select_db' => !$needsDB);
858 913
 		// Add in the port if needed
859
-		if (!empty($db_port))
860
-			$options['port'] = $db_port;
914
+		if (!empty($db_port)) {
915
+					$options['port'] = $db_port;
916
+		}
861 917
 		
862
-		if (!empty($db_mb4))
863
-			$options['db_mb4'] = $db_mb4;
918
+		if (!empty($db_mb4)) {
919
+					$options['db_mb4'] = $db_mb4;
920
+		}
864 921
 
865 922
 		$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options);
866 923
 
@@ -946,12 +1003,14 @@  discard block
 block discarded – undo
946 1003
 	$incontext['page_title'] = $txt['install_settings'];
947 1004
 
948 1005
 	// Let's see if we got the database type correct.
949
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
950
-		$db_type = $_POST['db_type'];
1006
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
1007
+			$db_type = $_POST['db_type'];
1008
+	}
951 1009
 
952 1010
 	// Else we'd better be able to get the connection.
953
-	else
954
-		load_database();
1011
+	else {
1012
+			load_database();
1013
+	}
955 1014
 
956 1015
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
957 1016
 
@@ -960,10 +1019,11 @@  discard block
 block discarded – undo
960 1019
 
961 1020
 		$secure = false;
962 1021
 
963
-		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
964
-			$secure = true;
965
-		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')
966
-			$secure = true;
1022
+		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
1023
+					$secure = true;
1024
+		} 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') {
1025
+					$secure = true;
1026
+		}
967 1027
 
968 1028
 	// Now, to put what we've learned together... and add a path.
969 1029
 	$incontext['detected_url'] = 'http' . ($secure ? 's' : '') . '://' . $host . substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
@@ -995,18 +1055,21 @@  discard block
 block discarded – undo
995 1055
 	// Submitting?
996 1056
 	if (isset($_POST['boardurl']))
997 1057
 	{
998
-		if (substr($_POST['boardurl'], -10) == '/index.php')
999
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1000
-		elseif (substr($_POST['boardurl'], -1) == '/')
1001
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1002
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1003
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1058
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1059
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1060
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1061
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1062
+		}
1063
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1064
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1065
+		}
1004 1066
 
1005 1067
 		//Make sure boardurl is aligned with ssl setting
1006
-		if (empty($_POST['force_ssl']))
1007
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1008
-		else
1009
-			$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1068
+		if (empty($_POST['force_ssl'])) {
1069
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('https://' => 'http://'));
1070
+		} else {
1071
+					$_POST['boardurl'] = strtr($_POST['boardurl'], array('http://' => 'https://'));
1072
+		}
1010 1073
 
1011 1074
 		// Save these variables.
1012 1075
 		$vars = array(
@@ -1045,10 +1108,10 @@  discard block
 block discarded – undo
1045 1108
 			{
1046 1109
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
1047 1110
 				return false;
1048
-			}
1049
-			else
1050
-				// Set the character set here.
1111
+			} else {
1112
+							// Set the character set here.
1051 1113
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1114
+			}
1052 1115
 		}
1053 1116
 
1054 1117
 		// Good, skip on.
@@ -1068,8 +1131,9 @@  discard block
 block discarded – undo
1068 1131
 	$incontext['continue'] = 1;
1069 1132
 
1070 1133
 	// Already done?
1071
-	if (isset($_POST['pop_done']))
1072
-		return true;
1134
+	if (isset($_POST['pop_done'])) {
1135
+			return true;
1136
+	}
1073 1137
 
1074 1138
 	// Reload settings.
1075 1139
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1087,8 +1151,9 @@  discard block
 block discarded – undo
1087 1151
 	$modSettings = array();
1088 1152
 	if ($result !== false)
1089 1153
 	{
1090
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1091
-			$modSettings[$row['variable']] = $row['value'];
1154
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1155
+					$modSettings[$row['variable']] = $row['value'];
1156
+		}
1092 1157
 		$smcFunc['db_free_result']($result);
1093 1158
 
1094 1159
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1101,20 +1166,22 @@  discard block
 block discarded – undo
1101 1166
 	$modSettings['disableQueryCheck'] = true;
1102 1167
 
1103 1168
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1104
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1105
-		$smcFunc['db_query']('', '
1169
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1170
+			$smcFunc['db_query']('', '
1106 1171
 			SET NAMES {string:utf8}',
1107 1172
 			array(
1108 1173
 				'db_error_skip' => true,
1109 1174
 				'utf8' => 'utf8',
1110 1175
 			)
1111 1176
 		);
1177
+	}
1112 1178
 
1113 1179
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1114
-	if (substr(__DIR__, -1) == '\\')
1115
-		$attachdir = __DIR__ . 'attachments';
1116
-	else
1117
-		$attachdir = __DIR__ . '/attachments';
1180
+	if (substr(__DIR__, -1) == '\\') {
1181
+			$attachdir = __DIR__ . 'attachments';
1182
+	} else {
1183
+			$attachdir = __DIR__ . '/attachments';
1184
+	}
1118 1185
 
1119 1186
 	$replaces = array(
1120 1187
 		'{$db_prefix}' => $db_prefix,
@@ -1131,8 +1198,9 @@  discard block
 block discarded – undo
1131 1198
 
1132 1199
 	foreach ($txt as $key => $value)
1133 1200
 	{
1134
-		if (substr($key, 0, 8) == 'default_')
1135
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1201
+		if (substr($key, 0, 8) == 'default_') {
1202
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1203
+		}
1136 1204
 	}
1137 1205
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1138 1206
 
@@ -1147,8 +1215,9 @@  discard block
 block discarded – undo
1147 1215
 
1148 1216
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1149 1217
 		{
1150
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1151
-				$engines[] = $row['Engine'];
1218
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1219
+							$engines[] = $row['Engine'];
1220
+			}
1152 1221
 		}
1153 1222
 
1154 1223
 		// Done with this now
@@ -1172,8 +1241,7 @@  discard block
 block discarded – undo
1172 1241
 			$replaces['START TRANSACTION;'] = '';
1173 1242
 			$replaces['COMMIT;'] = '';
1174 1243
 		}
1175
-	}
1176
-	else
1244
+	} else
1177 1245
 	{
1178 1246
 		$has_innodb = false;
1179 1247
 	}
@@ -1195,21 +1263,24 @@  discard block
 block discarded – undo
1195 1263
 	foreach ($sql_lines as $count => $line)
1196 1264
 	{
1197 1265
 		// No comments allowed!
1198
-		if (substr(trim($line), 0, 1) != '#')
1199
-			$current_statement .= "\n" . rtrim($line);
1266
+		if (substr(trim($line), 0, 1) != '#') {
1267
+					$current_statement .= "\n" . rtrim($line);
1268
+		}
1200 1269
 
1201 1270
 		// Is this the end of the query string?
1202
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1203
-			continue;
1271
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1272
+					continue;
1273
+		}
1204 1274
 
1205 1275
 		// Does this table already exist?  If so, don't insert more data into it!
1206 1276
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1207 1277
 		{
1208 1278
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1209
-			if (!empty($matches[0]))
1210
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1211
-			else
1212
-				$incontext['sql_results']['insert_dups']++;
1279
+			if (!empty($matches[0])) {
1280
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1281
+			} else {
1282
+							$incontext['sql_results']['insert_dups']++;
1283
+			}
1213 1284
 
1214 1285
 			$current_statement = '';
1215 1286
 			continue;
@@ -1218,8 +1289,9 @@  discard block
 block discarded – undo
1218 1289
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1219 1290
 		{
1220 1291
 			// Use the appropriate function based on the DB type
1221
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1222
-				$db_errorno = $db_type . '_errno';
1292
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1293
+							$db_errorno = $db_type . '_errno';
1294
+			}
1223 1295
 
1224 1296
 			// Error 1050: Table already exists!
1225 1297
 			// @todo Needs to be made better!
@@ -1234,18 +1306,18 @@  discard block
 block discarded – undo
1234 1306
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1235 1307
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1236 1308
 			}
1237
-		}
1238
-		else
1309
+		} else
1239 1310
 		{
1240
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1241
-				$incontext['sql_results']['tables']++;
1242
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1311
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1312
+							$incontext['sql_results']['tables']++;
1313
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1243 1314
 			{
1244 1315
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1245
-				if (!empty($matches[0]))
1246
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1247
-				else
1248
-					$incontext['sql_results']['inserts']++;
1316
+				if (!empty($matches[0])) {
1317
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1318
+				} else {
1319
+									$incontext['sql_results']['inserts']++;
1320
+				}
1249 1321
 			}
1250 1322
 		}
1251 1323
 
@@ -1258,15 +1330,17 @@  discard block
 block discarded – undo
1258 1330
 	// Sort out the context for the SQL.
1259 1331
 	foreach ($incontext['sql_results'] as $key => $number)
1260 1332
 	{
1261
-		if ($number == 0)
1262
-			unset($incontext['sql_results'][$key]);
1263
-		else
1264
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1333
+		if ($number == 0) {
1334
+					unset($incontext['sql_results'][$key]);
1335
+		} else {
1336
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1337
+		}
1265 1338
 	}
1266 1339
 
1267 1340
 	// Make sure UTF will be used globally.
1268
-	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'])))
1269
-		$newSettings[] = array('global_character_set', 'UTF-8');
1341
+	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']))) {
1342
+			$newSettings[] = array('global_character_set', 'UTF-8');
1343
+	}
1270 1344
 
1271 1345
 	// Auto-detect local & global cookie settings
1272 1346
 	$url_parts = parse_url($boardurl);
@@ -1295,15 +1369,19 @@  discard block
 block discarded – undo
1295 1369
 
1296 1370
 		// Look for subfolder, if found, set localCookie
1297 1371
 		// Checking for len > 1 ensures you don't have just a slash...
1298
-		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1)
1299
-			$localCookies = '1';
1372
+		if (!empty($url_parts['path']) && strlen($url_parts['path']) > 1) {
1373
+					$localCookies = '1';
1374
+		}
1300 1375
 
1301
-		if (isset($globalCookies))
1302
-			$newSettings[] = array('globalCookies', $globalCookies);
1303
-		if (isset($globalCookiesDomain))
1304
-			$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1305
-		if (isset($localCookies))
1306
-			$newSettings[] = array('localCookies', $localCookies);
1376
+		if (isset($globalCookies)) {
1377
+					$newSettings[] = array('globalCookies', $globalCookies);
1378
+		}
1379
+		if (isset($globalCookiesDomain)) {
1380
+					$newSettings[] = array('globalCookiesDomain', $globalCookiesDomain);
1381
+		}
1382
+		if (isset($localCookies)) {
1383
+					$newSettings[] = array('localCookies', $localCookies);
1384
+		}
1307 1385
 	}
1308 1386
 
1309 1387
 	// Are we allowing stat collection?
@@ -1321,16 +1399,17 @@  discard block
 block discarded – undo
1321 1399
 			fwrite($fp, $out);
1322 1400
 
1323 1401
 			$return_data = '';
1324
-			while (!feof($fp))
1325
-				$return_data .= fgets($fp, 128);
1402
+			while (!feof($fp)) {
1403
+							$return_data .= fgets($fp, 128);
1404
+			}
1326 1405
 
1327 1406
 			fclose($fp);
1328 1407
 
1329 1408
 			// Get the unique site ID.
1330 1409
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1331 1410
 
1332
-			if (!empty($ID[1]))
1333
-				$smcFunc['db_insert']('replace',
1411
+			if (!empty($ID[1])) {
1412
+							$smcFunc['db_insert']('replace',
1334 1413
 					$db_prefix . 'settings',
1335 1414
 					array('variable' => 'string', 'value' => 'string'),
1336 1415
 					array(
@@ -1339,11 +1418,12 @@  discard block
 block discarded – undo
1339 1418
 					),
1340 1419
 					array('variable')
1341 1420
 				);
1421
+			}
1342 1422
 		}
1343 1423
 	}
1344 1424
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1345
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1346
-		$smcFunc['db_query']('', '
1425
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1426
+			$smcFunc['db_query']('', '
1347 1427
 			DELETE FROM {db_prefix}settings
1348 1428
 			WHERE variable = {string:enable_sm_stats}',
1349 1429
 			array(
@@ -1351,20 +1431,23 @@  discard block
 block discarded – undo
1351 1431
 				'db_error_skip' => true,
1352 1432
 			)
1353 1433
 		);
1434
+	}
1354 1435
 
1355 1436
 	// Are we enabling SSL?
1356
-	if (!empty($_POST['force_ssl']))
1357
-		$newSettings[] = array('force_ssl', 1);
1437
+	if (!empty($_POST['force_ssl'])) {
1438
+			$newSettings[] = array('force_ssl', 1);
1439
+	}
1358 1440
 
1359 1441
 	// Setting a timezone is required.
1360 1442
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1361 1443
 	{
1362 1444
 		// Get PHP's default timezone, if set
1363 1445
 		$ini_tz = ini_get('date.timezone');
1364
-		if (!empty($ini_tz))
1365
-			$timezone_id = $ini_tz;
1366
-		else
1367
-			$timezone_id = '';
1446
+		if (!empty($ini_tz)) {
1447
+					$timezone_id = $ini_tz;
1448
+		} else {
1449
+					$timezone_id = '';
1450
+		}
1368 1451
 
1369 1452
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1370 1453
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1373,8 +1456,9 @@  discard block
 block discarded – undo
1373 1456
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1374 1457
 		}
1375 1458
 
1376
-		if (date_default_timezone_set($timezone_id))
1377
-			$newSettings[] = array('default_timezone', $timezone_id);
1459
+		if (date_default_timezone_set($timezone_id)) {
1460
+					$newSettings[] = array('default_timezone', $timezone_id);
1461
+		}
1378 1462
 	}
1379 1463
 
1380 1464
 	if (!empty($newSettings))
@@ -1405,16 +1489,18 @@  discard block
 block discarded – undo
1405 1489
 	}
1406 1490
 
1407 1491
 	// MySQL specific stuff
1408
-	if (substr($db_type, 0, 5) != 'mysql')
1409
-		return false;
1492
+	if (substr($db_type, 0, 5) != 'mysql') {
1493
+			return false;
1494
+	}
1410 1495
 
1411 1496
 	// Find database user privileges.
1412 1497
 	$privs = array();
1413 1498
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1414 1499
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1415 1500
 	{
1416
-		if ($row['Privilege'] == 'Alter')
1417
-			$privs[] = $row['Privilege'];
1501
+		if ($row['Privilege'] == 'Alter') {
1502
+					$privs[] = $row['Privilege'];
1503
+		}
1418 1504
 	}
1419 1505
 	$smcFunc['db_free_result']($get_privs);
1420 1506
 
@@ -1444,8 +1530,9 @@  discard block
 block discarded – undo
1444 1530
 	$incontext['continue'] = 1;
1445 1531
 
1446 1532
 	// Skipping?
1447
-	if (!empty($_POST['skip']))
1448
-		return true;
1533
+	if (!empty($_POST['skip'])) {
1534
+			return true;
1535
+	}
1449 1536
 
1450 1537
 	// Need this to check whether we need the database password.
1451 1538
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1462,18 +1549,22 @@  discard block
 block discarded – undo
1462 1549
 	// We need this to properly hash the password for Admin
1463 1550
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1464 1551
 			global $sourcedir;
1465
-			if (function_exists('mb_strtolower'))
1466
-				return mb_strtolower($string, 'UTF-8');
1552
+			if (function_exists('mb_strtolower')) {
1553
+							return mb_strtolower($string, 'UTF-8');
1554
+			}
1467 1555
 			require_once($sourcedir . '/Subs-Charset.php');
1468 1556
 			return utf8_strtolower($string);
1469 1557
 		};
1470 1558
 
1471
-	if (!isset($_POST['username']))
1472
-		$_POST['username'] = '';
1473
-	if (!isset($_POST['email']))
1474
-		$_POST['email'] = '';
1475
-	if (!isset($_POST['server_email']))
1476
-		$_POST['server_email'] = '';
1559
+	if (!isset($_POST['username'])) {
1560
+			$_POST['username'] = '';
1561
+	}
1562
+	if (!isset($_POST['email'])) {
1563
+			$_POST['email'] = '';
1564
+	}
1565
+	if (!isset($_POST['server_email'])) {
1566
+			$_POST['server_email'] = '';
1567
+	}
1477 1568
 
1478 1569
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1479 1570
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1492,8 +1583,9 @@  discard block
 block discarded – undo
1492 1583
 			'admin_group' => 1,
1493 1584
 		)
1494 1585
 	);
1495
-	if ($smcFunc['db_num_rows']($request) != 0)
1496
-		$incontext['skip'] = 1;
1586
+	if ($smcFunc['db_num_rows']($request) != 0) {
1587
+			$incontext['skip'] = 1;
1588
+	}
1497 1589
 	$smcFunc['db_free_result']($request);
1498 1590
 
1499 1591
 	// Trying to create an account?
@@ -1524,8 +1616,9 @@  discard block
 block discarded – undo
1524 1616
 		}
1525 1617
 
1526 1618
 		// Update the webmaster's email?
1527
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1528
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1619
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1620
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1621
+		}
1529 1622
 
1530 1623
 		// Work out whether we're going to have dodgy characters and remove them.
1531 1624
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1548,32 +1641,27 @@  discard block
 block discarded – undo
1548 1641
 			$smcFunc['db_free_result']($result);
1549 1642
 
1550 1643
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1551
-		}
1552
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1644
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1553 1645
 		{
1554 1646
 			// Try the previous step again.
1555 1647
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1556 1648
 			return false;
1557
-		}
1558
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1649
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1559 1650
 		{
1560 1651
 			// Try the previous step again.
1561 1652
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1562 1653
 			return false;
1563
-		}
1564
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1654
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1565 1655
 		{
1566 1656
 			// One step back, this time fill out a proper admin email address.
1567 1657
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1568 1658
 			return false;
1569
-		}
1570
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1659
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1571 1660
 		{
1572 1661
 			// One step back, this time fill out a proper admin email address.
1573 1662
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1574 1663
 			return false;
1575
-		}
1576
-		elseif ($_POST['username'] != '')
1664
+		} elseif ($_POST['username'] != '')
1577 1665
 		{
1578 1666
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1579 1667
 
@@ -1641,17 +1729,19 @@  discard block
 block discarded – undo
1641 1729
 	reloadSettings();
1642 1730
 
1643 1731
 	// Bring a warning over.
1644
-	if (!empty($incontext['account_existed']))
1645
-		$incontext['warning'] = $incontext['account_existed'];
1732
+	if (!empty($incontext['account_existed'])) {
1733
+			$incontext['warning'] = $incontext['account_existed'];
1734
+	}
1646 1735
 
1647
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1648
-		$smcFunc['db_query']('', '
1736
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1737
+			$smcFunc['db_query']('', '
1649 1738
 			SET NAMES {string:db_character_set}',
1650 1739
 			array(
1651 1740
 				'db_character_set' => $db_character_set,
1652 1741
 				'db_error_skip' => true,
1653 1742
 			)
1654 1743
 		);
1744
+	}
1655 1745
 
1656 1746
 	// As track stats is by default enabled let's add some activity.
1657 1747
 	$smcFunc['db_insert']('ignore',
@@ -1672,14 +1762,16 @@  discard block
 block discarded – undo
1672 1762
 	// Only proceed if we can load the data.
1673 1763
 	if ($request)
1674 1764
 	{
1675
-		while ($row = $smcFunc['db_fetch_row']($request))
1676
-			$modSettings[$row[0]] = $row[1];
1765
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1766
+					$modSettings[$row[0]] = $row[1];
1767
+		}
1677 1768
 		$smcFunc['db_free_result']($request);
1678 1769
 	}
1679 1770
 
1680 1771
 	// Automatically log them in ;)
1681
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1682
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1772
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1773
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1774
+	}
1683 1775
 
1684 1776
 	$result = $smcFunc['db_query']('', '
1685 1777
 		SELECT value
@@ -1690,13 +1782,14 @@  discard block
 block discarded – undo
1690 1782
 			'db_error_skip' => true,
1691 1783
 		)
1692 1784
 	);
1693
-	if ($smcFunc['db_num_rows']($result) != 0)
1694
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1785
+	if ($smcFunc['db_num_rows']($result) != 0) {
1786
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1787
+	}
1695 1788
 	$smcFunc['db_free_result']($result);
1696 1789
 
1697
-	if (empty($db_sessions))
1698
-		$_SESSION['admin_time'] = time();
1699
-	else
1790
+	if (empty($db_sessions)) {
1791
+			$_SESSION['admin_time'] = time();
1792
+	} else
1700 1793
 	{
1701 1794
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1702 1795
 
@@ -1720,8 +1813,9 @@  discard block
 block discarded – undo
1720 1813
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1721 1814
 		function($string){
1722 1815
 			global $sourcedir;
1723
-			if (function_exists('mb_strtolower'))
1724
-				return mb_strtolower($string, 'UTF-8');
1816
+			if (function_exists('mb_strtolower')) {
1817
+							return mb_strtolower($string, 'UTF-8');
1818
+			}
1725 1819
 			require_once($sourcedir . '/Subs-Charset.php');
1726 1820
 			return utf8_strtolower($string);
1727 1821
 		};
@@ -1737,8 +1831,9 @@  discard block
 block discarded – undo
1737 1831
 		)
1738 1832
 	);
1739 1833
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1740
-	if ($smcFunc['db_num_rows']($request) > 0)
1741
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1834
+	if ($smcFunc['db_num_rows']($request) > 0) {
1835
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1836
+	}
1742 1837
 	$smcFunc['db_free_result']($request);
1743 1838
 
1744 1839
 	// Now is the perfect time to fetch the SM files.
@@ -1757,8 +1852,9 @@  discard block
 block discarded – undo
1757 1852
 
1758 1853
 	// Check if we need some stupid MySQL fix.
1759 1854
 	$server_version = $smcFunc['db_server_info']();
1760
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1761
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1855
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1856
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1857
+	}
1762 1858
 
1763 1859
 	// Some final context for the template.
1764 1860
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1778,8 +1874,9 @@  discard block
 block discarded – undo
1778 1874
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1779 1875
 
1780 1876
 	// @todo Do we just want to read the file in clean, and split it this way always?
1781
-	if (count($settingsArray) == 1)
1782
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1877
+	if (count($settingsArray) == 1) {
1878
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1879
+	}
1783 1880
 
1784 1881
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1785 1882
 	{
@@ -1787,25 +1884,29 @@  discard block
 block discarded – undo
1787 1884
 		if (trim($settingsArray[$i]) == 'if (file_exists(dirname(__FILE__) . \'/install.php\'))' && trim($settingsArray[$i + 1]) == '{' && trim($settingsArray[$i + 9]) == '}')
1788 1885
 		{
1789 1886
 			// Set the ten lines to nothing.
1790
-			for ($j=0; $j < 10; $j++)
1791
-				$settingsArray[$i++] = '';
1887
+			for ($j=0; $j < 10; $j++) {
1888
+							$settingsArray[$i++] = '';
1889
+			}
1792 1890
 
1793 1891
 			continue;
1794 1892
 		}
1795 1893
 
1796
-		if (trim($settingsArray[$i]) == '?' . '>')
1797
-			$settingsArray[$i] = '';
1894
+		if (trim($settingsArray[$i]) == '?' . '>') {
1895
+					$settingsArray[$i] = '';
1896
+		}
1798 1897
 
1799 1898
 		// Don't trim or bother with it if it's not a variable.
1800
-		if (substr($settingsArray[$i], 0, 1) != '$')
1801
-			continue;
1899
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1900
+					continue;
1901
+		}
1802 1902
 
1803 1903
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1804 1904
 
1805
-		foreach ($vars as $var => $val)
1806
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1905
+		foreach ($vars as $var => $val) {
1906
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1807 1907
 			{
1808 1908
 				$comment = strstr($settingsArray[$i], '#');
1909
+		}
1809 1910
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1810 1911
 				unset($vars[$var]);
1811 1912
 			}
@@ -1815,36 +1916,41 @@  discard block
 block discarded – undo
1815 1916
 	if (!empty($vars))
1816 1917
 	{
1817 1918
 		$settingsArray[$i++] = '';
1818
-		foreach ($vars as $var => $val)
1819
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1919
+		foreach ($vars as $var => $val) {
1920
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1921
+		}
1820 1922
 	}
1821 1923
 
1822 1924
 	// Blank out the file - done to fix a oddity with some servers.
1823 1925
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1824
-	if (!$fp)
1825
-		return false;
1926
+	if (!$fp) {
1927
+			return false;
1928
+	}
1826 1929
 	fclose($fp);
1827 1930
 
1828 1931
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1829 1932
 
1830 1933
 	// Gotta have one of these ;)
1831
-	if (trim($settingsArray[0]) != '<?php')
1832
-		fwrite($fp, "<?php\n");
1934
+	if (trim($settingsArray[0]) != '<?php') {
1935
+			fwrite($fp, "<?php\n");
1936
+	}
1833 1937
 
1834 1938
 	$lines = count($settingsArray);
1835 1939
 	for ($i = 0; $i < $lines - 1; $i++)
1836 1940
 	{
1837 1941
 		// Don't just write a bunch of blank lines.
1838
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1839
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1942
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1943
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1944
+		}
1840 1945
 	}
1841 1946
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1842 1947
 	fclose($fp);
1843 1948
 
1844 1949
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1845 1950
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1846
-	if (function_exists('opcache_invalidate'))
1847
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1951
+	if (function_exists('opcache_invalidate')) {
1952
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1953
+	}
1848 1954
 
1849 1955
 	return true;
1850 1956
 }
@@ -1854,10 +1960,11 @@  discard block
 block discarded – undo
1854 1960
 	global $cachedir;
1855 1961
 
1856 1962
 	// Write out the db_last_error file with the error timestamp
1857
-	if (!empty($cachedir) && is_writable($cachedir))
1858
-		file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1859
-	else
1860
-		file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1963
+	if (!empty($cachedir) && is_writable($cachedir)) {
1964
+			file_put_contents($cachedir . '/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1965
+	} else {
1966
+			file_put_contents(dirname(__FILE__) . '/cache/db_last_error.php', '<' . '?' . "php\n" . '$db_last_error = 0;' . "\n" . '?' . '>');
1967
+	}
1861 1968
 
1862 1969
 	return true;
1863 1970
 }
@@ -1874,9 +1981,9 @@  discard block
 block discarded – undo
1874 1981
 	SecFilterScanPOST Off
1875 1982
 </IfModule>';
1876 1983
 
1877
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1878
-		return true;
1879
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1984
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1985
+			return true;
1986
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1880 1987
 	{
1881 1988
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1882 1989
 
@@ -1888,29 +1995,28 @@  discard block
 block discarded – undo
1888 1995
 				fwrite($ht_handle, $htaccess_addition);
1889 1996
 				fclose($ht_handle);
1890 1997
 				return true;
1998
+			} else {
1999
+							return false;
1891 2000
 			}
1892
-			else
1893
-				return false;
2001
+		} else {
2002
+					return true;
1894 2003
 		}
1895
-		else
1896
-			return true;
1897
-	}
1898
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1899
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1900
-	elseif (is_writable(dirname(__FILE__)))
2004
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
2005
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
2006
+	} elseif (is_writable(dirname(__FILE__)))
1901 2007
 	{
1902 2008
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1903 2009
 		{
1904 2010
 			fwrite($ht_handle, $htaccess_addition);
1905 2011
 			fclose($ht_handle);
1906 2012
 			return true;
2013
+		} else {
2014
+					return false;
1907 2015
 		}
1908
-		else
2016
+	} else {
1909 2017
 			return false;
1910 2018
 	}
1911
-	else
1912
-		return false;
1913
-}
2019
+	}
1914 2020
 
1915 2021
 function template_install_above()
1916 2022
 {
@@ -1949,9 +2055,10 @@  discard block
 block discarded – undo
1949 2055
 							<label for="installer_language">', $txt['installer_language'], ':</label>
1950 2056
 							<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1951 2057
 
1952
-		foreach ($incontext['detected_languages'] as $lang => $name)
1953
-			echo '
2058
+		foreach ($incontext['detected_languages'] as $lang => $name) {
2059
+					echo '
1954 2060
 								<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
2061
+		}
1955 2062
 
1956 2063
 		echo '
1957 2064
 							</select>
@@ -1971,9 +2078,10 @@  discard block
 block discarded – undo
1971 2078
 					<h2>', $txt['upgrade_progress'], '</h2>
1972 2079
 					<ul>';
1973 2080
 
1974
-	foreach ($incontext['steps'] as $num => $step)
1975
-		echo '
2081
+	foreach ($incontext['steps'] as $num => $step) {
2082
+			echo '
1976 2083
 						<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
2084
+	}
1977 2085
 
1978 2086
 	echo '
1979 2087
 					</ul>
@@ -1999,20 +2107,23 @@  discard block
 block discarded – undo
1999 2107
 		echo '
2000 2108
 							<div class="floatright">';
2001 2109
 
2002
-		if (!empty($incontext['continue']))
2003
-			echo '
2110
+		if (!empty($incontext['continue'])) {
2111
+					echo '
2004 2112
 								<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button">';
2005
-		if (!empty($incontext['skip']))
2006
-			echo '
2113
+		}
2114
+		if (!empty($incontext['skip'])) {
2115
+					echo '
2007 2116
 								<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button">';
2117
+		}
2008 2118
 		echo '
2009 2119
 							</div>';
2010 2120
 	}
2011 2121
 
2012 2122
 	// Show the closing form tag and other data only if not in the last step
2013
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
2014
-		echo '
2123
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2124
+			echo '
2015 2125
 						</form>';
2126
+	}
2016 2127
 
2017 2128
 	echo '
2018 2129
 					</div><!-- .panel -->
@@ -2045,13 +2156,15 @@  discard block
 block discarded – undo
2045 2156
 		</div>';
2046 2157
 
2047 2158
 	// Show the warnings, or not.
2048
-	if (template_warning_divs())
2049
-		echo '
2159
+	if (template_warning_divs()) {
2160
+			echo '
2050 2161
 		<h3>', $txt['install_all_lovely'], '</h3>';
2162
+	}
2051 2163
 
2052 2164
 	// Say we want the continue button!
2053
-	if (empty($incontext['error']))
2054
-		$incontext['continue'] = 1;
2165
+	if (empty($incontext['error'])) {
2166
+			$incontext['continue'] = 1;
2167
+	}
2055 2168
 
2056 2169
 	// For the latest version stuff.
2057 2170
 	echo '
@@ -2085,19 +2198,21 @@  discard block
 block discarded – undo
2085 2198
 	global $txt, $incontext;
2086 2199
 
2087 2200
 	// Errors are very serious..
2088
-	if (!empty($incontext['error']))
2089
-		echo '
2201
+	if (!empty($incontext['error'])) {
2202
+			echo '
2090 2203
 		<div class="errorbox">
2091 2204
 			<h3>', $txt['upgrade_critical_error'], '</h3>
2092 2205
 			', $incontext['error'], '
2093 2206
 		</div>';
2207
+	}
2094 2208
 	// A warning message?
2095
-	elseif (!empty($incontext['warning']))
2096
-		echo '
2209
+	elseif (!empty($incontext['warning'])) {
2210
+			echo '
2097 2211
 		<div class="errorbox">
2098 2212
 			<h3>', $txt['upgrade_warning'], '</h3>
2099 2213
 			', $incontext['warning'], '
2100 2214
 		</div>';
2215
+	}
2101 2216
 
2102 2217
 	return empty($incontext['error']) && empty($incontext['warning']);
2103 2218
 }
@@ -2113,26 +2228,29 @@  discard block
 block discarded – undo
2113 2228
 			<li>', $incontext['failed_files']), '</li>
2114 2229
 		</ul>';
2115 2230
 
2116
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2117
-		echo '
2231
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2232
+			echo '
2118 2233
 		<hr>
2119 2234
 		<p>', $txt['chmod_linux_info'], '</p>
2120 2235
 		<samp># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</samp>';
2236
+	}
2121 2237
 
2122 2238
 	// This is serious!
2123
-	if (!template_warning_divs())
2124
-		return;
2239
+	if (!template_warning_divs()) {
2240
+			return;
2241
+	}
2125 2242
 
2126 2243
 	echo '
2127 2244
 		<hr>
2128 2245
 		<p>', $txt['ftp_setup_info'], '</p>';
2129 2246
 
2130
-	if (!empty($incontext['ftp_errors']))
2131
-		echo '
2247
+	if (!empty($incontext['ftp_errors'])) {
2248
+			echo '
2132 2249
 		<div class="error_message">
2133 2250
 			', $txt['error_ftp_no_connect'], '<br><br>
2134 2251
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2135 2252
 		</div>';
2253
+	}
2136 2254
 
2137 2255
 	echo '
2138 2256
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2201,16 +2319,16 @@  discard block
 block discarded – undo
2201 2319
 			<dd>
2202 2320
 				<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2203 2321
 
2204
-	foreach ($incontext['supported_databases'] as $key => $db)
2205
-			echo '
2322
+	foreach ($incontext['supported_databases'] as $key => $db) {
2323
+				echo '
2206 2324
 					<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2325
+	}
2207 2326
 
2208 2327
 	echo '
2209 2328
 				</select>
2210 2329
 				<div class="smalltext">', $txt['db_settings_type_info'], '</div>
2211 2330
 			</dd>';
2212
-	}
2213
-	else
2331
+	} else
2214 2332
 	{
2215 2333
 		echo '
2216 2334
 			<dd>
@@ -2378,9 +2496,10 @@  discard block
 block discarded – undo
2378 2496
 		<div class="red">', $txt['error_db_queries'], '</div>
2379 2497
 		<ul>';
2380 2498
 
2381
-		foreach ($incontext['failures'] as $line => $fail)
2382
-			echo '
2499
+		foreach ($incontext['failures'] as $line => $fail) {
2500
+					echo '
2383 2501
 			<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2502
+		}
2384 2503
 
2385 2504
 		echo '
2386 2505
 		</ul>';
@@ -2445,15 +2564,16 @@  discard block
 block discarded – undo
2445 2564
 			</dd>
2446 2565
 		</dl>';
2447 2566
 
2448
-	if ($incontext['require_db_confirm'])
2449
-		echo '
2567
+	if ($incontext['require_db_confirm']) {
2568
+			echo '
2450 2569
 		<h2>', $txt['user_settings_database'], '</h2>
2451 2570
 		<p>', $txt['user_settings_database_info'], '</p>
2452 2571
 
2453 2572
 		<div class="lefttext">
2454 2573
 			<input type="password" name="password3" size="30">
2455 2574
 		</div>';
2456
-}
2575
+	}
2576
+	}
2457 2577
 
2458 2578
 // Tell them it's done, and to delete.
2459 2579
 function template_delete_install()
@@ -2466,13 +2586,14 @@  discard block
 block discarded – undo
2466 2586
 	template_warning_divs();
2467 2587
 
2468 2588
 	// Install directory still writable?
2469
-	if ($incontext['dir_still_writable'])
2470
-		echo '
2589
+	if ($incontext['dir_still_writable']) {
2590
+			echo '
2471 2591
 		<p><em>', $txt['still_writable'], '</em></p>';
2592
+	}
2472 2593
 
2473 2594
 	// Don't show the box if it's like 99% sure it won't work :P.
2474
-	if ($incontext['probably_delete_install'])
2475
-		echo '
2595
+	if ($incontext['probably_delete_install']) {
2596
+			echo '
2476 2597
 		<label>
2477 2598
 			<input type="checkbox" id="delete_self" onclick="doTheDelete();">
2478 2599
 			<strong>', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</strong>
@@ -2488,6 +2609,7 @@  discard block
 block discarded – undo
2488 2609
 				theCheck.disabled = true;
2489 2610
 			}
2490 2611
 		</script>';
2612
+	}
2491 2613
 
2492 2614
 	echo '
2493 2615
 		<p>', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '</p>
Please login to merge, or discard this patch.