Completed
Pull Request — release-2.1 (#4069)
by Jeremy
14:59 queued 05:24
created
other/upgrade.php 1 patch
Braces   +877 added lines, -643 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,9 +290,9 @@  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])) {
293
+		if (function_exists($step[2]) && $step[2]() === false) {
294
+					break;
295
+		} elseif (function_exists($step[2])) {
281 296
 			//Start each new step with this unset, so the 'normal' template is called first
282 297
 			unset($_GET['xml']);
283 298
 			$_GET['substep'] = 0;
@@ -321,17 +336,18 @@  discard block
 block discarded – undo
321 336
 		// This should not happen my dear... HELP ME DEVELOPERS!!
322 337
 		if (!empty($command_line))
323 338
 		{
324
-			if (function_exists('debug_print_backtrace'))
325
-				debug_print_backtrace();
339
+			if (function_exists('debug_print_backtrace')) {
340
+							debug_print_backtrace();
341
+			}
326 342
 
327 343
 			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.';
328 344
 			flush();
329 345
 			die();
330 346
 		}
331 347
 
332
-		if (!isset($_GET['xml']))
333
-			template_upgrade_above();
334
-		else
348
+		if (!isset($_GET['xml'])) {
349
+					template_upgrade_above();
350
+		} else
335 351
 		{
336 352
 			header('Content-Type: text/xml; charset=UTF-8');
337 353
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -353,25 +369,29 @@  discard block
 block discarded – undo
353 369
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
354 370
 
355 371
 			// Custom stuff to pass back?
356
-			if (!empty($upcontext['query_string']))
357
-				$upcontext['form_url'] .= $upcontext['query_string'];
372
+			if (!empty($upcontext['query_string'])) {
373
+							$upcontext['form_url'] .= $upcontext['query_string'];
374
+			}
358 375
 
359 376
 			// Call the appropriate subtemplate
360
-			if (is_callable('template_' . $upcontext['sub_template']))
361
-				call_user_func('template_' . $upcontext['sub_template']);
362
-			else
363
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
377
+			if (is_callable('template_' . $upcontext['sub_template'])) {
378
+							call_user_func('template_' . $upcontext['sub_template']);
379
+			} else {
380
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
381
+			}
364 382
 		}
365 383
 
366 384
 		// Was there an error?
367
-		if (!empty($upcontext['forced_error_message']))
368
-			echo $upcontext['forced_error_message'];
385
+		if (!empty($upcontext['forced_error_message'])) {
386
+					echo $upcontext['forced_error_message'];
387
+		}
369 388
 
370 389
 		// Show the footer.
371
-		if (!isset($_GET['xml']))
372
-			template_upgrade_below();
373
-		else
374
-			template_xml_below();
390
+		if (!isset($_GET['xml'])) {
391
+					template_upgrade_below();
392
+		} else {
393
+					template_xml_below();
394
+		}
375 395
 	}
376 396
 
377 397
 
@@ -383,15 +403,19 @@  discard block
 block discarded – undo
383 403
 		$seconds = intval($active % 60);
384 404
 
385 405
 		$totalTime = '';
386
-		if ($hours > 0)
387
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
388
-		if ($minutes > 0)
389
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
390
-		if ($seconds > 0)
391
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
406
+		if ($hours > 0) {
407
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
408
+		}
409
+		if ($minutes > 0) {
410
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
411
+		}
412
+		if ($seconds > 0) {
413
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
414
+		}
392 415
 
393
-		if (!empty($totalTime))
394
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
416
+		if (!empty($totalTime)) {
417
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
418
+		}
395 419
 	}
396 420
 
397 421
 	// Bang - gone!
@@ -404,8 +428,9 @@  discard block
 block discarded – undo
404 428
 	global $upgradeurl, $upcontext, $command_line;
405 429
 
406 430
 	// Command line users can't be redirected.
407
-	if ($command_line)
408
-		upgradeExit(true);
431
+	if ($command_line) {
432
+			upgradeExit(true);
433
+	}
409 434
 
410 435
 	// Are we providing the core info?
411 436
 	if ($addForm)
@@ -428,19 +453,22 @@  discard block
 block discarded – undo
428 453
 	global $modSettings, $sourcedir, $smcFunc;
429 454
 
430 455
 	// Do the non-SSI stuff...
431
-	if (function_exists('set_magic_quotes_runtime'))
432
-		@set_magic_quotes_runtime(0);
456
+	if (function_exists('set_magic_quotes_runtime')) {
457
+			@set_magic_quotes_runtime(0);
458
+	}
433 459
 
434 460
 	error_reporting(E_ALL);
435 461
 	define('SMF', 1);
436 462
 
437 463
 	// Start the session.
438
-	if (@ini_get('session.save_handler') == 'user')
439
-		@ini_set('session.save_handler', 'files');
464
+	if (@ini_get('session.save_handler') == 'user') {
465
+			@ini_set('session.save_handler', 'files');
466
+	}
440 467
 	@session_start();
441 468
 
442
-	if (empty($smcFunc))
443
-		$smcFunc = array();
469
+	if (empty($smcFunc)) {
470
+			$smcFunc = array();
471
+	}
444 472
 
445 473
 	// We need this for authentication and some upgrade code
446 474
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -452,32 +480,36 @@  discard block
 block discarded – undo
452 480
 	initialize_inputs();
453 481
 
454 482
 	// Get the database going!
455
-	if (empty($db_type) || $db_type == 'mysqli')
456
-		$db_type = 'mysql';
483
+	if (empty($db_type) || $db_type == 'mysqli') {
484
+			$db_type = 'mysql';
485
+	}
457 486
 
458 487
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
459 488
 	{
460 489
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
461 490
 
462 491
 		// Make the connection...
463
-		if (empty($db_connection))
464
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
465
-		else
466
-			// If we've returned here, ping/reconnect to be safe
492
+		if (empty($db_connection)) {
493
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
494
+		} else {
495
+					// If we've returned here, ping/reconnect to be safe
467 496
 			$smcFunc['db_ping']($db_connection);
497
+		}
468 498
 
469 499
 		// Oh dear god!!
470
-		if ($db_connection === null)
471
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
500
+		if ($db_connection === null) {
501
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
502
+		}
472 503
 
473
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
474
-			$smcFunc['db_query']('', '
504
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
505
+					$smcFunc['db_query']('', '
475 506
 			SET NAMES {string:db_character_set}',
476 507
 			array(
477 508
 				'db_error_skip' => true,
478 509
 				'db_character_set' => $db_character_set,
479 510
 			)
480 511
 		);
512
+		}
481 513
 
482 514
 		// Load the modSettings data...
483 515
 		$request = $smcFunc['db_query']('', '
@@ -488,11 +520,11 @@  discard block
 block discarded – undo
488 520
 			)
489 521
 		);
490 522
 		$modSettings = array();
491
-		while ($row = $smcFunc['db_fetch_assoc']($request))
492
-			$modSettings[$row['variable']] = $row['value'];
523
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
524
+					$modSettings[$row['variable']] = $row['value'];
525
+		}
493 526
 		$smcFunc['db_free_result']($request);
494
-	}
495
-	else
527
+	} else
496 528
 	{
497 529
 		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.');
498 530
 	}
@@ -506,9 +538,10 @@  discard block
 block discarded – undo
506 538
 		cleanRequest();
507 539
 	}
508 540
 
509
-	if (!isset($_GET['substep']))
510
-		$_GET['substep'] = 0;
511
-}
541
+	if (!isset($_GET['substep'])) {
542
+			$_GET['substep'] = 0;
543
+	}
544
+	}
512 545
 
513 546
 function initialize_inputs()
514 547
 {
@@ -538,8 +571,9 @@  discard block
 block discarded – undo
538 571
 		$dh = opendir(dirname(__FILE__));
539 572
 		while ($file = readdir($dh))
540 573
 		{
541
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
542
-				@unlink(dirname(__FILE__) . '/' . $file);
574
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
575
+							@unlink(dirname(__FILE__) . '/' . $file);
576
+			}
543 577
 		}
544 578
 		closedir($dh);
545 579
 
@@ -568,8 +602,9 @@  discard block
 block discarded – undo
568 602
 	$temp = 'upgrade_php?step';
569 603
 	while (strlen($temp) > 4)
570 604
 	{
571
-		if (isset($_GET[$temp]))
572
-			unset($_GET[$temp]);
605
+		if (isset($_GET[$temp])) {
606
+					unset($_GET[$temp]);
607
+		}
573 608
 		$temp = substr($temp, 1);
574 609
 	}
575 610
 
@@ -596,32 +631,39 @@  discard block
 block discarded – undo
596 631
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
597 632
 
598 633
 	// Need legacy scripts?
599
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
600
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
601
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
602
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
603
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
604
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
634
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
635
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
636
+	}
637
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
638
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
639
+	}
640
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
641
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
642
+	}
605 643
 
606 644
 	// We don't need "-utf8" files anymore...
607 645
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
608 646
 
609 647
 	// This needs to exist!
610
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
611
-		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>]');
612
-	else
613
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
648
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
649
+			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>]');
650
+	} else {
651
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
652
+	}
614 653
 
615
-	if (!$check)
616
-		// 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.
654
+	if (!$check) {
655
+			// 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.
617 656
 		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.');
657
+	}
618 658
 
619 659
 	// Do they meet the install requirements?
620
-	if (!php_version_check())
621
-		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.');
660
+	if (!php_version_check()) {
661
+			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.');
662
+	}
622 663
 
623
-	if (!db_version_check())
624
-		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.');
664
+	if (!db_version_check()) {
665
+			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.');
666
+	}
625 667
 
626 668
 	// Do some checks to make sure they have proper privileges
627 669
 	db_extend('packages');
@@ -636,14 +678,16 @@  discard block
 block discarded – undo
636 678
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
637 679
 
638 680
 	// Sorry... we need CREATE, ALTER and DROP
639
-	if (!$create || !$alter || !$drop)
640
-		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.');
681
+	if (!$create || !$alter || !$drop) {
682
+			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.');
683
+	}
641 684
 
642 685
 	// Do a quick version spot check.
643 686
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
644 687
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
645
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
646
-		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.');
688
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
689
+			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.');
690
+	}
647 691
 
648 692
 	// What absolutely needs to be writable?
649 693
 	$writable_files = array(
@@ -665,12 +709,13 @@  discard block
 block discarded – undo
665 709
 	quickFileWritable($custom_av_dir);
666 710
 
667 711
 	// Are we good now?
668
-	if (!is_writable($custom_av_dir))
669
-		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));
670
-	elseif ($need_settings_update)
712
+	if (!is_writable($custom_av_dir)) {
713
+			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));
714
+	} elseif ($need_settings_update)
671 715
 	{
672
-		if (!function_exists('cache_put_data'))
673
-			require_once($sourcedir . '/Load.php');
716
+		if (!function_exists('cache_put_data')) {
717
+					require_once($sourcedir . '/Load.php');
718
+		}
674 719
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
675 720
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
676 721
 	}
@@ -679,28 +724,33 @@  discard block
 block discarded – undo
679 724
 
680 725
 	// Check the cache directory.
681 726
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
682
-	if (!file_exists($cachedir_temp))
683
-		@mkdir($cachedir_temp);
684
-	if (!file_exists($cachedir_temp))
685
-		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.');
686
-
687
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
688
-		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>.');
689
-	elseif (!isset($_GET['skiplang']))
727
+	if (!file_exists($cachedir_temp)) {
728
+			@mkdir($cachedir_temp);
729
+	}
730
+	if (!file_exists($cachedir_temp)) {
731
+			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.');
732
+	}
733
+
734
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
735
+			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>.');
736
+	} elseif (!isset($_GET['skiplang']))
690 737
 	{
691 738
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
692 739
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
693 740
 
694
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
695
-			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>]');
741
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
742
+					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>]');
743
+		}
696 744
 	}
697 745
 
698
-	if (!makeFilesWritable($writable_files))
699
-		return false;
746
+	if (!makeFilesWritable($writable_files)) {
747
+			return false;
748
+	}
700 749
 
701 750
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
702
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
703
-		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.');
751
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
752
+			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.');
753
+	}
704 754
 
705 755
 	// Upgrade the agreement.
706 756
 	elseif (isset($modSettings['agreement']))
@@ -711,8 +761,8 @@  discard block
 block discarded – undo
711 761
 	}
712 762
 
713 763
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
714
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
715
-		$upcontext['warning'] = '
764
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
765
+			$upcontext['warning'] = '
716 766
 			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>
717 767
 			<ul>
718 768
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -720,10 +770,12 @@  discard block
 block discarded – undo
720 770
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
721 771
 			</ul>
722 772
 			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.';
773
+	}
723 774
 
724 775
 	// Either we're logged in or we're going to present the login.
725
-	if (checkLogin())
726
-		return true;
776
+	if (checkLogin()) {
777
+			return true;
778
+	}
727 779
 
728 780
 	$upcontext += createToken('login');
729 781
 
@@ -737,15 +789,17 @@  discard block
 block discarded – undo
737 789
 	global $smcFunc, $db_type, $support_js;
738 790
 
739 791
 	// Don't bother if the security is disabled.
740
-	if ($disable_security)
741
-		return true;
792
+	if ($disable_security) {
793
+			return true;
794
+	}
742 795
 
743 796
 	// Are we trying to login?
744 797
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
745 798
 	{
746 799
 		// If we've disabled security pick a suitable name!
747
-		if (empty($_POST['user']))
748
-			$_POST['user'] = 'Administrator';
800
+		if (empty($_POST['user'])) {
801
+					$_POST['user'] = 'Administrator';
802
+		}
749 803
 
750 804
 		// Before 2.0 these column names were different!
751 805
 		$oldDB = false;
@@ -760,16 +814,17 @@  discard block
 block discarded – undo
760 814
 					'db_error_skip' => true,
761 815
 				)
762 816
 			);
763
-			if ($smcFunc['db_num_rows']($request) != 0)
764
-				$oldDB = true;
817
+			if ($smcFunc['db_num_rows']($request) != 0) {
818
+							$oldDB = true;
819
+			}
765 820
 			$smcFunc['db_free_result']($request);
766 821
 		}
767 822
 
768 823
 		// Get what we believe to be their details.
769 824
 		if (!$disable_security)
770 825
 		{
771
-			if ($oldDB)
772
-				$request = $smcFunc['db_query']('', '
826
+			if ($oldDB) {
827
+							$request = $smcFunc['db_query']('', '
773 828
 					SELECT id_member, memberName AS member_name, passwd, id_group,
774 829
 					additionalGroups AS additional_groups, lngfile
775 830
 					FROM {db_prefix}members
@@ -779,8 +834,8 @@  discard block
 block discarded – undo
779 834
 						'db_error_skip' => true,
780 835
 					)
781 836
 				);
782
-			else
783
-				$request = $smcFunc['db_query']('', '
837
+			} else {
838
+							$request = $smcFunc['db_query']('', '
784 839
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
785 840
 					FROM {db_prefix}members
786 841
 					WHERE member_name = {string:member_name}',
@@ -789,6 +844,7 @@  discard block
 block discarded – undo
789 844
 						'db_error_skip' => true,
790 845
 					)
791 846
 				);
847
+			}
792 848
 			if ($smcFunc['db_num_rows']($request) != 0)
793 849
 			{
794 850
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -796,16 +852,17 @@  discard block
 block discarded – undo
796 852
 				$groups = explode(',', $addGroups);
797 853
 				$groups[] = $id_group;
798 854
 
799
-				foreach ($groups as $k => $v)
800
-					$groups[$k] = (int) $v;
855
+				foreach ($groups as $k => $v) {
856
+									$groups[$k] = (int) $v;
857
+				}
801 858
 
802 859
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
803 860
 
804 861
 				// We don't use "-utf8" anymore...
805 862
 				$user_language = str_ireplace('-utf8', '', $user_language);
863
+			} else {
864
+							$upcontext['username_incorrect'] = true;
806 865
 			}
807
-			else
808
-				$upcontext['username_incorrect'] = true;
809 866
 			$smcFunc['db_free_result']($request);
810 867
 		}
811 868
 		$upcontext['username'] = $_POST['user'];
@@ -815,13 +872,14 @@  discard block
 block discarded – undo
815 872
 		{
816 873
 			$upcontext['upgrade_status']['js'] = 1;
817 874
 			$support_js = 1;
875
+		} else {
876
+					$support_js = 0;
818 877
 		}
819
-		else
820
-			$support_js = 0;
821 878
 
822 879
 		// Note down the version we are coming from.
823
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
824
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
880
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
881
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
882
+		}
825 883
 
826 884
 		// Didn't get anywhere?
827 885
 		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']))
@@ -855,15 +913,15 @@  discard block
 block discarded – undo
855 913
 							'db_error_skip' => true,
856 914
 						)
857 915
 					);
858
-					if ($smcFunc['db_num_rows']($request) == 0)
859
-						return throw_error('You need to be an admin to perform an upgrade!');
916
+					if ($smcFunc['db_num_rows']($request) == 0) {
917
+											return throw_error('You need to be an admin to perform an upgrade!');
918
+					}
860 919
 					$smcFunc['db_free_result']($request);
861 920
 				}
862 921
 
863 922
 				$upcontext['user']['id'] = $id_member;
864 923
 				$upcontext['user']['name'] = $name;
865
-			}
866
-			else
924
+			} else
867 925
 			{
868 926
 				$upcontext['user']['id'] = 1;
869 927
 				$upcontext['user']['name'] = 'Administrator';
@@ -879,11 +937,11 @@  discard block
 block discarded – undo
879 937
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
880 938
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
881 939
 
882
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
883
-					$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'] . '.';
884
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
885
-					$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'] . '.';
886
-				else
940
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
941
+									$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'] . '.';
942
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
943
+									$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'] . '.';
944
+				} else
887 945
 				{
888 946
 					// Set this as the new language.
889 947
 					$upcontext['language'] = $user_language;
@@ -927,8 +985,9 @@  discard block
 block discarded – undo
927 985
 	unset($member_columns);
928 986
 
929 987
 	// If we've not submitted then we're done.
930
-	if (empty($_POST['upcont']))
931
-		return false;
988
+	if (empty($_POST['upcont'])) {
989
+			return false;
990
+	}
932 991
 
933 992
 	// Firstly, if they're enabling SM stat collection just do it.
934 993
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -945,16 +1004,17 @@  discard block
 block discarded – undo
945 1004
 			fwrite($fp, $out);
946 1005
 
947 1006
 			$return_data = '';
948
-			while (!feof($fp))
949
-				$return_data .= fgets($fp, 128);
1007
+			while (!feof($fp)) {
1008
+							$return_data .= fgets($fp, 128);
1009
+			}
950 1010
 
951 1011
 			fclose($fp);
952 1012
 
953 1013
 			// Get the unique site ID.
954 1014
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
955 1015
 
956
-			if (!empty($ID[1]))
957
-				$smcFunc['db_insert']('replace',
1016
+			if (!empty($ID[1])) {
1017
+							$smcFunc['db_insert']('replace',
958 1018
 					$db_prefix . 'settings',
959 1019
 					array('variable' => 'string', 'value' => 'string'),
960 1020
 					array(
@@ -963,11 +1023,12 @@  discard block
 block discarded – undo
963 1023
 					),
964 1024
 					array('variable')
965 1025
 				);
1026
+			}
966 1027
 		}
967 1028
 	}
