Completed
Branch release-2.1 (3c29ac)
by Mathias
08:54
created
other/install.php 2 patches
Spacing   +8 added lines, -10 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 		'utf8_default' => true,
63 63
 		'utf8_required' => true,
64 64
 		'alter_support' => true,
65
-		'validate_prefix' => function(&$value){
65
+		'validate_prefix' => function(&$value) {
66 66
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
67 67
 			return true;
68 68
 		},
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 		'utf8_support' => true,
80 80
 		'utf8_version' => '8.0',
81 81
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
82
-		'validate_prefix' => function(&$value){
82
+		'validate_prefix' => function(&$value) {
83 83
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
84 84
 
85 85
 			// Is it reserved?
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 	if (isset($_POST['db_user']))
742 742
 	{
743 743
 		$incontext['db']['user'] = $_POST['db_user'];
744
-		$incontext['db']['name'] =  $_POST['db_name'];
744
+		$incontext['db']['name'] = $_POST['db_name'];
745 745
 		$incontext['db']['server'] = $_POST['db_server'];
746 746
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
747 747
 
@@ -1144,7 +1144,7 @@  discard block
 block discarded – undo
1144 1144
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1145 1145
 		{
1146 1146
 			// Use the appropriate function based on the DB type
1147
-			if ($db_type == 'mysql' || $db_type =='mysqli')
1147
+			if ($db_type == 'mysql' || $db_type == 'mysqli')
1148 1148
 				$db_errorno = $db_type . '_errno';
1149 1149
 
1150 1150
 			// Error 1050: Table already exists!
@@ -1333,8 +1333,7 @@  discard block
 block discarded – undo
1333 1333
 	require_once($sourcedir . '/Subs.php');
1334 1334
 
1335 1335
 	// We need this to properly hash the password for Admin
1336
-	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1337
-		function($string){
1336
+	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1338 1337
 			global $sourcedir;
1339 1338
 			if (function_exists('mb_strtolower'))
1340 1339
 				return mb_strtolower($string, 'UTF-8');
@@ -1598,8 +1597,7 @@  discard block
 block discarded – undo
1598 1597
 	updateStats('topic');
1599 1598
 
1600 1599
 	// This function is needed to do the updateStats('subject') call.
1601
-	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1602
-		function($string){
1600
+	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1603 1601
 			global $sourcedir;
1604 1602
 			if (function_exists('mb_strtolower'))
1605 1603
 				return mb_strtolower($string, 'UTF-8');
@@ -1627,7 +1625,7 @@  discard block
 block discarded – undo
1627 1625
 	// Sanity check that they loaded earlier!
1628 1626
 	if (isset($modSettings['recycle_board']))
1629 1627
 	{
1630
-		$forum_version = $current_smf_version;  // The variable is usually defined in index.php so lets just use our variable to do it for us.
1628
+		$forum_version = $current_smf_version; // The variable is usually defined in index.php so lets just use our variable to do it for us.
1631 1629
 		scheduled_fetchSMfiles(); // Now go get those files!
1632 1630
 
1633 1631
 		// We've just installed!
@@ -1801,7 +1799,7 @@  discard block
 block discarded – undo
1801 1799
 		<title>', $txt['smf_installer'], '</title>
1802 1800
 		<link rel="stylesheet" href="Themes/default/css/index.css?alp21">
1803 1801
 		<link rel="stylesheet" href="Themes/default/css/install.css?alp21">
1804
-		', $txt['lang_rtl'] == true ? '<link rel="stylesheet" href="Themes/default/css/rtl.css?alp21">' : '' , '
1802
+		', $txt['lang_rtl'] == true ? '<link rel="stylesheet" href="Themes/default/css/rtl.css?alp21">' : '', '
1805 1803
 
1806 1804
 		<script src="Themes/default/scripts/jquery-2.1.3.min.js"></script>
1807 1805
 		<script src="Themes/default/scripts/script.js"></script>
Please login to merge, or discard this patch.
Braces   +428 added lines, -318 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
 
@@ -83,12 +84,14 @@  discard block
 block discarded – undo
83 84
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
84 85
 
85 86
 			// Is it reserved?
86
-			if ($value == 'pg_')
87
-				return $txt['error_db_prefix_reserved'];
87
+			if ($value == 'pg_') {
88
+							return $txt['error_db_prefix_reserved'];
89
+			}
88 90
 
89 91
 			// Is the prefix numeric?
90
-			if (preg_match('~^\d~', $value))
91
-				return $txt['error_db_prefix_numeric'];
92
+			if (preg_match('~^\d~', $value)) {
93
+							return $txt['error_db_prefix_numeric'];
94
+			}
92 95
 
93 96
 			return true;
94 97
 		},
@@ -135,10 +138,11 @@  discard block
 block discarded – undo
135 138
 		$incontext['skip'] = false;
136 139
 
137 140
 		// Call the step and if it returns false that means pause!
138
-		if (function_exists($step[2]) && $step[2]() === false)
139
-			break;
140
-		elseif (function_exists($step[2]))
141
-			$incontext['current_step']++;
141
+		if (function_exists($step[2]) && $step[2]() === false) {
142
+					break;
143
+		} elseif (function_exists($step[2])) {
144
+					$incontext['current_step']++;
145
+		}
142 146
 
143 147
 		// No warnings pass on.
144 148
 		$incontext['warning'] = '';
@@ -154,12 +158,14 @@  discard block
 block discarded – undo
154 158
 	global $databases, $incontext;
155 159
 
156 160
 	// Just so people using older versions of PHP aren't left in the cold.
157
-	if (!isset($_SERVER['PHP_SELF']))
158
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
161
+	if (!isset($_SERVER['PHP_SELF'])) {
162
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
163
+	}
159 164
 
160 165
 	// Turn off magic quotes runtime and enable error reporting.
161
-	if (function_exists('set_magic_quotes_runtime'))
162
-		@set_magic_quotes_runtime(0);
166
+	if (function_exists('set_magic_quotes_runtime')) {
167
+			@set_magic_quotes_runtime(0);
168
+	}
163 169
 	error_reporting(E_ALL);
164 170
 
165 171
 	// Fun.  Low PHP version...
@@ -173,21 +179,23 @@  discard block
 block discarded – undo
173 179
 	{
174 180
 		ob_start();
175 181
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
178
-		if (function_exists('session_start'))
179
-			@session_start();
180
-	}
181
-	else
182
+		if (ini_get('session.save_handler') == 'user') {
183
+					@ini_set('session.save_handler', 'files');
184
+		}
185
+		if (function_exists('session_start')) {
186
+					@session_start();
187
+		}
188
+	} else
182 189
 	{
183 190
 		ob_start('ob_gzhandler');
184 191
 
185
-		if (ini_get('session.save_handler') == 'user')
186
-			@ini_set('session.save_handler', 'files');
192
+		if (ini_get('session.save_handler') == 'user') {
193
+					@ini_set('session.save_handler', 'files');
194
+		}
187 195
 		session_start();
188 196
 
189
-		if (!headers_sent())
190
-			echo '<!DOCTYPE html>
197
+		if (!headers_sent()) {
198
+					echo '<!DOCTYPE html>
191 199
 <html>
192 200
 	<head>
193 201
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -196,6 +204,7 @@  discard block
 block discarded – undo
196 204
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
197 205
 	</body>
198 206
 </html>';
207
+		}
199 208
 		exit;
200 209
 	}
201 210
 
@@ -204,16 +213,18 @@  discard block
 block discarded – undo
204 213
 	{
205 214
 		$incontext['remote_files_available'] = false;
206 215
 		$test = @fsockopen('www.simplemachines.org', 80, $errno, $errstr, 1);
207
-		if ($test)
208
-			$incontext['remote_files_available'] = true;
216
+		if ($test) {
217
+					$incontext['remote_files_available'] = true;
218
+		}
209 219
 		@fclose($test);
210 220
 	}
211 221
 
212 222
 	// Add slashes, as long as they aren't already being added.
213
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
214
-		foreach ($_POST as $k => $v)
223
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
224
+			foreach ($_POST as $k => $v)
215 225
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
216 226
 				$_POST[$k] = addslashes($v);
227
+	}
217 228
 
218 229
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
219 230
 	if (isset($_GET['delete']))
@@ -234,8 +245,7 @@  discard block
 block discarded – undo
234 245
 			$ftp->close();
235 246
 
236 247
 			unset($_SESSION['installer_temp_ftp']);
237
-		}
238
-		else
248
+		} else
239 249
 		{
240 250
 			@unlink(__FILE__);
241 251
 
@@ -276,8 +286,9 @@  discard block
 block discarded – undo
276 286
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
277 287
 		while ($entry = $dir->read())
278 288
 		{
279
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
280
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
289
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
290
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
291
+			}
281 292
 		}
282 293
 		$dir->close();
283 294
 	}
@@ -312,10 +323,11 @@  discard block
 block discarded – undo
312 323
 	}
313 324
 
314 325
 	// Override the language file?
315
-	if (isset($_GET['lang_file']))
316
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
317
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
318
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
326
+	if (isset($_GET['lang_file'])) {
327
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
328
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
329
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
330
+	}
319 331
 
320 332
 	// Make sure it exists, if it doesn't reset it.
321 333
 	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']))
@@ -324,8 +336,9 @@  discard block
 block discarded – undo
324 336
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
325 337
 
326 338
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
327
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
328
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
339
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
340
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
341
+		}
329 342
 	}
