Completed
Pull Request — release-2.1 (#4069)
by Jeremy
08:10
created
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.
other/upgrade.php 1 patch
Braces   +878 added lines, -645 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']))
@@ -948,16 +1007,17 @@  discard block
 block discarded – undo
948 1007
 				fwrite($fp, $out);
949 1008
 
950 1009
 				$return_data = '';
951
-				while (!feof($fp))
952
-					$return_data .= fgets($fp, 128);
1010
+				while (!feof($fp)) {
1011
+									$return_data .= fgets($fp, 128);
1012
+				}
953 1013
 
954 1014
 				fclose($fp);
955 1015
 
956 1016
 				// Get the unique site ID.
957 1017
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
958 1018
 
959
-				if (!empty($ID[1]))
960
-					$smcFunc['db_insert']('replace',
1019
+				if (!empty($ID[1])) {
1020
+									$smcFunc['db_insert']('replace',
961 1021
 						$db_prefix . 'settings',
962 1022
 						array('variable' => 'string', 'value' => 'string'),
963 1023
 						array(
@@ -966,9 +1026,9 @@  discard block
 block discarded – undo
966 1026
 						),
967 1027
 						array('variable')
968 1028
 					);
1029
+				}
969 1030
 			}
970
-		}
971
-		else
1031
+		} else
972 1032
 		{
973 1033
 			$smcFunc['db_insert']('replace',
974 1034
 				$db_prefix . 'settings',
@@ -979,8 +1039,8 @@  discard block
 block discarded – undo
979 1039
 		}
980 1040
 	}
981 1041
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
982
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
983
-		$smcFunc['db_query']('', '
1042
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1043
+			$smcFunc['db_query']('', '
984 1044
 			DELETE FROM {db_prefix}settings
985 1045
 			WHERE variable = {string:enable_sm_stats}',
986 1046
 			array(
@@ -988,6 +1048,7 @@  discard block
 block discarded – undo
988 1048
 				'db_error_skip' => true,
989 1049
 			)
990 1050
 		);
1051
+	}
991 1052
 
992 1053
 	// Deleting old karma stuff?
993 1054
 	if (!empty($_POST['delete_karma']))
@@ -1002,20 +1063,22 @@  discard block
 block discarded – undo
1002 1063
 		);
1003 1064
 
1004 1065
 		// Cleaning up old karma member settings.
1005
-		if ($upcontext['karma_installed']['good'])
1006
-			$smcFunc['db_query']('', '
1066
+		if ($upcontext['karma_installed']['good']) {
1067
+					$smcFunc['db_query']('', '
1007 1068
 				ALTER TABLE {db_prefix}members
1008 1069
 				DROP karma_good',
1009 1070
 				array()
1010 1071
 			);
1072
+		}
1011 1073
 
1012 1074
 		// Does karma bad was enable?
1013
-		if ($upcontext['karma_installed']['bad'])
1014
-			$smcFunc['db_query']('', '
1075
+		if ($upcontext['karma_installed']['bad']) {
1076
+					$smcFunc['db_query']('', '
1015 1077
 				ALTER TABLE {db_prefix}members
1016 1078
 				DROP karma_bad',
1017 1079
 				array()
1018 1080
 			);
1081
+		}
1019 1082
 
1020 1083
 		// Cleaning up old karma permissions.
1021 1084
 		$smcFunc['db_query']('', '
@@ -1028,26 +1091,29 @@  discard block
 block discarded – undo
1028 1091
 	}
1029 1092
 
1030 1093
 	// Emptying the error log?
1031
-	if (!empty($_POST['empty_error']))
1032
-		$smcFunc['db_query']('truncate_table', '
1094
+	if (!empty($_POST['empty_error'])) {
1095
+			$smcFunc['db_query']('truncate_table', '
1033 1096
 			TRUNCATE {db_prefix}log_errors',
1034 1097
 			array(
1035 1098
 			)
1036 1099
 		);
1100
+	}
1037 1101
 
1038 1102
 	$changes = array();
1039 1103
 
1040 1104
 	// Add proxy settings.
1041
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1042
-		$changes += array(
1105
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1106
+			$changes += array(
1043 1107
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1044 1108
 			'image_proxy_maxsize' => 5190,
1045 1109
 			'image_proxy_enabled' => 0,
1046 1110
 		);
1111
+	}
1047 1112
 
1048 1113
 	// If we're overriding the language follow it through.
1049
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1050
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1114
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1115
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1116
+	}
1051 1117
 
1052 1118
 	if (!empty($_POST['maint']))
1053 1119
 	{
@@ -1059,30 +1125,34 @@  discard block
 block discarded – undo
1059 1125
 		{
1060 1126
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1061 1127
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1062
-		}
1063
-		else
1128
+		} else
1064 1129
 		{
1065 1130
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1066 1131
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1067 1132
 		}
1068 1133
 	}
1069 1134
 
1070
-	if ($command_line)
1071
-		echo ' * Updating Settings.php...';
1135
+	if ($command_line) {
1136
+			echo ' * Updating Settings.php...';
1137
+	}
1072 1138
 
1073 1139
 	// Fix some old paths.
1074
-	if (substr($boarddir, 0, 1) == '.')
1075
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1140
+	if (substr($boarddir, 0, 1) == '.') {
1141
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1142
+	}
1076 1143
 
1077
-	if (substr($sourcedir, 0, 1) == '.')
1078
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1144
+	if (substr($sourcedir, 0, 1) == '.') {
1145
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1146
+	}
1079 1147
 
1080
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1081
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1148
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1149
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1150
+	}
1082 1151
 
1083 1152
 	// Not had the database type added before?
1084
-	if (empty($db_type))
1085
-		$changes['db_type'] = 'mysql';
1153
+	if (empty($db_type)) {
1154
+			$changes['db_type'] = 'mysql';
1155
+	}
1086 1156
 
1087 1157
 	// If they have a "host:port" setup for the host, split that into separate values
1088 1158
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1093,32 +1163,36 @@  discard block
 block discarded – undo
1093 1163
 		$changes['db_server'] = '\'' . $db_server . '\'';
1094 1164
 
1095 1165
 		// Only set this if we're not using the default port
1096
-		if ($db_port != ini_get('mysqli.default_port'))
1097
-			$changes['db_port'] = (int) $db_port;
1098
-	}
1099
-	elseif (!empty($db_port))
1166
+		if ($db_port != ini_get('mysqli.default_port')) {
1167
+					$changes['db_port'] = (int) $db_port;
1168
+		}
1169
+	} elseif (!empty($db_port))
1100 1170
 	{
1101 1171
 		// If db_port is set and is the same as the default, set it to ''
1102 1172
 		if ($db_type == 'mysql')
1103 1173
 		{
1104
-			if ($db_port == ini_get('mysqli.default_port'))
1105
-				$changes['db_port'] = '\'\'';
1106
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1107
-				$changes['db_port'] = '\'\'';
1174
+			if ($db_port == ini_get('mysqli.default_port')) {
1175
+							$changes['db_port'] = '\'\'';
1176
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1177
+							$changes['db_port'] = '\'\'';
1178
+			}
1108 1179
 		}
1109 1180
 	}
1110 1181
 
1111 1182
 	// Maybe we haven't had this option yet?
1112
-	if (empty($packagesdir))
1113
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1183
+	if (empty($packagesdir)) {
1184
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1185
+	}
1114 1186
 
1115 1187
 	// Add support for $tasksdir var.
1116
-	if (empty($tasksdir))
1117
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1188
+	if (empty($tasksdir)) {
1189
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1190
+	}
1118 1191
 
1119 1192
 	// Make sure we fix the language as well.
1120
-	if (stristr($language, '-utf8'))
1121
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1193
+	if (stristr($language, '-utf8')) {
1194
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1195
+	}
1122 1196
 
1123 1197
 	// @todo Maybe change the cookie name if going to 1.1, too?
1124 1198
 
@@ -1126,8 +1200,9 @@  discard block
 block discarded – undo
1126 1200
 	require_once($sourcedir . '/Subs-Admin.php');
1127 1201
 	updateSettingsFile($changes);
1128 1202
 
1129
-	if ($command_line)
1130
-		echo ' Successful.' . "\n";
1203
+	if ($command_line) {
1204
+			echo ' Successful.' . "\n";
1205
+	}
1131 1206
 
1132 1207
 	// Are we doing debug?
1133 1208
 	if (isset($_POST['debug']))
@@ -1137,8 +1212,9 @@  discard block
 block discarded – undo
1137 1212
 	}
1138 1213
 
1139 1214
 	// If we're not backing up then jump one.
1140
-	if (empty($_POST['backup']))
1141
-		$upcontext['current_step']++;
1215
+	if (empty($_POST['backup'])) {
1216
+			$upcontext['current_step']++;
1217
+	}
1142 1218
 
1143 1219
 	// If we've got here then let's proceed to the next step!
1144 1220
 	return true;
@@ -1153,8 +1229,9 @@  discard block
 block discarded – undo
1153 1229
 	$upcontext['page_title'] = 'Backup Database';
1154 1230
 
1155 1231
 	// Done it already - js wise?
1156
-	if (!empty($_POST['backup_done']))
1157
-		return true;
1232
+	if (!empty($_POST['backup_done'])) {
1233
+			return true;
1234
+	}
1158 1235
 
1159 1236
 	// Some useful stuff here.
1160 1237
 	db_extend();
@@ -1168,9 +1245,10 @@  discard block
 block discarded – undo
1168 1245
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1169 1246
 
1170 1247
 	$table_names = array();
1171
-	foreach ($tables as $table)
1172
-		if (substr($table, 0, 7) !== 'backup_')
1248
+	foreach ($tables as $table) {
1249
+			if (substr($table, 0, 7) !== 'backup_')
1173 1250
 			$table_names[] = $table;
1251
+	}
1174 1252
 
1175 1253
 	$upcontext['table_count'] = count($table_names);
1176 1254
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1180,12 +1258,14 @@  discard block
 block discarded – undo
1180 1258
 	$file_steps = $upcontext['table_count'];
1181 1259
 
1182 1260
 	// What ones have we already done?
1183
-	foreach ($table_names as $id => $table)
1184
-		if ($id < $_GET['substep'])
1261
+	foreach ($table_names as $id => $table) {
1262
+			if ($id < $_GET['substep'])
1185 1263
 			$upcontext['previous_tables'][] = $table;
1264
+	}
1186 1265
 
1187
-	if ($command_line)
1188
-		echo 'Backing Up Tables.';
1266
+	if ($command_line) {
1267
+			echo 'Backing Up Tables.';
1268
+	}
1189 1269
 
1190 1270
 	// If we don't support javascript we backup here.
1191 1271
 	if (!$support_js || isset($_GET['xml']))
@@ -1204,8 +1284,9 @@  discard block
 block discarded – undo
1204 1284
 			backupTable($table_names[$substep]);
1205 1285
 
1206 1286
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1207
-			if (isset($_GET['xml']))
1208
-				return upgradeExit();
1287
+			if (isset($_GET['xml'])) {
1288
+							return upgradeExit();
1289
+			}
1209 1290
 		}
1210 1291
 
1211 1292
 		if ($command_line)
@@ -1238,9 +1319,10 @@  discard block
 block discarded – undo
1238 1319
 
1239 1320
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1240 1321
 
1241
-	if ($command_line)
1242
-		echo ' done.';
1243
-}
1322
+	if ($command_line) {
1323
+			echo ' done.';
1324
+	}
1325
+	}
1244 1326
 
1245 1327
 // Step 2: Everything.
1246 1328
 function DatabaseChanges()
@@ -1249,8 +1331,9 @@  discard block
 block discarded – undo
1249 1331
 	global $upcontext, $support_js, $db_type;
1250 1332
 
1251 1333
 	// Have we just completed this?
1252
-	if (!empty($_POST['database_done']))
1253
-		return true;
1334
+	if (!empty($_POST['database_done'])) {
1335
+			return true;
1336
+	}
1254 1337
 
1255 1338
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1256 1339
 	$upcontext['page_title'] = 'Database Changes';
@@ -1265,15 +1348,16 @@  discard block
 block discarded – undo
1265 1348
 	);
1266 1349
 
1267 1350
 	// How many files are there in total?
1268
-	if (isset($_GET['filecount']))
1269
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1270
-	else
1351
+	if (isset($_GET['filecount'])) {
1352
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1353
+	} else
1271 1354
 	{
1272 1355
 		$upcontext['file_count'] = 0;
1273 1356
 		foreach ($files as $file)
1274 1357
 		{
1275
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1276
-				$upcontext['file_count']++;
1358
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1359
+							$upcontext['file_count']++;
1360
+			}
1277 1361
 		}
1278 1362
 	}
1279 1363
 
@@ -1283,9 +1367,9 @@  discard block
 block discarded – undo
1283 1367
 	$upcontext['cur_file_num'] = 0;
1284 1368
 	foreach ($files as $file)
1285 1369
 	{
1286
-		if ($did_not_do)
1287
-			$did_not_do--;
1288
-		else
1370
+		if ($did_not_do) {
1371
+					$did_not_do--;
1372
+		} else
1289 1373
 		{
1290 1374
 			$upcontext['cur_file_num']++;
1291 1375
 			$upcontext['cur_file_name'] = $file[0];
@@ -1312,12 +1396,13 @@  discard block
 block discarded – undo
1312 1396
 					// Flag to move on to the next.
1313 1397
 					$upcontext['completed_step'] = true;
1314 1398
 					// Did we complete the whole file?
1315
-					if ($nextFile)
1316
-						$upcontext['current_debug_item_num'] = -1;
1399
+					if ($nextFile) {
1400
+											$upcontext['current_debug_item_num'] = -1;
1401
+					}
1317 1402
 					return upgradeExit();
1403
+				} elseif ($support_js) {
1404
+									break;
1318 1405
 				}
1319
-				elseif ($support_js)
1320
-					break;
1321 1406
 			}
1322 1407
 			// Set the progress bar to be right as if we had - even if we hadn't...
1323 1408
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1342,8 +1427,9 @@  discard block
 block discarded – undo
1342 1427
 	global $command_line, $language, $upcontext, $boarddir, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1343 1428
 
1344 1429
 	// Now it's nice to have some of the basic SMF source files.