968 1029
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
969
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
970
-		$smcFunc['db_query']('', '
1030
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1031
+			$smcFunc['db_query']('', '
971 1032
 			DELETE FROM {db_prefix}settings
972 1033
 			WHERE variable = {string:enable_sm_stats}',
973 1034
 			array(
@@ -975,6 +1036,7 @@  discard block
 block discarded – undo
975 1036
 				'db_error_skip' => true,
976 1037
 			)
977 1038
 		);
1039
+	}
978 1040
 
979 1041
 	// Deleting old karma stuff?
980 1042
 	if (!empty($_POST['delete_karma']))
@@ -989,20 +1051,22 @@  discard block
 block discarded – undo
989 1051
 		);
990 1052
 
991 1053
 		// Cleaning up old karma member settings.
992
-		if ($upcontext['karma_installed']['good'])
993
-			$smcFunc['db_query']('', '
1054
+		if ($upcontext['karma_installed']['good']) {
1055
+					$smcFunc['db_query']('', '
994 1056
 				ALTER TABLE {db_prefix}members
995 1057
 				DROP karma_good',
996 1058
 				array()
997 1059
 			);
1060
+		}
998 1061
 
999 1062
 		// Does karma bad was enable?
1000
-		if ($upcontext['karma_installed']['bad'])
1001
-			$smcFunc['db_query']('', '
1063
+		if ($upcontext['karma_installed']['bad']) {
1064
+					$smcFunc['db_query']('', '
1002 1065
 				ALTER TABLE {db_prefix}members
1003 1066
 				DROP karma_bad',
1004 1067
 				array()
1005 1068
 			);
1069
+		}
1006 1070
 
1007 1071
 		// Cleaning up old karma permissions.
1008 1072
 		$smcFunc['db_query']('', '
@@ -1015,26 +1079,29 @@  discard block
 block discarded – undo
1015 1079
 	}
1016 1080
 
1017 1081
 	// Emptying the error log?
1018
-	if (!empty($_POST['empty_error']))
1019
-		$smcFunc['db_query']('truncate_table', '
1082
+	if (!empty($_POST['empty_error'])) {
1083
+			$smcFunc['db_query']('truncate_table', '
1020 1084
 			TRUNCATE {db_prefix}log_errors',
1021 1085
 			array(
1022 1086
 			)
1023 1087
 		);
1088
+	}
1024 1089
 
1025 1090
 	$changes = array();
1026 1091
 
1027 1092
 	// Add proxy settings.
1028
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1029
-		$changes += array(
1093
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1094
+			$changes += array(
1030 1095
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1031 1096
 			'image_proxy_maxsize' => 5190,
1032 1097
 			'image_proxy_enabled' => 0,
1033 1098
 		);
1099
+	}
1034 1100
 
1035 1101
 	// If we're overriding the language follow it through.
1036
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1037
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1102
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1103
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1104
+	}
1038 1105
 
1039 1106
 	if (!empty($_POST['maint']))
1040 1107
 	{
@@ -1046,30 +1113,34 @@  discard block
 block discarded – undo
1046 1113
 		{
1047 1114
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1048 1115
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1049
-		}
1050
-		else
1116
+		} else
1051 1117
 		{
1052 1118
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1053 1119
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1054 1120
 		}
1055 1121
 	}
1056 1122
 
1057
-	if ($command_line)
1058
-		echo ' * Updating Settings.php...';
1123
+	if ($command_line) {
1124
+			echo ' * Updating Settings.php...';
1125
+	}
1059 1126
 
1060 1127
 	// Fix some old paths.
1061
-	if (substr($boarddir, 0, 1) == '.')
1062
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1128
+	if (substr($boarddir, 0, 1) == '.') {
1129
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1130
+	}
1063 1131
 
1064
-	if (substr($sourcedir, 0, 1) == '.')
1065
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1132
+	if (substr($sourcedir, 0, 1) == '.') {
1133
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1134
+	}
1066 1135
 
1067
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1068
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1136
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1137
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1138
+	}
1069 1139
 
1070 1140
 	// Not had the database type added before?
1071
-	if (empty($db_type))
1072
-		$changes['db_type'] = 'mysql';
1141
+	if (empty($db_type)) {
1142
+			$changes['db_type'] = 'mysql';
1143
+	}
1073 1144
 
1074 1145
 	// If they have a "host:port" setup for the host, split that into separate values
1075 1146
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1080,32 +1151,36 @@  discard block
 block discarded – undo
1080 1151
 		$changes['db_server'] = '\'' . $db_server . '\'';
1081 1152
 
1082 1153
 		// Only set this if we're not using the default port
1083
-		if ($db_port != ini_get('mysqli.default_port'))
1084
-			$changes['db_port'] = (int) $db_port;
1085
-	}
1086
-	elseif (!empty($db_port))
1154
+		if ($db_port != ini_get('mysqli.default_port')) {
1155
+					$changes['db_port'] = (int) $db_port;
1156
+		}
1157
+	} elseif (!empty($db_port))
1087 1158
 	{
1088 1159
 		// If db_port is set and is the same as the default, set it to ''
1089 1160
 		if ($db_type == 'mysql')
1090 1161
 		{
1091
-			if ($db_port == ini_get('mysqli.default_port'))
1092
-				$changes['db_port'] = '\'\'';
1093
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1094
-				$changes['db_port'] = '\'\'';
1162
+			if ($db_port == ini_get('mysqli.default_port')) {
1163
+							$changes['db_port'] = '\'\'';
1164
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1165
+							$changes['db_port'] = '\'\'';
1166
+			}
1095 1167
 		}
1096 1168
 	}
1097 1169
 
1098 1170
 	// Maybe we haven't had this option yet?
1099
-	if (empty($packagesdir))
1100
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1171
+	if (empty($packagesdir)) {
1172
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1173
+	}
1101 1174
 
1102 1175
 	// Add support for $tasksdir var.
1103
-	if (empty($tasksdir))
1104
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1176
+	if (empty($tasksdir)) {
1177
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1178
+	}
1105 1179
 
1106 1180
 	// Make sure we fix the language as well.
1107
-	if (stristr($language, '-utf8'))
1108
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1181
+	if (stristr($language, '-utf8')) {
1182
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1183
+	}
1109 1184
 
1110 1185
 	// @todo Maybe change the cookie name if going to 1.1, too?
1111 1186
 
@@ -1113,8 +1188,9 @@  discard block
 block discarded – undo
1113 1188
 	require_once($sourcedir . '/Subs-Admin.php');
1114 1189
 	updateSettingsFile($changes);
1115 1190
 
1116
-	if ($command_line)
1117
-		echo ' Successful.' . "\n";
1191
+	if ($command_line) {
1192
+			echo ' Successful.' . "\n";
1193
+	}
1118 1194
 
1119 1195
 	// Are we doing debug?
1120 1196
 	if (isset($_POST['debug']))
@@ -1124,8 +1200,9 @@  discard block
 block discarded – undo
1124 1200
 	}
1125 1201
 
1126 1202
 	// If we're not backing up then jump one.
1127
-	if (empty($_POST['backup']))
1128
-		$upcontext['current_step']++;
1203
+	if (empty($_POST['backup'])) {
1204
+			$upcontext['current_step']++;
1205
+	}
1129 1206
 
1130 1207
 	// If we've got here then let's proceed to the next step!
1131 1208
 	return true;
@@ -1140,8 +1217,9 @@  discard block
 block discarded – undo
1140 1217
 	$upcontext['page_title'] = 'Backup Database';
1141 1218
 
1142 1219
 	// Done it already - js wise?
1143
-	if (!empty($_POST['backup_done']))
1144
-		return true;
1220
+	if (!empty($_POST['backup_done'])) {
1221
+			return true;
1222
+	}
1145 1223
 
1146 1224
 	// Some useful stuff here.
1147 1225
 	db_extend();
@@ -1155,9 +1233,10 @@  discard block
 block discarded – undo
1155 1233
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1156 1234
 
1157 1235
 	$table_names = array();
1158
-	foreach ($tables as $table)
1159
-		if (substr($table, 0, 7) !== 'backup_')
1236
+	foreach ($tables as $table) {
1237
+			if (substr($table, 0, 7) !== 'backup_')
1160 1238
 			$table_names[] = $table;
1239
+	}
1161 1240
 
1162 1241
 	$upcontext['table_count'] = count($table_names);
1163 1242
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1167,12 +1246,14 @@  discard block
 block discarded – undo
1167 1246
 	$file_steps = $upcontext['table_count'];
1168 1247
 
1169 1248
 	// What ones have we already done?
1170
-	foreach ($table_names as $id => $table)
1171
-		if ($id < $_GET['substep'])
1249
+	foreach ($table_names as $id => $table) {
1250
+			if ($id < $_GET['substep'])
1172 1251
 			$upcontext['previous_tables'][] = $table;
1252
+	}
1173 1253
 
1174
-	if ($command_line)
1175
-		echo 'Backing Up Tables.';
1254
+	if ($command_line) {
1255
+			echo 'Backing Up Tables.';
1256
+	}
1176 1257
 
1177 1258
 	// If we don't support javascript we backup here.
1178 1259
 	if (!$support_js || isset($_GET['xml']))
@@ -1191,8 +1272,9 @@  discard block
 block discarded – undo
1191 1272
 			backupTable($table_names[$substep]);
1192 1273
 
1193 1274
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1194
-			if (isset($_GET['xml']))
1195
-				return upgradeExit();
1275
+			if (isset($_GET['xml'])) {
1276
+							return upgradeExit();
1277
+			}
1196 1278
 		}
1197 1279
 
1198 1280
 		if ($command_line)
@@ -1225,9 +1307,10 @@  discard block
 block discarded – undo
1225 1307
 
1226 1308
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1227 1309
 
1228
-	if ($command_line)
1229
-		echo ' done.';
1230
-}
1310
+	if ($command_line) {
1311
+			echo ' done.';
1312
+	}
1313
+	}
1231 1314
 
1232 1315
 // Step 2: Everything.
1233 1316
 function DatabaseChanges()
@@ -1236,8 +1319,9 @@  discard block
 block discarded – undo
1236 1319
 	global $upcontext, $support_js, $db_type;
1237 1320
 
1238 1321
 	// Have we just completed this?
1239
-	if (!empty($_POST['database_done']))
1240
-		return true;
1322
+	if (!empty($_POST['database_done'])) {
1323
+			return true;
1324
+	}
1241 1325
 
1242 1326
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1243 1327
 	$upcontext['page_title'] = 'Database Changes';
@@ -1252,15 +1336,16 @@  discard block
 block discarded – undo
1252 1336
 	);
1253 1337
 
1254 1338
 	// How many files are there in total?
1255
-	if (isset($_GET['filecount']))
1256
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1257
-	else
1339
+	if (isset($_GET['filecount'])) {
1340
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1341
+	} else
1258 1342
 	{
1259 1343
 		$upcontext['file_count'] = 0;
1260 1344
 		foreach ($files as $file)
1261 1345
 		{
1262
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1263
-				$upcontext['file_count']++;
1346
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1347
+							$upcontext['file_count']++;
1348
+			}
1264 1349
 		}
1265 1350
 	}
1266 1351
 
@@ -1270,9 +1355,9 @@  discard block
 block discarded – undo
1270 1355
 	$upcontext['cur_file_num'] = 0;
1271 1356
 	foreach ($files as $file)
1272 1357
 	{
1273
-		if ($did_not_do)
1274
-			$did_not_do--;
1275
-		else
1358
+		if ($did_not_do) {
1359
+					$did_not_do--;
1360
+		} else
1276 1361
 		{
1277 1362
 			$upcontext['cur_file_num']++;
1278 1363
 			$upcontext['cur_file_name'] = $file[0];
@@ -1299,12 +1384,13 @@  discard block
 block discarded – undo
1299 1384
 					// Flag to move on to the next.
1300 1385
 					$upcontext['completed_step'] = true;
1301 1386
 					// Did we complete the whole file?
1302
-					if ($nextFile)
1303
-						$upcontext['current_debug_item_num'] = -1;
1387
+					if ($nextFile) {
1388
+											$upcontext['current_debug_item_num'] = -1;
1389
+					}
1304 1390
 					return upgradeExit();
1391
+				} elseif ($support_js) {
1392
+									break;
1305 1393
 				}
1306
-				elseif ($support_js)
1307
-					break;
1308 1394
 			}
1309 1395
 			// Set the progress bar to be right as if we had - even if we hadn't...
1310 1396
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1329,8 +1415,9 @@  discard block
 block discarded – undo
1329 1415
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1330 1416
 
1331 1417
 	// Now it's nice to have some of the basic SMF source files.
1332
-	if (!isset($_GET['ssi']) && !$command_line)
1333
-		redirectLocation('&ssi=1');
1418
+	if (!isset($_GET['ssi']) && !$command_line) {
1419
+			redirectLocation('&ssi=1');
1420
+	}
1334 1421
 
1335 1422
 	$upcontext['sub_template'] = 'upgrade_complete';
1336 1423
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1346,14 +1433,16 @@  discard block
 block discarded – undo
1346 1433
 	// Are we in maintenance mode?
1347 1434
 	if (isset($upcontext['user']['main']))
1348 1435
 	{
1349
-		if ($command_line)
1350
-			echo ' * ';
1436
+		if ($command_line) {
1437
+					echo ' * ';
1438
+		}
1351 1439
 		$upcontext['removed_maintenance'] = true;
1352 1440
 		$changes['maintenance'] = $upcontext['user']['main'];
1353 1441
 	}
1354 1442
 	// Otherwise if somehow we are in 2 let's go to 1.
1355
-	elseif (!empty($maintenance) && $maintenance == 2)
1356
-		$changes['maintenance'] = 1;
1443
+	elseif (!empty($maintenance) && $maintenance == 2) {
1444
+			$changes['maintenance'] = 1;
1445
+	}
1357 1446
 
1358 1447
 	// Wipe this out...
1359 1448
 	$upcontext['user'] = array();
@@ -1368,9 +1457,9 @@  discard block
 block discarded – undo
1368 1457
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1369 1458
 
1370 1459
 	// Now is the perfect time to fetch the SM files.
1371
-	if ($command_line)
1372
-		cli_scheduled_fetchSMfiles();
1373
-	else
1460
+	if ($command_line) {
1461
+			cli_scheduled_fetchSMfiles();
1462
+	} else
1374 1463
 	{
1375 1464
 		require_once($sourcedir . '/ScheduledTasks.php');
1376 1465
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1378,8 +1467,9 @@  discard block
 block discarded – undo
1378 1467
 	}
1379 1468
 
1380 1469
 	// Log what we've done.
1381
-	if (empty($user_info['id']))
1382
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1470
+	if (empty($user_info['id'])) {
1471
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1472
+	}
1383 1473
 
1384 1474
 	// Log the action manually, so CLI still works.
1385 1475
 	$smcFunc['db_insert']('',
@@ -1398,8 +1488,9 @@  discard block
 block discarded – undo
1398 1488
 
1399 1489
 	// Save the current database version.
1400 1490
 	$server_version = $smcFunc['db_server_info']();
1401
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1402
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1491
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1492
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1493
+	}
1403 1494
 
1404 1495
 	if ($command_line)