330 343
 
331 344
 	// And now include the actual language file itself.
@@ -338,15 +351,18 @@  discard block
 block discarded – undo
338 351
 	global $db_prefix, $db_connection, $sourcedir;
339 352
 	global $smcFunc, $modSettings, $db_type, $db_name, $db_user, $db_persist;
340 353
 
341
-	if (empty($sourcedir))
342
-		$sourcedir = dirname(__FILE__) . '/Sources';
354
+	if (empty($sourcedir)) {
355
+			$sourcedir = dirname(__FILE__) . '/Sources';
356
+	}
343 357
 
344 358
 	// Need this to check whether we need the database password.
345 359
 	require(dirname(__FILE__) . '/Settings.php');
346
-	if (!defined('SMF'))
347
-		define('SMF', 1);
348
-	if (empty($smcFunc))
349
-		$smcFunc = array();
360
+	if (!defined('SMF')) {
361
+			define('SMF', 1);
362
+	}
363
+	if (empty($smcFunc)) {
364
+			$smcFunc = array();
365
+	}
350 366
 
351 367
 	$modSettings['disableQueryCheck'] = true;
352 368
 
@@ -354,8 +370,9 @@  discard block
 block discarded – undo
354 370
 	if (!$db_connection)
355 371
 	{
356 372
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
357
-		if (version_compare(PHP_VERSION, '5', '<'))
358
-			require_once($sourcedir . '/Subs-Compat.php');
373
+		if (version_compare(PHP_VERSION, '5', '<')) {
374
+					require_once($sourcedir . '/Subs-Compat.php');
375
+		}
359 376
 
360 377
 		$db_options = array('persist' => $db_persist);
361 378
 		$port = '';
@@ -366,19 +383,20 @@  discard block
 block discarded – undo
366 383
 			if ($db_type == 'mysql' || $db_type == 'mysqli')
367 384
 			{
368 385
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
369
-			}
370
-			elseif ($db_type == 'postgresql')
386
+			} elseif ($db_type == 'postgresql')
371 387
 			{
372 388
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
373 389
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
374 390
 			}
375 391
 		}
376 392
 
377
-		if (!empty($port))
378
-			$db_options['port'] = $port;
393
+		if (!empty($port)) {
394
+					$db_options['port'] = $port;
395
+		}
379 396
 
380
-		if (!$db_connection)
381
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
397
+		if (!$db_connection) {
398
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
399
+		}
382 400
 	}
383 401
 }
384 402
 
@@ -406,8 +424,9 @@  discard block
 block discarded – undo
406 424
 		// @todo REMOVE THIS!!
407 425
 		else
408 426
 		{
409
-			if (function_exists('doStep' . $_GET['step']))
410
-				call_user_func('doStep' . $_GET['step']);
427
+			if (function_exists('doStep' . $_GET['step'])) {
428
+							call_user_func('doStep' . $_GET['step']);
429
+			}
411 430
 		}
412 431
 		// Show the footer.
413 432
 		template_install_below();
@@ -425,8 +444,9 @@  discard block
 block discarded – undo
425 444
 	$incontext['sub_template'] = 'welcome_message';
426 445
 
427 446
 	// Done the submission?
428
-	if (isset($_POST['contbutt']))
429
-		return true;
447
+	if (isset($_POST['contbutt'])) {
448
+			return true;
449
+	}
430 450
 
431 451
 	// See if we think they have already installed it?
432 452
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -434,14 +454,17 @@  discard block
 block discarded – undo
434 454
 		$probably_installed = 0;
435 455
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
436 456
 		{
437
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
438
-				$probably_installed++;
439
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
440
-				$probably_installed++;
457
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
458
+							$probably_installed++;
459
+			}
460
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
461
+							$probably_installed++;
462
+			}
441 463
 		}
442 464
 
443
-		if ($probably_installed == 2)
444
-			$incontext['warning'] = $txt['error_already_installed'];
465
+		if ($probably_installed == 2) {
466
+					$incontext['warning'] = $txt['error_already_installed'];
467
+		}
445 468
 	}
446 469
 
447 470
 	// Is some database support even compiled in?
@@ -456,8 +479,7 @@  discard block
 block discarded – undo
456 479
 				$databases[$key]['supported'] = false;
457 480
 				$notFoundSQLFile = true;
458 481
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
459
-			}
460
-			else
482
+			} else
461 483
 			{
462 484
 				$db_type = $key;
463 485
 				$incontext['supported_databases'][] = $db;
@@ -466,29 +488,36 @@  discard block
 block discarded – undo
466 488
 	}
467 489
 
468 490
 	// Check the PHP version.
469
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
470
-		$error = 'error_php_too_low';
491
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
492
+			$error = 'error_php_too_low';
493
+	}
471 494
 	// Make sure we have a supported database
472
-	elseif (empty($incontext['supported_databases']))
473
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
495
+	elseif (empty($incontext['supported_databases'])) {
496
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
497
+	}
474 498
 	// How about session support?  Some crazy sysadmin remove it?
475
-	elseif (!function_exists('session_start'))
476
-		$error = 'error_session_missing';
499
+	elseif (!function_exists('session_start')) {
500
+			$error = 'error_session_missing';
501
+	}
477 502
 	// Make sure they uploaded all the files.
478
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
479
-		$error = 'error_missing_files';
503
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
504
+			$error = 'error_missing_files';
505
+	}
480 506
 	// Very simple check on the session.save_path for Windows.
481 507
 	// @todo Move this down later if they don't use database-driven sessions?
482
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
483
-		$error = 'error_session_save_path';
508
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
509
+			$error = 'error_session_save_path';
510
+	}
484 511
 
485 512
 	// Since each of the three messages would look the same, anyway...
486
-	if (isset($error))
487
-		$incontext['error'] = $txt[$error];
513
+	if (isset($error)) {
514
+			$incontext['error'] = $txt[$error];
515
+	}
488 516
 
489 517
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
490
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
491
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
518
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
519
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
520
+	}
492 521
 
493 522
 	return false;
494 523
 }
@@ -511,15 +540,18 @@  discard block
 block discarded – undo
511 540
 		'agreement.txt',
512 541
 		'Settings.php'
513 542
 	);
514
-	if (file_exists(dirname(__FILE__) . '/Settings_bak.php'))
515
-		$writable_files[] = 'Settings_bak.php';
543
+	if (file_exists(dirname(__FILE__) . '/Settings_bak.php')) {
544
+			$writable_files[] = 'Settings_bak.php';
545
+	}
516 546
 