1345
-	if (!isset($_GET['ssi']) && !$command_line)
1346
-		redirectLocation('&ssi=1');
1430
+	if (!isset($_GET['ssi']) && !$command_line) {
1431
+			redirectLocation('&ssi=1');
1432
+	}
1347 1433
 
1348 1434
 	$upcontext['sub_template'] = 'upgrade_complete';
1349 1435
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1359,14 +1445,16 @@  discard block
 block discarded – undo
1359 1445
 	// Are we in maintenance mode?
1360 1446
 	if (isset($upcontext['user']['main']))
1361 1447
 	{
1362
-		if ($command_line)
1363
-			echo ' * ';
1448
+		if ($command_line) {
1449
+					echo ' * ';
1450
+		}
1364 1451
 		$upcontext['removed_maintenance'] = true;
1365 1452
 		$changes['maintenance'] = $upcontext['user']['main'];
1366 1453
 	}
1367 1454
 	// Otherwise if somehow we are in 2 let's go to 1.
1368
-	elseif (!empty($maintenance) && $maintenance == 2)
1369
-		$changes['maintenance'] = 1;
1455
+	elseif (!empty($maintenance) && $maintenance == 2) {
1456
+			$changes['maintenance'] = 1;
1457
+	}
1370 1458
 
1371 1459
 	// Wipe this out...
1372 1460
 	$upcontext['user'] = array();
@@ -1381,9 +1469,9 @@  discard block
 block discarded – undo
1381 1469
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1382 1470
 
1383 1471
 	// Now is the perfect time to fetch the SM files.
1384
-	if ($command_line)
1385
-		cli_scheduled_fetchSMfiles();
1386
-	else
1472
+	if ($command_line) {
1473
+			cli_scheduled_fetchSMfiles();
1474
+	} else
1387 1475
 	{
1388 1476
 		require_once($sourcedir . '/ScheduledTasks.php');
1389 1477
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1391,8 +1479,9 @@  discard block
 block discarded – undo
1391 1479
 	}
1392 1480
 
1393 1481
 	// Log what we've done.
1394
-	if (empty($user_info['id']))
1395
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1482
+	if (empty($user_info['id'])) {
1483
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1484
+	}
1396 1485
 
1397 1486
 	// Log the action manually, so CLI still works.
1398 1487
 	$smcFunc['db_insert']('',
@@ -1411,8 +1500,9 @@  discard block
 block discarded – undo
1411 1500
 
1412 1501
 	// Save the current database version.
1413 1502
 	$server_version = $smcFunc['db_server_info']();
1414
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1415
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1503
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1504
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1505
+	}
1416 1506
 
1417 1507
 	if ($command_line)
1418 1508
 	{
@@ -1424,8 +1514,9 @@  discard block
 block discarded – undo
1424 1514
 
1425 1515
 	// Make sure it says we're done.
1426 1516
 	$upcontext['overall_percent'] = 100;
1427
-	if (isset($upcontext['step_progress']))
1428
-		unset($upcontext['step_progress']);
1517
+	if (isset($upcontext['step_progress'])) {
1518
+			unset($upcontext['step_progress']);
1519
+	}
1429 1520
 
1430 1521
 	$_GET['substep'] = 0;
1431 1522
 	return false;
@@ -1436,8 +1527,9 @@  discard block
 block discarded – undo
1436 1527
 {
1437 1528
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1438 1529
 
1439
-	if (empty($modSettings['time_format']))
1440
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1530
+	if (empty($modSettings['time_format'])) {
1531
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1532
+	}
1441 1533
 
1442 1534
 	// What files do we want to get
1443 1535
 	$request = $smcFunc['db_query']('', '
@@ -1471,8 +1563,9 @@  discard block
 block discarded – undo
1471 1563
 		$file_data = fetch_web_data($url);
1472 1564
 
1473 1565
 		// If we got an error - give up - the site might be down.
1474
-		if ($file_data === false)
1475
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1566
+		if ($file_data === false) {
1567
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1568
+		}
1476 1569
 
1477 1570
 		// Save the file to the database.
1478 1571
 		$smcFunc['db_query']('substring', '
@@ -1514,8 +1607,9 @@  discard block
 block discarded – undo
1514 1607
 	$themeData = array();
1515 1608
 	foreach ($values as $variable => $value)
1516 1609
 	{
1517
-		if (!isset($value) || $value === null)
1518
-			$value = 0;
1610
+		if (!isset($value) || $value === null) {
1611
+					$value = 0;
1612
+		}
1519 1613
 
1520 1614
 		$themeData[] = array(0, 1, $variable, $value);
1521 1615
 	}
@@ -1544,8 +1638,9 @@  discard block
 block discarded – undo
1544 1638
 
1545 1639
 	foreach ($values as $variable => $value)
1546 1640
 	{
1547
-		if (empty($modSettings[$value[0]]))
1548
-			continue;
1641
+		if (empty($modSettings[$value[0]])) {
1642
+					continue;
1643
+		}
1549 1644
 
1550 1645
 		$smcFunc['db_query']('', '
1551 1646
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1631,19 +1726,21 @@  discard block
 block discarded – undo
1631 1726
 	set_error_handler(
1632 1727
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1633 1728
 		{
1634
-			if ($support_js)
1635
-				return true;
1636
-			else
1637
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1729
+			if ($support_js) {
1730
+							return true;
1731
+			} else {
1732
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1733
+			}
1638 1734
 		}
1639 1735
 	);
1640 1736
 
1641 1737
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1642 1738
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1643
-	if ($db_type == 'mysql')
1644
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1645
-	else
1646
-		$db_collation = '';
1739
+	if ($db_type == 'mysql') {
1740
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1741
+	} else {
1742
+			$db_collation = '';
1743
+	}
1647 1744
 
1648 1745
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1649 1746
 
@@ -1655,8 +1752,9 @@  discard block
 block discarded – undo
1655 1752
 	$last_step = '';
1656 1753
 
1657 1754
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1658
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1659
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1755
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1756
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1757
+	}
1660 1758
 
1661 1759
 	// Count the total number of steps within this file - for progress.
1662 1760
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1676,15 +1774,18 @@  discard block
 block discarded – undo
1676 1774
 		$do_current = $substep >= $_GET['substep'];
1677 1775
 
1678 1776
 		// Get rid of any comments in the beginning of the line...
1679
-		if (substr(trim($line), 0, 2) === '/*')
1680
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1777
+		if (substr(trim($line), 0, 2) === '/*') {
1778
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1779
+		}
1681 1780
 
1682 1781
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1683
-		if ($is_debug && !$support_js && $command_line)
1684
-			flush();
1782
+		if ($is_debug && !$support_js && $command_line) {
1783
+					flush();
1784
+		}
1685 1785
 
1686
-		if (trim($line) === '')
1687
-			continue;
1786
+		if (trim($line) === '') {
1787
+					continue;
1788
+		}
1688 1789
 
1689 1790
 		if (trim(substr($line, 0, 3)) === '---')
1690 1791
 		{
@@ -1694,8 +1795,9 @@  discard block
 block discarded – undo
1694 1795
 			if (trim($current_data) != '' && $type !== '}')
1695 1796
 			{
1696 1797
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1697
-				if ($command_line)
1698
-					echo $upcontext['error_message'];
1798
+				if ($command_line) {
1799
+									echo $upcontext['error_message'];
1800
+				}
1699 1801
 			}
1700 1802
 
1701 1803
 			if ($type == ' ')
@@ -1713,17 +1815,18 @@  discard block
 block discarded – undo
1713 1815
 				if ($do_current)
1714 1816
 				{
1715 1817
 					$upcontext['actioned_items'][] = $last_step;
1716
-					if ($command_line)
1717
-						echo ' * ';
1818
+					if ($command_line) {
1819
+											echo ' * ';
1820
+					}
1718 1821
 				}
1719
-			}
1720
-			elseif ($type == '#')
1822
+			} elseif ($type == '#')
1721 1823
 			{
1722 1824
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1723 1825
 
1724 1826
 				$upcontext['current_debug_item_num']++;
1725
-				if (trim($line) != '---#')
1726
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1827
+				if (trim($line) != '---#') {
1828
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1829
+				}
1727 1830
 
1728 1831
 				// Have we already done something?
1729 1832
 				if (isset($_GET['xml']) && $done_something)
@@ -1734,34 +1837,36 @@  discard block
 block discarded – undo
1734 1837
 
1735 1838
 				if ($do_current)
1736 1839
 				{
1737
-					if (trim($line) == '---#' && $command_line)
1738
-						echo ' done.', $endl;
1739
-					elseif ($command_line)
1740
-						echo ' +++ ', rtrim(substr($line, 4));
1741
-					elseif (trim($line) != '---#')
1840
+					if (trim($line) == '---#' && $command_line) {
1841
+											echo ' done.', $endl;
1842
+					} elseif ($command_line) {
1843
+											echo ' +++ ', rtrim(substr($line, 4));
1844
+					} elseif (trim($line) != '---#')
1742 1845
 					{
1743
-						if ($is_debug)
1744
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1846
+						if ($is_debug) {
1847
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1848
+						}
1745 1849
 					}
1746 1850
 				}
1747 1851
 
1748 1852
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1749 1853
 				{
1750
-					if ($command_line)
1751
-						echo ' * ';
1752
-					else
1753
-						$upcontext['actioned_items'][] = $last_step;
1854
+					if ($command_line) {
1855
+											echo ' * ';
1856
+					} else {
1857
+											$upcontext['actioned_items'][] = $last_step;
1858
+					}
1754 1859
 				}
1755 1860
 
1756 1861
 				// Small step - only if we're actually doing stuff.
1757
-				if ($do_current)
1758
-					nextSubstep(++$substep);
1759
-				else
1760
-					$substep++;
1761
-			}
1762
-			elseif ($type == '{')
1763
-				$current_type = 'code';
1764
-			elseif ($type == '}')
1862
+				if ($do_current) {
1863
+									nextSubstep(++$substep);
1864
+				} else {
1865
+									$substep++;
1866
+				}
1867
+			} elseif ($type == '{') {
1868
+							$current_type = 'code';
1869
+			} elseif ($type == '}')
1765 1870
 			{
1766 1871
 				$current_type = 'sql';
1767 1872
 
@@ -1774,8 +1879,9 @@  discard block
 block discarded – undo
1774 1879
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1775 1880
 				{
1776 1881
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1777
-					if ($command_line)
1778
-						echo $upcontext['error_message'];
1882
+					if ($command_line) {
1883
+											echo $upcontext['error_message'];
1884
+					}
1779 1885
 				}
1780 1886
 
1781 1887
 				// Done with code!
@@ -1855,8 +1961,9 @@  discard block
 block discarded – undo
1855 1961
 	$db_unbuffered = false;
1856 1962
 
1857 1963
 	// Failure?!
1858
-	if ($result !== false)
1859
-		return $result;
1964
+	if ($result !== false) {
1965
+			return $result;
1966
+	}
1860 1967
 
1861 1968
 	$db_error_message = $smcFunc['db_error']($db_connection);
1862 1969
 	// If MySQL we do something more clever.
@@ -1884,54 +1991,61 @@  discard block
 block discarded – undo
1884 1991
 			{
1885 1992
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1886 1993
 				$result = mysqli_query($db_connection, $string);
1887
-				if ($result !== false)
1888
-					return $result;
1994
+				if ($result !== false) {
1995
+									return $result;
1996
+				}
1889 1997
 			}
1890
-		}
1891
-		elseif ($mysqli_errno == 2013)
1998
+		} elseif ($mysqli_errno == 2013)
1892 1999
 		{
1893 2000
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1894 2001
 			mysqli_select_db($db_connection, $db_name);
1895 2002
 			if ($db_connection)
1896 2003
 			{
1897 2004
 				$result = mysqli_query($db_connection, $string);
1898
-				if ($result !== false)
1899
-					return $result;
2005
+				if ($result !== false) {
2006
+									return $result;
2007
+				}
1900 2008
 			}
1901 2009
 		}
1902 2010
 		// Duplicate column name... should be okay ;).
1903
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1904
-			return false;
2011
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2012
+					return false;
2013
+		}
1905 2014
 		// Duplicate insert... make sure it's the proper type of query ;).
1906
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1907
-			return false;
2015
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2016
+					return false;
2017
+		}
1908 2018
 		// Creating an index on a non-existent column.
1909
-		elseif ($mysqli_errno == 1072)
1910
-			return false;
1911
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1912
-			return false;
2019
+		elseif ($mysqli_errno == 1072) {
2020
+					return false;
2021
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2022
+					return false;
2023
+		}
1913 2024
 	}
1914 2025
 	// If a table already exists don't go potty.
1915 2026
 	else
1916 2027
 	{
1917 2028
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1918 2029
 		{
1919
-			if (strpos($db_error_message, 'exist') !== false)
1920
-				return true;
1921
-		}
1922
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2030
+			if (strpos($db_error_message, 'exist') !== false) {
2031
+							return true;
2032
+			}
2033
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1923 2034
 		{
1924
-			if (strpos($db_error_message, 'duplicate') !== false)
1925
-				return true;
2035
+			if (strpos($db_error_message, 'duplicate') !== false) {
2036
+							return true;
2037
+			}
1926 2038
 		}
1927 2039
 	}
1928 2040
 
1929 2041
 	// Get the query string so we pass everything.
1930 2042
 	$query_string = '';
1931
-	foreach ($_GET as $k => $v)
1932
-		$query_string .= ';' . $k . '=' . $v;
1933
-	if (strlen($query_string) != 0)
1934
-		$query_string = '?' . substr($query_string, 1);
2043
+	foreach ($_GET as $k => $v) {
2044
+			$query_string .= ';' . $k . '=' . $v;
2045
+	}
2046
+	if (strlen($query_string) != 0) {
2047
+			$query_string = '?' . substr($query_string, 1);
2048
+	}
1935 2049
 
1936 2050
 	if ($command_line)