1405 1496
 	{
@@ -1411,8 +1502,9 @@  discard block
 block discarded – undo
1411 1502
 
1412 1503
 	// Make sure it says we're done.
1413 1504
 	$upcontext['overall_percent'] = 100;
1414
-	if (isset($upcontext['step_progress']))
1415
-		unset($upcontext['step_progress']);
1505
+	if (isset($upcontext['step_progress'])) {
1506
+			unset($upcontext['step_progress']);
1507
+	}
1416 1508
 
1417 1509
 	$_GET['substep'] = 0;
1418 1510
 	return false;
@@ -1423,8 +1515,9 @@  discard block
 block discarded – undo
1423 1515
 {
1424 1516
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1425 1517
 
1426
-	if (empty($modSettings['time_format']))
1427
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1518
+	if (empty($modSettings['time_format'])) {
1519
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1520
+	}
1428 1521
 
1429 1522
 	// What files do we want to get
1430 1523
 	$request = $smcFunc['db_query']('', '
@@ -1458,8 +1551,9 @@  discard block
 block discarded – undo
1458 1551
 		$file_data = fetch_web_data($url);
1459 1552
 
1460 1553
 		// If we got an error - give up - the site might be down.
1461
-		if ($file_data === false)
1462
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1554
+		if ($file_data === false) {
1555
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1556
+		}
1463 1557
 
1464 1558
 		// Save the file to the database.
1465 1559
 		$smcFunc['db_query']('substring', '
@@ -1501,8 +1595,9 @@  discard block
 block discarded – undo
1501 1595
 	$themeData = array();
1502 1596
 	foreach ($values as $variable => $value)
1503 1597
 	{
1504
-		if (!isset($value) || $value === null)
1505
-			$value = 0;
1598
+		if (!isset($value) || $value === null) {
1599
+					$value = 0;
1600
+		}
1506 1601
 
1507 1602
 		$themeData[] = array(0, 1, $variable, $value);
1508 1603
 	}
@@ -1531,8 +1626,9 @@  discard block
 block discarded – undo
1531 1626
 
1532 1627
 	foreach ($values as $variable => $value)
1533 1628
 	{
1534
-		if (empty($modSettings[$value[0]]))
1535
-			continue;
1629
+		if (empty($modSettings[$value[0]])) {
1630
+					continue;
1631
+		}
1536 1632
 
1537 1633
 		$smcFunc['db_query']('', '
1538 1634
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1618,19 +1714,21 @@  discard block
 block discarded – undo
1618 1714
 	set_error_handler(
1619 1715
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1620 1716
 		{
1621
-			if ($support_js)
1622
-				return true;
1623
-			else
1624
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1717
+			if ($support_js) {
1718
+							return true;
1719
+			} else {
1720
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1721
+			}
1625 1722
 		}
1626 1723
 	);
1627 1724
 
1628 1725
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1629 1726
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1630
-	if ($db_type == 'mysql')
1631
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1632
-	else
1633
-		$db_collation = '';
1727
+	if ($db_type == 'mysql') {
1728
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1729
+	} else {
1730
+			$db_collation = '';
1731
+	}
1634 1732
 
1635 1733
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1636 1734
 
@@ -1642,8 +1740,9 @@  discard block
 block discarded – undo
1642 1740
 	$last_step = '';
1643 1741
 
1644 1742
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1645
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1646
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1743
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1744
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1745
+	}
1647 1746
 
1648 1747
 	// Count the total number of steps within this file - for progress.
1649 1748
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1663,15 +1762,18 @@  discard block
 block discarded – undo
1663 1762
 		$do_current = $substep >= $_GET['substep'];
1664 1763
 
1665 1764
 		// Get rid of any comments in the beginning of the line...
1666
-		if (substr(trim($line), 0, 2) === '/*')
1667
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1765
+		if (substr(trim($line), 0, 2) === '/*') {
1766
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1767
+		}
1668 1768
 
1669 1769
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1670
-		if ($is_debug && !$support_js && $command_line)
1671
-			flush();
1770
+		if ($is_debug && !$support_js && $command_line) {
1771
+					flush();
1772
+		}
1672 1773
 
1673
-		if (trim($line) === '')
1674
-			continue;
1774
+		if (trim($line) === '') {
1775
+					continue;
1776
+		}
1675 1777
 
1676 1778
 		if (trim(substr($line, 0, 3)) === '---')
1677 1779
 		{
@@ -1681,8 +1783,9 @@  discard block
 block discarded – undo
1681 1783
 			if (trim($current_data) != '' && $type !== '}')
1682 1784
 			{
1683 1785
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1684
-				if ($command_line)
1685
-					echo $upcontext['error_message'];
1786
+				if ($command_line) {
1787
+									echo $upcontext['error_message'];
1788
+				}
1686 1789
 			}
1687 1790
 
1688 1791
 			if ($type == ' ')
@@ -1700,17 +1803,18 @@  discard block
 block discarded – undo
1700 1803
 				if ($do_current)
1701 1804
 				{
1702 1805
 					$upcontext['actioned_items'][] = $last_step;
1703
-					if ($command_line)
1704
-						echo ' * ';
1806
+					if ($command_line) {
1807
+											echo ' * ';
1808
+					}
1705 1809
 				}
1706
-			}
1707
-			elseif ($type == '#')
1810
+			} elseif ($type == '#')
1708 1811
 			{
1709 1812
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1710 1813
 
1711 1814
 				$upcontext['current_debug_item_num']++;
1712
-				if (trim($line) != '---#')
1713
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1815
+				if (trim($line) != '---#') {
1816
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1817
+				}
1714 1818
 
1715 1819
 				// Have we already done something?
1716 1820
 				if (isset($_GET['xml']) && $done_something)
@@ -1721,34 +1825,36 @@  discard block
 block discarded – undo
1721 1825
 
1722 1826
 				if ($do_current)
1723 1827
 				{
1724
-					if (trim($line) == '---#' && $command_line)
1725
-						echo ' done.', $endl;
1726
-					elseif ($command_line)
1727
-						echo ' +++ ', rtrim(substr($line, 4));
1728
-					elseif (trim($line) != '---#')
1828
+					if (trim($line) == '---#' && $command_line) {
1829
+											echo ' done.', $endl;
1830
+					} elseif ($command_line) {
1831
+											echo ' +++ ', rtrim(substr($line, 4));
1832
+					} elseif (trim($line) != '---#')
1729 1833
 					{
1730
-						if ($is_debug)
1731
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1834
+						if ($is_debug) {
1835
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1836
+						}
1732 1837
 					}
1733 1838
 				}
1734 1839
 
1735 1840
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1736 1841
 				{
1737
-					if ($command_line)
1738
-						echo ' * ';
1739
-					else
1740
-						$upcontext['actioned_items'][] = $last_step;
1842
+					if ($command_line) {
1843
+											echo ' * ';
1844
+					} else {
1845
+											$upcontext['actioned_items'][] = $last_step;
1846
+					}
1741 1847
 				}
1742 1848
 
1743 1849
 				// Small step - only if we're actually doing stuff.
1744
-				if ($do_current)
1745
-					nextSubstep(++$substep);
1746
-				else
1747
-					$substep++;
1748
-			}
1749
-			elseif ($type == '{')
1750
-				$current_type = 'code';
1751
-			elseif ($type == '}')
1850
+				if ($do_current) {
1851
+									nextSubstep(++$substep);
1852
+				} else {
1853
+									$substep++;
1854
+				}
1855
+			} elseif ($type == '{') {
1856
+							$current_type = 'code';
1857
+			} elseif ($type == '}')
1752 1858
 			{
1753 1859
 				$current_type = 'sql';
1754 1860
 
@@ -1761,8 +1867,9 @@  discard block
 block discarded – undo
1761 1867
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1762 1868
 				{
1763 1869
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1764
-					if ($command_line)
1765
-						echo $upcontext['error_message'];
1870
+					if ($command_line) {
1871
+											echo $upcontext['error_message'];
1872
+					}
1766 1873
 				}
1767 1874
 
1768 1875
 				// Done with code!
@@ -1842,8 +1949,9 @@  discard block
 block discarded – undo
1842 1949
 	$db_unbuffered = false;
1843 1950
 
1844 1951
 	// Failure?!
1845
-	if ($result !== false)
1846
-		return $result;
1952
+	if ($result !== false) {
1953
+			return $result;
1954
+	}
1847 1955
 
1848 1956
 	$db_error_message = $smcFunc['db_error']($db_connection);
1849 1957
 	// If MySQL we do something more clever.
@@ -1871,54 +1979,61 @@  discard block
 block discarded – undo
1871 1979
 			{
1872 1980
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1873 1981
 				$result = mysqli_query($db_connection, $string);
1874
-				if ($result !== false)
1875
-					return $result;
1982
+				if ($result !== false) {
1983
+									return $result;
1984
+				}
1876 1985
 			}
1877
-		}
1878
-		elseif ($mysqli_errno == 2013)
1986
+		} elseif ($mysqli_errno == 2013)
1879 1987
 		{
1880 1988
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1881 1989
 			mysqli_select_db($db_connection, $db_name);
1882 1990
 			if ($db_connection)
1883 1991
 			{
1884 1992
 				$result = mysqli_query($db_connection, $string);
1885
-				if ($result !== false)
1886
-					return $result;
1993
+				if ($result !== false) {
1994
+									return $result;
1995
+				}
1887 1996
 			}
1888 1997
 		}
1889 1998
 		// Duplicate column name... should be okay ;).
1890
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1891
-			return false;
1999
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2000
+					return false;
2001
+		}
1892 2002
 		// Duplicate insert... make sure it's the proper type of query ;).
1893
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1894
-			return false;
2003
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2004
+					return false;
2005
+		}
1895 2006
 		// Creating an index on a non-existent column.
1896
-		elseif ($mysqli_errno == 1072)
1897
-			return false;
1898
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1899
-			return false;
2007
+		elseif ($mysqli_errno == 1072) {
2008
+					return false;
2009
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2010
+					return false;
2011
+		}
1900 2012
 	}
1901 2013
 	// If a table already exists don't go potty.
1902 2014
 	else
1903 2015
 	{
1904 2016
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1905 2017
 		{
1906
-			if (strpos($db_error_message, 'exist') !== false)
1907
-				return true;
1908
-		}
1909
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2018
+			if (strpos($db_error_message, 'exist') !== false) {
2019
+							return true;
2020
+			}
2021
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1910 2022
 		{
1911
-			if (strpos($db_error_message, 'duplicate') !== false)
1912
-				return true;
2023
+			if (strpos($db_error_message, 'duplicate') !== false) {
2024
+							return true;
2025
+			}
1913 2026
 		}
1914 2027
 	}
1915 2028
 
1916 2029
 	// Get the query string so we pass everything.
1917 2030
 	$query_string = '';
1918
-	foreach ($_GET as $k => $v)
1919
-		$query_string .= ';' . $k . '=' . $v;
1920
-	if (strlen($query_string) != 0)
1921
-		$query_string = '?' . substr($query_string, 1);
2031
+	foreach ($_GET as $k => $v) {
2032
+			$query_string .= ';' . $k . '=' . $v;
2033
+	}
2034
+	if (strlen($query_string) != 0) {
2035
+			$query_string = '?' . substr($query_string, 1);
2036
+	}
1922 2037
 
1923 2038
 	if ($command_line)
1924 2039
 	{
@@ -1973,16 +2088,18 @@  discard block
 block discarded – undo
1973 2088
 			{
1974 2089
 				$found |= 1;
1975 2090
 				// Do some checks on the data if we have it set.
1976
-				if (isset($change['col_type']))
1977
-					$found &= $change['col_type'] === $column['type'];
1978
-				if (isset($change['null_allowed']))
1979
-					$found &= $column['null'] == $change['null_allowed'];
1980
-				if (isset($change['default']))
1981
-					$found &= $change['default'] === $column['default'];
2091
+				if (isset($change['col_type'])) {
2092
+									$found &= $change['col_type'] === $column['type'];
2093
+				}
2094
+				if (isset($change['null_allowed'])) {
2095
+									$found &= $column['null'] == $change['null_allowed'];
2096
+				}
2097
+				if (isset($change['default'])) {
2098
+									$found &= $change['default'] === $column['default'];
2099
+				}
1982 2100
 			}
1983 2101
 		}
1984
-	}
1985
-	elseif ($change['type'] === 'index')
2102
+	} elseif ($change['type'] === 'index')
1986 2103
 	{
1987 2104
 		$request = upgrade_query('
1988 2105
 			SHOW INDEX
@@ -1991,9 +2108,10 @@  discard block
 block discarded – undo
1991 2108
 		{
1992 2109
 			$cur_index = array();
1993 2110
 
1994
-			while ($row = $smcFunc['db_fetch_assoc']($request))
1995
-				if ($row['Key_name'] === $change['name'])
2111
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2112
+							if ($row['Key_name'] === $change['name'])
1996 2113
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2114
+			}
1997 2115
 
1998 2116
 			ksort($cur_index, SORT_NUMERIC);
1999 2117
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2003,14 +2121,17 @@  discard block
 block discarded – undo
2003 2121
 	}
2004 2122
 
2005 2123
 	// If we're trying to add and it's added, we're done.
2006
-	if ($found && in_array($change['method'], array('add', 'change')))
2007
-		return true;
2124
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2125
+			return true;
2126
+	}
2008 2127
 	// Otherwise if we're removing and it wasn't found we're also done.
2009
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2010
-		return true;
2128
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2129
+			return true;
2130
+	}
2011 2131
 	// Otherwise is it just a test?
2012
-	elseif ($is_test)
2013
-		return false;
2132
+	elseif ($is_test) {
2133
+			return false;
2134
+	}
2014 2135
 
2015 2136
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2016 2137
 	$running = false;
@@ -2021,8 +2142,9 @@  discard block
 block discarded – undo
2021 2142
 			SHOW FULL PROCESSLIST');
2022 2143
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2023 2144
 		{
2024
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2025
-				$found = true;
2145
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2146
+							$found = true;
2147
+			}
2026 2148
 		}
2027 2149
 
2028 2150
 		// Can't find it? Then we need to run it fools!
@@ -2034,8 +2156,9 @@  discard block
 block discarded – undo
2034 2156
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2035 2157
 				' . $change['text'], true) !== false;
2036 2158
 
2037
-			if (!$success)
2038
-				return false;
2159
+			if (!$success) {
2160
+							return false;
2161
+			}
2039 2162
 
2040 2163
 			// Return
2041 2164
 			$running = true;
@@ -2077,8 +2200,9 @@  discard block
 block discarded – undo
2077 2200
 			'db_error_skip' => true,
2078 2201
 		)
2079 2202
 	);
2080
-	if ($smcFunc['db_num_rows']($request) === 0)
2081
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2203
+	if ($smcFunc['db_num_rows']($request) === 0) {
2204
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2205
+	}
2082 2206
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2083 2207
 	$smcFunc['db_free_result']($request);
2084 2208
 
@@ -2100,18 +2224,19 @@  discard block
 block discarded – undo
2100 2224
 			)
2101 2225
 		);
2102 2226
 		// No results? Just forget it all together.
2103
-		if ($smcFunc['db_num_rows']($request) === 0)
2104
-			unset($table_row['Collation']);
2105
-		else
2106
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2227
+		if ($smcFunc['db_num_rows']($request) === 0) {
2228
+					unset($table_row['Collation']);
2229
+		} else {
2230
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2231
+		}
2107 2232
 		$smcFunc['db_free_result']($request);
2108 2233
 	}
2109 2234
 
2110 2235
 	if ($column_fix)
2111 2236
 	{
2112 2237
 		// Make sure there are no NULL's left.
2113
-		if ($null_fix)
2114
-			$smcFunc['db_query']('', '
2238
+		if ($null_fix) {
2239
+					$smcFunc['db_query']('', '
2115 2240
 				UPDATE {db_prefix}' . $change['table'] . '
2116 2241
 				SET ' . $change['column'] . ' = {string:default}
2117 2242
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2120,6 +2245,7 @@  discard block
 block discarded – undo
2120 2245
 					'db_error_skip' => true,
2121 2246
 				)
2122 2247
 			);
2248
+		}
2123 2249
 
2124 2250
 		// Do the actual alteration.
2125 2251
 		$smcFunc['db_query']('', '
@@ -2148,8 +2274,9 @@  discard block
 block discarded – undo
2148 2274
 	}
2149 2275
 
2150 2276
 	// Not a column we need to check on?
2151
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2152
-		return;
2277
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2278
+			return;
2279
+	}
2153 2280
 
2154 2281
 	// Break it up you (six|seven).
2155 2282
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2168,13 +2295,13 @@  discard block
 block discarded – undo
2168 2295
 				'new_name' => $temp[2],
2169 2296
 		));
2170 2297
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2171
-		if ($smcFunc['db_num_rows'] != 1)
2172
-			return;
2298
+		if ($smcFunc['db_num_rows'] != 1) {
2299
+					return;
2300
+		}
2173 2301
 
2174 2302
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2175 2303
 		$smcFunc['db_free_result']($request);
2176
-	}
2177
-	else
2304
+	} else
2178 2305
 	{
2179 2306
 		// Do this the old fashion, sure method way.
2180 2307
 		$request = $smcFunc['db_query']('', '
@@ -2185,21 +2312,24 @@  discard block
 block discarded – undo
2185 2312
 		));
2186 2313
 		// Mayday!
2187 2314
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2188
-		if ($smcFunc['db_num_rows'] == 0)
2189
-			return;
2315
+		if ($smcFunc['db_num_rows'] == 0) {
2316
+					return;
2317
+		}
2190 2318
 
2191 2319
 		// Oh where, oh where has my little field gone. Oh where can it be...
2192
-		while ($row = $smcFunc['db_query']($request))
2193
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2320
+		while ($row = $smcFunc['db_query']($request)) {
2321
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2194 2322
 			{
2195 2323
 				$current_type = $row['Type'];
2324
+		}
2196 2325
 				break;
2197 2326
 			}
2198 2327
 	}
2199 2328
 
2200 2329
 	// If this doesn't match, the column may of been altered for a reason.
2201
-	if (trim($current_type) != trim($temp[3]))
2202
-		$temp[3] = $current_type;
2330
+	if (trim($current_type) != trim($temp[3])) {
2331
+			$temp[3] = $current_type;
2332
+	}
2203 2333
 
2204 2334
 	// Piece this back together.
2205 2335
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2211,8 +2341,9 @@  discard block
 block discarded – undo
2211 2341
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2212 2342
 	global $step_progress, $is_debug, $upcontext;
2213 2343
 
2214
-	if ($_GET['substep'] < $substep)
2215
-		$_GET['substep'] = $substep;
2344
+	if ($_GET['substep'] < $substep) {
2345
+			$_GET['substep'] = $substep;
2346
+	}
2216 2347
 
2217 2348
 	if ($command_line)
2218 2349
 	{
@@ -2225,29 +2356,33 @@  discard block
 block discarded – undo
2225 2356
 	}
2226 2357
 
2227 2358
 	@set_time_limit(300);
2228
-	if (function_exists('apache_reset_timeout'))
2229
-		@apache_reset_timeout();
2359
+	if (function_exists('apache_reset_timeout')) {
2360
+			@apache_reset_timeout();
2361
+	}
2230 2362
 
2231
-	if (time() - $start_time <= $timeLimitThreshold)
2232
-		return;
2363
+	if (time() - $start_time <= $timeLimitThreshold) {
2364
+			return;
2365
+	}
2233 2366
 
2234 2367
 	// Do we have some custom step progress stuff?
2235 2368
 	if (!empty($step_progress))
2236 2369
 	{
2237 2370
 		$upcontext['substep_progress'] = 0;
2238 2371
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2239
-		if ($step_progress['current'] > $step_progress['total'])
2240
-			$upcontext['substep_progress'] = 99.9;
2241
-		else
2242
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2372
+		if ($step_progress['current'] > $step_progress['total']) {
2373
+					$upcontext['substep_progress'] = 99.9;
2374
+		} else {
2375
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2376
+		}
2243 2377
 
2244 2378
 		// Make it nicely rounded.
2245 2379
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2246 2380
 	}
2247 2381
 
2248 2382
 	// If this is XML we just exit right away!
2249
-	if (isset($_GET['xml']))
2250
-		return upgradeExit();
2383
+	if (isset($_GET['xml'])) {
2384
+			return upgradeExit();
2385
+	}
2251 2386
 
2252 2387
 	// We're going to pause after this!
2253 2388
 	$upcontext['pause'] = true;
@@ -2255,13 +2390,15 @@  discard block
 block discarded – undo
2255 2390
 	$upcontext['query_string'] = '';
2256 2391
 	foreach ($_GET as $k => $v)
2257 2392
 	{
2258
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2259
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2393
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2394
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2395
+		}
2260 2396
 	}
2261 2397
 
2262 2398
 	// Custom warning?
2263
-	if (!empty($custom_warning))
2264
-		$upcontext['custom_warning'] = $custom_warning;
2399
+	if (!empty($custom_warning)) {
2400
+			$upcontext['custom_warning'] = $custom_warning;
2401
+	}
2265 2402
 
2266 2403
 	upgradeExit();
2267 2404
 }
@@ -2276,25 +2413,26 @@  discard block
 block discarded – undo
2276 2413
 	ob_implicit_flush(true);
2277 2414
 	@set_time_limit(600);
2278 2415
 
2279
-	if (!isset($_SERVER['argv']))
2280
-		$_SERVER['argv'] = array();
2416
+	if (!isset($_SERVER['argv'])) {
2417
+			$_SERVER['argv'] = array();
2418
+	}
2281 2419
 	$_GET['maint'] = 1;
2282 2420
 
2283 2421
 	foreach ($_SERVER['argv'] as $i => $arg)
2284 2422
 	{
2285
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2286
-			$_GET['lang'] = $match[1];
2287
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2288
-			continue;
2289
-		elseif ($arg == '--no-maintenance')
2290
-			$_GET['maint'] = 0;
2291
-		elseif ($arg == '--debug')
2292
-			$is_debug = true;
2293
-		elseif ($arg == '--backup')
2294
-			$_POST['backup'] = 1;
2295
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2296
-			$_GET['conv'] = 1;
2297
-		elseif ($i != 0)
2423
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2424
+					$_GET['lang'] = $match[1];
2425
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2426
+					continue;
2427
+		} elseif ($arg == '--no-maintenance') {
2428
+					$_GET['maint'] = 0;
2429
+		} elseif ($arg == '--debug') {
2430
+					$is_debug = true;
2431
+		} elseif ($arg == '--backup') {
2432
+					$_POST['backup'] = 1;
2433
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2434
+					$_GET['conv'] = 1;
2435
+		} elseif ($i != 0)
2298 2436
 		{
2299 2437
 			echo 'SMF Command-line Upgrader
2300 2438
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2308,10 +2446,12 @@  discard block
 block discarded – undo
2308 2446
 		}