517
-	foreach ($incontext['detected_languages'] as $lang => $temp)
518
-		$extra_files[] = 'Themes/default/languages/' . $lang;
547
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
548
+			$extra_files[] = 'Themes/default/languages/' . $lang;
549
+	}
519 550
 
520 551
 	// With mod_security installed, we could attempt to fix it with .htaccess.
521
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
522
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
552
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
553
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
554
+	}
523 555
 
524 556
 	$failed_files = array();
525 557
 
@@ -535,12 +567,14 @@  discard block
 block discarded – undo
535 567
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
536 568
 
537 569
 				// Well, 755 hopefully worked... if not, try 777.
538
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
539
-					$failed_files[] = $file;
570
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
571
+									$failed_files[] = $file;
572
+				}
540 573
 			}
541 574
 		}
542
-		foreach ($extra_files as $file)
543
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
575
+		foreach ($extra_files as $file) {
576
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
577
+		}
544 578
 	}
545 579
 	// Windows is trickier.  Let's try opening for r+...
546 580
 	else
@@ -550,30 +584,35 @@  discard block
 block discarded – undo
550 584
 		foreach ($writable_files as $file)
551 585
 		{
552 586
 			// Folders can't be opened for write... but the index.php in them can ;)
553
-			if (is_dir(dirname(__FILE__) . '/' . $file))
554
-				$file .= '/index.php';
587
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
588
+							$file .= '/index.php';
589
+			}
555 590
 
556 591
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
557 592
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
558 593
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
559 594
 
560 595
 			// Hmm, okay, try just for write in that case...
561
-			if (!is_resource($fp))
562
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
596
+			if (!is_resource($fp)) {
597
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
598
+			}
563 599
 
564
-			if (!is_resource($fp))
565
-				$failed_files[] = $file;
600
+			if (!is_resource($fp)) {
601
+							$failed_files[] = $file;
602
+			}
566 603
 
567 604
 			@fclose($fp);
568 605
 		}
569
-		foreach ($extra_files as $file)
570
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
606
+		foreach ($extra_files as $file) {
607
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
608
+		}
571 609
 	}
572 610
 
573 611
 	$failure = count($failed_files) >= 1;
574 612
 
575
-	if (!isset($_SERVER))
576
-		return !$failure;
613
+	if (!isset($_SERVER)) {
614
+			return !$failure;
615
+	}
577 616
 
578 617
 	// Put the list into context.
579 618
 	$incontext['failed_files'] = $failed_files;
@@ -621,19 +660,23 @@  discard block
 block discarded – undo
621 660
 
622 661
 		if (!isset($ftp) || $ftp->error !== false)
623 662
 		{
624
-			if (!isset($ftp))
625
-				$ftp = new ftp_connection(null);
663
+			if (!isset($ftp)) {
664
+							$ftp = new ftp_connection(null);
665
+			}
626 666
 			// Save the error so we can mess with listing...
627
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
628
-				$incontext['ftp_errors'][] = $ftp->last_message;
667
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
668
+							$incontext['ftp_errors'][] = $ftp->last_message;
669
+			}
629 670
 
630 671
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
631 672
 
632
-			if (empty($_POST['ftp_path']) && $found_path)
633
-				$_POST['ftp_path'] = $detect_path;
673
+			if (empty($_POST['ftp_path']) && $found_path) {
674
+							$_POST['ftp_path'] = $detect_path;
675
+			}
634 676
 
635
-			if (!isset($_POST['ftp_username']))
636
-				$_POST['ftp_username'] = $username;
677
+			if (!isset($_POST['ftp_username'])) {
678
+							$_POST['ftp_username'] = $username;
679
+			}
637 680
 
638 681
 			// Set the username etc, into context.
639 682
 			$incontext['ftp'] = array(
@@ -645,8 +688,7 @@  discard block
 block discarded – undo
645 688
 			);
646 689
 
647 690
 			return false;
648
-		}
649
-		else
691
+		} else
650 692
 		{
651 693
 			$_SESSION['installer_temp_ftp'] = array(
652 694
 				'server' => $_POST['ftp_server'],
@@ -660,10 +702,12 @@  discard block
 block discarded – undo
660 702
 
661 703
 			foreach ($failed_files as $file)
662 704
 			{
663
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
664
-					$ftp->chmod($file, 0755);
665
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
666
-					$ftp->chmod($file, 0777);
705
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
706
+									$ftp->chmod($file, 0755);
707
+				}
708
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
709
+									$ftp->chmod($file, 0777);
710
+				}
667 711
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
668 712
 				{
669 713
 					$failed_files_updated[] = $file;
@@ -718,15 +762,17 @@  discard block
 block discarded – undo
718 762
 
719 763
 			if (!$foundOne)
720 764
 			{
721
-				if (isset($db['default_host']))
722
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
765
+				if (isset($db['default_host'])) {
766
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
767
+				}
723 768
 				if (isset($db['default_user']))
724 769
 				{
725 770
 					$incontext['db']['user'] = ini_get($db['default_user']);
726 771
 					$incontext['db']['name'] = ini_get($db['default_user']);
727 772
 				}
728
-				if (isset($db['default_password']))
729
-					$incontext['db']['pass'] = ini_get($db['default_password']);
773
+				if (isset($db['default_password'])) {
774
+									$incontext['db']['pass'] = ini_get($db['default_password']);
775
+				}
730 776
 
731 777
 				// For simplicity and less confusion, leave the port blank by default
732 778
 				$incontext['db']['port'] = '';
@@ -745,10 +791,10 @@  discard block
 block discarded – undo
745 791
 		$incontext['db']['server'] = $_POST['db_server'];
746 792
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
747 793
 
748
-		if (!empty($_POST['db_port']))
749
-			$incontext['db']['port'] = $_POST['db_port'];
750
-	}
751
-	else
794
+		if (!empty($_POST['db_port'])) {
795
+					$incontext['db']['port'] = $_POST['db_port'];
796
+		}
797
+	} else
752 798
 	{
753 799
 		$incontext['db']['prefix'] = 'smf_';
754 800
 	}
@@ -784,10 +830,11 @@  discard block
 block discarded – undo
784 830
 		if (!empty($_POST['db_port']))
785 831
 		{
786 832
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
787
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
788
-				$vars['db_port'] = (int) $_POST['db_port'];
789
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
790
-				$vars['db_port'] = (int) $_POST['db_port'];
833
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
834
+							$vars['db_port'] = (int) $_POST['db_port'];
835
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
836
+							$vars['db_port'] = (int) $_POST['db_port'];
837
+			}
791 838
 		}
792 839
 
793 840
 		// God I hope it saved!
@@ -800,8 +847,9 @@  discard block
 block discarded – undo
800 847
 		// Make sure it works.
801 848
 		require(dirname(__FILE__) . '/Settings.php');
802 849
 
803
-		if (empty($sourcedir))
804
-			$sourcedir = dirname(__FILE__) . '/Sources';
850
+		if (empty($sourcedir)) {
851
+					$sourcedir = dirname(__FILE__) . '/Sources';
852
+		}
805 853
 
806 854
 		// Better find the database file!
807 855
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -811,18 +859,21 @@  discard block
 block discarded – undo
811 859
 		}
812 860
 
813 861
 		// Now include it for database functions!
814
-		if (!defined('SMF'))
815
-			define('SMF', 1);
862
+		if (!defined('SMF')) {
863
+					define('SMF', 1);
864
+		}
816 865
 
817 866
 		$modSettings['disableQueryCheck'] = true;
818
-		if (empty($smcFunc))
819
-			$smcFunc = array();
867
+		if (empty($smcFunc)) {
868
+					$smcFunc = array();
869
+		}
820 870
 
821 871
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
822 872
 
823 873
 		// What - running PHP4? The shame!
824
-		if (version_compare(PHP_VERSION, '5', '<'))
825
-			require_once($sourcedir . '/Subs-Compat.php');
874
+		if (version_compare(PHP_VERSION, '5', '<')) {
875
+					require_once($sourcedir . '/Subs-Compat.php');
876
+		}
826 877
 