1937 2051
 	{
@@ -1986,16 +2100,18 @@  discard block
 block discarded – undo
1986 2100
 			{
1987 2101
 				$found |= 1;
1988 2102
 				// Do some checks on the data if we have it set.
1989
-				if (isset($change['col_type']))
1990
-					$found &= $change['col_type'] === $column['type'];
1991
-				if (isset($change['null_allowed']))
1992
-					$found &= $column['null'] == $change['null_allowed'];
1993
-				if (isset($change['default']))
1994
-					$found &= $change['default'] === $column['default'];
2103
+				if (isset($change['col_type'])) {
2104
+									$found &= $change['col_type'] === $column['type'];
2105
+				}
2106
+				if (isset($change['null_allowed'])) {
2107
+									$found &= $column['null'] == $change['null_allowed'];
2108
+				}
2109
+				if (isset($change['default'])) {
2110
+									$found &= $change['default'] === $column['default'];
2111
+				}
1995 2112
 			}
1996 2113
 		}
1997
-	}
1998
-	elseif ($change['type'] === 'index')
2114
+	} elseif ($change['type'] === 'index')
1999 2115
 	{
2000 2116
 		$request = upgrade_query('
2001 2117
 			SHOW INDEX
@@ -2004,9 +2120,10 @@  discard block
 block discarded – undo
2004 2120
 		{
2005 2121
 			$cur_index = array();
2006 2122
 
2007
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2008
-				if ($row['Key_name'] === $change['name'])
2123
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2124
+							if ($row['Key_name'] === $change['name'])
2009 2125
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2126
+			}
2010 2127
 
2011 2128
 			ksort($cur_index, SORT_NUMERIC);
2012 2129
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2016,14 +2133,17 @@  discard block
 block discarded – undo
2016 2133
 	}
2017 2134
 
2018 2135
 	// If we're trying to add and it's added, we're done.
2019
-	if ($found && in_array($change['method'], array('add', 'change')))
2020
-		return true;
2136
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2137
+			return true;
2138
+	}
2021 2139
 	// Otherwise if we're removing and it wasn't found we're also done.
2022
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2023
-		return true;
2140
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2141
+			return true;
2142
+	}
2024 2143
 	// Otherwise is it just a test?
2025
-	elseif ($is_test)
2026
-		return false;
2144
+	elseif ($is_test) {
2145
+			return false;
2146
+	}
2027 2147
 
2028 2148
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2029 2149
 	$running = false;
@@ -2034,8 +2154,9 @@  discard block
 block discarded – undo
2034 2154
 			SHOW FULL PROCESSLIST');
2035 2155
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2036 2156
 		{
2037
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2038
-				$found = true;
2157
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2158
+							$found = true;
2159
+			}
2039 2160
 		}
2040 2161
 
2041 2162
 		// Can't find it? Then we need to run it fools!
@@ -2047,8 +2168,9 @@  discard block
 block discarded – undo
2047 2168
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2048 2169
 				' . $change['text'], true) !== false;
2049 2170
 
2050
-			if (!$success)
2051
-				return false;
2171
+			if (!$success) {
2172
+							return false;
2173
+			}
2052 2174
 
2053 2175
 			// Return
2054 2176
 			$running = true;
@@ -2090,8 +2212,9 @@  discard block
 block discarded – undo
2090 2212
 			'db_error_skip' => true,
2091 2213
 		)
2092 2214
 	);
2093
-	if ($smcFunc['db_num_rows']($request) === 0)
2094
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2215
+	if ($smcFunc['db_num_rows']($request) === 0) {
2216
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2217
+	}
2095 2218
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2096 2219
 	$smcFunc['db_free_result']($request);
2097 2220
 
@@ -2113,18 +2236,19 @@  discard block
 block discarded – undo
2113 2236
 			)
2114 2237
 		);
2115 2238
 		// No results? Just forget it all together.
2116
-		if ($smcFunc['db_num_rows']($request) === 0)
2117
-			unset($table_row['Collation']);
2118
-		else
2119
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2239
+		if ($smcFunc['db_num_rows']($request) === 0) {
2240
+					unset($table_row['Collation']);
2241
+		} else {
2242
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2243
+		}
2120 2244
 		$smcFunc['db_free_result']($request);
2121 2245
 	}
2122 2246
 
2123 2247
 	if ($column_fix)
2124 2248
 	{
2125 2249
 		// Make sure there are no NULL's left.
2126
-		if ($null_fix)
2127
-			$smcFunc['db_query']('', '
2250
+		if ($null_fix) {
2251
+					$smcFunc['db_query']('', '
2128 2252
 				UPDATE {db_prefix}' . $change['table'] . '
2129 2253
 				SET ' . $change['column'] . ' = {string:default}
2130 2254
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2133,6 +2257,7 @@  discard block
 block discarded – undo
2133 2257
 					'db_error_skip' => true,
2134 2258
 				)
2135 2259
 			);
2260
+		}
2136 2261
 
2137 2262
 		// Do the actual alteration.
2138 2263
 		$smcFunc['db_query']('', '
@@ -2161,8 +2286,9 @@  discard block
 block discarded – undo
2161 2286
 	}
2162 2287
 
2163 2288
 	// Not a column we need to check on?
2164
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2165
-		return;
2289
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2290
+			return;
2291
+	}
2166 2292
 
2167 2293
 	// Break it up you (six|seven).
2168 2294
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2181,13 +2307,13 @@  discard block
 block discarded – undo
2181 2307
 				'new_name' => $temp[2],
2182 2308
 		));
2183 2309
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2184
-		if ($smcFunc['db_num_rows'] != 1)
2185
-			return;
2310
+		if ($smcFunc['db_num_rows'] != 1) {
2311
+					return;
2312
+		}
2186 2313
 
2187 2314
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2188 2315
 		$smcFunc['db_free_result']($request);
2189
-	}
2190
-	else
2316
+	} else
2191 2317
 	{
2192 2318
 		// Do this the old fashion, sure method way.
2193 2319
 		$request = $smcFunc['db_query']('', '
@@ -2198,21 +2324,24 @@  discard block
 block discarded – undo
2198 2324
 		));
2199 2325
 		// Mayday!
2200 2326
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2201
-		if ($smcFunc['db_num_rows'] == 0)
2202
-			return;
2327
+		if ($smcFunc['db_num_rows'] == 0) {
2328
+					return;
2329
+		}
2203 2330
 
2204 2331
 		// Oh where, oh where has my little field gone. Oh where can it be...
2205
-		while ($row = $smcFunc['db_query']($request))
2206
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2332
+		while ($row = $smcFunc['db_query']($request)) {
2333
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2207 2334
 			{
2208 2335
 				$current_type = $row['Type'];
2336
+		}
2209 2337
 				break;
2210 2338
 			}
2211 2339
 	}
2212 2340
 
2213 2341
 	// If this doesn't match, the column may of been altered for a reason.
2214
-	if (trim($current_type) != trim($temp[3]))
2215
-		$temp[3] = $current_type;
2342
+	if (trim($current_type) != trim($temp[3])) {
2343
+			$temp[3] = $current_type;
2344
+	}
2216 2345
 
2217 2346
 	// Piece this back together.
2218 2347
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2224,8 +2353,9 @@  discard block
 block discarded – undo
2224 2353
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2225 2354
 	global $step_progress, $is_debug, $upcontext;
2226 2355
 
2227
-	if ($_GET['substep'] < $substep)
2228
-		$_GET['substep'] = $substep;
2356
+	if ($_GET['substep'] < $substep) {
2357
+			$_GET['substep'] = $substep;
2358
+	}
2229 2359
 
2230 2360
 	if ($command_line)
2231 2361
 	{
@@ -2238,29 +2368,33 @@  discard block
 block discarded – undo
2238 2368
 	}
2239 2369
 
2240 2370
 	@set_time_limit(300);
2241
-	if (function_exists('apache_reset_timeout'))
2242
-		@apache_reset_timeout();
2371
+	if (function_exists('apache_reset_timeout')) {
2372
+			@apache_reset_timeout();
2373
+	}
2243 2374
 
2244
-	if (time() - $start_time <= $timeLimitThreshold)
2245
-		return;
2375
+	if (time() - $start_time <= $timeLimitThreshold) {
2376
+			return;
2377
+	}
2246 2378
 
2247 2379
 	// Do we have some custom step progress stuff?
2248 2380
 	if (!empty($step_progress))
2249 2381
 	{
2250 2382
 		$upcontext['substep_progress'] = 0;
2251 2383
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2252
-		if ($step_progress['current'] > $step_progress['total'])
2253
-			$upcontext['substep_progress'] = 99.9;
2254
-		else
2255
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2384
+		if ($step_progress['current'] > $step_progress['total']) {
2385
+					$upcontext['substep_progress'] = 99.9;
2386
+		} else {
2387
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2388
+		}
2256 2389
 
2257 2390
 		// Make it nicely rounded.
2258 2391
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2259 2392
 	}
2260 2393
 
2261 2394
 	// If this is XML we just exit right away!
2262
-	if (isset($_GET['xml']))
2263
-		return upgradeExit();
2395
+	if (isset($_GET['xml'])) {
2396
+			return upgradeExit();
2397
+	}
2264 2398
 
2265 2399
 	// We're going to pause after this!
2266 2400
 	$upcontext['pause'] = true;
@@ -2268,13 +2402,15 @@  discard block
 block discarded – undo
2268 2402
 	$upcontext['query_string'] = '';
2269 2403
 	foreach ($_GET as $k => $v)
2270 2404
 	{
2271
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2272
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2405
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2406
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2407
+		}
2273 2408
 	}
2274 2409
 
2275 2410
 	// Custom warning?
2276
-	if (!empty($custom_warning))
2277
-		$upcontext['custom_warning'] = $custom_warning;
2411
+	if (!empty($custom_warning)) {
2412
+			$upcontext['custom_warning'] = $custom_warning;
2413
+	}
2278 2414
 
2279 2415
 	upgradeExit();
2280 2416
 }
@@ -2289,25 +2425,26 @@  discard block
 block discarded – undo
2289 2425
 	ob_implicit_flush(true);
2290 2426
 	@set_time_limit(600);
2291 2427
 
2292
-	if (!isset($_SERVER['argv']))
2293
-		$_SERVER['argv'] = array();
2428
+	if (!isset($_SERVER['argv'])) {
2429
+			$_SERVER['argv'] = array();
2430
+	}
2294 2431
 	$_GET['maint'] = 1;
2295 2432
 
2296 2433
 	foreach ($_SERVER['argv'] as $i => $arg)
2297 2434
 	{
2298
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2299
-			$_GET['lang'] = $match[1];
2300
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2301
-			continue;
2302
-		elseif ($arg == '--no-maintenance')
2303
-			$_GET['maint'] = 0;
2304
-		elseif ($arg == '--debug')
2305
-			$is_debug = true;
2306
-		elseif ($arg == '--backup')
2307
-			$_POST['backup'] = 1;
2308
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2309
-			$_GET['conv'] = 1;
2310
-		elseif ($i != 0)
2435
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2436
+					$_GET['lang'] = $match[1];
2437
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2438
+					continue;
2439
+		} elseif ($arg == '--no-maintenance') {
2440
+					$_GET['maint'] = 0;
2441
+		} elseif ($arg == '--debug') {
2442
+					$is_debug = true;
2443
+		} elseif ($arg == '--backup') {
2444
+					$_POST['backup'] = 1;
2445
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2446
+					$_GET['conv'] = 1;
2447
+		} elseif ($i != 0)
2311 2448
 		{
2312 2449
 			echo 'SMF Command-line Upgrader
2313 2450
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2321,10 +2458,12 @@  discard block
 block discarded – undo
2321 2458
 		}
2322 2459
 	}
2323 2460
 
2324
-	if (!php_version_check())
2325
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2326
-	if (!db_version_check())
2327
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2461
+	if (!php_version_check()) {
2462
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2463
+	}
2464
+	if (!db_version_check()) {
2465
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2466
+	}
2328 2467
 
2329 2468
 	// Do some checks to make sure they have proper privileges
2330 2469
 	db_extend('packages');
@@ -2339,34 +2478,39 @@  discard block
 block discarded – undo
2339 2478
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2340 2479
 
2341 2480
 	// Sorry... we need CREATE, ALTER and DROP
2342
-	if (!$create || !$alter || !$drop)
2343
-		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);
2481
+	if (!$create || !$alter || !$drop) {
2482
+			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);
2483
+	}
2344 2484
 
2345 2485
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2346 2486
 		&& @file_exists($sourcedir . '/QueryString.php')
2347 2487
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2348
-	if (!$check && !isset($modSettings['smfVersion']))
2349
-		print_error('Error: Some files are missing or out-of-date.', true);
2488
+	if (!$check && !isset($modSettings['smfVersion'])) {
2489
+			print_error('Error: Some files are missing or out-of-date.', true);
2490
+	}
2350 2491
 
2351 2492
 	// Do a quick version spot check.
2352 2493
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2353 2494
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2354
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2355
-		print_error('Error: Some files have not yet been updated properly.');
2495
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2496
+			print_error('Error: Some files have not yet been updated properly.');
2497
+	}
2356 2498
 
2357 2499
 	// Make sure Settings.php is writable.
2358 2500
 		quickFileWritable($boarddir . '/Settings.php');
2359
-	if (!is_writable($boarddir . '/Settings.php'))
2360
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2501
+	if (!is_writable($boarddir . '/Settings.php')) {
2502
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2503
+	}
2361 2504
 
2362 2505
 	// Make sure Settings_bak.php is writable.
2363 2506
 		quickFileWritable($boarddir . '/Settings_bak.php');
2364
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2365
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2507
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2508
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2509
+	}
2366 2510
 
2367
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2368
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2369
-	elseif (isset($modSettings['agreement']))
2511
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2512
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2513
+	} elseif (isset($modSettings['agreement']))
2370 2514
 	{
2371 2515
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2372 2516
 		fwrite($fp, $modSettings['agreement']);
@@ -2376,31 +2520,36 @@  discard block
 block discarded – undo
2376 2520
 	// Make sure Themes is writable.
2377 2521
 	quickFileWritable($modSettings['theme_dir']);
2378 2522
 
2379
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2380
-		print_error('Error: Unable to obtain write access to "Themes".');
2523
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2524
+			print_error('Error: Unable to obtain write access to "Themes".');
2525
+	}
2381 2526
 
2382 2527
 	// Make sure cache directory exists and is writable!
2383 2528
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2384
-	if (!file_exists($cachedir_temp))
2385
-		@mkdir($cachedir_temp);
2529
+	if (!file_exists($cachedir_temp)) {
2530
+			@mkdir($cachedir_temp);
2531
+	}
2386 2532
 