2309 2447
 	}
2310 2448
 
2311
-	if (!php_version_check())
2312
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2313
-	if (!db_version_check())
2314
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2449
+	if (!php_version_check()) {
2450
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2451
+	}
2452
+	if (!db_version_check()) {
2453
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2454
+	}
2315 2455
 
2316 2456
 	// Do some checks to make sure they have proper privileges
2317 2457
 	db_extend('packages');
@@ -2326,34 +2466,39 @@  discard block
 block discarded – undo
2326 2466
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2327 2467
 
2328 2468
 	// Sorry... we need CREATE, ALTER and DROP
2329
-	if (!$create || !$alter || !$drop)
2330
-		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);
2469
+	if (!$create || !$alter || !$drop) {
2470
+			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);
2471
+	}
2331 2472
 
2332 2473
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2333 2474
 		&& @file_exists($sourcedir . '/QueryString.php')
2334 2475
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2335
-	if (!$check && !isset($modSettings['smfVersion']))
2336
-		print_error('Error: Some files are missing or out-of-date.', true);
2476
+	if (!$check && !isset($modSettings['smfVersion'])) {
2477
+			print_error('Error: Some files are missing or out-of-date.', true);
2478
+	}
2337 2479
 
2338 2480
 	// Do a quick version spot check.
2339 2481
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2340 2482
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2341
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2342
-		print_error('Error: Some files have not yet been updated properly.');
2483
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2484
+			print_error('Error: Some files have not yet been updated properly.');
2485
+	}
2343 2486
 
2344 2487
 	// Make sure Settings.php is writable.
2345 2488
 		quickFileWritable($boarddir . '/Settings.php');
2346
-	if (!is_writable($boarddir . '/Settings.php'))
2347
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2489
+	if (!is_writable($boarddir . '/Settings.php')) {
2490
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2491
+	}
2348 2492
 
2349 2493
 	// Make sure Settings_bak.php is writable.
2350 2494
 		quickFileWritable($boarddir . '/Settings_bak.php');
2351
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2352
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2495
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2496
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2497
+	}
2353 2498
 
2354
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2355
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2356
-	elseif (isset($modSettings['agreement']))
2499
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2500
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2501
+	} elseif (isset($modSettings['agreement']))
2357 2502
 	{
2358 2503
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2359 2504
 		fwrite($fp, $modSettings['agreement']);
@@ -2363,31 +2508,36 @@  discard block
 block discarded – undo
2363 2508
 	// Make sure Themes is writable.
2364 2509
 	quickFileWritable($modSettings['theme_dir']);
2365 2510
 
2366
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2367
-		print_error('Error: Unable to obtain write access to "Themes".');
2511
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2512
+			print_error('Error: Unable to obtain write access to "Themes".');
2513
+	}
2368 2514
 
2369 2515
 	// Make sure cache directory exists and is writable!
2370 2516
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2371
-	if (!file_exists($cachedir_temp))
2372
-		@mkdir($cachedir_temp);
2517
+	if (!file_exists($cachedir_temp)) {
2518
+			@mkdir($cachedir_temp);
2519
+	}
2373 2520
 
2374 2521
 	// Make sure the cache temp dir is writable.
2375 2522
 	quickFileWritable($cachedir_temp);
2376 2523
 
2377
-	if (!is_writable($cachedir_temp))
2378
-		print_error('Error: Unable to obtain write access to "cache".', true);
2524
+	if (!is_writable($cachedir_temp)) {
2525
+			print_error('Error: Unable to obtain write access to "cache".', true);
2526
+	}
2379 2527
 
2380
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2381
-		print_error('Error: Unable to find language files!', true);
2382
-	else
2528
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2529
+			print_error('Error: Unable to find language files!', true);
2530
+	} else
2383 2531
 	{
2384 2532
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2385 2533
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2386 2534
 
2387
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2388
-			print_error('Error: Language files out of date.', true);
2389
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2390
-			print_error('Error: Install language is missing for selected language.', true);
2535
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2536
+					print_error('Error: Language files out of date.', true);
2537
+		}
2538
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2539
+					print_error('Error: Install language is missing for selected language.', true);
2540
+		}
2391 2541
 
2392 2542
 		// Otherwise include it!
2393 2543
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2406,8 +2556,9 @@  discard block
 block discarded – undo
2406 2556
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2407 2557
 
2408 2558
 	// Done it already?
2409
-	if (!empty($_POST['utf8_done']))
2410
-		return true;
2559
+	if (!empty($_POST['utf8_done'])) {
2560
+			return true;
2561
+	}
2411 2562
 
2412 2563
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2413 2564
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2420,8 +2571,7 @@  discard block
 block discarded – undo
2420 2571
 		);
2421 2572
 
2422 2573
 		return true;
2423
-	}
2424
-	else
2574
+	} else
2425 2575
 	{
2426 2576
 		$upcontext['page_title'] = 'Converting to UTF8';
2427 2577
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2465,8 +2615,9 @@  discard block
 block discarded – undo
2465 2615
 			)
2466 2616
 		);
2467 2617
 		$db_charsets = array();
2468
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2469
-			$db_charsets[] = $row['Charset'];
2618
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2619
+					$db_charsets[] = $row['Charset'];
2620
+		}
2470 2621
 
2471 2622
 		$smcFunc['db_free_result']($request);
2472 2623
 
@@ -2502,13 +2653,15 @@  discard block
 block discarded – undo
2502 2653
 		// If there's a fulltext index, we need to drop it first...
2503 2654
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2504 2655
 		{
2505
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2506
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2656
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2657
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2507 2658
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2659
+			}
2508 2660
 			$smcFunc['db_free_result']($request);
2509 2661
 
2510
-			if (isset($upcontext['fulltext_index']))
2511
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2662
+			if (isset($upcontext['fulltext_index'])) {
2663
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2664
+			}
2512 2665
 		}
2513 2666
 
2514 2667
 		// Drop it and make a note...
@@ -2698,8 +2851,9 @@  discard block
 block discarded – undo
2698 2851
 			$replace = '%field%';
2699 2852
 
2700 2853
 			// Build a huge REPLACE statement...
2701
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2702
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2854
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2855
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2856
+			}
2703 2857
 		}
2704 2858
 
2705 2859
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2709,9 +2863,10 @@  discard block
 block discarded – undo
2709 2863
 		$upcontext['table_count'] = count($queryTables);
2710 2864
 	
2711 2865
 		// What ones have we already done?
2712
-		foreach ($queryTables as $id => $table)
2713
-			if ($id < $_GET['substep'])
2866
+		foreach ($queryTables as $id => $table) {
2867
+					if ($id < $_GET['substep'])
2714 2868
 				$upcontext['previous_tables'][] = $table;
2869
+		}
2715 2870
 
2716 2871
 		$upcontext['cur_table_num'] = $_GET['substep'];
2717 2872
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2748,8 +2903,9 @@  discard block
 block discarded – undo
2748 2903
 			nextSubstep($substep);
2749 2904
 
2750 2905
 			// Just to make sure it doesn't time out.
2751
-			if (function_exists('apache_reset_timeout'))
2752
-				@apache_reset_timeout();
2906
+			if (function_exists('apache_reset_timeout')) {
2907
+							@apache_reset_timeout();
2908
+			}
2753 2909
 
2754 2910
 			$table_charsets = array();
2755 2911
 
@@ -2770,8 +2926,9 @@  discard block
 block discarded – undo
2770 2926
 					{
2771 2927
 						list($charset) = explode('_', $collation);
2772 2928
 
2773
-						if (!isset($table_charsets[$charset]))
2774
-							$table_charsets[$charset] = array();
2929
+						if (!isset($table_charsets[$charset])) {
2930
+													$table_charsets[$charset] = array();
2931
+						}
2775 2932
 
2776 2933
 						$table_charsets[$charset][] = $column_info;
2777 2934
 					}
@@ -2811,10 +2968,11 @@  discard block
 block discarded – undo
2811 2968
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2812 2969
 				{
2813 2970
 					$update = '';
2814
-					foreach ($table_charsets as $charset => $columns)
2815
-						foreach ($columns as $column)
2971
+					foreach ($table_charsets as $charset => $columns) {
2972
+											foreach ($columns as $column)
2816 2973
 							$update .= '
2817 2974
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2975
+					}
2818 2976
 
2819 2977
 					$smcFunc['db_query']('', '
2820 2978
 						UPDATE {raw:table_name}
@@ -2839,8 +2997,9 @@  discard block
 block discarded – undo
2839 2997
 			// Now do the actual conversion (if still needed).
2840 2998
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2841 2999
 			{
2842
-				if ($command_line)
2843
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3000
+				if ($command_line) {
3001
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3002
+				}
2844 3003
 
2845 3004
 				$smcFunc['db_query']('', '
2846 3005
 					ALTER TABLE {raw:table_name}
@@ -2850,12 +3009,14 @@  discard block
 block discarded – undo
2850 3009
 					)
2851 3010
 				);
2852 3011
 
2853
-				if ($command_line)
2854
-					echo " done.\n";
3012
+				if ($command_line) {
3013
+									echo " done.\n";
3014
+				}
2855 3015
 			}
2856 3016
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2857
-			if (isset($_GET['xml']))
2858
-				return upgradeExit();
3017
+			if (isset($_GET['xml'])) {
3018
+							return upgradeExit();
3019
+			}
2859 3020
 		}
2860 3021
 
2861 3022
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2884,8 +3045,8 @@  discard block
 block discarded – undo
2884 3045
 		);
2885 3046
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2886 3047
 		{
2887
-			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)
2888
-				$smcFunc['db_query']('', '
3048
+			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) {
3049
+							$smcFunc['db_query']('', '
2889 3050
 					UPDATE {db_prefix}log_actions
2890 3051
 					SET extra = {string:extra}
2891 3052
 					WHERE id_action = {int:current_action}',
@@ -2894,6 +3055,7 @@  discard block
 block discarded – undo
2894 3055
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2895 3056
 					)
2896 3057
 				);
3058
+			}
2897 3059
 		}
2898 3060
 		$smcFunc['db_free_result']($request);
2899 3061
 
@@ -2915,15 +3077,17 @@  discard block
 block discarded – undo
2915 3077
 	// First thing's first - did we already do this?
2916 3078
 	if (!empty($modSettings['json_done']))
2917 3079
 	{
2918
-		if ($command_line)
2919
-			return DeleteUpgrade();
2920
-		else
2921
-			return true;
3080
+		if ($command_line) {
3081
+					return DeleteUpgrade();
3082
+		} else {
3083
+					return true;
3084
+		}
2922 3085
 	}
2923 3086
 
2924 3087
 	// Done it already - js wise?
2925
-	if (!empty($_POST['json_done']))
2926
-		return true;
3088
+	if (!empty($_POST['json_done'])) {
3089
+			return true;
3090
+	}
2927 3091
 
2928 3092
 	// List of tables affected by this function
2929 3093
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2955,12 +3119,14 @@  discard block
 block discarded – undo
2955 3119
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2956 3120
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2957 3121
 
2958
-	foreach ($keys as $id => $table)
2959
-		if ($id < $_GET['substep'])
3122
+	foreach ($keys as $id => $table) {
3123
+			if ($id < $_GET['substep'])
2960 3124
 			$upcontext['previous_tables'][] = $table;
3125
+	}
2961 3126
 
2962
-	if ($command_line)
2963
-		echo 'Converting data from serialize() to json_encode().';
3127
+	if ($command_line) {
3128
+			echo 'Converting data from serialize() to json_encode().';
3129
+	}
2964 3130
 
2965 3131
 	if (!$support_js || isset($_GET['xml']))
2966 3132
 	{
@@ -3000,8 +3166,9 @@  discard block
 block discarded – undo
3000 3166
 
3001 3167
 				// Loop through and fix these...
3002 3168
 				$new_settings = array();
3003
-				if ($command_line)
3004
-					echo "\n" . 'Fixing some settings...';
3169
+				if ($command_line) {
3170
+									echo "\n" . 'Fixing some settings...';
3171
+				}
3005 3172
 
3006 3173
 				foreach ($serialized_settings as $var)
3007 3174
 				{
@@ -3009,22 +3176,24 @@  discard block
 block discarded – undo
3009 3176
 					{
3010 3177
 						// Attempt to unserialize the setting
3011 3178
 						$temp = @safe_unserialize($modSettings[$var]);
3012
-						if (!$temp && $command_line)
3013
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3014
-						elseif ($temp !== false)
3015
-							$new_settings[$var] = json_encode($temp);
3179
+						if (!$temp && $command_line) {
3180
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3181
+						} elseif ($temp !== false) {
3182
+													$new_settings[$var] = json_encode($temp);
3183
+						}
3016 3184
 					}
3017 3185
 				}
3018 3186
 
3019 3187
 				// Update everything at once
3020
-				if (!function_exists('cache_put_data'))
3021
-					require_once($sourcedir . '/Load.php');
3188
+				if (!function_exists('cache_put_data')) {
3189
+									require_once($sourcedir . '/Load.php');
3190
+				}
3022 3191
 				updateSettings($new_settings, true);
3023 3192
 
3024
-				if ($command_line)
3025
-					echo ' done.';
3026
-			}
3027
-			elseif ($table == 'themes')
3193
+				if ($command_line) {
3194
+									echo ' done.';
3195
+				}
3196
+			} elseif ($table == 'themes')
3028 3197
 			{
3029 3198
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3030 3199
 				$query = $smcFunc['db_query']('', '
@@ -3043,10 +3212,11 @@  discard block
 block discarded – undo
3043 3212
 
3044 3213
 						if ($command_line)
3045 3214
 						{
3046
-							if ($temp === false)
3047
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3048
-							else
3049
-								echo "\n" . 'Fixing admin preferences...';
3215
+							if ($temp === false) {
3216
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3217
+							} else {
3218
+															echo "\n" . 'Fixing admin preferences...';
3219
+							}
3050 3220
 						}
3051 3221
 
3052 3222
 						if ($temp !== false)
@@ -3068,15 +3238,15 @@  discard block
 block discarded – undo
3068 3238
 								)
3069 3239
 							);
3070 3240
 
3071
-							if ($command_line)
3072
-								echo ' done.';
3241
+							if ($command_line) {
3242
+															echo ' done.';
3243
+							}
3073 3244
 						}
3074 3245
 					}
3075 3246
 
3076 3247
 					$smcFunc['db_free_result']($query);
3077 3248
 				}
3078
-			}
3079
-			else
3249
+			} else
3080 3250
 			{
3081 3251
 				// First item is always the key...
3082 3252
 				$key = $info[0];
@@ -3087,8 +3257,7 @@  discard block
 block discarded – undo
3087 3257
 				{
3088 3258
 					$col_select = $info[1];
3089 3259
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3090
-				}
3091
-				else
3260
+				} else
3092 3261
 				{
3093 3262
 					$col_select = implode(', ', $info);
3094 3263
 				}
@@ -3121,8 +3290,7 @@  discard block
 block discarded – undo
3121 3290
 								if ($temp === false && $command_line)
3122 3291
 								{
3123 3292
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3124
-								}
3125
-								else
3293
+								} else
3126 3294
 								{
3127 3295
 									$row[$col] = json_encode($temp);
3128 3296
 
@@ -3147,16 +3315,18 @@  discard block
 block discarded – undo
3147 3315
 						}
3148 3316
 					}
3149 3317
 
3150
-					if ($command_line)
3151
-						echo ' done.';
3318
+					if ($command_line) {
3319
+											echo ' done.';
3320
+					}
3152 3321
 
3153 3322
 					// Free up some memory...
3154 3323
 					$smcFunc['db_free_result']($query);
3155 3324
 				}
3156 3325
 			}
3157 3326
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3158
-			if (isset($_GET['xml']))
3159
-				return upgradeExit();
3327
+			if (isset($_GET['xml'])) {
3328
+							return upgradeExit();
3329
+			}
3160 3330
 		}
3161 3331
 
3162 3332
 		if ($command_line)
@@ -3171,8 +3341,9 @@  discard block
 block discarded – undo
3171 3341
 
3172 3342
 		$_GET['substep'] = 0;
3173 3343
 		// Make sure we move on!
3174
-		if ($command_line)
3175
-			return DeleteUpgrade();
3344
+		if ($command_line) {
3345
+					return DeleteUpgrade();
3346
+		}
3176 3347
 
3177 3348
 		return true;
3178 3349
 	}
@@ -3192,14 +3363,16 @@  discard block
 block discarded – undo
3192 3363
 	global $upcontext, $txt, $settings;
3193 3364
 
3194 3365
 	// Don't call me twice!
3195
-	if (!empty($upcontext['chmod_called']))
3196
-		return;
3366
+	if (!empty($upcontext['chmod_called'])) {
3367
+			return;
3368
+	}
3197 3369
 
3198 3370
 	$upcontext['chmod_called'] = true;
3199 3371
 
3200 3372
 	// Nothing?
3201
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3202
-		return;
3373
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3374
+			return;
3375
+	}
3203 3376
 
3204 3377
 	// Was it a problem with Windows?
3205 3378
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3231,11 +3404,12 @@  discard block
 block discarded – undo
3231 3404
 					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\');
3232 3405
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3233 3406
 
3234
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3235
-		echo '
3407
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3408
+			echo '
3236 3409
 					content.write(\'<hr>\n\t\t\t\');
3237 3410
 					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\');
3238 3411
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3412
+	}
3239 3413
 
3240 3414
 	echo '
3241 3415
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3243,17 +3417,19 @@  discard block
 block discarded – undo
3243 3417
 				}
3244 3418
 			</script>';
3245 3419
 
3246
-	if (!empty($upcontext['chmod']['ftp_error']))
3247
-		echo '
3420
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3421
+			echo '
3248 3422
 			<div class="error_message red">
3249 3423
 				The following error was encountered when trying to connect:<br><br>
3250 3424
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3251 3425
 			</div>
3252 3426
 			<br>';
3427
+	}
3253 3428
 
3254
-	if (empty($upcontext['chmod_in_form']))
3255
-		echo '
3429
+	if (empty($upcontext['chmod_in_form'])) {
3430
+			echo '
3256 3431
 	<form action="', $upcontext['form_url'], '" method="post">';
3432
+	}
3257 3433
 
3258 3434
 	echo '
3259 3435
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3288,10 +3464,11 @@  discard block
 block discarded – undo
3288 3464
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3289 3465
 	</div>';
3290 3466
 
3291
-	if (empty($upcontext['chmod_in_form']))
3292
-		echo '
3467
+	if (empty($upcontext['chmod_in_form'])) {
3468
+			echo '
3293 3469
 	</form>';
3294
-}
3470
+	}
3471
+	}
3295 3472
 
3296 3473
 function template_upgrade_above()
