Completed
Push — release-2.1 ( 7ebe8b...6f4f70 )
by John
14:07 queued 05:28
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.
Sources/ManageServer.php 1 patch
Braces   +265 added lines, -204 removed lines patch added patch discarded remove patch
@@ -59,8 +59,9 @@  discard block
 block discarded – undo
59 59
  * @version 2.1 Beta 3
60 60
  */
61 61
 
62
-if (!defined('SMF'))
62
+if (!defined('SMF')) {
63 63
 	die('No direct access...');
64
+}
64 65
 
65 66
 /**
66 67
  * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects
@@ -111,10 +112,11 @@  discard block
 block discarded – undo
111 112
 	$settings_not_writable = !is_writable($boarddir . '/Settings.php');
112 113
 	$settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
113 114
 
114
-	if ($settings_not_writable)
115
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
116
-	elseif ($settings_backup_fail)
117
-		$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
115
+	if ($settings_not_writable) {
116
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>';
117
+	} elseif ($settings_backup_fail) {
118
+			$context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>';
119
+	}
118 120
 
119 121
 	$context['settings_not_writable'] = $settings_not_writable;
120 122
 
@@ -168,8 +170,9 @@  discard block
 block discarded – undo
168 170
 
169 171
 	call_integration_hook('integrate_general_settings', array(&$config_vars));
170 172
 
171
-	if ($return_config)
172
-		return $config_vars;
173
+	if ($return_config) {
174
+			return $config_vars;
175
+	}
173 176
 
174 177
 	// Setup the template stuff.
175 178
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save';
@@ -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);
@@ -248,8 +252,9 @@  discard block
 block discarded – undo
248 252
 		$request = $smcFunc['db_query']('', 'SELECT cfgname FROM pg_ts_config', array());
249 253
 		$fts_language = array();
250 254
 		
251
-		while ($row = $smcFunc['db_fetch_assoc']($request))
252
-			$fts_language[$row['cfgname']] = $row['cfgname'];
255
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
256
+					$fts_language[$row['cfgname']] = $row['cfgname'];
257
+		}
253 258
 		
254 259
 		$config_vars = array_merge ($config_vars, array(
255 260
 				'',
@@ -261,8 +266,9 @@  discard block
 block discarded – undo
261 266
 
262 267
 	call_integration_hook('integrate_database_settings', array(&$config_vars));
263 268
 
264
-	if ($return_config)
265
-		return $config_vars;
269
+	if ($return_config) {
270
+			return $config_vars;
271
+	}
266 272
 
267 273
 	// Setup the template stuff.
268 274
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save';
@@ -337,13 +343,15 @@  discard block
 block discarded – undo
337 343
 		hideGlobalCookies();
338 344
 	});', true);
339 345
 
340
-	if (empty($user_settings['tfa_secret']))
341
-		addInlineJavaScript('');
346
+	if (empty($user_settings['tfa_secret'])) {
347
+			addInlineJavaScript('');
348
+	}
342 349
 
343 350
 	call_integration_hook('integrate_cookie_settings', array(&$config_vars));
344 351
 
345
-	if ($return_config)
346
-		return $config_vars;
352
+	if ($return_config) {
353
+			return $config_vars;
354
+	}
347 355
 
348 356
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save';
349 357
 	$context['settings_title'] = $txt['cookies_sessions_settings'];
@@ -354,11 +362,13 @@  discard block
 block discarded – undo
354 362
 		call_integration_hook('integrate_save_cookie_settings');
355 363
 
356 364
 		// Local and global do not play nicely together.
357
-		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies']))
358
-			unset ($_POST['globalCookies']);
365
+		if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) {
366
+					unset ($_POST['globalCookies']);
367
+		}
359 368
 
360
-		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false)
361
-			fatal_lang_error('invalid_cookie_domain', false);
369
+		if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) {
370
+					fatal_lang_error('invalid_cookie_domain', false);
371
+		}
362 372
 
363 373
 		saveSettings($config_vars);
364 374
 
@@ -441,8 +451,9 @@  discard block
 block discarded – undo
441 451
 
442 452
 	call_integration_hook('integrate_general_security_settings', array(&$config_vars));
443 453
 
444
-	if ($return_config)
445
-		return $config_vars;
454
+	if ($return_config) {
455
+			return $config_vars;
456
+	}
446 457
 
447 458
 	// Saving?
448 459
 	if (isset($_GET['save']))
@@ -481,8 +492,7 @@  discard block
 block discarded – undo
481 492
 		$txt['cache_settings_message'] = $txt['detected_no_caching'];
482 493
 		$cache_level = array($txt['cache_off']);
483 494
 		$detected['none'] = $txt['cache_off'];
484
-	}
485
-	else
495
+	} else
486 496
 	{
487 497
 		$txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected));
488 498
 		$cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']);
@@ -519,8 +529,9 @@  discard block
 block discarded – undo
519 529
 			}
520 530
 		}
521 531
 	}
522
-	if ($return_config)
523
-		return $config_vars;
532
+	if ($return_config) {
533
+			return $config_vars;
534
+	}
524 535
 
525 536
 	// Saving again?
526 537
 	if (isset($_GET['save']))
@@ -548,8 +559,9 @@  discard block
 block discarded – undo
548 559
 	$context['save_disabled'] = $context['settings_not_writable'];
549 560
 
550 561
 	// Decide what message to show.
551
-	if (!$context['save_disabled'])
552
-		$context['settings_message'] = $txt['caching_information'];
562
+	if (!$context['save_disabled']) {
563
+			$context['settings_message'] = $txt['caching_information'];
564
+	}
553 565
 
554 566
 	// Prepare the template.
555 567
 	prepareServerSettingsContext($config_vars);
@@ -572,24 +584,25 @@  discard block
 block discarded – undo
572 584
 	if (stripos(PHP_OS, 'win') === 0)
573 585
 	{
574 586
 		$context['settings_message'] = $txt['loadavg_disabled_windows'];
575
-		if (isset($_GET['save']))
576
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
577
-	}
578
-	elseif (stripos(PHP_OS, 'darwin') === 0)
587
+		if (isset($_GET['save'])) {
588
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_windows'];
589
+		}
590
+	} elseif (stripos(PHP_OS, 'darwin') === 0)
579 591
 	{
580 592
 		$context['settings_message'] = $txt['loadavg_disabled_osx'];
581
-		if (isset($_GET['save']))
582
-			$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
583
-	}
584
-	else
593
+		if (isset($_GET['save'])) {
594
+					$_SESSION['adm-save'] = $txt['loadavg_disabled_osx'];
595
+		}
596
+	} else
585 597
 	{
586 598
 		$modSettings['load_average'] = @file_get_contents('/proc/loadavg');
587
-		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0)
588
-			$modSettings['load_average'] = (float) $matches[1];
589
-		elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0)
590
-			$modSettings['load_average'] = (float) $matches[1];
591
-		else
592
-			unset($modSettings['load_average']);
599
+		if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) {
600
+					$modSettings['load_average'] = (float) $matches[1];
601
+		} elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) {
602
+					$modSettings['load_average'] = (float) $matches[1];
603
+		} else {
604
+					unset($modSettings['load_average']);
605
+		}
593 606
 
594 607
 		if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0)
595 608
 		{
@@ -625,8 +638,9 @@  discard block
 block discarded – undo
625 638
 
626 639
 	call_integration_hook('integrate_loadavg_settings', array(&$config_vars));
627 640
 
628
-	if ($return_config)
629
-		return $config_vars;
641
+	if ($return_config) {
642
+			return $config_vars;
643
+	}
630 644
 
631 645
 	$context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save';
632 646
 	$context['settings_title'] = $txt['load_balancing_settings'];
@@ -637,24 +651,27 @@  discard block
 block discarded – undo
637 651
 		// Stupidity is not allowed.
638 652
 		foreach ($_POST as $key => $value)
639 653
 		{
640
-			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values)))
641
-				continue;
642
-			else
643
-				$_POST[$key] = (float) $value;
644
-
645
-			if ($key == 'loadavg_auto_opt' && $value <= 1)
646
-				$_POST['loadavg_auto_opt'] = 1.0;
647
-			elseif ($key == 'loadavg_forum' && $value < 10)
648
-				$_POST['loadavg_forum'] = 10.0;
649
-			elseif ($value < 2)
650
-				$_POST[$key] = 2.0;
654
+			if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) {
655
+							continue;
656
+			} else {
657
+							$_POST[$key] = (float) $value;
658
+			}
659
+
660
+			if ($key == 'loadavg_auto_opt' && $value <= 1) {
661
+							$_POST['loadavg_auto_opt'] = 1.0;
662
+			} elseif ($key == 'loadavg_forum' && $value < 10) {
663
+							$_POST['loadavg_forum'] = 10.0;
664
+			} elseif ($value < 2) {
665
+							$_POST[$key] = 2.0;
666
+			}
651 667
 		}
652 668
 
653 669
 		call_integration_hook('integrate_save_loadavg_settings');
654 670
 
655 671
 		saveDBSettings($config_vars);
656
-		if (!isset($_SESSION['adm-save']))
657
-			$_SESSION['adm-save'] = true;
672
+		if (!isset($_SESSION['adm-save'])) {
673
+					$_SESSION['adm-save'] = true;
674
+		}
658 675
 		redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']);
659 676
 	}
660 677
 
@@ -690,10 +707,11 @@  discard block
 block discarded – undo
690 707
 
691 708
 	if (isset($_SESSION['adm-save']))
692 709
 	{
693
-		if ($_SESSION['adm-save'] === true)
694
-			$context['saved_successful'] = true;
695
-		else
696
-			$context['saved_failed'] = $_SESSION['adm-save'];
710
+		if ($_SESSION['adm-save'] === true) {
711
+					$context['saved_successful'] = true;
712
+		} else {
713
+					$context['saved_failed'] = $_SESSION['adm-save'];
714
+		}
697 715
 
698 716
 		unset($_SESSION['adm-save']);
699 717
 	}
@@ -701,9 +719,9 @@  discard block
 block discarded – undo
701 719
 	$context['config_vars'] = array();
702 720
 	foreach ($config_vars as $identifier => $config_var)
703 721
 	{
704
-		if (!is_array($config_var) || !isset($config_var[1]))
705
-			$context['config_vars'][] = $config_var;
706
-		else
722
+		if (!is_array($config_var) || !isset($config_var[1])) {
723
+					$context['config_vars'][] = $config_var;
724
+		} else
707 725
 		{
708 726
 			$varname = $config_var[0];
709 727
 			global $$varname;
@@ -738,16 +756,19 @@  discard block
 block discarded – undo
738 756
 			if ($config_var[3] == 'int' || $config_var[3] == 'float')
739 757
 			{
740 758
 				// Default to a min of 0 if one isn't set
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;
759
+				if (isset($config_var['min'])) {
760
+									$context['config_vars'][$config_var[0]]['min'] = $config_var['min'];
761
+				} else {
762
+									$context['config_vars'][$config_var[0]]['min'] = 0;
763
+				}
745 764
 
746
-				if (isset($config_var['max']))
747
-					$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
765
+				if (isset($config_var['max'])) {
766
+									$context['config_vars'][$config_var[0]]['max'] = $config_var['max'];
767
+				}
748 768
 
749
-				if (isset($config_var['step']))
750
-					$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
769
+				if (isset($config_var['step'])) {
770
+									$context['config_vars'][$config_var[0]]['step'] = $config_var['step'];
771
+				}
751 772
 			}
752 773
 
753 774
 			// If this is a select box handle any data.
@@ -755,12 +776,13 @@  discard block
 block discarded – undo
755 776
 			{
756 777
 				// If it's associative
757 778
 				$config_values = array_values($config_var[4]);
758
-				if (isset($config_values[0]) && is_array($config_values[0]))
759
-					$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
760
-				else
779
+				if (isset($config_values[0]) && is_array($config_values[0])) {
780
+									$context['config_vars'][$config_var[0]]['data'] = $config_var[4];
781
+				} else
761 782
 				{
762
-					foreach ($config_var[4] as $key => $item)
763
-						$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
783
+					foreach ($config_var[4] as $key => $item) {
784
+											$context['config_vars'][$config_var[0]]['data'][] = array($key, $item);
785
+					}
764 786
 				}
765 787
 			}
766 788
 		}
@@ -785,10 +807,11 @@  discard block
 block discarded – undo
785 807
 
786 808
 	if (isset($_SESSION['adm-save']))
787 809
 	{
788
-		if ($_SESSION['adm-save'] === true)
789
-			$context['saved_successful'] = true;
790
-		else
791
-			$context['saved_failed'] = $_SESSION['adm-save'];
810
+		if ($_SESSION['adm-save'] === true) {
811
+					$context['saved_successful'] = true;
812
+		} else {
813
+					$context['saved_failed'] = $_SESSION['adm-save'];
814
+		}
792 815
 
793 816
 		unset($_SESSION['adm-save']);
794 817
 	}
@@ -800,26 +823,30 @@  discard block
 block discarded – undo
800 823
 	foreach ($config_vars as $config_var)
801 824
 	{
802 825
 		// HR?
803
-		if (!is_array($config_var))
804
-			$context['config_vars'][] = $config_var;
805
-		else
826
+		if (!is_array($config_var)) {
827
+					$context['config_vars'][] = $config_var;
828
+		} else
806 829
 		{
807 830
 			// If it has no name it doesn't have any purpose!
808
-			if (empty($config_var[1]))
809
-				continue;
831
+			if (empty($config_var[1])) {
832
+							continue;
833
+			}
810 834
 
811 835
 			// Special case for inline permissions
812
-			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions'))
813
-				$inlinePermissions[] = $config_var[1];
814
-			elseif ($config_var[0] == 'permissions')
815
-				continue;
836
+			if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) {
837
+							$inlinePermissions[] = $config_var[1];
838
+			} elseif ($config_var[0] == 'permissions') {
839
+							continue;
840
+			}
816 841
 
817
-			if ($config_var[0] == 'boards')
818
-				$board_list = true;
842
+			if ($config_var[0] == 'boards') {
843
+							$board_list = true;
844
+			}
819 845
 
820 846
 			// Are we showing the BBC selection box?
821
-			if ($config_var[0] == 'bbc')
822
-				$bbcChoice[] = $config_var[1];
847
+			if ($config_var[0] == 'bbc') {
848
+							$bbcChoice[] = $config_var[1];
849
+			}
823 850
 
824 851
 			// We need to do some parsing of the value before we pass it in.
825 852
 			if (isset($modSettings[$config_var[1]]))
@@ -838,8 +865,7 @@  discard block
 block discarded – undo
838 865
 					default:
839 866
 						$value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]);
840 867
 				}
841
-			}
842
-			else
868
+			} else
843 869
 			{
844 870
 				// Darn, it's empty. What type is expected?
845 871
 				switch ($config_var[0])
@@ -879,16 +905,19 @@  discard block
 block discarded – undo
879 905
 			if ($config_var[0] == 'int' || $config_var[0] == 'float')
880 906
 			{
881 907
 				// Default to a min of 0 if one isn't set
882
-				if (isset($config_var['min']))
883
-					$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
884
-				else
885
-					$context['config_vars'][$config_var[1]]['min'] = 0;
908
+				if (isset($config_var['min'])) {
909
+									$context['config_vars'][$config_var[1]]['min'] = $config_var['min'];
910
+				} else {
911
+									$context['config_vars'][$config_var[1]]['min'] = 0;
912
+				}
886 913
 
887
-				if (isset($config_var['max']))
888
-					$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
914
+				if (isset($config_var['max'])) {
915
+									$context['config_vars'][$config_var[1]]['max'] = $config_var['max'];
916
+				}
889 917
 
890
-				if (isset($config_var['step']))
891
-					$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
918
+				if (isset($config_var['step'])) {
919
+									$context['config_vars'][$config_var[1]]['step'] = $config_var['step'];
920
+				}
892 921
 			}
893 922
 
894 923
 			// If this is a select box handle any data.
@@ -902,12 +931,13 @@  discard block
 block discarded – undo
902 931
 				}
903 932
 
904 933
 				// If it's associative
905
-				if (isset($config_var[2][0]) && is_array($config_var[2][0]))
906
-					$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
907
-				else
934
+				if (isset($config_var[2][0]) && is_array($config_var[2][0])) {
935
+									$context['config_vars'][$config_var[1]]['data'] = $config_var[2];
936
+				} else
908 937
 				{
909
-					foreach ($config_var[2] as $key => $item)
910
-						$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
938
+					foreach ($config_var[2] as $key => $item) {
939
+											$context['config_vars'][$config_var[1]]['data'][] = array($key, $item);
940
+					}
911 941
 				}
912 942
 			}
913 943
 
@@ -916,17 +946,19 @@  discard block
 block discarded – undo
916 946
 			{
917 947
 				if (!is_numeric($k))
918 948
 				{
919
-					if (substr($k, 0, 2) == 'on')
920
-						$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
921
-					else
922
-						$context['config_vars'][$config_var[1]][$k] = $v;
949
+					if (substr($k, 0, 2) == 'on') {
950
+											$context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"';
951
+					} else {
952
+											$context['config_vars'][$config_var[1]][$k] = $v;
953
+					}
923 954
 				}
924 955
 
925 956
 				// See if there are any other labels that might fit?
926
-				if (isset($txt['setting_' . $config_var[1]]))
927
-					$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
928
-				elseif (isset($txt['groups_' . $config_var[1]]))
929
-					$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
957
+				if (isset($txt['setting_' . $config_var[1]])) {
958
+									$context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]];
959
+				} elseif (isset($txt['groups_' . $config_var[1]])) {
960
+									$context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]];
961
+				}
930 962
 			}
931 963
 
932 964
 			// Set the subtext in case it's part of the label.
@@ -959,8 +991,9 @@  discard block
 block discarded – undo
959 991
 		// What are the options, eh?
960 992
 		$temp = parse_bbc(false);
961 993
 		$bbcTags = array();
962
-		foreach ($temp as $tag)
963
-			$bbcTags[] = $tag['tag'];
994
+		foreach ($temp as $tag) {
995
+					$bbcTags[] = $tag['tag'];
996
+		}
964 997
 
965 998
 		$bbcTags = array_unique($bbcTags);
966 999
 		$totalTags = count($bbcTags);
@@ -975,8 +1008,9 @@  discard block
 block discarded – undo
975 1008
 		$col = 0; $i = 0;
976 1009
 		foreach ($bbcTags as $tag)
977 1010
 		{
978
-			if ($i % $tagsPerColumn == 0 && $i != 0)
979
-				$col++;
1011
+			if ($i % $tagsPerColumn == 0 && $i != 0) {
1012
+							$col++;
1013
+			}
980 1014
 
981 1015
 			$context['bbc_columns'][$col][] = array(
982 1016
 				'tag' => $tag,
@@ -1019,18 +1053,21 @@  discard block
 block discarded – undo
1019 1053
 	validateToken('admin-ssc');
1020 1054
 
1021 1055
 	// Fix the darn stupid cookiename! (more may not be allowed, but these for sure!)
1022
-	if (isset($_POST['cookiename']))
1023
-		$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1056
+	if (isset($_POST['cookiename'])) {
1057
+			$_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']);
1058
+	}
1024 1059
 
1025 1060
 	// Fix the forum's URL if necessary.
1026 1061
 	if (isset($_POST['boardurl']))
1027 1062
 	{
1028
-		if (substr($_POST['boardurl'], -10) == '/index.php')
1029
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1030
-		elseif (substr($_POST['boardurl'], -1) == '/')
1031
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1032
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
1033
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1063
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
1064
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
1065
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
1066
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
1067
+		}
1068
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
1069
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
1070
+		}
1034 1071
 	}
1035 1072
 
1036 1073
 	// Any passwords?
@@ -1065,21 +1102,21 @@  discard block
 block discarded – undo
1065 1102
 	// Figure out which config vars we're saving here...
1066 1103
 	foreach ($config_vars as $var)
1067 1104
 	{
1068
-		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]])))
1069
-			continue;
1105
+		if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) {
1106
+					continue;
1107
+		}
1070 1108
 
1071 1109
 		$config_var = $var[0];
1072 1110
 
1073 1111
 		if (in_array($config_var, $config_passwords))
1074 1112
 		{
1075
-			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1])
1076
-				$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1077
-		}
1078
-		elseif (in_array($config_var, $config_strs))
1113
+			if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) {
1114
+							$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\'';
1115
+			}
1116
+		} elseif (in_array($config_var, $config_strs))
1079 1117
 		{
1080 1118
 			$new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\'';
1081
-		}
1082
-		elseif (in_array($config_var, $config_ints))
1119
+		} elseif (in_array($config_var, $config_ints))
1083 1120
 		{
1084 1121
 			$new_settings[$config_var] = (int) $_POST[$config_var];
1085 1122
 
@@ -1088,17 +1125,17 @@  discard block
 block discarded – undo
1088 1125
 			$new_settings[$config_var] = max($min, $new_settings[$config_var]);
1089 1126
 
1090 1127
 			// Is there a max value for this as well?
1091
-			if (isset($var['max']))
1092
-				$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1093
-		}
1094
-		elseif (in_array($config_var, $config_bools))
1128
+			if (isset($var['max'])) {
1129
+							$new_settings[$config_var] = min($var['max'], $new_settings[$config_var]);
1130
+			}
1131
+		} elseif (in_array($config_var, $config_bools))
1095 1132
 		{
1096
-			if (!empty($_POST[$config_var]))
1097
-				$new_settings[$config_var] = '1';
1098
-			else
1099
-				$new_settings[$config_var] = '0';
1100
-		}
1101
-		else
1133
+			if (!empty($_POST[$config_var])) {
1134
+							$new_settings[$config_var] = '1';
1135
+			} else {
1136
+							$new_settings[$config_var] = '0';
1137
+			}
1138
+		} else
1102 1139
 		{
1103 1140
 			// This shouldn't happen, but it might...
1104 1141
 			fatal_error('Unknown config_var \'' . $config_var . '\'');
@@ -1114,30 +1151,35 @@  discard block
 block discarded – undo
1114 1151
 	foreach ($config_vars as $config_var)
1115 1152
 	{
1116 1153
 		// We just saved the file-based settings, so skip their definitions.
1117
-		if (!is_array($config_var) || $config_var[2] == 'file')
1118
-			continue;
1154
+		if (!is_array($config_var) || $config_var[2] == 'file') {
1155
+					continue;
1156
+		}
1119 1157
 
1120 1158
 		$new_setting = array($config_var[3], $config_var[0]);
1121 1159
 
1122 1160
 		// Select options need carried over, too.
1123
-		if (isset($config_var[4]))
1124
-			$new_setting[] = $config_var[4];
1161
+		if (isset($config_var[4])) {
1162
+					$new_setting[] = $config_var[4];
1163
+		}
1125 1164
 
1126 1165
 		// Include min and max if necessary
1127
-		if (isset($config_var['min']))
1128
-			$new_setting['min'] = $config_var['min'];
1166
+		if (isset($config_var['min'])) {
1167
+					$new_setting['min'] = $config_var['min'];
1168
+		}
1129 1169
 
1130
-		if (isset($config_var['max']))
1131
-			$new_setting['max'] = $config_var['max'];
1170
+		if (isset($config_var['max'])) {
1171
+					$new_setting['max'] = $config_var['max'];
1172
+		}
1132 1173
 
1133 1174
 		// Rewrite the definition a bit.
1134 1175
 		$new_settings[] = $new_setting;
1135 1176
 	}
1136 1177
 
1137 1178
 	// Save the new database-based settings, if any.
1138
-	if (!empty($new_settings))
1139
-		saveDBSettings($new_settings);
1140
-}
1179
+	if (!empty($new_settings)) {
1180
+			saveDBSettings($new_settings);
1181
+	}
1182
+	}
1141 1183
 
1142 1184
 /**
1143 1185
  * Helper function for saving database settings.
@@ -1155,22 +1197,25 @@  discard block
 block discarded – undo
1155 1197
 	$inlinePermissions = array();
1156 1198
 	foreach ($config_vars as $var)
1157 1199
 	{
1158
-		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']))))
1159
-			continue;
1200
+		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'])))) {
1201
+					continue;
1202
+		}
1160 1203
 
1161 1204
 		// Checkboxes!
1162
-		elseif ($var[0] == 'check')
1163
-			$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1205
+		elseif ($var[0] == 'check') {
1206
+					$setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0';
1207
+		}
1164 1208
 		// Select boxes!
1165
-		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2])))
1166
-			$setArray[$var[1]] = $_POST[$var[1]];
1167
-		elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1209
+		elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) {
1210
+					$setArray[$var[1]] = $_POST[$var[1]];
1211
+		} elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array())
1168 1212
 		{
1169 1213
 			// For security purposes we validate this line by line.
1170 1214
 			$lOptions = array();
1171
-			foreach ($_POST[$var[1]] as $invar)
1172
-				if (in_array($invar, array_keys($var[2])))
1215
+			foreach ($_POST[$var[1]] as $invar) {
1216
+							if (in_array($invar, array_keys($var[2])))
1173 1217
 					$lOptions[] = $invar;
1218
+			}
1174 1219
 
1175 1220
 			$setArray[$var[1]] = json_encode($lOptions);
1176 1221
 		}
@@ -1184,18 +1229,20 @@  discard block
 block discarded – undo
1184 1229
 				$request = $smcFunc['db_query']('', '
1185 1230
 					SELECT id_board
1186 1231
 					FROM {db_prefix}boards');
1187
-				while ($row = $smcFunc['db_fetch_row']($request))
1188
-					$board_list[$row[0]] = true;
1232
+				while ($row = $smcFunc['db_fetch_row']($request)) {
1233
+									$board_list[$row[0]] = true;
1234
+				}
1189 1235
 
1190 1236
 				$smcFunc['db_free_result']($request);
1191 1237
 			}
1192 1238
 
1193 1239
 			$lOptions = array();
1194 1240
 
1195
-			if (!empty($_POST[$var[1]]))
1196
-				foreach ($_POST[$var[1]] as $invar => $dummy)
1241
+			if (!empty($_POST[$var[1]])) {
1242
+							foreach ($_POST[$var[1]] as $invar => $dummy)
1197 1243
 					if (isset($board_list[$invar]))
1198 1244
 						$lOptions[] = $invar;
1245
+			}
1199 1246
 
1200 1247
 			$setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : '';
1201 1248
 		}
@@ -1209,8 +1256,9 @@  discard block
 block discarded – undo
1209 1256
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1210 1257
 
1211 1258
 			// Do we have a max value for this as well?
1212
-			if (isset($var['max']))
1213
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1259
+			if (isset($var['max'])) {
1260
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1261
+			}
1214 1262
 		}
1215 1263
 		// Floating point!
1216 1264
 		elseif ($var[0] == 'float')
@@ -1222,40 +1270,47 @@  discard block
 block discarded – undo
1222 1270
 			$setArray[$var[1]] = max($min, $setArray[$var[1]]);
1223 1271
 
1224 1272
 			// Do we have a max value for this as well?
1225
-			if (isset($var['max']))
1226
-				$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1273
+			if (isset($var['max'])) {
1274
+							$setArray[$var[1]] = min($var['max'], $setArray[$var[1]]);
1275
+			}
1227 1276
 		}
1228 1277
 		// Text!
1229
-		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time')))
1230
-			$setArray[$var[1]] = $_POST[$var[1]];
1278
+		elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) {
1279
+					$setArray[$var[1]] = $_POST[$var[1]];
1280
+		}
1231 1281
 		// Passwords!
1232 1282
 		elseif ($var[0] == 'password')
1233 1283
 		{
1234
-			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1])
1235
-				$setArray[$var[1]] = $_POST[$var[1]][0];
1284
+			if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) {
1285
+							$setArray[$var[1]] = $_POST[$var[1]][0];
1286
+			}
1236 1287
 		}
1237 1288
 		// BBC.
1238 1289
 		elseif ($var[0] == 'bbc')
1239 1290
 		{
1240 1291
 
1241 1292
 			$bbcTags = array();
1242
-			foreach (parse_bbc(false) as $tag)
1243
-				$bbcTags[] = $tag['tag'];
1293
+			foreach (parse_bbc(false) as $tag) {
1294
+							$bbcTags[] = $tag['tag'];
1295
+			}
1244 1296
 
1245
-			if (!isset($_POST[$var[1] . '_enabledTags']))
1246
-				$_POST[$var[1] . '_enabledTags'] = array();
1247
-			elseif (!is_array($_POST[$var[1] . '_enabledTags']))
1248
-				$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1297
+			if (!isset($_POST[$var[1] . '_enabledTags'])) {
1298
+							$_POST[$var[1] . '_enabledTags'] = array();
1299
+			} elseif (!is_array($_POST[$var[1] . '_enabledTags'])) {
1300
+							$_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']);
1301
+			}
1249 1302
 
1250 1303
 			$setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags']));
1251 1304
 		}
1252 1305
 		// Permissions?
1253
-		elseif ($var[0] == 'permissions')
1254
-			$inlinePermissions[] = $var[1];
1306
+		elseif ($var[0] == 'permissions') {
1307
+					$inlinePermissions[] = $var[1];
1308
+		}
1255 1309
 	}
1256 1310
 
1257
-	if (!empty($setArray))
1258
-		updateSettings($setArray);
1311
+	if (!empty($setArray)) {
1312
+			updateSettings($setArray);
1313
+	}
1259 1314
 
1260 1315
 	// If we have inline permissions we need to save them.
1261 1316
 	if (!empty($inlinePermissions) && allowedTo('manage_permissions'))
@@ -1292,18 +1347,21 @@  discard block
 block discarded – undo
1292 1347
 	// put all of it into an array
1293 1348
 	foreach ($info_lines as $line)
1294 1349
 	{
1295
-		if (preg_match('~(' . $remove . ')~', $line))
1296
-			continue;
1350
+		if (preg_match('~(' . $remove . ')~', $line)) {
1351
+					continue;
1352
+		}
1297 1353
 
1298 1354
 		// new category?
1299
-		if (strpos($line, '<h2>') !== false)
1300
-			$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1355
+		if (strpos($line, '<h2>') !== false) {
1356
+					$category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category;
1357
+		}
1301 1358
 
1302 1359
 		// load it as setting => value or the old setting local master
1303
-		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1304
-			$pinfo[$category][$val[1]] = $val[2];
1305
-		elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val))
1306
-			$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1360
+		if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1361
+					$pinfo[$category][$val[1]] = $val[2];
1362
+		} elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) {
1363
+					$pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]);
1364
+		}
1307 1365
 	}
1308 1366
 
1309 1367
 	// load it in to context and display it
@@ -1338,8 +1396,9 @@  discard block
 block discarded – undo
1338 1396
 				$testAPI = new $cache_class_name();
1339 1397
 
1340 1398
 				// No Support?  NEXT!
1341
-				if (!$testAPI->isSupported(true))
1342
-					continue;
1399
+				if (!$testAPI->isSupported(true)) {
1400
+									continue;
1401
+				}
1343 1402
 
1344 1403
 				$apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache;
1345 1404
 			}
@@ -1364,8 +1423,9 @@  discard block
 block discarded – undo
1364 1423
 	global $modSettings, $boardurl, $smcFunc;
1365 1424
 
1366 1425
 	// Already have a key?  Can't register again.
1367
-	if (!empty($modSettings['sm_stats_key']))
1368
-		return true;
1426
+	if (!empty($modSettings['sm_stats_key'])) {
1427
+			return true;
1428
+	}
1369 1429
 
1370 1430
 	$fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr);
1371 1431
 	if ($fp)
@@ -1376,8 +1436,9 @@  discard block
 block discarded – undo
1376 1436
 		fwrite($fp, $out);
1377 1437
 
1378 1438
 		$return_data = '';
1379
-		while (!feof($fp))
1380
-			$return_data .= fgets($fp, 128);
1439
+		while (!feof($fp)) {
1440
+					$return_data .= fgets($fp, 128);
1441
+		}
1381 1442
 
1382 1443
 		fclose($fp);
1383 1444
 
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +875 added lines, -643 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
 $upcontext['inactive_timeout'] = 10;
76 76
 
77 77
 // The helper is crucial. Include it first thing.
78
-if (!file_exists($upgrade_path . '/upgrade-helper.php'))
78
+if (!file_exists($upgrade_path . '/upgrade-helper.php')) {
79 79
     die('upgrade-helper.php not found where it was expected: ' . $upgrade_path . '/upgrade-helper.php! Make sure you have uploaded ALL files from the upgrade package. The upgrader cannot continue.');
80
+}
80 81
 
81 82
 require_once($upgrade_path . '/upgrade-helper.php');
82 83
 
@@ -100,11 +101,14 @@  discard block
 block discarded – undo
100 101
 	ini_set('default_socket_timeout', 900);
101 102
 }
102 103
 // Clean the upgrade path if this is from the client.
103
-if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
104
-	for ($i = 1; $i < $_SERVER['argc']; $i++)
104
+if (!empty($_SERVER['argv']) && php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
105
+	for ($i = 1;
106
+}
107
+$i < $_SERVER['argc']; $i++)
105 108
 	{
106
-		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0)
107
-			$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
109
+		if (preg_match('~^--path=(.+)$~', $_SERVER['argv'][$i], $match) != 0) {
110
+					$upgrade_path = substr($match[1], -1) == '/' ? substr($match[1], 0, -1) : $match[1];
111
+		}
108 112
 	}
109 113
 
110 114
 // Are we from the client?
@@ -112,16 +116,17 @@  discard block
 block discarded – undo
112 116
 {
113 117
 	$command_line = true;
114 118
 	$disable_security = true;
115
-}
116
-else
119
+} else {
117 120
 	$command_line = false;
121
+}
118 122
 
119 123
 // Load this now just because we can.
120 124
 require_once($upgrade_path . '/Settings.php');
121 125
 
122 126
 // We don't use "-utf8" anymore...  Tweak the entry that may have been loaded by Settings.php
123
-if (isset($language))
127
+if (isset($language)) {
124 128
 	$language = str_ireplace('-utf8', '', $language);
129
+}
125 130
 
126 131
 // Are we logged in?
127 132
 if (isset($upgradeData))
@@ -129,10 +134,12 @@  discard block
 block discarded – undo
129 134
 	$upcontext['user'] = json_decode(base64_decode($upgradeData), true);
130 135
 
131 136
 	// Check for sensible values.
132
-	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400)
133
-		$upcontext['user']['started'] = time();
134
-	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400)
135
-		$upcontext['user']['updated'] = 0;
137
+	if (empty($upcontext['user']['started']) || $upcontext['user']['started'] < time() - 86400) {
138
+			$upcontext['user']['started'] = time();
139
+	}
140
+	if (empty($upcontext['user']['updated']) || $upcontext['user']['updated'] < time() - 86400) {
141
+			$upcontext['user']['updated'] = 0;
142
+	}
136 143
 
137 144
 	$upcontext['started'] = $upcontext['user']['started'];
138 145
 	$upcontext['updated'] = $upcontext['user']['updated'];
@@ -190,8 +197,9 @@  discard block
 block discarded – undo
190 197
 			'db_error_skip' => true,
191 198
 		)
192 199
 	);
193
-	while ($row = $smcFunc['db_fetch_assoc']($request))
194
-		$modSettings[$row['variable']] = $row['value'];
200
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
201
+			$modSettings[$row['variable']] = $row['value'];
202
+	}
195 203
 	$smcFunc['db_free_result']($request);
196 204
 }
197 205
 
@@ -201,10 +209,12 @@  discard block
 block discarded – undo
201 209
 	$modSettings['theme_url'] = 'Themes/default';
202 210
 	$modSettings['images_url'] = 'Themes/default/images';
203 211
 }
204
-if (!isset($settings['default_theme_url']))
212
+if (!isset($settings['default_theme_url'])) {
205 213
 	$settings['default_theme_url'] = $modSettings['theme_url'];
206
-if (!isset($settings['default_theme_dir']))
214
+}
215
+if (!isset($settings['default_theme_dir'])) {
207 216
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
217
+}
208 218
 
209 219
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
210 220
 // Default title...
@@ -222,13 +232,15 @@  discard block
 block discarded – undo
222 232
 	$support_js = $upcontext['upgrade_status']['js'];
223 233
 
224 234
 	// Only set this if the upgrader status says so.
225
-	if (empty($is_debug))
226
-		$is_debug = $upcontext['upgrade_status']['debug'];
235
+	if (empty($is_debug)) {
236
+			$is_debug = $upcontext['upgrade_status']['debug'];
237
+	}
227 238
 
228 239
 	// Load the language.
229
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
230
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
231
-}
240
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
241
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
242
+	}
243
+	}
232 244
 // Set the defaults.
233 245
 else
234 246
 {
@@ -246,15 +258,18 @@  discard block
 block discarded – undo
246 258
 }
247 259
 
248 260
 // If this isn't the first stage see whether they are logging in and resuming.
249
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
261
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
250 262
 	checkLogin();
263
+}
251 264
 
252
-if ($command_line)
265
+if ($command_line) {
253 266
 	cmdStep0();
267
+}
254 268
 
255 269
 // Don't error if we're using xml.
256
-if (isset($_GET['xml']))
270
+if (isset($_GET['xml'])) {
257 271
 	$upcontext['return_error'] = true;
272
+}
258 273
 
259 274
 // Loop through all the steps doing each one as required.
260 275
 $upcontext['overall_percent'] = 0;
@@ -275,9 +290,9 @@  discard block
 block discarded – undo
275 290
 		}
276 291
 
277 292
 		// Call the step and if it returns false that means pause!
278
-		if (function_exists($step[2]) && $step[2]() === false)
279
-			break;
280
-		elseif (function_exists($step[2])) {
293
+		if (function_exists($step[2]) && $step[2]() === false) {
294
+					break;
295
+		} elseif (function_exists($step[2])) {
281 296
 			//Start each new step with this unset, so the 'normal' template is called first
282 297
 			unset($_GET['xml']);
283 298
 			$_GET['substep'] = 0;
@@ -321,17 +336,18 @@  discard block
 block discarded – undo
321 336
 		// This should not happen my dear... HELP ME DEVELOPERS!!
322 337
 		if (!empty($command_line))
323 338
 		{
324
-			if (function_exists('debug_print_backtrace'))
325
-				debug_print_backtrace();
339
+			if (function_exists('debug_print_backtrace')) {
340
+							debug_print_backtrace();
341
+			}
326 342
 
327 343
 			echo "\n" . 'Error: Unexpected call to use the ' . (isset($upcontext['sub_template']) ? $upcontext['sub_template'] : '') . ' template. Please copy and paste all the text above and visit the SMF support forum to tell the Developers that they\'ve made a boo boo; they\'ll get you up and running again.';
328 344
 			flush();
329 345
 			die();
330 346
 		}
331 347
 
332
-		if (!isset($_GET['xml']))
333
-			template_upgrade_above();
334
-		else
348
+		if (!isset($_GET['xml'])) {
349
+					template_upgrade_above();
350
+		} else
335 351
 		{
336 352
 			header('Content-Type: text/xml; charset=UTF-8');
337 353
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -353,25 +369,29 @@  discard block
 block discarded – undo
353 369
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
354 370
 
355 371
 			// Custom stuff to pass back?
356
-			if (!empty($upcontext['query_string']))
357
-				$upcontext['form_url'] .= $upcontext['query_string'];
372
+			if (!empty($upcontext['query_string'])) {
373
+							$upcontext['form_url'] .= $upcontext['query_string'];
374
+			}
358 375
 
359 376
 			// Call the appropriate subtemplate
360
-			if (is_callable('template_' . $upcontext['sub_template']))
361
-				call_user_func('template_' . $upcontext['sub_template']);
362
-			else
363
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
377
+			if (is_callable('template_' . $upcontext['sub_template'])) {
378
+							call_user_func('template_' . $upcontext['sub_template']);
379
+			} else {
380
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
381
+			}
364 382
 		}
365 383
 
366 384
 		// Was there an error?
367
-		if (!empty($upcontext['forced_error_message']))
368
-			echo $upcontext['forced_error_message'];
385
+		if (!empty($upcontext['forced_error_message'])) {
386
+					echo $upcontext['forced_error_message'];
387
+		}
369 388
 
370 389
 		// Show the footer.
371
-		if (!isset($_GET['xml']))
372
-			template_upgrade_below();
373
-		else
374
-			template_xml_below();
390
+		if (!isset($_GET['xml'])) {
391
+					template_upgrade_below();
392
+		} else {
393
+					template_xml_below();
394
+		}
375 395
 	}
376 396
 
377 397
 
@@ -383,15 +403,19 @@  discard block
 block discarded – undo
383 403
 		$seconds = intval($active % 60);
384 404
 
385 405
 		$totalTime = '';
386
-		if ($hours > 0)
387
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
388
-		if ($minutes > 0)
389
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
390
-		if ($seconds > 0)
391
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
406
+		if ($hours > 0) {
407
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
408
+		}
409
+		if ($minutes > 0) {
410
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
411
+		}
412
+		if ($seconds > 0) {
413
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
414
+		}
392 415
 
393
-		if (!empty($totalTime))
394
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
416
+		if (!empty($totalTime)) {
417
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
418
+		}
395 419
 	}
396 420
 
397 421
 	// Bang - gone!
@@ -404,8 +428,9 @@  discard block
 block discarded – undo
404 428
 	global $upgradeurl, $upcontext, $command_line;
405 429
 
406 430
 	// Command line users can't be redirected.
407
-	if ($command_line)
408
-		upgradeExit(true);
431
+	if ($command_line) {
432
+			upgradeExit(true);
433
+	}
409 434
 
410 435
 	// Are we providing the core info?
411 436
 	if ($addForm)
@@ -431,12 +456,14 @@  discard block
 block discarded – undo
431 456
 	define('SMF', 1);
432 457
 
433 458
 	// Start the session.
434
-	if (@ini_get('session.save_handler') == 'user')
435
-		@ini_set('session.save_handler', 'files');
459
+	if (@ini_get('session.save_handler') == 'user') {
460
+			@ini_set('session.save_handler', 'files');
461
+	}
436 462
 	@session_start();
437 463
 
438
-	if (empty($smcFunc))
439
-		$smcFunc = array();
464
+	if (empty($smcFunc)) {
465
+			$smcFunc = array();
466
+	}
440 467
 
441 468
 	// We need this for authentication and some upgrade code
442 469
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -448,32 +475,36 @@  discard block
 block discarded – undo
448 475
 	initialize_inputs();
449 476
 
450 477
 	// Get the database going!
451
-	if (empty($db_type) || $db_type == 'mysqli')
452
-		$db_type = 'mysql';
478
+	if (empty($db_type) || $db_type == 'mysqli') {
479
+			$db_type = 'mysql';
480
+	}
453 481
 
454 482
 	if (file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
455 483
 	{
456 484
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
457 485
 
458 486
 		// Make the connection...
459
-		if (empty($db_connection))
460
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
461
-		else
462
-			// If we've returned here, ping/reconnect to be safe
487
+		if (empty($db_connection)) {
488
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
489
+		} else {
490
+					// If we've returned here, ping/reconnect to be safe
463 491
 			$smcFunc['db_ping']($db_connection);
492
+		}
464 493
 
465 494
 		// Oh dear god!!
466
-		if ($db_connection === null)
467
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
495
+		if ($db_connection === null) {
496
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
497
+		}
468 498
 
469
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
470
-			$smcFunc['db_query']('', '
499
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
500
+					$smcFunc['db_query']('', '
471 501
 			SET NAMES {string:db_character_set}',
472 502
 			array(
473 503
 				'db_error_skip' => true,
474 504
 				'db_character_set' => $db_character_set,
475 505
 			)
476 506
 		);
507
+		}
477 508
 
478 509
 		// Load the modSettings data...
479 510
 		$request = $smcFunc['db_query']('', '
@@ -484,11 +515,11 @@  discard block
 block discarded – undo
484 515
 			)
485 516
 		);
486 517
 		$modSettings = array();
487
-		while ($row = $smcFunc['db_fetch_assoc']($request))
488
-			$modSettings[$row['variable']] = $row['value'];
518
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
519
+					$modSettings[$row['variable']] = $row['value'];
520
+		}
489 521
 		$smcFunc['db_free_result']($request);
490
-	}
491
-	else
522
+	} else
492 523
 	{
493 524
 		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.');
494 525
 	}
@@ -502,9 +533,10 @@  discard block
 block discarded – undo
502 533
 		cleanRequest();
503 534
 	}
504 535
 
505
-	if (!isset($_GET['substep']))
506
-		$_GET['substep'] = 0;
507
-}
536
+	if (!isset($_GET['substep'])) {
537
+			$_GET['substep'] = 0;
538
+	}
539
+	}
508 540
 
509 541
 function initialize_inputs()
510 542
 {
@@ -534,8 +566,9 @@  discard block
 block discarded – undo
534 566
 		$dh = opendir(dirname(__FILE__));
535 567
 		while ($file = readdir($dh))
536 568
 		{
537
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
538
-				@unlink(dirname(__FILE__) . '/' . $file);
569
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
570
+							@unlink(dirname(__FILE__) . '/' . $file);
571
+			}
539 572
 		}
540 573
 		closedir($dh);
541 574
 
@@ -564,8 +597,9 @@  discard block
 block discarded – undo
564 597
 	$temp = 'upgrade_php?step';
565 598
 	while (strlen($temp) > 4)
566 599
 	{
567
-		if (isset($_GET[$temp]))
568
-			unset($_GET[$temp]);
600
+		if (isset($_GET[$temp])) {
601
+					unset($_GET[$temp]);
602
+		}
569 603
 		$temp = substr($temp, 1);
570 604
 	}
571 605
 
@@ -592,32 +626,39 @@  discard block
 block discarded – undo
592 626
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
593 627
 
594 628
 	// Need legacy scripts?
595
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
596
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
597
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
598
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
599
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
600
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
629
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
630
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
631
+	}
632
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
633
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
634
+	}
635
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
636
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
637
+	}
601 638
 
602 639
 	// We don't need "-utf8" files anymore...
603 640
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
604 641
 
605 642
 	// This needs to exist!
606
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
607
-		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>]');
608
-	else
609
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
643
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
644
+			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>]');
645
+	} else {
646
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
647
+	}
610 648
 
611
-	if (!$check)
612
-		// 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.
649
+	if (!$check) {
650
+			// 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.
613 651
 		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.');
652
+	}
614 653
 
615 654
 	// Do they meet the install requirements?
616
-	if (!php_version_check())
617
-		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.');
655
+	if (!php_version_check()) {
656
+			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.');
657
+	}
618 658
 
619
-	if (!db_version_check())
620
-		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.');
659
+	if (!db_version_check()) {
660
+			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.');
661
+	}
621 662
 
622 663
 	// Do some checks to make sure they have proper privileges
623 664
 	db_extend('packages');
@@ -632,14 +673,16 @@  discard block
 block discarded – undo
632 673
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
633 674
 
634 675
 	// Sorry... we need CREATE, ALTER and DROP
635
-	if (!$create || !$alter || !$drop)
636
-		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.');
676
+	if (!$create || !$alter || !$drop) {
677
+			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.');
678
+	}
637 679
 
638 680
 	// Do a quick version spot check.
639 681
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
640 682
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
641
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
642
-		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.');
683
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
684
+			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.');
685
+	}
643 686
 
644 687
 	// What absolutely needs to be writable?
645 688
 	$writable_files = array(
@@ -661,12 +704,13 @@  discard block
 block discarded – undo
661 704
 	quickFileWritable($custom_av_dir);
662 705
 
663 706
 	// Are we good now?
664
-	if (!is_writable($custom_av_dir))
665
-		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));
666
-	elseif ($need_settings_update)
707
+	if (!is_writable($custom_av_dir)) {
708
+			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));
709
+	} elseif ($need_settings_update)
667 710
 	{
668
-		if (!function_exists('cache_put_data'))
669
-			require_once($sourcedir . '/Load.php');
711
+		if (!function_exists('cache_put_data')) {
712
+					require_once($sourcedir . '/Load.php');
713
+		}
670 714
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
671 715
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
672 716
 	}
@@ -675,28 +719,33 @@  discard block
 block discarded – undo
675 719
 
676 720
 	// Check the cache directory.
677 721
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
678
-	if (!file_exists($cachedir_temp))
679
-		@mkdir($cachedir_temp);
680
-	if (!file_exists($cachedir_temp))
681
-		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.');
682
-
683
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
684
-		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>.');
685
-	elseif (!isset($_GET['skiplang']))
722
+	if (!file_exists($cachedir_temp)) {
723
+			@mkdir($cachedir_temp);
724
+	}
725
+	if (!file_exists($cachedir_temp)) {
726
+			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.');
727
+	}
728
+
729
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
730
+			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>.');
731
+	} elseif (!isset($_GET['skiplang']))
686 732
 	{
687 733
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
688 734
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
689 735
 
690
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
691
-			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>]');
736
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
737
+					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>]');
738
+		}
692 739
 	}
693 740
 
694
-	if (!makeFilesWritable($writable_files))
695
-		return false;
741
+	if (!makeFilesWritable($writable_files)) {
742
+			return false;
743
+	}
696 744
 
697 745
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
698
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
699
-		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.');
746
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
747
+			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.');
748
+	}
700 749
 
701 750
 	// Upgrade the agreement.
702 751
 	elseif (isset($modSettings['agreement']))
@@ -707,8 +756,8 @@  discard block
 block discarded – undo
707 756
 	}
708 757
 
709 758
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
710
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
711
-		$upcontext['warning'] = '
759
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
760
+			$upcontext['warning'] = '
712 761
 			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>
713 762
 			<ul>
714 763
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -716,10 +765,12 @@  discard block
 block discarded – undo
716 765
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
717 766
 			</ul>
718 767
 			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.';
768
+	}
719 769
 
720 770
 	// Either we're logged in or we're going to present the login.
721
-	if (checkLogin())
722
-		return true;
771
+	if (checkLogin()) {
772
+			return true;
773
+	}
723 774
 
724 775
 	$upcontext += createToken('login');
725 776
 
@@ -733,15 +784,17 @@  discard block
 block discarded – undo
733 784
 	global $smcFunc, $db_type, $support_js;
734 785
 
735 786
 	// Don't bother if the security is disabled.
736
-	if ($disable_security)
737
-		return true;
787
+	if ($disable_security) {
788
+			return true;
789
+	}
738 790
 
739 791
 	// Are we trying to login?
740 792
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
741 793
 	{
742 794
 		// If we've disabled security pick a suitable name!
743
-		if (empty($_POST['user']))
744
-			$_POST['user'] = 'Administrator';
795
+		if (empty($_POST['user'])) {
796
+					$_POST['user'] = 'Administrator';
797
+		}
745 798
 
746 799
 		// Before 2.0 these column names were different!
747 800
 		$oldDB = false;
@@ -756,16 +809,17 @@  discard block
 block discarded – undo
756 809
 					'db_error_skip' => true,
757 810
 				)
758 811
 			);
759
-			if ($smcFunc['db_num_rows']($request) != 0)
760
-				$oldDB = true;
812
+			if ($smcFunc['db_num_rows']($request) != 0) {
813
+							$oldDB = true;
814
+			}
761 815
 			$smcFunc['db_free_result']($request);
762 816
 		}
763 817
 
764 818
 		// Get what we believe to be their details.
765 819
 		if (!$disable_security)
766 820
 		{
767
-			if ($oldDB)
768
-				$request = $smcFunc['db_query']('', '
821
+			if ($oldDB) {
822
+							$request = $smcFunc['db_query']('', '
769 823
 					SELECT id_member, memberName AS member_name, passwd, id_group,
770 824
 					additionalGroups AS additional_groups, lngfile
771 825
 					FROM {db_prefix}members
@@ -775,8 +829,8 @@  discard block
 block discarded – undo
775 829
 						'db_error_skip' => true,
776 830
 					)
777 831
 				);
778
-			else
779
-				$request = $smcFunc['db_query']('', '
832
+			} else {
833
+							$request = $smcFunc['db_query']('', '
780 834
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
781 835
 					FROM {db_prefix}members
782 836
 					WHERE member_name = {string:member_name}',
@@ -785,6 +839,7 @@  discard block
 block discarded – undo
785 839
 						'db_error_skip' => true,
786 840
 					)
787 841
 				);
842
+			}
788 843
 			if ($smcFunc['db_num_rows']($request) != 0)
789 844
 			{
790 845
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -792,16 +847,17 @@  discard block
 block discarded – undo
792 847
 				$groups = explode(',', $addGroups);
793 848
 				$groups[] = $id_group;
794 849
 
795
-				foreach ($groups as $k => $v)
796
-					$groups[$k] = (int) $v;
850
+				foreach ($groups as $k => $v) {
851
+									$groups[$k] = (int) $v;
852
+				}
797 853
 
798 854
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
799 855
 
800 856
 				// We don't use "-utf8" anymore...
801 857
 				$user_language = str_ireplace('-utf8', '', $user_language);
858
+			} else {
859
+							$upcontext['username_incorrect'] = true;
802 860
 			}
803
-			else
804
-				$upcontext['username_incorrect'] = true;
805 861
 			$smcFunc['db_free_result']($request);
806 862
 		}
807 863
 		$upcontext['username'] = $_POST['user'];
@@ -811,13 +867,14 @@  discard block
 block discarded – undo
811 867
 		{
812 868
 			$upcontext['upgrade_status']['js'] = 1;
813 869
 			$support_js = 1;
870
+		} else {
871
+					$support_js = 0;
814 872
 		}
815
-		else
816
-			$support_js = 0;
817 873
 
818 874
 		// Note down the version we are coming from.
819
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
820
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
875
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
876
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
877
+		}
821 878
 
822 879
 		// Didn't get anywhere?
823 880
 		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']))
@@ -851,15 +908,15 @@  discard block
 block discarded – undo
851 908
 							'db_error_skip' => true,
852 909
 						)
853 910
 					);
854
-					if ($smcFunc['db_num_rows']($request) == 0)
855
-						return throw_error('You need to be an admin to perform an upgrade!');
911
+					if ($smcFunc['db_num_rows']($request) == 0) {
912
+											return throw_error('You need to be an admin to perform an upgrade!');
913
+					}
856 914
 					$smcFunc['db_free_result']($request);
857 915
 				}
858 916
 
859 917
 				$upcontext['user']['id'] = $id_member;
860 918
 				$upcontext['user']['name'] = $name;
861
-			}
862
-			else
919
+			} else
863 920
 			{
864 921
 				$upcontext['user']['id'] = 1;
865 922
 				$upcontext['user']['name'] = 'Administrator';
@@ -875,11 +932,11 @@  discard block
 block discarded – undo
875 932
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
876 933
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
877 934
 
878
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
879
-					$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'] . '.';
880
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
881
-					$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'] . '.';
882
-				else
935
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
936
+									$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'] . '.';
937
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
938
+									$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'] . '.';
939
+				} else
883 940
 				{
884 941
 					// Set this as the new language.
885 942
 					$upcontext['language'] = $user_language;
@@ -923,8 +980,9 @@  discard block
 block discarded – undo
923 980
 	unset($member_columns);
924 981
 
925 982
 	// If we've not submitted then we're done.
926
-	if (empty($_POST['upcont']))
927
-		return false;
983
+	if (empty($_POST['upcont'])) {
984
+			return false;
985
+	}
928 986
 
929 987
 	// Firstly, if they're enabling SM stat collection just do it.
930 988
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -944,16 +1002,17 @@  discard block
 block discarded – undo
944 1002
 				fwrite($fp, $out);
945 1003
 
946 1004
 				$return_data = '';
947
-				while (!feof($fp))
948
-					$return_data .= fgets($fp, 128);
1005
+				while (!feof($fp)) {
1006
+									$return_data .= fgets($fp, 128);
1007
+				}
949 1008
 
950 1009
 				fclose($fp);
951 1010
 
952 1011
 				// Get the unique site ID.
953 1012
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
954 1013
 
955
-				if (!empty($ID[1]))
956
-					$smcFunc['db_insert']('replace',
1014
+				if (!empty($ID[1])) {
1015
+									$smcFunc['db_insert']('replace',
957 1016
 						$db_prefix . 'settings',
958 1017
 						array('variable' => 'string', 'value' => 'string'),
959 1018
 						array(
@@ -962,9 +1021,9 @@  discard block
 block discarded – undo
962 1021
 						),
963 1022
 						array('variable')
964 1023
 					);
1024
+				}
965 1025
 			}
966
-		}
967
-		else
1026
+		} else
968 1027
 		{
969 1028
 			$smcFunc['db_insert']('replace',
970 1029
 				$db_prefix . 'settings',
@@ -975,8 +1034,8 @@  discard block
 block discarded – undo
975 1034
 		}
976 1035
 	}
977 1036
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
978
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
979
-		$smcFunc['db_query']('', '
1037
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1038
+			$smcFunc['db_query']('', '
980 1039
 			DELETE FROM {db_prefix}settings
981 1040
 			WHERE variable = {string:enable_sm_stats}',
982 1041
 			array(
@@ -984,6 +1043,7 @@  discard block
 block discarded – undo
984 1043
 				'db_error_skip' => true,
985 1044
 			)
986 1045
 		);
1046
+	}
987 1047
 
988 1048
 	// Deleting old karma stuff?
989 1049
 	if (!empty($_POST['delete_karma']))
@@ -998,20 +1058,22 @@  discard block
 block discarded – undo
998 1058
 		);
999 1059
 
1000 1060
 		// Cleaning up old karma member settings.
1001
-		if ($upcontext['karma_installed']['good'])
1002
-			$smcFunc['db_query']('', '
1061
+		if ($upcontext['karma_installed']['good']) {
1062
+					$smcFunc['db_query']('', '
1003 1063
 				ALTER TABLE {db_prefix}members
1004 1064
 				DROP karma_good',
1005 1065
 				array()
1006 1066
 			);
1067
+		}
1007 1068
 
1008 1069
 		// Does karma bad was enable?
1009
-		if ($upcontext['karma_installed']['bad'])
1010
-			$smcFunc['db_query']('', '
1070
+		if ($upcontext['karma_installed']['bad']) {
1071
+					$smcFunc['db_query']('', '
1011 1072
 				ALTER TABLE {db_prefix}members
1012 1073
 				DROP karma_bad',
1013 1074
 				array()
1014 1075
 			);
1076
+		}
1015 1077
 
1016 1078
 		// Cleaning up old karma permissions.
1017 1079
 		$smcFunc['db_query']('', '
@@ -1024,26 +1086,29 @@  discard block
 block discarded – undo
1024 1086
 	}
1025 1087
 
1026 1088
 	// Emptying the error log?
1027
-	if (!empty($_POST['empty_error']))
1028
-		$smcFunc['db_query']('truncate_table', '
1089
+	if (!empty($_POST['empty_error'])) {
1090
+			$smcFunc['db_query']('truncate_table', '
1029 1091
 			TRUNCATE {db_prefix}log_errors',
1030 1092
 			array(
1031 1093
 			)
1032 1094
 		);
1095
+	}
1033 1096
 
1034 1097
 	$changes = array();
1035 1098
 
1036 1099
 	// Add proxy settings.
1037
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1038
-		$changes += array(
1100
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1101
+			$changes += array(
1039 1102
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1040 1103
 			'image_proxy_maxsize' => 5190,
1041 1104
 			'image_proxy_enabled' => 0,
1042 1105
 		);
1106
+	}
1043 1107
 
1044 1108
 	// If we're overriding the language follow it through.
1045
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1046
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1109
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1110
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1111
+	}
1047 1112
 
1048 1113
 	if (!empty($_POST['maint']))
1049 1114
 	{
@@ -1055,30 +1120,34 @@  discard block
 block discarded – undo
1055 1120
 		{
1056 1121
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1057 1122
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1058
-		}
1059
-		else
1123
+		} else
1060 1124
 		{
1061 1125
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1062 1126
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1063 1127
 		}
1064 1128
 	}
1065 1129
 
1066
-	if ($command_line)
1067
-		echo ' * Updating Settings.php...';
1130
+	if ($command_line) {
1131
+			echo ' * Updating Settings.php...';
1132
+	}
1068 1133
 
1069 1134
 	// Fix some old paths.
1070
-	if (substr($boarddir, 0, 1) == '.')
1071
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1135
+	if (substr($boarddir, 0, 1) == '.') {
1136
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1137
+	}
1072 1138
 
1073
-	if (substr($sourcedir, 0, 1) == '.')
1074
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1139
+	if (substr($sourcedir, 0, 1) == '.') {
1140
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1141
+	}
1075 1142
 
1076
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1077
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1143
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1144
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1145
+	}
1078 1146
 
1079 1147
 	// Not had the database type added before?
1080
-	if (empty($db_type))
1081
-		$changes['db_type'] = 'mysql';
1148
+	if (empty($db_type)) {
1149
+			$changes['db_type'] = 'mysql';
1150
+	}
1082 1151
 
1083 1152
 	// If they have a "host:port" setup for the host, split that into separate values
1084 1153
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1089,32 +1158,36 @@  discard block
 block discarded – undo
1089 1158
 		$changes['db_server'] = '\'' . $db_server . '\'';
1090 1159
 
1091 1160
 		// Only set this if we're not using the default port
1092
-		if ($db_port != ini_get('mysqli.default_port'))
1093
-			$changes['db_port'] = (int) $db_port;
1094
-	}
1095
-	elseif (!empty($db_port))
1161
+		if ($db_port != ini_get('mysqli.default_port')) {
1162
+					$changes['db_port'] = (int) $db_port;
1163
+		}
1164
+	} elseif (!empty($db_port))
1096 1165
 	{
1097 1166
 		// If db_port is set and is the same as the default, set it to ''
1098 1167
 		if ($db_type == 'mysql')
1099 1168
 		{
1100
-			if ($db_port == ini_get('mysqli.default_port'))
1101
-				$changes['db_port'] = '\'\'';
1102
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1103
-				$changes['db_port'] = '\'\'';
1169
+			if ($db_port == ini_get('mysqli.default_port')) {
1170
+							$changes['db_port'] = '\'\'';
1171
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1172
+							$changes['db_port'] = '\'\'';
1173
+			}
1104 1174
 		}
1105 1175
 	}
1106 1176
 
1107 1177
 	// Maybe we haven't had this option yet?
1108
-	if (empty($packagesdir))
1109
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1178
+	if (empty($packagesdir)) {
1179
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1180
+	}
1110 1181
 
1111 1182
 	// Add support for $tasksdir var.
1112
-	if (empty($tasksdir))
1113
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1183
+	if (empty($tasksdir)) {
1184
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1185
+	}
1114 1186
 
1115 1187
 	// Make sure we fix the language as well.
1116
-	if (stristr($language, '-utf8'))
1117
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1188
+	if (stristr($language, '-utf8')) {
1189
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1190
+	}
1118 1191
 
1119 1192
 	// @todo Maybe change the cookie name if going to 1.1, too?
1120 1193
 
@@ -1122,8 +1195,9 @@  discard block
 block discarded – undo
1122 1195
 	require_once($sourcedir . '/Subs-Admin.php');
1123 1196
 	updateSettingsFile($changes);
1124 1197
 
1125
-	if ($command_line)
1126
-		echo ' Successful.' . "\n";
1198
+	if ($command_line) {
1199
+			echo ' Successful.' . "\n";
1200
+	}
1127 1201
 
1128 1202
 	// Are we doing debug?
1129 1203
 	if (isset($_POST['debug']))
@@ -1133,8 +1207,9 @@  discard block
 block discarded – undo
1133 1207
 	}
1134 1208
 
1135 1209
 	// If we're not backing up then jump one.
1136
-	if (empty($_POST['backup']))
1137
-		$upcontext['current_step']++;
1210
+	if (empty($_POST['backup'])) {
1211
+			$upcontext['current_step']++;
1212
+	}
1138 1213
 
1139 1214
 	// If we've got here then let's proceed to the next step!
1140 1215
 	return true;
@@ -1149,8 +1224,9 @@  discard block
 block discarded – undo
1149 1224
 	$upcontext['page_title'] = 'Backup Database';
1150 1225
 
1151 1226
 	// Done it already - js wise?
1152
-	if (!empty($_POST['backup_done']))
1153
-		return true;
1227
+	if (!empty($_POST['backup_done'])) {
1228
+			return true;
1229
+	}
1154 1230
 
1155 1231
 	// Some useful stuff here.
1156 1232
 	db_extend();
@@ -1164,9 +1240,10 @@  discard block
 block discarded – undo
1164 1240
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1165 1241
 
1166 1242
 	$table_names = array();
1167
-	foreach ($tables as $table)
1168
-		if (substr($table, 0, 7) !== 'backup_')
1243
+	foreach ($tables as $table) {
1244
+			if (substr($table, 0, 7) !== 'backup_')
1169 1245
 			$table_names[] = $table;
1246
+	}
1170 1247
 
1171 1248
 	$upcontext['table_count'] = count($table_names);
1172 1249
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1176,12 +1253,14 @@  discard block
 block discarded – undo
1176 1253
 	$file_steps = $upcontext['table_count'];
1177 1254
 
1178 1255
 	// What ones have we already done?
1179
-	foreach ($table_names as $id => $table)
1180
-		if ($id < $_GET['substep'])
1256
+	foreach ($table_names as $id => $table) {
1257
+			if ($id < $_GET['substep'])
1181 1258
 			$upcontext['previous_tables'][] = $table;
1259
+	}
1182 1260
 
1183
-	if ($command_line)
1184
-		echo 'Backing Up Tables.';
1261
+	if ($command_line) {
1262
+			echo 'Backing Up Tables.';
1263
+	}
1185 1264
 
1186 1265
 	// If we don't support javascript we backup here.
1187 1266
 	if (!$support_js || isset($_GET['xml']))
@@ -1200,8 +1279,9 @@  discard block
 block discarded – undo
1200 1279
 			backupTable($table_names[$substep]);
1201 1280
 
1202 1281
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1203
-			if (isset($_GET['xml']))
1204
-				return upgradeExit();
1282
+			if (isset($_GET['xml'])) {
1283
+							return upgradeExit();
1284
+			}
1205 1285
 		}
1206 1286
 
1207 1287
 		if ($command_line)
@@ -1234,9 +1314,10 @@  discard block
 block discarded – undo
1234 1314
 
1235 1315
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1236 1316
 
1237
-	if ($command_line)
1238
-		echo ' done.';
1239
-}
1317
+	if ($command_line) {
1318
+			echo ' done.';
1319
+	}
1320
+	}
1240 1321
 
1241 1322
 // Step 2: Everything.
1242 1323
 function DatabaseChanges()
@@ -1245,8 +1326,9 @@  discard block
 block discarded – undo
1245 1326
 	global $upcontext, $support_js, $db_type;
1246 1327
 
1247 1328
 	// Have we just completed this?
1248
-	if (!empty($_POST['database_done']))
1249
-		return true;
1329
+	if (!empty($_POST['database_done'])) {
1330
+			return true;
1331
+	}
1250 1332
 
1251 1333
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1252 1334
 	$upcontext['page_title'] = 'Database Changes';
@@ -1261,15 +1343,16 @@  discard block
 block discarded – undo
1261 1343
 	);
1262 1344
 
1263 1345
 	// How many files are there in total?
1264
-	if (isset($_GET['filecount']))
1265
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1266
-	else
1346
+	if (isset($_GET['filecount'])) {
1347
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1348
+	} else
1267 1349
 	{
1268 1350
 		$upcontext['file_count'] = 0;
1269 1351
 		foreach ($files as $file)
1270 1352
 		{
1271
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1272
-				$upcontext['file_count']++;
1353
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1354
+							$upcontext['file_count']++;
1355
+			}
1273 1356
 		}
1274 1357
 	}
1275 1358
 
@@ -1279,9 +1362,9 @@  discard block
 block discarded – undo
1279 1362
 	$upcontext['cur_file_num'] = 0;
1280 1363
 	foreach ($files as $file)
1281 1364
 	{
1282
-		if ($did_not_do)
1283
-			$did_not_do--;
1284
-		else
1365
+		if ($did_not_do) {
1366
+					$did_not_do--;
1367
+		} else
1285 1368
 		{
1286 1369
 			$upcontext['cur_file_num']++;
1287 1370
 			$upcontext['cur_file_name'] = $file[0];
@@ -1308,12 +1391,13 @@  discard block
 block discarded – undo
1308 1391
 					// Flag to move on to the next.
1309 1392
 					$upcontext['completed_step'] = true;
1310 1393
 					// Did we complete the whole file?
1311
-					if ($nextFile)
1312
-						$upcontext['current_debug_item_num'] = -1;
1394
+					if ($nextFile) {
1395
+											$upcontext['current_debug_item_num'] = -1;
1396
+					}
1313 1397
 					return upgradeExit();
1398
+				} elseif ($support_js) {
1399
+									break;
1314 1400
 				}
1315
-				elseif ($support_js)
1316
-					break;
1317 1401
 			}
1318 1402
 			// Set the progress bar to be right as if we had - even if we hadn't...
1319 1403
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1338,8 +1422,9 @@  discard block
 block discarded – undo
1338 1422
 	global $command_line, $language, $upcontext, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1339 1423
 
1340 1424
 	// Now it's nice to have some of the basic SMF source files.
1341
-	if (!isset($_GET['ssi']) && !$command_line)
1342
-		redirectLocation('&ssi=1');
1425
+	if (!isset($_GET['ssi']) && !$command_line) {
1426
+			redirectLocation('&ssi=1');
1427
+	}
1343 1428
 
1344 1429
 	$upcontext['sub_template'] = 'upgrade_complete';
1345 1430
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1355,14 +1440,16 @@  discard block
 block discarded – undo
1355 1440
 	// Are we in maintenance mode?
1356 1441
 	if (isset($upcontext['user']['main']))
1357 1442
 	{
1358
-		if ($command_line)
1359
-			echo ' * ';
1443
+		if ($command_line) {
1444
+					echo ' * ';
1445
+		}
1360 1446
 		$upcontext['removed_maintenance'] = true;
1361 1447
 		$changes['maintenance'] = $upcontext['user']['main'];
1362 1448
 	}
1363 1449
 	// Otherwise if somehow we are in 2 let's go to 1.
1364
-	elseif (!empty($maintenance) && $maintenance == 2)
1365
-		$changes['maintenance'] = 1;
1450
+	elseif (!empty($maintenance) && $maintenance == 2) {
1451
+			$changes['maintenance'] = 1;
1452
+	}
1366 1453
 
1367 1454
 	// Wipe this out...
1368 1455
 	$upcontext['user'] = array();
@@ -1377,9 +1464,9 @@  discard block
 block discarded – undo
1377 1464
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1378 1465
 
1379 1466
 	// Now is the perfect time to fetch the SM files.
1380
-	if ($command_line)
1381
-		cli_scheduled_fetchSMfiles();
1382
-	else
1467
+	if ($command_line) {
1468
+			cli_scheduled_fetchSMfiles();
1469
+	} else
1383 1470
 	{
1384 1471
 		require_once($sourcedir . '/ScheduledTasks.php');
1385 1472
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1387,8 +1474,9 @@  discard block
 block discarded – undo
1387 1474
 	}
1388 1475
 
1389 1476
 	// Log what we've done.
1390
-	if (empty($user_info['id']))
1391
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1477
+	if (empty($user_info['id'])) {
1478
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1479
+	}
1392 1480
 
1393 1481
 	// Log the action manually, so CLI still works.
1394 1482
 	$smcFunc['db_insert']('',
@@ -1407,8 +1495,9 @@  discard block
 block discarded – undo
1407 1495
 
1408 1496
 	// Save the current database version.
1409 1497
 	$server_version = $smcFunc['db_server_info']();
1410
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1411
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1498
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1499
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1500
+	}
1412 1501
 
1413 1502
 	if ($command_line)
1414 1503
 	{
@@ -1420,8 +1509,9 @@  discard block
 block discarded – undo
1420 1509
 
1421 1510
 	// Make sure it says we're done.
1422 1511
 	$upcontext['overall_percent'] = 100;
1423
-	if (isset($upcontext['step_progress']))
1424
-		unset($upcontext['step_progress']);
1512
+	if (isset($upcontext['step_progress'])) {
1513
+			unset($upcontext['step_progress']);
1514
+	}
1425 1515
 
1426 1516
 	$_GET['substep'] = 0;
1427 1517
 	return false;
@@ -1432,8 +1522,9 @@  discard block
 block discarded – undo
1432 1522
 {
1433 1523
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1434 1524
 
1435
-	if (empty($modSettings['time_format']))
1436
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1525
+	if (empty($modSettings['time_format'])) {
1526
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1527
+	}
1437 1528
 
1438 1529
 	// What files do we want to get
1439 1530
 	$request = $smcFunc['db_query']('', '
@@ -1467,8 +1558,9 @@  discard block
 block discarded – undo
1467 1558
 		$file_data = fetch_web_data($url);
1468 1559
 
1469 1560
 		// If we got an error - give up - the site might be down.
1470
-		if ($file_data === false)
1471
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1561
+		if ($file_data === false) {
1562
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1563
+		}
1472 1564
 
1473 1565
 		// Save the file to the database.
1474 1566
 		$smcFunc['db_query']('substring', '
@@ -1510,8 +1602,9 @@  discard block
 block discarded – undo
1510 1602
 	$themeData = array();
1511 1603
 	foreach ($values as $variable => $value)
1512 1604
 	{
1513
-		if (!isset($value) || $value === null)
1514
-			$value = 0;
1605
+		if (!isset($value) || $value === null) {
1606
+					$value = 0;
1607
+		}
1515 1608
 
1516 1609
 		$themeData[] = array(0, 1, $variable, $value);
1517 1610
 	}
@@ -1540,8 +1633,9 @@  discard block
 block discarded – undo
1540 1633
 
1541 1634
 	foreach ($values as $variable => $value)
1542 1635
 	{
1543
-		if (empty($modSettings[$value[0]]))
1544
-			continue;
1636
+		if (empty($modSettings[$value[0]])) {
1637
+					continue;
1638
+		}
1545 1639
 
1546 1640
 		$smcFunc['db_query']('', '
1547 1641
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1627,19 +1721,21 @@  discard block
 block discarded – undo
1627 1721
 	set_error_handler(
1628 1722
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1629 1723
 		{
1630
-			if ($support_js)
1631
-				return true;
1632
-			else
1633
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1724
+			if ($support_js) {
1725
+							return true;
1726
+			} else {
1727
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1728
+			}
1634 1729
 		}
1635 1730
 	);
1636 1731
 
1637 1732
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1638 1733
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1639
-	if ($db_type == 'mysql')
1640
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1641
-	else
1642
-		$db_collation = '';
1734
+	if ($db_type == 'mysql') {
1735
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1736
+	} else {
1737
+			$db_collation = '';
1738
+	}
1643 1739
 
1644 1740
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1645 1741
 
@@ -1651,8 +1747,9 @@  discard block
 block discarded – undo
1651 1747
 	$last_step = '';
1652 1748
 
1653 1749
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1654
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1655
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1750
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1751
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1752
+	}
1656 1753
 
1657 1754
 	// Count the total number of steps within this file - for progress.
1658 1755
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1672,15 +1769,18 @@  discard block
 block discarded – undo
1672 1769
 		$do_current = $substep >= $_GET['substep'];
1673 1770
 
1674 1771
 		// Get rid of any comments in the beginning of the line...
1675
-		if (substr(trim($line), 0, 2) === '/*')
1676
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1772
+		if (substr(trim($line), 0, 2) === '/*') {
1773
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1774
+		}
1677 1775
 
1678 1776
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1679
-		if ($is_debug && !$support_js && $command_line)
1680
-			flush();
1777
+		if ($is_debug && !$support_js && $command_line) {
1778
+					flush();
1779
+		}
1681 1780
 
1682
-		if (trim($line) === '')
1683
-			continue;
1781
+		if (trim($line) === '') {
1782
+					continue;
1783
+		}
1684 1784
 
1685 1785
 		if (trim(substr($line, 0, 3)) === '---')
1686 1786
 		{
@@ -1690,8 +1790,9 @@  discard block
 block discarded – undo
1690 1790
 			if (trim($current_data) != '' && $type !== '}')
1691 1791
 			{
1692 1792
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1693
-				if ($command_line)
1694
-					echo $upcontext['error_message'];
1793
+				if ($command_line) {
1794
+									echo $upcontext['error_message'];
1795
+				}
1695 1796
 			}
1696 1797
 
1697 1798
 			if ($type == ' ')
@@ -1709,17 +1810,18 @@  discard block
 block discarded – undo
1709 1810
 				if ($do_current)
1710 1811
 				{
1711 1812
 					$upcontext['actioned_items'][] = $last_step;
1712
-					if ($command_line)
1713
-						echo ' * ';
1813
+					if ($command_line) {
1814
+											echo ' * ';
1815
+					}
1714 1816
 				}
1715
-			}
1716
-			elseif ($type == '#')
1817
+			} elseif ($type == '#')
1717 1818
 			{
1718 1819
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1719 1820
 
1720 1821
 				$upcontext['current_debug_item_num']++;
1721
-				if (trim($line) != '---#')
1722
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1822
+				if (trim($line) != '---#') {
1823
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1824
+				}
1723 1825
 
1724 1826
 				// Have we already done something?
1725 1827
 				if (isset($_GET['xml']) && $done_something)
@@ -1730,34 +1832,36 @@  discard block
 block discarded – undo
1730 1832
 
1731 1833
 				if ($do_current)
1732 1834
 				{
1733
-					if (trim($line) == '---#' && $command_line)
1734
-						echo ' done.', $endl;
1735
-					elseif ($command_line)
1736
-						echo ' +++ ', rtrim(substr($line, 4));
1737
-					elseif (trim($line) != '---#')
1835
+					if (trim($line) == '---#' && $command_line) {
1836
+											echo ' done.', $endl;
1837
+					} elseif ($command_line) {
1838
+											echo ' +++ ', rtrim(substr($line, 4));
1839
+					} elseif (trim($line) != '---#')
1738 1840
 					{
1739
-						if ($is_debug)
1740
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1841
+						if ($is_debug) {
1842
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1843
+						}
1741 1844
 					}
1742 1845
 				}
1743 1846
 
1744 1847
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1745 1848
 				{
1746
-					if ($command_line)
1747
-						echo ' * ';
1748
-					else
1749
-						$upcontext['actioned_items'][] = $last_step;
1849
+					if ($command_line) {
1850
+											echo ' * ';
1851
+					} else {
1852
+											$upcontext['actioned_items'][] = $last_step;
1853
+					}
1750 1854
 				}
1751 1855
 
1752 1856
 				// Small step - only if we're actually doing stuff.
1753
-				if ($do_current)
1754
-					nextSubstep(++$substep);
1755
-				else
1756
-					$substep++;
1757
-			}
1758
-			elseif ($type == '{')
1759
-				$current_type = 'code';
1760
-			elseif ($type == '}')
1857
+				if ($do_current) {
1858
+									nextSubstep(++$substep);
1859
+				} else {
1860
+									$substep++;
1861
+				}
1862
+			} elseif ($type == '{') {
1863
+							$current_type = 'code';
1864
+			} elseif ($type == '}')
1761 1865
 			{
1762 1866
 				$current_type = 'sql';
1763 1867
 
@@ -1770,8 +1874,9 @@  discard block
 block discarded – undo
1770 1874
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1771 1875
 				{
1772 1876
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1773
-					if ($command_line)
1774
-						echo $upcontext['error_message'];
1877
+					if ($command_line) {
1878
+											echo $upcontext['error_message'];
1879
+					}
1775 1880
 				}
1776 1881
 
1777 1882
 				// Done with code!
@@ -1851,8 +1956,9 @@  discard block
 block discarded – undo
1851 1956
 	$db_unbuffered = false;
1852 1957
 
1853 1958
 	// Failure?!
1854
-	if ($result !== false)
1855
-		return $result;
1959
+	if ($result !== false) {
1960
+			return $result;
1961
+	}
1856 1962
 
1857 1963
 	$db_error_message = $smcFunc['db_error']($db_connection);
1858 1964
 	// If MySQL we do something more clever.
@@ -1880,54 +1986,61 @@  discard block
 block discarded – undo
1880 1986
 			{
1881 1987
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1882 1988
 				$result = mysqli_query($db_connection, $string);
1883
-				if ($result !== false)
1884
-					return $result;
1989
+				if ($result !== false) {
1990
+									return $result;
1991
+				}
1885 1992
 			}
1886
-		}
1887
-		elseif ($mysqli_errno == 2013)
1993
+		} elseif ($mysqli_errno == 2013)
1888 1994
 		{
1889 1995
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1890 1996
 			mysqli_select_db($db_connection, $db_name);
1891 1997
 			if ($db_connection)
1892 1998
 			{
1893 1999
 				$result = mysqli_query($db_connection, $string);
1894
-				if ($result !== false)
1895
-					return $result;
2000
+				if ($result !== false) {
2001
+									return $result;
2002
+				}
1896 2003
 			}
1897 2004
 		}
1898 2005
 		// Duplicate column name... should be okay ;).
1899
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1900
-			return false;
2006
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2007
+					return false;
2008
+		}
1901 2009
 		// Duplicate insert... make sure it's the proper type of query ;).
1902
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1903
-			return false;
2010
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2011
+					return false;
2012
+		}
1904 2013
 		// Creating an index on a non-existent column.
1905
-		elseif ($mysqli_errno == 1072)
1906
-			return false;
1907
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1908
-			return false;
2014
+		elseif ($mysqli_errno == 1072) {
2015
+					return false;
2016
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2017
+					return false;
2018
+		}
1909 2019
 	}
1910 2020
 	// If a table already exists don't go potty.
1911 2021
 	else
1912 2022
 	{
1913 2023
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1914 2024
 		{
1915
-			if (strpos($db_error_message, 'exist') !== false)
1916
-				return true;
1917
-		}
1918
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2025
+			if (strpos($db_error_message, 'exist') !== false) {
2026
+							return true;
2027
+			}
2028
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1919 2029
 		{
1920
-			if (strpos($db_error_message, 'duplicate') !== false)
1921
-				return true;
2030
+			if (strpos($db_error_message, 'duplicate') !== false) {
2031
+							return true;
2032
+			}
1922 2033
 		}
1923 2034
 	}
1924 2035
 
1925 2036
 	// Get the query string so we pass everything.
1926 2037
 	$query_string = '';
1927
-	foreach ($_GET as $k => $v)
1928
-		$query_string .= ';' . $k . '=' . $v;
1929
-	if (strlen($query_string) != 0)
1930
-		$query_string = '?' . substr($query_string, 1);
2038
+	foreach ($_GET as $k => $v) {
2039
+			$query_string .= ';' . $k . '=' . $v;
2040
+	}
2041
+	if (strlen($query_string) != 0) {
2042
+			$query_string = '?' . substr($query_string, 1);
2043
+	}
1931 2044
 
1932 2045
 	if ($command_line)
1933 2046
 	{
@@ -1982,16 +2095,18 @@  discard block
 block discarded – undo
1982 2095
 			{
1983 2096
 				$found |= 1;
1984 2097
 				// Do some checks on the data if we have it set.
1985
-				if (isset($change['col_type']))
1986
-					$found &= $change['col_type'] === $column['type'];
1987
-				if (isset($change['null_allowed']))
1988
-					$found &= $column['null'] == $change['null_allowed'];
1989
-				if (isset($change['default']))
1990
-					$found &= $change['default'] === $column['default'];
2098
+				if (isset($change['col_type'])) {
2099
+									$found &= $change['col_type'] === $column['type'];
2100
+				}
2101
+				if (isset($change['null_allowed'])) {
2102
+									$found &= $column['null'] == $change['null_allowed'];
2103
+				}
2104
+				if (isset($change['default'])) {
2105
+									$found &= $change['default'] === $column['default'];
2106
+				}
1991 2107
 			}
1992 2108
 		}
1993
-	}
1994
-	elseif ($change['type'] === 'index')
2109
+	} elseif ($change['type'] === 'index')
1995 2110
 	{
1996 2111
 		$request = upgrade_query('
1997 2112
 			SHOW INDEX
@@ -2000,9 +2115,10 @@  discard block
 block discarded – undo
2000 2115
 		{
2001 2116
 			$cur_index = array();
2002 2117
 
2003
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2004
-				if ($row['Key_name'] === $change['name'])
2118
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2119
+							if ($row['Key_name'] === $change['name'])
2005 2120
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2121
+			}
2006 2122
 
2007 2123
 			ksort($cur_index, SORT_NUMERIC);
2008 2124
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2012,14 +2128,17 @@  discard block
 block discarded – undo
2012 2128
 	}
2013 2129
 
2014 2130
 	// If we're trying to add and it's added, we're done.
2015
-	if ($found && in_array($change['method'], array('add', 'change')))
2016
-		return true;
2131
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2132
+			return true;
2133
+	}
2017 2134
 	// Otherwise if we're removing and it wasn't found we're also done.
2018
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2019
-		return true;
2135
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2136
+			return true;
2137
+	}
2020 2138
 	// Otherwise is it just a test?
2021
-	elseif ($is_test)
2022
-		return false;
2139
+	elseif ($is_test) {
2140
+			return false;
2141
+	}
2023 2142
 
2024 2143
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2025 2144
 	$running = false;
@@ -2030,8 +2149,9 @@  discard block
 block discarded – undo
2030 2149
 			SHOW FULL PROCESSLIST');
2031 2150
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2032 2151
 		{
2033
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2034
-				$found = true;
2152
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2153
+							$found = true;
2154
+			}
2035 2155
 		}
2036 2156
 
2037 2157
 		// Can't find it? Then we need to run it fools!
@@ -2043,8 +2163,9 @@  discard block
 block discarded – undo
2043 2163
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2044 2164
 				' . $change['text'], true) !== false;
2045 2165
 
2046
-			if (!$success)
2047
-				return false;
2166
+			if (!$success) {
2167
+							return false;
2168
+			}
2048 2169
 
2049 2170
 			// Return
2050 2171
 			$running = true;
@@ -2086,8 +2207,9 @@  discard block
 block discarded – undo
2086 2207
 			'db_error_skip' => true,
2087 2208
 		)
2088 2209
 	);
2089
-	if ($smcFunc['db_num_rows']($request) === 0)
2090
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2210
+	if ($smcFunc['db_num_rows']($request) === 0) {
2211
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2212
+	}
2091 2213
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2092 2214
 	$smcFunc['db_free_result']($request);
2093 2215
 
@@ -2109,18 +2231,19 @@  discard block
 block discarded – undo
2109 2231
 			)
2110 2232
 		);
2111 2233
 		// No results? Just forget it all together.
2112
-		if ($smcFunc['db_num_rows']($request) === 0)
2113
-			unset($table_row['Collation']);
2114
-		else
2115
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2234
+		if ($smcFunc['db_num_rows']($request) === 0) {
2235
+					unset($table_row['Collation']);
2236
+		} else {
2237
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2238
+		}
2116 2239
 		$smcFunc['db_free_result']($request);
2117 2240
 	}
2118 2241
 
2119 2242
 	if ($column_fix)
2120 2243
 	{
2121 2244
 		// Make sure there are no NULL's left.
2122
-		if ($null_fix)
2123
-			$smcFunc['db_query']('', '
2245
+		if ($null_fix) {
2246
+					$smcFunc['db_query']('', '
2124 2247
 				UPDATE {db_prefix}' . $change['table'] . '
2125 2248
 				SET ' . $change['column'] . ' = {string:default}
2126 2249
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2129,6 +2252,7 @@  discard block
 block discarded – undo
2129 2252
 					'db_error_skip' => true,
2130 2253
 				)
2131 2254
 			);
2255
+		}
2132 2256
 
2133 2257
 		// Do the actual alteration.
2134 2258
 		$smcFunc['db_query']('', '
@@ -2157,8 +2281,9 @@  discard block
 block discarded – undo
2157 2281
 	}
2158 2282
 
2159 2283
 	// Not a column we need to check on?
2160
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2161
-		return;
2284
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2285
+			return;
2286
+	}
2162 2287
 
2163 2288
 	// Break it up you (six|seven).
2164 2289
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2177,13 +2302,13 @@  discard block
 block discarded – undo
2177 2302
 				'new_name' => $temp[2],
2178 2303
 		));
2179 2304
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2180
-		if ($smcFunc['db_num_rows'] != 1)
2181
-			return;
2305
+		if ($smcFunc['db_num_rows'] != 1) {
2306
+					return;
2307
+		}
2182 2308
 
2183 2309
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2184 2310
 		$smcFunc['db_free_result']($request);
2185
-	}
2186
-	else
2311
+	} else
2187 2312
 	{
2188 2313
 		// Do this the old fashion, sure method way.
2189 2314
 		$request = $smcFunc['db_query']('', '
@@ -2194,21 +2319,24 @@  discard block
 block discarded – undo
2194 2319
 		));
2195 2320
 		// Mayday!
2196 2321
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2197
-		if ($smcFunc['db_num_rows'] == 0)
2198
-			return;
2322
+		if ($smcFunc['db_num_rows'] == 0) {
2323
+					return;
2324
+		}
2199 2325
 
2200 2326
 		// Oh where, oh where has my little field gone. Oh where can it be...
2201
-		while ($row = $smcFunc['db_query']($request))
2202
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2327
+		while ($row = $smcFunc['db_query']($request)) {
2328
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2203 2329
 			{
2204 2330
 				$current_type = $row['Type'];
2331
+		}
2205 2332
 				break;
2206 2333
 			}
2207 2334
 	}
2208 2335
 
2209 2336
 	// If this doesn't match, the column may of been altered for a reason.
2210
-	if (trim($current_type) != trim($temp[3]))
2211
-		$temp[3] = $current_type;
2337
+	if (trim($current_type) != trim($temp[3])) {
2338
+			$temp[3] = $current_type;
2339
+	}
2212 2340
 
2213 2341
 	// Piece this back together.
2214 2342
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2220,8 +2348,9 @@  discard block
 block discarded – undo
2220 2348
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2221 2349
 	global $step_progress, $is_debug, $upcontext;
2222 2350
 
2223
-	if ($_GET['substep'] < $substep)
2224
-		$_GET['substep'] = $substep;
2351
+	if ($_GET['substep'] < $substep) {
2352
+			$_GET['substep'] = $substep;
2353
+	}
2225 2354
 
2226 2355
 	if ($command_line)
2227 2356
 	{
@@ -2234,29 +2363,33 @@  discard block
 block discarded – undo
2234 2363
 	}
2235 2364
 
2236 2365
 	@set_time_limit(300);
2237
-	if (function_exists('apache_reset_timeout'))
2238
-		@apache_reset_timeout();
2366
+	if (function_exists('apache_reset_timeout')) {
2367
+			@apache_reset_timeout();
2368
+	}
2239 2369
 
2240
-	if (time() - $start_time <= $timeLimitThreshold)
2241
-		return;
2370
+	if (time() - $start_time <= $timeLimitThreshold) {
2371
+			return;
2372
+	}
2242 2373
 
2243 2374
 	// Do we have some custom step progress stuff?
2244 2375
 	if (!empty($step_progress))
2245 2376
 	{
2246 2377
 		$upcontext['substep_progress'] = 0;
2247 2378
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2248
-		if ($step_progress['current'] > $step_progress['total'])
2249
-			$upcontext['substep_progress'] = 99.9;
2250
-		else
2251
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2379
+		if ($step_progress['current'] > $step_progress['total']) {
2380
+					$upcontext['substep_progress'] = 99.9;
2381
+		} else {
2382
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2383
+		}
2252 2384
 
2253 2385
 		// Make it nicely rounded.
2254 2386
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2255 2387
 	}
2256 2388
 
2257 2389
 	// If this is XML we just exit right away!
2258
-	if (isset($_GET['xml']))
2259
-		return upgradeExit();
2390
+	if (isset($_GET['xml'])) {
2391
+			return upgradeExit();
2392
+	}
2260 2393
 
2261 2394
 	// We're going to pause after this!
2262 2395
 	$upcontext['pause'] = true;
@@ -2264,13 +2397,15 @@  discard block
 block discarded – undo
2264 2397
 	$upcontext['query_string'] = '';
2265 2398
 	foreach ($_GET as $k => $v)
2266 2399
 	{
2267
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2268
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2400
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2401
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2402
+		}
2269 2403
 	}
2270 2404
 
2271 2405
 	// Custom warning?
2272
-	if (!empty($custom_warning))
2273
-		$upcontext['custom_warning'] = $custom_warning;
2406
+	if (!empty($custom_warning)) {
2407
+			$upcontext['custom_warning'] = $custom_warning;
2408
+	}
2274 2409
 
2275 2410
 	upgradeExit();
2276 2411
 }
@@ -2285,25 +2420,26 @@  discard block
 block discarded – undo
2285 2420
 	ob_implicit_flush(true);
2286 2421
 	@set_time_limit(600);
2287 2422
 
2288
-	if (!isset($_SERVER['argv']))
2289
-		$_SERVER['argv'] = array();
2423
+	if (!isset($_SERVER['argv'])) {
2424
+			$_SERVER['argv'] = array();
2425
+	}
2290 2426
 	$_GET['maint'] = 1;
2291 2427
 
2292 2428
 	foreach ($_SERVER['argv'] as $i => $arg)
2293 2429
 	{
2294
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2295
-			$_GET['lang'] = $match[1];
2296
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2297
-			continue;
2298
-		elseif ($arg == '--no-maintenance')
2299
-			$_GET['maint'] = 0;
2300
-		elseif ($arg == '--debug')
2301
-			$is_debug = true;
2302
-		elseif ($arg == '--backup')
2303
-			$_POST['backup'] = 1;
2304
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2305
-			$_GET['conv'] = 1;
2306
-		elseif ($i != 0)
2430
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2431
+					$_GET['lang'] = $match[1];
2432
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2433
+					continue;
2434
+		} elseif ($arg == '--no-maintenance') {
2435
+					$_GET['maint'] = 0;
2436
+		} elseif ($arg == '--debug') {
2437
+					$is_debug = true;
2438
+		} elseif ($arg == '--backup') {
2439
+					$_POST['backup'] = 1;
2440
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2441
+					$_GET['conv'] = 1;
2442
+		} elseif ($i != 0)
2307 2443
 		{
2308 2444
 			echo 'SMF Command-line Upgrader
2309 2445
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2317,10 +2453,12 @@  discard block
 block discarded – undo
2317 2453
 		}
2318 2454
 	}
2319 2455
 
2320
-	if (!php_version_check())
2321
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2322
-	if (!db_version_check())
2323
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2456
+	if (!php_version_check()) {
2457
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2458
+	}
2459
+	if (!db_version_check()) {
2460
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2461
+	}
2324 2462
 
2325 2463
 	// Do some checks to make sure they have proper privileges
2326 2464
 	db_extend('packages');
@@ -2335,34 +2473,39 @@  discard block
 block discarded – undo
2335 2473
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2336 2474
 
2337 2475
 	// Sorry... we need CREATE, ALTER and DROP
2338
-	if (!$create || !$alter || !$drop)
2339
-		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);
2476
+	if (!$create || !$alter || !$drop) {
2477
+			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);
2478
+	}
2340 2479
 
2341 2480
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2342 2481
 		&& @file_exists($sourcedir . '/QueryString.php')
2343 2482
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2344
-	if (!$check && !isset($modSettings['smfVersion']))
2345
-		print_error('Error: Some files are missing or out-of-date.', true);
2483
+	if (!$check && !isset($modSettings['smfVersion'])) {
2484
+			print_error('Error: Some files are missing or out-of-date.', true);
2485
+	}
2346 2486
 
2347 2487
 	// Do a quick version spot check.
2348 2488
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2349 2489
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2350
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2351
-		print_error('Error: Some files have not yet been updated properly.');
2490
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2491
+			print_error('Error: Some files have not yet been updated properly.');
2492
+	}
2352 2493
 
2353 2494
 	// Make sure Settings.php is writable.
2354 2495
 		quickFileWritable($boarddir . '/Settings.php');
2355
-	if (!is_writable($boarddir . '/Settings.php'))
2356
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2496
+	if (!is_writable($boarddir . '/Settings.php')) {
2497
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2498
+	}
2357 2499
 
2358 2500
 	// Make sure Settings_bak.php is writable.
2359 2501
 		quickFileWritable($boarddir . '/Settings_bak.php');
2360
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2361
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2502
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2503
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2504
+	}
2362 2505
 
2363
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2364
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2365
-	elseif (isset($modSettings['agreement']))
2506
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2507
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2508
+	} elseif (isset($modSettings['agreement']))
2366 2509
 	{
2367 2510
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2368 2511
 		fwrite($fp, $modSettings['agreement']);
@@ -2372,31 +2515,36 @@  discard block
 block discarded – undo
2372 2515
 	// Make sure Themes is writable.
2373 2516
 	quickFileWritable($modSettings['theme_dir']);
2374 2517
 
2375
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2376
-		print_error('Error: Unable to obtain write access to "Themes".');
2518
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2519
+			print_error('Error: Unable to obtain write access to "Themes".');
2520
+	}
2377 2521
 
2378 2522
 	// Make sure cache directory exists and is writable!
2379 2523
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2380
-	if (!file_exists($cachedir_temp))
2381
-		@mkdir($cachedir_temp);
2524
+	if (!file_exists($cachedir_temp)) {
2525
+			@mkdir($cachedir_temp);
2526
+	}
2382 2527
 
2383 2528
 	// Make sure the cache temp dir is writable.
2384 2529
 	quickFileWritable($cachedir_temp);
2385 2530
 
2386
-	if (!is_writable($cachedir_temp))
2387
-		print_error('Error: Unable to obtain write access to "cache".', true);
2531
+	if (!is_writable($cachedir_temp)) {
2532
+			print_error('Error: Unable to obtain write access to "cache".', true);
2533
+	}
2388 2534
 
2389
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2390
-		print_error('Error: Unable to find language files!', true);
2391
-	else
2535
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2536
+			print_error('Error: Unable to find language files!', true);
2537
+	} else
2392 2538
 	{
2393 2539
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2394 2540
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2395 2541
 
2396
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2397
-			print_error('Error: Language files out of date.', true);
2398
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2399
-			print_error('Error: Install language is missing for selected language.', true);
2542
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2543
+					print_error('Error: Language files out of date.', true);
2544
+		}
2545
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2546
+					print_error('Error: Install language is missing for selected language.', true);
2547
+		}
2400 2548
 
2401 2549
 		// Otherwise include it!
2402 2550
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2415,8 +2563,9 @@  discard block
 block discarded – undo
2415 2563
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2416 2564
 
2417 2565
 	// Done it already?
2418
-	if (!empty($_POST['utf8_done']))
2419
-		return true;
2566
+	if (!empty($_POST['utf8_done'])) {
2567
+			return true;
2568
+	}
2420 2569
 
2421 2570
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2422 2571
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2429,8 +2578,7 @@  discard block
 block discarded – undo
2429 2578
 		);
2430 2579
 
2431 2580
 		return true;
2432
-	}
2433
-	else
2581
+	} else
2434 2582
 	{
2435 2583
 		$upcontext['page_title'] = 'Converting to UTF8';
2436 2584
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2474,8 +2622,9 @@  discard block
 block discarded – undo
2474 2622
 			)
2475 2623
 		);
2476 2624
 		$db_charsets = array();
2477
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2478
-			$db_charsets[] = $row['Charset'];
2625
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2626
+					$db_charsets[] = $row['Charset'];
2627
+		}
2479 2628
 
2480 2629
 		$smcFunc['db_free_result']($request);
2481 2630
 
@@ -2511,13 +2660,15 @@  discard block
 block discarded – undo
2511 2660
 		// If there's a fulltext index, we need to drop it first...
2512 2661
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2513 2662
 		{
2514
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2515
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2663
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2664
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2516 2665
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2666
+			}
2517 2667
 			$smcFunc['db_free_result']($request);
2518 2668
 
2519
-			if (isset($upcontext['fulltext_index']))
2520
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2669
+			if (isset($upcontext['fulltext_index'])) {
2670
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2671
+			}
2521 2672
 		}
2522 2673
 
2523 2674
 		// Drop it and make a note...
@@ -2707,8 +2858,9 @@  discard block
 block discarded – undo
2707 2858
 			$replace = '%field%';
2708 2859
 
2709 2860
 			// Build a huge REPLACE statement...
2710
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2711
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2861
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2862
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2863
+			}
2712 2864
 		}
2713 2865
 
2714 2866
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2718,9 +2870,10 @@  discard block
 block discarded – undo
2718 2870
 		$upcontext['table_count'] = count($queryTables);
2719 2871
 
2720 2872
 		// What ones have we already done?
2721
-		foreach ($queryTables as $id => $table)
2722
-			if ($id < $_GET['substep'])
2873
+		foreach ($queryTables as $id => $table) {
2874
+					if ($id < $_GET['substep'])
2723 2875
 				$upcontext['previous_tables'][] = $table;
2876
+		}
2724 2877
 
2725 2878
 		$upcontext['cur_table_num'] = $_GET['substep'];
2726 2879
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2757,8 +2910,9 @@  discard block
 block discarded – undo
2757 2910
 			nextSubstep($substep);
2758 2911
 
2759 2912
 			// Just to make sure it doesn't time out.
2760
-			if (function_exists('apache_reset_timeout'))
2761
-				@apache_reset_timeout();
2913
+			if (function_exists('apache_reset_timeout')) {
2914
+							@apache_reset_timeout();
2915
+			}
2762 2916
 
2763 2917
 			$table_charsets = array();
2764 2918
 
@@ -2779,8 +2933,9 @@  discard block
 block discarded – undo
2779 2933
 					{
2780 2934
 						list($charset) = explode('_', $collation);
2781 2935
 
2782
-						if (!isset($table_charsets[$charset]))
2783
-							$table_charsets[$charset] = array();
2936
+						if (!isset($table_charsets[$charset])) {
2937
+													$table_charsets[$charset] = array();
2938
+						}
2784 2939
 
2785 2940
 						$table_charsets[$charset][] = $column_info;
2786 2941
 					}
@@ -2820,10 +2975,11 @@  discard block
 block discarded – undo
2820 2975
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2821 2976
 				{
2822 2977
 					$update = '';
2823
-					foreach ($table_charsets as $charset => $columns)
2824
-						foreach ($columns as $column)
2978
+					foreach ($table_charsets as $charset => $columns) {
2979
+											foreach ($columns as $column)
2825 2980
 							$update .= '
2826 2981
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
2982
+					}
2827 2983
 
2828 2984
 					$smcFunc['db_query']('', '
2829 2985
 						UPDATE {raw:table_name}
@@ -2848,8 +3004,9 @@  discard block
 block discarded – undo
2848 3004
 			// Now do the actual conversion (if still needed).
2849 3005
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2850 3006
 			{
2851
-				if ($command_line)
2852
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3007
+				if ($command_line) {
3008
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3009
+				}
2853 3010
 
2854 3011
 				$smcFunc['db_query']('', '
2855 3012
 					ALTER TABLE {raw:table_name}
@@ -2859,12 +3016,14 @@  discard block
 block discarded – undo
2859 3016
 					)
2860 3017
 				);
2861 3018
 
2862
-				if ($command_line)
2863
-					echo " done.\n";
3019
+				if ($command_line) {
3020
+									echo " done.\n";
3021
+				}
2864 3022
 			}
2865 3023
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2866
-			if (isset($_GET['xml']))
2867
-				return upgradeExit();
3024
+			if (isset($_GET['xml'])) {
3025
+							return upgradeExit();
3026
+			}
2868 3027
 		}
2869 3028
 
2870 3029
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2893,8 +3052,8 @@  discard block
 block discarded – undo
2893 3052
 		);
2894 3053
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2895 3054
 		{
2896
-			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)
2897
-				$smcFunc['db_query']('', '
3055
+			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) {
3056
+							$smcFunc['db_query']('', '
2898 3057
 					UPDATE {db_prefix}log_actions
2899 3058
 					SET extra = {string:extra}
2900 3059
 					WHERE id_action = {int:current_action}',
@@ -2903,6 +3062,7 @@  discard block
 block discarded – undo
2903 3062
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2904 3063
 					)
2905 3064
 				);
3065
+			}
2906 3066
 		}
2907 3067
 		$smcFunc['db_free_result']($request);
2908 3068
 
@@ -2924,15 +3084,17 @@  discard block
 block discarded – undo
2924 3084
 	// First thing's first - did we already do this?
2925 3085
 	if (!empty($modSettings['json_done']))
2926 3086
 	{
2927
-		if ($command_line)
2928
-			return DeleteUpgrade();
2929
-		else
2930
-			return true;
3087
+		if ($command_line) {
3088
+					return DeleteUpgrade();
3089
+		} else {
3090
+					return true;
3091
+		}
2931 3092
 	}
2932 3093
 
2933 3094
 	// Done it already - js wise?
2934
-	if (!empty($_POST['json_done']))
2935
-		return true;
3095
+	if (!empty($_POST['json_done'])) {
3096
+			return true;
3097
+	}
2936 3098
 
2937 3099
 	// List of tables affected by this function
2938 3100
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2964,12 +3126,14 @@  discard block
 block discarded – undo
2964 3126
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
2965 3127
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
2966 3128
 
2967
-	foreach ($keys as $id => $table)
2968
-		if ($id < $_GET['substep'])
3129
+	foreach ($keys as $id => $table) {
3130
+			if ($id < $_GET['substep'])
2969 3131
 			$upcontext['previous_tables'][] = $table;
3132
+	}
2970 3133
 
2971
-	if ($command_line)
2972
-		echo 'Converting data from serialize() to json_encode().';
3134
+	if ($command_line) {
3135
+			echo 'Converting data from serialize() to json_encode().';
3136
+	}
2973 3137
 
2974 3138
 	if (!$support_js || isset($_GET['xml']))
2975 3139
 	{
@@ -3009,8 +3173,9 @@  discard block
 block discarded – undo
3009 3173
 
3010 3174
 				// Loop through and fix these...
3011 3175
 				$new_settings = array();
3012
-				if ($command_line)
3013
-					echo "\n" . 'Fixing some settings...';
3176
+				if ($command_line) {
3177
+									echo "\n" . 'Fixing some settings...';
3178
+				}
3014 3179
 
3015 3180
 				foreach ($serialized_settings as $var)
3016 3181
 				{
@@ -3018,22 +3183,24 @@  discard block
 block discarded – undo
3018 3183
 					{
3019 3184
 						// Attempt to unserialize the setting
3020 3185
 						$temp = @safe_unserialize($modSettings[$var]);
3021
-						if (!$temp && $command_line)
3022
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3023
-						elseif ($temp !== false)
3024
-							$new_settings[$var] = json_encode($temp);
3186
+						if (!$temp && $command_line) {
3187
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3188
+						} elseif ($temp !== false) {
3189
+													$new_settings[$var] = json_encode($temp);
3190
+						}
3025 3191
 					}
3026 3192
 				}
3027 3193
 
3028 3194
 				// Update everything at once
3029
-				if (!function_exists('cache_put_data'))
3030
-					require_once($sourcedir . '/Load.php');
3195
+				if (!function_exists('cache_put_data')) {
3196
+									require_once($sourcedir . '/Load.php');
3197
+				}
3031 3198
 				updateSettings($new_settings, true);
3032 3199
 
3033
-				if ($command_line)
3034
-					echo ' done.';
3035
-			}
3036
-			elseif ($table == 'themes')
3200
+				if ($command_line) {
3201
+									echo ' done.';
3202
+				}
3203
+			} elseif ($table == 'themes')
3037 3204
 			{
3038 3205
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3039 3206
 				$query = $smcFunc['db_query']('', '
@@ -3052,10 +3219,11 @@  discard block
 block discarded – undo
3052 3219
 
3053 3220
 						if ($command_line)
3054 3221
 						{
3055
-							if ($temp === false)
3056
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3057
-							else
3058
-								echo "\n" . 'Fixing admin preferences...';
3222
+							if ($temp === false) {
3223
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3224
+							} else {
3225
+															echo "\n" . 'Fixing admin preferences...';
3226
+							}
3059 3227
 						}
3060 3228
 
3061 3229
 						if ($temp !== false)
@@ -3077,15 +3245,15 @@  discard block
 block discarded – undo
3077 3245
 								)
3078 3246
 							);
3079 3247
 
3080
-							if ($command_line)
3081
-								echo ' done.';
3248
+							if ($command_line) {
3249
+															echo ' done.';
3250
+							}
3082 3251
 						}
3083 3252
 					}
3084 3253
 
3085 3254
 					$smcFunc['db_free_result']($query);
3086 3255
 				}
3087
-			}
3088
-			else
3256
+			} else
3089 3257
 			{
3090 3258
 				// First item is always the key...
3091 3259
 				$key = $info[0];
@@ -3096,8 +3264,7 @@  discard block
 block discarded – undo
3096 3264
 				{
3097 3265
 					$col_select = $info[1];
3098 3266
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3099
-				}
3100
-				else
3267
+				} else
3101 3268
 				{
3102 3269
 					$col_select = implode(', ', $info);
3103 3270
 				}
@@ -3130,8 +3297,7 @@  discard block
 block discarded – undo
3130 3297
 								if ($temp === false && $command_line)
3131 3298
 								{
3132 3299
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3133
-								}
3134
-								else
3300
+								} else
3135 3301
 								{
3136 3302
 									$row[$col] = json_encode($temp);
3137 3303
 
@@ -3156,16 +3322,18 @@  discard block
 block discarded – undo
3156 3322
 						}
3157 3323
 					}
3158 3324
 
3159
-					if ($command_line)
3160
-						echo ' done.';
3325
+					if ($command_line) {
3326
+											echo ' done.';
3327
+					}
3161 3328
 
3162 3329
 					// Free up some memory...
3163 3330
 					$smcFunc['db_free_result']($query);
3164 3331
 				}
3165 3332
 			}
3166 3333
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3167
-			if (isset($_GET['xml']))
3168
-				return upgradeExit();
3334
+			if (isset($_GET['xml'])) {
3335
+							return upgradeExit();
3336
+			}
3169 3337
 		}
3170 3338
 
3171 3339
 		if ($command_line)
@@ -3180,8 +3348,9 @@  discard block
 block discarded – undo
3180 3348
 
3181 3349
 		$_GET['substep'] = 0;
3182 3350
 		// Make sure we move on!
3183
-		if ($command_line)
3184
-			return DeleteUpgrade();
3351
+		if ($command_line) {
3352
+					return DeleteUpgrade();
3353
+		}
3185 3354
 
3186 3355
 		return true;
3187 3356
 	}
@@ -3201,14 +3370,16 @@  discard block
 block discarded – undo
3201 3370
 	global $upcontext, $txt, $settings;
3202 3371
 
3203 3372
 	// Don't call me twice!
3204
-	if (!empty($upcontext['chmod_called']))
3205
-		return;
3373
+	if (!empty($upcontext['chmod_called'])) {
3374
+			return;
3375
+	}
3206 3376
 
3207 3377
 	$upcontext['chmod_called'] = true;
3208 3378
 
3209 3379
 	// Nothing?
3210
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3211
-		return;
3380
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3381
+			return;
3382
+	}
3212 3383
 
3213 3384
 	// Was it a problem with Windows?
3214 3385
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3240,11 +3411,12 @@  discard block
 block discarded – undo
3240 3411
 					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\');
3241 3412
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3242 3413
 
3243
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3244
-		echo '
3414
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3415
+			echo '
3245 3416
 					content.write(\'<hr>\n\t\t\t\');
3246 3417
 					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\');
3247 3418
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3419
+	}
3248 3420
 
3249 3421
 	echo '
3250 3422
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3252,17 +3424,19 @@  discard block
 block discarded – undo
3252 3424
 				}
3253 3425
 			</script>';
3254 3426
 
3255
-	if (!empty($upcontext['chmod']['ftp_error']))
3256
-		echo '
3427
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3428
+			echo '
3257 3429
 			<div class="error_message red">
3258 3430
 				The following error was encountered when trying to connect:<br><br>
3259 3431
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3260 3432
 			</div>
3261 3433
 			<br>';
3434
+	}
3262 3435
 
3263
-	if (empty($upcontext['chmod_in_form']))
3264
-		echo '
3436
+	if (empty($upcontext['chmod_in_form'])) {
3437
+			echo '
3265 3438
 	<form action="', $upcontext['form_url'], '" method="post">';
3439
+	}
3266 3440
 
3267 3441
 	echo '
3268 3442
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3297,10 +3471,11 @@  discard block
 block discarded – undo
3297 3471
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button_submit"></div>
3298 3472
 	</div>';
3299 3473
 
3300
-	if (empty($upcontext['chmod_in_form']))
3301
-		echo '
3474
+	if (empty($upcontext['chmod_in_form'])) {
3475
+			echo '
3302 3476
 	</form>';
3303
-}
3477
+	}
3478
+	}
3304 3479
 
3305 3480
 function template_upgrade_above()
3306 3481
 {
@@ -3360,9 +3535,10 @@  discard block
 block discarded – undo
3360 3535
 				<h2>', $txt['upgrade_progress'], '</h2>
3361 3536
 				<ul>';
3362 3537
 
3363
-	foreach ($upcontext['steps'] as $num => $step)
3364
-		echo '
3538
+	foreach ($upcontext['steps'] as $num => $step) {
3539
+			echo '
3365 3540
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3541
+	}
3366 3542
 
3367 3543
 	echo '
3368 3544
 					</ul>
@@ -3375,8 +3551,8 @@  discard block
 block discarded – undo
3375 3551
 				</div>
3376 3552
 			</div>';
3377 3553
 
3378
-	if (isset($upcontext['step_progress']))
3379
-		echo '
3554
+	if (isset($upcontext['step_progress'])) {
3555
+			echo '
3380 3556
 				<br>
3381 3557
 				<br>
3382 3558
 				<div id="progress_bar_step">
@@ -3385,6 +3561,7 @@  discard block
 block discarded – undo
3385 3561
 						<span>', $txt['upgrade_step_progress'], '</span>
3386 3562
 					</div>
3387 3563
 				</div>';
3564
+	}
3388 3565
 
3389 3566
 	echo '
3390 3567
 				<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>
@@ -3415,32 +3592,36 @@  discard block
 block discarded – undo
3415 3592
 {
3416 3593
 	global $upcontext, $txt;
3417 3594
 
3418
-	if (!empty($upcontext['pause']))
3419
-		echo '
3595
+	if (!empty($upcontext['pause'])) {
3596
+			echo '
3420 3597
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3421 3598
 
3422 3599
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3423 3600
 								<h3>
3424 3601
 									', $txt['upgrade_paused_overload'], '
3425 3602
 								</h3>';
3603
+	}
3426 3604
 
3427
-	if (!empty($upcontext['custom_warning']))
3428
-		echo '
3605
+	if (!empty($upcontext['custom_warning'])) {
3606
+			echo '
3429 3607
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3430 3608
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3431 3609
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3432 3610
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3433 3611
 								</div>';
3612
+	}
3434 3613
 
3435 3614
 	echo '
3436 3615
 								<div class="righttext" style="margin: 1ex;">';
3437 3616
 
3438
-	if (!empty($upcontext['continue']))
3439
-		echo '
3617
+	if (!empty($upcontext['continue'])) {
3618
+			echo '
3440 3619
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button_submit">';
3441
-	if (!empty($upcontext['skip']))
3442
-		echo '
3620
+	}
3621
+	if (!empty($upcontext['skip'])) {
3622
+			echo '
3443 3623
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button_submit">';
3624
+	}
3444 3625
 
3445 3626
 	echo '
3446 3627
 								</div>
@@ -3490,11 +3671,12 @@  discard block
 block discarded – undo
3490 3671
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3491 3672
 	<smf>';
3492 3673
 
3493
-	if (!empty($upcontext['get_data']))
3494
-		foreach ($upcontext['get_data'] as $k => $v)
3674
+	if (!empty($upcontext['get_data'])) {
3675
+			foreach ($upcontext['get_data'] as $k => $v)
3495 3676
 			echo '
3496 3677
 		<get key="', $k, '">', $v, '</get>';
3497
-}
3678
+	}
3679
+	}
3498 3680
 
3499 3681
 function template_xml_below()
3500 3682
 {
@@ -3535,8 +3717,8 @@  discard block
 block discarded – undo
3535 3717
 	template_chmod();
3536 3718
 
3537 3719
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3538
-	if ($upcontext['is_large_forum'])
3539
-		echo '
3720
+	if ($upcontext['is_large_forum']) {
3721
+			echo '
3540 3722
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3541 3723
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3542 3724
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3544,10 +3726,11 @@  discard block
 block discarded – undo
3544 3726
 				', $txt['upgrade_warning_lots_data'], '
3545 3727
 			</div>
3546 3728
 		</div>';
3729
+	}
3547 3730
 
3548 3731
 	// A warning message?
3549
-	if (!empty($upcontext['warning']))
3550
-		echo '
3732
+	if (!empty($upcontext['warning'])) {
3733
+			echo '
3551 3734
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3552 3735
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3553 3736
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3555,6 +3738,7 @@  discard block
 block discarded – undo
3555 3738
 				', $upcontext['warning'], '
3556 3739
 			</div>
3557 3740
 		</div>';
3741
+	}
3558 3742
 
3559 3743
 	// Paths are incorrect?
3560 3744
 	echo '
@@ -3570,20 +3754,22 @@  discard block
 block discarded – undo
3570 3754
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3571 3755
 	{
3572 3756
 		$ago = time() - $upcontext['started'];
3573
-		if ($ago < 60)
3574
-			$ago = $ago . ' seconds';
3575
-		elseif ($ago < 3600)
3576
-			$ago = (int) ($ago / 60) . ' minutes';
3577
-		else
3578
-			$ago = (int) ($ago / 3600) . ' hours';
3757
+		if ($ago < 60) {
3758
+					$ago = $ago . ' seconds';
3759
+		} elseif ($ago < 3600) {
3760
+					$ago = (int) ($ago / 60) . ' minutes';
3761
+		} else {
3762
+					$ago = (int) ($ago / 3600) . ' hours';
3763
+		}
3579 3764
 
3580 3765
 		$active = time() - $upcontext['updated'];
3581
-		if ($active < 60)
3582
-			$updated = $active . ' seconds';
3583
-		elseif ($active < 3600)
3584
-			$updated = (int) ($active / 60) . ' minutes';
3585
-		else
3586
-			$updated = (int) ($active / 3600) . ' hours';
3766
+		if ($active < 60) {
3767
+					$updated = $active . ' seconds';
3768
+		} elseif ($active < 3600) {
3769
+					$updated = (int) ($active / 60) . ' minutes';
3770
+		} else {
3771
+					$updated = (int) ($active / 3600) . ' hours';
3772
+		}
3587 3773
 
3588 3774
 		echo '
3589 3775
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3592,16 +3778,18 @@  discard block
 block discarded – undo
3592 3778
 			<div style="padding-left: 6ex;">
3593 3779
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3594 3780
 
3595
-		if ($active < 600)
3596
-			echo '
3781
+		if ($active < 600) {
3782
+					echo '
3597 3783
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3784
+		}
3598 3785
 
3599
-		if ($active > $upcontext['inactive_timeout'])
3600
-			echo '
3786
+		if ($active > $upcontext['inactive_timeout']) {
3787
+					echo '
3601 3788
 				<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.';
3602
-		else
3603
-			echo '
3789
+		} else {
3790
+					echo '
3604 3791
 				<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!');
3792
+		}
3605 3793
 
3606 3794
 		echo '
3607 3795
 			</div>
@@ -3617,9 +3805,10 @@  discard block
 block discarded – undo
3617 3805
 					<td>
3618 3806
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', ' class="input_text">';
3619 3807
 
3620
-	if (!empty($upcontext['username_incorrect']))
3621
-		echo '
3808
+	if (!empty($upcontext['username_incorrect'])) {
3809
+			echo '
3622 3810
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3811
+	}
3623 3812
 
3624 3813
 	echo '
3625 3814
 					</td>
@@ -3630,9 +3819,10 @@  discard block
 block discarded – undo
3630 3819
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', ' class="input_password">
3631 3820
 						<input type="hidden" name="hash_passwrd" value="">';
3632 3821
 
3633
-	if (!empty($upcontext['password_failed']))
3634
-		echo '
3822
+	if (!empty($upcontext['password_failed'])) {
3823
+			echo '
3635 3824
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3825
+	}
3636 3826
 
3637 3827
 	echo '
3638 3828
 					</td>
@@ -3703,8 +3893,8 @@  discard block
 block discarded – undo
3703 3893
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3704 3894
 
3705 3895
 	// Warning message?
3706
-	if (!empty($upcontext['upgrade_options_warning']))
3707
-		echo '
3896
+	if (!empty($upcontext['upgrade_options_warning'])) {
3897
+			echo '
3708 3898
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3709 3899
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3710 3900
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3712,6 +3902,7 @@  discard block
 block discarded – undo
3712 3902
 				', $upcontext['upgrade_options_warning'], '
3713 3903
 			</div>
3714 3904
 		</div>';
3905
+	}
3715 3906
 
3716 3907
 	echo '
3717 3908
 				<table>
@@ -3754,8 +3945,8 @@  discard block
 block discarded – undo
3754 3945
 						</td>
3755 3946
 					</tr>';
3756 3947
 
3757
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3758
-		echo '
3948
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3949
+			echo '
3759 3950
 					<tr valign="top">
3760 3951
 						<td width="2%">
3761 3952
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1" class="input_check">
@@ -3764,6 +3955,7 @@  discard block
 block discarded – undo
3764 3955
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3765 3956
 						</td>
3766 3957
 					</tr>';
3958
+	}
3767 3959
 
3768 3960
 	echo '
3769 3961
 					<tr valign="top">
@@ -3801,10 +3993,11 @@  discard block
 block discarded – undo
3801 3993
 			</div>';
3802 3994
 
3803 3995
 	// Dont any tables so far?
3804
-	if (!empty($upcontext['previous_tables']))
3805
-		foreach ($upcontext['previous_tables'] as $table)
3996
+	if (!empty($upcontext['previous_tables'])) {
3997
+			foreach ($upcontext['previous_tables'] as $table)
3806 3998
 			echo '
3807 3999
 			<br>Completed Table: &quot;', $table, '&quot;.';
4000
+	}
3808 4001
 
3809 4002
 	echo '
3810 4003
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3841,12 +4034,13 @@  discard block
 block discarded – undo
3841 4034
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3842 4035
 
3843 4036
 		// If debug flood the screen.
3844
-		if ($is_debug)
3845
-			echo '
4037
+		if ($is_debug) {
4038
+					echo '
3846 4039
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3847 4040
 
3848 4041
 				if (document.getElementById(\'debug_section\').scrollHeight)
3849 4042
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4043
+		}
3850 4044
 
3851 4045
 		echo '
3852 4046
 				// Get the next update...
@@ -3879,8 +4073,9 @@  discard block
 block discarded – undo
3879 4073
 {
3880 4074
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3881 4075
 
3882
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3883
-		$is_debug = true;
4076
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4077
+			$is_debug = true;
4078
+	}
3884 4079
 
3885 4080
 	echo '
3886 4081
 		<h3>Executing database changes</h3>
@@ -3895,8 +4090,9 @@  discard block
 block discarded – undo
3895 4090
 	{
3896 4091
 		foreach ($upcontext['actioned_items'] as $num => $item)
3897 4092
 		{
3898
-			if ($num != 0)
3899
-				echo ' Successful!';
4093
+			if ($num != 0) {
4094
+							echo ' Successful!';
4095
+			}
3900 4096
 			echo '<br>' . $item;
3901 4097
 		}
3902 4098
 		if (!empty($upcontext['changes_complete']))
@@ -3909,28 +4105,32 @@  discard block
 block discarded – undo
3909 4105
 				$seconds = intval($active % 60);
3910 4106
 
3911 4107
 				$totalTime = '';
3912
-				if ($hours > 0)
3913
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3914
-				if ($minutes > 0)
3915
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3916
-				if ($seconds > 0)
3917
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4108
+				if ($hours > 0) {
4109
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4110
+				}
4111
+				if ($minutes > 0) {
4112
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4113
+				}
4114
+				if ($seconds > 0) {
4115
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4116
+				}
3918 4117
 			}
3919 4118
 
3920
-			if ($is_debug && !empty($totalTime))
3921
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3922
-			else
3923
-				echo ' Successful!<br><br>';
4119
+			if ($is_debug && !empty($totalTime)) {
4120
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4121
+			} else {
4122
+							echo ' Successful!<br><br>';
4123
+			}
3924 4124
 
3925 4125
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3926 4126
 		}
3927
-	}
3928
-	else
4127
+	} else
3929 4128
 	{
3930 4129
 		// Tell them how many files we have in total.
3931
-		if ($upcontext['file_count'] > 1)
3932
-			echo '
4130
+		if ($upcontext['file_count'] > 1) {
4131
+					echo '
3933 4132
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4133
+		}
3934 4134
 
3935 4135
 		echo '
3936 4136
 		<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>
@@ -3946,19 +4146,23 @@  discard block
 block discarded – undo
3946 4146
 				$seconds = intval($active % 60);
3947 4147
 
3948 4148
 				$totalTime = '';
3949
-				if ($hours > 0)
3950
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3951
-				if ($minutes > 0)
3952
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3953
-				if ($seconds > 0)
3954
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4149
+				if ($hours > 0) {
4150
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4151
+				}
4152
+				if ($minutes > 0) {
4153
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4154
+				}
4155
+				if ($seconds > 0) {
4156
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4157
+				}
3955 4158
 			}
3956 4159
 
3957 4160
 			echo '
3958 4161
 			<br><span id="upgradeCompleted">';
3959 4162
 
3960
-			if (!empty($totalTime))
3961
-				echo 'Completed in ', $totalTime, '<br>';
4163
+			if (!empty($totalTime)) {
4164
+							echo 'Completed in ', $totalTime, '<br>';
4165
+			}
3962 4166
 
3963 4167
 			echo '</span>
3964 4168
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -3995,9 +4199,10 @@  discard block
 block discarded – undo
3995 4199
 			var getData = "";
3996 4200
 			var debugItems = ', $upcontext['debug_items'], ';';
3997 4201
 
3998
-		if ($is_debug)
3999
-			echo '
4202
+		if ($is_debug) {
4203
+					echo '
4000 4204
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4205
+		}
4001 4206
 
4002 4207
 		echo '
4003 4208
 			function getNextItem()
@@ -4037,9 +4242,10 @@  discard block
 block discarded – undo
4037 4242
 						document.getElementById("error_block").style.display = "";
4038 4243
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4039 4244
 
4040
-	if ($is_debug)
4041
-		echo '
4245
+	if ($is_debug) {
4246
+			echo '
4042 4247
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4248
+	}
4043 4249
 
4044 4250
 	echo '
4045 4251
 					}
@@ -4060,9 +4266,10 @@  discard block
 block discarded – undo
4060 4266
 						document.getElementById("error_block").style.display = "";
4061 4267
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4062 4268
 
4063
-	if ($is_debug)
4064
-		echo '
4269
+	if ($is_debug) {
4270
+			echo '
4065 4271
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4272
+	}
4066 4273
 
4067 4274
 	echo '
4068 4275
 					}
@@ -4121,8 +4328,8 @@  discard block
 block discarded – undo
4121 4328
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4122 4329
 				{';
4123 4330
 
4124
-		if ($is_debug)
4125
-			echo '
4331
+		if ($is_debug) {
4332
+					echo '
4126 4333
 					document.getElementById(\'debug_section\').style.display = "none";
4127 4334
 
4128 4335
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4140,6 +4347,7 @@  discard block
 block discarded – undo
4140 4347
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4141 4348
 
4142 4349
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4350
+		}
4143 4351
 
4144 4352
 		echo '
4145 4353
 
@@ -4147,9 +4355,10 @@  discard block
 block discarded – undo
4147 4355
 					document.getElementById(\'contbutt\').disabled = 0;
4148 4356
 					document.getElementById(\'database_done\').value = 1;';
4149 4357
 
4150
-		if ($upcontext['file_count'] > 1)
4151
-			echo '
4358
+		if ($upcontext['file_count'] > 1) {
4359
+					echo '
4152 4360
 					document.getElementById(\'info1\').style.display = "none";';
4361
+		}
4153 4362
 
4154 4363
 		echo '
4155 4364
 					document.getElementById(\'info2\').style.display = "none";
@@ -4162,9 +4371,10 @@  discard block
 block discarded – undo
4162 4371
 					lastItem = 0;
4163 4372
 					prevFile = curFile;';
4164 4373
 
4165
-		if ($is_debug)
4166
-			echo '
4374
+		if ($is_debug) {
4375
+					echo '
4167 4376
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4377
+		}
4168 4378
 
4169 4379
 		echo '
4170 4380
 					getNextItem();
@@ -4172,8 +4382,8 @@  discard block
 block discarded – undo
4172 4382
 				}';
4173 4383
 
4174 4384
 		// If debug scroll the screen.
4175
-		if ($is_debug)
4176
-			echo '
4385
+		if ($is_debug) {
4386
+					echo '
4177 4387
 				if (iLastSubStepProgress == -1)
4178 4388
 				{
4179 4389
 					// Give it consistent dots.
@@ -4192,6 +4402,7 @@  discard block
 block discarded – undo
4192 4402
 
4193 4403
 				if (document.getElementById(\'debug_section\').scrollHeight)
4194 4404
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4405
+		}
4195 4406
 
4196 4407
 		echo '
4197 4408
 				// Update the page.
@@ -4252,9 +4463,10 @@  discard block
 block discarded – undo
4252 4463
 			}';
4253 4464
 
4254 4465
 		// Start things off assuming we've not errored.
4255
-		if (empty($upcontext['error_message']))
4256
-			echo '
4466
+		if (empty($upcontext['error_message'])) {
4467
+					echo '
4257 4468
 			getNextItem();';
4469
+		}
4258 4470
 
4259 4471
 		echo '
4260 4472
 		//# sourceURL=dynamicScript-dbch.js
@@ -4272,18 +4484,21 @@  discard block
 block discarded – undo
4272 4484
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4273 4485
 	<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>';
4274 4486
 
4275
-	if (!empty($upcontext['error_message']))
4276
-		echo '
4487
+	if (!empty($upcontext['error_message'])) {
4488
+			echo '
4277 4489
 	<error>', $upcontext['error_message'], '</error>';
4490
+	}
4278 4491
 
4279
-	if (!empty($upcontext['error_string']))
4280
-		echo '
4492
+	if (!empty($upcontext['error_string'])) {
4493
+			echo '
4281 4494
 	<sql>', $upcontext['error_string'], '</sql>';
4495
+	}
4282 4496
 
4283
-	if ($is_debug)
4284
-		echo '
4497
+	if ($is_debug) {
4498
+			echo '
4285 4499
 	<curtime>', time(), '</curtime>';
4286
-}
4500
+	}
4501
+	}
4287 4502
 
4288 4503
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4289 4504
 function template_convert_utf8()
@@ -4302,18 +4517,20 @@  discard block
 block discarded – undo
4302 4517
 			</div>';
4303 4518
 
4304 4519
 	// Done any tables so far?
4305
-	if (!empty($upcontext['previous_tables']))
4306
-		foreach ($upcontext['previous_tables'] as $table)
4520
+	if (!empty($upcontext['previous_tables'])) {
4521
+			foreach ($upcontext['previous_tables'] as $table)
4307 4522
 			echo '
4308 4523
 			<br>Completed Table: &quot;', $table, '&quot;.';
4524
+	}
4309 4525
 
4310 4526
 	echo '
4311 4527
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4312 4528
 
4313 4529
 	// If we dropped their index, let's let them know
4314
-	if ($upcontext['dropping_index'])
4315
-		echo '
4530
+	if ($upcontext['dropping_index']) {
4531
+			echo '
4316 4532
 				<br><span id="indexmsg" style="font-weight: bold; font-style: italic; display: ', $upcontext['cur_table_num'] == $upcontext['table_count'] ? 'inline' : 'none', ';">Please note that your fulltext index was dropped to facilitate the conversion and will need to be recreated in the admin area after the upgrade is complete.</span>';
4533
+	}
4317 4534
 
4318 4535
 	// Completion notification
4319 4536
 	echo '
@@ -4350,12 +4567,13 @@  discard block
 block discarded – undo
4350 4567
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4351 4568
 
4352 4569
 		// If debug flood the screen.
4353
-		if ($is_debug)
4354
-			echo '
4570
+		if ($is_debug) {
4571
+					echo '
4355 4572
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4356 4573
 
4357 4574
 				if (document.getElementById(\'debug_section\').scrollHeight)
4358 4575
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4576
+		}
4359 4577
 
4360 4578
 		echo '
4361 4579
 				// Get the next update...
@@ -4403,19 +4621,21 @@  discard block
 block discarded – undo
4403 4621
 			</div>';
4404 4622
 
4405 4623
 	// Dont any tables so far?
4406
-	if (!empty($upcontext['previous_tables']))
4407
-		foreach ($upcontext['previous_tables'] as $table)
4624
+	if (!empty($upcontext['previous_tables'])) {
4625
+			foreach ($upcontext['previous_tables'] as $table)
4408 4626
 			echo '
4409 4627
 			<br>Completed Table: &quot;', $table, '&quot;.';
4628
+	}
4410 4629
 
4411 4630
 	echo '
4412 4631
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4413 4632
 			<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 4633
 
4415 4634
 	// Try to make sure substep was reset.
4416
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4417
-		echo '
4635
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4636
+			echo '
4418 4637
 			<input type="hidden" name="substep" id="substep" value="0">';
4638
+	}
4419 4639
 
4420 4640
 	// Continue please!
4421 4641
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4448,12 +4668,13 @@  discard block
 block discarded – undo
4448 4668
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4449 4669
 
4450 4670
 		// If debug flood the screen.
4451
-		if ($is_debug)
4452
-			echo '
4671
+		if ($is_debug) {
4672
+					echo '
4453 4673
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4454 4674
 
4455 4675
 				if (document.getElementById(\'debug_section\').scrollHeight)
4456 4676
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4677
+		}
4457 4678
 
4458 4679
 		echo '
4459 4680
 				// Get the next update...
@@ -4489,8 +4710,8 @@  discard block
 block discarded – undo
4489 4710
 	<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 4711
 	<form action="', $boardurl, '/index.php">';
4491 4712
 
4492
-	if (!empty($upcontext['can_delete_script']))
4493
-		echo '
4713
+	if (!empty($upcontext['can_delete_script'])) {
4714
+			echo '
4494 4715
 			<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 4716
 			<script>
4496 4717
 				function doTheDelete(theCheck)
@@ -4502,6 +4723,7 @@  discard block
 block discarded – undo
4502 4723
 				}
4503 4724
 			</script>
4504 4725
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4726
+	}
4505 4727
 
4506 4728
 	$active = time() - $upcontext['started'];
4507 4729
 	$hours = floor($active / 3600);
@@ -4511,16 +4733,20 @@  discard block
 block discarded – undo
4511 4733
 	if ($is_debug)
4512 4734
 	{
4513 4735
 		$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' : '') . ' ';
4736
+		if ($hours > 0) {
4737
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4738
+		}
4739
+		if ($minutes > 0) {
4740
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4741
+		}
4742
+		if ($seconds > 0) {
4743
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4744
+		}
4520 4745
 	}
4521 4746
 
4522
-	if ($is_debug && !empty($totalTime))
4523
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4747
+	if ($is_debug && !empty($totalTime)) {
4748
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4749
+	}
4524 4750
 
4525 4751
 	echo '<br>
4526 4752
 			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 +4773,9 @@  discard block
 block discarded – undo
4547 4773
 
4548 4774
 	$current_substep = $_GET['substep'];
4549 4775
 
4550
-	if (empty($_GET['a']))
4551
-		$_GET['a'] = 0;
4776
+	if (empty($_GET['a'])) {
4777
+			$_GET['a'] = 0;
4778
+	}
4552 4779
 	$step_progress['name'] = 'Converting ips';
4553 4780
 	$step_progress['current'] = $_GET['a'];
4554 4781
 
@@ -4591,16 +4818,19 @@  discard block
 block discarded – undo
4591 4818
 				'empty' => '',
4592 4819
 				'limit' => $limit,
4593 4820
 		));
4594
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4595
-			$arIp[] = $row[$oldCol];
4821
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4822
+					$arIp[] = $row[$oldCol];
4823
+		}
4596 4824
 		$smcFunc['db_free_result']($request);
4597 4825
 
4598 4826
 		// Special case, null ip could keep us in a loop.
4599
-		if (is_null($arIp[0]))
4600
-			unset($arIp[0]);
4827
+		if (is_null($arIp[0])) {
4828
+					unset($arIp[0]);
4829
+		}
4601 4830
 
4602
-		if (empty($arIp))
4603
-			$is_done = true;
4831
+		if (empty($arIp)) {
4832
+					$is_done = true;
4833
+		}
4604 4834
 
4605 4835
 		$updates = array();
4606 4836
 		$cases = array();
@@ -4609,16 +4839,18 @@  discard block
 block discarded – undo
4609 4839
 		{
4610 4840
 			$arIp[$i] = trim($arIp[$i]);
4611 4841
 
4612
-			if (empty($arIp[$i]))
4613
-				continue;
4842
+			if (empty($arIp[$i])) {
4843
+							continue;
4844
+			}
4614 4845
 
4615 4846
 			$updates['ip' . $i] = $arIp[$i];
4616 4847
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4617 4848
 
4618 4849
 			if ($setSize > 0 && $i % $setSize === 0)
4619 4850
 			{
4620
-				if (count($updates) == 1)
4621
-					continue;
4851
+				if (count($updates) == 1) {
4852
+									continue;
4853
+				}
4622 4854
 
4623 4855
 				$updates['whereSet'] = array_values($updates);
4624 4856
 				$smcFunc['db_query']('', '
@@ -4652,8 +4884,7 @@  discard block
 block discarded – undo
4652 4884
 							'ip' => $ip
4653 4885
 					));
4654 4886
 				}
4655
-			}
4656
-			else
4887
+			} else
4657 4888
 			{
4658 4889
 				$updates['whereSet'] = array_values($updates);
4659 4890
 				$smcFunc['db_query']('', '
@@ -4667,9 +4898,9 @@  discard block
 block discarded – undo
4667 4898
 					$updates
4668 4899
 				);
4669 4900
 			}
4901
+		} else {
4902
+					$is_done = true;
4670 4903
 		}
4671
-		else
4672
-			$is_done = true;
4673 4904
 
4674 4905
 		$_GET['a'] += $limit;
4675 4906
 		$step_progress['current'] = $_GET['a'];
@@ -4695,10 +4926,11 @@  discard block
 block discarded – undo
4695 4926
 
4696 4927
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4697 4928
 
4698
-	if (isset($columns[$column]))
4699
-		return $columns[$column];
4700
-	else
4701
-		return null;
4702
-}
4929
+	if (isset($columns[$column])) {
4930
+			return $columns[$column];
4931
+	} else {
4932
+			return null;
4933
+	}
4934
+	}
4703 4935
 
4704 4936
 ?>
4705 4937
\ No newline at end of file
Please login to merge, or discard this patch.
other/install.php 1 patch
Braces   +438 added lines, -326 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;">
21 21
 
22 22
 // Let's pull in useful classes
23
-if (!defined('SMF'))
23
+if (!defined('SMF')) {
24 24
 	define('SMF', 1);
25
+}
25 26
 
26 27
 require_once('Sources/Class-Package.php');
27 28
 
@@ -63,10 +64,11 @@  discard block
 block discarded – undo
63 64
 
64 65
 			list ($charcode) = pg_fetch_row($request);
65 66
 
66
-			if ($charcode == 'UTF8')
67
-				return true;
68
-			else
69
-				return false;
67
+			if ($charcode == 'UTF8') {
68
+							return true;
69
+			} else {
70
+							return false;
71
+			}
70 72
 		},
71 73
 		'utf8_version' => '8.0',
72 74
 		'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;',
@@ -76,12 +78,14 @@  discard block
 block discarded – undo
76 78
 			$value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value);
77 79
 
78 80
 			// Is it reserved?
79
-			if ($value == 'pg_')
80
-				return $txt['error_db_prefix_reserved'];
81
+			if ($value == 'pg_') {
82
+							return $txt['error_db_prefix_reserved'];
83
+			}
81 84
 
82 85
 			// Is the prefix numeric?
83
-			if (preg_match('~^\d~', $value))
84
-				return $txt['error_db_prefix_numeric'];
86
+			if (preg_match('~^\d~', $value)) {
87
+							return $txt['error_db_prefix_numeric'];
88
+			}
85 89
 
86 90
 			return true;
87 91
 		},
@@ -128,10 +132,11 @@  discard block
 block discarded – undo
128 132
 		$incontext['skip'] = false;
129 133
 
130 134
 		// Call the step and if it returns false that means pause!
131
-		if (function_exists($step[2]) && $step[2]() === false)
132
-			break;
133
-		elseif (function_exists($step[2]))
134
-			$incontext['current_step']++;
135
+		if (function_exists($step[2]) && $step[2]() === false) {
136
+					break;
137
+		} elseif (function_exists($step[2])) {
138
+					$incontext['current_step']++;
139
+		}
135 140
 
136 141
 		// No warnings pass on.
137 142
 		$incontext['warning'] = '';
@@ -147,8 +152,9 @@  discard block
 block discarded – undo
147 152
 	global $databases;
148 153
 
149 154
 	// Just so people using older versions of PHP aren't left in the cold.
150
-	if (!isset($_SERVER['PHP_SELF']))
151
-		$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
155
+	if (!isset($_SERVER['PHP_SELF'])) {
156
+			$_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php';
157
+	}
152 158
 
153 159
 	// Enable error reporting.
154 160
 	error_reporting(E_ALL);
@@ -164,21 +170,23 @@  discard block
 block discarded – undo
164 170
 	{
165 171
 		ob_start();
166 172
 
167
-		if (ini_get('session.save_handler') == 'user')
168
-			@ini_set('session.save_handler', 'files');
169
-		if (function_exists('session_start'))
170
-			@session_start();
171
-	}
172
-	else
173
+		if (ini_get('session.save_handler') == 'user') {
174
+					@ini_set('session.save_handler', 'files');
175
+		}
176
+		if (function_exists('session_start')) {
177
+					@session_start();
178
+		}
179
+	} else
173 180
 	{
174 181
 		ob_start('ob_gzhandler');
175 182
 
176
-		if (ini_get('session.save_handler') == 'user')
177
-			@ini_set('session.save_handler', 'files');
183
+		if (ini_get('session.save_handler') == 'user') {
184
+					@ini_set('session.save_handler', 'files');
185
+		}
178 186
 		session_start();
179 187
 
180
-		if (!headers_sent())
181
-			echo '<!DOCTYPE html>
188
+		if (!headers_sent()) {
189
+					echo '<!DOCTYPE html>
182 190
 <html>
183 191
 	<head>
184 192
 		<title>', htmlspecialchars($_GET['pass_string']), '</title>
@@ -187,14 +195,16 @@  discard block
 block discarded – undo
187 195
 		<strong>', htmlspecialchars($_GET['pass_string']), '</strong>
188 196
 	</body>
189 197
 </html>';
198
+		}
190 199
 		exit;
191 200
 	}
192 201
 
193 202
 	// Add slashes, as long as they aren't already being added.
194
-	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0)
195
-		foreach ($_POST as $k => $v)
203
+	if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) {
204
+			foreach ($_POST as $k => $v)
196 205
 			if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false)
197 206
 				$_POST[$k] = addslashes($v);
207
+	}
198 208
 
199 209
 	// This is really quite simple; if ?delete is on the URL, delete the installer...
200 210
 	if (isset($_GET['delete']))
@@ -215,8 +225,7 @@  discard block
 block discarded – undo
215 225
 			$ftp->close();
216 226
 
217 227
 			unset($_SESSION['installer_temp_ftp']);
218
-		}
219
-		else
228
+		} else
220 229
 		{
221 230
 			@unlink(__FILE__);
222 231
 
@@ -237,10 +246,11 @@  discard block
 block discarded – undo
237 246
 	{
238 247
 		// Get PHP's default timezone, if set
239 248
 		$ini_tz = ini_get('date.timezone');
240
-		if (!empty($ini_tz))
241
-			$timezone_id = $ini_tz;
242
-		else
243
-			$timezone_id = '';
249
+		if (!empty($ini_tz)) {
250
+					$timezone_id = $ini_tz;
251
+		} else {
252
+					$timezone_id = '';
253
+		}
244 254
 
245 255
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
246 256
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -270,8 +280,9 @@  discard block
 block discarded – undo
270 280
 		$dir = dir(dirname(__FILE__) . '/Themes/default/languages');
271 281
 		while ($entry = $dir->read())
272 282
 		{
273
-			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php')
274
-				$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
283
+			if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') {
284
+							$incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12));
285
+			}
275 286
 		}
276 287
 		$dir->close();
277 288
 	}
@@ -306,10 +317,11 @@  discard block
 block discarded – undo
306 317
 	}
307 318
 
308 319
 	// Override the language file?
309
-	if (isset($_GET['lang_file']))
310
-		$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
311
-	elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file']))
312
-		$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
320
+	if (isset($_GET['lang_file'])) {
321
+			$_SESSION['installer_temp_lang'] = $_GET['lang_file'];
322
+	} elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) {
323
+			$_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file'];
324
+	}
313 325
 
314 326
 	// Make sure it exists, if it doesn't reset it.
315 327
 	if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang']))
@@ -318,8 +330,9 @@  discard block
 block discarded – undo
318 330
 		list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
319 331
 
320 332
 		// If we have english and some other language, use the other language.  We Americans hate english :P.
321
-		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1)
322
-			list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
333
+		if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) {
334
+					list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']);
335
+		}
323 336
 	}
324 337
 
325 338
 	// And now include the actual language file itself.
@@ -332,15 +345,18 @@  discard block
 block discarded – undo
332 345
 	global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings;
333 346
 	global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist;
334 347
 
335
-	if (empty($sourcedir))
336
-		$sourcedir = dirname(__FILE__) . '/Sources';
348
+	if (empty($sourcedir)) {
349
+			$sourcedir = dirname(__FILE__) . '/Sources';
350
+	}
337 351
 
338 352
 	// Need this to check whether we need the database password.
339 353
 	require(dirname(__FILE__) . '/Settings.php');
340
-	if (!defined('SMF'))
341
-		define('SMF', 1);
342
-	if (empty($smcFunc))
343
-		$smcFunc = array();
354
+	if (!defined('SMF')) {
355
+			define('SMF', 1);
356
+	}
357
+	if (empty($smcFunc)) {
358
+			$smcFunc = array();
359
+	}
344 360
 
345 361
 	$modSettings['disableQueryCheck'] = true;
346 362
 
@@ -348,8 +364,9 @@  discard block
 block discarded – undo
348 364
 	if (!$db_connection)
349 365
 	{
350 366
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
351
-		if (version_compare(PHP_VERSION, '5', '<'))
352
-			require_once($sourcedir . '/Subs-Compat.php');
367
+		if (version_compare(PHP_VERSION, '5', '<')) {
368
+					require_once($sourcedir . '/Subs-Compat.php');
369
+		}
353 370
 
354 371
 		$db_options = array('persist' => $db_persist);
355 372
 		$port = '';
@@ -360,19 +377,20 @@  discard block
 block discarded – undo
360 377
 			if ($db_type == 'mysql')
361 378
 			{
362 379
 				$port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port'];
363
-			}
364
-			elseif ($db_type == 'postgresql')
380
+			} elseif ($db_type == 'postgresql')
365 381
 			{
366 382
 				// PostgreSQL doesn't have a default port setting in php.ini, so just check against the default
367 383
 				$port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port'];
368 384
 			}
369 385
 		}
370 386
 
371
-		if (!empty($port))
372
-			$db_options['port'] = $port;
387
+		if (!empty($port)) {
388
+					$db_options['port'] = $port;
389
+		}
373 390
 
374
-		if (!$db_connection)
375
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
391
+		if (!$db_connection) {
392
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options);
393
+		}
376 394
 	}
377 395
 }
378 396
 
@@ -400,8 +418,9 @@  discard block
 block discarded – undo
400 418
 		// @todo REMOVE THIS!!
401 419
 		else
402 420
 		{
403
-			if (function_exists('doStep' . $_GET['step']))
404
-				call_user_func('doStep' . $_GET['step']);
421
+			if (function_exists('doStep' . $_GET['step'])) {
422
+							call_user_func('doStep' . $_GET['step']);
423
+			}
405 424
 		}
406 425
 		// Show the footer.
407 426
 		template_install_below();
@@ -419,8 +438,9 @@  discard block
 block discarded – undo
419 438
 	$incontext['sub_template'] = 'welcome_message';
420 439
 
421 440
 	// Done the submission?
422
-	if (isset($_POST['contbutt']))
423
-		return true;
441
+	if (isset($_POST['contbutt'])) {
442
+			return true;
443
+	}
424 444
 
425 445
 	// See if we think they have already installed it?
426 446
 	if (is_readable(dirname(__FILE__) . '/Settings.php'))
@@ -428,14 +448,17 @@  discard block
 block discarded – undo
428 448
 		$probably_installed = 0;
429 449
 		foreach (file(dirname(__FILE__) . '/Settings.php') as $line)
430 450
 		{
431
-			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line))
432
-				$probably_installed++;
433
-			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line))
434
-				$probably_installed++;
451
+			if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) {
452
+							$probably_installed++;
453
+			}
454
+			if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) {
455
+							$probably_installed++;
456
+			}
435 457
 		}
436 458
 
437
-		if ($probably_installed == 2)
438
-			$incontext['warning'] = $txt['error_already_installed'];
459
+		if ($probably_installed == 2) {
460
+					$incontext['warning'] = $txt['error_already_installed'];
461
+		}
439 462
 	}
440 463
 
441 464
 	// Is some database support even compiled in?
@@ -450,36 +473,43 @@  discard block
 block discarded – undo
450 473
 				$databases[$key]['supported'] = false;
451 474
 				$notFoundSQLFile = true;
452 475
 				$txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql');
476
+			} else {
477
+							$incontext['supported_databases'][] = $db;
453 478
 			}
454
-			else
455
-				$incontext['supported_databases'][] = $db;
456 479
 		}
457 480
 	}
458 481
 
459 482
 	// Check the PHP version.
460
-	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>')))
461
-		$error = 'error_php_too_low';
483
+	if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) {
484
+			$error = 'error_php_too_low';
485
+	}
462 486
 	// Make sure we have a supported database
463
-	elseif (empty($incontext['supported_databases']))
464
-		$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
487
+	elseif (empty($incontext['supported_databases'])) {
488
+			$error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing';
489
+	}
465 490
 	// How about session support?  Some crazy sysadmin remove it?
466
-	elseif (!function_exists('session_start'))
467
-		$error = 'error_session_missing';
491
+	elseif (!function_exists('session_start')) {
492
+			$error = 'error_session_missing';
493
+	}
468 494
 	// Make sure they uploaded all the files.
469
-	elseif (!file_exists(dirname(__FILE__) . '/index.php'))
470
-		$error = 'error_missing_files';
495
+	elseif (!file_exists(dirname(__FILE__) . '/index.php')) {
496
+			$error = 'error_missing_files';
497
+	}
471 498
 	// Very simple check on the session.save_path for Windows.
472 499
 	// @todo Move this down later if they don't use database-driven sessions?
473
-	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\')
474
-		$error = 'error_session_save_path';
500
+	elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') {
501
+			$error = 'error_session_save_path';
502
+	}
475 503
 
476 504
 	// Since each of the three messages would look the same, anyway...
477
-	if (isset($error))
478
-		$incontext['error'] = $txt[$error];
505
+	if (isset($error)) {
506
+			$incontext['error'] = $txt[$error];
507
+	}
479 508
 
480 509
 	// Mod_security blocks everything that smells funny. Let SMF handle security.
481
-	if (!fixModSecurity() && !isset($_GET['overmodsecurity']))
482
-		$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
510
+	if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) {
511
+			$incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again'];
512
+	}
483 513
 
484 514
 	return false;
485 515
 }
@@ -505,12 +535,14 @@  discard block
 block discarded – undo
505 535
 		'db_last_error.php',
506 536
 	);
507 537
 
508
-	foreach ($incontext['detected_languages'] as $lang => $temp)
509
-		$extra_files[] = 'Themes/default/languages/' . $lang;
538
+	foreach ($incontext['detected_languages'] as $lang => $temp) {
539
+			$extra_files[] = 'Themes/default/languages/' . $lang;
540
+	}
510 541
 
511 542
 	// With mod_security installed, we could attempt to fix it with .htaccess.
512
-	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules()))
513
-		$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
543
+	if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) {
544
+			$writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.';
545
+	}
514 546
 
515 547
 	$failed_files = array();
516 548
 
@@ -526,12 +558,14 @@  discard block
 block discarded – undo
526 558
 				@chmod(dirname(__FILE__) . '/' . $file, 0755);
527 559
 
528 560
 				// Well, 755 hopefully worked... if not, try 777.
529
-				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777))
530
-					$failed_files[] = $file;
561
+				if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) {
562
+									$failed_files[] = $file;
563
+				}
531 564
 			}
532 565
 		}
533
-		foreach ($extra_files as $file)
534
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
566
+		foreach ($extra_files as $file) {
567
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
568
+		}
535 569
 	}
536 570
 	// Windows is trickier.  Let's try opening for r+...
537 571
 	else
@@ -541,30 +575,35 @@  discard block
 block discarded – undo
541 575
 		foreach ($writable_files as $file)
542 576
 		{
543 577
 			// Folders can't be opened for write... but the index.php in them can ;)
544
-			if (is_dir(dirname(__FILE__) . '/' . $file))
545
-				$file .= '/index.php';
578
+			if (is_dir(dirname(__FILE__) . '/' . $file)) {
579
+							$file .= '/index.php';
580
+			}
546 581
 
547 582
 			// Funny enough, chmod actually does do something on windows - it removes the read only attribute.
548 583
 			@chmod(dirname(__FILE__) . '/' . $file, 0777);
549 584
 			$fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+');
550 585
 
551 586
 			// Hmm, okay, try just for write in that case...
552
-			if (!is_resource($fp))
553
-				$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
587
+			if (!is_resource($fp)) {
588
+							$fp = @fopen(dirname(__FILE__) . '/' . $file, 'w');
589
+			}
554 590
 
555
-			if (!is_resource($fp))
556
-				$failed_files[] = $file;
591
+			if (!is_resource($fp)) {
592
+							$failed_files[] = $file;
593
+			}
557 594
 
558 595
 			@fclose($fp);
559 596
 		}
560
-		foreach ($extra_files as $file)
561
-			@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
597
+		foreach ($extra_files as $file) {
598
+					@chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777);
599
+		}
562 600
 	}
563 601
 
564 602
 	$failure = count($failed_files) >= 1;
565 603
 
566
-	if (!isset($_SERVER))
567
-		return !$failure;
604
+	if (!isset($_SERVER)) {
605
+			return !$failure;
606
+	}
568 607
 
569 608
 	// Put the list into context.
570 609
 	$incontext['failed_files'] = $failed_files;
@@ -612,19 +651,23 @@  discard block
 block discarded – undo
612 651
 
613 652
 		if (!isset($ftp) || $ftp->error !== false)
614 653
 		{
615
-			if (!isset($ftp))
616
-				$ftp = new ftp_connection(null);
654
+			if (!isset($ftp)) {
655
+							$ftp = new ftp_connection(null);
656
+			}
617 657
 			// Save the error so we can mess with listing...
618
-			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message))
619
-				$incontext['ftp_errors'][] = $ftp->last_message;
658
+			elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) {
659
+							$incontext['ftp_errors'][] = $ftp->last_message;
660
+			}
620 661
 
621 662
 			list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__));
622 663
 
623
-			if (empty($_POST['ftp_path']) && $found_path)
624
-				$_POST['ftp_path'] = $detect_path;
664
+			if (empty($_POST['ftp_path']) && $found_path) {
665
+							$_POST['ftp_path'] = $detect_path;
666
+			}
625 667
 
626
-			if (!isset($_POST['ftp_username']))
627
-				$_POST['ftp_username'] = $username;
668
+			if (!isset($_POST['ftp_username'])) {
669
+							$_POST['ftp_username'] = $username;
670
+			}
628 671
 
629 672
 			// Set the username etc, into context.
630 673
 			$incontext['ftp'] = array(
@@ -636,8 +679,7 @@  discard block
 block discarded – undo
636 679
 			);
637 680
 
638 681
 			return false;
639
-		}
640
-		else
682
+		} else
641 683
 		{
642 684
 			$_SESSION['installer_temp_ftp'] = array(
643 685
 				'server' => $_POST['ftp_server'],
@@ -651,10 +693,12 @@  discard block
 block discarded – undo
651 693
 
652 694
 			foreach ($failed_files as $file)
653 695
 			{
654
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
655
-					$ftp->chmod($file, 0755);
656
-				if (!is_writable(dirname(__FILE__) . '/' . $file))
657
-					$ftp->chmod($file, 0777);
696
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
697
+									$ftp->chmod($file, 0755);
698
+				}
699
+				if (!is_writable(dirname(__FILE__) . '/' . $file)) {
700
+									$ftp->chmod($file, 0777);
701
+				}
658 702
 				if (!is_writable(dirname(__FILE__) . '/' . $file))
659 703
 				{
660 704
 					$failed_files_updated[] = $file;
@@ -710,15 +754,17 @@  discard block
 block discarded – undo
710 754
 
711 755
 			if (!$foundOne)
712 756
 			{
713
-				if (isset($db['default_host']))
714
-					$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
757
+				if (isset($db['default_host'])) {
758
+									$incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost';
759
+				}
715 760
 				if (isset($db['default_user']))
716 761
 				{
717 762
 					$incontext['db']['user'] = ini_get($db['default_user']);
718 763
 					$incontext['db']['name'] = ini_get($db['default_user']);
719 764
 				}
720
-				if (isset($db['default_password']))
721
-					$incontext['db']['pass'] = ini_get($db['default_password']);
765
+				if (isset($db['default_password'])) {
766
+									$incontext['db']['pass'] = ini_get($db['default_password']);
767
+				}
722 768
 
723 769
 				// For simplicity and less confusion, leave the port blank by default
724 770
 				$incontext['db']['port'] = '';
@@ -737,10 +783,10 @@  discard block
 block discarded – undo
737 783
 		$incontext['db']['server'] = $_POST['db_server'];
738 784
 		$incontext['db']['prefix'] = $_POST['db_prefix'];
739 785
 
740
-		if (!empty($_POST['db_port']))
741
-			$incontext['db']['port'] = $_POST['db_port'];
742
-	}
743
-	else
786
+		if (!empty($_POST['db_port'])) {
787
+					$incontext['db']['port'] = $_POST['db_port'];
788
+		}
789
+	} else
744 790
 	{
745 791
 		$incontext['db']['prefix'] = 'smf_';
746 792
 	}
@@ -776,10 +822,11 @@  discard block
 block discarded – undo
776 822
 		if (!empty($_POST['db_port']))
777 823
 		{
778 824
 			// For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though.
779
-			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port'))
780
-				$vars['db_port'] = (int) $_POST['db_port'];
781
-			elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432)
782
-				$vars['db_port'] = (int) $_POST['db_port'];
825
+			if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) {
826
+							$vars['db_port'] = (int) $_POST['db_port'];
827
+			} elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) {
828
+							$vars['db_port'] = (int) $_POST['db_port'];
829
+			}
783 830
 		}
784 831
 
785 832
 		// God I hope it saved!
@@ -792,8 +839,9 @@  discard block
 block discarded – undo
792 839
 		// Make sure it works.
793 840
 		require(dirname(__FILE__) . '/Settings.php');
794 841
 
795
-		if (empty($sourcedir))
796
-			$sourcedir = dirname(__FILE__) . '/Sources';
842
+		if (empty($sourcedir)) {
843
+					$sourcedir = dirname(__FILE__) . '/Sources';
844
+		}
797 845
 
798 846
 		// Better find the database file!
799 847
 		if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php'))
@@ -803,18 +851,21 @@  discard block
 block discarded – undo
803 851
 		}
804 852
 
805 853
 		// Now include it for database functions!
806
-		if (!defined('SMF'))
807
-			define('SMF', 1);
854
+		if (!defined('SMF')) {
855
+					define('SMF', 1);
856
+		}
808 857
 
809 858
 		$modSettings['disableQueryCheck'] = true;
810
-		if (empty($smcFunc))
811
-			$smcFunc = array();
859
+		if (empty($smcFunc)) {
860
+					$smcFunc = array();
861
+		}
812 862
 
813 863
 			require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
814 864
 
815 865
 		// What - running PHP4? The shame!
816
-		if (version_compare(PHP_VERSION, '5', '<'))
817
-			require_once($sourcedir . '/Subs-Compat.php');
866
+		if (version_compare(PHP_VERSION, '5', '<')) {
867
+					require_once($sourcedir . '/Subs-Compat.php');
868
+		}
818 869
 
819 870
 		// Attempt a connection.
820 871
 		$needsDB = !empty($databases[$db_type]['always_has_db']);
@@ -902,12 +953,14 @@  discard block
 block discarded – undo
902 953
 	$incontext['page_title'] = $txt['install_settings'];
903 954
 
904 955
 	// Let's see if we got the database type correct.
905
-	if (isset($_POST['db_type'], $databases[$_POST['db_type']]))
906
-		$db_type = $_POST['db_type'];
956
+	if (isset($_POST['db_type'], $databases[$_POST['db_type']])) {
957
+			$db_type = $_POST['db_type'];
958
+	}
907 959
 
908 960
 	// Else we'd better be able to get the connection.
909
-	else
910
-		load_database();
961
+	else {
962
+			load_database();
963
+	}
911 964
 
912 965
 	$db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type;
913 966
 
@@ -927,12 +980,14 @@  discard block
 block discarded – undo
927 980
 	// Submitting?
928 981
 	if (isset($_POST['boardurl']))
929 982
 	{
930
-		if (substr($_POST['boardurl'], -10) == '/index.php')
931
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
932
-		elseif (substr($_POST['boardurl'], -1) == '/')
933
-			$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
934
-		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://')
935
-			$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
983
+		if (substr($_POST['boardurl'], -10) == '/index.php') {
984
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -10);
985
+		} elseif (substr($_POST['boardurl'], -1) == '/') {
986
+					$_POST['boardurl'] = substr($_POST['boardurl'], 0, -1);
987
+		}
988
+		if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') {
989
+					$_POST['boardurl'] = 'http://' . $_POST['boardurl'];
990
+		}
936 991
 
937 992
 		// Save these variables.
938 993
 		$vars = array(
@@ -971,10 +1026,10 @@  discard block
 block discarded – undo
971 1026
 			{
972 1027
 				$incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']);
973 1028
 				return false;
974
-			}
975
-			else
976
-				// Set the character set here.
1029
+			} else {
1030
+							// Set the character set here.
977 1031
 				updateSettingsFile(array('db_character_set' => 'utf8'));
1032
+			}
978 1033
 		}
979 1034
 
980 1035
 		// Good, skip on.
@@ -994,8 +1049,9 @@  discard block
 block discarded – undo
994 1049
 	$incontext['continue'] = 1;
995 1050
 
996 1051
 	// Already done?
997
-	if (isset($_POST['pop_done']))
998
-		return true;
1052
+	if (isset($_POST['pop_done'])) {
1053
+			return true;
1054
+	}
999 1055
 
1000 1056
 	// Reload settings.
1001 1057
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1013,8 +1069,9 @@  discard block
 block discarded – undo
1013 1069
 	$modSettings = array();
1014 1070
 	if ($result !== false)
1015 1071
 	{
1016
-		while ($row = $smcFunc['db_fetch_assoc']($result))
1017
-			$modSettings[$row['variable']] = $row['value'];
1072
+		while ($row = $smcFunc['db_fetch_assoc']($result)) {
1073
+					$modSettings[$row['variable']] = $row['value'];
1074
+		}
1018 1075
 		$smcFunc['db_free_result']($result);
1019 1076
 
1020 1077
 		// Do they match?  If so, this is just a refresh so charge on!
@@ -1027,20 +1084,22 @@  discard block
 block discarded – undo
1027 1084
 	$modSettings['disableQueryCheck'] = true;
1028 1085
 
1029 1086
 	// If doing UTF8, select it. PostgreSQL requires passing it as a string...
1030
-	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support']))
1031
-		$smcFunc['db_query']('', '
1087
+	if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) {
1088
+			$smcFunc['db_query']('', '
1032 1089
 			SET NAMES {string:utf8}',
1033 1090
 			array(
1034 1091
 				'db_error_skip' => true,
1035 1092
 				'utf8' => 'utf8',
1036 1093
 			)
1037 1094
 		);
1095
+	}
1038 1096
 
1039 1097
 	// Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments...
1040
-	if (substr(__DIR__, -1) == '\\')
1041
-		$attachdir = __DIR__ . 'attachments';
1042
-	else
1043
-		$attachdir = __DIR__ . '/attachments';
1098
+	if (substr(__DIR__, -1) == '\\') {
1099
+			$attachdir = __DIR__ . 'attachments';
1100
+	} else {
1101
+			$attachdir = __DIR__ . '/attachments';
1102
+	}
1044 1103
 
1045 1104
 	$replaces = array(
1046 1105
 		'{$db_prefix}' => $db_prefix,
@@ -1057,8 +1116,9 @@  discard block
 block discarded – undo
1057 1116
 
1058 1117
 	foreach ($txt as $key => $value)
1059 1118
 	{
1060
-		if (substr($key, 0, 8) == 'default_')
1061
-			$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1119
+		if (substr($key, 0, 8) == 'default_') {
1120
+					$replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value);
1121
+		}
1062 1122
 	}
1063 1123
 	$replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n'));
1064 1124
 
@@ -1073,8 +1133,9 @@  discard block
 block discarded – undo
1073 1133
 
1074 1134
 		while ($row = $smcFunc['db_fetch_assoc']($get_engines))
1075 1135
 		{
1076
-			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT')
1077
-				$engines[] = $row['Engine'];
1136
+			if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') {
1137
+							$engines[] = $row['Engine'];
1138
+			}
1078 1139
 		}
1079 1140
 
1080 1141
 		// Done with this now
@@ -1098,8 +1159,7 @@  discard block
 block discarded – undo
1098 1159
 			$replaces['START TRANSACTION;'] = '';
1099 1160
 			$replaces['COMMIT;'] = '';
1100 1161
 		}
1101
-	}
1102
-	else
1162
+	} else
1103 1163
 	{
1104 1164
 		$has_innodb = false;
1105 1165
 	}
@@ -1121,21 +1181,24 @@  discard block
 block discarded – undo
1121 1181
 	foreach ($sql_lines as $count => $line)
1122 1182
 	{
1123 1183
 		// No comments allowed!
1124
-		if (substr(trim($line), 0, 1) != '#')
1125
-			$current_statement .= "\n" . rtrim($line);
1184
+		if (substr(trim($line), 0, 1) != '#') {
1185
+					$current_statement .= "\n" . rtrim($line);
1186
+		}
1126 1187
 
1127 1188
 		// Is this the end of the query string?
1128
-		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines)))
1129
-			continue;
1189
+		if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) {
1190
+					continue;
1191
+		}
1130 1192
 
1131 1193
 		// Does this table already exist?  If so, don't insert more data into it!
1132 1194
 		if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists))
1133 1195
 		{
1134 1196
 			preg_match_all('~\)[,;]~', $current_statement, $matches);
1135
-			if (!empty($matches[0]))
1136
-				$incontext['sql_results']['insert_dups'] += count($matches[0]);
1137
-			else
1138
-				$incontext['sql_results']['insert_dups']++;
1197
+			if (!empty($matches[0])) {
1198
+							$incontext['sql_results']['insert_dups'] += count($matches[0]);
1199
+			} else {
1200
+							$incontext['sql_results']['insert_dups']++;
1201
+			}
1139 1202
 
1140 1203
 			$current_statement = '';
1141 1204
 			continue;
@@ -1144,8 +1207,9 @@  discard block
 block discarded – undo
1144 1207
 		if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false)
1145 1208
 		{
1146 1209
 			// Use the appropriate function based on the DB type
1147
-			if ($db_type == 'mysql' || $db_type == 'mysqli')
1148
-				$db_errorno = $db_type . '_errno';
1210
+			if ($db_type == 'mysql' || $db_type == 'mysqli') {
1211
+							$db_errorno = $db_type . '_errno';
1212
+			}
1149 1213
 
1150 1214
 			// Error 1050: Table already exists!
1151 1215
 			// @todo Needs to be made better!
@@ -1160,18 +1224,18 @@  discard block
 block discarded – undo
1160 1224
 				// MySQLi requires a connection object. It's optional with MySQL and Postgres
1161 1225
 				$incontext['failures'][$count] = $smcFunc['db_error']($db_connection);
1162 1226
 			}
1163
-		}
1164
-		else
1227
+		} else
1165 1228
 		{
1166
-			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1167
-				$incontext['sql_results']['tables']++;
1168
-			elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1229
+			if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) {
1230
+							$incontext['sql_results']['tables']++;
1231
+			} elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1)
1169 1232
 			{
1170 1233
 				preg_match_all('~\)[,;]~', $current_statement, $matches);
1171
-				if (!empty($matches[0]))
1172
-					$incontext['sql_results']['inserts'] += count($matches[0]);
1173
-				else
1174
-					$incontext['sql_results']['inserts']++;
1234
+				if (!empty($matches[0])) {
1235
+									$incontext['sql_results']['inserts'] += count($matches[0]);
1236
+				} else {
1237
+									$incontext['sql_results']['inserts']++;
1238
+				}
1175 1239
 			}
1176 1240
 		}
1177 1241
 
@@ -1184,15 +1248,17 @@  discard block
 block discarded – undo
1184 1248
 	// Sort out the context for the SQL.
1185 1249
 	foreach ($incontext['sql_results'] as $key => $number)
1186 1250
 	{
1187
-		if ($number == 0)
1188
-			unset($incontext['sql_results'][$key]);
1189
-		else
1190
-			$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1251
+		if ($number == 0) {
1252
+					unset($incontext['sql_results'][$key]);
1253
+		} else {
1254
+					$incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number);
1255
+		}
1191 1256
 	}
1192 1257
 
1193 1258
 	// Make sure UTF will be used globally.
1194
-	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8'])))
1195
-		$newSettings[] = array('global_character_set', 'UTF-8');
1259
+	if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) {
1260
+			$newSettings[] = array('global_character_set', 'UTF-8');
1261
+	}
1196 1262
 
1197 1263
 	// Maybe we can auto-detect better cookie settings?
1198 1264
 	preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches);
@@ -1203,16 +1269,20 @@  discard block
 block discarded – undo
1203 1269
 		$globalCookies = false;
1204 1270
 
1205 1271
 		// Okay... let's see.  Using a subdomain other than www.? (not a perfect check.)
1206
-		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www'))))
1207
-			$globalCookies = true;
1272
+		if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) {
1273
+					$globalCookies = true;
1274
+		}
1208 1275
 		// If there's a / in the middle of the path, or it starts with ~... we want local.
1209
-		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false))
1210
-			$localCookies = true;
1276
+		if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) {
1277
+					$localCookies = true;
1278
+		}
1211 1279
 
1212
-		if ($globalCookies)
1213
-			$newSettings[] = array('globalCookies', '1');
1214
-		if ($localCookies)
1215
-			$newSettings[] = array('localCookies', '1');
1280
+		if ($globalCookies) {
1281
+					$newSettings[] = array('globalCookies', '1');
1282
+		}
1283
+		if ($localCookies) {
1284
+					$newSettings[] = array('localCookies', '1');
1285
+		}
1216 1286
 	}
1217 1287
 
1218 1288
 	// Are we allowing stat collection?
@@ -1230,16 +1300,17 @@  discard block
 block discarded – undo
1230 1300
 			fwrite($fp, $out);
1231 1301
 
1232 1302
 			$return_data = '';
1233
-			while (!feof($fp))
1234
-				$return_data .= fgets($fp, 128);
1303
+			while (!feof($fp)) {
1304
+							$return_data .= fgets($fp, 128);
1305
+			}
1235 1306
 
1236 1307
 			fclose($fp);
1237 1308
 
1238 1309
 			// Get the unique site ID.
1239 1310
 			preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
1240 1311
 
1241
-			if (!empty($ID[1]))
1242
-				$smcFunc['db_insert']('replace',
1312
+			if (!empty($ID[1])) {
1313
+							$smcFunc['db_insert']('replace',
1243 1314
 					$db_prefix . 'settings',
1244 1315
 					array('variable' => 'string', 'value' => 'string'),
1245 1316
 					array(
@@ -1248,11 +1319,12 @@  discard block
 block discarded – undo
1248 1319
 					),
1249 1320
 					array('variable')
1250 1321
 				);
1322
+			}
1251 1323
 		}
1252 1324
 	}
1253 1325
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1254
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1255
-		$smcFunc['db_query']('', '
1326
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1327
+			$smcFunc['db_query']('', '
1256 1328
 			DELETE FROM {db_prefix}settings
1257 1329
 			WHERE variable = {string:enable_sm_stats}',
1258 1330
 			array(
@@ -1260,20 +1332,23 @@  discard block
 block discarded – undo
1260 1332
 				'db_error_skip' => true,
1261 1333
 			)
1262 1334
 		);
1335
+	}
1263 1336
 
1264 1337
 	// Are we enabling SSL?
1265
-	if (!empty($_POST['force_ssl']))
1266
-		$newSettings[] = array('force_ssl', 2);
1338
+	if (!empty($_POST['force_ssl'])) {
1339
+			$newSettings[] = array('force_ssl', 2);
1340
+	}
1267 1341
 
1268 1342
 	// Setting a timezone is required.
1269 1343
 	if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set'))
1270 1344
 	{
1271 1345
 		// Get PHP's default timezone, if set
1272 1346
 		$ini_tz = ini_get('date.timezone');
1273
-		if (!empty($ini_tz))
1274
-			$timezone_id = $ini_tz;
1275
-		else
1276
-			$timezone_id = '';
1347
+		if (!empty($ini_tz)) {
1348
+					$timezone_id = $ini_tz;
1349
+		} else {
1350
+					$timezone_id = '';
1351
+		}
1277 1352
 
1278 1353
 		// If date.timezone is unset, invalid, or just plain weird, make a best guess
1279 1354
 		if (!in_array($timezone_id, timezone_identifiers_list()))
@@ -1282,8 +1357,9 @@  discard block
 block discarded – undo
1282 1357
 			$timezone_id = timezone_name_from_abbr('', $server_offset, 0);
1283 1358
 		}
1284 1359
 
1285
-		if (date_default_timezone_set($timezone_id))
1286
-			$newSettings[] = array('default_timezone', $timezone_id);
1360
+		if (date_default_timezone_set($timezone_id)) {
1361
+					$newSettings[] = array('default_timezone', $timezone_id);
1362
+		}
1287 1363
 	}
1288 1364
 
1289 1365
 	if (!empty($newSettings))
@@ -1314,16 +1390,18 @@  discard block
 block discarded – undo
1314 1390
 	}
1315 1391
 
1316 1392
 	// MySQL specific stuff
1317
-	if (substr($db_type, 0, 5) != 'mysql')
1318
-		return false;
1393
+	if (substr($db_type, 0, 5) != 'mysql') {
1394
+			return false;
1395
+	}
1319 1396
 
1320 1397
 	// Find database user privileges.
1321 1398
 	$privs = array();
1322 1399
 	$get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array());
1323 1400
 	while ($row = $smcFunc['db_fetch_assoc']($get_privs))
1324 1401
 	{
1325
-		if ($row['Privilege'] == 'Alter')
1326
-			$privs[] = $row['Privilege'];
1402
+		if ($row['Privilege'] == 'Alter') {
1403
+					$privs[] = $row['Privilege'];
1404
+		}
1327 1405
 	}
1328 1406
 	$smcFunc['db_free_result']($get_privs);
1329 1407
 
@@ -1353,8 +1431,9 @@  discard block
 block discarded – undo
1353 1431
 	$incontext['continue'] = 1;
1354 1432
 
1355 1433
 	// Skipping?
1356
-	if (!empty($_POST['skip']))
1357
-		return true;
1434
+	if (!empty($_POST['skip'])) {
1435
+			return true;
1436
+	}
1358 1437
 
1359 1438
 	// Need this to check whether we need the database password.
1360 1439
 	require(dirname(__FILE__) . '/Settings.php');
@@ -1367,18 +1446,22 @@  discard block
 block discarded – undo
1367 1446
 	// We need this to properly hash the password for Admin
1368 1447
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) {
1369 1448
 			global $sourcedir;
1370
-			if (function_exists('mb_strtolower'))
1371
-				return mb_strtolower($string, 'UTF-8');
1449
+			if (function_exists('mb_strtolower')) {
1450
+							return mb_strtolower($string, 'UTF-8');
1451
+			}
1372 1452
 			require_once($sourcedir . '/Subs-Charset.php');
1373 1453
 			return utf8_strtolower($string);
1374 1454
 		};
1375 1455
 
1376
-	if (!isset($_POST['username']))
1377
-		$_POST['username'] = '';
1378
-	if (!isset($_POST['email']))
1379
-		$_POST['email'] = '';
1380
-	if (!isset($_POST['server_email']))
1381
-		$_POST['server_email'] = '';
1456
+	if (!isset($_POST['username'])) {
1457
+			$_POST['username'] = '';
1458
+	}
1459
+	if (!isset($_POST['email'])) {
1460
+			$_POST['email'] = '';
1461
+	}
1462
+	if (!isset($_POST['server_email'])) {
1463
+			$_POST['server_email'] = '';
1464
+	}
1382 1465
 
1383 1466
 	$incontext['username'] = htmlspecialchars(stripslashes($_POST['username']));
1384 1467
 	$incontext['email'] = htmlspecialchars(stripslashes($_POST['email']));
@@ -1397,8 +1480,9 @@  discard block
 block discarded – undo
1397 1480
 			'admin_group' => 1,
1398 1481
 		)
1399 1482
 	);
1400
-	if ($smcFunc['db_num_rows']($request) != 0)
1401
-		$incontext['skip'] = 1;
1483
+	if ($smcFunc['db_num_rows']($request) != 0) {
1484
+			$incontext['skip'] = 1;
1485
+	}
1402 1486
 	$smcFunc['db_free_result']($request);
1403 1487
 
1404 1488
 	// Trying to create an account?
@@ -1429,8 +1513,9 @@  discard block
 block discarded – undo
1429 1513
 		}
1430 1514
 
1431 1515
 		// Update the webmaster's email?
1432
-		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]'))
1433
-			updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1516
+		if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) {
1517
+					updateSettingsFile(array('webmaster_email' => $_POST['server_email']));
1518
+		}
1434 1519
 
1435 1520
 		// Work out whether we're going to have dodgy characters and remove them.
1436 1521
 		$invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0;
@@ -1453,32 +1538,27 @@  discard block
 block discarded – undo
1453 1538
 			$smcFunc['db_free_result']($result);
1454 1539
 
1455 1540
 			$incontext['account_existed'] = $txt['error_user_settings_taken'];
1456
-		}
1457
-		elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1541
+		} elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25)
1458 1542
 		{
1459 1543
 			// Try the previous step again.
1460 1544
 			$incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long'];
1461 1545
 			return false;
1462
-		}
1463
-		elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1546
+		} elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false)
1464 1547
 		{
1465 1548
 			// Try the previous step again.
1466 1549
 			$incontext['error'] = $txt['error_invalid_characters_username'];
1467 1550
 			return false;
1468
-		}
1469
-		elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1551
+		} elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255)
1470 1552
 		{
1471 1553
 			// One step back, this time fill out a proper admin email address.
1472 1554
 			$incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']);
1473 1555
 			return false;
1474
-		}
1475
-		elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1556
+		} elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255)
1476 1557
 		{
1477 1558
 			// One step back, this time fill out a proper admin email address.
1478 1559
 			$incontext['error'] = $txt['error_valid_server_email_needed'];
1479 1560
 			return false;
1480
-		}
1481
-		elseif ($_POST['username'] != '')
1561
+		} elseif ($_POST['username'] != '')
1482 1562
 		{
1483 1563
 			$incontext['member_salt'] = substr(md5(mt_rand()), 0, 4);
1484 1564
 
@@ -1543,17 +1623,19 @@  discard block
 block discarded – undo
1543 1623
 	require_once($sourcedir . '/Subs-Auth.php');
1544 1624
 
1545 1625
 	// Bring a warning over.
1546
-	if (!empty($incontext['account_existed']))
1547
-		$incontext['warning'] = $incontext['account_existed'];
1626
+	if (!empty($incontext['account_existed'])) {
1627
+			$incontext['warning'] = $incontext['account_existed'];
1628
+	}
1548 1629
 
1549
-	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support']))
1550
-		$smcFunc['db_query']('', '
1630
+	if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
1631
+			$smcFunc['db_query']('', '
1551 1632
 			SET NAMES {string:db_character_set}',
1552 1633
 			array(
1553 1634
 				'db_character_set' => $db_character_set,
1554 1635
 				'db_error_skip' => true,
1555 1636
 			)
1556 1637
 		);
1638
+	}
1557 1639
 
1558 1640
 	// As track stats is by default enabled let's add some activity.
1559 1641
 	$smcFunc['db_insert']('ignore',
@@ -1574,14 +1656,16 @@  discard block
 block discarded – undo
1574 1656
 	// Only proceed if we can load the data.
1575 1657
 	if ($request)
1576 1658
 	{
1577
-		while ($row = $smcFunc['db_fetch_row']($request))
1578
-			$modSettings[$row[0]] = $row[1];
1659
+		while ($row = $smcFunc['db_fetch_row']($request)) {
1660
+					$modSettings[$row[0]] = $row[1];
1661
+		}
1579 1662
 		$smcFunc['db_free_result']($request);
1580 1663
 	}
1581 1664
 
1582 1665
 	// Automatically log them in ;)
1583
-	if (isset($incontext['member_id']) && isset($incontext['member_salt']))
1584
-		setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1666
+	if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
1667
+			setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt']));
1668
+	}
1585 1669
 
1586 1670
 	$result = $smcFunc['db_query']('', '
1587 1671
 		SELECT value
@@ -1592,13 +1676,14 @@  discard block
 block discarded – undo
1592 1676
 			'db_error_skip' => true,
1593 1677
 		)
1594 1678
 	);
1595
-	if ($smcFunc['db_num_rows']($result) != 0)
1596
-		list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1679
+	if ($smcFunc['db_num_rows']($result) != 0) {
1680
+			list ($db_sessions) = $smcFunc['db_fetch_row']($result);
1681
+	}
1597 1682
 	$smcFunc['db_free_result']($result);
1598 1683
 
1599
-	if (empty($db_sessions))
1600
-		$_SESSION['admin_time'] = time();
1601
-	else
1684
+	if (empty($db_sessions)) {
1685
+			$_SESSION['admin_time'] = time();
1686
+	} else
1602 1687
 	{
1603 1688
 		$_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
1604 1689
 
@@ -1622,8 +1707,9 @@  discard block
 block discarded – undo
1622 1707
 	$smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' :
1623 1708
 		function($string){
1624 1709
 			global $sourcedir;
1625
-			if (function_exists('mb_strtolower'))
1626
-				return mb_strtolower($string, 'UTF-8');
1710
+			if (function_exists('mb_strtolower')) {
1711
+							return mb_strtolower($string, 'UTF-8');
1712
+			}
1627 1713
 			require_once($sourcedir . '/Subs-Charset.php');
1628 1714
 			return utf8_strtolower($string);
1629 1715
 		};
@@ -1639,8 +1725,9 @@  discard block
 block discarded – undo
1639 1725
 		)
1640 1726
 	);
1641 1727
 	$context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8';
1642
-	if ($smcFunc['db_num_rows']($request) > 0)
1643
-		updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1728
+	if ($smcFunc['db_num_rows']($request) > 0) {
1729
+			updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
1730
+	}
1644 1731
 	$smcFunc['db_free_result']($request);
1645 1732
 
1646 1733
 	// Now is the perfect time to fetch the SM files.
@@ -1659,8 +1746,9 @@  discard block
 block discarded – undo
1659 1746
 
1660 1747
 	// Check if we need some stupid MySQL fix.
1661 1748
 	$server_version = $smcFunc['db_server_info']();
1662
-	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1663
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1749
+	if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1750
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1751
+	}
1664 1752
 
1665 1753
 	// Some final context for the template.
1666 1754
 	$incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
@@ -1680,8 +1768,9 @@  discard block
 block discarded – undo
1680 1768
 	$settingsArray = file(dirname(__FILE__) . '/Settings.php');
1681 1769
 
1682 1770
 	// @todo Do we just want to read the file in clean, and split it this way always?
1683
-	if (count($settingsArray) == 1)
1684
-		$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1771
+	if (count($settingsArray) == 1) {
1772
+			$settingsArray = preg_split('~[\r\n]~', $settingsArray[0]);
1773
+	}
1685 1774
 
1686 1775
 	for ($i = 0, $n = count($settingsArray); $i < $n; $i++)
1687 1776
 	{
@@ -1696,19 +1785,22 @@  discard block
 block discarded – undo
1696 1785
 			continue;
1697 1786
 		}
1698 1787
 
1699
-		if (trim($settingsArray[$i]) == '?' . '>')
1700
-			$settingsArray[$i] = '';
1788
+		if (trim($settingsArray[$i]) == '?' . '>') {
1789
+					$settingsArray[$i] = '';
1790
+		}
1701 1791
 
1702 1792
 		// Don't trim or bother with it if it's not a variable.
1703
-		if (substr($settingsArray[$i], 0, 1) != '$')
1704
-			continue;
1793
+		if (substr($settingsArray[$i], 0, 1) != '$') {
1794
+					continue;
1795
+		}
1705 1796
 
1706 1797
 		$settingsArray[$i] = rtrim($settingsArray[$i]) . "\n";
1707 1798
 
1708
-		foreach ($vars as $var => $val)
1709
-			if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1799
+		foreach ($vars as $var => $val) {
1800
+					if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0)
1710 1801
 			{
1711 1802
 				$comment = strstr($settingsArray[$i], '#');
1803
+		}
1712 1804
 				$settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n");
1713 1805
 				unset($vars[$var]);
1714 1806
 			}
@@ -1718,36 +1810,41 @@  discard block
 block discarded – undo
1718 1810
 	if (!empty($vars))
1719 1811
 	{
1720 1812
 		$settingsArray[$i++] = '';
1721
-		foreach ($vars as $var => $val)
1722
-			$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1813
+		foreach ($vars as $var => $val) {
1814
+					$settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n";
1815
+		}
1723 1816
 	}
1724 1817
 
1725 1818
 	// Blank out the file - done to fix a oddity with some servers.
1726 1819
 	$fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w');
1727
-	if (!$fp)
1728
-		return false;
1820
+	if (!$fp) {
1821
+			return false;
1822
+	}
1729 1823
 	fclose($fp);
1730 1824
 
1731 1825
 	$fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+');
1732 1826
 
1733 1827
 	// Gotta have one of these ;)
1734
-	if (trim($settingsArray[0]) != '<?php')
1735
-		fwrite($fp, "<?php\n");
1828
+	if (trim($settingsArray[0]) != '<?php') {
1829
+			fwrite($fp, "<?php\n");
1830
+	}
1736 1831
 
1737 1832
 	$lines = count($settingsArray);
1738 1833
 	for ($i = 0; $i < $lines - 1; $i++)
1739 1834
 	{
1740 1835
 		// Don't just write a bunch of blank lines.
1741
-		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '')
1742
-			fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1836
+		if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') {
1837
+					fwrite($fp, strtr($settingsArray[$i], "\r", ''));
1838
+		}
1743 1839
 	}
1744 1840
 	fwrite($fp, $settingsArray[$i] . '?' . '>');
1745 1841
 	fclose($fp);
1746 1842
 
1747 1843
 	// Even though on normal installations the filemtime should prevent this being used by the installer incorrectly
1748 1844
 	// it seems that there are times it might not. So let's MAKE it dump the cache.
1749
-	if (function_exists('opcache_invalidate'))
1750
-		opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1845
+	if (function_exists('opcache_invalidate')) {
1846
+			opcache_invalidate(dirname(__FILE__) . '/Settings.php', true);
1847
+	}
1751 1848
 
1752 1849
 	return true;
1753 1850
 }
@@ -1772,9 +1869,9 @@  discard block
 block discarded – undo
1772 1869
 	SecFilterScanPOST Off
1773 1870
 </IfModule>';
1774 1871
 
1775
-	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules()))
1776
-		return true;
1777
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1872
+	if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) {
1873
+			return true;
1874
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess'))
1778 1875
 	{
1779 1876
 		$current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess'));
1780 1877
 
@@ -1786,29 +1883,28 @@  discard block
 block discarded – undo
1786 1883
 				fwrite($ht_handle, $htaccess_addition);
1787 1884
 				fclose($ht_handle);
1788 1885
 				return true;
1886
+			} else {
1887
+							return false;
1789 1888
 			}
1790
-			else
1791
-				return false;
1889
+		} else {
1890
+					return true;
1792 1891
 		}
1793
-		else
1794
-			return true;
1795
-	}
1796
-	elseif (file_exists(dirname(__FILE__) . '/.htaccess'))
1797
-		return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1798
-	elseif (is_writable(dirname(__FILE__)))
1892
+	} elseif (file_exists(dirname(__FILE__) . '/.htaccess')) {
1893
+			return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false;
1894
+	} elseif (is_writable(dirname(__FILE__)))
1799 1895
 	{
1800 1896
 		if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w'))
1801 1897
 		{
1802 1898
 			fwrite($ht_handle, $htaccess_addition);
1803 1899
 			fclose($ht_handle);
1804 1900
 			return true;
1901
+		} else {
1902
+					return false;
1805 1903
 		}
1806
-		else
1904
+	} else {
1807 1905
 			return false;
1808 1906
 	}
1809
-	else
1810
-		return false;
1811
-}
1907
+	}
1812 1908
 
1813 1909
 function template_install_above()
1814 1910
 {
@@ -1846,9 +1942,10 @@  discard block
 block discarded – undo
1846 1942
 								<label for="installer_language">', $txt['installer_language'], ':</label>
1847 1943
 								<select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">';
1848 1944
 
1849
-		foreach ($incontext['detected_languages'] as $lang => $name)
1850
-			echo '
1945
+		foreach ($incontext['detected_languages'] as $lang => $name) {
1946
+					echo '
1851 1947
 									<option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>';
1948
+		}
1852 1949
 
1853 1950
 		echo '
1854 1951
 								</select>
@@ -1868,9 +1965,10 @@  discard block
 block discarded – undo
1868 1965
 						<h2>', $txt['upgrade_progress'], '</h2>
1869 1966
 						<ul>';
1870 1967
 
1871
-	foreach ($incontext['steps'] as $num => $step)
1872
-		echo '
1968
+	foreach ($incontext['steps'] as $num => $step) {
1969
+			echo '
1873 1970
 							<li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
1971
+	}
1874 1972
 
1875 1973
 	echo '
1876 1974
 						</ul>
@@ -1895,20 +1993,23 @@  discard block
 block discarded – undo
1895 1993
 		echo '
1896 1994
 								<div>';
1897 1995
 
1898
-		if (!empty($incontext['continue']))
1899
-			echo '
1996
+		if (!empty($incontext['continue'])) {
1997
+					echo '
1900 1998
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
1901
-		if (!empty($incontext['skip']))
1902
-			echo '
1999
+		}
2000
+		if (!empty($incontext['skip'])) {
2001
+					echo '
1903 2002
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />';
2003
+		}
1904 2004
 		echo '
1905 2005
 								</div>';
1906 2006
 	}
1907 2007
 
1908 2008
 	// Show the closing form tag and other data only if not in the last step
1909
-	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step'])
1910
-		echo '
2009
+	if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) {
2010
+			echo '
1911 2011
 							</form>';
2012
+	}
1912 2013
 
1913 2014
 	echo '
1914 2015
 						</div>
@@ -1943,13 +2044,15 @@  discard block
 block discarded – undo
1943 2044
 		</div>';
1944 2045
 
1945 2046
 	// Show the warnings, or not.
1946
-	if (template_warning_divs())
1947
-		echo '
2047
+	if (template_warning_divs()) {
2048
+			echo '
1948 2049
 		<h3>', $txt['install_all_lovely'], '</h3>';
2050
+	}
1949 2051
 
1950 2052
 	// Say we want the continue button!
1951
-	if (empty($incontext['error']))
1952
-		$incontext['continue'] = 1;
2053
+	if (empty($incontext['error'])) {
2054
+			$incontext['continue'] = 1;
2055
+	}
1953 2056
 
1954 2057
 	// For the latest version stuff.
1955 2058
 	echo '
@@ -1983,8 +2086,8 @@  discard block
 block discarded – undo
1983 2086
 	global $txt, $incontext;
1984 2087
 
1985 2088
 	// Errors are very serious..
1986
-	if (!empty($incontext['error']))
1987
-		echo '
2089
+	if (!empty($incontext['error'])) {
2090
+			echo '
1988 2091
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1989 2092
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
1990 2093
 			<strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br>
@@ -1992,9 +2095,10 @@  discard block
 block discarded – undo
1992 2095
 				', $incontext['error'], '
1993 2096
 			</div>
1994 2097
 		</div>';
2098
+	}
1995 2099
 	// A warning message?
1996
-	elseif (!empty($incontext['warning']))
1997
-		echo '
2100
+	elseif (!empty($incontext['warning'])) {
2101
+			echo '
1998 2102
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
1999 2103
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
2000 2104
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -2002,6 +2106,7 @@  discard block
 block discarded – undo
2002 2106
 				', $incontext['warning'], '
2003 2107
 			</div>
2004 2108
 		</div>';
2109
+	}
2005 2110
 
2006 2111
 	return empty($incontext['error']) && empty($incontext['warning']);
2007 2112
 }
@@ -2017,27 +2122,30 @@  discard block
 block discarded – undo
2017 2122
 			<li>', $incontext['failed_files']), '</li>
2018 2123
 		</ul>';
2019 2124
 
2020
-	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux')
2021
-		echo '
2125
+	if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') {
2126
+			echo '
2022 2127
 		<hr>
2023 2128
 		<p>', $txt['chmod_linux_info'], '</p>
2024 2129
 		<tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>';
2130
+	}
2025 2131
 
2026 2132
 	// This is serious!
2027
-	if (!template_warning_divs())
2028
-		return;
2133
+	if (!template_warning_divs()) {
2134
+			return;
2135
+	}
2029 2136
 
2030 2137
 	echo '
2031 2138
 		<hr>
2032 2139
 		<p>', $txt['ftp_setup_info'], '</p>';
2033 2140
 
2034
-	if (!empty($incontext['ftp_errors']))
2035
-		echo '
2141
+	if (!empty($incontext['ftp_errors'])) {
2142
+			echo '
2036 2143
 		<div class="error_message">
2037 2144
 			', $txt['error_ftp_no_connect'], '<br><br>
2038 2145
 			<code>', implode('<br>', $incontext['ftp_errors']), '</code>
2039 2146
 		</div>
2040 2147
 		<br>';
2148
+	}
2041 2149
 
2042 2150
 	echo '
2043 2151
 		<form action="', $incontext['form_url'], '" method="post">
@@ -2097,17 +2205,17 @@  discard block
 block discarded – undo
2097 2205
 				<td>
2098 2206
 					<select name="db_type" id="db_type_input" onchange="toggleDBInput();">';
2099 2207
 
2100
-	foreach ($incontext['supported_databases'] as $key => $db)
2101
-			echo '
2208
+	foreach ($incontext['supported_databases'] as $key => $db) {
2209
+				echo '
2102 2210
 						<option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>';
2211
+	}
2103 2212
 
2104 2213
 	echo '
2105 2214
 					</select>
2106 2215
 					<div class="smalltext block">', $txt['db_settings_type_info'], '</div>
2107 2216
 				</td>
2108 2217
 			</tr>';
2109
-	}
2110
-	else
2218
+	} else
2111 2219
 	{
2112 2220
 		echo '
2113 2221
 			<tr style="display: none;">
@@ -2299,9 +2407,10 @@  discard block
 block discarded – undo
2299 2407
 				<div style="color: red;">', $txt['error_db_queries'], '</div>
2300 2408
 				<ul>';
2301 2409
 
2302
-		foreach ($incontext['failures'] as $line => $fail)
2303
-			echo '
2410
+		foreach ($incontext['failures'] as $line => $fail) {
2411
+					echo '
2304 2412
 						<li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>';
2413
+		}
2305 2414
 
2306 2415
 		echo '
2307 2416
 				</ul>';
@@ -2362,15 +2471,16 @@  discard block
 block discarded – undo
2362 2471
 			</tr>
2363 2472
 		</table>';
2364 2473
 
2365
-	if ($incontext['require_db_confirm'])
2366
-		echo '
2474
+	if ($incontext['require_db_confirm']) {
2475
+			echo '
2367 2476
 		<h2>', $txt['user_settings_database'], '</h2>
2368 2477
 		<p>', $txt['user_settings_database_info'], '</p>
2369 2478
 
2370 2479
 		<div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;">
2371 2480
 			<input type="password" name="password3" size="30" class="input_password" />
2372 2481
 		</div>';
2373
-}
2482
+	}
2483
+	}
2374 2484
 
2375 2485
 // Tell them it's done, and to delete.
2376 2486
 function template_delete_install()
@@ -2383,14 +2493,15 @@  discard block
 block discarded – undo
2383 2493
 	template_warning_divs();
2384 2494
 
2385 2495
 	// Install directory still writable?
2386
-	if ($incontext['dir_still_writable'])
2387
-		echo '
2496
+	if ($incontext['dir_still_writable']) {
2497
+			echo '
2388 2498
 		<em>', $txt['still_writable'], '</em><br>
2389 2499
 		<br>';
2500
+	}
2390 2501
 
2391 2502
 	// Don't show the box if it's like 99% sure it won't work :P.
2392
-	if ($incontext['probably_delete_install'])
2393
-		echo '
2503
+	if ($incontext['probably_delete_install']) {
2504
+			echo '
2394 2505
 		<div style="margin: 1ex; font-weight: bold;">
2395 2506
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label>
2396 2507
 		</div>
@@ -2406,6 +2517,7 @@  discard block
 block discarded – undo
2406 2517
 			}
2407 2518
 		</script>
2408 2519
 		<br>';
2520
+	}
2409 2521
 
2410 2522
 	echo '
2411 2523
 		', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br>
Please login to merge, or discard this patch.