2387 2533
 	// Make sure the cache temp dir is writable.
2388 2534
 	quickFileWritable($cachedir_temp);
2389 2535
 
2390
-	if (!is_writable($cachedir_temp))
2391
-		print_error('Error: Unable to obtain write access to "cache".', true);
2536
+	if (!is_writable($cachedir_temp)) {
2537
+			print_error('Error: Unable to obtain write access to "cache".', true);
2538
+	}
2392 2539
 
2393
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2394
-		print_error('Error: Unable to find language files!', true);
2395
-	else
2540
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2541
+			print_error('Error: Unable to find language files!', true);
2542
+	} else
2396 2543
 	{
2397 2544
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2398 2545
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2399 2546
 
2400
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2401
-			print_error('Error: Language files out of date.', true);
2402
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2403
-			print_error('Error: Install language is missing for selected language.', true);
2547
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2548
+					print_error('Error: Language files out of date.', true);
2549
+		}
2550
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2551
+					print_error('Error: Install language is missing for selected language.', true);
2552
+		}
2404 2553
 
2405 2554
 		// Otherwise include it!
2406 2555
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2419,8 +2568,9 @@  discard block
 block discarded – undo
2419 2568
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2420 2569
 
2421 2570
 	// Done it already?
2422
-	if (!empty($_POST['utf8_done']))
2423
-		return true;
2571
+	if (!empty($_POST['utf8_done'])) {
2572
+			return true;
2573
+	}
2424 2574
 
2425 2575
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2426 2576
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2433,8 +2583,7 @@  discard block
 block discarded – undo
2433 2583
 		);
2434 2584
 
2435 2585
 		return true;
2436
-	}
2437
-	else
2586
+	} else
2438 2587
 	{
2439 2588
 		$upcontext['page_title'] = 'Converting to UTF8';
2440 2589
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2478,8 +2627,9 @@  discard block
 block discarded – undo
2478 2627
 			)
2479 2628
 		);
2480 2629
 		$db_charsets = array();
2481
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2482
-			$db_charsets[] = $row['Charset'];
2630
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2631
+					$db_charsets[] = $row['Charset'];
2632
+		}
2483 2633
 
2484 2634
 		$smcFunc['db_free_result']($request);
2485 2635
 
@@ -2515,13 +2665,15 @@  discard block
 block discarded – undo
2515 2665
 		// If there's a fulltext index, we need to drop it first...
2516 2666
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2517 2667
 		{
2518
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2519
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2668
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2669
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2520 2670
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2671
+			}
2521 2672
 			$smcFunc['db_free_result']($request);
2522 2673
 
2523
-			if (isset($upcontext['fulltext_index']))
2524
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2674
+			if (isset($upcontext['fulltext_index'])) {
2675
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2676
+			}
2525 2677
 		}
2526 2678
 
2527 2679
 		// Drop it and make a note...
@@ -2711,8 +2863,9 @@  discard block
 block discarded – undo
2711 2863
 			$replace = '%field%';
2712 2864
 
2713 2865
 			// Build a huge REPLACE statement...
2714
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2715
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2866
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2867
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2868
+			}
2716 2869
 		}
2717 2870
 
2718 2871
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2722,9 +2875,10 @@  discard block
 block discarded – undo
2722 2875
 		$upcontext['table_count'] = count($queryTables);
2723 2876
 	
2724 2877
 		// What ones have we already done?
2725
-		foreach ($queryTables as $id => $table)
2726
-			if ($id < $_GET['substep'])
2878
+		foreach ($queryTables as $id => $table) {
2879
+					if ($id < $_GET['substep'])
2727 2880
 				$upcontext['previous_tables'][] = $table;
2881
+		}
2728 2882
 
2729 2883
 		$upcontext['cur_table_num'] = $_GET['substep'];
2730 2884
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2761,8 +2915,9 @@  discard block
 block discarded – undo
2761 2915
 			nextSubstep($substep);
2762 2916
 
2763 2917
 			// Just to make sure it doesn't time out.
2764
-			if (function_exists('apache_reset_timeout'))
2765
-				@apache_reset_timeout();
2918
+			if (function_exists('apache_reset_timeout')) {
2919
+							@apache_reset_timeout();
2920
+			}
2766 2921
 
2767 2922
 			$table_charsets = array();
2768 2923
 
@@ -2783,8 +2938,9 @@  discard block
 block discarded – undo
2783 2938
 					{
2784 2939
 						list($charset) = explode('_', $collation);
2785 2940
 
2786
-						if (!isset($table_charsets[$charset]))
2787
-							$table_charsets[$charset] = array();
2941
+						if (!isset($table_charsets[$charset])) {
2942
+													$table_charsets[$charset] = array();
2943
+						}
2788 2944
 
2789 2945
 						$table_charsets[$charset][] = $column_info;
2790 2946
 					}
@@ -2824,10 +2980,11 @@  discard block
 block discarded – undo
2824 2980
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2825 2981
 				{
2826 2982
 					$update = '';
2827
-					foreach ($table_charsets as $charset => $columns)
2828
-						foreach ($columns as $column)
2983
+					foreach ($table_charsets as $charset => $columns) {
2984
+											foreach ($columns as $column)
2829 2985
 							$update .= '
2830 2986
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2987
+					}
2831 2988
 
2832 2989
 					$smcFunc['db_query']('', '
2833 2990
 						UPDATE {raw:table_name}
@@ -2852,8 +3009,9 @@  discard block
 block discarded – undo
2852 3009
 			// Now do the actual conversion (if still needed).
2853 3010
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2854 3011
 			{
2855
-				if ($command_line)
2856
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3012
+				if ($command_line) {
3013
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3014
+				}
2857 3015
 
2858 3016
 				$smcFunc['db_query']('', '
2859 3017
 					ALTER TABLE {raw:table_name}
@@ -2863,12 +3021,14 @@  discard block
 block discarded – undo
2863 3021
 					)
2864 3022
 				);
2865 3023
 
2866
-				if ($command_line)
2867
-					echo " done.\n";
3024
+				if ($command_line) {
3025
+									echo " done.\n";
3026
+				}
2868 3027
 			}
2869 3028
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2870
-			if (isset($_GET['xml']))
2871
-				return upgradeExit();
3029
+			if (isset($_GET['xml'])) {
3030
+							return upgradeExit();
3031
+			}
2872 3032
 		}
2873 3033
 
2874 3034
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2897,8 +3057,8 @@  discard block
 block discarded – undo
2897 3057
 		);
2898 3058
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2899 3059
 		{
2900
-			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)
2901
-				$smcFunc['db_query']('', '
3060
+			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) {
3061
+							$smcFunc['db_query']('', '
2902 3062
 					UPDATE {db_prefix}log_actions
2903 3063
 					SET extra = {string:extra}
2904 3064
 					WHERE id_action = {int:current_action}',
@@ -2907,6 +3067,7 @@  discard block
 block discarded – undo
2907 3067
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2908 3068
 					)
2909 3069
 				);
3070
+			}
2910 3071
 		}
2911 3072
 		$smcFunc['db_free_result']($request);
2912 3073
 
@@ -2928,15 +3089,17 @@  discard block
 block discarded – undo
2928 3089
 	// First thing's first - did we already do this?
2929 3090
 	if (!empty($modSettings['json_done']))
2930 3091
 	{
2931
-		if ($command_line)
2932
-			return DeleteUpgrade();
2933
-		else
2934
-			return true;
3092
+		if ($command_line) {
3093
+					return DeleteUpgrade();
3094
+		} else {
3095
+					return true;
3096
+		}
2935 3097
 	}
2936 3098
 
2937 3099
 	// Done it already - js wise?
2938
-	if (!empty($_POST['json_done']))
2939
-		return true;
3100
+	if (!empty($_POST['json_done'])) {
3101
+			return true;
3102
+	}
2940 3103
 
2941 3104
 	// List of tables affected by this function
2942 3105
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2968,12 +3131,14 @@  discard block
 block discarded – undo
2968 3131
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2969 3132
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2970 3133
 
2971
-	foreach ($keys as $id => $table)
2972
-		if ($id < $_GET['substep'])
3134
+	foreach ($keys as $id => $table) {
3135
+			if ($id < $_GET['substep'])
2973 3136
 			$upcontext['previous_tables'][] = $table;
3137
+	}
2974 3138
 
2975
-	if ($command_line)
2976
-		echo 'Converting data from serialize() to json_encode().';
3139
+	if ($command_line) {
3140
+			echo 'Converting data from serialize() to json_encode().';
3141
+	}
2977 3142
 
2978 3143
 	if (!$support_js || isset($_GET['xml']))
2979 3144
 	{
@@ -3013,8 +3178,9 @@  discard block
 block discarded – undo
3013 3178
 
3014 3179
 				// Loop through and fix these...
3015 3180
 				$new_settings = array();
3016
-				if ($command_line)
3017
-					echo "\n" . 'Fixing some settings...';
3181
+				if ($command_line) {
3182
+									echo "\n" . 'Fixing some settings...';
3183
+				}
3018 3184
 
3019 3185
 				foreach ($serialized_settings as $var)
3020 3186
 				{
@@ -3022,22 +3188,24 @@  discard block
 block discarded – undo
3022 3188
 					{
3023 3189
 						// Attempt to unserialize the setting
3024 3190
 						$temp = @safe_unserialize($modSettings[$var]);
3025
-						if (!$temp && $command_line)
3026
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3027
-						elseif ($temp !== false)
3028
-							$new_settings[$var] = json_encode($temp);
3191
+						if (!$temp && $command_line) {
3192
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3193
+						} elseif ($temp !== false) {
3194
+													$new_settings[$var] = json_encode($temp);
3195
+						}
3029 3196
 					}
3030 3197
 				}
3031 3198
 
3032 3199
 				// Update everything at once
3033
-				if (!function_exists('cache_put_data'))
3034
-					require_once($sourcedir . '/Load.php');
3200
+				if (!function_exists('cache_put_data')) {
3201
+									require_once($sourcedir . '/Load.php');
3202
+				}
3035 3203
 				updateSettings($new_settings, true);
3036 3204
 
3037
-				if ($command_line)
3038
-					echo ' done.';
3039
-			}
3040
-			elseif ($table == 'themes')
3205
+				if ($command_line) {
3206
+									echo ' done.';
3207
+				}
3208
+			} elseif ($table == 'themes')
3041 3209
 			{
3042 3210
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3043 3211
 				$query = $smcFunc['db_query']('', '
@@ -3056,10 +3224,11 @@  discard block
 block discarded – undo
3056 3224
 
3057 3225
 						if ($command_line)
3058 3226
 						{
3059
-							if ($temp === false)
3060
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3061
-							else
3062
-								echo "\n" . 'Fixing admin preferences...';
3227
+							if ($temp === false) {
3228
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3229
+							} else {
3230
+															echo "\n" . 'Fixing admin preferences...';
3231
+							}
3063 3232
 						}
3064 3233
 
3065 3234
 						if ($temp !== false)
@@ -3081,15 +3250,15 @@  discard block
 block discarded – undo
3081 3250
 								)
3082 3251
 							);
3083 3252
 
3084
-							if ($command_line)
3085
-								echo ' done.';
3253
+							if ($command_line) {
3254
+															echo ' done.';
3255
+							}
3086 3256
 						}
3087 3257
 					}
3088 3258
 
3089 3259
 					$smcFunc['db_free_result']($query);
3090 3260
 				}
3091
-			}
3092
-			else
3261
+			} else
3093 3262
 			{
3094 3263
 				// First item is always the key...
3095 3264
 				$key = $info[0];
@@ -3100,8 +3269,7 @@  discard block
 block discarded – undo
3100 3269
 				{
3101 3270
 					$col_select = $info[1];
3102 3271
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3103
-				}
3104
-				else
3272
+				} else
3105 3273
 				{
3106 3274
 					$col_select = implode(', ', $info);
3107 3275
 				}
@@ -3134,8 +3302,7 @@  discard block
 block discarded – undo
3134 3302
 								if ($temp === false && $command_line)
3135 3303
 								{
3136 3304
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3137
-								}
3138
-								else
3305
+								} else
3139 3306
 								{
3140 3307
 									$row[$col] = json_encode($temp);
3141 3308
 
@@ -3160,16 +3327,18 @@  discard block
 block discarded – undo
3160 3327
 						}
3161 3328
 					}
3162 3329
 
3163
-					if ($command_line)
3164
-						echo ' done.';
3330
+					if ($command_line) {
3331
+											echo ' done.';
3332
+					}
3165 3333
 
3166 3334
 					// Free up some memory...
3167 3335
 					$smcFunc['db_free_result']($query);
3168 3336
 				}
3169 3337
 			}
3170 3338
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3171
-			if (isset($_GET['xml']))
3172
-				return upgradeExit();
3339
+			if (isset($_GET['xml'])) {
3340
+							return upgradeExit();
3341
+			}
3173 3342
 		}
3174 3343
 
3175 3344
 		if ($command_line)
@@ -3184,8 +3353,9 @@  discard block
 block discarded – undo
3184 3353
 
3185 3354
 		$_GET['substep'] = 0;
3186 3355
 		// Make sure we move on!
3187
-		if ($command_line)
3188
-			return DeleteUpgrade();
3356
+		if ($command_line) {
3357
+					return DeleteUpgrade();
3358
+		}
3189 3359
 
3190 3360
 		return true;
3191 3361
 	}
@@ -3205,14 +3375,16 @@  discard block
 block discarded – undo
3205 3375
 	global $upcontext, $txt, $settings;
3206 3376
 
3207 3377
 	// Don't call me twice!
3208
-	if (!empty($upcontext['chmod_called']))
3209
-		return;
3378
+	if (!empty($upcontext['chmod_called'])) {
3379
+			return;
3380
+	}
3210 3381
 
3211 3382
 	$upcontext['chmod_called'] = true;
3212 3383
 
3213 3384
 	// Nothing?
3214
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3215
-		return;
3385
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3386
+			return;
3387
+	}
3216 3388
 
3217 3389
 	// Was it a problem with Windows?
3218 3390
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3244,11 +3416,12 @@  discard block
 block discarded – undo
3244 3416
 					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\');
3245 3417
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3246 3418
 