3297 3474
 {
@@ -3351,9 +3528,10 @@  discard block
 block discarded – undo
3351 3528
 				<h2>', $txt['upgrade_progress'], '</h2>
3352 3529
 				<ul>';
3353 3530
 
3354
-	foreach ($upcontext['steps'] as $num => $step)
3355
-		echo '
3531
+	foreach ($upcontext['steps'] as $num => $step) {
3532
+			echo '
3356 3533
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3534
+	}
3357 3535
 
3358 3536
 	echo '
3359 3537
 					</ul>
@@ -3366,8 +3544,8 @@  discard block
 block discarded – undo
3366 3544
 				</div>
3367 3545
 			</div>';
3368 3546
 
3369
-	if (isset($upcontext['step_progress']))
3370
-		echo '
3547
+	if (isset($upcontext['step_progress'])) {
3548
+			echo '
3371 3549
 				<br>
3372 3550
 				<br>
3373 3551
 				<div id="progress_bar_step">
@@ -3376,6 +3554,7 @@  discard block
 block discarded – undo
3376 3554
 						<span>', $txt['upgrade_step_progress'], '</span>
3377 3555
 					</div>
3378 3556
 				</div>';
3557
+	}
3379 3558
 
3380 3559
 	echo '
3381 3560
 				<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>
@@ -3406,32 +3585,36 @@  discard block
 block discarded – undo
3406 3585
 {
3407 3586
 	global $upcontext, $txt;
3408 3587
 
3409
-	if (!empty($upcontext['pause']))
3410
-		echo '
3588
+	if (!empty($upcontext['pause'])) {
3589
+			echo '
3411 3590
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3412 3591
 
3413 3592
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3414 3593
 								<h3>
3415 3594
 									', $txt['upgrade_paused_overload'], '
3416 3595
 								</h3>';
3596
+	}
3417 3597
 
3418
-	if (!empty($upcontext['custom_warning']))
3419
-		echo '
3598
+	if (!empty($upcontext['custom_warning'])) {
3599
+			echo '
3420 3600
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3421 3601
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3422 3602
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3423 3603
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3424 3604
 								</div>';
3605
+	}
3425 3606
 
3426 3607
 	echo '
3427 3608
 								<div class="righttext" style="margin: 1ex;">';
3428 3609
 
3429
-	if (!empty($upcontext['continue']))
3430
-		echo '
3610
+	if (!empty($upcontext['continue'])) {
3611
+			echo '
3431 3612
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3432
-	if (!empty($upcontext['skip']))
3433
-		echo '
3613
+	}
3614
+	if (!empty($upcontext['skip'])) {
3615
+			echo '
3434 3616
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3617
+	}
3435 3618
 
3436 3619
 	echo '
3437 3620
 								</div>
@@ -3481,11 +3664,12 @@  discard block
 block discarded – undo
3481 3664
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3482 3665
 	<smf>';
3483 3666
 
3484
-	if (!empty($upcontext['get_data']))
3485
-		foreach ($upcontext['get_data'] as $k => $v)
3667
+	if (!empty($upcontext['get_data'])) {
3668
+			foreach ($upcontext['get_data'] as $k => $v)
3486 3669
 			echo '
3487 3670
 		<get key="', $k, '">', $v, '</get>';
3488
-}
3671
+	}
3672
+	}
3489 3673
 
3490 3674
 function template_xml_below()
3491 3675
 {
@@ -3526,8 +3710,8 @@  discard block
 block discarded – undo
3526 3710
 	template_chmod();
3527 3711
 
3528 3712
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3529
-	if ($upcontext['is_large_forum'])
3530
-		echo '
3713
+	if ($upcontext['is_large_forum']) {
3714
+			echo '
3531 3715
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3532 3716
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3533 3717
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3535,10 +3719,11 @@  discard block
 block discarded – undo
3535 3719
 				', $txt['upgrade_warning_lots_data'], '
3536 3720
 			</div>
3537 3721
 		</div>';
3722
+	}
3538 3723
 
3539 3724
 	// A warning message?
3540
-	if (!empty($upcontext['warning']))
3541
-		echo '
3725
+	if (!empty($upcontext['warning'])) {
3726
+			echo '
3542 3727
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3543 3728
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3544 3729
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3546,6 +3731,7 @@  discard block
 block discarded – undo
3546 3731
 				', $upcontext['warning'], '
3547 3732
 			</div>
3548 3733
 		</div>';
3734
+	}
3549 3735
 
3550 3736
 	// Paths are incorrect?
3551 3737
 	echo '
@@ -3561,20 +3747,22 @@  discard block
 block discarded – undo
3561 3747
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3562 3748
 	{
3563 3749
 		$ago = time() - $upcontext['started'];
3564
-		if ($ago < 60)
3565
-			$ago = $ago . ' seconds';
3566
-		elseif ($ago < 3600)
3567
-			$ago = (int) ($ago / 60) . ' minutes';
3568
-		else
3569
-			$ago = (int) ($ago / 3600) . ' hours';
3750
+		if ($ago < 60) {
3751
+					$ago = $ago . ' seconds';
3752
+		} elseif ($ago < 3600) {
3753
+					$ago = (int) ($ago / 60) . ' minutes';
3754
+		} else {
3755
+					$ago = (int) ($ago / 3600) . ' hours';
3756
+		}
3570 3757
 
3571 3758
 		$active = time() - $upcontext['updated'];
3572
-		if ($active < 60)
3573
-			$updated = $active . ' seconds';
3574
-		elseif ($active < 3600)
3575
-			$updated = (int) ($active / 60) . ' minutes';
3576
-		else
3577
-			$updated = (int) ($active / 3600) . ' hours';
3759
+		if ($active < 60) {
3760
+					$updated = $active . ' seconds';
3761
+		} elseif ($active < 3600) {
3762
+					$updated = (int) ($active / 60) . ' minutes';
3763
+		} else {
3764
+					$updated = (int) ($active / 3600) . ' hours';
3765
+		}
3578 3766
 
3579 3767
 		echo '
3580 3768
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3583,16 +3771,18 @@  discard block
 block discarded – undo
3583 3771
 			<div style="padding-left: 6ex;">
3584 3772
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3585 3773
 
3586
-		if ($active < 600)
3587
-			echo '
3774
+		if ($active < 600) {
3775
+					echo '
3588 3776
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3777
+		}
3589 3778
 
3590
-		if ($active > $upcontext['inactive_timeout'])
3591
-			echo '
3779
+		if ($active > $upcontext['inactive_timeout']) {
3780
+					echo '
3592 3781
 				<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.';
3593
-		else
3594
-			echo '
3782
+		} else {
3783
+					echo '
3595 3784
 				<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!');
3785
+		}
3596 3786
 
3597 3787
 		echo '
3598 3788
 			</div>
@@ -3608,9 +3798,10 @@  discard block
 block discarded – undo
3608 3798
 					<td>
3609 3799
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3610 3800
 
3611
-	if (!empty($upcontext['username_incorrect']))
3612
-		echo '
3801
+	if (!empty($upcontext['username_incorrect'])) {
3802
+			echo '
3613 3803
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3804
+	}
3614 3805
 
3615 3806
 	echo '
3616 3807
 					</td>
@@ -3621,9 +3812,10 @@  discard block
 block discarded – undo
3621 3812
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3622 3813
 						<input type="hidden" name="hash_passwrd" value="">';
3623 3814
 
3624
-	if (!empty($upcontext['password_failed']))
3625
-		echo '
3815
+	if (!empty($upcontext['password_failed'])) {
3816
+			echo '
3626 3817
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3818
+	}
3627 3819
 
3628 3820
 	echo '
3629 3821
 					</td>
@@ -3694,8 +3886,8 @@  discard block
 block discarded – undo
3694 3886
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3695 3887
 
3696 3888
 	// Warning message?
3697
-	if (!empty($upcontext['upgrade_options_warning']))
3698
-		echo '
3889
+	if (!empty($upcontext['upgrade_options_warning'])) {
3890
+			echo '
3699 3891
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3700 3892
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3701 3893
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3703,6 +3895,7 @@  discard block
 block discarded – undo
3703 3895
 				', $upcontext['upgrade_options_warning'], '
3704 3896
 			</div>
3705 3897
 		</div>';
3898
+	}
3706 3899
 
3707 3900
 	echo '
3708 3901
 				<table>
@@ -3745,8 +3938,8 @@  discard block
 block discarded – undo
3745 3938
 						</td>
3746 3939
 					</tr>';
3747 3940
 
3748
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3749
-		echo '
3941
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3942
+			echo '
3750 3943
 					<tr valign="top">
3751 3944
 						<td width="2%">
3752 3945
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3755,6 +3948,7 @@  discard block
 block discarded – undo
3755 3948
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3756 3949
 						</td>
3757 3950
 					</tr>';
3951
+	}
3758 3952
 
3759 3953
 	echo '
3760 3954
 					<tr valign="top">
@@ -3792,10 +3986,11 @@  discard block
 block discarded – undo
3792 3986
 			</div>';
3793 3987
 
3794 3988
 	// Dont any tables so far?
3795
-	if (!empty($upcontext['previous_tables']))
3796
-		foreach ($upcontext['previous_tables'] as $table)
3989
+	if (!empty($upcontext['previous_tables'])) {
3990
+			foreach ($upcontext['previous_tables'] as $table)
3797 3991
 			echo '
3798 3992
 			<br>Completed Table: &quot;', $table, '&quot;.';
3993
+	}
3799 3994
 
3800 3995
 	echo '
3801 3996
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3832,12 +4027,13 @@  discard block
 block discarded – undo
3832 4027
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3833 4028
 
3834 4029
 		// If debug flood the screen.
3835
-		if ($is_debug)
3836
-			echo '
4030
+		if ($is_debug) {
4031
+					echo '
3837 4032
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3838 4033
 
3839 4034
 				if (document.getElementById(\'debug_section\').scrollHeight)
3840 4035
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4036
+		}
3841 4037
 
3842 4038
 		echo '
3843 4039
 				// Get the next update...
@@ -3870,8 +4066,9 @@  discard block
 block discarded – undo
3870 4066
 {
3871 4067
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3872 4068
 
3873
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3874
-		$is_debug = true;
4069
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4070
+			$is_debug = true;
4071
+	}
3875 4072
 
3876 4073
 	echo '
3877 4074
 		<h3>Executing database changes</h3>
@@ -3886,8 +4083,9 @@  discard block
 block discarded – undo
3886 4083
 	{
3887 4084
 		foreach ($upcontext['actioned_items'] as $num => $item)
3888 4085
 		{
3889
-			if ($num != 0)
3890
-				echo ' Successful!';
4086
+			if ($num != 0) {
4087
+							echo ' Successful!';
4088
+			}
3891 4089
 			echo '<br>' . $item;
3892 4090
 		}
3893 4091
 		if (!empty($upcontext['changes_complete']))
@@ -3900,28 +4098,32 @@  discard block
 block discarded – undo
3900 4098
 				$seconds = intval($active % 60);
3901 4099
 
3902 4100
 				$totalTime = '';
3903
-				if ($hours > 0)
3904
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3905
-				if ($minutes > 0)
3906
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3907
-				if ($seconds > 0)
3908
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4101
+				if ($hours > 0) {
4102
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4103
+				}
4104
+				if ($minutes > 0) {
4105
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4106
+				}
4107
+				if ($seconds > 0) {
4108
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4109
+				}
3909 4110
 			}
3910 4111
 
3911
-			if ($is_debug && !empty($totalTime))
3912
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3913
-			else
3914
-				echo ' Successful!<br><br>';
4112
+			if ($is_debug && !empty($totalTime)) {
4113
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4114
+			} else {
4115
+							echo ' Successful!<br><br>';
4116
+			}
3915 4117
 
3916 4118
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3917 4119
 		}
3918
-	}
3919
-	else
4120
+	} else
3920 4121
 	{
3921 4122
 		// Tell them how many files we have in total.
3922
-		if ($upcontext['file_count'] > 1)
3923
-			echo '
4123
+		if ($upcontext['file_count'] > 1) {
4124
+					echo '
3924 4125
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4126
+		}
3925 4127
 
3926 4128
 		echo '
3927 4129
 		<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>
@@ -3937,19 +4139,23 @@  discard block
 block discarded – undo
3937 4139
 				$seconds = intval($active % 60);
3938 4140
 
3939 4141
 				$totalTime = '';
3940
-				if ($hours > 0)
3941
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3942
-				if ($minutes > 0)
3943
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3944
-				if ($seconds > 0)
3945
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4142
+				if ($hours > 0) {
4143
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4144
+				}
4145
+				if ($minutes > 0) {
4146
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4147
+				}
4148
+				if ($seconds > 0) {
4149
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4150
+				}
3946 4151
 			}
3947 4152
 
3948 4153
 			echo '
3949 4154
 			<br><span id="upgradeCompleted">';
3950 4155
 
3951
-			if (!empty($totalTime))
3952
-				echo 'Completed in ', $totalTime, '<br>';
4156
+			if (!empty($totalTime)) {
4157
+							echo 'Completed in ', $totalTime, '<br>';
4158
+			}
3953 4159
 
3954 4160
 			echo '</span>
3955 4161
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -3986,9 +4192,10 @@  discard block
 block discarded – undo
3986 4192
 			var getData = "";
3987 4193
 			var debugItems = ', $upcontext['debug_items'], ';';
3988 4194
 
3989
-		if ($is_debug)
3990
-			echo '
4195
+		if ($is_debug) {
4196
+					echo '
3991 4197
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4198
+		}
3992 4199
 
3993 4200
 		echo '
3994 4201
 			function getNextItem()
@@ -4028,9 +4235,10 @@  discard block
 block discarded – undo
4028 4235
 						document.getElementById("error_block").style.display = "";
4029 4236
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4030 4237
 
4031
-	if ($is_debug)
4032
-		echo '
4238
+	if ($is_debug) {
4239
+			echo '
4033 4240
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4241
+	}
4034 4242
 
4035 4243
 	echo '
4036 4244
 					}
@@ -4051,9 +4259,10 @@  discard block
 block discarded – undo
4051 4259
 						document.getElementById("error_block").style.display = "";
4052 4260
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4053 4261
 
4054
-	if ($is_debug)
4055
-		echo '
4262
+	if ($is_debug) {
4263
+			echo '
4056 4264
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4265
+	}
4057 4266
 
4058 4267
 	echo '
4059 4268
 					}
@@ -4112,8 +4321,8 @@  discard block
 block discarded – undo