827 878
 		// Attempt a connection.
828 879
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -910,12 +961,14 @@  discard block
 block discarded – undo
910 961
 	$incontext['page_title'] = $txt['install_settings'];
911 962
 
912 963
 	// Let's see if we got the database type correct.
913
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
914
-		$db_type = $_POST['db_type'];
964
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
965
+			$db_type = $_POST['db_type'];
966
+	}
915 967
 
916 968
 	// Else we'd better be able to get the connection.
917
-	else
918
-		load_database();
969
+	else {
970
+			load_database();
971
+	}
919 972
 
920 973
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
921 974
 
@@ -935,12 +988,14 @@  discard block
 block discarded – undo
935 988
 	// Submitting?
936 989
 	if (isset($_POST['boardurl']))
937 990
 	{
938
-		if (substr($_POST['boardurl'], -10) == '/index.php')
939
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
940
-		elseif (substr($_POST['boardurl'], -1) == '/')
941
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
942
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
943
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
991
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
992
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
993
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
994
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
995
+		}
996
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
997
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
998
+		}
944 999
 
945 1000
 		// Save these variables.
946 1001
 		$vars = array(
@@ -971,10 +1026,10 @@  discard block
 block discarded – undo
971 1026
 			{
972 1027
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
973 1028
 				return false;
974
-			}
975
-			else
976
-				// Set the character set here.
1029
+			} else {
1030
+							// Set the character set here.
977 1031
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1032
+			}
978 1033
 		}
979 1034
 
980 1035
 		// Good, skip on.
@@ -994,8 +1049,9 @@  discard block
 block discarded – undo
994 1049
 	$incontext['continue'] = 1;
995 1050
 
996 1051
 	// Already done?
997
-	if (isset($_POST['pop_done']))
998
-		return true;
1052
+	if (isset($_POST['pop_done'])) {
1053
+			return true;
1054
+	}
999 1055
 
1000 1056
 	// Reload settings.
1001 1057
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1013,8 +1069,9 @@  discard block
 block discarded – undo
1013 1069
 	$modSettings = array();
1014 1070
 	if ($result !== false)
1015 1071
 	{
1016
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1017
-			$modSettings[$row['variable']] = $row['value'];
1072
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1073
+					$modSettings[$row['variable']] = $row['value'];
1074
+		}
1018 1075
 		$smcFunc['db_free_result']($result);
1019 1076
 
1020 1077
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1027,20 +1084,22 @@  discard block
 block discarded – undo
1027 1084
 	$modSettings['disableQueryCheck'] = true;
1028 1085
 
1029 1086
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1030
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1031
-		$smcFunc['db_query']('', '
1087
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1088
+			$smcFunc['db_query']('', '
1032 1089
 			SET NAMES {string:utf8}',
1033 1090
 			array(
1034 1091
 				'db_error_skip' => true,
1035 1092
 				'utf8' => 'utf8',
1036 1093
 			)
1037 1094
 		);
1095
+	}
1038 1096
 
1039 1097
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1040
-	if (substr(__DIR__, -1) == '\\')
1041
-		$attachdir = __DIR__ . 'attachments';
1042
-	else
1043
-		$attachdir = __DIR__ . '/attachments';
1098
+	if (substr(__DIR__, -1) == '\\') {
1099
+			$attachdir = __DIR__ . 'attachments';
1100
+	} else {
1101
+			$attachdir = __DIR__ . '/attachments';
1102
+	}
1044 1103
 
1045 1104
 	$replaces = array(
1046 1105
 		'{$db_prefix}' => $db_prefix,
@@ -1057,8 +1116,9 @@  discard block
 block discarded – undo
1057 1116
 
1058 1117
 	foreach ($txt as $key => $value)
1059 1118
 	{
1060
-		if (substr($key, 0, 8) == 'default_')
1061
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1119
+		if (substr($key, 0, 8) == 'default_') {
1120
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1121
+		}
1062 1122
 	}
1063 1123
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1064 1124
 
@@ -1073,8 +1133,9 @@  discard block
 block discarded – undo
1073 1133
 
1074 1134
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1075 1135
 		{
1076
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1077
-				$engines[] = $row['Engine'];
1136
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1137
+							$engines[] = $row['Engine'];
1138
+			}
1078 1139
 		}
1079 1140
 
1080 1141
 		// Done with this now
@@ -1098,8 +1159,7 @@  discard block
 block discarded – undo
1098 1159
 			$replaces['START TRANSACTION;'] = '';
1099 1160
 			$replaces['COMMIT;'] = '';
1100 1161
 		}
1101
-	}
1102
-	else
1162
+	} else
1103 1163
 	{
1104 1164
 		$has_innodb = false;
1105 1165
 	}
@@ -1121,21 +1181,24 @@  discard block
 block discarded – undo
1121 1181
 	foreach ($sql_lines as $count => $line)
1122 1182
 	{
1123 1183
 		// No comments allowed!
1124
-		if (substr(trim($line), 0, 1) != '#')
1125
-			$current_statement .= "\n" . rtrim($line);
1184
+		if (substr(trim($line), 0, 1) != '#') {
1185
+					$current_statement .= "\n" . rtrim($line);
1186
+		}
1126 1187
 
1127 1188
 		// Is this the end of the query string?
1128
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1129
-			continue;
1189
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1190
+					continue;
1191
+		}
1130 1192
 
1131 1193
 		// Does this table already exist?  If so, don't insert more data into it!
1132 1194
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1133 1195
 		{
1134 1196
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1135
-			if (!empty($matches[0]))
1136
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1137
-			else
1138
-				$incontext['sql_results']['insert_dups']++;
1197
+			if (!empty($matches[0])) {
1198
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1199
+			} else {
1200
+							$incontext['sql_results']['insert_dups']++;
1201
+			}
1139 1202
 
1140 1203
 			$current_statement = '';
1141 1204
 			continue;
@@ -1144,8 +1207,9 @@  discard block
 block discarded – undo
1144 1207
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1145 1208
 		{
1146 1209
 			// Use the appropriate function based on the DB type
1147
-			if ($db_type == 'mysql' || $db_type =='mysqli')
1148
-				$db_errorno = $db_type . '_errno';
1210
+			if ($db_type == 'mysql' || $db_type =='mysqli') {
1211
+							$db_errorno = $db_type . '_errno';
1212
+			}
1149 1213
 
1150 1214
 			// Error 1050: Table already exists!
1151 1215
 			// @todo Needs to be made better!
@@ -1160,18 +1224,18 @@  discard block
 block discarded – undo
1160 1224
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1161 1225
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1162 1226
 			}
1163
-		}
1164
-		else
1227
+		} else
1165 1228
 		{
1166
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1167
-				$incontext['sql_results']['tables']++;
1168
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1229
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1230
+							$incontext['sql_results']['tables']++;
1231
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1169 1232
 			{
1170 1233
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1171
-				if (!empty($matches[0]))
1172
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1173
-				else
1174
-					$incontext['sql_results']['inserts']++;
1234
+				if (!empty($matches[0])) {
1235
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1236
+				} else {
1237
+									$incontext['sql_results']['inserts']++;
1238
+				}
1175 1239
 			}
1176 1240
 		}
1177 1241
 
@@ -1184,15 +1248,17 @@  discard block
 block discarded – undo
1184 1248
 	// Sort out the context for the SQL.
1185 1249
 	foreach ($incontext['sql_results'] as $key => $number)
1186 1250
 	{
1187
-		if ($number == 0)
1188
-			unset($incontext['sql_results'][$key]);
1189
-		else
1190
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1251
+		if ($number == 0) {
1252
+					unset($incontext['sql_results'][$key]);
1253
+		} else {
1254
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1255
+		}
1191 1256
 	}
1192 1257
 
1193 1258
 	// Make sure UTF will be used globally.
1194
-	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'])))
1195
-		$newSettings[] = array('global_character_set', 'UTF-8');
1259
+	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']))) {
1260
+			$newSettings[] = array('global_character_set', 'UTF-8');
1261
+	}
1196 1262
 
