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