3247
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3248
-		echo '
3419
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3420
+			echo '
3249 3421
 					content.write(\'<hr>\n\t\t\t\');
3250 3422
 					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\');
3251 3423
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3424
+	}
3252 3425
 
3253 3426
 	echo '
3254 3427
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3256,17 +3429,19 @@  discard block
 block discarded – undo
3256 3429
 				}
3257 3430
 			</script>';
3258 3431
 
3259
-	if (!empty($upcontext['chmod']['ftp_error']))
3260
-		echo '
3432
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3433
+			echo '
3261 3434
 			<div class="error_message red">
3262 3435
 				The following error was encountered when trying to connect:<br><br>
3263 3436
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3264 3437
 			</div>
3265 3438
 			<br>';
3439
+	}
3266 3440
 
3267
-	if (empty($upcontext['chmod_in_form']))
3268
-		echo '
3441
+	if (empty($upcontext['chmod_in_form'])) {
3442
+			echo '
3269 3443
 	<form action="', $upcontext['form_url'], '" method="post">';
3444
+	}
3270 3445
 
3271 3446
 	echo '
3272 3447
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3301,10 +3476,11 @@  discard block
 block discarded – undo
3301 3476
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3302 3477
 	</div>';
3303 3478
 
3304
-	if (empty($upcontext['chmod_in_form']))
3305
-		echo '
3479
+	if (empty($upcontext['chmod_in_form'])) {
3480
+			echo '
3306 3481
 	</form>';
3307
-}
3482
+	}
3483
+	}
3308 3484
 
3309 3485
 function template_upgrade_above()
3310 3486
 {
@@ -3364,9 +3540,10 @@  discard block
 block discarded – undo
3364 3540
 				<h2>', $txt['upgrade_progress'], '</h2>
3365 3541
 				<ul>';
3366 3542
 
3367
-	foreach ($upcontext['steps'] as $num => $step)
3368
-		echo '
3543
+	foreach ($upcontext['steps'] as $num => $step) {
3544
+			echo '
3369 3545
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3546
+	}
3370 3547
 
3371 3548
 	echo '
3372 3549
 					</ul>
@@ -3379,8 +3556,8 @@  discard block
 block discarded – undo
3379 3556
 				</div>
3380 3557
 			</div>';
3381 3558
 
3382
-	if (isset($upcontext['step_progress']))
3383
-		echo '
3559
+	if (isset($upcontext['step_progress'])) {
3560
+			echo '
3384 3561
 				<br>
3385 3562
 				<br>
3386 3563
 				<div id="progress_bar_step">
@@ -3389,6 +3566,7 @@  discard block
 block discarded – undo
3389 3566
 						<span>', $txt['upgrade_step_progress'], '</span>
3390 3567
 					</div>
3391 3568
 				</div>';
3569
+	}
3392 3570
 
3393 3571
 	echo '
3394 3572
 				<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>
@@ -3419,32 +3597,36 @@  discard block
 block discarded – undo
3419 3597
 {
3420 3598
 	global $upcontext, $txt;
3421 3599
 
3422
-	if (!empty($upcontext['pause']))
3423
-		echo '
3600
+	if (!empty($upcontext['pause'])) {
3601
+			echo '
3424 3602
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3425 3603
 
3426 3604
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3427 3605
 								<h3>
3428 3606
 									', $txt['upgrade_paused_overload'], '
3429 3607
 								</h3>';
3608
+	}
3430 3609
 
3431
-	if (!empty($upcontext['custom_warning']))
3432
-		echo '
3610
+	if (!empty($upcontext['custom_warning'])) {
3611
+			echo '
3433 3612
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3434 3613
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3435 3614
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3436 3615
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3437 3616
 								</div>';
3617
+	}
3438 3618
 
3439 3619
 	echo '
3440 3620
 								<div class="righttext" style="margin: 1ex;">';
3441 3621
 
3442
-	if (!empty($upcontext['continue']))
3443
-		echo '
3622
+	if (!empty($upcontext['continue'])) {
3623
+			echo '
3444 3624
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3445
-	if (!empty($upcontext['skip']))
3446
-		echo '
3625
+	}
3626
+	if (!empty($upcontext['skip'])) {
3627
+			echo '
3447 3628
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3629
+	}
3448 3630
 
3449 3631
 	echo '
3450 3632
 								</div>
@@ -3494,11 +3676,12 @@  discard block
 block discarded – undo
3494 3676
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3495 3677
 	<smf>';
3496 3678
 
3497
-	if (!empty($upcontext['get_data']))
3498
-		foreach ($upcontext['get_data'] as $k => $v)
3679
+	if (!empty($upcontext['get_data'])) {
3680
+			foreach ($upcontext['get_data'] as $k => $v)
3499 3681
 			echo '
3500 3682
 		<get key="', $k, '">', $v, '</get>';
3501
-}
3683
+	}
3684
+	}
3502 3685
 
3503 3686
 function template_xml_below()
3504 3687
 {
@@ -3539,8 +3722,8 @@  discard block
 block discarded – undo
3539 3722
 	template_chmod();
3540 3723
 
3541 3724
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3542
-	if ($upcontext['is_large_forum'])
3543
-		echo '
3725
+	if ($upcontext['is_large_forum']) {
3726
+			echo '
3544 3727
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3545 3728
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3546 3729
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3548,10 +3731,11 @@  discard block
 block discarded – undo
3548 3731
 				', $txt['upgrade_warning_lots_data'], '
3549 3732
 			</div>
3550 3733
 		</div>';
3734
+	}
3551 3735
 
3552 3736
 	// A warning message?
3553
-	if (!empty($upcontext['warning']))
3554
-		echo '
3737
+	if (!empty($upcontext['warning'])) {
3738
+			echo '
3555 3739
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3556 3740
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3557 3741
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3559,6 +3743,7 @@  discard block
 block discarded – undo
3559 3743
 				', $upcontext['warning'], '
3560 3744
 			</div>
3561 3745
 		</div>';
3746
+	}
3562 3747
 
3563 3748
 	// Paths are incorrect?
3564 3749
 	echo '
@@ -3574,20 +3759,22 @@  discard block
 block discarded – undo
3574 3759
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3575 3760
 	{
3576 3761
 		$ago = time() - $upcontext['started'];
3577
-		if ($ago < 60)
3578
-			$ago = $ago . ' seconds';
3579
-		elseif ($ago < 3600)
3580
-			$ago = (int) ($ago / 60) . ' minutes';
3581
-		else
3582
-			$ago = (int) ($ago / 3600) . ' hours';
3762
+		if ($ago < 60) {
3763
+					$ago = $ago . ' seconds';
3764
+		} elseif ($ago < 3600) {
3765
+					$ago = (int) ($ago / 60) . ' minutes';
3766
+		} else {
3767
+					$ago = (int) ($ago / 3600) . ' hours';
3768
+		}
3583 3769
 
3584 3770
 		$active = time() - $upcontext['updated'];
3585
-		if ($active < 60)
3586
-			$updated = $active . ' seconds';
3587
-		elseif ($active < 3600)
3588
-			$updated = (int) ($active / 60) . ' minutes';
3589
-		else
3590
-			$updated = (int) ($active / 3600) . ' hours';
3771
+		if ($active < 60) {
3772
+					$updated = $active . ' seconds';
3773
+		} elseif ($active < 3600) {
3774
+					$updated = (int) ($active / 60) . ' minutes';
3775
+		} else {
3776
+					$updated = (int) ($active / 3600) . ' hours';
3777
+		}
3591 3778
 
3592 3779
 		echo '
3593 3780
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3596,16 +3783,18 @@  discard block
 block discarded – undo
3596 3783
 			<div style="padding-left: 6ex;">
3597 3784
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3598 3785
 
3599
-		if ($active < 600)
3600
-			echo '
3786
+		if ($active < 600) {
3787
+					echo '
3601 3788
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3789
+		}
3602 3790
 
3603
-		if ($active > $upcontext['inactive_timeout'])
3604
-			echo '
3791
+		if ($active > $upcontext['inactive_timeout']) {
3792
+					echo '
3605 3793
 				<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.';
3606
-		else
3607
-			echo '
3794
+		} else {
3795
+					echo '
3608 3796
 				<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!');
3797
+		}
3609 3798
 
3610 3799
 		echo '
3611 3800
 			</div>
@@ -3621,9 +3810,10 @@  discard block
 block discarded – undo
3621 3810
 					<td>
3622 3811
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3623 3812
 
3624
-	if (!empty($upcontext['username_incorrect']))
3625
-		echo '
3813
+	if (!empty($upcontext['username_incorrect'])) {
3814
+			echo '
3626 3815
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3816
+	}
3627 3817
 
3628 3818
 	echo '
3629 3819
 					</td>
@@ -3634,9 +3824,10 @@  discard block
 block discarded – undo
3634 3824
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3635 3825
 						<input type="hidden" name="hash_passwrd" value="">';
3636 3826
 
3637
-	if (!empty($upcontext['password_failed']))
3638
-		echo '
3827
+	if (!empty($upcontext['password_failed'])) {
3828
+			echo '
3639 3829
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3830
+	}
3640 3831
 
3641 3832
 	echo '
3642 3833
 					</td>
@@ -3707,8 +3898,8 @@  discard block
 block discarded – undo
3707 3898
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3708 3899
 
3709 3900
 	// Warning message?
3710
-	if (!empty($upcontext['upgrade_options_warning']))
3711
-		echo '
3901
+	if (!empty($upcontext['upgrade_options_warning'])) {
3902
+			echo '
3712 3903
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3713 3904
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3714 3905
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3716,6 +3907,7 @@  discard block
 block discarded – undo
3716 3907
 				', $upcontext['upgrade_options_warning'], '
3717 3908
 			</div>
3718 3909
 		</div>';
3910
+	}
3719 3911
 
3720 3912
 	echo '
3721 3913
 				<table>
@@ -3758,8 +3950,8 @@  discard block
 block discarded – undo
3758 3950
 						</td>
3759 3951
 					</tr>';
3760 3952
 
3761
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3762
-		echo '
3953
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3954
+			echo '
3763 3955
 					<tr valign="top">
3764 3956
 						<td width="2%">
3765 3957
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3768,6 +3960,7 @@  discard block
 block discarded – undo
3768 3960
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3769 3961
 						</td>
3770 3962
 					</tr>';
3963
+	}
3771 3964
 
3772 3965
 	echo '
3773 3966
 					<tr valign="top">
@@ -3805,10 +3998,11 @@  discard block
 block discarded – undo
3805 3998
 			</div>';
3806 3999
 
3807 4000
 	// Dont any tables so far?
3808
-	if (!empty($upcontext['previous_tables']))
3809
-		foreach ($upcontext['previous_tables'] as $table)
4001
+	if (!empty($upcontext['previous_tables'])) {
4002
+			foreach ($upcontext['previous_tables'] as $table)
3810 4003
 			echo '
3811 4004
 			<br>Completed Table: &quot;', $table, '&quot;.';
4005
+	}
3812 4006
 
3813 4007
 	echo '
3814 4008
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3845,12 +4039,13 @@  discard block
 block discarded – undo
3845 4039
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3846 4040
 
3847 4041
 		// If debug flood the screen.
3848
-		if ($is_debug)
3849
-			echo '
4042
+		if ($is_debug) {
4043
+					echo '
3850 4044
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3851 4045
 
3852 4046
 				if (document.getElementById(\'debug_section\').scrollHeight)
3853 4047
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4048
+		}
3854 4049
 
3855 4050
 		echo '
3856 4051
 				// Get the next update...
@@ -3883,8 +4078,9 @@  discard block
 block discarded – undo
3883 4078
 {
3884 4079
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3885 4080
 
3886
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3887
-		$is_debug = true;
4081
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4082
+			$is_debug = true;
4083
+	}
3888 4084
 
3889 4085
 	echo '
3890 4086
 		<h3>Executing database changes</h3>
@@ -3899,8 +4095,9 @@  discard block
 block discarded – undo
3899 4095
 	{
3900 4096
 		foreach ($upcontext['actioned_items'] as $num => $item)
3901 4097
 		{
3902
-			if ($num != 0)
3903
-				echo ' Successful!';
4098
+			if ($num != 0) {
4099
+							echo ' Successful!';
4100
+			}
3904 4101
 			echo '<br>' . $item;
3905 4102
 		}
3906 4103
 		if (!empty($upcontext['changes_complete']))
@@ -3913,28 +4110,32 @@  discard block
 block discarded – undo
3913 4110
 				$seconds = intval($active % 60);
3914 4111
 
3915 4112
 				$totalTime = '';
3916
-				if ($hours > 0)
3917
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3918
-				if ($minutes > 0)
3919
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3920
-				if ($seconds > 0)
3921
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4113
+				if ($hours > 0) {
4114
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4115
+				}
4116
+				if ($minutes > 0) {
4117
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4118
+				}
4119
+				if ($seconds > 0) {
4120
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4121
+				}
3922 4122
 			}
3923 4123
 
3924
-			if ($is_debug && !empty($totalTime))
3925
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3926
-			else
3927
-				echo ' Successful!<br><br>';
4124
+			if ($is_debug && !empty($totalTime)) {
4125
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4126
+			} else {
4127
+							echo ' Successful!<br><br>';
4128
+			}
3928 4129
 
3929 4130
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3930 4131
 		}
3931
-	}
3932
-	else
4132
+	} else
3933 4133
 	{
3934 4134
 		// Tell them how many files we have in total.
3935
-		if ($upcontext['file_count'] > 1)
3936
-			echo '
4135
+		if ($upcontext['file_count'] > 1) {
4136
+					echo '
3937 4137
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4138
+		}
3938 4139
 
3939 4140
 		echo '
3940 4141
 		<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>
@@ -3950,19 +4151,23 @@  discard block
 block discarded – undo
3950 4151
 				$seconds = intval($active % 60);
3951 4152
 
3952 4153
 				$totalTime = '';
3953
-				if ($hours > 0)
3954
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3955
-				if ($minutes > 0)
3956
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3957
-				if ($seconds > 0)
3958
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4154
+				if ($hours > 0) {
4155
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4156
+				}
4157
+				if ($minutes > 0) {
4158
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4159
+				}
4160
+				if ($seconds > 0) {
4161
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4162
+				}
3959 4163
 			}
3960 4164
 
3961 4165
 			echo '