1197 1263
 	// Maybe we can auto-detect better cookie settings?
1198 1264
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1203,16 +1269,20 @@  discard block
 block discarded – undo
1203 1269
 		$globalCookies = false;
1204 1270
 
1205 1271
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1206
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1207
-			$globalCookies = true;
1272
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1273
+					$globalCookies = true;
1274
+		}
1208 1275
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1209
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1210
-			$localCookies = true;
1276
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1277
+					$localCookies = true;
1278
+		}
1211 1279
 
1212
-		if ($globalCookies)
1213
-			$newSettings[] = array('globalCookies', '1');
1214
-		if ($localCookies)
1215
-			$newSettings[] = array('localCookies', '1');
1280
+		if ($globalCookies) {
1281
+					$newSettings[] = array('globalCookies', '1');
1282
+		}
1283
+		if ($localCookies) {
1284
+					$newSettings[] = array('localCookies', '1');
1285
+		}
1216 1286
 	}
1217 1287
 
1218 1288
 	// Are we allowing stat collection?
@@ -1228,30 +1298,34 @@  discard block
 block discarded – undo
1228 1298
 			fwrite($fp, $out);
1229 1299
 
1230 1300
 			$return_data = '';
1231
-			while (!feof($fp))
1232
-				$return_data .= fgets($fp, 128);
1301
+			while (!feof($fp)) {
1302
+							$return_data .= fgets($fp, 128);
1303
+			}
1233 1304
 
1234 1305
 			fclose($fp);
1235 1306
 
1236 1307
 			// Get the unique site ID.
1237 1308
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1238 1309
 
1239
-			if (!empty($ID[1]))
1240
-				$newSettings[] = array('allow_sm_stats', $ID[1]);
1310
+			if (!empty($ID[1])) {
1311
+							$newSettings[] = array('allow_sm_stats', $ID[1]);
1312
+			}
1241 1313
 		}
1242 1314
 	}
1243 1315
 
1244 1316
 	// Are we enabling SSL?
1245
-	if (!empty($_POST['force_ssl']))
1246
-		$newSettings[] = array('force_ssl', 2);
1317
+	if (!empty($_POST['force_ssl'])) {
1318
+			$newSettings[] = array('force_ssl', 2);
1319
+	}
1247 1320
 
1248 1321
 	// As of PHP 5.1, setting a timezone is required.
1249 1322
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1250 1323
 	{
1251 1324
 		$server_offset = mktime(0, 0, 0, 1, 1, 1970);
1252 1325
 		$timezone_id = 'Etc/GMT' . ($server_offset > 0 ? '+' : '') . ($server_offset / 3600);
1253
-		if (date_default_timezone_set($timezone_id))
1254
-			$newSettings[] = array('default_timezone', $timezone_id);
1326
+		if (date_default_timezone_set($timezone_id)) {
1327
+					$newSettings[] = array('default_timezone', $timezone_id);
1328
+		}
1255 1329
 	}
1256 1330
 
1257 1331
 	if (!empty($newSettings))
@@ -1282,16 +1356,18 @@  discard block
 block discarded – undo
1282 1356
 	}
1283 1357
 
1284 1358
 	// MySQL specific stuff
1285
-	if (substr($db_type, 0, 5) != 'mysql')
1286
-		return false;
1359
+	if (substr($db_type, 0, 5) != 'mysql') {
1360
+			return false;
1361
+	}
1287 1362
 
1288 1363
 	// Find database user privileges.
1289 1364
 	$privs = array();
1290 1365
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1291 1366
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1292 1367
 	{
1293
-		if ($row['Privilege'] == 'Alter')
1294
-			$privs[] = $row['Privilege'];
1368
+		if ($row['Privilege'] == 'Alter') {
1369
+					$privs[] = $row['Privilege'];
1370
+		}
1295 1371
 	}
1296 1372
 	$smcFunc['db_free_result']($get_privs);
1297 1373
 
@@ -1321,8 +1397,9 @@  discard block
 block discarded – undo
1321 1397
 	$incontext['continue'] = 1;
1322 1398
 
1323 1399
 	// Skipping?
1324
-	if (!empty($_POST['skip']))
1325
-		return true;
1400
+	if (!empty($_POST['skip'])) {
1401
+			return true;
1402
+	}
1326 1403
 
1327 1404
 	// Need this to check whether we need the database password.
1328 1405
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1336,18 +1413,22 @@  discard block
 block discarded – undo
1336 1413
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1337 1414
 		function($string){
1338 1415
 			global $sourcedir;
1339
-			if (function_exists('mb_strtolower'))
1340
-				return mb_strtolower($string, 'UTF-8');
1416
+			if (function_exists('mb_strtolower')) {
1417
+							return mb_strtolower($string, 'UTF-8');
1418
+			}
1341 1419
 			require_once($sourcedir . '/Subs-Charset.php');
1342 1420
 			return utf8_strtolower($string);
1343 1421
 		};
1344 1422
 
1345
-	if (!isset($_POST['username']))
1346
-		$_POST['username'] = '';
1347
-	if (!isset($_POST['email']))
1348
-		$_POST['email'] = '';
1349
-	if (!isset($_POST['server_email']))
1350
-		$_POST['server_email'] = '';
1423
+	if (!isset($_POST['username'])) {
1424
+			$_POST['username'] = '';
1425
+	}
1426
+	if (!isset($_POST['email'])) {
1427
+			$_POST['email'] = '';
1428
+	}
1429
+	if (!isset($_POST['server_email'])) {
1430
+			$_POST['server_email'] = '';
1431
+	}
1351 1432
 
1352 1433
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1353 1434
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1366,8 +1447,9 @@  discard block
 block discarded – undo
1366 1447
 			'admin_group' => 1,
1367 1448
 		)
1368 1449
 	);
1369
-	if ($smcFunc['db_num_rows']($request) != 0)
1370
-		$incontext['skip'] = 1;
1450
+	if ($smcFunc['db_num_rows']($request) != 0) {
1451
+			$incontext['skip'] = 1;
1452
+	}
1371 1453
 	$smcFunc['db_free_result']($request);
1372 1454
 
1373 1455
 	// Trying to create an account?
@@ -1398,8 +1480,9 @@  discard block
 block discarded – undo
1398 1480
 		}
1399 1481
 
1400 1482
 		// Update the webmaster's email?
1401
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1402
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1483
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1484
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1485
+		}
1403 1486
 
1404 1487
 		// Work out whether we're going to have dodgy characters and remove them.
1405 1488
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1422,32 +1505,27 @@  discard block
 block discarded – undo
1422 1505
 			$smcFunc['db_free_result']($result);
1423 1506
 
1424 1507
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1425
-		}
1426
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1508
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1427 1509
 		{
1428 1510
 			// Try the previous step again.
1429 1511
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1430 1512
 			return false;
1431
-		}
1432
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1513
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1433 1514
 		{
1434 1515
 			// Try the previous step again.
1435 1516
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1436 1517
 			return false;
1437
-		}
1438
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1518
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1439 1519
 		{
1440 1520
 			// One step back, this time fill out a proper admin email address.
1441 1521
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1442 1522
 			return false;
1443
-		}
1444
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1523
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1445 1524
 		{
1446 1525
 			// One step back, this time fill out a proper admin email address.
1447 1526
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1448 1527
 			return false;
1449
-		}
1450
-		elseif ($_POST['username'] != '')
1528
+		} elseif ($_POST['username'] != '')
1451 1529
 		{
1452 1530
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1453 1531
 
@@ -1522,17 +1600,19 @@  discard block
 block discarded – undo
1522 1600
 	require_once($sourcedir . '/Subs-Auth.php');
1523 1601
 
1524 1602
 	// Bring a warning over.
1525
-	if (!empty($incontext['account_existed']))
1526
-		$incontext['warning'] = $incontext['account_existed'];
1603
+	if (!empty($incontext['account_existed'])) {
1604
+			$incontext['warning'] = $incontext['account_existed'];
1605
+	}
1527 1606
 
1528
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1529
-		$smcFunc['db_query']('', '
1607
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1608
+			$smcFunc['db_query']('', '
1530 1609
 			SET NAMES {string:db_character_set}',
1531 1610
 			array(
1532 1611
 				'db_character_set' => $db_character_set,
1533 1612
 				'db_error_skip' => true,
1534 1613
 			)
1535 1614
 		);
1615
+	}
1536 1616
 
1537 1617
 	// As track stats is by default enabled let's add some activity.
1538 1618
 	$smcFunc['db_insert']('ignore',
@@ -1553,14 +1633,16 @@  discard block
 block discarded – undo
1553 1633
 	// Only proceed if we can load the data.
1554 1634
 	if ($request)
1555 1635
 	{
1556
-		while ($row = $smcFunc['db_fetch_row']($request))
1557
-			$modSettings[$row[0]] = $row[1];
1636
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1637
+					$modSettings[$row[0]] = $row[1];
1638
+		}
1558 1639
 		$smcFunc['db_free_result']($request);
1559 1640
 	}
1560 1641
 
1561 1642
 	// Automatically log them in ;)
1562
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1563
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1643
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1644
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1645
+	}
1564 1646
 