4112 4321
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4113 4322
 				{';
4114 4323
 
4115
-		if ($is_debug)
4116
-			echo '
4324
+		if ($is_debug) {
4325
+					echo '
4117 4326
 					document.getElementById(\'debug_section\').style.display = "none";
4118 4327
 
4119 4328
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4131,6 +4340,7 @@  discard block
 block discarded – undo
4131 4340
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4132 4341
 
4133 4342
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4343
+		}
4134 4344
 
4135 4345
 		echo '
4136 4346
 
@@ -4138,9 +4348,10 @@  discard block
 block discarded – undo
4138 4348
 					document.getElementById(\'contbutt\').disabled = 0;
4139 4349
 					document.getElementById(\'database_done\').value = 1;';
4140 4350
 
4141
-		if ($upcontext['file_count'] > 1)
4142
-			echo '
4351
+		if ($upcontext['file_count'] > 1) {
4352
+					echo '
4143 4353
 					document.getElementById(\'info1\').style.display = "none";';
4354
+		}
4144 4355
 
4145 4356
 		echo '
4146 4357
 					document.getElementById(\'info2\').style.display = "none";
@@ -4153,9 +4364,10 @@  discard block
 block discarded – undo
4153 4364
 					lastItem = 0;
4154 4365
 					prevFile = curFile;';
4155 4366
 
4156
-		if ($is_debug)
4157
-			echo '
4367
+		if ($is_debug) {
4368
+					echo '
4158 4369
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4370
+		}
4159 4371
 
4160 4372
 		echo '
4161 4373
 					getNextItem();
@@ -4163,8 +4375,8 @@  discard block
 block discarded – undo
4163 4375
 				}';
4164 4376
 
4165 4377
 		// If debug scroll the screen.
4166
-		if ($is_debug)
4167
-			echo '
4378
+		if ($is_debug) {
4379
+					echo '
4168 4380
 				if (iLastSubStepProgress == -1)
4169 4381
 				{
4170 4382
 					// Give it consistent dots.
@@ -4183,6 +4395,7 @@  discard block
 block discarded – undo
4183 4395
 
4184 4396
 				if (document.getElementById(\'debug_section\').scrollHeight)
4185 4397
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4398
+		}
4186 4399
 
4187 4400
 		echo '
4188 4401
 				// Update the page.
@@ -4243,9 +4456,10 @@  discard block
 block discarded – undo
4243 4456
 			}';
4244 4457
 
4245 4458
 		// Start things off assuming we've not errored.
4246
-		if (empty($upcontext['error_message']))
4247
-			echo '
4459
+		if (empty($upcontext['error_message'])) {
4460
+					echo '
4248 4461
 			getNextItem();';
4462
+		}
4249 4463
 
4250 4464
 		echo '
4251 4465
 		//# sourceURL=dynamicScript-dbch.js 
@@ -4263,18 +4477,21 @@  discard block
 block discarded – undo
4263 4477
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4264 4478
 	<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>';
4265 4479
 
4266
-	if (!empty($upcontext['error_message']))
4267
-		echo '
4480
+	if (!empty($upcontext['error_message'])) {
4481
+			echo '
4268 4482
 	<error>', $upcontext['error_message'], '</error>';
4483
+	}
4269 4484
 
4270
-	if (!empty($upcontext['error_string']))
4271
-		echo '
4485
+	if (!empty($upcontext['error_string'])) {
4486
+			echo '
4272 4487
 	<sql>', $upcontext['error_string'], '</sql>';
4488
+	}
4273 4489
 
4274
-	if ($is_debug)
4275
-		echo '
4490
+	if ($is_debug) {
4491
+			echo '
4276 4492
 	<curtime>', time(), '</curtime>';
4277
-}
4493
+	}
4494
+	}
4278 4495
 
4279 4496
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4280 4497
 function template_convert_utf8()
@@ -4293,18 +4510,20 @@  discard block
 block discarded – undo
4293 4510
 			</div>';
4294 4511
 
4295 4512
 	// Done any tables so far?
4296
-	if (!empty($upcontext['previous_tables']))
4297
-		foreach ($upcontext['previous_tables'] as $table)
4513
+	if (!empty($upcontext['previous_tables'])) {
4514
+			foreach ($upcontext['previous_tables'] as $table)
4298 4515
 			echo '
4299 4516
 			<br>Completed Table: &quot;', $table, '&quot;.';
4517
+	}
4300 4518
 
4301 4519
 	echo '
4302 4520
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4303 4521
 
4304 4522
 	// If we dropped their index, let's let them know
4305
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4306
-		echo '
4523
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4524
+			echo '
4307 4525
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4526
+	}
4308 4527
 
4309 4528
 	echo '
4310 4529
 			<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>';
@@ -4340,12 +4559,13 @@  discard block
 block discarded – undo
4340 4559
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4341 4560
 
4342 4561
 		// If debug flood the screen.
4343
-		if ($is_debug)
4344
-			echo '
4562
+		if ($is_debug) {
4563
+					echo '
4345 4564
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4346 4565
 
4347 4566
 				if (document.getElementById(\'debug_section\').scrollHeight)
4348 4567
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4568
+		}
4349 4569
 
4350 4570
 		echo '
4351 4571
 				// Get the next update...
@@ -4390,19 +4610,21 @@  discard block
 block discarded – undo
4390 4610
 			</div>';
4391 4611
 
4392 4612
 	// Dont any tables so far?
4393
-	if (!empty($upcontext['previous_tables']))
4394
-		foreach ($upcontext['previous_tables'] as $table)
4613
+	if (!empty($upcontext['previous_tables'])) {
4614
+			foreach ($upcontext['previous_tables'] as $table)
4395 4615
 			echo '
4396 4616
 			<br>Completed Table: &quot;', $table, '&quot;.';
4617
+	}
4397 4618
 
4398 4619
 	echo '
4399 4620
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4400 4621
 			<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>';
4401 4622
 
4402 4623
 	// Try to make sure substep was reset.
4403
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4404
-		echo '
4624
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4625
+			echo '
4405 4626
 			<input type="hidden" name="substep" id="substep" value="0">';
4627
+	}
4406 4628
 
4407 4629
 	// Continue please!
4408 4630
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4435,12 +4657,13 @@  discard block
 block discarded – undo
4435 4657
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4436 4658
 
4437 4659
 		// If debug flood the screen.
4438
-		if ($is_debug)
4439
-			echo '
4660
+		if ($is_debug) {
4661
+					echo '
4440 4662
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4441 4663
 
4442 4664
 				if (document.getElementById(\'debug_section\').scrollHeight)
4443 4665
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4666
+		}
4444 4667
 
4445 4668
 		echo '
4446 4669
 				// Get the next update...
@@ -4476,8 +4699,8 @@  discard block
 block discarded – undo
4476 4699
 	<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>
4477 4700
 	<form action="', $boardurl, '/index.php">';
4478 4701
 
4479
-	if (!empty($upcontext['can_delete_script']))
4480
-		echo '
4702
+	if (!empty($upcontext['can_delete_script'])) {
4703
+			echo '
4481 4704
 			<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>
4482 4705
 			<script>
4483 4706
 				function doTheDelete(theCheck)
@@ -4489,6 +4712,7 @@  discard block
 block discarded – undo
4489 4712
 				}
4490 4713
 			</script>
4491 4714
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4715
+	}
4492 4716
 
4493 4717
 	$active = time() - $upcontext['started'];
4494 4718
 	$hours = floor($active / 3600);
@@ -4498,16 +4722,20 @@  discard block
 block discarded – undo
4498 4722
 	if ($is_debug)
4499 4723
 	{
4500 4724
 		$totalTime = '';
4501
-		if ($hours > 0)
4502
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4503
-		if ($minutes > 0)
4504
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4505
-		if ($seconds > 0)
4506
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4725
+		if ($hours > 0) {
4726
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4727
+		}
4728
+		if ($minutes > 0) {
4729
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4730
+		}
4731
+		if ($seconds > 0) {
4732
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4733
+		}
4507 4734
 	}
4508 4735
 
4509
-	if ($is_debug && !empty($totalTime))
4510
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4736
+	if ($is_debug && !empty($totalTime)) {
4737
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4738
+	}
4511 4739
 
4512 4740
 	echo '<br>
4513 4741
 			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>
@@ -4534,8 +4762,9 @@  discard block
 block discarded – undo
4534 4762
 
4535 4763
 	$current_substep = $_GET['substep'];
4536 4764
 
4537
-	if (empty($_GET['a']))
4538
-		$_GET['a'] = 0;
4765
+	if (empty($_GET['a'])) {
4766
+			$_GET['a'] = 0;
4767
+	}
4539 4768
 	$step_progress['name'] = 'Converting ips';
4540 4769
 	$step_progress['current'] = $_GET['a'];
4541 4770
 
@@ -4578,16 +4807,19 @@  discard block
 block discarded – undo
4578 4807
 				'empty' => '',
4579 4808
 				'limit' => $limit,
4580 4809
 		));
4581
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4582
-			$arIp[] = $row[$oldCol];
4810
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4811
+					$arIp[] = $row[$oldCol];
4812
+		}
4583 4813
 		$smcFunc['db_free_result']($request);
4584 4814
 
4585 4815
 		// Special case, null ip could keep us in a loop.
4586
-		if (is_null($arIp[0]))
4587
-			unset($arIp[0]);
4816
+		if (is_null($arIp[0])) {
4817
+					unset($arIp[0]);
4818
+		}
4588 4819
 
4589
-		if (empty($arIp))
4590
-			$is_done = true;
4820
+		if (empty($arIp)) {
4821
+					$is_done = true;
4822
+		}
4591 4823
 
4592 4824
 		$updates = array();
4593 4825
 		$cases = array();
@@ -4596,16 +4828,18 @@  discard block
 block discarded – undo
4596 4828
 		{
4597 4829
 			$arIp[$i] = trim($arIp[$i]);
4598 4830
 
4599
-			if (empty($arIp[$i]))
4600
-				continue;
4831
+			if (empty($arIp[$i])) {
4832
+							continue;
4833
+			}
4601 4834
 
4602 4835
 			$updates['ip' . $i] = $arIp[$i];
4603 4836
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4604 4837
 
4605 4838
 			if ($setSize > 0 && $i % $setSize === 0)
4606 4839
 			{
4607
-				if (count($updates) == 1)
4608
-					continue;
4840
+				if (count($updates) == 1) {
4841
+									continue;
4842
+				}
4609 4843
 
4610 4844
 				$updates['whereSet'] = array_values($updates);
4611 4845
 				$smcFunc['db_query']('', '
@@ -4639,8 +4873,7 @@  discard block
 block discarded – undo
4639 4873
 							'ip' => $ip
4640 4874
 					));
4641 4875
 				}
4642
-			}
4643
-			else
4876
+			} else
4644 4877
 			{
4645 4878
 				$updates['whereSet'] = array_values($updates);
4646 4879
 				$smcFunc['db_query']('', '
@@ -4654,9 +4887,9 @@  discard block
 block discarded – undo
4654 4887
 					$updates
4655 4888
 				);
4656 4889
 			}
4890
+		} else {
4891
+					$is_done = true;
4657 4892
 		}
4658
-		else
4659
-			$is_done = true;
4660 4893
 
4661 4894
 		$_GET['a'] += $limit;
4662 4895
 		$step_progress['current'] = $_GET['a'];
@@ -4682,10 +4915,11 @@  discard block
 block discarded – undo
4682 4915
  
4683 4916
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4684 4917
 
4685
-	if (isset($columns[$column]))
4686
-		return $columns[$column];
4687
-	else
4688
-		return null;
4689
-}
4918
+	if (isset($columns[$column])) {
4919
+			return $columns[$column];
4920
+	} else {
4921
+			return null;
4922
+	}
4923
+	}
4690 4924
 
4691 4925
 ?>
4692 4926
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Stats.php 1 patch
Braces   +112 added lines, -78 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
  * Display some useful/interesting board statistics.
@@ -30,8 +31,9 @@  discard block
 block discarded – undo
30 31
 
31 32
 	isAllowedTo('view_stats');
32 33
 	// Page disabled - redirect them out
33
-	if (empty($modSettings['trackStats']))
34
-		fatal_lang_error('feature_disabled', true);
34
+	if (empty($modSettings['trackStats'])) {
35
+			fatal_lang_error('feature_disabled', true);
36
+	}
35 37
 
36 38
 	if (!empty($_REQUEST['expand']))
37 39
 	{
@@ -39,31 +41,34 @@  discard block
 block discarded – undo
39 41
 
40 42
 		$month = (int) substr($_REQUEST['expand'], 4);
41 43
 		$year = (int) substr($_REQUEST['expand'], 0, 4);
42
-		if ($year > 1900 && $year < 2200 && $month >= 1 && $month <= 12)
43
-			$_SESSION['expanded_stats'][$year][] = $month;
44
-	}
45
-	elseif (!empty($_REQUEST['collapse']))
44
+		if ($year > 1900 && $year < 2200 && $month >= 1 && $month <= 12) {
45
+					$_SESSION['expanded_stats'][$year][] = $month;
46
+		}
47
+	} elseif (!empty($_REQUEST['collapse']))
46 48
 	{
47 49
 		$context['robot_no_index'] = true;
48 50
 
49 51
 		$month = (int) substr($_REQUEST['collapse'], 4);
50 52
 		$year = (int) substr($_REQUEST['collapse'], 0, 4);
51
-		if (!empty($_SESSION['expanded_stats'][$year]))
52
-			$_SESSION['expanded_stats'][$year] = array_diff($_SESSION['expanded_stats'][$year], array($month));
53
+		if (!empty($_SESSION['expanded_stats'][$year])) {
54
+					$_SESSION['expanded_stats'][$year] = array_diff($_SESSION['expanded_stats'][$year], array($month));
55
+		}
53 56
 	}
54 57
 
55 58
 	// Handle the XMLHttpRequest.
56 59
 	if (isset($_REQUEST['xml']))
57 60
 	{
58 61
 		// Collapsing stats only needs adjustments of the session variables.
59
-		if (!empty($_REQUEST['collapse']))
60
-			obExit(false);
62
+		if (!empty($_REQUEST['collapse'])) {
63
+					obExit(false);
64
+		}
61 65
 
62 66
 		$context['sub_template'] = 'stats';
63 67
 		$context['yearly'] = array();
64 68
 
65
-		if (empty($month) || empty($year))
66
-			return;
69
+		if (empty($month) || empty($year)) {
70
+					return;
71
+		}
67 72
 
68 73
 		getDailyStats('YEAR(date) = {int:year} AND MONTH(date) = {int:month}', array('year' => $year, 'month' => $month));
69 74
 		$context['yearly'][$year]['months'][$month]['date'] = array(
@@ -220,8 +225,9 @@  discard block
 block discarded – undo
220 225
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
221 226
 		);
222 227
 
223
-		if ($max_num_posts < $row_members['posts'])
224
-			$max_num_posts = $row_members['posts'];
228
+		if ($max_num_posts < $row_members['posts']) {
229
+					$max_num_posts = $row_members['posts'];
230
+		}
225 231
 	}
226 232
 	$smcFunc['db_free_result']($members_result);
227 233
 
@@ -257,8 +263,9 @@  discard block
 block discarded – undo
257 263
 			'link' => '<a href="' . $scripturl . '?board=' . $row_board['id_board'] . '.0">' . $row_board['name'] . '</a>'
258 264
 		);
259 265
 
260
-		if ($max_num_posts < $row_board['num_posts'])
261
-			$max_num_posts = $row_board['num_posts'];
266
+		if ($max_num_posts < $row_board['num_posts']) {
267
+					$max_num_posts = $row_board['num_posts'];
268
+		}
262 269
 	}
263 270
 	$smcFunc['db_free_result']($boards_result);
264 271
 
@@ -284,12 +291,13 @@  discard block
 block discarded – undo
284 291
 			)
285 292
 		);
286 293
 		$topic_ids = array();
287
-		while ($row = $smcFunc['db_fetch_assoc']($request))
288
-			$topic_ids[] = $row['id_topic'];
294
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
295
+					$topic_ids[] = $row['id_topic'];
296
+		}
289 297
 		$smcFunc['db_free_result']($request);
298
+	} else {
299
+			$topic_ids = array();
290 300
 	}
291
-	else
292
-		$topic_ids = array();
293 301
 
294 302
 	// Topic replies top 10.
295 303
 	$topic_reply_result = $smcFunc['db_query']('', '
@@ -329,8 +337,9 @@  discard block
 block discarded – undo
329 337
 			'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_reply['id_topic'] . '.0">' . $row_topic_reply['subject'] . '</a>'
330 338
 		);
331 339
 
332
-		if ($max_num_replies < $row_topic_reply['num_replies'])
333
-			$max_num_replies = $row_topic_reply['num_replies'];
340
+		if ($max_num_replies < $row_topic_reply['num_replies']) {
341
+					$max_num_replies = $row_topic_reply['num_replies'];
342
+		}
334 343
 	}
335 344
 	$smcFunc['db_free_result']($topic_reply_result);
336 345
 
@@ -354,12 +363,13 @@  discard block
 block discarded – undo
354 363
 			)
355 364
 		);
356 365
 		$topic_ids = array();
357
-		while ($row = $smcFunc['db_fetch_assoc']($request))
358
-			$topic_ids[] = $row['id_topic'];
366
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
367
+					$topic_ids[] = $row['id_topic'];
368
+		}
359 369
 		$smcFunc['db_free_result']($request);
370
+	} else {
371
+			$topic_ids = array();
360 372
 	}
361
-	else
362
-		$topic_ids = array();
363 373
 
364 374
 	// Topic views top 10.
365 375
 	$topic_view_result = $smcFunc['db_query']('', '
@@ -399,8 +409,9 @@  discard block
 block discarded – undo
399 409
 			'link' => '<a href="' . $scripturl . '?topic=' . $row_topic_views['id_topic'] . '.0">' . $row_topic_views['subject'] . '</a>'
400 410
 		);
401 411
 
402
-		if ($max_num < $row_topic_views['num_views'])
403
-			$max_num = $row_topic_views['num_views'];
412
+		if ($max_num < $row_topic_views['num_views']) {
413
+					$max_num = $row_topic_views['num_views'];
414
+		}
404 415
 	}
405 416
 	$smcFunc['db_free_result']($topic_view_result);
406 417
 
@@ -425,15 +436,17 @@  discard block
 block discarded – undo
425 436
 			)
426 437
 		);
427 438
 		$members = array();
428
-		while ($row = $smcFunc['db_fetch_assoc']($request))
429
-			$members[$row['id_member_started']] = $row['hits'];
439
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
440
+					$members[$row['id_member_started']] = $row['hits'];
441
+		}
430 442
 		$smcFunc['db_free_result']($request);
431 443
 
432 444
 		cache_put_data('stats_top_starters', $members, 360);
433 445
 	}
434 446
 
435
-	if (empty($members))
436
-		$members = array(0 => 0);
447
+	if (empty($members)) {
448
+			$members = array(0 => 0);
449
+	}
437 450
 
438 451
 	// Topic poster top 10.
439 452
 	$members_result = $smcFunc['db_query']('', '
@@ -458,8 +471,9 @@  discard block
 block discarded – undo
458 471
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
459 472
 		);
460 473
 
461
-		if ($max_num < $members[$row_members['id_member']])
462
-			$max_num = $members[$row_members['id_member']];
474
+		if ($max_num < $members[$row_members['id_member']]) {
475
+					$max_num = $members[$row_members['id_member']];
476
+		}
463 477
 	}
464 478
 	ksort($context['stats_blocks']['starters']);
465 479
 	$smcFunc['db_free_result']($members_result);
@@ -488,8 +502,9 @@  discard block
 block discarded – undo
488 502
 	while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
489 503
 	{
490 504
 		$temp2[] = (int) $row_members['id_member'];
491
-		if (count($context['stats_blocks']['time_online']) >= 10)
492
-			continue;
505
+		if (count($context['stats_blocks']['time_online']) >= 10) {
506
+					continue;
507
+		}
493 508
 
494 509
 		// Figure out the days, hours and minutes.
495 510
 		$timeDays = floor($row_members['total_time_logged_in'] / 86400);
@@ -497,10 +512,12 @@  discard block
 block discarded – undo
497 512
 
498 513
 		// Figure out which things to show... (days, hours, minutes, etc.)
499 514
 		$timelogged = '';
500
-		if ($timeDays > 0)
501
-			$timelogged .= $timeDays . $txt['totalTimeLogged5'];
502
-		if ($timeHours > 0)
503
-			$timelogged .= $timeHours . $txt['totalTimeLogged6'];
515
+		if ($timeDays > 0) {
516
+					$timelogged .= $timeDays . $txt['totalTimeLogged5'];
517
+		}
518
+		if ($timeHours > 0) {
519
+					$timelogged .= $timeHours . $txt['totalTimeLogged6'];
520
+		}
504 521
 		$timelogged .= floor(($row_members['total_time_logged_in'] % 3600) / 60) . $txt['totalTimeLogged7'];
505 522
 
506 523
 		$context['stats_blocks']['time_online'][] = array(
@@ -512,17 +529,20 @@  discard block
 block discarded – undo
512 529
 			'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
513 530
 		);
514 531
 
515
-		if ($max_time_online < $row_members['total_time_logged_in'])
516
-			$max_time_online = $row_members['total_time_logged_in'];
532
+		if ($max_time_online < $row_members['total_time_logged_in']) {
533
+					$max_time_online = $row_members['total_time_logged_in'];
534
+		}
517 535
 	}
518 536
 	$smcFunc['db_free_result']($members_result);
519 537
 
520
-	foreach ($context['stats_blocks']['time_online'] as $i => $member)
521
-		$context['stats_blocks']['time_online'][$i]['percent'] = round(($member['seconds_online'] * 100) / $max_time_online);
538
+	foreach ($context['stats_blocks']['time_online'] as $i => $member) {
539
+			$context['stats_blocks']['time_online'][$i]['percent'] = round(($member['seconds_online'] * 100) / $max_time_online);
540
+	}
522 541
 
523 542
 	// Cache the ones we found for a bit, just so we don't have to look again.
524
-	if ($temp !== $temp2)
525
-		cache_put_data('stats_total_time_members', $temp2, 480);
543
+	if ($temp !== $temp2) {
544
+			cache_put_data('stats_total_time_members', $temp2, 480);
545
+	}
526 546
 
527 547
 	// Likes.
528 548
 	if (!empty($modSettings['enable_likes']))
@@ -558,13 +578,15 @@  discard block
 block discarded – undo
558 578
 				'link' => '<a href="' . $scripturl . '?msg=' . $row_liked_message['id_msg'] .'">' . $row_liked_message['subject'] . '</a>'
559 579
 			);
560 580
 
561
-			if ($max_liked_message < $row_liked_message['likes'])
562
-				$max_liked_message = $row_liked_message['likes'];
581
+			if ($max_liked_message < $row_liked_message['likes']) {
582
+							$max_liked_message = $row_liked_message['likes'];
583
+			}
563 584
 		}
564 585
 		$smcFunc['db_free_result']($liked_messages);
565 586
 
566
-		foreach ($context['stats_blocks']['liked_messages'] as $i => $liked_messages)
567
-			$context['stats_blocks']['liked_messages'][$i]['percent'] = round(($liked_messages['num'] * 100) / $max_liked_message);
587
+		foreach ($context['stats_blocks']['liked_messages'] as $i => $liked_messages) {
588
+					$context['stats_blocks']['liked_messages'][$i]['percent'] = round(($liked_messages['num'] * 100) / $max_liked_message);
589
+		}
568 590
 
569 591
 		// Liked users top 10.
570 592
 		$context['stats_blocks']['liked_users'] = array();
@@ -595,14 +617,16 @@  discard block
 block discarded – undo
595 617
 				'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_liked_users['liked_user'] . '">' . $row_liked_users['real_name'] . '</a>',
596 618
 			);
597 619
 
598
-			if ($max_liked_users < $row_liked_users['count'])
599
-				$max_liked_users = $row_liked_users['count'];
620
+			if ($max_liked_users < $row_liked_users['count']) {
621
+							$max_liked_users = $row_liked_users['count'];
622
+			}
600 623
 		}