3962 4166
 			<br><span id="upgradeCompleted">';
3963 4167
 
3964
-			if (!empty($totalTime))
3965
-				echo 'Completed in ', $totalTime, '<br>';
4168
+			if (!empty($totalTime)) {
4169
+							echo 'Completed in ', $totalTime, '<br>';
4170
+			}
3966 4171
 
3967 4172
 			echo '</span>
3968 4173
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -3999,9 +4204,10 @@  discard block
 block discarded – undo
3999 4204
 			var getData = "";
4000 4205
 			var debugItems = ', $upcontext['debug_items'], ';';
4001 4206
 
4002
-		if ($is_debug)
4003
-			echo '
4207
+		if ($is_debug) {
4208
+					echo '
4004 4209
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4210
+		}
4005 4211
 
4006 4212
 		echo '
4007 4213
 			function getNextItem()
@@ -4041,9 +4247,10 @@  discard block
 block discarded – undo
4041 4247
 						document.getElementById("error_block").style.display = "";
4042 4248
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4043 4249
 
4044
-	if ($is_debug)
4045
-		echo '
4250
+	if ($is_debug) {
4251
+			echo '
4046 4252
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4253
+	}
4047 4254
 
4048 4255
 	echo '
4049 4256
 					}
@@ -4064,9 +4271,10 @@  discard block
 block discarded – undo
4064 4271
 						document.getElementById("error_block").style.display = "";
4065 4272
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4066 4273
 
4067
-	if ($is_debug)
4068
-		echo '
4274
+	if ($is_debug) {
4275
+			echo '
4069 4276
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4277
+	}
4070 4278
 
4071 4279
 	echo '
4072 4280
 					}
@@ -4125,8 +4333,8 @@  discard block
 block discarded – undo
4125 4333
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4126 4334
 				{';
4127 4335
 
4128
-		if ($is_debug)
4129
-			echo '
4336
+		if ($is_debug) {
4337
+					echo '
4130 4338
 					document.getElementById(\'debug_section\').style.display = "none";
4131 4339
 
4132 4340
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4144,6 +4352,7 @@  discard block
 block discarded – undo
4144 4352
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4145 4353
 
4146 4354
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4355
+		}
4147 4356
 
4148 4357
 		echo '
4149 4358
 
@@ -4151,9 +4360,10 @@  discard block
 block discarded – undo
4151 4360
 					document.getElementById(\'contbutt\').disabled = 0;
4152 4361
 					document.getElementById(\'database_done\').value = 1;';
4153 4362
 
4154
-		if ($upcontext['file_count'] > 1)
4155
-			echo '
4363
+		if ($upcontext['file_count'] > 1) {
4364
+					echo '
4156 4365
 					document.getElementById(\'info1\').style.display = "none";';
4366
+		}
4157 4367
 
4158 4368
 		echo '
4159 4369
 					document.getElementById(\'info2\').style.display = "none";
@@ -4166,9 +4376,10 @@  discard block
 block discarded – undo
4166 4376
 					lastItem = 0;
4167 4377
 					prevFile = curFile;';
4168 4378
 
4169
-		if ($is_debug)
4170
-			echo '
4379
+		if ($is_debug) {
4380
+					echo '
4171 4381
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4382
+		}
4172 4383
 
4173 4384
 		echo '
4174 4385
 					getNextItem();
@@ -4176,8 +4387,8 @@  discard block
 block discarded – undo
4176 4387
 				}';
4177 4388
 
4178 4389
 		// If debug scroll the screen.
4179
-		if ($is_debug)
4180
-			echo '
4390
+		if ($is_debug) {
4391
+					echo '
4181 4392
 				if (iLastSubStepProgress == -1)
4182 4393
 				{
4183 4394
 					// Give it consistent dots.
@@ -4196,6 +4407,7 @@  discard block
 block discarded – undo
4196 4407
 
4197 4408
 				if (document.getElementById(\'debug_section\').scrollHeight)
4198 4409
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4410
+		}
4199 4411
 
4200 4412
 		echo '
4201 4413
 				// Update the page.
@@ -4256,9 +4468,10 @@  discard block
 block discarded – undo
4256 4468
 			}';
4257 4469
 
4258 4470
 		// Start things off assuming we've not errored.
4259
-		if (empty($upcontext['error_message']))
4260
-			echo '
4471
+		if (empty($upcontext['error_message'])) {
4472
+					echo '
4261 4473
 			getNextItem();';
4474
+		}
4262 4475
 
4263 4476
 		echo '
4264 4477
 		//# sourceURL=dynamicScript-dbch.js 
@@ -4276,18 +4489,21 @@  discard block
 block discarded – undo
4276 4489
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4277 4490
 	<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>';
4278 4491
 
4279
-	if (!empty($upcontext['error_message']))
4280
-		echo '
4492
+	if (!empty($upcontext['error_message'])) {
4493
+			echo '
4281 4494
 	<error>', $upcontext['error_message'], '</error>';
4495
+	}
4282 4496
 
4283
-	if (!empty($upcontext['error_string']))
4284
-		echo '
4497
+	if (!empty($upcontext['error_string'])) {
4498
+			echo '
4285 4499
 	<sql>', $upcontext['error_string'], '</sql>';
4500
+	}
4286 4501
 
4287
-	if ($is_debug)
4288
-		echo '
4502
+	if ($is_debug) {
4503
+			echo '
4289 4504
 	<curtime>', time(), '</curtime>';
4290
-}
4505
+	}
4506
+	}
4291 4507
 
4292 4508
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4293 4509
 function template_convert_utf8()
@@ -4306,18 +4522,20 @@  discard block
 block discarded – undo
4306 4522
 			</div>';
4307 4523
 
4308 4524
 	// Done any tables so far?
4309
-	if (!empty($upcontext['previous_tables']))
4310
-		foreach ($upcontext['previous_tables'] as $table)
4525
+	if (!empty($upcontext['previous_tables'])) {
4526
+			foreach ($upcontext['previous_tables'] as $table)
4311 4527
 			echo '
4312 4528
 			<br>Completed Table: &quot;', $table, '&quot;.';
4529
+	}
4313 4530
 
4314 4531
 	echo '
4315 4532
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4316 4533
 
4317 4534
 	// If we dropped their index, let's let them know
4318
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index'])
4319
-		echo '
4535
+	if ($upcontext['cur_table_num'] == $upcontext['table_count'] && $upcontext['dropping_index']) {
4536
+			echo '
4320 4537
 			<br><span style="display:inline;">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated.</span>';
4538
+	}
4321 4539
 
4322 4540
 	echo '
4323 4541
 			<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>';
@@ -4353,12 +4571,13 @@  discard block
 block discarded – undo
4353 4571
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4354 4572
 
4355 4573
 		// If debug flood the screen.
4356
-		if ($is_debug)
4357
-			echo '
4574
+		if ($is_debug) {
4575
+					echo '
4358 4576
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4359 4577
 
4360 4578
 				if (document.getElementById(\'debug_section\').scrollHeight)
4361 4579
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4580
+		}
4362 4581
 
4363 4582
 		echo '
4364 4583
 				// Get the next update...
@@ -4403,19 +4622,21 @@  discard block
 block discarded – undo
4403 4622
 			</div>';
4404 4623
 
4405 4624
 	// Dont any tables so far?
4406
-	if (!empty($upcontext['previous_tables']))
4407
-		foreach ($upcontext['previous_tables'] as $table)
4625
+	if (!empty($upcontext['previous_tables'])) {
4626
+			foreach ($upcontext['previous_tables'] as $table)
4408 4627
 			echo '
4409 4628
 			<br>Completed Table: &quot;', $table, '&quot;.';
4629
+	}
4410 4630
 
4411 4631
 	echo '
4412 4632
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4413 4633
 			<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>';
4414 4634
 
4415 4635
 	// Try to make sure substep was reset.
4416
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4417
-		echo '
4636
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4637
+			echo '
4418 4638
 			<input type="hidden" name="substep" id="substep" value="0">';
4639
+	}
4419 4640
 
4420 4641
 	// Continue please!
4421 4642
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4448,12 +4669,13 @@  discard block
 block discarded – undo
4448 4669
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4449 4670
 
4450 4671
 		// If debug flood the screen.
4451
-		if ($is_debug)
4452
-			echo '
4672
+		if ($is_debug) {
4673
+					echo '
4453 4674
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4454 4675
 
4455 4676
 				if (document.getElementById(\'debug_section\').scrollHeight)
4456 4677
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4678
+		}
4457 4679
 
4458 4680
 		echo '
4459 4681
 				// Get the next update...
@@ -4489,8 +4711,8 @@  discard block
 block discarded – undo
4489 4711
 	<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>
4490 4712
 	<form action="', $boardurl, '/index.php">';
4491 4713
 
4492
-	if (!empty($upcontext['can_delete_script']))
4493
-		echo '
4714
+	if (!empty($upcontext['can_delete_script'])) {
4715
+			echo '
4494 4716
 			<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>
4495 4717
 			<script>
4496 4718
 				function doTheDelete(theCheck)
@@ -4502,6 +4724,7 @@  discard block
 block discarded – undo
4502 4724
 				}
4503 4725
 			</script>
4504 4726
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4727
+	}
4505 4728
 
4506 4729
 	$active = time() - $upcontext['started'];
4507 4730
 	$hours = floor($active / 3600);
@@ -4511,16 +4734,20 @@  discard block
 block discarded – undo
4511 4734
 	if ($is_debug)
4512 4735
 	{
4513 4736
 		$totalTime = '';
4514
-		if ($hours > 0)
4515
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4516
-		if ($minutes > 0)
4517
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4518
-		if ($seconds > 0)
4519
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4737
+		if ($hours > 0) {
4738
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4739
+		}
4740
+		if ($minutes > 0) {
4741
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4742
+		}
4743
+		if ($seconds > 0) {
4744
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4745
+		}
4520 4746
 	}
4521 4747
 
4522
-	if ($is_debug && !empty($totalTime))
4523
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4748
+	if ($is_debug && !empty($totalTime)) {
4749
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4750
+	}
4524 4751
 
4525 4752
 	echo '<br>
4526 4753
 			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>
@@ -4547,8 +4774,9 @@  discard block
 block discarded – undo
4547 4774
 
4548 4775
 	$current_substep = $_GET['substep'];
4549 4776
 
4550
-	if (empty($_GET['a']))
4551
-		$_GET['a'] = 0;
4777
+	if (empty($_GET['a'])) {
4778
+			$_GET['a'] = 0;
4779
+	}
4552 4780
 	$step_progress['name'] = 'Converting ips';
4553 4781
 	$step_progress['current'] = $_GET['a'];
4554 4782
 
@@ -4591,16 +4819,19 @@  discard block
 block discarded – undo
4591 4819
 				'empty' => '',
4592 4820
 				'limit' => $limit,
4593 4821
 		));
4594
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4595
-			$arIp[] = $row[$oldCol];
4822
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4823
+					$arIp[] = $row[$oldCol];
4824
+		}
4596 4825
 		$smcFunc['db_free_result']($request);
4597 4826
 
4598 4827
 		// Special case, null ip could keep us in a loop.
4599
-		if (is_null($arIp[0]))
4600
-			unset($arIp[0]);
4828
+		if (is_null($arIp[0])) {
4829
+					unset($arIp[0]);
4830
+		}
4601 4831
 
4602
-		if (empty($arIp))
4603
-			$is_done = true;
4832
+		if (empty($arIp)) {
4833
+					$is_done = true;
4834
+		}
4604 4835
 
4605 4836
 		$updates = array();
4606 4837
 		$cases = array();
@@ -4609,16 +4840,18 @@  discard block
 block discarded – undo
4609 4840
 		{
4610 4841
 			$arIp[$i] = trim($arIp[$i]);
4611 4842
 
4612
-			if (empty($arIp[$i]))
4613
-				continue;
4843
+			if (empty($arIp[$i])) {
4844
+							continue;
4845
+			}
4614 4846
 
4615 4847
 			$updates['ip' . $i] = $arIp[$i];
4616 4848
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4617 4849
 
4618 4850
 			if ($setSize > 0 && $i % $setSize === 0)
4619 4851
 			{
4620
-				if (count($updates) == 1)
4621
-					continue;
4852
+				if (count($updates) == 1) {
4853
+									continue;
4854
+				}
4622 4855
 
4623 4856
 				$updates['whereSet'] = array_values($updates);
4624 4857
 				$smcFunc['db_query']('', '
@@ -4652,8 +4885,7 @@  discard block
 block discarded – undo
4652 4885
 							'ip' => $ip
4653 4886
 					));
4654 4887
 				}
4655
-			}
4656
-			else
4888
+			} else
4657 4889
 			{
4658 4890
 				$updates['whereSet'] = array_values($updates);
4659 4891
 				$smcFunc['db_query']('', '
@@ -4667,9 +4899,9 @@  discard block
 block discarded – undo
4667 4899
 					$updates
4668 4900
 				);
4669 4901
 			}
4902
+		} else {
4903
+					$is_done = true;
4670 4904
 		}
4671
-		else
4672
-			$is_done = true;
4673 4905
 
4674 4906
 		$_GET['a'] += $limit;
4675 4907
 		$step_progress['current'] = $_GET['a'];
@@ -4695,10 +4927,11 @@  discard block
 block discarded – undo
4695 4927
  
4696 4928
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4697 4929
 
4698
-	if (isset($columns[$column]))
4699
-		return $columns[$column];
4700
-	else
4701
-		return null;
4702
-}
4930
+	if (isset($columns[$column])) {
4931
+			return $columns[$column];
4932
+	} else {
4933
+			return null;
4934
+	}
4935
+	}
4703 4936
 
4704 4937
 ?>
4705 4938
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/ManageServer.php 1 patch
Braces   +262 added lines, -202 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';
@@ -186,8 +189,9 @@  discard block
 block discarded – undo
186 189
 			$registerSMStats = registerSMStats();
187 190
 
188 191
 			// Failed to register, disable it again.
189
-			if (empty($registerSMStats))
190
-				$_POST['enable_sm_stats'] = 0;
192
+			if (empty($registerSMStats)) {
193
+							$_POST['enable_sm_stats'] = 0;
194
+			}
191 195
 		}
192 196
 
193 197
 		saveSettings($config_vars);