1565 1647
 	$result = $smcFunc['db_query']('', '
1566 1648
 		SELECT value
@@ -1571,13 +1653,14 @@  discard block
 block discarded – undo
1571 1653
 			'db_error_skip' => true,
1572 1654
 		)
1573 1655
 	);
1574
-	if ($smcFunc['db_num_rows']($result) != 0)
1575
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1656
+	if ($smcFunc['db_num_rows']($result) != 0) {
1657
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1658
+	}
1576 1659
 	$smcFunc['db_free_result']($result);
1577 1660
 
1578
-	if (empty($db_sessions))
1579
-		$_SESSION['admin_time'] = time();
1580
-	else
1661
+	if (empty($db_sessions)) {
1662
+			$_SESSION['admin_time'] = time();
1663
+	} else
1581 1664
 	{
1582 1665
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1583 1666
 
@@ -1601,8 +1684,9 @@  discard block
 block discarded – undo
1601 1684
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1602 1685
 		function($string){
1603 1686
 			global $sourcedir;
1604
-			if (function_exists('mb_strtolower'))
1605
-				return mb_strtolower($string, 'UTF-8');
1687
+			if (function_exists('mb_strtolower')) {
1688
+							return mb_strtolower($string, 'UTF-8');
1689
+			}
1606 1690
 			require_once($sourcedir . '/Subs-Charset.php');
1607 1691
 			return utf8_strtolower($string);
1608 1692
 		};
@@ -1618,8 +1702,9 @@  discard block
 block discarded – undo
1618 1702
 		)
1619 1703
 	);
1620 1704
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1621
-	if ($smcFunc['db_num_rows']($request) > 0)
1622
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1705
+	if ($smcFunc['db_num_rows']($request) > 0) {
1706
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1707
+	}
1623 1708
 	$smcFunc['db_free_result']($request);
1624 1709
 
1625 1710
 	// Now is the perfect time to fetch the SM files.
@@ -1638,8 +1723,9 @@  discard block
 block discarded – undo
1638 1723
 
1639 1724
 	// Check if we need some stupid MySQL fix.
1640 1725
 	$server_version = $smcFunc['db_server_info']();
1641
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1642
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1726
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1727
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1728
+	}
1643 1729
 
1644 1730
 	// Some final context for the template.
1645 1731
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1659,8 +1745,9 @@  discard block
 block discarded – undo
1659 1745
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1660 1746
 
1661 1747
 	// @todo Do we just want to read the file in clean, and split it this way always?
1662
-	if (count($settingsArray) == 1)
1663
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1748
+	if (count($settingsArray) == 1) {
1749
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1750
+	}
1664 1751
 
1665 1752
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1666 1753
 	{
@@ -1675,19 +1762,22 @@  discard block
 block discarded – undo
1675 1762
 			continue;
1676 1763
 		}
1677 1764
 
1678
-		if (trim($settingsArray[$i]) == '?' . '>')
1679
-			$settingsArray[$i] = '';
1765
+		if (trim($settingsArray[$i]) == '?' . '>') {
1766
+					$settingsArray[$i] = '';
1767
+		}
1680 1768
 
1681 1769
 		// Don't trim or bother with it if it's not a variable.
1682
-		if (substr($settingsArray[$i], 0, 1) != '$')
1683
-			continue;
1770
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1771
+					continue;
1772
+		}
1684 1773
 
1685 1774
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1686 1775
 
1687
-		foreach ($vars as $var => $val)
1688
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1776
+		foreach ($vars as $var => $val) {
1777
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1689 1778
 			{
1690 1779
 				$comment = strstr($settingsArray[$i], '#');
1780
+		}
1691 1781
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1692 1782
 				unset($vars[$var]);
1693 1783
 			}
@@ -1697,36 +1787,41 @@  discard block
 block discarded – undo
1697 1787
 	if (!empty($vars))
1698 1788
 	{
1699 1789
 		$settingsArray[$i++] = '';
1700
-		foreach ($vars as $var => $val)
1701
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1790
+		foreach ($vars as $var => $val) {
1791
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1792
+		}
1702 1793
 	}
1703 1794
 
1704 1795
 	// Blank out the file - done to fix a oddity with some servers.
1705 1796
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1706
-	if (!$fp)
1707
-		return false;
1797
+	if (!$fp) {
1798
+			return false;
1799
+	}
1708 1800
 	fclose($fp);
1709 1801
 
1710 1802
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1711 1803
 
1712 1804
 	// Gotta have one of these ;)
1713
-	if (trim($settingsArray[0]) != '<?php')
1714
-		fwrite($fp, "<?php\n");
1805
+	if (trim($settingsArray[0]) != '<?php') {
1806
+			fwrite($fp, "<?php\n");
1807
+	}
1715 1808
 
1716 1809
 	$lines = count($settingsArray);
1717 1810
 	for ($i = 0; $i < $lines - 1; $i++)
1718 1811
 	{
1719 1812
 		// Don't just write a bunch of blank lines.
1720
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1721
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1813
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1814
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1815
+		}
1722 1816
 	}
1723 1817
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1724 1818
 	fclose($fp);
1725 1819
 
1726 1820
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1727 1821
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1728
-	if (function_exists('opcache_invalidate'))
1729
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1822
+	if (function_exists('opcache_invalidate')) {
1823
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1824
+	}
1730 1825
 
1731 1826
 	return true;
1732 1827
 }
@@ -1751,9 +1846,9 @@  discard block
 block discarded – undo
1751 1846
 	SecFilterScanPOST Off
1752 1847
 </IfModule>';
1753 1848
 
1754
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1755
-		return true;
1756
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1849
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1850
+			return true;
1851
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1757 1852
 	{
1758 1853
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1759 1854
 
@@ -1765,29 +1860,28 @@  discard block
 block discarded – undo
1765 1860
 				fwrite($ht_handle, $htaccess_addition);
1766 1861
 				fclose($ht_handle);
1767 1862
 				return true;
1863
+			} else {
1864
+							return false;
1768 1865
 			}
1769
-			else
1770
-				return false;
1866
+		} else {
1867
+					return true;
1771 1868
 		}
1772
-		else
1773
-			return true;
1774
-	}
1775
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1776
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1777
-	elseif (is_writable(dirname(__FILE__)))
1869
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1870
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1871
+	} elseif (is_writable(dirname(__FILE__)))
1778 1872
 	{
1779 1873
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1780 1874
 		{
1781 1875
 			fwrite($ht_handle, $htaccess_addition);
1782 1876
 			fclose($ht_handle);
1783 1877
 			return true;
1878
+		} else {
1879
+					return false;
1784 1880
 		}
1785
-		else
1881
+	} else {
1786 1882
 			return false;
1787 1883
 	}
1788
-	else
1789
-		return false;
1790
-}
1884
+	}
1791 1885
 