601 624
 
602 625
 		$smcFunc['db_free_result']($liked_users);
603 626
 
604
-		foreach ($context['stats_blocks']['liked_users'] as $i => $liked_users)
605
-			$context['stats_blocks']['liked_users'][$i]['percent'] = round(($liked_users['num'] * 100) / $max_liked_users);
627
+		foreach ($context['stats_blocks']['liked_users'] as $i => $liked_users) {
628
+					$context['stats_blocks']['liked_users'][$i]['percent'] = round(($liked_users['num'] * 100) / $max_liked_users);
629
+		}
606 630
 	}
607 631
 
608 632
 	// Activity by month.
@@ -620,8 +644,8 @@  discard block
 block discarded – undo
620 644
 		$ID_MONTH = $row_months['stats_year'] . sprintf('%02d', $row_months['stats_month']);
621 645
 		$expanded = !empty($_SESSION['expanded_stats'][$row_months['stats_year']]) && in_array($row_months['stats_month'], $_SESSION['expanded_stats'][$row_months['stats_year']]);
622 646
 
623
-		if (!isset($context['yearly'][$row_months['stats_year']]))
624
-			$context['yearly'][$row_months['stats_year']] = array(
647
+		if (!isset($context['yearly'][$row_months['stats_year']])) {
648
+					$context['yearly'][$row_months['stats_year']] = array(
625 649
 				'year' => $row_months['stats_year'],
626 650
 				'new_topics' => 0,
627 651
 				'new_posts' => 0,
@@ -633,6 +657,7 @@  discard block
 block discarded – undo
633 657
 				'expanded' => false,
634 658
 				'current_year' => $row_months['stats_year'] == date('Y'),
635 659
 			);
660
+		}
636 661
 
637 662
 		$context['yearly'][$row_months['stats_year']]['months'][(int) $row_months['stats_month']] = array(
638 663
 			'id' => $ID_MONTH,
@@ -678,26 +703,30 @@  discard block
 block discarded – undo
678 703
 		$context['yearly'][$year]['hits'] = comma_format($data['hits']);
679 704
 
680 705
 		// Keep a list of collapsed years.
681
-		if (!$data['expanded'] && !$data['current_year'])
682
-			$context['collapsed_years'][] = $year;
706
+		if (!$data['expanded'] && !$data['current_year']) {
707
+					$context['collapsed_years'][] = $year;
708
+		}
683 709
 	}
684 710
 
685
-	if (empty($_SESSION['expanded_stats']))
686
-		return;
711
+	if (empty($_SESSION['expanded_stats'])) {
712
+			return;
713
+	}
687 714
 
688 715
 	$condition_text = array();
689 716
 	$condition_params = array();
690
-	foreach ($_SESSION['expanded_stats'] as $year => $months)
691
-		if (!empty($months))
717
+	foreach ($_SESSION['expanded_stats'] as $year => $months) {
718
+			if (!empty($months))
692 719
 		{
693 720
 			$condition_text[] = 'YEAR(date) = {int:year_' . $year . '} AND MONTH(date) IN ({array_int:months_' . $year . '})';
721
+	}
694 722
 			$condition_params['year_' . $year] = $year;
695 723
 			$condition_params['months_' . $year] = $months;
696 724
 		}
697 725
 
698 726
 	// No daily stats to even look at?
699
-	if (empty($condition_text))
700
-		return;
727
+	if (empty($condition_text)) {
728
+			return;
729
+	}
701 730
 
702 731
 	getDailyStats(implode(' OR ', $condition_text), $condition_params);
703 732
 
@@ -723,8 +752,8 @@  discard block
 block discarded – undo
723 752
 		ORDER BY stats_day ASC',
724 753
 		$condition_parameters
725 754
 	);
726
-	while ($row_days = $smcFunc['db_fetch_assoc']($days_result))
727
-		$context['yearly'][$row_days['stats_year']]['months'][(int) $row_days['stats_month']]['days'][] = array(
755
+	while ($row_days = $smcFunc['db_fetch_assoc']($days_result)) {
756
+			$context['yearly'][$row_days['stats_year']]['months'][(int) $row_days['stats_month']]['days'][] = array(
728 757
 			'day' => sprintf('%02d', $row_days['stats_day']),
729 758
 			'month' => sprintf('%02d', $row_days['stats_month']),
730 759
 			'year' => $row_days['stats_year'],
@@ -734,6 +763,7 @@  discard block
 block discarded – undo
734 763
 			'most_members_online' => comma_format($row_days['most_on']),
735 764
 			'hits' => comma_format($row_days['hits'])
736 765
 		);
766
+	}
737 767
 	$smcFunc['db_free_result']($days_result);
738 768
 }
739 769
 
@@ -751,16 +781,19 @@  discard block
 block discarded – undo
751 781
 	global $modSettings, $user_info, $forum_version, $sourcedir;
752 782
 
753 783
 	// First, is it disabled?
754
-	if (empty($modSettings['enable_sm_stats']) || empty($modSettings['sm_stats_key']))
755
-		die();
784
+	if (empty($modSettings['enable_sm_stats']) || empty($modSettings['sm_stats_key'])) {
785
+			die();
786
+	}
756 787
 
757 788
 	// Are we saying who we are, and are we right? (OR an admin)
758
-	if (!$user_info['is_admin'] && (!isset($_GET['sid']) || $_GET['sid'] != $modSettings['sm_stats_key']))
759
-		die();
789
+	if (!$user_info['is_admin'] && (!isset($_GET['sid']) || $_GET['sid'] != $modSettings['sm_stats_key'])) {
790
+			die();
791
+	}
760 792
 
761 793
 	// Verify the referer...
762
-	if (!$user_info['is_admin'] && (!isset($_SERVER['HTTP_REFERER']) || md5($_SERVER['HTTP_REFERER']) != '746cb59a1a0d5cf4bd240e5a67c73085'))
763
-		die();
794
+	if (!$user_info['is_admin'] && (!isset($_SERVER['HTTP_REFERER']) || md5($_SERVER['HTTP_REFERER']) != '746cb59a1a0d5cf4bd240e5a67c73085')) {
795
+			die();
796
+	}
764 797
 
765 798
 	// Get some server versions.
766 799
 	require_once($sourcedir . '/Subs-Admin.php');
@@ -786,16 +819,17 @@  discard block
 block discarded – undo
786 819
 	);
787 820
 
788 821
 	// Encode all the data, for security.
789
-	foreach ($stats_to_send as $k => $v)
790
-		$stats_to_send[$k] = urlencode($k) . '=' . urlencode($v);
822
+	foreach ($stats_to_send as $k => $v) {
823
+			$stats_to_send[$k] = urlencode($k) . '=' . urlencode($v);
824
+	}
791 825
 
792 826
 	// Turn this into the query string!
793 827
 	$stats_to_send = implode('&', $stats_to_send);
794 828
 
795 829
 	// If we're an admin, just plonk them out.