@@ -244,8 +248,9 @@  discard block
 block discarded – undo
244 248
 
245 249
 	call_integration_hook('integrate_database_settings', array(&$config_vars));
246 250
 
247
-	if ($return_config)
248
-		return $config_vars;
251
+	if ($return_config) {
252
+			return $config_vars;
253
+	}
249 254
 
250 255
 	// Setup the template stuff.
251 256
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
@@ -320,13 +325,15 @@  discard block
 block discarded – undo
320 325
 		hideGlobalCookies();
321 326
 	});', true);
322 327
 
323
-	if (empty($user_settings['tfa_secret']))
324
-		addInlineJavaScript('');
328
+	if (empty($user_settings['tfa_secret'])) {
329
+			addInlineJavaScript('');
330
+	}
325 331
 
326 332
 	call_integration_hook('integrate_cookie_settings', array(&$config_vars));
327 333
 
328
-	if ($return_config)
329
-		return $config_vars;
334
+	if ($return_config) {
335
+			return $config_vars;
336
+	}
330 337
 
331 338
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
332 339
 	$context['settings_title'] = $txt['cookies_sessions_settings'];
@@ -337,11 +344,13 @@  discard block
 block discarded – undo
337 344
 		call_integration_hook('integrate_save_cookie_settings');
338 345
 
339 346
 		// Local and global do not play nicely together.
340
-		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
341
-			unset ($_POST['globalCookies']);
347
+		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) {
348
+					unset ($_POST['globalCookies']);
349
+		}
342 350
 
343
-		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
344
-			fatal_lang_error('invalid_cookie_domain', false);
351
+		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) {
352
+					fatal_lang_error('invalid_cookie_domain', false);
353
+		}
345 354
 
346 355
 		saveSettings($config_vars);
347 356
 
@@ -424,8 +433,9 @@  discard block
 block discarded – undo
424 433
 
425 434
 	call_integration_hook('integrate_general_security_settings', array(&$config_vars));
426 435
 
427
-	if ($return_config)
428
-		return $config_vars;
436
+	if ($return_config) {
437
+			return $config_vars;
438
+	}
429 439
 
430 440
 	// Saving?
431 441
 	if (isset($_GET['save']))
@@ -464,8 +474,7 @@  discard block
 block discarded – undo
464 474
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
465 475
 		$cache_level = array($txt['cache_off']);
466 476
 		$detected['none'] = $txt['cache_off'];
467
-	}
468
-	else
477
+	} else
469 478
 	{
470 479
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
471 480
 		$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
@@ -502,8 +511,9 @@  discard block
 block discarded – undo
502 511
 			}
503 512
 		}
504 513
 	}
505
-	if ($return_config)
506
-		return $config_vars;
514
+	if ($return_config) {
515
+			return $config_vars;
516
+	}
507 517
 
508 518
 	// Saving again?
509 519
 	if (isset($_GET['save']))
@@ -531,8 +541,9 @@  discard block
 block discarded – undo
531 541
 	$context['save_disabled'] = $context['settings_not_writable'];
532 542
 
533 543
 	// Decide what message to show.
534
-	if (!$context['save_disabled'])
535
-		$context['settings_message'] = $txt['caching_information'];
544
+	if (!$context['save_disabled']) {
545
+			$context['settings_message'] = $txt['caching_information'];
546
+	}
536 547
 
537 548
 	// Prepare the template.
538 549
 	prepareServerSettingsContext($config_vars);
@@ -555,24 +566,25 @@  discard block
 block discarded – undo
555 566
 	if (stripos(PHP_OS, 'win') === 0)
556 567
 	{
557 568
 		$context['settings_message'] = $txt['loadavg_disabled_windows'];
558
-		if (isset($_GET['save']))
559
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
560
-	}
561
-	elseif (stripos(PHP_OS, 'darwin') === 0)
569
+		if (isset($_GET['save'])) {
570
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
571
+		}
572
+	} elseif (stripos(PHP_OS, 'darwin') === 0)
562 573
 	{
563 574
 		$context['settings_message'] = $txt['loadavg_disabled_osx'];
564
-		if (isset($_GET['save']))
565
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
566
-	}
567
-	else
575
+		if (isset($_GET['save'])) {
576
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
577
+		}
578
+	} else
568 579
 	{
569 580
 		$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
570
-		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
571
-			$modSettings['load_average'] = (float) $matches[1];
572
-		elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
573
-			$modSettings['load_average'] = (float) $matches[1];
574
-		else
575
-			unset($modSettings['load_average']);
581
+		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) {
582
+					$modSettings['load_average'] = (float) $matches[1];
583
+		} elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) {
584
+					$modSettings['load_average'] = (float) $matches[1];
585
+		} else {
586
+					unset($modSettings['load_average']);
587
+		}
576 588
 
577 589
 		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
578 590
 		{
@@ -608,8 +620,9 @@  discard block
 block discarded – undo
608 620
 
609 621
 	call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
610 622
 
611
-	if ($return_config)
612
-		return $config_vars;
623
+	if ($return_config) {
624
+			return $config_vars;
625
+	}
613 626
 
614 627
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
615 628
 	$context['settings_title'] = $txt['load_balancing_settings'];
@@ -620,24 +633,27 @@  discard block
 block discarded – undo
620 633
 		// Stupidity is not allowed.
621 634
 		foreach ($_POST as $key => $value)
622 635
 		{
623
-			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values)))
624
-				continue;
625
-			else
626
-				$_POST[$key] = (float) $value;
627
-
628
-			if ($key == 'loadavg_auto_opt' && $value <= 1)
629
-				$_POST['loadavg_auto_opt'] = 1.0;
630
-			elseif ($key == 'loadavg_forum' && $value < 10)
631
-				$_POST['loadavg_forum'] = 10.0;
632
-			elseif ($value < 2)
633
-				$_POST[$key] = 2.0;
636
+			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) {
637
+							continue;
638
+			} else {
639
+							$_POST[$key] = (float) $value;
640
+			}
641
+
642
+			if ($key == 'loadavg_auto_opt' && $value <= 1) {
643
+							$_POST['loadavg_auto_opt'] = 1.0;
644
+			} elseif ($key == 'loadavg_forum' && $value < 10) {
645
+							$_POST['loadavg_forum'] = 10.0;
646
+			} elseif ($value < 2) {
647
+							$_POST[$key] = 2.0;
648
+			}
634 649
 		}
635 650
 
636 651
 		call_integration_hook('integrate_save_loadavg_settings');
637 652
 
638 653
 		saveDBSettings($config_vars);
639
-		if (!isset($_SESSION['adm-save']))
640
-			$_SESSION['adm-save'] = true;
654
+		if (!isset($_SESSION['adm-save'])) {
655
+					$_SESSION['adm-save'] = true;
656
+		}
641 657
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
642 658
 	}
643 659
 
@@ -673,10 +689,11 @@  discard block
 block discarded – undo
673 689
 
674 690
 	if (isset($_SESSION['adm-save']))
675 691
 	{
676
-		if ($_SESSION['adm-save'] === true)
677
-			$context['saved_successful'] = true;
678
-		else
679
-			$context['saved_failed'] = $_SESSION['adm-save'];
692
+		if ($_SESSION['adm-save'] === true) {
693
+					$context['saved_successful'] = true;
694
+		} else {
695
+					$context['saved_failed'] = $_SESSION['adm-save'];
696
+		}
680 697
 
681 698
 		unset($_SESSION['adm-save']);
682 699
 	}
@@ -684,9 +701,9 @@  discard block
 block discarded – undo
684 701
 	$context['config_vars'] = array();
685 702
 	foreach ($config_vars as $identifier => $config_var)
686 703
 	{
687
-		if (!is_array($config_var) || !isset($config_var[1]))
688
-			$context['config_vars'][] = $config_var;
689
-		else
704
+		if (!is_array($config_var) || !isset($config_var[1])) {
705
+					$context['config_vars'][] = $config_var;
706
+		} else
690 707
 		{
691 708
 			$varname = $config_var[0];
692 709
 			global $$varname;
@@ -721,16 +738,19 @@  discard block
 block discarded – undo
721 738
 			if ($config_var[3] == 'int' || $config_var[3] == 'float')
722 739
 			{
723 740
 				// Default to a min of 0 if one isn't set
724
-				if (isset($config_var['min']))
725
-					$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
726
-				else
727
-					$context['config_vars'][$config_var[0]]['min'] = 0;
741
+				if (isset($config_var['min'])) {
742
+									$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
743
+				} else {
744
+									$context['config_vars'][$config_var[0]]['min'] = 0;
745
+				}
728 746
 
729
-				if (isset($config_var['max']))
730
-					$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
747
+				if (isset($config_var['max'])) {
748
+									$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
749
+				}
731 750
 
732
-				if (isset($config_var['step']))
733
-					$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
751
+				if (isset($config_var['step'])) {
752
+									$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
753
+				}
734 754
 			}
735 755
 
736 756
 			// If this is a select box handle any data.
@@ -738,12 +758,13 @@  discard block
 block discarded – undo
738 758
 			{
739 759
 				// If it's associative
740 760
 				$config_values = array_values($config_var[4]);
741
-				if (isset($config_values[0]) && is_array($config_values[0]))
742
-					$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
743
-				else
761
+				if (isset($config_values[0]) && is_array($config_values[0])) {
762
+									$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
763
+				} else
744 764
 				{
745
-					foreach ($config_var[4] as $key => $item)
746
-						$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
765
+					foreach ($config_var[4] as $key => $item) {
766
+											$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
767
+					}
747 768
 				}
748 769
 			}
749 770
 		}
@@ -768,10 +789,11 @@  discard block
 block discarded – undo
768 789
 
769 790
 	if (isset($_SESSION['adm-save']))
770 791
 	{
771
-		if ($_SESSION['adm-save'] === true)
772
-			$context['saved_successful'] = true;
773
-		else
774
-			$context['saved_failed'] = $_SESSION['adm-save'];
792
+		if ($_SESSION['adm-save'] === true) {
793
+					$context['saved_successful'] = true;
794
+		} else {
795
+					$context['saved_failed'] = $_SESSION['adm-save'];
796
+		}
775 797
 
776 798
 		unset($_SESSION['adm-save']);
777 799
 	}
@@ -783,26 +805,30 @@  discard block
 block discarded – undo
783 805
 	foreach ($config_vars as $config_var)
784 806
 	{
785 807
 		// HR?
786
-		if (!is_array($config_var))
787
-			$context['config_vars'][] = $config_var;
788
-		else
808
+		if (!is_array($config_var)) {
809
+					$context['config_vars'][] = $config_var;
810
+		} else
789 811
 		{
790 812
 			// If it has no name it doesn't have any purpose!
791
-			if (empty($config_var[1]))
792
-				continue;
813
+			if (empty($config_var[1])) {
814
+							continue;
815
+			}
793 816
 
794 817
 			// Special case for inline permissions
795
-			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
796
-				$inlinePermissions[] = $config_var[1];
797
-			elseif ($config_var[0] == 'permissions')
798
-				continue;
818
+			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
819
+							$inlinePermissions[] = $config_var[1];
820
+			} elseif ($config_var[0] == 'permissions') {
821
+							continue;
822
+			}
799 823
 
800
-			if ($config_var[0] == 'boards')
801
-				$board_list = true;
824
+			if ($config_var[0] == 'boards') {
825
+							$board_list = true;
826
+			}
802 827
 
803 828
 			// Are we showing the BBC selection box?
804
-			if ($config_var[0] == 'bbc')
805
-				$bbcChoice[] = $config_var[1];
829
+			if ($config_var[0] == 'bbc') {
830
+							$bbcChoice[] = $config_var[1];
831
+			}
806 832
 
807 833
 			// We need to do some parsing of the value before we pass it in.
808 834
 			if (isset($modSettings[$config_var[1]]))
@@ -821,8 +847,7 @@  discard block
 block discarded – undo
821 847
 					default:
822 848
 						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
823 849
 				}
824
-			}
825
-			else
850
+			} else
826 851
 			{
827 852
 				// Darn, it's empty. What type is expected?
828 853
 				switch ($config_var[0])
@@ -862,16 +887,19 @@  discard block
 block discarded – undo
862 887
 			if ($config_var[0] == 'int' || $config_var[0] == 'float')
863 888
 			{
864 889
 				// Default to a min of 0 if one isn't set
865
-				if (isset($config_var['min']))
866
-					$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
867
-				else
868
-					$context['config_vars'][$config_var[1]]['min'] = 0;
890
+				if (isset($config_var['min'])) {
891
+									$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
892
+				} else {
893
+									$context['config_vars'][$config_var[1]]['min'] = 0;
894
+				}
869 895
 
870
-				if (isset($config_var['max']))
871
-					$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
896
+				if (isset($config_var['max'])) {
897
+									$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
898
+				}
872 899
 
873
-				if (isset($config_var['step']))
874
-					$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
900
+				if (isset($config_var['step'])) {
901
+									$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
902
+				}
875 903
 			}
876 904
 
877 905
 			// If this is a select box handle any data.
@@ -885,12 +913,13 @@  discard block
 block discarded – undo
885 913
 				}
886 914
 
887 915
 				// If it's associative
888
-				if (isset($config_var[2][0]) && is_array($config_var[2][0]))
889
-					$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
890
-				else
916
+				if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
917
+									$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
918
+				} else
891 919
 				{
892
-					foreach ($config_var[2] as $key => $item)
893
-						$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
920
+					foreach ($config_var[2] as $key => $item) {
921
+											$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
922
+					}
894 923
 				}
895 924
 			}
896 925
 
@@ -899,17 +928,19 @@  discard block
 block discarded – undo
899 928
 			{
900 929
 				if (!is_numeric($k))
901 930
 				{
902
-					if (substr($k, 0, 2) == 'on')
903
-						$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
904
-					else
905
-						$context['config_vars'][$config_var[1]][$k] = $v;
931
+					if (substr($k, 0, 2) == 'on') {
932
+											$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
933
+					} else {
934
+											$context['config_vars'][$config_var[1]][$k] = $v;
935
+					}
906 936
 				}
907 937
 
908 938
 				// See if there are any other labels that might fit?
909
-				if (isset($txt['setting_' . $config_var[1]]))
910
-					$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
911
-				elseif (isset($txt['groups_' . $config_var[1]]))
912
-					$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
939
+				if (isset($txt['setting_' . $config_var[1]])) {
940
+									$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
941
+				} elseif (isset($txt['groups_' . $config_var[1]])) {
942
+									$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
943
+				}
913 944
 			}