1792 1886
 function template_install_above()
1793 1887
 {
@@ -1825,9 +1919,10 @@  discard block
 block discarded – undo
1825 1919
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1826 1920
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1827 1921
 
1828
-		foreach ($incontext['detected_languages'] as $lang => $name)
1829
-			echo '
1922
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1923
+					echo '
1830 1924
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1925
+		}
1831 1926
 
1832 1927
 		echo '
1833 1928
 								</select>
@@ -1847,9 +1942,10 @@  discard block
 block discarded – undo
1847 1942
 						<h2>', $txt['upgrade_progress'], '</h2>
1848 1943
 						<ul>';
1849 1944
 
1850
-	foreach ($incontext['steps'] as $num => $step)
1851
-		echo '
1945
+	foreach ($incontext['steps'] as $num => $step) {
1946
+			echo '
1852 1947
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1948
+	}
1853 1949
 
1854 1950
 	echo '
1855 1951
 						</ul>
@@ -1874,20 +1970,23 @@  discard block
 block discarded – undo
1874 1970
 		echo '
1875 1971
 								<div>';
1876 1972
 
1877
-		if (!empty($incontext['continue']))
1878
-			echo '
1973
+		if (!empty($incontext['continue'])) {
1974
+					echo '
1879 1975
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1880
-		if (!empty($incontext['skip']))
1881
-			echo '
1976
+		}
1977
+		if (!empty($incontext['skip'])) {
1978
+					echo '
1882 1979
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1980
+		}
1883 1981
 		echo '
1884 1982
 								</div>';
1885 1983
 	}
1886 1984
 
1887 1985
 	// Show the closing form tag and other data only if not in the last step
1888
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1889
-		echo '
1986
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
1987
+			echo '
1890 1988
 							</form>';
1989
+	}
1891 1990
 
1892 1991
 	echo '
1893 1992
 						</div>
@@ -1922,13 +2021,15 @@  discard block
 block discarded – undo
1922 2021
 		</div>';
1923 2022
 
1924 2023
 	// Show the warnings, or not.
1925
-	if (template_warning_divs())
1926
-		echo '
2024
+	if (template_warning_divs()) {
2025
+			echo '
1927 2026
 		<h3>', $txt['install_all_lovely'], '</h3>';
2027
+	}
1928 2028
 
1929 2029
 	// Say we want the continue button!
1930
-	if (empty($incontext['error']))
1931
-		$incontext['continue'] = 1;
2030
+	if (empty($incontext['error'])) {
2031
+			$incontext['continue'] = 1;
2032
+	}
1932 2033
 
1933 2034
 	// For the latest version stuff.
1934 2035
 	echo '
@@ -1962,8 +2063,8 @@  discard block
 block discarded – undo
1962 2063
 	global $txt, $incontext;
1963 2064
 
1964 2065
 	// Errors are very serious..
1965
-	if (!empty($incontext['error']))
1966
-		echo '
2066
+	if (!empty($incontext['error'])) {
2067
+			echo '
1967 2068
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1968 2069
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1969 2070
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1971,9 +2072,10 @@  discard block
 block discarded – undo
1971 2072
 				', $incontext['error'], '
1972 2073
 			</div>
1973 2074
 		</div>';
2075
+	}
1974 2076
 	// A warning message?
1975
-	elseif (!empty($incontext['warning']))
1976
-		echo '
2077
+	elseif (!empty($incontext['warning'])) {
2078
+			echo '
1977 2079
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1978 2080
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1979 2081
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -1981,6 +2083,7 @@  discard block
 block discarded – undo
1981 2083
 				', $incontext['warning'], '
1982 2084
 			</div>
1983 2085
 		</div>';
2086
+	}
1984 2087
 
1985 2088
 	return empty($incontext['error']) && empty($incontext['warning']);
1986 2089
 }
@@ -1996,27 +2099,30 @@  discard block
 block discarded – undo
1996 2099
 			<li>', $incontext['failed_files']), '</li>
1997 2100
 		</ul>';
1998 2101
 
1999
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2000
-		echo '
2102
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2103
+			echo '
2001 2104
 		<hr>
2002 2105
 		<p>', $txt['chmod_linux_info'], '</p>
2003 2106
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2107
+	}
2004 2108
 
2005 2109
 	// This is serious!
2006
-	if (!template_warning_divs())
2007
-		return;
2110
+	if (!template_warning_divs()) {
2111
+			return;
2112
+	}
2008 2113
 
2009 2114
 	echo '
2010 2115
 		<hr>
2011 2116
 		<p>', $txt['ftp_setup_info'], '</p>';
2012 2117
 
2013
-	if (!empty($incontext['ftp_errors']))
2014
-		echo '
2118
+	if (!empty($incontext['ftp_errors'])) {
2119
+			echo '
2015 2120
 		<div class="error_message">
2016 2121
 			', $txt['error_ftp_no_connect'], '<br><br>
2017 2122
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2018 2123
 		</div>
2019 2124
 		<br>';
2125
+	}
2020 2126
 
2021 2127
 	echo '
2022 2128
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2076,17 +2182,17 @@  discard block
 block discarded – undo
2076 2182
 				<td>
2077 2183
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2078 2184
 
2079
-	foreach ($incontext['supported_databases'] as $key => $db)
2080
-			echo '
2185
+	foreach ($incontext['supported_databases'] as $key => $db) {
2186
+				echo '
2081 2187
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2188
+	}
2082 2189
 
2083 2190
 	echo '
2084 2191
 					</select>
2085 2192
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2086 2193
 				</td>
2087 2194
 			</tr>';
2088
-	}
2089
-	else
2195
+	} else
2090 2196
 	{
2091 2197
 		echo '
2092 2198
 			<tr style="display: none;">
@@ -2278,9 +2384,10 @@  discard block
 block discarded – undo
2278 2384
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2279 2385
 				<ul>';
2280 2386
 
2281
-		foreach ($incontext['failures'] as $line => $fail)
2282
-			echo '
2387
+		foreach ($incontext['failures'] as $line => $fail) {
2388
+					echo '
2283 2389
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2390
+		}
2284 2391
 
2285 2392
 		echo '
2286 2393
 				</ul>';
@@ -2341,15 +2448,16 @@  discard block
 block discarded – undo
2341 2448
 			</tr>
2342 2449
 		</table>';
2343 2450
 
2344
-	if ($incontext['require_db_confirm'])
2345
-		echo '
2451
+	if ($incontext['require_db_confirm']) {
2452
+			echo '
2346 2453
 		<h2>', $txt['user_settings_database'], '</h2>
2347 2454
 		<p>', $txt['user_settings_database_info'], '</p>
2348 2455
 
2349 2456
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2350 2457
 			<input type="password" name="password3" size="30" class="input_password" />
2351 2458
 		</div>';
2352
-}
2459
+	}
2460
+	}
2353 2461
 
2354 2462
 // Tell them it's done, and to delete.
2355 2463
 function template_delete_install()
@@ -2362,14 +2470,15 @@  discard block
 block discarded – undo
2362 2470
 	template_warning_divs();
2363 2471
 
2364 2472
 	// Install directory still writable?
2365
-	if ($incontext['dir_still_writable'])
2366
-		echo '
2473
+	if ($incontext['dir_still_writable']) {
2474
+			echo '
2367 2475
 		<em>', $txt['still_writable'], '</em><br>
2368 2476
 		<br>';
2477
+	}
2369 2478
 
2370 2479
 	// Don't show the box if it's like 99% sure it won't work :P.
2371
-	if ($incontext['probably_delete_install'])
2372
-		echo '
2480
+	if ($incontext['probably_delete_install']) {
2481
+			echo '
2373 2482
 		<div style="margin: 1ex; font-weight: bold;">
2374 2483
 			<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>
2375 2484
 		</div>
@@ -2385,6 +2494,7 @@  discard block
 block discarded – undo
2385 2494
 			}
2386 2495
 		</script>
2387 2496
 		<br>';
2497
+	}
2388 2498
 
2389 2499
 	echo '