796
-	if ($user_info['is_admin'])
797
-		echo $stats_to_send;
798
-	else
830
+	if ($user_info['is_admin']) {
831
+			echo $stats_to_send;
832
+	} else
799 833
 	{
800 834
 		// Connect to the collection script.
801 835
 		$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
Please login to merge, or discard this patch.
Sources/ManageServer.php 1 patch
Braces   +265 added lines, -204 removed lines patch added patch discarded remove patch
@@ -59,8 +59,9 @@  discard block
 block discarded – undo
59 59
  * @version 2.1 Beta 3
60 60
  */
61 61
 
62
-if (!defined('SMF'))
62
+if (!defined('SMF')) {
63 63
 	die('No direct access...');
64
+}
64 65
 
65 66
 /**
66 67
  * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects
@@ -111,10 +112,11 @@  discard block
 block discarded – undo
111 112
 	$settings_not_writable = !is_writable($boarddir . '/Settings.php');
112 113
 	$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
113 114
 
114
-	if ($settings_not_writable)
115
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
116
-	elseif ($settings_backup_fail)
117
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
115
+	if ($settings_not_writable) {
116
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
117
+	} elseif ($settings_backup_fail) {
118
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
119
+	}
118 120
 
119 121
 	$context['settings_not_writable'] = $settings_not_writable;
120 122
 
@@ -168,8 +170,9 @@  discard block
 block discarded – undo
168 170
 
169 171
 	call_integration_hook('integrate_general_settings', array(&$config_vars));
170 172
 
171
-	if ($return_config)
172
-		return $config_vars;
173
+	if ($return_config) {
174
+			return $config_vars;
175
+	}
173 176
 
174 177
 	// Setup the template stuff.
175 178
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save';
@@ -181,8 +184,9 @@  discard block
 block discarded – undo
181 184
 		call_integration_hook('integrate_save_general_settings');
182 185
 
183 186
 		// Are we saving the stat collection?
184
-		if (!empty($_POST['enable_sm_stats']) && empty($modSettings['sm_stats_key']))
185
-			registerSMStats();
187
+		if (!empty($_POST['enable_sm_stats']) && empty($modSettings['sm_stats_key'])) {
188
+					registerSMStats();
189
+		}
186 190
 
187 191
 		saveSettings($config_vars);
188 192
 		$_SESSION['adm-save'] = true;
@@ -238,8 +242,9 @@  discard block
 block discarded – undo
238 242
 
239 243
 	call_integration_hook('integrate_database_settings', array(&$config_vars));
240 244
 
241
-	if ($return_config)
242
-		return $config_vars;
245
+	if ($return_config) {
246
+			return $config_vars;
247
+	}
243 248
 
244 249
 	// Setup the template stuff.
245 250
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
@@ -314,13 +319,15 @@  discard block
 block discarded – undo
314 319
 		hideGlobalCookies();
315 320
 	});', true);
316 321
 
317
-	if (empty($user_settings['tfa_secret']))
318
-		addInlineJavaScript('');
322
+	if (empty($user_settings['tfa_secret'])) {
323
+			addInlineJavaScript('');
324
+	}
319 325
 
320 326
 	call_integration_hook('integrate_cookie_settings', array(&$config_vars));
321 327
 
322
-	if ($return_config)
323
-		return $config_vars;
328
+	if ($return_config) {
329
+			return $config_vars;
330
+	}
324 331
 
325 332
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
326 333
 	$context['settings_title'] = $txt['cookies_sessions_settings'];
@@ -331,11 +338,13 @@  discard block
 block discarded – undo
331 338
 		call_integration_hook('integrate_save_cookie_settings');
332 339
 
333 340
 		// Local and global do not play nicely together.
334
-		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
335
-			unset ($_POST['globalCookies']);
341
+		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) {
342
+					unset ($_POST['globalCookies']);
343
+		}
336 344
 
337
-		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
338
-			fatal_lang_error('invalid_cookie_domain', false);
345
+		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) {
346
+					fatal_lang_error('invalid_cookie_domain', false);
347
+		}
339 348
 
340 349
 		saveSettings($config_vars);
341 350
 
@@ -418,8 +427,9 @@  discard block
 block discarded – undo
418 427
 
419 428
 	call_integration_hook('integrate_general_security_settings', array(&$config_vars));
420 429
 
421
-	if ($return_config)
422
-		return $config_vars;
430
+	if ($return_config) {
431
+			return $config_vars;
432
+	}
423 433
 
424 434
 	// Saving?
425 435
 	if (isset($_GET['save']))
@@ -458,8 +468,7 @@  discard block
 block discarded – undo
458 468
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
459 469
 		$cache_level = array($txt['cache_off']);
460 470
 		$detected['none'] = $txt['cache_off'];
461
-	}
462
-	else
471
+	} else
463 472
 	{
464 473
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
465 474
 		$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
@@ -496,8 +505,9 @@  discard block
 block discarded – undo
496 505
 			}
497 506
 		}
498 507
 	}
499
-	if ($return_config)
500
-		return $config_vars;
508
+	if ($return_config) {
509
+			return $config_vars;
510
+	}
501 511
 
502 512
 	// Saving again?
503 513
 	if (isset($_GET['save']))
@@ -525,8 +535,9 @@  discard block
 block discarded – undo
525 535
 	$context['save_disabled'] = $context['settings_not_writable'];
526 536
 
527 537
 	// Decide what message to show.
528
-	if (!$context['save_disabled'])
529
-		$context['settings_message'] = $txt['caching_information'];
538
+	if (!$context['save_disabled']) {
539
+			$context['settings_message'] = $txt['caching_information'];
540
+	}
530 541
 
531 542
 	// Prepare the template.
532 543
 	prepareServerSettingsContext($config_vars);
@@ -549,24 +560,25 @@  discard block
 block discarded – undo
549 560
 	if (stripos(PHP_OS, 'win') === 0)
550 561
 	{
551 562
 		$context['settings_message'] = $txt['loadavg_disabled_windows'];
552
-		if (isset($_GET['save']))
553
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
554
-	}
555
-	elseif (stripos(PHP_OS, 'darwin') === 0)
563
+		if (isset($_GET['save'])) {
564
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
565
+		}
566
+	} elseif (stripos(PHP_OS, 'darwin') === 0)
556 567
 	{
557 568
 		$context['settings_message'] = $txt['loadavg_disabled_osx'];
558
-		if (isset($_GET['save']))
559
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
560
-	}
561
-	else
569
+		if (isset($_GET['save'])) {
570
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
571
+		}
572
+	} else
562 573
 	{
563 574
 		$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
564
-		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
565
-			$modSettings['load_average'] = (float) $matches[1];
566
-		elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
567
-			$modSettings['load_average'] = (float) $matches[1];
568
-		else
569
-			unset($modSettings['load_average']);
575
+		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) {
576
+					$modSettings['load_average'] = (float) $matches[1];
577
+		} elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) {
578
+					$modSettings['load_average'] = (float) $matches[1];
579
+		} else {
580
+					unset($modSettings['load_average']);
581
+		}
570 582
 
571 583
 		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
572 584
 		{
@@ -602,8 +614,9 @@  discard block
 block discarded – undo
602 614
 
603 615
 	call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
604 616
 
605
-	if ($return_config)
606
-		return $config_vars;
617
+	if ($return_config) {
618
+			return $config_vars;
619
+	}
607 620
 
608 621
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
609 622
 	$context['settings_title'] = $txt['load_balancing_settings'];
@@ -614,24 +627,27 @@  discard block
 block discarded – undo
614 627
 		// Stupidity is not allowed.
615 628
 		foreach ($_POST as $key => $value)
616 629
 		{
617
-			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values)))
618
-				continue;
619
-			else
620
-				$_POST[$key] = (float) $value;
621
-
622
-			if ($key == 'loadavg_auto_opt' && $value <= 1)
623
-				$_POST['loadavg_auto_opt'] = 1.0;
624
-			elseif ($key == 'loadavg_forum' && $value < 10)
625
-				$_POST['loadavg_forum'] = 10.0;
626
-			elseif ($value < 2)
627
-				$_POST[$key] = 2.0;
630
+			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) {
631
+							continue;
632
+			} else {
633
+							$_POST[$key] = (float) $value;
634
+			}
635
+
636
+			if ($key == 'loadavg_auto_opt' && $value <= 1) {
637
+							$_POST['loadavg_auto_opt'] = 1.0;
638
+			} elseif ($key == 'loadavg_forum' && $value < 10) {
639
+							$_POST['loadavg_forum'] = 10.0;
640
+			} elseif ($value < 2) {
641
+							$_POST[$key] = 2.0;
642
+			}
628 643
 		}
629 644
 
630 645
 		call_integration_hook('integrate_save_loadavg_settings');
631 646
 
632 647
 		saveDBSettings($config_vars);
633
-		if (!isset($_SESSION['adm-save']))
634
-			$_SESSION['adm-save'] = true;
648
+		if (!isset($_SESSION['adm-save'])) {
649
+					$_SESSION['adm-save'] = true;
650
+		}
635 651
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
636 652
 	}
637 653
 
@@ -667,10 +683,11 @@  discard block
 block discarded – undo
667 683
 
668 684
 	if (isset($_SESSION['adm-save']))
669 685
 	{
670
-		if ($_SESSION['adm-save'] === true)
671
-			$context['saved_successful'] = true;
672
-		else
673
-			$context['saved_failed'] = $_SESSION['adm-save'];
686
+		if ($_SESSION['adm-save'] === true) {
687
+					$context['saved_successful'] = true;
688
+		} else {
689
+					$context['saved_failed'] = $_SESSION['adm-save'];
690
+		}
674 691
 
675 692
 		unset($_SESSION['adm-save']);
676 693
 	}
@@ -678,9 +695,9 @@  discard block
 block discarded – undo
678 695
 	$context['config_vars'] = array();
679 696
 	foreach ($config_vars as $identifier => $config_var)
680 697
 	{
681
-		if (!is_array($config_var) || !isset($config_var[1]))
682
-			$context['config_vars'][] = $config_var;
683
-		else
698
+		if (!is_array($config_var) || !isset($config_var[1])) {
699
+					$context['config_vars'][] = $config_var;
700
+		} else
684 701
 		{
685 702
 			$varname = $config_var[0];
686 703
 			global $$varname;
@@ -715,16 +732,19 @@  discard block
 block discarded – undo
715 732
 			if ($config_var[3] == 'int' || $config_var[3] == 'float')
716 733
 			{
717 734
 				// Default to a min of 0 if one isn't set
718
-				if (isset($config_var['min']))
719
-					$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
720
-				else
721
-					$context['config_vars'][$config_var[0]]['min'] = 0;
735
+				if (isset($config_var['min'])) {
736
+									$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
737
+				} else {
738
+									$context['config_vars'][$config_var[0]]['min'] = 0;
739
+				}
722 740
 
723
-				if (isset($config_var['max']))
724
-					$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
741
+				if (isset($config_var['max'])) {
742
+									$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
743
+				}
725 744
 
726
-				if (isset($config_var['step']))
727
-					$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
745
+				if (isset($config_var['step'])) {
746
+									$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
747
+				}
728 748
 			}
729 749
 
730 750
 			// If this is a select box handle any data.
@@ -732,12 +752,13 @@  discard block
 block discarded – undo
732 752
 			{
733 753
 				// If it's associative
734 754
 				$config_values = array_values($config_var[4]);
735
-				if (isset($config_values[0]) && is_array($config_values[0]))
736
-					$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
737
-				else
755
+				if (isset($config_values[0]) && is_array($config_values[0])) {
756
+									$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
757
+				} else
738 758
 				{
739
-					foreach ($config_var[4] as $key => $item)
740
-						$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
759
+					foreach ($config_var[4] as $key => $item) {
760
+											$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
761
+					}
741 762
 				}
742 763
 			}
743 764
 		}
@@ -762,10 +783,11 @@  discard block
 block discarded – undo
762 783
 
763 784
 	if (isset($_SESSION['adm-save']))
764 785
 	{
765
-		if ($_SESSION['adm-save'] === true)
766
-			$context['saved_successful'] = true;
767
-		else
768
-			$context['saved_failed'] = $_SESSION['adm-save'];
786
+		if ($_SESSION['adm-save'] === true) {
787
+					$context['saved_successful'] = true;
788
+		} else {
789
+					$context['saved_failed'] = $_SESSION['adm-save'];
790
+		}
769 791
 
770 792
 		unset($_SESSION['adm-save']);
771 793
 	}
@@ -777,26 +799,30 @@  discard block
 block discarded – undo
777 799
 	foreach ($config_vars as $config_var)
778 800
 	{
779 801
 		// HR?
780
-		if (!is_array($config_var))
781
-			$context['config_vars'][] = $config_var;
782
-		else
802
+		if (!is_array($config_var)) {
803
+					$context['config_vars'][] = $config_var;
804
+		} else
783 805
 		{
784 806
 			// If it has no name it doesn't have any purpose!
785
-			if (empty($config_var[1]))
786
-				continue;
807
+			if (empty($config_var[1])) {
808
+							continue;
809
+			}
787 810
 
788 811
 			// Special case for inline permissions
789
-			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
790
-				$inlinePermissions[] = $config_var[1];
791
-			elseif ($config_var[0] == 'permissions')
792
-				continue;
812
+			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
813
+							$inlinePermissions[] = $config_var[1];
814
+			} elseif ($config_var[0] == 'permissions') {
815
+							continue;
816
+			}
793 817
 
794
-			if ($config_var[0] == 'boards')
795
-				$board_list = true;
818
+			if ($config_var[0] == 'boards') {
819
+							$board_list = true;
820
+			}
796 821
 
797 822
 			// Are we showing the BBC selection box?
798
-			if ($config_var[0] == 'bbc')
799
-				$bbcChoice[] = $config_var[1];
823
+			if ($config_var[0] == 'bbc') {
824
+							$bbcChoice[] = $config_var[1];
825
+			}
800 826
 
801 827
 			// We need to do some parsing of the value before we pass it in.
802 828
 			if (isset($modSettings[$config_var[1]]))
@@ -815,8 +841,7 @@  discard block
 block discarded – undo
815 841
 					default:
816 842
 						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
817 843
 				}
818
-			}
819
-			else
844
+			} else
820 845
 			{
821 846
 				// Darn, it's empty. What type is expected?
822 847
 				switch ($config_var[0])
@@ -856,16 +881,19 @@  discard block
 block discarded – undo
856 881
 			if ($config_var[0] == 'int' || $config_var[0] == 'float')
857 882
 			{
858 883
 				// Default to a min of 0 if one isn't set
859
-				if (isset($config_var['min']))
860
-					$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
861
-				else
862
-					$context['config_vars'][$config_var[1]]['min'] = 0;
884
+				if (isset($config_var['min'])) {
885
+									$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
886
+				} else {
887
+									$context['config_vars'][$config_var[1]]['min'] = 0;
888
+				}
863 889
 
864
-				if (isset($config_var['max']))
865
-					$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
890
+				if (isset($config_var['max'])) {
891
+									$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
892
+				}
866 893
 
867
-				if (isset($config_var['step']))
868
-					$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
894
+				if (isset($config_var['step'])) {
895
+									$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
896
+				}
869 897
 			}
870 898
 
871 899
 			// If this is a select box handle any data.
@@ -879,12 +907,13 @@  discard block
 block discarded – undo
879 907
 				}
880 908
 
881 909
 				// If it's associative
882
-				if (isset($config_var[2][0]) && is_array($config_var[2][0]))
883
-					$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
884
-				else
910
+				if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
911
+									$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
912
+				} else
885 913
 				{
886
-					foreach ($config_var[2] as $key => $item)
887
-						$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
914
+					foreach ($config_var[2] as $key => $item) {
915
+											$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
916
+					}
888 917
 				}
889 918
 			}
890 919
 
@@ -893,17 +922,19 @@  discard block
 block discarded – undo
893 922
 			{
894 923
 				if (!is_numeric($k))
895 924
 				{
896
-					if (substr($k, 0, 2) == 'on')
897
-						$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
898
-					else
899
-						$context['config_vars'][$config_var[1]][$k] = $v;
925
+					if (substr($k, 0, 2) == 'on') {
926
+											$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
927
+					} else {
928
+											$context['config_vars'][$config_var[1]][$k] = $v;
929
+					}
900 930
 				}
901 931
 
902 932
 				// See if there are any other labels that might fit?
903
-				if (isset($txt['setting_' . $config_var[1]]))
904
-					$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
905
-				elseif (isset($txt['groups_' . $config_var[1]]))
906
-					$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
933
+				if (isset($txt['setting_' . $config_var[1]])) {
934
+									$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
935
+				} elseif (isset($txt['groups_' . $config_var[1]])) {
936
+									$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
937
+				}
907 938
 			}
908 939
 
909 940
 			// Set the subtext in case it's part of the label.
@@ -936,8 +967,9 @@  discard block
 block discarded – undo
936 967
 		// What are the options, eh?
937 968
 		$temp = parse_bbc(false);
938 969
 		$bbcTags = array();
939
-		foreach ($temp as $tag)
940
-			$bbcTags[] = $tag['tag'];
970
+		foreach ($temp as $tag) {
971
+					$bbcTags[] = $tag['tag'];
972
+		}
941 973
 
942 974
 		$bbcTags = array_unique($bbcTags);
943 975
 		$totalTags = count($bbcTags);
@@ -952,8 +984,9 @@  discard block
 block discarded – undo
952 984
 		$col = 0; $i = 0;
953 985
 		foreach ($bbcTags as $tag)
954 986
 		{
955
-			if ($i % $tagsPerColumn == 0 && $i != 0)
956
-				$col++;
987
+			if ($i % $tagsPerColumn == 0 && $i != 0) {
988
+							$col++;
989
+			}
957 990
 
958 991
 			$context['bbc_columns'][$col][] = array(
959 992
 				'tag' => $tag,
@@ -996,18 +1029,21 @@  discard block
 block discarded – undo
996 1029
 	validateToken('admin-ssc');
997 1030
 
998 1031
 	// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
999
-	if (isset($_POST['cookiename']))
1000
-		$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1032
+	if (isset($_POST['cookiename'])) {
1033
+			$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1034
+	}
1001 1035
 
1002 1036
 	// Fix the forum's URL if necessary.
1003 1037
 	if (isset($_POST['boardurl']))
1004 1038
 	{
1005
-		if (substr($_POST['boardurl'], -10) == '/index.php')
1006
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1007
-		elseif (substr($_POST['boardurl'], -1) == '/')
1008
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1009
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1010
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1039
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1040
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1041
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1042
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1043
+		}
1044
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1045
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1046
+		}
1011 1047
 	}
1012 1048
 
1013 1049
 	// Any passwords?
@@ -1042,21 +1078,21 @@  discard block
 block discarded – undo
1042 1078
 	// Figure out which config vars we're saving here...
1043 1079
 	foreach ($config_vars as $var)
1044 1080
 	{
1045
-		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]])))
1046
-			continue;
1081
+		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) {
1082
+					continue;
1083
+		}
1047 1084
 
1048 1085
 		$config_var = $var[0];
1049 1086
 
1050 1087
 		if (in_array($config_var, $config_passwords))
1051 1088
 		{
1052
-			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
1053
-				$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1054
-		}
1055
-		elseif (in_array($config_var, $config_strs))
1089
+			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) {
1090
+							$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1091
+			}
1092
+		} elseif (in_array($config_var, $config_strs))
1056 1093
 		{
1057 1094
 			$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
1058
-		}
1059
-		elseif (in_array($config_var, $config_ints))
1095
+		} elseif (in_array($config_var, $config_ints))
1060 1096
 		{
1061 1097
 			$new_settings[$config_var] = (int) $_POST[$config_var];
1062 1098
 
@@ -1065,17 +1101,17 @@  discard block
 block discarded – undo
1065 1101
 			$new_settings[$config_var] = max($min, $new_settings[$config_var]);
1066 1102
 
1067 1103
 			// Is there a max value for this as well?
1068
-			if (isset($var['max']))
1069
-				$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1070
-		}
1071
-		elseif (in_array($config_var, $config_bools))
1104
+			if (isset($var['max'])) {
1105
+							$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1106
+			}
1107
+		} elseif (in_array($config_var, $config_bools))
1072 1108
 		{
1073
-			if (!empty($_POST[$config_var]))
1074
-				$new_settings[$config_var] = '1';
1075
-			else
1076
-				$new_settings[$config_var] = '0';
1077
-		}
1078
-		else
1109
+			if (!empty($_POST[$config_var])) {
1110
+							$new_settings[$config_var] = '1';
1111
+			} else {
1112
+							$new_settings[$config_var] = '0';
1113
+			}
1114
+		} else
1079 1115
 		{
1080 1116
 			// This shouldn't happen, but it might...
1081 1117
 			fatal_error('Unknown config_var \'' . $config_var . '\'');
@@ -1091,30 +1127,35 @@  discard block
 block discarded – undo
1091 1127
 	foreach ($config_vars as $config_var)
1092 1128
 	{
1093 1129
 		// We just saved the file-based settings, so skip their definitions.
1094
-		if (!is_array($config_var) || $config_var[2] == 'file')
1095
-			continue;
1130
+		if (!is_array($config_var) || $config_var[2] == 'file') {
1131
+					continue;
1132
+		}
1096 1133
 
1097 1134
 		$new_setting = array($config_var[3], $config_var[0]);
1098 1135
 
1099 1136
 		// Select options need carried over, too.
1100
-		if (isset($config_var[4]))
1101
-			$new_setting[] = $config_var[4];
1137
+		if (isset($config_var[4])) {
1138
+					$new_setting[] = $config_var[4];
1139
+		}
1102 1140
 
1103 1141
 		// Include min and max if necessary
1104
-		if (isset($config_var['min']))
1105
-			$new_setting['min'] = $config_var['min'];
1142
+		if (isset($config_var['min'])) {
1143
+					$new_setting['min'] = $config_var['min'];
1144
+		}
1106 1145
 
1107
-		if (isset($config_var['max']))
1108
-			$new_setting['max'] = $config_var['max'];
1146
+		if (isset($config_var['max'])) {
1147
+					$new_setting['max'] = $config_var['max'];
1148
+		}
1109 1149
 
1110 1150
 		// Rewrite the definition a bit.
1111 1151
 		$new_settings[] = $new_setting;
1112 1152
 	}
1113 1153
 
1114 1154
 	// Save the new database-based settings, if any.
1115
-	if (!empty($new_settings))
1116
-		saveDBSettings($new_settings);
1117
-}
1155
+	if (!empty($new_settings)) {
1156
+			saveDBSettings($new_settings);
1157
+	}
1158
+	}
1118 1159
 
1119 1160
 /**
1120 1161
  * Helper function for saving database settings.
@@ -1132,22 +1173,25 @@  discard block
 block discarded – undo
1132 1173
 	$inlinePermissions = array();
1133 1174
 	foreach ($config_vars as $var)
1134 1175
 	{
1135
-		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags']))))
1136
-			continue;
1176
+		if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) {
1177
+					continue;
1178
+		}
1137 1179
 
1138 1180
 		// Checkboxes!
1139
-		elseif ($var[0] == 'check')
1140
-			$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1181
+		elseif ($var[0] == 'check') {
1182
+					$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1183
+		}
1141 1184
 		// Select boxes!
1142
-		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
1143
-			$setArray[$var[1]] = $_POST[$var[1]];
1144
-		elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1185
+		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) {
1186
+					$setArray[$var[1]] = $_POST[$var[1]];
1187
+		} elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1145 1188
 		{
1146 1189
 			// For security purposes we validate this line by line.
1147 1190
 			$lOptions = array();
1148
-			foreach ($_POST[$var[1]] as $invar)
1149
-				if (in_array($invar, array_keys($var[2])))
1191
+			foreach ($_POST[$var[1]] as $invar) {
1192
+							if (in_array($invar, array_keys($var[2])))
1150 1193
 					$lOptions[] = $invar;
1194
+			}
1151 1195
 
1152 1196
 			$setArray[$var[1]] = json_encode($lOptions);
1153 1197
 		}
@@ -1161,18 +1205,20 @@  discard block
 block discarded – undo
1161 1205
 				$request = $smcFunc['db_query']('', '
1162 1206
 					SELECT id_board
1163 1207
 					FROM {db_prefix}boards');
1164
-				while ($row = $smcFunc['db_fetch_row']($request))
1165
-					$board_list[$row[0]] = true;
1208
+				while ($row = $smcFunc['db_fetch_row']($request)) {
1209
+									$board_list[$row[0]] = true;
1210
+				}
1166 1211
 
1167 1212
 				$smcFunc['db_free_result']($request);
1168 1213
 			}
1169 1214
 
1170 1215
 			$lOptions = array();
1171 1216
 
1172
-			if (!empty($_POST[$var[1]]))
1173
-				foreach ($_POST[$var[1]] as $invar => $dummy)
1217
+			if (!empty($_POST[$var[1]])) {
1218
+							foreach ($_POST[$var[1]] as $invar => $dummy)
1174 1219
 					if (isset($board_list[$invar]))
1175 1220
 						$lOptions[] = $invar;
1221
+			}
1176 1222
 
1177 1223
 			$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : '';
1178 1224
 		}
@@ -1186,8 +1232,9 @@  discard block
 block discarded – undo
1186 1232
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1187 1233
 
1188 1234
 			// Do we have a max value for this as well?
1189
-			if (isset($var['max']))
1190
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1235
+			if (isset($var['max'])) {
1236
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1237
+			}
1191 1238
 		}
1192 1239
 		// Floating point!
1193 1240
 		elseif ($var[0] == 'float')
@@ -1199,40 +1246,47 @@  discard block
 block discarded – undo
1199 1246
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1200 1247
 
1201 1248
 			// Do we have a max value for this as well?
1202
-			if (isset($var['max']))
1203
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1249
+			if (isset($var['max'])) {
1250
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1251
+			}
1204 1252
 		}
1205 1253
 		// Text!
1206
-		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time')))
1207
-			$setArray[$var[1]] = $_POST[$var[1]];
1254
+		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) {
1255
+					$setArray[$var[1]] = $_POST[$var[1]];
1256
+		}
1208 1257
 		// Passwords!
1209 1258
 		elseif ($var[0] == 'password')
1210 1259
 		{
1211
-			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
1212
-				$setArray[$var[1]] = $_POST[$var[1]][0];
1260
+			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) {
1261
+							$setArray[$var[1]] = $_POST[$var[1]][0];
1262
+			}
1213 1263
 		}
1214 1264
 		// BBC.
1215 1265
 		elseif ($var[0] == 'bbc')
1216 1266
 		{
1217 1267
 
1218 1268
 			$bbcTags = array();
1219
-			foreach (parse_bbc(false) as $tag)
1220
-				$bbcTags[] = $tag['tag'];
1269
+			foreach (parse_bbc(false) as $tag) {
1270
+							$bbcTags[] = $tag['tag'];
1271
+			}
1221 1272
 
1222
-			if (!isset($_POST[$var[1] . '_enabledTags']))
1223
-				$_POST[$var[1] . '_enabledTags'] = array();
1224
-			elseif (!is_array($_POST[$var[1] . '_enabledTags']))
1225
-				$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1273
+			if (!isset($_POST[$var[1] . '_enabledTags'])) {
1274
+							$_POST[$var[1] . '_enabledTags'] = array();
1275
+			} elseif (!is_array($_POST[$var[1] . '_enabledTags'])) {
1276
+							$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1277
+			}
1226 1278
 
1227 1279
 			$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
1228 1280
 		}
1229 1281
 		// Permissions?
1230
-		elseif ($var[0] == 'permissions')
1231
-			$inlinePermissions[] = $var[1];
1282
+		elseif ($var[0] == 'permissions') {
1283
+					$inlinePermissions[] = $var[1];
1284
+		}
1232 1285
 	}
1233 1286
 
1234
-	if (!empty($setArray))
1235
-		updateSettings($setArray);
1287
+	if (!empty($setArray)) {
1288
+			updateSettings($setArray);
1289
+	}
1236 1290
 
1237 1291
 	// If we have inline permissions we need to save them.
1238 1292
 	if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
@@ -1269,18 +1323,21 @@  discard block
 block discarded – undo
1269 1323
 	// put all of it into an array
1270 1324
 	foreach ($info_lines as $line)
1271 1325
 	{
1272
-		if (preg_match('~(' . $remove . ')~', $line))
1273
-			continue;
1326
+		if (preg_match('~(' . $remove . ')~', $line)) {
1327
+					continue;
1328
+		}
1274 1329
 
1275 1330
 		// new category?
1276
-		if (strpos($line, '<h2>') !== false)
1277
-			$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1331
+		if (strpos($line, '<h2>') !== false) {
1332
+					$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1333
+		}
1278 1334
 
1279 1335
 		// load it as setting => value or the old setting local master
1280
-		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1281
-			$pinfo[$category][$val[1]] = $val[2];
1282
-		elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1283
-			$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1336
+		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1337
+					$pinfo[$category][$val[1]] = $val[2];
1338
+		} elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1339
+					$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1340
+		}
1284 1341
 	}
1285 1342
 
1286 1343
 	// load it in to context and display it
@@ -1315,8 +1372,9 @@  discard block
 block discarded – undo
1315 1372
 				$testAPI = new $cache_class_name();
1316 1373
 
1317 1374
 				// No Support?  NEXT!
1318
-				if (!$testAPI->isSupported(true))
1319
-					continue;
1375
+				if (!$testAPI->isSupported(true)) {
1376
+									continue;
1377
+				}
1320 1378
 
1321 1379
 				$apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache;
1322 1380
 			}
@@ -1341,8 +1399,9 @@  discard block
 block discarded – undo
1341 1399
 	global $modSettings, $boardurl, $smcFunc;
1342 1400
 
1343 1401
 	// Already have a key?  Can't register again.
1344
-	if (!empty($modSettings['sm_stats_key']))
1345
-		return true;
1402
+	if (!empty($modSettings['sm_stats_key'])) {
1403
+			return true;
1404
+	}
1346 1405
 
1347 1406
 	$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
1348 1407
 	if ($fp)
@@ -1353,21 +1412,23 @@  discard block
 block discarded – undo
1353 1412
 		fwrite($fp, $out);
1354 1413
 
1355 1414
 		$return_data = '';
1356
-		while (!feof($fp))
1357
-			$return_data .= fgets($fp, 128);
1415
+		while (!feof($fp)) {
1416
+					$return_data .= fgets($fp, 128);
1417
+		}
1358 1418
 
1359 1419
 		fclose($fp);
1360 1420
 
1361 1421
 		// Get the unique site ID.
1362 1422
 		preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1363 1423
 
1364
-		if (!empty($ID[1]))
1365
-			$smcFunc['db_insert']('replace',
1424
+		if (!empty($ID[1])) {
1425
+					$smcFunc['db_insert']('replace',
1366 1426
 				'{db_prefix}settings',
1367 1427
 				array('variable' => 'string', 'value' => 'string'),
1368 1428
 				array('sm_stats_key', $ID[1]),
1369 1429
 				array('variable')
1370 1430
 			);
1431
+		}
1371 1432
 	}
1372 1433
 }
1373 1434
 
Please login to merge, or discard this patch.