914 945
 
915 946
 			// Set the subtext in case it's part of the label.
@@ -942,8 +973,9 @@  discard block
 block discarded – undo
942 973
 		// What are the options, eh?
943 974
 		$temp = parse_bbc(false);
944 975
 		$bbcTags = array();
945
-		foreach ($temp as $tag)
946
-			$bbcTags[] = $tag['tag'];
976
+		foreach ($temp as $tag) {
977
+					$bbcTags[] = $tag['tag'];
978
+		}
947 979
 
948 980
 		$bbcTags = array_unique($bbcTags);
949 981
 		$totalTags = count($bbcTags);
@@ -958,8 +990,9 @@  discard block
 block discarded – undo
958 990
 		$col = 0; $i = 0;
959 991
 		foreach ($bbcTags as $tag)
960 992
 		{
961
-			if ($i % $tagsPerColumn == 0 && $i != 0)
962
-				$col++;
993
+			if ($i % $tagsPerColumn == 0 && $i != 0) {
994
+							$col++;
995
+			}
963 996
 
964 997
 			$context['bbc_columns'][$col][] = array(
965 998
 				'tag' => $tag,
@@ -1002,18 +1035,21 @@  discard block
 block discarded – undo
1002 1035
 	validateToken('admin-ssc');
1003 1036
 
1004 1037
 	// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
1005
-	if (isset($_POST['cookiename']))
1006
-		$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1038
+	if (isset($_POST['cookiename'])) {
1039
+			$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1040
+	}
1007 1041
 
1008 1042
 	// Fix the forum's URL if necessary.
1009 1043
 	if (isset($_POST['boardurl']))
1010 1044
 	{
1011
-		if (substr($_POST['boardurl'], -10) == '/index.php')
1012
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1013
-		elseif (substr($_POST['boardurl'], -1) == '/')
1014
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1015
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1016
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1045
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1046
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1047
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1048
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1049
+		}
1050
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1051
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1052
+		}
1017 1053
 	}
1018 1054
 
1019 1055
 	// Any passwords?
@@ -1048,21 +1084,21 @@  discard block
 block discarded – undo
1048 1084
 	// Figure out which config vars we're saving here...
1049 1085
 	foreach ($config_vars as $var)
1050 1086
 	{
1051
-		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]])))
1052
-			continue;
1087
+		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) {
1088
+					continue;
1089
+		}
1053 1090
 
1054 1091
 		$config_var = $var[0];
1055 1092
 
1056 1093
 		if (in_array($config_var, $config_passwords))
1057 1094
 		{
1058
-			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
1059
-				$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1060
-		}
1061
-		elseif (in_array($config_var, $config_strs))
1095
+			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) {
1096
+							$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1097
+			}
1098
+		} elseif (in_array($config_var, $config_strs))
1062 1099
 		{
1063 1100
 			$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
1064
-		}
1065
-		elseif (in_array($config_var, $config_ints))
1101
+		} elseif (in_array($config_var, $config_ints))
1066 1102
 		{
1067 1103
 			$new_settings[$config_var] = (int) $_POST[$config_var];
1068 1104
 
@@ -1071,17 +1107,17 @@  discard block
 block discarded – undo
1071 1107
 			$new_settings[$config_var] = max($min, $new_settings[$config_var]);
1072 1108
 
1073 1109
 			// Is there a max value for this as well?
1074
-			if (isset($var['max']))
1075
-				$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1076
-		}
1077
-		elseif (in_array($config_var, $config_bools))
1110
+			if (isset($var['max'])) {
1111
+							$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1112
+			}
1113
+		} elseif (in_array($config_var, $config_bools))
1078 1114
 		{
1079
-			if (!empty($_POST[$config_var]))
1080
-				$new_settings[$config_var] = '1';
1081
-			else
1082
-				$new_settings[$config_var] = '0';
1083
-		}
1084
-		else
1115
+			if (!empty($_POST[$config_var])) {
1116
+							$new_settings[$config_var] = '1';
1117
+			} else {
1118
+							$new_settings[$config_var] = '0';
1119
+			}
1120
+		} else
1085 1121
 		{
1086 1122
 			// This shouldn't happen, but it might...
1087 1123
 			fatal_error('Unknown config_var \'' . $config_var . '\'');
@@ -1097,30 +1133,35 @@  discard block
 block discarded – undo
1097 1133
 	foreach ($config_vars as $config_var)
1098 1134
 	{
1099 1135
 		// We just saved the file-based settings, so skip their definitions.
1100
-		if (!is_array($config_var) || $config_var[2] == 'file')
1101
-			continue;
1136
+		if (!is_array($config_var) || $config_var[2] == 'file') {
1137
+					continue;
1138
+		}
1102 1139
 
1103 1140
 		$new_setting = array($config_var[3], $config_var[0]);
1104 1141
 
1105 1142
 		// Select options need carried over, too.
1106
-		if (isset($config_var[4]))
1107
-			$new_setting[] = $config_var[4];
1143
+		if (isset($config_var[4])) {
1144
+					$new_setting[] = $config_var[4];
1145
+		}
1108 1146
 
1109 1147
 		// Include min and max if necessary
1110
-		if (isset($config_var['min']))
1111
-			$new_setting['min'] = $config_var['min'];
1148
+		if (isset($config_var['min'])) {
1149
+					$new_setting['min'] = $config_var['min'];
1150
+		}
1112 1151
 
1113
-		if (isset($config_var['max']))
1114
-			$new_setting['max'] = $config_var['max'];
1152
+		if (isset($config_var['max'])) {
1153
+					$new_setting['max'] = $config_var['max'];
1154
+		}
1115 1155
 
1116 1156
 		// Rewrite the definition a bit.
1117 1157
 		$new_settings[] = $new_setting;
1118 1158
 	}
1119 1159
 
1120 1160
 	// Save the new database-based settings, if any.
1121
-	if (!empty($new_settings))
1122
-		saveDBSettings($new_settings);
1123
-}
1161
+	if (!empty($new_settings)) {
1162
+			saveDBSettings($new_settings);
1163
+	}
1164
+	}
1124 1165
 
1125 1166
 /**
1126 1167
  * Helper function for saving database settings.
@@ -1138,22 +1179,25 @@  discard block
 block discarded – undo
1138 1179
 	$inlinePermissions = array();
1139 1180
 	foreach ($config_vars as $var)
1140 1181
 	{
1141
-		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']))))
1142
-			continue;
1182
+		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'])))) {
1183
+					continue;
1184
+		}
1143 1185
 
1144 1186
 		// Checkboxes!
1145
-		elseif ($var[0] == 'check')
1146
-			$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1187
+		elseif ($var[0] == 'check') {
1188
+					$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1189
+		}
1147 1190
 		// Select boxes!
1148
-		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
1149
-			$setArray[$var[1]] = $_POST[$var[1]];
1150
-		elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1191
+		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) {
1192
+					$setArray[$var[1]] = $_POST[$var[1]];
1193
+		} elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1151 1194
 		{
1152 1195
 			// For security purposes we validate this line by line.
1153 1196
 			$lOptions = array();
1154
-			foreach ($_POST[$var[1]] as $invar)
1155
-				if (in_array($invar, array_keys($var[2])))
1197
+			foreach ($_POST[$var[1]] as $invar) {
1198
+							if (in_array($invar, array_keys($var[2])))
1156 1199
 					$lOptions[] = $invar;
1200
+			}
1157 1201
 
1158 1202
 			$setArray[$var[1]] = json_encode($lOptions);
1159 1203
 		}
@@ -1167,18 +1211,20 @@  discard block
 block discarded – undo
1167 1211
 				$request = $smcFunc['db_query']('', '
1168 1212
 					SELECT id_board
1169 1213
 					FROM {db_prefix}boards');
1170
-				while ($row = $smcFunc['db_fetch_row']($request))
1171
-					$board_list[$row[0]] = true;
1214
+				while ($row = $smcFunc['db_fetch_row']($request)) {
1215
+									$board_list[$row[0]] = true;
1216
+				}
1172 1217
 
1173 1218
 				$smcFunc['db_free_result']($request);
1174 1219
 			}
1175 1220
 
1176 1221
 			$lOptions = array();
1177 1222
 
1178
-			if (!empty($_POST[$var[1]]))
1179
-				foreach ($_POST[$var[1]] as $invar => $dummy)
1223
+			if (!empty($_POST[$var[1]])) {
1224
+							foreach ($_POST[$var[1]] as $invar => $dummy)
1180 1225
 					if (isset($board_list[$invar]))
1181 1226
 						$lOptions[] = $invar;
1227
+			}
1182 1228
 
1183 1229
 			$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : '';
1184 1230
 		}
@@ -1192,8 +1238,9 @@  discard block
 block discarded – undo
1192 1238
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1193 1239
 
1194 1240
 			// Do we have a max value for this as well?
1195
-			if (isset($var['max']))
1196
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1241
+			if (isset($var['max'])) {
1242
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1243
+			}
1197 1244
 		}
1198 1245
 		// Floating point!
1199 1246
 		elseif ($var[0] == 'float')
@@ -1205,40 +1252,47 @@  discard block
 block discarded – undo
1205 1252
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1206 1253
 
1207 1254
 			// Do we have a max value for this as well?
1208
-			if (isset($var['max']))
1209
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1255
+			if (isset($var['max'])) {
1256
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1257
+			}
1210 1258
 		}
1211 1259
 		// Text!
1212
-		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time')))
1213
-			$setArray[$var[1]] = $_POST[$var[1]];
1260
+		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) {
1261
+					$setArray[$var[1]] = $_POST[$var[1]];
1262
+		}
1214 1263
 		// Passwords!
1215 1264
 		elseif ($var[0] == 'password')
1216 1265
 		{
1217
-			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
1218
-				$setArray[$var[1]] = $_POST[$var[1]][0];
1266
+			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) {
1267
+							$setArray[$var[1]] = $_POST[$var[1]][0];
1268
+			}
1219 1269
 		}
1220 1270
 		// BBC.
1221 1271
 		elseif ($var[0] == 'bbc')
1222 1272
 		{
1223 1273
 
1224 1274
 			$bbcTags = array();
1225
-			foreach (parse_bbc(false) as $tag)
1226
-				$bbcTags[] = $tag['tag'];
1275
+			foreach (parse_bbc(false) as $tag) {
1276
+							$bbcTags[] = $tag['tag'];
1277
+			}
1227 1278
 
1228
-			if (!isset($_POST[$var[1] . '_enabledTags']))
1229
-				$_POST[$var[1] . '_enabledTags'] = array();
1230
-			elseif (!is_array($_POST[$var[1] . '_enabledTags']))
1231
-				$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1279
+			if (!isset($_POST[$var[1] . '_enabledTags'])) {
1280
+							$_POST[$var[1] . '_enabledTags'] = array();
1281
+			} elseif (!is_array($_POST[$var[1] . '_enabledTags'])) {
1282
+							$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1283
+			}
1232 1284
 
1233 1285
 			$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
1234 1286
 		}
1235 1287
 		// Permissions?
1236
-		elseif ($var[0] == 'permissions')
1237
-			$inlinePermissions[] = $var[1];
1288
+		elseif ($var[0] == 'permissions') {
1289
+					$inlinePermissions[] = $var[1];
1290
+		}
1238 1291
 	}
1239 1292
 
1240
-	if (!empty($setArray))
1241
-		updateSettings($setArray);
1293
+	if (!empty($setArray)) {
1294
+			updateSettings($setArray);
1295
+	}
1242 1296
 
1243 1297
 	// If we have inline permissions we need to save them.
1244 1298
 	if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
@@ -1275,18 +1329,21 @@  discard block
 block discarded – undo
1275 1329
 	// put all of it into an array
1276 1330
 	foreach ($info_lines as $line)
1277 1331
 	{
1278
-		if (preg_match('~(' . $remove . ')~', $line))
1279
-			continue;
1332
+		if (preg_match('~(' . $remove . ')~', $line)) {
1333
+					continue;
1334
+		}
1280 1335
 
1281 1336
 		// new category?
1282
-		if (strpos($line, '<h2>') !== false)
1283
-			$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1337
+		if (strpos($line, '<h2>') !== false) {
1338
+					$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1339
+		}
1284 1340
 
1285 1341
 		// load it as setting => value or the old setting local master
1286
-		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1287
-			$pinfo[$category][$val[1]] = $val[2];
1288
-		elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1289
-			$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1342
+		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1343
+					$pinfo[$category][$val[1]] = $val[2];
1344
+		} elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1345
+					$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1346
+		}
1290 1347
 	}
1291 1348
 
1292 1349
 	// load it in to context and display it
@@ -1321,8 +1378,9 @@  discard block
 block discarded – undo
1321 1378
 				$testAPI = new $cache_class_name();
1322 1379
 
1323 1380
 				// No Support?  NEXT!
1324
-				if (!$testAPI->isSupported(true))
1325
-					continue;
1381
+				if (!$testAPI->isSupported(true)) {
1382
+									continue;
1383
+				}
1326 1384
 
1327 1385
 				$apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache;
1328 1386
 			}
@@ -1347,8 +1405,9 @@  discard block
 block discarded – undo
1347 1405
 	global $modSettings, $boardurl, $smcFunc;
1348 1406
 
1349 1407
 	// Already have a key?  Can't register again.
1350
-	if (!empty($modSettings['sm_stats_key']))
1351
-		return true;
1408
+	if (!empty($modSettings['sm_stats_key'])) {
1409
+			return true;
1410
+	}
1352 1411
 
1353 1412
 	$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
1354 1413
 	if ($fp)
@@ -1359,8 +1418,9 @@  discard block
 block discarded – undo
1359 1418
 		fwrite($fp, $out);
1360 1419
 
1361 1420
 		$return_data = '';
1362
-		while (!feof($fp))
1363
-			$return_data .= fgets($fp, 128);
1421
+		while (!feof($fp)) {
1422
+					$return_data .= fgets($fp, 128);
1423
+		}
1364 1424
 
1365 1425
 		fclose($fp);
1366 1426
 
Please login to merge, or discard this patch.