2390 2500
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.
subscriptions.php 1 patch
Braces   +38 added lines, -28 removed lines patch added patch discarded remove patch
@@ -16,8 +16,9 @@  discard block
 block discarded – undo
16 16
 
17 17
 // Start things rolling by getting SMF alive...
18 18
 $ssi_guest_access = true;
19
-if (!file_exists(dirname(__FILE__) . '/SSI.php'))
19
+if (!file_exists(dirname(__FILE__) . '/SSI.php')) {
20 20
 	die('Cannot find SSI.php');
21
+}
21 22
 
22 23
 require_once(dirname(__FILE__) . '/SSI.php');
23 24
 require_once($sourcedir . '/ManagePaid.php');
@@ -35,20 +36,22 @@  discard block
 block discarded – undo
35 36
 }
36 37
 
37 38
 // I assume we're even active?
38
-if (empty($modSettings['paid_enabled']))
39
+if (empty($modSettings['paid_enabled'])) {
39 40
 	exit;
41
+}
40 42
 
41 43
 // If we have some custom people who find out about problems load them here.
42 44
 $notify_users = array();
43 45
 if (!empty($modSettings['paid_email_to']))
44 46
 {
45
-	foreach (explode(',', $modSettings['paid_email_to']) as $email)
46
-		$notify_users[] = array(
47
+	foreach (explode(',', $modSettings['paid_email_to']) as $email) {
48
+			$notify_users[] = array(
47 49
 			'email' => $email,
48 50
 			'name' => $txt['who_member'],
49 51
 			'id' => 0,
50 52
 		);
51
-}
53
+	}
54
+	}
52 55
 
53 56
 // We need to see whether we can find the correct payment gateway,
54 57
 // we'll going to go through all our gateway scripts and find out
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
 	}
66 69
 }
67 70
 
68
-if (empty($txnType))
71
+if (empty($txnType)) {
69 72
 	generateSubscriptionError($txt['paid_unknown_transaction_type']);
73
+}
70 74
 
71 75
 // Get the subscription and member ID amoungst others...
72 76
 @list($subscription_id, $member_id) = $gatewayClass->precheck();
@@ -76,8 +80,9 @@  discard block
 block discarded – undo
76 80
 $member_id = (int) $member_id;
77 81
 
78 82
 // This would be bad...
79
-if (empty($member_id))
83
+if (empty($member_id)) {
80 84
 	generateSubscriptionError($txt['paid_empty_member']);
85
+}
81 86
 
82 87
 // Verify the member.
83 88
 $request = $smcFunc['db_query']('', '
@@ -89,8 +94,9 @@  discard block
 block discarded – undo
89 94
 	)
90 95
 );
91 96
 // Didn't find them?
92
-if ($smcFunc['db_num_rows']($request) === 0)
97
+if ($smcFunc['db_num_rows']($request) === 0) {
93 98
 	generateSubscriptionError(sprintf($txt['paid_could_not_find_member'], $member_id));
99
+}
94 100
 $member_info = $smcFunc['db_fetch_assoc']($request);
95 101
 $smcFunc['db_free_result']($request);
96 102
 
@@ -105,8 +111,9 @@  discard block
 block discarded – undo
105 111
 );
106 112
 
107 113
 // Didn't find it?
108
-if ($smcFunc['db_num_rows']($request) === 0)
114
+if ($smcFunc['db_num_rows']($request) === 0) {
109 115
 	generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription'], $member_id, $subscription_id));
116
+}
110 117
 
111 118
 $subscription_info = $smcFunc['db_fetch_assoc']($request);
112 119
 $smcFunc['db_free_result']($request);
@@ -123,8 +130,9 @@  discard block
 block discarded – undo
123 130
 		'current_member' => $member_id,
124 131
 	)
125 132
 );
126
-if ($smcFunc['db_num_rows']($request) === 0)
133
+if ($smcFunc['db_num_rows']($request) === 0) {
127 134
 	generateSubscriptionError(sprintf($txt['paid_count_not_find_subscription_log'], $member_id, $subscription_id));
135
+}
128 136
 $subscription_info += $smcFunc['db_fetch_assoc']($request);
129 137
 $smcFunc['db_free_result']($request);
130 138
 
@@ -139,8 +147,7 @@  discard block
 block discarded – undo
139 147
 		removeSubscription($subscription_id, $member_id);
140 148
 		$subscription_act = time();
141 149
 		$status = 0;
142
-	}
143
-	else
150
+	} else
144 151
 	{
145 152
 		loadSubscriptions();
146 153
 		$subscription_act = $subscription_info['end_time'] - $context['subscriptions'][$subscription_id]['num_length'];
@@ -188,16 +195,18 @@  discard block
 block discarded – undo
188 195
 	if (!$gatewayClass->isSubscription())
189 196
 	{
190 197
 		$real_details = json_decode($subscription_info['pending_details'], true);
191
-		if (empty($real_details))
192
-			generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id));
198
+		if (empty($real_details)) {
199
+					generateSubscriptionError(sprintf($txt['paid_count_not_find_outstanding_payment'], $member_id, $subscription_id));
200
+		}
193 201
 
194 202
 		// Now we just try to find anything pending.
195 203
 		// We don't really care which it is as security happens later.
196 204
 		foreach ($real_details as $id => $detail)
197 205
 		{
198 206
 			unset($real_details[$id]);
199
-			if ($detail[3] == 'payback' && $subscription_info['payments_pending'])
200
-				$subscription_info['payments_pending']--;
207
+			if ($detail[3] == 'payback' && $subscription_info['payments_pending']) {
208
+							$subscription_info['payments_pending']--;
209
+			}
201 210
 			break;
202 211
 		}
203 212
 
@@ -223,10 +232,11 @@  discard block
 block discarded – undo
223 232
 		// This is a little harder, can we find the right duration?
224 233
 		foreach ($cost as $duration => $value)
225 234
 		{
226
-			if ($duration == 'fixed')
227
-				continue;
228
-			elseif ((float) $value == (float) $total_cost)
229
-				$found_duration = strtoupper(substr($duration, 0, 1));
235
+			if ($duration == 'fixed') {
236
+							continue;
237
+			} elseif ((float) $value == (float) $total_cost) {
238
+							$found_duration = strtoupper(substr($duration, 0, 1));
239
+			}
230 240
 		}
231 241
 
232 242
 		// If we have the duration then we're done.
@@ -235,8 +245,7 @@  discard block
 block discarded – undo
235 245
 			$notify = true;
236 246
 			addSubscription($subscription_id, $member_id, $found_duration);
237 247
 		}
238
-	}
239
-	else
248
+	} else
240 249
 	{
241 250
 		$actual_cost = $cost['fixed'];
242 251
 
@@ -268,10 +277,10 @@  discard block
 block discarded – undo
268 277
 // Maybe they're cancelling. Some subscriptions may require actively doing something, but PayPal doesn't, for example.
269 278
 elseif ($gatewayClass->isCancellation())
270 279
 {
271
-	if (method_exists($gatewayClass, 'performCancel'))
272
-		$gatewayClass->performCancel($subscription_id, $member_id, $subscription_info);
273
-}
274
-else
280
+	if (method_exists($gatewayClass, 'performCancel')) {
281
+			$gatewayClass->performCancel($subscription_id, $member_id, $subscription_info);
282
+	}
283
+	} else
275 284
 {
276 285
 	// Some other "valid" transaction such as:
277 286
 	//
@@ -308,8 +317,9 @@  discard block
 block discarded – undo
308 317
 	// Maybe we can try to give them the post data?
309 318
 	if (!empty($_POST))
310 319
 	{
311
-		foreach ($_POST as $key => $val)
312
-			$text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val);
320
+		foreach ($_POST as $key => $val) {
321
+					$text .= '<br>' . $smcFunc['htmlspecialchars']($key) . ': ' . $smcFunc['htmlspecialchars']($val);
322
+		}
313 323
 	}
314 324
 
315 325
 	// Then just log and die.
Please login to merge, or discard this patch.