Completed
Push — release-2.1 ( 5f73de...e7eefc )
by Colin
07:52
created
Sources/Profile.php 1 patch
Braces   +155 added lines, -118 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * The main designating function for modifying profiles. Loads up info, determins what to do, etc.
@@ -29,18 +30,21 @@  discard block
 block discarded – undo
29 30
 	global $modSettings, $memberContext, $profile_vars, $post_errors, $smcFunc;
30 31
 
31 32
 	// Don't reload this as we may have processed error strings.
32
-	if (empty($post_errors))
33
-		loadLanguage('Profile+Drafts');
33
+	if (empty($post_errors)) {
34
+			loadLanguage('Profile+Drafts');
35
+	}
34 36
 	loadTemplate('Profile');
35 37
 
36 38
 	require_once($sourcedir . '/Subs-Menu.php');
37 39
 
38 40
 	// Did we get the user by name...
39
-	if (isset($_REQUEST['user']))
40
-		$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
41
+	if (isset($_REQUEST['user'])) {
42
+			$memberResult = loadMemberData($_REQUEST['user'], true, 'profile');
43
+	}
41 44
 	// ... or by id_member?
42
-	elseif (!empty($_REQUEST['u']))
43
-		$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
45
+	elseif (!empty($_REQUEST['u'])) {
46
+			$memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile');
47
+	}
44 48
 	// If it was just ?action=profile, edit your own profile, but only if you're not a guest.
45 49
 	else
46 50
 	{
@@ -50,8 +54,9 @@  discard block
 block discarded – undo
50 54
 	}
51 55
 
52 56
 	// Check if loadMemberData() has returned a valid result.
53
-	if (!$memberResult)
54
-		fatal_lang_error('not_a_user', false, 404);
57
+	if (!$memberResult) {
58
+			fatal_lang_error('not_a_user', false, 404);
59
+	}
55 60
 
56 61
 	// If all went well, we have a valid member ID!
57 62
 	list ($memID) = $memberResult;
@@ -67,8 +72,9 @@  discard block
 block discarded – undo
67 72
 
68 73
 	// Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission.
69 74
 	// And we care about what the current user can do, not what the user whose profile it is.
70
-	if ($user_info['mod_cache']['gq'] != '0=1')
71
-		$user_info['permissions'][] = 'approve_group_requests';
75
+	if ($user_info['mod_cache']['gq'] != '0=1') {
76
+			$user_info['permissions'][] = 'approve_group_requests';
77
+	}
72 78
 
73 79
 	// If paid subscriptions are enabled, make sure we actually have at least one subscription available...
74 80
 	$context['subs_available'] = false;
@@ -436,21 +442,25 @@  discard block
 block discarded – undo
436 442
 		foreach ($section['areas'] as $area_id => $area)
437 443
 		{
438 444
 			// If it said no permissions that meant it wasn't valid!
439
-			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any']))
440
-				$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
445
+			if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) {
446
+							$profile_areas[$section_id]['areas'][$area_id]['enabled'] = false;
447
+			}
441 448
 			// Otherwise pick the right set.
442
-			else
443
-				$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
449
+			else {
450
+							$profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any'];
451
+			}
444 452
 
445 453
 			// Password required in most cases
446
-			if (!empty($area['password']))
447
-				$context['password_areas'][] = $area_id;
454
+			if (!empty($area['password'])) {
455
+							$context['password_areas'][] = $area_id;
456
+			}
448 457
 		}
449 458
 	}
450 459
 
451 460
 	// Is there an updated message to show?
452
-	if (isset($_GET['updated']))
453
-		$context['profile_updated'] = $txt['profile_updated_own'];
461
+	if (isset($_GET['updated'])) {
462
+			$context['profile_updated'] = $txt['profile_updated_own'];
463
+	}
454 464
 
455 465
 	// Set a few options for the menu.
456 466
 	$menuOptions = array(
@@ -465,8 +475,9 @@  discard block
 block discarded – undo
465 475
 	$profile_include_data = createMenu($profile_areas, $menuOptions);
466 476
 
467 477
 	// No menu means no access.
468
-	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession()))
469
-		fatal_lang_error('no_access', false);
478
+	if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) {
479
+			fatal_lang_error('no_access', false);
480
+	}
470 481
 
471 482
 	// Make a note of the Unique ID for this menu.
472 483
 	$context['profile_menu_id'] = $context['max_menu_id'];
@@ -492,8 +503,9 @@  discard block
 block discarded – undo
492 503
 			if ($current_area == $area_id)
493 504
 			{
494 505
 				// This can't happen - but is a security check.
495
-				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false))
496
-					fatal_lang_error('no_access', false);
506
+				if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) {
507
+									fatal_lang_error('no_access', false);
508
+				}
497 509
 
498 510
 				// Are we saving data in a valid area?
499 511
 				if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview']))
@@ -512,12 +524,14 @@  discard block
 block discarded – undo
512 524
 				}
513 525
 
514 526
 				// Does this require session validating?
515
-				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner']))
516
-					$security_checks['validate'] = true;
527
+				if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) {
528
+									$security_checks['validate'] = true;
529
+				}
517 530
 
518 531
 				// Permissions for good measure.
519
-				if (!empty($profile_include_data['permission']))
520
-					$security_checks['permission'] = $profile_include_data['permission'];
532
+				if (!empty($profile_include_data['permission'])) {
533
+									$security_checks['permission'] = $profile_include_data['permission'];
534
+				}
521 535
 
522 536
 				// Either way got something.
523 537
 				$found_area = true;
@@ -526,21 +540,26 @@  discard block
 block discarded – undo
526 540
 	}
527 541
 
528 542
 	// Oh dear, some serious security lapse is going on here... we'll put a stop to that!
529
-	if (!$found_area)
530
-		fatal_lang_error('no_access', false);
543
+	if (!$found_area) {
544
+			fatal_lang_error('no_access', false);
545
+	}
531 546
 
532 547
 	// Release this now.
533 548
 	unset($profile_areas);
534 549
 
535 550
 	// Now the context is setup have we got any security checks to carry out additional to that above?
536
-	if (isset($security_checks['session']))
537
-		checkSession($security_checks['session']);
538
-	if (isset($security_checks['validate']))
539
-		validateSession();
540
-	if (isset($security_checks['validateToken']))
541
-		validateToken($token_name, $token_type);
542
-	if (isset($security_checks['permission']))
543
-		isAllowedTo($security_checks['permission']);
551
+	if (isset($security_checks['session'])) {
552
+			checkSession($security_checks['session']);
553
+	}
554
+	if (isset($security_checks['validate'])) {
555
+			validateSession();
556
+	}
557
+	if (isset($security_checks['validateToken'])) {
558
+			validateToken($token_name, $token_type);
559
+	}
560
+	if (isset($security_checks['permission'])) {
561
+			isAllowedTo($security_checks['permission']);
562
+	}
544 563
 
545 564
 	// Create a token if needed.
546 565
 	if (isset($security_checks['needsToken']) || isset($security_checks['validateToken']))
@@ -550,8 +569,9 @@  discard block
 block discarded – undo
550 569
 	}
551 570
 
552 571
 	// File to include?
553
-	if (isset($profile_include_data['file']))
554
-		require_once($sourcedir . '/' . $profile_include_data['file']);
572
+	if (isset($profile_include_data['file'])) {
573
+			require_once($sourcedir . '/' . $profile_include_data['file']);
574
+	}
555 575
 
556 576
 	// Build the link tree.
557 577
 	$context['linktree'][] = array(
@@ -559,17 +579,19 @@  discard block
 block discarded – undo
559 579
 		'name' => sprintf($txt['profile_of_username'], $context['member']['name']),
560 580
 	);
561 581
 
562
-	if (!empty($profile_include_data['label']))
563
-		$context['linktree'][] = array(
582
+	if (!empty($profile_include_data['label'])) {
583
+			$context['linktree'][] = array(
564 584
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'],
565 585
 			'name' => $profile_include_data['label'],
566 586
 		);
587
+	}
567 588
 
568
-	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label'])
569
-		$context['linktree'][] = array(
589
+	if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) {
590
+			$context['linktree'][] = array(
570 591
 			'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'],
571 592
 			'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0],
572 593
 		);
594
+	}
573 595
 
574 596
 	// Set the template for this area and add the profile layer.
575 597
 	$context['sub_template'] = $profile_include_data['function'];
@@ -595,12 +617,14 @@  discard block
 block discarded – undo
595 617
 		if ($check_password)
596 618
 		{
597 619
 			// Check to ensure we're forcing SSL for authentication
598
-			if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
599
-				fatal_lang_error('login_ssl_required');
620
+			if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
621
+							fatal_lang_error('login_ssl_required');
622
+			}
600 623
 
601 624
 			// You didn't even enter a password!
602
-			if (trim($_POST['oldpasswrd']) == '')
603
-				$post_errors[] = 'no_password';
625
+			if (trim($_POST['oldpasswrd']) == '') {
626
+							$post_errors[] = 'no_password';
627
+			}
604 628
 
605 629
 			// Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password
606 630
 			$_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']);
@@ -609,42 +633,43 @@  discard block
 block discarded – undo
609 633
 			$good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true);
610 634
 
611 635
 			// Bad password!!!
612
-			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd']))
613
-				$post_errors[] = 'bad_password';
636
+			if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) {
637
+							$post_errors[] = 'bad_password';
638
+			}
614 639
 
615 640
 			// Warn other elements not to jump the gun and do custom changes!
616
-			if (in_array('bad_password', $post_errors))
617
-				$context['password_auth_failed'] = true;
641
+			if (in_array('bad_password', $post_errors)) {
642
+							$context['password_auth_failed'] = true;
643
+			}
618 644
 		}
619 645
 
620 646
 		// Change the IP address in the database.
621
-		if ($context['user']['is_owner'])
622
-			$profile_vars['member_ip'] = $user_info['ip'];
647
+		if ($context['user']['is_owner']) {
648
+					$profile_vars['member_ip'] = $user_info['ip'];
649
+		}
623 650
 
624 651
 		// Now call the sub-action function...
625 652
 		if ($current_area == 'activateaccount')
626 653
 		{
627
-			if (empty($post_errors))
628
-				activateAccount($memID);
629
-		}
630
-		elseif ($current_area == 'deleteaccount')
654
+			if (empty($post_errors)) {
655
+							activateAccount($memID);
656
+			}
657
+		} elseif ($current_area == 'deleteaccount')
631 658
 		{
632 659
 			if (empty($post_errors))
633 660
 			{
634 661
 				deleteAccount2($memID);
635 662
 				redirectexit();
636 663
 			}
637
-		}
638
-		elseif ($current_area == 'groupmembership' && empty($post_errors))
664
+		} elseif ($current_area == 'groupmembership' && empty($post_errors))
639 665
 		{
640 666
 			$msg = groupMembership2($profile_vars, $post_errors, $memID);
641 667
 
642 668
 			// Whatever we've done, we have nothing else to do here...
643 669
 			redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=groupmembership' . (!empty($msg) ? ';msg=' . $msg : ''));
644
-		}
645
-		elseif (in_array($current_area, array('account', 'forumprofile', 'theme')))
646
-			saveProfileFields();
647
-		else
670
+		} elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) {
671
+					saveProfileFields();
672
+		} else
648 673
 		{
649 674
 			$force_redirect = true;
650 675
 			// Ensure we include this.
@@ -660,34 +685,36 @@  discard block
 block discarded – undo
660 685
 			// Load the language file so we can give a nice explanation of the errors.
661 686
 			loadLanguage('Errors');
662 687
 			$context['post_errors'] = $post_errors;
663
-		}
664
-		elseif (!empty($profile_vars))
688
+		} elseif (!empty($profile_vars))
665 689
 		{
666 690
 			// If we've changed the password, notify any integration that may be listening in.
667
-			if (isset($profile_vars['passwd']))
668
-				call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
691
+			if (isset($profile_vars['passwd'])) {
692
+							call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2']));
693
+			}
669 694
 
670 695
 			updateMemberData($memID, $profile_vars);
671 696
 
672 697
 			// What if this is the newest member?
673
-			if ($modSettings['latestMember'] == $memID)
674
-				updateStats('member');
675
-			elseif (isset($profile_vars['real_name']))
676
-				updateSettings(array('memberlist_updated' => time()));
698
+			if ($modSettings['latestMember'] == $memID) {
699
+							updateStats('member');
700
+			} elseif (isset($profile_vars['real_name'])) {
701
+							updateSettings(array('memberlist_updated' => time()));
702
+			}
677 703
 
678 704
 			// If the member changed his/her birthdate, update calendar statistics.
679
-			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name']))
680
-				updateSettings(array(
705
+			if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) {
706
+							updateSettings(array(
681 707
 					'calendar_updated' => time(),
682 708
 				));
709
+			}
683 710
 
684 711
 			// Anything worth logging?
685 712
 			if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled']))
686 713
 			{
687 714
 				$log_changes = array();
688 715
 				require_once($sourcedir . '/Logging.php');
689
-				foreach ($context['log_changes'] as $k => $v)
690
-					$log_changes[] = array(
716
+				foreach ($context['log_changes'] as $k => $v) {
717
+									$log_changes[] = array(
691 718
 						'action' => $k,
692 719
 						'log_type' => 'user',
693 720
 						'extra' => array_merge($v, array(
@@ -695,14 +722,16 @@  discard block
 block discarded – undo
695 722
 							'member_affected' => $memID,
696 723
 						)),
697 724
 					);
725
+				}
698 726
 
699 727
 				logActions($log_changes);
700 728
 			}
701 729
 
702 730
 			// Have we got any post save functions to execute?
703
-			if (!empty($context['profile_execute_on_save']))
704
-				foreach ($context['profile_execute_on_save'] as $saveFunc)
731
+			if (!empty($context['profile_execute_on_save'])) {
732
+							foreach ($context['profile_execute_on_save'] as $saveFunc)
705 733
 					$saveFunc();
734
+			}
706 735
 
707 736
 			// Let them know it worked!
708 737
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']);
@@ -716,27 +745,31 @@  discard block
 block discarded – undo
716 745
 	if (!empty($post_errors))
717 746
 	{
718 747
 		// Set all the errors so the template knows what went wrong.
719
-		foreach ($post_errors as $error_type)
720
-			$context['modify_error'][$error_type] = true;
748
+		foreach ($post_errors as $error_type) {
749
+					$context['modify_error'][$error_type] = true;
750
+		}
721 751
 	}
722 752
 	// If it's you then we should redirect upon save.
723
-	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview'])
724
-		redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
725
-	elseif (!empty($force_redirect))
726
-		redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
753
+	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) {
754
+			redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
755
+	} elseif (!empty($force_redirect)) {
756
+			redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
757
+	}
727 758
 
728 759
 
729 760
 	// Get the right callable.
730 761
 	$call = call_helper($profile_include_data['function'], true);
731 762
 
732 763
 	// Is it valid?
733
-	if (!empty($call))
734
-		call_user_func($call, $memID);
764
+	if (!empty($call)) {
765
+			call_user_func($call, $memID);
766
+	}
735 767
 
736 768
 	// Set the page title if it's not already set...
737
-	if (!isset($context['page_title']))
738
-		$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
739
-}
769
+	if (!isset($context['page_title'])) {
770
+			$context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : '');
771
+	}
772
+	}
740 773
 
741 774
 /**
742 775
  * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user.
@@ -859,16 +892,18 @@  discard block
 block discarded – undo
859 892
 	if (!allowedTo('admin_forum') && $area != 'register')
860 893
 	{
861 894
 		// If it's the owner they can see two types of private fields, regardless.
862
-		if ($memID == $user_info['id'])
863
-			$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
864
-		else
865
-			$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
895
+		if ($memID == $user_info['id']) {
896
+					$where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)';
897
+		} else {
898
+					$where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0';
899
+		}
866 900
 	}
867 901
 
868
-	if ($area == 'register')
869
-		$where .= ' AND show_reg != 0';
870
-	elseif ($area != 'summary')
871
-		$where .= ' AND show_profile = {string:area}';
902
+	if ($area == 'register') {
903
+			$where .= ' AND show_reg != 0';
904
+	} elseif ($area != 'summary') {
905
+			$where .= ' AND show_profile = {string:area}';
906
+	}
872 907
 
873 908
 	// Load all the relevant fields - and data.
874 909
 	$request = $smcFunc['db_query']('', '
@@ -894,13 +929,15 @@  discard block
 block discarded – undo
894 929
 		if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']]))
895 930
 		{
896 931
 			$value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]);
897
-			if (in_array($row['field_type'], array('select', 'radio')))
898
-					$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
932
+			if (in_array($row['field_type'], array('select', 'radio'))) {
933
+								$value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : '';
934
+			}
899 935
 		}
900 936
 
901 937
 		// Don't show the "disabled" option for the "gender" field if we are on the "summary" area.
902
-		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled')
903
-			continue;
938
+		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled') {
939
+					continue;
940
+		}
904 941
 
905 942
 		// HTML for the input form.
906 943
 		$output_html = $value;
@@ -909,8 +946,7 @@  discard block
 block discarded – undo
909 946
 			$true = (!$exists && $row['default_value']) || $value;
910 947
 			$input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . '>';
911 948
 			$output_html = $true ? $txt['yes'] : $txt['no'];
912
-		}
913
-		elseif ($row['field_type'] == 'select')
949
+		} elseif ($row['field_type'] == 'select')
914 950
 		{
915 951
 			$input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>';
916 952
 			$options = explode(',', $row['field_options']);
@@ -918,13 +954,13 @@  discard block
 block discarded – undo
918 954
 			{
919 955
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
920 956
 				$input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>';
921
-				if ($true)
922
-					$output_html = $v;
957
+				if ($true) {
958
+									$output_html = $v;
959
+				}
923 960
 			}
924 961
 
925 962
 			$input_html .= '</select>';
926
-		}
927
-		elseif ($row['field_type'] == 'radio')
963
+		} elseif ($row['field_type'] == 'radio')
928 964
 		{
929 965
 			$input_html = '<fieldset>';
930 966
 			$options = explode(',', $row['field_options']);
@@ -932,36 +968,37 @@  discard block
 block discarded – undo
932 968
 			{
933 969
 				$true = (!$exists && $row['default_value'] == $v) || $value == $v;
934 970
 				$input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '"' . ($true ? ' checked' : '') . '>' . $v . '</label><br>';
935
-				if ($true)
936
-					$output_html = $v;
971
+				if ($true) {
972
+									$output_html = $v;
973
+				}
937 974
 			}
938 975
 			$input_html .= '</fieldset>';
939
-		}
940
-		elseif ($row['field_type'] == 'text')
976
+		} elseif ($row['field_type'] == 'text')
941 977
 		{
942 978
 			$input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($row['field_length'] != 0 ? ' maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . un_htmlspecialchars($value) . '"' . ($row['show_reg'] == 2 ? ' required' : '') . '>';
943
-		}
944
-		else
979
+		} else
945 980
 		{
946 981
 			@list ($rows, $cols) = @explode(',', $row['default_value']);
947 982
 			$input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '') . '>' . un_htmlspecialchars($value) . '</textarea>';
948 983
 		}
949 984
 
950 985
 		// Parse BBCode
951
-		if ($row['bbc'])
952
-			$output_html = parse_bbc($output_html);
953
-		elseif ($row['field_type'] == 'textarea')
954
-			// Allow for newlines at least
986
+		if ($row['bbc']) {
987
+					$output_html = parse_bbc($output_html);
988
+		} elseif ($row['field_type'] == 'textarea') {
989
+					// Allow for newlines at least
955 990
 			$output_html = strtr($output_html, array("\n" => '<br>'));
991
+		}
956 992
 
957 993
 		// Enclosing the user input within some other text?
958
-		if (!empty($row['enclose']) && !empty($output_html))
959
-			$output_html = strtr($row['enclose'], array(
994
+		if (!empty($row['enclose']) && !empty($output_html)) {
995
+					$output_html = strtr($row['enclose'], array(
960 996
 				'{SCRIPTURL}' => $scripturl,
961 997
 				'{IMAGES_URL}' => $settings['images_url'],
962 998
 				'{DEFAULT_IMAGES_URL}' => $settings['default_images_url'],
963 999
 				'{INPUT}' => un_htmlspecialchars($output_html),
964 1000
 			));
1001
+		}
965 1002
 
966 1003
 		$context['custom_fields'][] = array(
967 1004
 			'name' => $row['field_name'],
Please login to merge, or discard this patch.
Sources/Subs-Menu.php 1 patch
Braces   +75 added lines, -57 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
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
  * Create a menu.
@@ -64,22 +65,26 @@  discard block
 block discarded – undo
64 65
 	$menu_context['current_action'] = isset($menuOptions['action']) ? $menuOptions['action'] : $context['current_action'];
65 66
 
66 67
 	// Allow extend *any* menu with a single hook
67
-	if (!empty($menu_context['current_action']))
68
-		call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
68
+	if (!empty($menu_context['current_action'])) {
69
+			call_integration_hook('integrate_' . $menu_context['current_action'] . '_areas', array(&$menuData));
70
+	}
69 71
 
70 72
 	// What is the current area selected?
71
-	if (isset($menuOptions['current_area']) || isset($_GET['area']))
72
-		$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
73
+	if (isset($menuOptions['current_area']) || isset($_GET['area'])) {
74
+			$menu_context['current_area'] = isset($menuOptions['current_area']) ? $menuOptions['current_area'] : $_GET['area'];
75
+	}
73 76
 
74 77
 	// Build a list of additional parameters that should go in the URL.
75 78
 	$menu_context['extra_parameters'] = '';
76
-	if (!empty($menuOptions['extra_url_parameters']))
77
-		foreach ($menuOptions['extra_url_parameters'] as $key => $value)
79
+	if (!empty($menuOptions['extra_url_parameters'])) {
80
+			foreach ($menuOptions['extra_url_parameters'] as $key => $value)
78 81
 			$menu_context['extra_parameters'] .= ';' . $key . '=' . $value;
82
+	}
79 83
 
80 84
 	// Only include the session ID in the URL if it's strictly necessary.
81
-	if (empty($menuOptions['disable_url_session_check']))
82
-		$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
85
+	if (empty($menuOptions['disable_url_session_check'])) {
86
+			$menu_context['extra_parameters'] .= ';' . $context['session_var'] . '=' . $context['session_id'];
87
+	}
83 88
 
84 89
 	$include_data = array();
85 90
 
@@ -87,8 +92,9 @@  discard block
 block discarded – undo
87 92
 	foreach ($menuData as $section_id => $section)
88 93
 	{
89 94
 		// Is this enabled - or has as permission check - which fails?
90
-		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission'])))
91
-			continue;
95
+		if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($section['permission']) && !allowedTo($section['permission']))) {
96
+					continue;
97
+		}
92 98
 
93 99
 		// Now we cycle through the sections to pick the right area.
94 100
 		foreach ($section['areas'] as $area_id => $area)
@@ -110,59 +116,57 @@  discard block
 block discarded – undo
110 116
 					if (empty($area['hidden']))
111 117
 					{
112 118
 						// First time this section?
113
-						if (!isset($menu_context['sections'][$section_id]))
114
-							$menu_context['sections'][$section_id]['title'] = $section['title'];
119
+						if (!isset($menu_context['sections'][$section_id])) {
120
+													$menu_context['sections'][$section_id]['title'] = $section['title'];
121
+						}
115 122
 
116 123
 						$menu_context['sections'][$section_id]['areas'][$area_id] = array('label' => isset($area['label']) ? $area['label'] : $txt[$area_id]);
117 124
 						// We'll need the ID as well...
118 125
 						$menu_context['sections'][$section_id]['id'] = $section_id;
119 126
 						// Does it have a custom URL?
120
-						if (isset($area['custom_url']))
121
-							$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
127
+						if (isset($area['custom_url'])) {
128
+													$menu_context['sections'][$section_id]['areas'][$area_id]['url'] = $area['custom_url'];
129
+						}
122 130
 
123 131
 						// Does this area have its own icon?
124 132
 						if (!isset($area['force_menu_into_arms_of_another_menu']) && $user_info['name'] == 'iamanoompaloompa')
125 133
 						{
126 134
 							$menu_context['sections'][$section_id]['areas'][$area_id] = $smcFunc['json_decode'](base64_decode('eyJsYWJlbCI6Ik9vbXBhIExvb21wYSIsInVybCI6Imh0dHBzOlwvXC9lbi53aWtpcGVkaWEub3JnXC93aWtpXC9Pb21wYV9Mb29tcGFzPyIsImljb24iOiI8aW1nIHNyYz1cImh0dHBzOlwvXC93d3cuc2ltcGxlbWFjaGluZXMub3JnXC9pbWFnZXNcL29vbXBhLmdpZlwiIGFsdD1cIkknbSBhbiBPb21wYSBMb29tcGFcIiBcLz4ifQ=='), true);
127
-						}
128
-						elseif (isset($area['icon']))
135
+						} elseif (isset($area['icon']))
129 136
 						{
130 137
 							if (file_exists($settings['theme_dir'] . '/images/admin/' . $area['icon']))
131 138
 							{
132 139
 								$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['images_url'] . '/admin/' . $area['icon'] . '" alt="">';
133
-							}
134
-							elseif (file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon']))
140
+							} elseif (file_exists($settings['default_theme_dir'] . '/images/admin/' . $area['icon']))
135 141
 							{
136 142
 								$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<img src="' . $settings['default_images_url'] . '/admin/' . $area['icon'] . '" alt="">';
143
+							} else {
144
+															$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
137 145
 							}
138
-							else
139
-								$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area['icon'] . '"></span>';
146
+						} else {
147
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
140 148
 						}
141
-						else
142
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon'] = '<span class="generic_icons ' . $area_id . '"></span>';
143 149
 
144 150
 						if (isset($area['icon_class']) && empty($menu_context['sections'][$section_id]['areas'][$area_id]['icon']))
145 151
 						{
146 152
 							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . $area['icon_class'];
147
-						}
148
-						elseif (isset($area['icon']))
153
+						} elseif (isset($area['icon']))
149 154
 						{
150 155
 							if (substr($area['icon'], -4) === '.png' || substr($area['icon'], -4) === '.gif')
151 156
 							{
152 157
 								if (file_exists($settings['theme_dir'] . '/images/admin/big/' . $area['icon']))
153 158
 								{
154 159
 									$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['theme_url'] . '/images/admin/big/' . $area['icon'];
155
-								}
156
-								elseif (file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
160
+								} elseif (file_exists($settings['default_theme_dir'] . '/images/admin/big/' . $area['icon']))
157 161
 								{
158 162
 									$menu_context['sections'][$section_id]['areas'][$area_id]['icon_file'] = $settings['default_theme_url'] . '/images/admin/big/' . $area['icon'];
159 163
 								}
160 164
 							}
161 165
 
162 166
 							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area['icon']);
167
+						} else {
168
+													$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
163 169
 						}
164
-						else
165
-							$menu_context['sections'][$section_id]['areas'][$area_id]['icon_class'] = $menu_context['current_action'] . '_menu_icon ' . str_replace(array('.png', '.gif'), '', $area_id);
166 170
 
167 171
 						// This is a shortcut for Font-Icon users so they don't have to re-do whole CSS.
168 172
 						$menu_context['sections'][$section_id]['areas'][$area_id]['plain_class'] = !empty($area['icon']) ? $area['icon'] : '';
@@ -179,35 +183,41 @@  discard block
 block discarded – undo
179 183
 							{
180 184
 								if ((empty($sub[1]) || allowedTo($sub[1])) && (!isset($sub['enabled']) || !empty($sub['enabled'])))
181 185
 								{
182
-									if ($first_sa == null)
183
-										$first_sa = $sa;
186
+									if ($first_sa == null) {
187
+																			$first_sa = $sa;
188
+									}
184 189
 
185 190
 									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa] = array('label' => $sub[0]);
186 191
 									// Custom URL?
187
-									if (isset($sub['url']))
188
-										$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
192
+									if (isset($sub['url'])) {
193
+																			$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['url'] = $sub['url'];
194
+									}
189 195
 
190 196
 									// A bit complicated - but is this set?
191 197
 									if ($menu_context['current_area'] == $area_id)
192 198
 									{
193 199
 										// Save which is the first...
194
-										if (empty($first_sa))
195
-											$first_sa = $sa;
200
+										if (empty($first_sa)) {
201
+																					$first_sa = $sa;
202
+										}
196 203
 
197 204
 										// Is this the current subsection?
198
-										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa)
199
-											$menu_context['current_subsection'] = $sa;
205
+										if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == $sa) {
206
+																					$menu_context['current_subsection'] = $sa;
207
+										}
200 208
 										// Otherwise is it the default?
201
-										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2]))
202
-											$menu_context['current_subsection'] = $sa;
209
+										elseif (!isset($menu_context['current_subsection']) && !empty($sub[2])) {
210
+																					$menu_context['current_subsection'] = $sa;
211
+										}
203 212
 									}
204 213
 
205 214
 									// Let's assume this is the last, for now.
206 215
 									$last_sa = $sa;
207 216
 								}
208 217
 								// Mark it as disabled...
209
-								else
210
-									$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
218
+								else {
219
+																	$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$sa]['disabled'] = true;
220
+								}
211 221
 							}
212 222
 
213 223
 							// Set which one is first, last and selected in the group.
@@ -216,8 +226,9 @@  discard block
 block discarded – undo
216 226
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $last_sa : $first_sa]['is_first'] = true;
217 227
 								$menu_context['sections'][$section_id]['areas'][$area_id]['subsections'][$context['right_to_left'] ? $first_sa : $last_sa]['is_last'] = true;
218 228
 
219
-								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection']))
220
-									$menu_context['current_subsection'] = $first_sa;
229
+								if ($menu_context['current_area'] == $area_id && !isset($menu_context['current_subsection'])) {
230
+																	$menu_context['current_subsection'] = $first_sa;
231
+								}
221 232
 							}
222 233
 						}
223 234
 					}
@@ -251,23 +262,26 @@  discard block
 block discarded – undo
251 262
 	$menu_context['base_url'] = isset($menuOptions['base_url']) ? $menuOptions['base_url'] : $scripturl . '?action=' . $menu_context['current_action'];
252 263
 
253 264
 	// If we didn't find the area we were looking for go to a default one.
254
-	if (isset($backup_area) && empty($found_section))
255
-		$menu_context['current_area'] = $backup_area;
265
+	if (isset($backup_area) && empty($found_section)) {
266
+			$menu_context['current_area'] = $backup_area;
267
+	}
256 268
 
257 269
 	// If there are sections quickly goes through all the sections to check if the base menu has an url
258 270
 	if (!empty($menu_context['current_section']))
259 271
 	{
260 272
 		$menu_context['sections'][$menu_context['current_section']]['selected'] = true;
261 273
 		$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['selected'] = true;
262
-		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]))
263
-			$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
274
+		if (!empty($menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']])) {
275
+					$menu_context['sections'][$menu_context['current_section']]['areas'][$menu_context['current_area']]['subsections'][$context['current_subaction']]['selected'] = true;
276
+		}
264 277
 
265
-		foreach ($menu_context['sections'] as $section_id => $section)
266
-			foreach ($section['areas'] as $area_id => $area)
278
+		foreach ($menu_context['sections'] as $section_id => $section) {
279
+					foreach ($section['areas'] as $area_id => $area)
267 280
 			{
268 281
 				if (!isset($menu_context['sections'][$section_id]['url']))
269 282
 				{
270 283
 					$menu_context['sections'][$section_id]['url'] = isset($area['url']) ? $area['url'] : $menu_context['base_url'] . ';area=' . $area_id;
284
+		}
271 285
 					break;
272 286
 				}
273 287
 			}
@@ -278,8 +292,9 @@  discard block
 block discarded – undo
278 292
 	{
279 293
 		// Never happened!
280 294
 		$context['max_menu_id']--;
281
-		if ($context['max_menu_id'] == 0)
282
-			unset($context['max_menu_id']);
295
+		if ($context['max_menu_id'] == 0) {
296
+					unset($context['max_menu_id']);
297
+		}
283 298
 
284 299
 		return false;
285 300
 	}
@@ -290,8 +305,9 @@  discard block
 block discarded – undo
290 305
 	$context['template_layers'][] = $menu_context['layer_name'];
291 306
 
292 307
 	// Check we had something - for sanity sake.
293
-	if (empty($include_data))
294
-		return false;
308
+	if (empty($include_data)) {
309
+			return false;
310
+	}
295 311
 
296 312
 	// Finally - return information on the selected item.
297 313
 	$include_data += array(
@@ -314,12 +330,14 @@  discard block
 block discarded – undo
314 330
 	global $context;
315 331
 
316 332
 	$menu_name = $menu_id == 'last' && isset($context['max_menu_id']) && isset($context['menu_data_' . $context['max_menu_id']]) ? 'menu_data_' . $context['max_menu_id'] : 'menu_data_' . $menu_id;
317
-	if (!isset($context[$menu_name]))
318
-		return false;
333
+	if (!isset($context[$menu_name])) {
334
+			return false;
335
+	}
319 336
 
320 337
 	$layer_index = array_search($context[$menu_name]['layer_name'], $context['template_layers']);
321
-	if ($layer_index !== false)
322
-		unset($context['template_layers'][$layer_index]);
338
+	if ($layer_index !== false) {
339
+			unset($context['template_layers'][$layer_index]);
340
+	}
323 341
 
324 342
 	unset($context[$menu_name]);
325 343
 }
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +158 added lines, -124 removed lines patch added patch discarded remove patch
@@ -14,8 +14,9 @@  discard block
 block discarded – undo
14 14
  * @version 2.1 Beta 4
15 15
  */
16 16
 
17
-if (!defined('SMF'))
17
+if (!defined('SMF')) {
18 18
 	die('No direct access...');
19
+}
19 20
 
20 21
 /**
21 22
  * Ask them for their login information. (shows a page for the user to type
@@ -29,8 +30,9 @@  discard block
 block discarded – undo
29 30
 	global $txt, $context, $scripturl, $user_info;
30 31
 
31 32
 	// You are already logged in, go take a tour of the boards
32
-	if (!empty($user_info['id']))
33
-		redirectexit();
33
+	if (!empty($user_info['id'])) {
34
+			redirectexit();
35
+	}
34 36
 
35 37
 	// We need to load the Login template/language file.
36 38
 	loadLanguage('Login');
@@ -57,10 +59,11 @@  discard block
 block discarded – undo
57 59
 	);
58 60
 
59 61
 	// Set the login URL - will be used when the login process is done (but careful not to send us to an attachment).
60
-	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0)
61
-		$_SESSION['login_url'] = $_SESSION['old_url'];
62
-	elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false)
63
-		unset($_SESSION['login_url']);
62
+	if (isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) {
63
+			$_SESSION['login_url'] = $_SESSION['old_url'];
64
+	} elseif (isset($_SESSION['login_url']) && strpos($_SESSION['login_url'], 'dlattach') !== false) {
65
+			unset($_SESSION['login_url']);
66
+	}
64 67
 
65 68
 	// Create a one time token.
66 69
 	createToken('login');
@@ -83,8 +86,9 @@  discard block
 block discarded – undo
83 86
 	global $cookiename, $modSettings, $context, $sourcedir, $maintenance;
84 87
 
85 88
 	// Check to ensure we're forcing SSL for authentication
86
-	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -102,19 +106,20 @@  discard block
 block discarded – undo
102 106
 			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
103 107
 
104 108
 			// That didn't work... Maybe it's using serialize?
105
-			if (is_null($timeout))
106
-				list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
107
-		}
108
-		elseif (isset($_SESSION['login_' . $cookiename]))
109
+			if (is_null($timeout)) {
110
+							list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
111
+			}
112
+		} elseif (isset($_SESSION['login_' . $cookiename]))
109 113
 		{
110 114
 			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
111 115
 
112 116
 			// Try for old format
113
-			if (is_null($timeout))
114
-				list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
117
+			if (is_null($timeout)) {
118
+							list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
119
+			}
120
+		} else {
121
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
115 122
 		}
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
118 123
 
119 124
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 125
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -127,10 +132,11 @@  discard block
 block discarded – undo
127 132
 			list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
128 133
 
129 134
 			// If we're preserving the cookie, reset it with updated salt
130
-			if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp)
131
-				setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
132
-			else
133
-				setTFACookie(-3600, 0, '');
135
+			if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) {
136
+							setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
137
+			} else {
138
+							setTFACookie(-3600, 0, '');
139
+			}
134 140
 		}
135 141
 
136 142
 		setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
@@ -141,20 +147,20 @@  discard block
 block discarded – undo
141 147
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
142 148
 	{
143 149
 		// Strike!  You're outta there!
144
-		if ($_GET['member'] != $user_info['id'])
145
-			fatal_lang_error('login_cookie_error', false);
150
+		if ($_GET['member'] != $user_info['id']) {
151
+					fatal_lang_error('login_cookie_error', false);
152
+		}
146 153
 
147 154
 		$user_info['can_mod'] = allowedTo('access_mod_center') || (!$user_info['is_guest'] && ($user_info['mod_cache']['gq'] != '0=1' || $user_info['mod_cache']['bq'] != '0=1' || ($modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']))));
148 155
 
149 156
 		// Some whitelisting for login_url...
150
-		if (empty($_SESSION['login_url']))
151
-			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
152
-		elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
157
+		if (empty($_SESSION['login_url'])) {
158
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
159
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
153 160
 		{
154 161
 			unset ($_SESSION['login_url']);
155 162
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
156
-		}
157
-		else
163
+		} else
158 164
 		{
159 165
 			// Best not to clutter the session data too much...
160 166
 			$temp = $_SESSION['login_url'];
@@ -165,8 +171,9 @@  discard block
 block discarded – undo
165 171
 	}
166 172
 
167 173
 	// Beyond this point you are assumed to be a guest trying to login.
168
-	if (!$user_info['is_guest'])
169
-		redirectexit();
174
+	if (!$user_info['is_guest']) {
175
+			redirectexit();
176
+	}
170 177
 
171 178
 	// Are you guessing with a script?
172 179
 	checkSession();
@@ -174,18 +181,21 @@  discard block
 block discarded – undo
174 181
 	spamProtection('login');
175 182
 
176 183
 	// Set the login_url if it's not already set (but careful not to send us to an attachment).
177
-	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false))
178
-		$_SESSION['login_url'] = $_SESSION['old_url'];
184
+	if ((empty($_SESSION['login_url']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'dlattach') === false && preg_match('~(board|topic)[=,]~', $_SESSION['old_url']) != 0) || (isset($_GET['quicklogin']) && isset($_SESSION['old_url']) && strpos($_SESSION['old_url'], 'login') === false)) {
185
+			$_SESSION['login_url'] = $_SESSION['old_url'];
186
+	}
179 187
 
180 188
 	// Been guessing a lot, haven't we?
181
-	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3)
182
-		fatal_lang_error('login_threshold_fail', 'login');
189
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
190
+			fatal_lang_error('login_threshold_fail', 'login');
191
+	}
183 192
 
184 193
 	// Set up the cookie length.  (if it's invalid, just fall through and use the default.)
185
-	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1))
186
-		$modSettings['cookieTime'] = 3153600;
187
-	elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600))
188
-		$modSettings['cookieTime'] = (int) $_POST['cookielength'];
194
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
195
+			$modSettings['cookieTime'] = 3153600;
196
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
197
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
198
+	}
189 199
 
190 200
 	loadLanguage('Login');
191 201
 	// Load the template stuff.
@@ -305,8 +315,9 @@  discard block
 block discarded – undo
305 315
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
306 316
 
307 317
 			// Snitz style - SHA-256.  Technically, this is a downgrade, but most PHP configurations don't support sha256 anyway.
308
-			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256'))
309
-				$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
318
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
319
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
320
+			}
310 321
 
311 322
 			// phpBB3 users new hashing.  We now support it as well ;).
312 323
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -326,27 +337,29 @@  discard block
 block discarded – undo
326 337
 			// Some common md5 ones.
327 338
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
328 339
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
329
-		}
330
-		elseif (strlen($user_settings['passwd']) == 40)
340
+		} elseif (strlen($user_settings['passwd']) == 40)
331 341
 		{
332 342
 			// Maybe they are using a hash from before the password fix.
333 343
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
334 344
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
335 345
 
336 346
 			// BurningBoard3 style of hashing.
337
-			if (!empty($modSettings['enable_password_conversion']))
338
-				$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
347
+			if (!empty($modSettings['enable_password_conversion'])) {
348
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
349
+			}
339 350
 
340 351
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
341 352
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
342 353
 			{
343 354
 				// Try iconv first, for no particular reason.
344
-				if (function_exists('iconv'))
345
-					$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
355
+				if (function_exists('iconv')) {
356
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
357
+				}
346 358
 
347 359
 				// Say it aint so, iconv failed!
348
-				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding'))
349
-					$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
360
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
361
+									$other_passwords[] = sha1(strtolower(mb_convert_encoding($user_settings['member_name'], 'UTF-8', $modSettings['previousCharacterSet'])) . un_htmlspecialchars(mb_convert_encoding($_POST['passwrd'], 'UTF-8', $modSettings['previousCharacterSet'])));
362
+				}
350 363
 			}
351 364
 		}
352 365
 
@@ -376,8 +389,9 @@  discard block
 block discarded – undo
376 389
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
377 390
 
378 391
 			// Hmm... don't remember it, do you?  Here, try the password reminder ;).
379
-			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold'])
380
-				redirectexit('action=reminder');
392
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
393
+							redirectexit('action=reminder');
394
+			}
381 395
 			// We'll give you another chance...
382 396
 			else
383 397
 			{
@@ -388,8 +402,7 @@  discard block
 block discarded – undo
388 402
 				return;
389 403
 			}
390 404
 		}
391
-	}
392
-	elseif (!empty($user_settings['passwd_flood']))
405
+	} elseif (!empty($user_settings['passwd_flood']))
393 406
 	{
394 407
 		// Let's be sure they weren't a little hacker.
395 408
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -406,8 +419,9 @@  discard block
 block discarded – undo
406 419
 	}
407 420
 
408 421
 	// Check their activation status.
409
-	if (!checkActivation())
410
-		return;
422
+	if (!checkActivation()) {
423
+			return;
424
+	}
411 425
 
412 426
 	DoLogin();
413 427
 }
@@ -419,8 +433,9 @@  discard block
 block discarded – undo
419 433
 {
420 434
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
421 435
 
422
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
423
-		fatal_lang_error('no_access', false);
436
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
437
+			fatal_lang_error('no_access', false);
438
+	}
424 439
 
425 440
 	loadLanguage('Profile');
426 441
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -428,8 +443,9 @@  discard block
 block discarded – undo
428 443
 	$member = $context['tfa_member'];
429 444
 
430 445
 	// Prevent replay attacks by limiting at least 2 minutes before they can log in again via 2FA
431
-	if (time() - $member['last_login'] < 120)
432
-		fatal_lang_error('tfa_wait', false);
446
+	if (time() - $member['last_login'] < 120) {
447
+			fatal_lang_error('tfa_wait', false);
448
+	}
433 449
 
434 450
 	$totp = new \TOTP\Auth($member['tfa_secret']);
435 451
 	$totp->setRange(1);
@@ -443,8 +459,9 @@  discard block
 block discarded – undo
443 459
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
444 460
 	{
445 461
 		// Check to ensure we're forcing SSL for authentication
446
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
447
-			fatal_lang_error('login_ssl_required');
462
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
463
+					fatal_lang_error('login_ssl_required');
464
+		}
448 465
 
449 466
 		$code = $_POST['tfa_code'];
450 467
 
@@ -454,20 +471,19 @@  discard block
 block discarded – undo
454 471
 
455 472
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve']));
456 473
 			redirectexit();
457
-		}
458
-		else
474
+		} else
459 475
 		{
460 476
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
461 477
 
462 478
 			$context['tfa_error'] = true;
463 479
 			$context['tfa_value'] = $_POST['tfa_code'];
464 480
 		}
465
-	}
466
-	elseif (!empty($_POST['tfa_backup']))
481
+	} elseif (!empty($_POST['tfa_backup']))
467 482
 	{
468 483
 		// Check to ensure we're forcing SSL for authentication
469
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'))
470
-			fatal_lang_error('login_ssl_required');
484
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
485
+					fatal_lang_error('login_ssl_required');
486
+		}
471 487
 
472 488
 		$backup = $_POST['tfa_backup'];
473 489
 
@@ -481,8 +497,7 @@  discard block
 block discarded – undo
481 497
 			));
482 498
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
483 499
 			redirectexit('action=profile;area=tfasetup;backup');
484
-		}
485
-		else
500
+		} else
486 501
 		{
487 502
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
488 503
 
@@ -505,8 +520,9 @@  discard block
 block discarded – undo
505 520
 {
506 521
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
507 522
 
508
-	if (!isset($context['login_errors']))
509
-		$context['login_errors'] = array();
523
+	if (!isset($context['login_errors'])) {
524
+			$context['login_errors'] = array();
525
+	}
510 526
 
511 527
 	// What is the true activation status of this account?
512 528
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -518,8 +534,9 @@  discard block
 block discarded – undo
518 534
 		return false;
519 535
 	}
520 536
 	// Awaiting approval still?
521
-	elseif ($activation_status == 3)
522
-		fatal_lang_error('still_awaiting_approval', 'user');
537
+	elseif ($activation_status == 3) {
538
+			fatal_lang_error('still_awaiting_approval', 'user');
539
+	}
523 540
 	// Awaiting deletion, changed their mind?
524 541
 	elseif ($activation_status == 4)
525 542
 	{
@@ -527,8 +544,7 @@  discard block
 block discarded – undo
527 544
 		{
528 545
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
529 546
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
530
-		}
531
-		else
547
+		} else
532 548
 		{
533 549
 			$context['disable_login_hashing'] = true;
534 550
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -568,8 +584,9 @@  discard block
 block discarded – undo
568 584
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
569 585
 
570 586
 	// Reset the login threshold.
571
-	if (isset($_SESSION['failed_login']))
572
-		unset($_SESSION['failed_login']);
587
+	if (isset($_SESSION['failed_login'])) {
588
+			unset($_SESSION['failed_login']);
589
+	}
573 590
 
574 591
 	$user_info['is_guest'] = false;
575 592
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -591,16 +608,18 @@  discard block
 block discarded – undo
591 608
 			'id_member' => $user_info['id'],
592 609
 		)
593 610
 	);
594
-	if ($smcFunc['db_num_rows']($request) == 1)
595
-		$_SESSION['first_login'] = true;
596
-	else
597
-		unset($_SESSION['first_login']);
611
+	if ($smcFunc['db_num_rows']($request) == 1) {
612
+			$_SESSION['first_login'] = true;
613
+	} else {
614
+			unset($_SESSION['first_login']);
615
+	}
598 616
 	$smcFunc['db_free_result']($request);
599 617
 
600 618
 	// You've logged in, haven't you?
601 619
 	$update = array('member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP']);
602
-	if (empty($user_settings['tfa_secret']))
603
-		$update['last_login'] = time();
620
+	if (empty($user_settings['tfa_secret'])) {
621
+			$update['last_login'] = time();
622
+	}
604 623
 	updateMemberData($user_info['id'], $update);
605 624
 
606 625
 	// Get rid of the online entry for that old guest....
@@ -614,8 +633,8 @@  discard block
 block discarded – undo
614 633
 	$_SESSION['log_time'] = 0;
615 634
 
616 635
 	// Log this entry, only if we have it enabled.
617
-	if (!empty($modSettings['loginHistoryDays']))
618
-		$smcFunc['db_insert']('insert',
636
+	if (!empty($modSettings['loginHistoryDays'])) {
637
+			$smcFunc['db_insert']('insert',
619 638
 			'{db_prefix}member_logins',
620 639
 			array(
621 640
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -627,13 +646,15 @@  discard block
 block discarded – undo
627 646
 				'id_member', 'time'
628 647
 			)
629 648
 		);
649
+	}
630 650
 
631 651
 	// Just log you back out if it's in maintenance mode and you AREN'T an admin.
632
-	if (empty($maintenance) || allowedTo('admin_forum'))
633
-		redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
634
-	else
635
-		redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
636
-}
652
+	if (empty($maintenance) || allowedTo('admin_forum')) {
653
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
654
+	} else {
655
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
656
+	}
657
+	}
637 658
 
638 659
 /**
639 660
  * Logs the current user out of their account.
@@ -649,13 +670,15 @@  discard block
 block discarded – undo
649 670
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
650 671
 
651 672
 	// Make sure they aren't being auto-logged out.
652
-	if (!$internal)
653
-		checkSession('get');
673
+	if (!$internal) {
674
+			checkSession('get');
675
+	}
654 676
 
655 677
 	require_once($sourcedir . '/Subs-Auth.php');
656 678
 
657
-	if (isset($_SESSION['pack_ftp']))
658
-		$_SESSION['pack_ftp'] = null;
679
+	if (isset($_SESSION['pack_ftp'])) {
680
+			$_SESSION['pack_ftp'] = null;
681
+	}
659 682
 
660 683
 	// It won't be first login anymore.
661 684
 	unset($_SESSION['first_login']);
@@ -683,8 +706,9 @@  discard block
 block discarded – undo
683 706
 
684 707
 	// And some other housekeeping while we're at it.
685 708
 	$salt = substr(md5(mt_rand()), 0, 4);
686
-	if (!empty($user_info['id']))
687
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
709
+	if (!empty($user_info['id'])) {
710
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
711
+	}
688 712
 
689 713
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
690 714
 	{
@@ -693,10 +717,11 @@  discard block
 block discarded – undo
693 717
 		list ($tfamember, $tfasecret, $exp, $state, $preserve) = $tfadata;
694 718
 
695 719
 		// If we're preserving the cookie, reset it with updated salt
696
-		if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp)
697
-			setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
698
-		else
699
-			setTFACookie(-3600, 0, '');
720
+		if (isset($tfamember, $tfasecret, $exp, $state, $preserve) && $preserve && time() < $exp) {
721
+					setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
722
+		} else {
723
+					setTFACookie(-3600, 0, '');
724
+		}
700 725
 	}
701 726
 
702 727
 	session_destroy();
@@ -704,14 +729,13 @@  discard block
 block discarded – undo
704 729
 	// Off to the merry board index we go!
705 730
 	if ($redirect)
706 731
 	{
707
-		if (empty($_SESSION['logout_url']))
708
-			redirectexit('', $context['server']['needs_login_fix']);
709
-		elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
732
+		if (empty($_SESSION['logout_url'])) {
733
+					redirectexit('', $context['server']['needs_login_fix']);
734
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
710 735
 		{
711 736
 			unset ($_SESSION['logout_url']);
712 737
 			redirectexit();
713
-		}
714
-		else
738
+		} else
715 739
 		{
716 740
 			$temp = $_SESSION['logout_url'];
717 741
 			unset($_SESSION['logout_url']);
@@ -744,8 +768,9 @@  discard block
 block discarded – undo
744 768
 function phpBB3_password_check($passwd, $passwd_hash)
745 769
 {
746 770
 	// Too long or too short?
747
-	if (strlen($passwd_hash) != 34)
748
-		return;
771
+	if (strlen($passwd_hash) != 34) {
772
+			return;
773
+	}
749 774
 
750 775
 	// Range of characters allowed.
751 776
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -756,8 +781,9 @@  discard block
 block discarded – undo
756 781
 	$salt = substr($passwd_hash, 4, 8);
757 782
 
758 783
 	$hash = md5($salt . $passwd, true);
759
-	for (; $count != 0; --$count)
760
-		$hash = md5($hash . $passwd, true);
784
+	for (; $count != 0; --$count) {
785
+			$hash = md5($hash . $passwd, true);
786
+	}
761 787
 
762 788
 	$output = substr($passwd_hash, 0, 12);
763 789
 	$i = 0;
@@ -766,21 +792,25 @@  discard block
 block discarded – undo
766 792
 		$value = ord($hash[$i++]);
767 793
 		$output .= $range[$value & 0x3f];
768 794
 
769
-		if ($i < 16)
770
-			$value |= ord($hash[$i]) << 8;
795
+		if ($i < 16) {
796
+					$value |= ord($hash[$i]) << 8;
797
+		}
771 798
 
772 799
 		$output .= $range[($value >> 6) & 0x3f];
773 800
 
774
-		if ($i++ >= 16)
775
-			break;
801
+		if ($i++ >= 16) {
802
+					break;
803
+		}
776 804
 
777
-		if ($i < 16)
778
-			$value |= ord($hash[$i]) << 16;
805
+		if ($i < 16) {
806
+					$value |= ord($hash[$i]) << 16;
807
+		}
779 808
 
780 809
 		$output .= $range[($value >> 12) & 0x3f];
781 810
 
782
-		if ($i++ >= 16)
783
-			break;
811
+		if ($i++ >= 16) {
812
+					break;
813
+		}
784 814
 
785 815
 		$output .= $range[($value >> 18) & 0x3f];
786 816
 	}
@@ -812,8 +842,9 @@  discard block
 block discarded – undo
812 842
 		require_once($sourcedir . '/Subs-Auth.php');
813 843
 		setLoginCookie(-3600, 0);
814 844
 
815
-		if (isset($_SESSION['login_' . $cookiename]))
816
-			unset($_SESSION['login_' . $cookiename]);
845
+		if (isset($_SESSION['login_' . $cookiename])) {
846
+					unset($_SESSION['login_' . $cookiename]);
847
+		}
817 848
 	}
818 849
 
819 850
 	// We need a member!
@@ -827,8 +858,9 @@  discard block
 block discarded – undo
827 858
 	}
828 859
 
829 860
 	// Right, have we got a flood value?
830
-	if ($password_flood_value !== false)
831
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
861
+	if ($password_flood_value !== false) {
862
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
863
+	}
832 864
 
833 865
 	// Timestamp or number of tries invalid?
834 866
 	if (empty($number_tries) || empty($time_stamp))
@@ -844,15 +876,17 @@  discard block
 block discarded – undo
844 876
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
845 877
 
846 878
 		// They are trying too fast, make them wait longer
847
-		if ($time_stamp < time() - 10)
848
-			$time_stamp = time();
879
+		if ($time_stamp < time() - 10) {
880
+					$time_stamp = time();
881
+		}
849 882
 	}
850 883
 
851 884
 	$number_tries++;
852 885
 
853 886
 	// Broken the law?
854
-	if ($number_tries > 5)
855
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
887
+	if ($number_tries > 5) {
888
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
889
+	}
856 890
 
857 891
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
858 892
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/ModerationCenter.php 1 patch
Braces   +136 added lines, -100 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
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
  * Entry point for the moderation center.
@@ -26,8 +27,9 @@  discard block
 block discarded – undo
26 27
 	global $smcFunc, $txt, $context, $scripturl, $modSettings, $user_info, $sourcedir, $options;
27 28
 
28 29
 	// Don't run this twice... and don't conflict with the admin bar.
29
-	if (isset($context['admin_area']))
30
-		return;
30
+	if (isset($context['admin_area'])) {
31
+			return;
32
+	}
31 33
 
32 34
 	$context['can_moderate_boards'] = $user_info['mod_cache']['bq'] != '0=1';
33 35
 	$context['can_moderate_groups'] = $user_info['mod_cache']['gq'] != '0=1';
@@ -35,8 +37,9 @@  discard block
 block discarded – undo
35 37
 	$context['can_moderate_users'] = allowedTo('moderate_forum');
36 38
 
37 39
 	// Everyone using this area must be allowed here!
38
-	if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users'])
39
-		isAllowedTo('access_mod_center');
40
+	if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users']) {
41
+			isAllowedTo('access_mod_center');
42
+	}
40 43
 
41 44
 	// We're gonna want a menu of some kind.
42 45
 	require_once($sourcedir . '/Subs-Menu.php');
@@ -195,8 +198,9 @@  discard block
 block discarded – undo
195 198
 	unset($moderation_areas);
196 199
 
197 200
 	// We got something - didn't we? DIDN'T WE!
198
-	if ($mod_include_data == false)
199
-		fatal_lang_error('no_access', false);
201
+	if ($mod_include_data == false) {
202
+			fatal_lang_error('no_access', false);
203
+	}
200 204
 
201 205
 	// Retain the ID information in case required by a subaction.
202 206
 	$context['moderation_menu_id'] = $context['max_menu_id'];
@@ -219,22 +223,25 @@  discard block
 block discarded – undo
219 223
 		'url' => $scripturl . '?action=moderate',
220 224
 		'name' => $txt['moderation_center'],
221 225
 	);
222
-	if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index')
223
-		$context['linktree'][] = array(
226
+	if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index') {
227
+			$context['linktree'][] = array(
224 228
 			'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'],
225 229
 			'name' => $mod_include_data['label'],
226 230
 		);
227
-	if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label'])
228
-		$context['linktree'][] = array(
231
+	}
232
+	if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label']) {
233
+			$context['linktree'][] = array(
229 234
 			'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'],
230 235
 			'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0],
231 236
 		);
237
+	}
232 238
 
233 239
 	// Now - finally - the bit before the encore - the main performance of course!
234 240
 	if (!$dont_call)
235 241
 	{
236
-		if (isset($mod_include_data['file']))
237
-			require_once($sourcedir . '/' . $mod_include_data['file']);
242
+		if (isset($mod_include_data['file'])) {
243
+					require_once($sourcedir . '/' . $mod_include_data['file']);
244
+		}
238 245
 
239 246
 		call_helper($mod_include_data['function']);
240 247
 	}
@@ -259,8 +266,9 @@  discard block
 block discarded – undo
259 266
 	// Load what blocks the user actually can see...
260 267
 	$valid_blocks = array();
261 268
 
262
-	if ($context['can_moderate_groups'])
263
-		$valid_blocks['g'] = 'GroupRequests';
269
+	if ($context['can_moderate_groups']) {
270
+			$valid_blocks['g'] = 'GroupRequests';
271
+	}
264 272
 	if ($context['can_moderate_boards'])
265 273
 	{
266 274
 		$valid_blocks['r'] = 'ReportedPosts';
@@ -269,8 +277,9 @@  discard block
 block discarded – undo
269 277
 	if ($context['can_moderate_users'])
270 278
 	{
271 279
 		// This falls under the category of moderating users as well...
272
-		if (!$context['can_moderate_boards'])
273
-			$valid_blocks['w'] = 'WatchedUsers';
280
+		if (!$context['can_moderate_boards']) {
281
+					$valid_blocks['w'] = 'WatchedUsers';
282
+		}
274 283
 
275 284
 		$valid_blocks['rm'] = 'ReportedMembers';
276 285
 	}
@@ -281,8 +290,9 @@  discard block
 block discarded – undo
281 290
 	foreach ($valid_blocks as $k => $block)
282 291
 	{
283 292
 		$block = 'ModBlock' . $block;
284
-		if (function_exists($block))
285
-			$context['mod_blocks'][] = $block();
293
+		if (function_exists($block)) {
294
+					$context['mod_blocks'][] = $block();
295
+		}
286 296
 	}
287 297
 
288 298
 	$context['admin_prefs'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array();
@@ -309,8 +319,9 @@  discard block
 block discarded – undo
309 319
 			)
310 320
 		);
311 321
 		$watched_users = array();
312
-		while ($row = $smcFunc['db_fetch_assoc']($request))
313
-			$watched_users[] = $row;
322
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
323
+					$watched_users[] = $row;
324
+		}
314 325
 		$smcFunc['db_free_result']($request);
315 326
 
316 327
 		cache_put_data('recent_user_watches', $watched_users, 240);
@@ -402,8 +413,9 @@  discard block
 block discarded – undo
402 413
 			$note_owner = $smcFunc['db_num_rows']($get_owner);
403 414
 			$smcFunc['db_free_result']($get_owner);
404 415
 
405
-			if (empty($note_owner))
406
-				fatal_lang_error('mc_notes_delete_own', false);
416
+			if (empty($note_owner)) {
417
+							fatal_lang_error('mc_notes_delete_own', false);
418
+			}
407 419
 		}
408 420
 
409 421
 		// Lets delete it.
@@ -460,12 +472,14 @@  discard block
 block discarded – undo
460 472
 			)
461 473
 		);
462 474
 		$moderator_notes = array();
463
-		while ($row = $smcFunc['db_fetch_assoc']($request))
464
-			$moderator_notes[] = $row;
475
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
476
+					$moderator_notes[] = $row;
477
+		}
465 478
 		$smcFunc['db_free_result']($request);
466 479
 
467
-		if ($offset == 0)
468
-			cache_put_data('moderator_notes', $moderator_notes, 240);
480
+		if ($offset == 0) {
481
+					cache_put_data('moderator_notes', $moderator_notes, 240);
482
+		}
469 483
 	}
470 484
 
471 485
 	// Lets construct a page index.
@@ -504,8 +518,9 @@  discard block
 block discarded – undo
504 518
 	// Got the info already?
505 519
 	$cachekey = md5($smcFunc['json_encode']($user_info['mod_cache']['bq']));
506 520
 	$context['reported_posts'] = array();
507
-	if ($user_info['mod_cache']['bq'] == '0=1')
508
-		return 'reported_posts_block';
521
+	if ($user_info['mod_cache']['bq'] == '0=1') {
522
+			return 'reported_posts_block';
523
+	}
509 524
 
510 525
 	if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null)
511 526
 	{
@@ -529,8 +544,9 @@  discard block
 block discarded – undo
529 544
 			)
530 545
 		);
531 546
 		$reported_posts = array();
532
-		while ($row = $smcFunc['db_fetch_assoc']($request))
533
-			$reported_posts[] = $row;
547
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
548
+					$reported_posts[] = $row;
549
+		}
534 550
 		$smcFunc['db_free_result']($request);
535 551
 
536 552
 		// Cache it.
@@ -568,8 +584,9 @@  discard block
 block discarded – undo
568 584
 
569 585
 	$context['group_requests'] = array();
570 586
 	// Make sure they can even moderate someone!
571
-	if ($user_info['mod_cache']['gq'] == '0=1')
572
-		return 'group_requests_block';
587
+	if ($user_info['mod_cache']['gq'] == '0=1') {
588
+			return 'group_requests_block';
589
+	}
573 590
 
574 591
 	// What requests are outstanding?
575 592
 	$request = $smcFunc['db_query']('', '
@@ -618,8 +635,9 @@  discard block
 block discarded – undo
618 635
 	// Got the info already?
619 636
 	$cachekey = md5($smcFunc['json_encode']((int) allowedTo('moderate_forum')));
620 637
 	$context['reported_users'] = array();
621
-	if (!allowedTo('moderate_forum'))
622
-		return 'reported_users_block';
638
+	if (!allowedTo('moderate_forum')) {
639
+			return 'reported_users_block';
640
+	}
623 641
 
624 642
 	if (($reported_users = cache_get_data('reported_users_' . $cachekey, 90)) === null)
625 643
 	{
@@ -642,8 +660,9 @@  discard block
 block discarded – undo
642 660
 			)
643 661
 		);
644 662
 		$reported_users = array();
645
-		while ($row = $smcFunc['db_fetch_assoc']($request))
646
-			$reported_users[] = $row;
663
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
664
+					$reported_users[] = $row;
665
+		}
647 666
 		$smcFunc['db_free_result']($request);
648 667
 
649 668
 		// Cache it.
@@ -742,15 +761,15 @@  discard block
 block discarded – undo
742 761
 		// Time to update.
743 762
 		updateSettings(array('last_mod_report_action' => time()));
744 763
 		recountOpenReports('members');
745
-	}
746
-	elseif (isset($_POST['close']) && isset($_POST['close_selected']))
764
+	} elseif (isset($_POST['close']) && isset($_POST['close_selected']))
747 765
 	{
748 766
 		checkSession();
749 767
 
750 768
 		// All the ones to update...
751 769
 		$toClose = array();
752
-		foreach ($_POST['close'] as $rid)
753
-			$toClose[] = (int) $rid;
770
+		foreach ($_POST['close'] as $rid) {
771
+					$toClose[] = (int) $rid;
772
+		}
754 773
 
755 774
 		if (!empty($toClose))
756 775
 		{
@@ -903,8 +922,9 @@  discard block
 block discarded – undo
903 922
 	global $context, $user_info;
904 923
 
905 924
 	// You need to be allowed to moderate groups...
906
-	if ($user_info['mod_cache']['gq'] == '0=1')
907
-		isAllowedTo('manage_membergroups');
925
+	if ($user_info['mod_cache']['gq'] == '0=1') {
926
+			isAllowedTo('manage_membergroups');
927
+	}
908 928
 
909 929
 	// Load the group templates.
910 930
 	loadTemplate('ModerationCenter');
@@ -915,8 +935,9 @@  discard block
 block discarded – undo
915 935
 		'view' => 'ViewGroups',
916 936
 	);
917 937
 
918
-	if (!isset($_GET['sa']) || !isset($subActions[$_GET['sa']]))
919
-		$_GET['sa'] = 'view';
938
+	if (!isset($_GET['sa']) || !isset($subActions[$_GET['sa']])) {
939
+			$_GET['sa'] = 'view';
940
+	}
920 941
 	$context['sub_action'] = $_GET['sa'];
921 942
 
922 943
 	// Call the relevant function.
@@ -946,8 +967,9 @@  discard block
 block discarded – undo
946 967
 			'id_notice' => $id_notice,
947 968
 		)
948 969
 	);
949
-	if ($smcFunc['db_num_rows']($request) == 0)
950
-		fatal_lang_error('no_access', false);
970
+	if ($smcFunc['db_num_rows']($request) == 0) {
971
+			fatal_lang_error('no_access', false);
972
+	}
951 973
 	list ($context['notice_body'], $context['notice_subject']) = $smcFunc['db_fetch_row']($request);
952 974
 	$smcFunc['db_free_result']($request);
953 975
 
@@ -984,18 +1006,20 @@  discard block
 block discarded – undo
984 1006
 		checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post');
985 1007
 
986 1008
 		$toDelete = array();
987
-		if (!is_array($_REQUEST['delete']))
988
-			$toDelete[] = (int) $_REQUEST['delete'];
989
-		else
990
-			foreach ($_REQUEST['delete'] as $did)
1009
+		if (!is_array($_REQUEST['delete'])) {
1010
+					$toDelete[] = (int) $_REQUEST['delete'];
1011
+		} else {
1012
+					foreach ($_REQUEST['delete'] as $did)
991 1013
 				$toDelete[] = (int) $did;
1014
+		}
992 1015
 
993 1016
 		if (!empty($toDelete))
994 1017
 		{
995 1018
 			require_once($sourcedir . '/RemoveTopic.php');
996 1019
 			// If they don't have permission we'll let it error - either way no chance of a security slip here!
997
-			foreach ($toDelete as $did)
998
-				removeMessage($did);
1020
+			foreach ($toDelete as $did) {
1021
+							removeMessage($did);
1022
+			}
999 1023
 		}
1000 1024
 	}
1001 1025
 
@@ -1004,20 +1028,21 @@  discard block
 block discarded – undo
1004 1028
 	{
1005 1029
 		$approve_query = '';
1006 1030
 		$delete_boards = array();
1007
-	}
1008
-	else
1031
+	} else
1009 1032
 	{
1010 1033
 		// Still obey permissions!
1011 1034
 		$approve_boards = boardsAllowedTo('approve_posts');
1012 1035
 		$delete_boards = boardsAllowedTo('delete_any');
1013 1036
 
1014
-		if ($approve_boards == array(0))
1015
-			$approve_query = '';
1016
-		elseif (!empty($approve_boards))
1017
-			$approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
1037
+		if ($approve_boards == array(0)) {
1038
+					$approve_query = '';
1039
+		} elseif (!empty($approve_boards)) {
1040
+					$approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
1041
+		}
1018 1042
 		// Nada, zip, etc...
1019
-		else
1020
-			$approve_query = ' AND 1=0';
1043
+		else {
1044
+					$approve_query = ' AND 1=0';
1045
+		}
1021 1046
 	}
1022 1047
 
1023 1048
 	require_once($sourcedir . '/Subs-List.php');
@@ -1116,10 +1141,11 @@  discard block
 block discarded – undo
1116 1141
 				'data' => array(
1117 1142
 					'function' => function($member) use ($scripturl)
1118 1143
 					{
1119
-						if ($member['last_post_id'])
1120
-							return '<a href="' . $scripturl . '?msg=' . $member['last_post_id'] . '">' . $member['last_post'] . '</a>';
1121
-						else
1122
-							return $member['last_post'];
1144
+						if ($member['last_post_id']) {
1145
+													return '<a href="' . $scripturl . '?msg=' . $member['last_post_id'] . '">' . $member['last_post'] . '</a>';
1146
+						} else {
1147
+													return $member['last_post'];
1148
+						}
1123 1149
 					},
1124 1150
 				),
1125 1151
 			),
@@ -1247,8 +1273,9 @@  discard block
 block discarded – undo
1247 1273
 			)
1248 1274
 		);
1249 1275
 		$latest_posts = array();
1250
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1251
-			$latest_posts[$row['id_member']] = $row['last_post_id'];
1276
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1277
+					$latest_posts[$row['id_member']] = $row['last_post_id'];
1278
+		}
1252 1279
 
1253 1280
 		if (!empty($latest_posts))
1254 1281
 		{
@@ -1439,15 +1466,17 @@  discard block
 block discarded – undo
1439 1466
 	// Setup the direction stuff...
1440 1467
 	$context['order'] = isset($_REQUEST['sort']) && isset($sort_types[$_REQUEST['sort']]) ? $_REQUEST['sort'] : 'member';
1441 1468
 
1442
-	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search']))
1443
-		$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
1444
-	else
1445
-		$search_params_string = $search_params['string'];
1469
+	if (!isset($search_params['string']) || (!empty($_REQUEST['search']) && $search_params['string'] != $_REQUEST['search'])) {
1470
+			$search_params_string = empty($_REQUEST['search']) ? '' : $_REQUEST['search'];
1471
+	} else {
1472
+			$search_params_string = $search_params['string'];
1473
+	}
1446 1474
 
1447
-	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']]))
1448
-		$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
1449
-	else
1450
-		$search_params_type = $search_params['type'];
1475
+	if (isset($_REQUEST['search_type']) || empty($search_params['type']) || !isset($searchTypes[$search_params['type']])) {
1476
+			$search_params_type = isset($_REQUEST['search_type']) && isset($searchTypes[$_REQUEST['search_type']]) ? $_REQUEST['search_type'] : (isset($searchTypes[$context['order']]) ? $context['order'] : 'member');
1477
+	} else {
1478
+			$search_params_type = $search_params['type'];
1479
+	}
1451 1480
 
1452 1481
 	$search_params = array(
1453 1482
 		'string' => $search_params_string,
@@ -1530,9 +1559,10 @@  discard block
 block discarded – undo
1530 1559
 								' . $rowData['reason'] . '
1531 1560
 							</div>';
1532 1561
 
1533
-						if (!empty($rowData['id_notice']))
1534
-							$output .= '
1562
+						if (!empty($rowData['id_notice'])) {
1563
+													$output .= '
1535 1564
 								&nbsp;<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $rowData['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>';
1565
+						}
1536 1566
 						return $output;
1537 1567
 					},
1538 1568
 				),
@@ -1650,9 +1680,9 @@  discard block
 block discarded – undo
1650 1680
 	global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir, $user_info;
1651 1681
 
1652 1682
 	// Submitting a new one?
1653
-	if (isset($_POST['add']))
1654
-		return ModifyWarningTemplate();
1655
-	elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
1683
+	if (isset($_POST['add'])) {
1684
+			return ModifyWarningTemplate();
1685
+	} elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
1656 1686
 	{
1657 1687
 		checkSession();
1658 1688
 		validateToken('mod-wt');
@@ -1671,8 +1701,9 @@  discard block
 block discarded – undo
1671 1701
 				'current_member' => $user_info['id'],
1672 1702
 			)
1673 1703
 		);
1674
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1675
-			logAction('delete_warn_template', array('template' => $row['recipient_name']));
1704
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1705
+					logAction('delete_warn_template', array('template' => $row['recipient_name']));
1706
+		}
1676 1707
 		$smcFunc['db_free_result']($request);
1677 1708
 
1678 1709
 		// Do the deletes.
@@ -1963,16 +1994,18 @@  discard block
 block discarded – undo
1963 1994
 				);
1964 1995
 
1965 1996
 				// If it wasn't visible and now is they've effectively added it.
1966
-				if ($context['template_data']['personal'] && !$recipient_id)
1967
-					logAction('add_warn_template', array('template' => $_POST['template_title']));
1997
+				if ($context['template_data']['personal'] && !$recipient_id) {
1998
+									logAction('add_warn_template', array('template' => $_POST['template_title']));
1999
+				}
1968 2000
 				// Conversely if they made it personal it's a delete.
1969
-				elseif (!$context['template_data']['personal'] && $recipient_id)
1970
-					logAction('delete_warn_template', array('template' => $_POST['template_title']));
2001
+				elseif (!$context['template_data']['personal'] && $recipient_id) {
2002
+									logAction('delete_warn_template', array('template' => $_POST['template_title']));
2003
+				}
1971 2004
 				// Otherwise just an edit.
1972
-				else
1973
-					logAction('modify_warn_template', array('template' => $_POST['template_title']));
1974
-			}
1975
-			else
2005
+				else {
2006
+									logAction('modify_warn_template', array('template' => $_POST['template_title']));
2007
+				}
2008
+			} else
1976 2009
 			{
1977 2010
 				$smcFunc['db_insert']('',
1978 2011
 					'{db_prefix}log_comments',
@@ -1992,17 +2025,18 @@  discard block
 block discarded – undo
1992 2025
 
1993 2026
 			// Get out of town...
1994 2027
 			redirectexit('action=moderate;area=warnings;sa=templates');
1995
-		}
1996
-		else
2028
+		} else
1997 2029
 		{
1998 2030
 			$context['warning_errors'] = array();
1999 2031
 			$context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : '';
2000 2032
 			$context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default'];
2001 2033
 			$context['template_data']['personal'] = !empty($_POST['make_personal']);
2002
-			if (empty($_POST['template_title']))
2003
-				$context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
2004
-			if (empty($_POST['template_body']))
2005
-				$context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
2034
+			if (empty($_POST['template_title'])) {
2035
+							$context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
2036
+			}
2037
+			if (empty($_POST['template_body'])) {
2038
+							$context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
2039
+			}
2006 2040
 		}
2007 2041
 	}
2008 2042
 
@@ -2047,8 +2081,9 @@  discard block
 block discarded – undo
2047 2081
 		// Now check other options!
2048 2082
 		$pref_binary = 0;
2049 2083
 
2050
-		if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval']))
2051
-			$pref_binary |= 4;
2084
+		if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval'])) {
2085
+					$pref_binary |= 4;
2086
+		}
2052 2087
 
2053 2088
 		// Put it all together.
2054 2089
 		$mod_prefs = '0||' . $pref_binary;
@@ -2072,9 +2107,10 @@  discard block
 block discarded – undo
2072 2107
 	unset($_SESSION['moderate_time']);
2073 2108
 
2074 2109
 	// Clean any moderator tokens as well.
2075
-	foreach ($_SESSION['token'] as $key => $token)
2076
-		if (strpos($key, '-mod') !== false)
2110
+	foreach ($_SESSION['token'] as $key => $token) {
2111
+			if (strpos($key, '-mod') !== false)
2077 2112
 			unset($_SESSION['token'][$key]);
2113
+	}
2078 2114
 
2079 2115
 	redirectexit();
2080 2116
 }
Please login to merge, or discard this patch.
Sources/Profile-Actions.php 1 patch
Braces   +117 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
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
  * Activate an account.
@@ -48,8 +49,9 @@  discard block
 block discarded – undo
48 49
 		logAction('approve_member', array('member' => $memID), 'admin');
49 50
 
50 51
 		// If we are doing approval, update the stats for the member just in case.
51
-		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15)))
52
-			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
52
+		if (in_array($user_profile[$memID]['is_activated'], array(3, 4, 5, 13, 14, 15))) {
53
+					updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 1 ? $modSettings['unapprovedMembers'] - 1 : 0)));
54
+		}
53 55
 
54 56
 		// Make sure we update the stats too.
55 57
 		updateStats('member', false);
@@ -76,8 +78,9 @@  discard block
 block discarded – undo
76 78
 	$issueErrors = array();
77 79
 
78 80
 	// Doesn't hurt to be overly cautious.
79
-	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning'))
80
-		fatal_lang_error('no_access', false);
81
+	if (empty($modSettings['warning_enable']) || ($context['user']['is_owner'] && !$cur_profile['warning']) || !allowedTo('issue_warning')) {
82
+			fatal_lang_error('no_access', false);
83
+	}
81 84
 
82 85
 	// Get the base (errors related) stuff done.
83 86
 	loadLanguage('Errors');
@@ -135,16 +138,18 @@  discard block
 block discarded – undo
135 138
 
136 139
 		// This cannot be empty!
137 140
 		$_POST['warn_reason'] = isset($_POST['warn_reason']) ? trim($_POST['warn_reason']) : '';
138
-		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner'])
139
-			$issueErrors[] = 'warning_no_reason';
141
+		if ($_POST['warn_reason'] == '' && !$context['user']['is_owner']) {
142
+					$issueErrors[] = 'warning_no_reason';
143
+		}
140 144
 		$_POST['warn_reason'] = $smcFunc['htmlspecialchars']($_POST['warn_reason']);
141 145
 
142 146
 		$_POST['warning_level'] = (int) $_POST['warning_level'];
143 147
 		$_POST['warning_level'] = max(0, min(100, $_POST['warning_level']));
144
-		if ($_POST['warning_level'] < $context['min_allowed'])
145
-			$_POST['warning_level'] = $context['min_allowed'];
146
-		elseif ($_POST['warning_level'] > $context['max_allowed'])
147
-			$_POST['warning_level'] = $context['max_allowed'];
148
+		if ($_POST['warning_level'] < $context['min_allowed']) {
149
+					$_POST['warning_level'] = $context['min_allowed'];
150
+		} elseif ($_POST['warning_level'] > $context['max_allowed']) {
151
+					$_POST['warning_level'] = $context['max_allowed'];
152
+		}
148 153
 
149 154
 		// Do we actually have to issue them with a PM?
150 155
 		$id_notice = 0;
@@ -152,8 +157,9 @@  discard block
 block discarded – undo
152 157
 		{
153 158
 			$_POST['warn_sub'] = trim($_POST['warn_sub']);
154 159
 			$_POST['warn_body'] = trim($_POST['warn_body']);
155
-			if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
156
-				$issueErrors[] = 'warning_notify_blank';
160
+			if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
161
+							$issueErrors[] = 'warning_notify_blank';
162
+			}
157 163
 			// Send the PM?
158 164
 			else
159 165
 			{
@@ -190,8 +196,8 @@  discard block
 block discarded – undo
190 196
 		if (empty($issueErrors))
191 197
 		{
192 198
 			// Log what we've done!
193
-			if (!$context['user']['is_owner'])
194
-				$smcFunc['db_insert']('',
199
+			if (!$context['user']['is_owner']) {
200
+							$smcFunc['db_insert']('',
195 201
 					'{db_prefix}log_comments',
196 202
 					array(
197 203
 						'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int', 'recipient_name' => 'string-255',
@@ -203,14 +209,14 @@  discard block
 block discarded – undo
203 209
 					),
204 210
 					array('id_comment')
205 211
 				);
212
+			}
206 213
 
207 214
 			// Make the change.
208 215
 			updateMemberData($memID, array('warning' => $_POST['warning_level']));
209 216
 
210 217
 			// Leave a lovely message.
211 218
 			$context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : $txt['profile_warning_success'];
212
-		}
213
-		else
219
+		} else
214 220
 		{
215 221
 			// Try to remember some bits.
216 222
 			$context['warning_data'] = array(
@@ -229,8 +235,9 @@  discard block
 block discarded – undo
229 235
 	{
230 236
 		$warning_body = !empty($_POST['warn_body']) ? trim(censorText($_POST['warn_body'])) : '';
231 237
 		$context['preview_subject'] = !empty($_POST['warn_sub']) ? trim($smcFunc['htmlspecialchars']($_POST['warn_sub'])) : '';
232
-		if (empty($_POST['warn_sub']) || empty($_POST['warn_body']))
233
-			$issueErrors[] = 'warning_notify_blank';
238
+		if (empty($_POST['warn_sub']) || empty($_POST['warn_body'])) {
239
+					$issueErrors[] = 'warning_notify_blank';
240
+		}
234 241
 
235 242
 		if (!empty($_POST['warn_body']))
236 243
 		{
@@ -254,8 +261,9 @@  discard block
 block discarded – undo
254 261
 	{
255 262
 		// Fill in the suite of errors.
256 263
 		$context['post_errors'] = array();
257
-		foreach ($issueErrors as $error)
258
-			$context['post_errors'][] = $txt[$error];
264
+		foreach ($issueErrors as $error) {
265
+					$context['post_errors'][] = $txt[$error];
266
+		}
259 267
 	}
260 268
 
261 269
 
@@ -272,9 +280,10 @@  discard block
 block discarded – undo
272 280
 		$modSettings['warning_mute'] => $txt['profile_warning_effect_mute'],
273 281
 	);
274 282
 	$context['current_level'] = 0;
275
-	foreach ($context['level_effects'] as $limit => $dummy)
276
-		if ($context['member']['warning'] >= $limit)
283
+	foreach ($context['level_effects'] as $limit => $dummy) {
284
+			if ($context['member']['warning'] >= $limit)
277 285
 			$context['current_level'] = $limit;
286
+	}
278 287
 
279 288
 	$listOptions = array(
280 289
 		'id' => 'view_warnings',
@@ -337,11 +346,12 @@  discard block
 block discarded – undo
337 346
 							' . $warning['reason'] . '
338 347
 						</div>';
339 348
 
340
-						if (!empty($warning['id_notice']))
341
-							$ret .= '
349
+						if (!empty($warning['id_notice'])) {
350
+													$ret .= '
342 351
 						<div class="floatright">
343 352
 							<a href="' . $scripturl . '?action=moderate;area=notice;nid=' . $warning['id_notice'] . '" onclick="window.open(this.href, \'\', \'scrollbars=yes,resizable=yes,width=400,height=250\');return false;" target="_blank" title="' . $txt['profile_warning_previous_notice'] . '"><span class="generic_icons filter centericon"></span></a>
344 353
 						</div>';
354
+						}
345 355
 
346 356
 						return $ret;
347 357
 					},
@@ -413,8 +423,9 @@  discard block
 block discarded – undo
413 423
 	while ($row = $smcFunc['db_fetch_assoc']($request))
414 424
 	{
415 425
 		// If we're not warning for a message skip any that are.
416
-		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false)
417
-			continue;
426
+		if (!$context['warning_for_message'] && strpos($row['body'], '{MESSAGE}') !== false) {
427
+					continue;
428
+		}
418 429
 
419 430
 		$context['notification_templates'][] = array(
420 431
 			'title' => $row['template_title'],
@@ -424,16 +435,18 @@  discard block
 block discarded – undo
424 435
 	$smcFunc['db_free_result']($request);
425 436
 
426 437
 	// Setup the "default" templates.
427
-	foreach (array('spamming', 'offence', 'insulting') as $type)
428
-		$context['notification_templates'][] = array(
438
+	foreach (array('spamming', 'offence', 'insulting') as $type) {
439
+			$context['notification_templates'][] = array(
429 440
 			'title' => $txt['profile_warning_notify_title_' . $type],
430 441
 			'body' => sprintf($txt['profile_warning_notify_template_outline' . (!empty($context['warning_for_message']) ? '_post' : '')], $txt['profile_warning_notify_for_' . $type]),
431 442
 		);
443
+	}
432 444
 
433 445
 	// Replace all the common variables in the templates.
434
-	foreach ($context['notification_templates'] as $k => $name)
435
-		$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
436
-}
446
+	foreach ($context['notification_templates'] as $k => $name) {
447
+			$context['notification_templates'][$k]['body'] = strtr($name['body'], array('{MEMBER}' => un_htmlspecialchars($context['member']['name']), '{MESSAGE}' => '[url=' . $scripturl . '?msg=' . $context['warning_for_message'] . ']' . un_htmlspecialchars($context['warned_message_subject']) . '[/url]', '{SCRIPTURL}' => $scripturl, '{FORUMNAME}' => $mbname, '{REGARDS}' => $txt['regards_team']));
448
+	}
449
+	}
437 450
 
438 451
 /**
439 452
  * Get the number of warnings a user has. Callback for $listOptions['get_count'] in issueWarning()
@@ -517,10 +530,11 @@  discard block
 block discarded – undo
517 530
 {
518 531
 	global $txt, $context, $modSettings, $cur_profile;
519 532
 
520
-	if (!$context['user']['is_owner'])
521
-		isAllowedTo('profile_remove_any');
522
-	elseif (!allowedTo('profile_remove_any'))
523
-		isAllowedTo('profile_remove_own');
533
+	if (!$context['user']['is_owner']) {
534
+			isAllowedTo('profile_remove_any');
535
+	} elseif (!allowedTo('profile_remove_any')) {
536
+			isAllowedTo('profile_remove_own');
537
+	}
524 538
 
525 539
 	// Permissions for removing stuff...
526 540
 	$context['can_delete_posts'] = !$context['user']['is_owner'] && allowedTo('moderate_forum');
@@ -547,10 +561,11 @@  discard block
 block discarded – undo
547 561
 
548 562
 	// @todo Add a way to delete pms as well?
549 563
 
550
-	if (!$context['user']['is_owner'])
551
-		isAllowedTo('profile_remove_any');
552
-	elseif (!allowedTo('profile_remove_any'))
553
-		isAllowedTo('profile_remove_own');
564
+	if (!$context['user']['is_owner']) {
565
+			isAllowedTo('profile_remove_any');
566
+	} elseif (!allowedTo('profile_remove_any')) {
567
+			isAllowedTo('profile_remove_own');
568
+	}
554 569
 
555 570
 	checkSession();
556 571
 
@@ -576,8 +591,9 @@  discard block
 block discarded – undo
576 591
 		list ($another) = $smcFunc['db_fetch_row']($request);
577 592
 		$smcFunc['db_free_result']($request);
578 593
 
579
-		if (empty($another))
580
-			fatal_lang_error('at_least_one_admin', 'critical');
594
+		if (empty($another)) {
595
+					fatal_lang_error('at_least_one_admin', 'critical');
596
+		}
581 597
 	}
582 598
 
583 599
 	// This file is needed for the deleteMembers function.
@@ -656,8 +672,9 @@  discard block
 block discarded – undo
656 672
 					)
657 673
 				);
658 674
 				$topicIDs = array();
659
-				while ($row = $smcFunc['db_fetch_assoc']($request))
660
-					$topicIDs[] = $row['id_topic'];
675
+				while ($row = $smcFunc['db_fetch_assoc']($request)) {
676
+									$topicIDs[] = $row['id_topic'];
677
+				}
661 678
 				$smcFunc['db_free_result']($request);
662 679
 
663 680
 				// Actually remove the topics. Ignore recycling if we want to perma-delete things...
@@ -680,8 +697,9 @@  discard block
 block discarded – undo
680 697
 			// This could take a while... but ya know it's gonna be worth it in the end.
681 698
 			while ($row = $smcFunc['db_fetch_assoc']($request))
682 699
 			{
683
-				if (function_exists('apache_reset_timeout'))
684
-					@apache_reset_timeout();
700
+				if (function_exists('apache_reset_timeout')) {
701
+									@apache_reset_timeout();
702
+				}
685 703
 
686 704
 				removeMessage($row['id_msg']);
687 705
 			}
@@ -689,8 +707,9 @@  discard block
 block discarded – undo
689 707
 		}
690 708
 
691 709
 		// Only delete this poor members account if they are actually being booted out of camp.
692
-		if (isset($_POST['deleteAccount']))
693
-			deleteMembers($memID);
710
+		if (isset($_POST['deleteAccount'])) {
711
+					deleteMembers($memID);
712
+		}
694 713
 	}
695 714
 	// Do they need approval to delete?
696 715
 	elseif (!empty($modSettings['approveAccountDeletion']) && !allowedTo('moderate_forum'))
@@ -741,18 +760,18 @@  discard block
 block discarded – undo
741 760
 		{
742 761
 			foreach ($costs as $duration => $cost)
743 762
 			{
744
-				if ($cost != 0)
745
-					$cost_array[$duration] = $cost;
763
+				if ($cost != 0) {
764
+									$cost_array[$duration] = $cost;
765
+				}
746 766
 			}
747
-		}
748
-		else
767
+		} else
749 768
 		{
750 769
 			$cost_array['fixed'] = $costs['fixed'];
751 770
 		}
752 771
 
753
-		if (empty($cost_array))
754
-			unset($context['subscriptions'][$id]);
755
-		else
772
+		if (empty($cost_array)) {
773
+					unset($context['subscriptions'][$id]);
774
+		} else
756 775
 		{
757 776
 			$context['subscriptions'][$id]['member'] = 0;
758 777
 			$context['subscriptions'][$id]['subscribed'] = false;
@@ -765,13 +784,15 @@  discard block
 block discarded – undo
765 784
 	foreach ($gateways as $id => $gateway)
766 785
 	{
767 786
 		$gateways[$id] = new $gateway['display_class']();
768
-		if (!$gateways[$id]->gatewayEnabled())
769
-			unset($gateways[$id]);
787
+		if (!$gateways[$id]->gatewayEnabled()) {
788
+					unset($gateways[$id]);
789
+		}
770 790
 	}
771 791
 
772 792
 	// No gateways yet?
773
-	if (empty($gateways))
774
-		fatal_error($txt['paid_admin_not_setup_gateway']);
793
+	if (empty($gateways)) {
794
+			fatal_error($txt['paid_admin_not_setup_gateway']);
795
+	}
775 796
 
776 797
 	// Get the current subscriptions.
777 798
 	$request = $smcFunc['db_query']('', '
@@ -786,8 +807,9 @@  discard block
 block discarded – undo
786 807
 	while ($row = $smcFunc['db_fetch_assoc']($request))
787 808
 	{
788 809
 		// The subscription must exist!
789
-		if (!isset($context['subscriptions'][$row['id_subscribe']]))
790
-			continue;
810
+		if (!isset($context['subscriptions'][$row['id_subscribe']])) {
811
+					continue;
812
+		}
791 813
 
792 814
 		$context['current'][$row['id_subscribe']] = array(
793 815
 			'id' => $row['id_sublog'],
@@ -801,8 +823,9 @@  discard block
 block discarded – undo
801 823
 			'status_text' => $row['status'] == 0 ? ($row['payments_pending'] ? $txt['paid_pending'] : $txt['paid_finished']) : $txt['paid_active'],
802 824
 		);
803 825
 
804
-		if ($row['status'] == 1)
805
-			$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
826
+		if ($row['status'] == 1) {
827
+					$context['subscriptions'][$row['id_subscribe']]['subscribed'] = true;
828
+		}
806 829
 	}
807 830
 	$smcFunc['db_free_result']($request);
808 831
 
@@ -853,21 +876,25 @@  discard block
 block discarded – undo
853 876
 	if (isset($_GET['confirm']) && isset($_POST['sub_id']) && is_array($_POST['sub_id']))
854 877
 	{
855 878
 		// Hopefully just one.
856
-		foreach ($_POST['sub_id'] as $k => $v)
857
-			$ID_SUB = (int) $k;
879
+		foreach ($_POST['sub_id'] as $k => $v) {
880
+					$ID_SUB = (int) $k;
881
+		}
858 882
 
859
-		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0)
860
-			fatal_lang_error('paid_sub_not_active');
883
+		if (!isset($context['subscriptions'][$ID_SUB]) || $context['subscriptions'][$ID_SUB]['active'] == 0) {
884
+					fatal_lang_error('paid_sub_not_active');
885
+		}
861 886
 
862 887
 		// Simplify...
863 888
 		$context['sub'] = $context['subscriptions'][$ID_SUB];
864 889
 		$period = 'xx';
865
-		if ($context['sub']['flexible'])
866
-			$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
890
+		if ($context['sub']['flexible']) {
891
+					$period = isset($_POST['cur'][$ID_SUB]) && isset($context['sub']['costs'][$_POST['cur'][$ID_SUB]]) ? $_POST['cur'][$ID_SUB] : 'xx';
892
+		}
867 893
 
868 894
 		// Check we have a valid cost.
869
-		if ($context['sub']['flexible'] && $period == 'xx')
870
-			fatal_lang_error('paid_sub_not_active');
895
+		if ($context['sub']['flexible'] && $period == 'xx') {
896
+					fatal_lang_error('paid_sub_not_active');
897
+		}
871 898
 
872 899
 		// Sort out the cost/currency.
873 900
 		$context['currency'] = $modSettings['paid_currency_code'];
@@ -880,8 +907,7 @@  discard block
 block discarded – undo
880 907
 			$context['cost'] = sprintf($modSettings['paid_currency_symbol'], $context['value']) . '/' . $txt[$_POST['cur'][$ID_SUB]];
881 908
 			// The period value for paypal.
882 909
 			$context['paypal_period'] = strtoupper(substr($_POST['cur'][$ID_SUB], 0, 1));
883
-		}
884
-		else
910
+		} else
885 911
 		{
886 912
 			// Real cost...
887 913
 			$context['value'] = $context['sub']['costs']['fixed'];
@@ -898,13 +924,15 @@  discard block
 block discarded – undo
898 924
 		foreach ($gateways as $id => $gateway)
899 925
 		{
900 926
 			$fields = $gateways[$id]->fetchGatewayFields($context['sub']['id'] . '+' . $memID, $context['sub'], $context['value'], $period, $scripturl . '?action=profile;u=' . $memID . ';area=subscriptions;sub_id=' . $context['sub']['id'] . ';done');
901
-			if (!empty($fields['form']))
902
-				$context['gateways'][] = $fields;
927
+			if (!empty($fields['form'])) {
928
+							$context['gateways'][] = $fields;
929
+			}
903 930
 		}
904 931
 
905 932
 		// Bugger?!
906
-		if (empty($context['gateways']))
907
-			fatal_error($txt['paid_admin_not_setup_gateway']);
933
+		if (empty($context['gateways'])) {
934
+					fatal_error($txt['paid_admin_not_setup_gateway']);
935
+		}
908 936
 
909 937
 		// Now we are going to assume they want to take this out ;)
910 938
 		$new_data = array($context['sub']['id'], $context['value'], $period, 'prepay');
@@ -912,16 +940,19 @@  discard block
 block discarded – undo
912 940
 		{
913 941
 			// What are the details like?
914 942
 			$current_pending = array();
915
-			if ($context['current'][$context['sub']['id']]['pending_details'] != '')
916
-				$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
943
+			if ($context['current'][$context['sub']['id']]['pending_details'] != '') {
944
+							$current_pending = $smcFunc['json_decode']($context['current'][$context['sub']['id']]['pending_details'], true);
945
+			}
917 946
 			// Don't get silly.
918
-			if (count($current_pending) > 9)
919
-				$current_pending = array();
947
+			if (count($current_pending) > 9) {
948
+							$current_pending = array();
949
+			}
920 950
 			$pending_count = 0;
921 951
 			// Only record real pending payments as will otherwise confuse the admin!
922
-			foreach ($current_pending as $pending)
923
-				if ($pending[3] == 'payback')
952
+			foreach ($current_pending as $pending) {
953
+							if ($pending[3] == 'payback')
924 954
 					$pending_count++;
955
+			}
925 956
 
926 957
 			if (!in_array($new_data, $current_pending))
927 958
 			{
@@ -966,9 +997,9 @@  discard block
 block discarded – undo
966 997
 
967 998
 		// Quit.
968 999
 		return;
1000
+	} else {
1001
+			$context['sub_template'] = 'user_subscription';
1002
+	}
969 1003
 	}
970
-	else
971
-		$context['sub_template'] = 'user_subscription';
972
-}
973 1004
 
974 1005
 ?>
975 1006
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Logging.php 1 patch
Braces   +140 added lines, -101 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
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
  * Truncate the GET array to a specified length
@@ -26,14 +27,15 @@  discard block
 block discarded – undo
26 27
 function truncateArray($arr, $max_length=1900)
27 28
 {
28 29
 	$curr_length = array_sum(array_map("strlen", $arr));
29
-	if ($curr_length <= $max_length)
30
-		return $arr;
31
-	else
30
+	if ($curr_length <= $max_length) {
31
+			return $arr;
32
+	} else
32 33
 	{
33 34
 		// Truncate each element's value to a reasonable length
34 35
 		$param_max = floor($max_length/count($arr));
35
-		foreach ($arr as $key => &$value)
36
-			$value = substr($value, 0, $param_max - strlen($key) - 5);
36
+		foreach ($arr as $key => &$value) {
37
+					$value = substr($value, 0, $param_max - strlen($key) - 5);
38
+		}
37 39
 		return $arr;
38 40
 	}
39 41
 }
@@ -55,8 +57,9 @@  discard block
 block discarded – undo
55 57
 		// Don't update for every page - this isn't wholly accurate but who cares.
56 58
 		if ($topic)
57 59
 		{
58
-			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic)
59
-				$force = false;
60
+			if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) {
61
+							$force = false;
62
+			}
60 63
 			$_SESSION['last_topic_id'] = $topic;
61 64
 		}
62 65
 	}
@@ -69,22 +72,24 @@  discard block
 block discarded – undo
69 72
 	}
70 73
 
71 74
 	// Don't mark them as online more than every so often.
72
-	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force)
73
-		return;
75
+	if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) {
76
+			return;
77
+	}
74 78
 
75 79
 	if (!empty($modSettings['who_enabled']))
76 80
 	{
77 81
 		$encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
78 82
 
79 83
 		// In the case of a dlattach action, session_var may not be set.
80
-		if (!isset($context['session_var']))
81
-			$context['session_var'] = $_SESSION['session_var'];
84
+		if (!isset($context['session_var'])) {
85
+					$context['session_var'] = $_SESSION['session_var'];
86
+		}
82 87
 
83 88
 		unset($encoded_get['sesc'], $encoded_get[$context['session_var']]);
84 89
 		$encoded_get = $smcFunc['json_encode']($encoded_get);
90
+	} else {
91
+			$encoded_get = '';
85 92
 	}
86
-	else
87
-		$encoded_get = '';
88 93
 
89 94
 	// Guests use 0, members use their session ID.
90 95
 	$session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id();
@@ -124,17 +129,18 @@  discard block
 block discarded – undo
124 129
 		);
125 130
 
126 131
 		// Guess it got deleted.
127
-		if ($smcFunc['db_affected_rows']() == 0)
132
+		if ($smcFunc['db_affected_rows']() == 0) {
133
+					$_SESSION['log_time'] = 0;
134
+		}
135
+	} else {
128 136
 			$_SESSION['log_time'] = 0;
129 137
 	}
130
-	else
131
-		$_SESSION['log_time'] = 0;
132 138
 
133 139
 	// Otherwise, we have to delete and insert.
134 140
 	if (empty($_SESSION['log_time']))
135 141
 	{
136
-		if ($do_delete || !empty($user_info['id']))
137
-			$smcFunc['db_query']('', '
142
+		if ($do_delete || !empty($user_info['id'])) {
143
+					$smcFunc['db_query']('', '
138 144
 				DELETE FROM {db_prefix}log_online
139 145
 				WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'),
140 146
 				array(
@@ -142,6 +148,7 @@  discard block
 block discarded – undo
142 148
 					'log_time' => time() - $modSettings['lastActive'] * 60,
143 149
 				)
144 150
 			);
151
+		}
145 152
 
146 153
 		$smcFunc['db_insert']($do_delete ? 'ignore' : 'replace',
147 154
 			'{db_prefix}log_online',
@@ -155,21 +162,24 @@  discard block
 block discarded – undo
155 162
 	$_SESSION['log_time'] = time();
156 163
 
157 164
 	// Well, they are online now.
158
-	if (empty($_SESSION['timeOnlineUpdated']))
159
-		$_SESSION['timeOnlineUpdated'] = time();
165
+	if (empty($_SESSION['timeOnlineUpdated'])) {
166
+			$_SESSION['timeOnlineUpdated'] = time();
167
+	}
160 168
 
161 169
 	// Set their login time, if not already done within the last minute.
162 170
 	if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa'))))
163 171
 	{
164 172
 		// Don't count longer than 15 minutes.
165
-		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
166
-			$_SESSION['timeOnlineUpdated'] = time();
173
+		if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) {
174
+					$_SESSION['timeOnlineUpdated'] = time();
175
+		}
167 176
 
168 177
 		$user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
169 178
 		updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in']));
170 179
 
171
-		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
172
-			cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
180
+		if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
181
+					cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60);
182
+		}
173 183
 
174 184
 		$user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
175 185
 		$_SESSION['timeOnlineUpdated'] = time();
@@ -206,8 +216,7 @@  discard block
 block discarded – undo
206 216
 			// Oops. maybe we have no more disk space left, or some other troubles, troubles...
207 217
 			// Copy the file back and run for your life!
208 218
 			@copy($boarddir . '/db_last_error_bak.php', $boarddir . '/db_last_error.php');
209
-		}
210
-		else
219
+		} else
211 220
 		{
212 221
 			@touch($boarddir . '/' . 'Settings.php');
213 222
 			return true;
@@ -227,22 +236,27 @@  discard block
 block discarded – undo
227 236
 	global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt;
228 237
 
229 238
 	// Add to Settings.php if you want to show the debugging information.
230
-	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery'))
231
-		return;
239
+	if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) {
240
+			return;
241
+	}
232 242
 
233
-	if (empty($_SESSION['view_queries']))
234
-		$_SESSION['view_queries'] = 0;
235
-	if (empty($context['debug']['language_files']))
236
-		$context['debug']['language_files'] = array();
237
-	if (empty($context['debug']['sheets']))
238
-		$context['debug']['sheets'] = array();
243
+	if (empty($_SESSION['view_queries'])) {
244
+			$_SESSION['view_queries'] = 0;
245
+	}
246
+	if (empty($context['debug']['language_files'])) {
247
+			$context['debug']['language_files'] = array();
248
+	}
249
+	if (empty($context['debug']['sheets'])) {
250
+			$context['debug']['sheets'] = array();
251
+	}
239 252
 
240 253
 	$files = get_included_files();
241 254
 	$total_size = 0;
242 255
 	for ($i = 0, $n = count($files); $i < $n; $i++)
243 256
 	{
244
-		if (file_exists($files[$i]))
245
-			$total_size += filesize($files[$i]);
257
+		if (file_exists($files[$i])) {
258
+					$total_size += filesize($files[$i]);
259
+		}
246 260
 		$files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)'));
247 261
 	}
248 262
 
@@ -251,8 +265,9 @@  discard block
 block discarded – undo
251 265
 	{
252 266
 		foreach ($db_cache as $q => $qq)
253 267
 		{
254
-			if (!empty($qq['w']))
255
-				$warnings += count($qq['w']);
268
+			if (!empty($qq['w'])) {
269
+							$warnings += count($qq['w']);
270
+			}
256 271
 		}
257 272
 
258 273
 		$_SESSION['debug'] = &$db_cache;
@@ -273,12 +288,14 @@  discard block
 block discarded – undo
273 288
 	',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),'
274 289
 	', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>';
275 290
 
276
-	if (function_exists('memory_get_peak_usage'))
277
-		echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
291
+	if (function_exists('memory_get_peak_usage')) {
292
+			echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>';
293
+	}
278 294
 
279 295
 	// What tokens are active?
280
-	if (isset($_SESSION['token']))
281
-		echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
296
+	if (isset($_SESSION['token'])) {
297
+			echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>';
298
+	}
282 299
 
283 300
 	if (!empty($modSettings['cache_enable']) && !empty($cache_hits))
284 301
 	{
@@ -292,10 +309,12 @@  discard block
 block discarded – undo
292 309
 			$total_t += $cache_hit['t'];
293 310
 			$total_s += $cache_hit['s'];
294 311
 		}
295
-		if (!isset($cache_misses))
296
-			$cache_misses = array();
297
-		foreach ($cache_misses as $missed)
298
-			$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
312
+		if (!isset($cache_misses)) {
313
+					$cache_misses = array();
314
+		}
315
+		foreach ($cache_misses as $missed) {
316
+					$missed_entries[] = $missed['d'] . ' ' . $missed['k'];
317
+		}
299 318
 
300 319
 		echo '
301 320
 	', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br>
@@ -306,38 +325,44 @@  discard block
 block discarded – undo
306 325
 	<a href="', $scripturl, '?action=viewquery" target="_blank">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br>
307 326
 	<br>';
308 327
 
309
-	if ($_SESSION['view_queries'] == 1 && !empty($db_cache))
310
-		foreach ($db_cache as $q => $qq)
328
+	if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) {
329
+			foreach ($db_cache as $q => $qq)
311 330
 		{
312 331
 			$is_select = strpos(trim($qq['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0;
332
+	}
313 333
 			// Temporary tables created in earlier queries are not explainable.
314 334
 			if ($is_select)
315 335
 			{
316
-				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp)
317
-					if (strpos(trim($qq['q']), $tmp) !== false)
336
+				foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) {
337
+									if (strpos(trim($qq['q']), $tmp) !== false)
318 338
 					{
319 339
 						$is_select = false;
340
+				}
320 341
 						break;
321 342
 					}
322 343
 			}
323 344
 			// But actual creation of the temporary tables are.
324
-			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0)
325
-				$is_select = true;
345
+			elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) {
346
+							$is_select = true;
347
+			}
326 348
 
327 349
 			// Make the filenames look a bit better.
328
-			if (isset($qq['f']))
329
-				$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
350
+			if (isset($qq['f'])) {
351
+							$qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']);
352
+			}
330 353
 
331 354
 			echo '
332 355
 	<strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" style="text-decoration: none;">' : '', nl2br(str_replace("\t", '&nbsp;&nbsp;&nbsp;', $smcFunc['htmlspecialchars'](ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br>
333 356
 	&nbsp;&nbsp;&nbsp;';
334
-			if (!empty($qq['f']) && !empty($qq['l']))
335
-				echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
357
+			if (!empty($qq['f']) && !empty($qq['l'])) {
358
+							echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']);
359
+			}
336 360
 
337
-			if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at']))
338
-				echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>';
339
-			elseif (isset($qq['t']))
340
-				echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>';
361
+			if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) {
362
+							echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>';
363
+			} elseif (isset($qq['t'])) {
364
+							echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>';
365
+			}
341 366
 			echo '
342 367
 	<br>';
343 368
 		}
@@ -362,12 +387,14 @@  discard block
 block discarded – undo
362 387
 	global $modSettings, $smcFunc;
363 388
 	static $cache_stats = array();
364 389
 
365
-	if (empty($modSettings['trackStats']))
366
-		return false;
367
-	if (!empty($stats))
368
-		return $cache_stats = array_merge($cache_stats, $stats);
369
-	elseif (empty($cache_stats))
370
-		return false;
390
+	if (empty($modSettings['trackStats'])) {
391
+			return false;
392
+	}
393
+	if (!empty($stats)) {
394
+			return $cache_stats = array_merge($cache_stats, $stats);
395
+	} elseif (empty($cache_stats)) {
396
+			return false;
397
+	}
371 398
 
372 399
 	$setStringUpdate = '';
373 400
 	$insert_keys = array();
@@ -380,10 +407,11 @@  discard block
 block discarded – undo
380 407
 		$setStringUpdate .= '
381 408
 			' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ',';
382 409
 
383
-		if ($change === '+')
384
-			$cache_stats[$field] = 1;
385
-		else
386
-			$update_parameters[$field] = $change;
410
+		if ($change === '+') {
411
+					$cache_stats[$field] = 1;
412
+		} else {
413
+					$update_parameters[$field] = $change;
414
+		}
387 415
 		$insert_keys[$field] = 'int';
388 416
 	}
389 417
 
@@ -447,43 +475,50 @@  discard block
 block discarded – undo
447 475
 	);
448 476
 
449 477
 	// Make sure this particular log is enabled first...
450
-	if (empty($modSettings['modlog_enabled']))
451
-		unset ($log_types['moderate']);
452
-	if (empty($modSettings['userlog_enabled']))
453
-		unset ($log_types['user']);
454
-	if (empty($modSettings['adminlog_enabled']))
455
-		unset ($log_types['admin']);
478
+	if (empty($modSettings['modlog_enabled'])) {
479
+			unset ($log_types['moderate']);
480
+	}
481
+	if (empty($modSettings['userlog_enabled'])) {
482
+			unset ($log_types['user']);
483
+	}
484
+	if (empty($modSettings['adminlog_enabled'])) {
485
+			unset ($log_types['admin']);
486
+	}
456 487
 
457 488
 	call_integration_hook('integrate_log_types', array(&$log_types));
458 489
 
459 490
 	foreach ($logs as $log)
460 491
 	{
461
-		if (!isset($log_types[$log['log_type']]))
462
-			return false;
492
+		if (!isset($log_types[$log['log_type']])) {
493
+					return false;
494
+		}
463 495
 
464
-		if (!is_array($log['extra']))
465
-			trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
496
+		if (!is_array($log['extra'])) {
497
+					trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE);
498
+		}
466 499
 
467 500
 		// Pull out the parts we want to store separately, but also make sure that the data is proper
468 501
 		if (isset($log['extra']['topic']))
469 502
 		{
470
-			if (!is_numeric($log['extra']['topic']))
471
-				trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
503
+			if (!is_numeric($log['extra']['topic'])) {
504
+							trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE);
505
+			}
472 506
 			$topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic'];
473 507
 			unset($log['extra']['topic']);
508
+		} else {
509
+					$topic_id = 0;
474 510
 		}
475
-		else
476
-			$topic_id = 0;
477 511
 
478 512
 		if (isset($log['extra']['message']))
479 513
 		{
480
-			if (!is_numeric($log['extra']['message']))
481
-				trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
514
+			if (!is_numeric($log['extra']['message'])) {
515
+							trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE);
516
+			}
482 517
 			$msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message'];
483 518
 			unset($log['extra']['message']);
519
+		} else {
520
+					$msg_id = 0;
484 521
 		}
485
-		else
486
-			$msg_id = 0;
487 522
 
488 523
 		// @todo cache this?
489 524
 		// Is there an associated report on this?
@@ -510,23 +545,26 @@  discard block
 block discarded – undo
510 545
 			$smcFunc['db_free_result']($request);
511 546
 		}
512 547
 
513
-		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member']))
514
-			trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
548
+		if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) {
549
+					trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE);
550
+		}
515 551
 
516 552
 		if (isset($log['extra']['board']))
517 553
 		{
518
-			if (!is_numeric($log['extra']['board']))
519
-				trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
554
+			if (!is_numeric($log['extra']['board'])) {
555
+							trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE);
556
+			}
520 557
 			$board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board'];
521 558
 			unset($log['extra']['board']);
559
+		} else {
560
+					$board_id = 0;
522 561
 		}
523
-		else
524
-			$board_id = 0;
525 562
 
526 563
 		if (isset($log['extra']['board_to']))
527 564
 		{
528
-			if (!is_numeric($log['extra']['board_to']))
529
-				trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
565
+			if (!is_numeric($log['extra']['board_to'])) {
566
+							trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE);
567
+			}
530 568
 			if (empty($board_id))
531 569
 			{
532 570
 				$board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to'];
@@ -534,10 +572,11 @@  discard block
 block discarded – undo
534 572
 			}
535 573
 		}
536 574
 
537
-		if (isset($log['extra']['member_affected']))
538
-			$memID = $log['extra']['member_affected'];
539
-		else
540
-			$memID = $user_info['id'];
575
+		if (isset($log['extra']['member_affected'])) {
576
+					$memID = $log['extra']['member_affected'];
577
+		} else {
578
+					$memID = $user_info['id'];
579
+		}
541 580
 
542 581
 		$inserts[] = array(
543 582
 			time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'],
Please login to merge, or discard this patch.
Sources/ManageMembers.php 1 patch
Braces   +158 added lines, -116 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * The main entrance point for the Manage Members screen.
@@ -62,16 +63,18 @@  discard block
 block discarded – undo
62 63
 	$context['activation_numbers'] = array();
63 64
 	$context['awaiting_activation'] = 0;
64 65
 	$context['awaiting_approval'] = 0;
65
-	while ($row = $smcFunc['db_fetch_assoc']($request))
66
-		$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
66
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
67
+			$context['activation_numbers'][$row['is_activated']] = $row['total_members'];
68
+	}
67 69
 	$smcFunc['db_free_result']($request);
68 70
 
69 71
 	foreach ($context['activation_numbers'] as $activation_type => $total_members)
70 72
 	{
71
-		if (in_array($activation_type, array(0, 2)))
72
-			$context['awaiting_activation'] += $total_members;
73
-		elseif (in_array($activation_type, array(3, 4, 5)))
74
-			$context['awaiting_approval'] += $total_members;
73
+		if (in_array($activation_type, array(0, 2))) {
74
+					$context['awaiting_activation'] += $total_members;
75
+		} elseif (in_array($activation_type, array(3, 4, 5))) {
76
+					$context['awaiting_approval'] += $total_members;
77
+		}
75 78
 	}
76 79
 
77 80
 	// For the page header... do we show activation?
@@ -124,8 +127,9 @@  discard block
 block discarded – undo
124 127
 	}
125 128
 	if (!$context['show_approve'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'approve'))
126 129
 	{
127
-		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate'))
128
-			$context['tabs']['search']['is_last'] = true;
130
+		if (!$context['show_activate'] && ($_REQUEST['sa'] != 'browse' || $_REQUEST['type'] != 'activate')) {
131
+					$context['tabs']['search']['is_last'] = true;
132
+		}
129 133
 		unset($context['tabs']['approve']);
130 134
 	}
131 135
 
@@ -157,8 +161,9 @@  discard block
 block discarded – undo
157 161
 		foreach ($_POST['delete'] as $key => $value)
158 162
 		{
159 163
 			// Don't delete yourself, idiot.
160
-			if ($value != $user_info['id'])
161
-				$delete[$key] = (int) $value;
164
+			if ($value != $user_info['id']) {
165
+							$delete[$key] = (int) $value;
166
+			}
162 167
 		}
163 168
 
164 169
 		if (!empty($delete))
@@ -194,17 +199,18 @@  discard block
 block discarded – undo
194 199
 		);
195 200
 		while ($row = $smcFunc['db_fetch_assoc']($request))
196 201
 		{
197
-			if ($row['min_posts'] == -1)
198
-				$context['membergroups'][] = array(
202
+			if ($row['min_posts'] == -1) {
203
+							$context['membergroups'][] = array(
199 204
 					'id' => $row['id_group'],
200 205
 					'name' => $row['group_name'],
201 206
 					'can_be_additional' => true
202 207
 				);
203
-			else
204
-				$context['postgroups'][] = array(
208
+			} else {
209
+							$context['postgroups'][] = array(
205 210
 					'id' => $row['id_group'],
206 211
 					'name' => $row['group_name']
207 212
 				);
213
+			}
208 214
 		}
209 215
 		$smcFunc['db_free_result']($request);
210 216
 
@@ -268,14 +274,15 @@  discard block
 block discarded – undo
268 274
 		call_integration_hook('integrate_view_members_params', array(&$params));
269 275
 
270 276
 		$search_params = array();
271
-		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types']))
272
-			$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
273
-		elseif (!empty($_POST))
277
+		if ($context['sub_action'] == 'query' && !empty($_REQUEST['params']) && empty($_POST['types'])) {
278
+					$search_params = $smcFunc['json_decode'](base64_decode($_REQUEST['params']), true);
279
+		} elseif (!empty($_POST))
274 280
 		{
275 281
 			$search_params['types'] = $_POST['types'];
276
-			foreach ($params as $param_name => $param_info)
277
-				if (isset($_POST[$param_name]))
282
+			foreach ($params as $param_name => $param_info) {
283
+							if (isset($_POST[$param_name]))
278 284
 					$search_params[$param_name] = $_POST[$param_name];
285
+			}
279 286
 		}
280 287
 
281 288
 		$search_url_params = isset($search_params) ? base64_encode($smcFunc['json_encode']($search_params)) : null;
@@ -288,18 +295,21 @@  discard block
 block discarded – undo
288 295
 		foreach ($params as $param_name => $param_info)
289 296
 		{
290 297
 			// Not filled in?
291
-			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '')
292
-				continue;
298
+			if (!isset($search_params[$param_name]) || $search_params[$param_name] === '') {
299
+							continue;
300
+			}
293 301
 
294 302
 			// Make sure numeric values are really numeric.
295
-			if (in_array($param_info['type'], array('int', 'age')))
296
-				$search_params[$param_name] = (int) $search_params[$param_name];
303
+			if (in_array($param_info['type'], array('int', 'age'))) {
304
+							$search_params[$param_name] = (int) $search_params[$param_name];
305
+			}
297 306
 			// Date values have to match the specified format.
298 307
 			elseif ($param_info['type'] == 'date')
299 308
 			{
300 309
 				// Check if this date format is valid.
301
-				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
302
-					continue;
310
+				if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0) {
311
+									continue;
312
+				}
303 313
 
304 314
 				$search_params[$param_name] = strtotime($search_params[$param_name]);
305 315
 			}
@@ -308,8 +318,9 @@  discard block
 block discarded – undo
308 318
 			if (!empty($param_info['range']))
309 319
 			{
310 320
 				// Default to '=', just in case...
311
-				if (empty($range_trans[$search_params['types'][$param_name]]))
312
-					$search_params['types'][$param_name] = '=';
321
+				if (empty($range_trans[$search_params['types'][$param_name]])) {
322
+									$search_params['types'][$param_name] = '=';
323
+				}
313 324
 
314 325
 				// Handle special case 'age'.
315 326
 				if ($param_info['type'] == 'age')
@@ -337,29 +348,30 @@  discard block
 block discarded – undo
337 348
 				elseif ($param_info['type'] == 'date' && $search_params['types'][$param_name] == '=')
338 349
 				{
339 350
 					$query_parts[] = $param_info['db_fields'][0] . ' > ' . $search_params[$param_name] . ' AND ' . $param_info['db_fields'][0] . ' < ' . ($search_params[$param_name] + 86400);
351
+				} else {
352
+									$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
340 353
 				}
341
-				else
342
-					$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
343 354
 			}
344 355
 			// Checkboxes.
345 356
 			elseif ($param_info['type'] == 'checkbox')
346 357
 			{
347 358
 				// Each checkbox or no checkbox at all is checked -> ignore.
348
-				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values']))
349
-					continue;
359
+				if (!is_array($search_params[$param_name]) || count($search_params[$param_name]) == 0 || count($search_params[$param_name]) == count($param_info['values'])) {
360
+									continue;
361
+				}
350 362
 
351 363
 				$query_parts[] = ($param_info['db_fields'][0]) . ' IN ({array_string:' . $param_name . '_check})';
352 364
 				$where_params[$param_name . '_check'] = $search_params[$param_name];
353
-			}
354
-			else
365
+			} else
355 366
 			{
356 367
 				// Replace the wildcard characters ('*' and '?') into MySQL ones.
357 368
 				$parameter = strtolower(strtr($smcFunc['htmlspecialchars']($search_params[$param_name], ENT_QUOTES), array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_')));
358 369
 
359
-				if ($smcFunc['db_case_sensitive'])
360
-					$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
361
-				else
362
-					$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
370
+				if ($smcFunc['db_case_sensitive']) {
371
+									$query_parts[] = '(LOWER(' . implode(') LIKE {string:' . $param_name . '_normal} OR LOWER(', $param_info['db_fields']) . ') LIKE {string:' . $param_name . '_normal})';
372
+				} else {
373
+									$query_parts[] = '(' . implode(' LIKE {string:' . $param_name . '_normal} OR ', $param_info['db_fields']) . ' LIKE {string:' . $param_name . '_normal})';
374
+				}
363 375
 				$where_params[$param_name . '_normal'] = '%' . $parameter . '%';
364 376
 			}
365 377
 		}
@@ -375,16 +387,18 @@  discard block
 block discarded – undo
375 387
 		}
376 388
 
377 389
 		// Additional membergroups (these are only relevant if not all primary groups where selected!).
378
-		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1])))
379
-			foreach ($search_params['membergroups'][2] as $mg)
390
+		if (!empty($search_params['membergroups'][2]) && (empty($search_params['membergroups'][1]) || count($context['membergroups']) != count($search_params['membergroups'][1]))) {
391
+					foreach ($search_params['membergroups'][2] as $mg)
380 392
 			{
381 393
 				$mg_query_parts[] = 'FIND_IN_SET({int:add_group_' . $mg . '}, mem.additional_groups) != 0';
394
+		}
382 395
 				$where_params['add_group_' . $mg] = $mg;
383 396
 			}
384 397
 
385 398
 		// Combine the one or two membergroup parts into one query part linked with an OR.
386
-		if (!empty($mg_query_parts))
387
-			$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
399
+		if (!empty($mg_query_parts)) {
400
+					$query_parts[] = '(' . implode(' OR ', $mg_query_parts) . ')';
401
+		}
388 402
 
389 403
 		// Get all selected post count related membergroups.
390 404
 		if (!empty($search_params['postgroups']) && count($search_params['postgroups']) != count($context['postgroups']))
@@ -396,9 +410,9 @@  discard block
 block discarded – undo
396 410
 		// Construct the where part of the query.
397 411
 		$where = empty($query_parts) ? '1=1' : implode('
398 412
 			AND ', $query_parts);
413
+	} else {
414
+			$search_url_params = null;
399 415
 	}
400
-	else
401
-		$search_url_params = null;
402 416
 
403 417
 	// Construct the additional URL part with the query info in it.
404 418
 	$context['params_url'] = $context['sub_action'] == 'query' ? ';sa=query;params=' . $search_url_params : '';
@@ -521,28 +535,32 @@  discard block
 block discarded – undo
521 535
 					'function' => function($rowData) use ($txt)
522 536
 					{
523 537
 						// Calculate number of days since last online.
524
-						if (empty($rowData['last_login']))
525
-							$difference = $txt['never'];
526
-						else
538
+						if (empty($rowData['last_login'])) {
539
+													$difference = $txt['never'];
540
+						} else
527 541
 						{
528 542
 							$num_days_difference = jeffsdatediff($rowData['last_login']);
529 543
 
530 544
 							// Today.
531
-							if (empty($num_days_difference))
532
-								$difference = $txt['viewmembers_today'];
545
+							if (empty($num_days_difference)) {
546
+															$difference = $txt['viewmembers_today'];
547
+							}
533 548
 
534 549
 							// Yesterday.
535
-							elseif ($num_days_difference == 1)
536
-								$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
550
+							elseif ($num_days_difference == 1) {
551
+															$difference = sprintf('1 %1$s', $txt['viewmembers_day_ago']);
552
+							}
537 553
 
538 554
 							// X days ago.
539
-							else
540
-								$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
555
+							else {
556
+															$difference = sprintf('%1$d %2$s', $num_days_difference, $txt['viewmembers_days_ago']);
557
+							}
541 558
 						}
542 559
 
543 560
 						// Show it in italics if they're not activated...
544
-						if ($rowData['is_activated'] % 10 != 1)
545
-							$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
561
+						if ($rowData['is_activated'] % 10 != 1) {
562
+													$difference = sprintf('<em title="%1$s">%2$s</em>', $txt['not_activated'], $difference);
563
+						}
546 564
 
547 565
 						return $difference;
548 566
 					},
@@ -594,8 +612,9 @@  discard block
 block discarded – undo
594 612
 	);
595 613
 
596 614
 	// Without enough permissions, don't show 'delete members' checkboxes.
597
-	if (!allowedTo('profile_remove_any'))
598
-		unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
615
+	if (!allowedTo('profile_remove_any')) {
616
+			unset($listOptions['cols']['check'], $listOptions['form'], $listOptions['additional_rows']);
617
+	}
599 618
 
600 619
 	require_once($sourcedir . '/Subs-List.php');
601 620
 	createList($listOptions);
@@ -638,17 +657,18 @@  discard block
 block discarded – undo
638 657
 	);
639 658
 	while ($row = $smcFunc['db_fetch_assoc']($request))
640 659
 	{
641
-		if ($row['min_posts'] == -1)
642
-			$context['membergroups'][] = array(
660
+		if ($row['min_posts'] == -1) {
661
+					$context['membergroups'][] = array(
643 662
 				'id' => $row['id_group'],
644 663
 				'name' => $row['group_name'],
645 664
 				'can_be_additional' => true
646 665
 			);
647
-		else
648
-			$context['postgroups'][] = array(
666
+		} else {
667
+					$context['postgroups'][] = array(
649 668
 				'id' => $row['id_group'],
650 669
 				'name' => $row['group_name']
651 670
 			);
671
+		}
652 672
 	}
653 673
 	$smcFunc['db_free_result']($request);
654 674
 
@@ -675,8 +695,9 @@  discard block
 block discarded – undo
675 695
 	$context['page_title'] = $txt['admin_members'];
676 696
 	$context['sub_template'] = 'admin_browse';
677 697
 	$context['browse_type'] = isset($_REQUEST['type']) ? $_REQUEST['type'] : (!empty($modSettings['registration_method']) && $modSettings['registration_method'] == 1 ? 'activate' : 'approve');
678
-	if (isset($context['tabs'][$context['browse_type']]))
679
-		$context['tabs'][$context['browse_type']]['is_selected'] = true;
698
+	if (isset($context['tabs'][$context['browse_type']])) {
699
+			$context['tabs'][$context['browse_type']]['is_selected'] = true;
700
+	}
680 701
 
681 702
 	// Allowed filters are those we can have, in theory.
682 703
 	$context['allowed_filters'] = $context['browse_type'] == 'approve' ? array(3, 4, 5) : array(0, 2);
@@ -687,18 +708,20 @@  discard block
 block discarded – undo
687 708
 	foreach ($context['activation_numbers'] as $type => $amount)
688 709
 	{
689 710
 		// We have some of these...
690
-		if (in_array($type, $context['allowed_filters']) && $amount > 0)
691
-			$context['available_filters'][] = array(
711
+		if (in_array($type, $context['allowed_filters']) && $amount > 0) {
712
+					$context['available_filters'][] = array(
692 713
 				'type' => $type,
693 714
 				'amount' => $amount,
694 715
 				'desc' => isset($txt['admin_browse_filter_type_' . $type]) ? $txt['admin_browse_filter_type_' . $type] : '?',
695 716
 				'selected' => $type == $context['current_filter']
696 717
 			);
718
+		}
697 719
 	}
698 720
 
699 721
 	// If the filter was not sent, set it to whatever has people in it!
700
-	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount']))
701
-		$context['current_filter'] = $context['available_filters'][0]['type'];
722
+	if ($context['current_filter'] == -1 && !empty($context['available_filters'][0]['amount'])) {
723
+			$context['current_filter'] = $context['available_filters'][0]['type'];
724
+	}
702 725
 
703 726
 	// This little variable is used to determine if we should flag where we are looking.
704 727
 	$context['show_filter'] = ($context['current_filter'] != 0 && $context['current_filter'] != 3) || count($context['available_filters']) > 1;
@@ -713,44 +736,47 @@  discard block
 block discarded – undo
713 736
 	);
714 737
 
715 738
 	// Are we showing duplicate information?
716
-	if (isset($_GET['showdupes']))
717
-		$_SESSION['showdupes'] = (int) $_GET['showdupes'];
739
+	if (isset($_GET['showdupes'])) {
740
+			$_SESSION['showdupes'] = (int) $_GET['showdupes'];
741
+	}
718 742
 	$context['show_duplicates'] = !empty($_SESSION['showdupes']);
719 743
 
720 744
 	// Determine which actions we should allow on this page.
721 745
 	if ($context['browse_type'] == 'approve')
722 746
 	{
723 747
 		// If we are approving deleted accounts we have a slightly different list... actually a mirror ;)
724
-		if ($context['current_filter'] == 4)
725
-			$context['allowed_actions'] = array(
748
+		if ($context['current_filter'] == 4) {
749
+					$context['allowed_actions'] = array(
726 750
 				'reject' => $txt['admin_browse_w_approve_deletion'],
727 751
 				'ok' => $txt['admin_browse_w_reject'],
728 752
 			);
729
-		else
730
-			$context['allowed_actions'] = array(
753
+		} else {
754
+					$context['allowed_actions'] = array(
731 755
 				'ok' => $txt['admin_browse_w_approve'],
732 756
 				'okemail' => $txt['admin_browse_w_approve'] . ' ' . $txt['admin_browse_w_email'],
733 757
 				'require_activation' => $txt['admin_browse_w_approve_require_activate'],
734 758
 				'reject' => $txt['admin_browse_w_reject'],
735 759
 				'rejectemail' => $txt['admin_browse_w_reject'] . ' ' . $txt['admin_browse_w_email'],
736 760
 			);
737
-	}
738
-	elseif ($context['browse_type'] == 'activate')
739
-		$context['allowed_actions'] = array(
761
+		}
762
+	} elseif ($context['browse_type'] == 'activate') {
763
+			$context['allowed_actions'] = array(
740 764
 			'ok' => $txt['admin_browse_w_activate'],
741 765
 			'okemail' => $txt['admin_browse_w_activate'] . ' ' . $txt['admin_browse_w_email'],
742 766
 			'delete' => $txt['admin_browse_w_delete'],
743 767
 			'deleteemail' => $txt['admin_browse_w_delete'] . ' ' . $txt['admin_browse_w_email'],
744 768
 			'remind' => $txt['admin_browse_w_remind'] . ' ' . $txt['admin_browse_w_email'],
745 769
 		);
770
+	}
746 771
 
747 772
 	// Create an option list for actions allowed to be done with selected members.
748 773
 	$allowed_actions = '
749 774
 			<option selected value="">' . $txt['admin_browse_with_selected'] . ':</option>
750 775
 			<option value="" disabled>-----------------------------</option>';
751
-	foreach ($context['allowed_actions'] as $key => $desc)
752
-		$allowed_actions .= '
776
+	foreach ($context['allowed_actions'] as $key => $desc) {
777
+			$allowed_actions .= '
753 778
 			<option value="' . $key . '">' . $desc . '</option>';
779
+	}
754 780
 
755 781
 	// Setup the Javascript function for selecting an action for the list.
756 782
 	$javascript = '
@@ -762,15 +788,16 @@  discard block
 block discarded – undo
762 788
 			var message = "";';
763 789
 
764 790
 	// We have special messages for approving deletion of accounts - it's surprisingly logical - honest.
765
-	if ($context['current_filter'] == 4)
766
-		$javascript .= '
791
+	if ($context['current_filter'] == 4) {
792
+			$javascript .= '
767 793
 			if (document.forms.postForm.todo.value.indexOf("reject") != -1)
768 794
 				message = "' . $txt['admin_browse_w_delete'] . '";
769 795
 			else
770 796
 				message = "' . $txt['admin_browse_w_reject'] . '";';
797
+	}
771 798
 	// Otherwise a nice standard message.
772
-	else
773
-		$javascript .= '
799
+	else {
800
+			$javascript .= '
774 801
 			if (document.forms.postForm.todo.value.indexOf("delete") != -1)
775 802
 				message = "' . $txt['admin_browse_w_delete'] . '";
776 803
 			else if (document.forms.postForm.todo.value.indexOf("reject") != -1)
@@ -779,6 +806,7 @@  discard block
 block discarded – undo
779 806
 				message = "' . $txt['admin_browse_w_remind'] . '";
780 807
 			else
781 808
 				message = "' . ($context['browse_type'] == 'approve' ? $txt['admin_browse_w_approve'] : $txt['admin_browse_w_activate']) . '";';
809
+	}
782 810
 	$javascript .= '
783 811
 			if (confirm(message + " ' . $txt['admin_browse_warn'] . '"))
784 812
 				document.forms.postForm.submit();
@@ -911,10 +939,11 @@  discard block
 block discarded – undo
911 939
 						$member_links = array();
912 940
 						foreach ($rowData['duplicate_members'] as $member)
913 941
 						{
914
-							if ($member['id'])
915
-								$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
916
-							else
917
-								$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
942
+							if ($member['id']) {
943
+															$member_links[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '" ' . (!empty($member['is_banned']) ? 'class="red"' : '') . '>' . $member['name'] . '</a>';
944
+							} else {
945
+															$member_links[] = $member['name'] . ' (' . $txt['guest'] . ')';
946
+							}
918 947
 						}
919 948
 						return implode(', ', $member_links);
920 949
 					},
@@ -963,14 +992,16 @@  discard block
 block discarded – undo
963 992
 	);
964 993
 
965 994
 	// Pick what column to actually include if we're showing duplicates.
966
-	if ($context['show_duplicates'])
967
-		unset($listOptions['columns']['email']);
968
-	else
969
-		unset($listOptions['columns']['duplicates']);
995
+	if ($context['show_duplicates']) {
996
+			unset($listOptions['columns']['email']);
997
+	} else {
998
+			unset($listOptions['columns']['duplicates']);
999
+	}
970 1000
 
971 1001
 	// Only show hostname on duplicates as it takes a lot of time.
972
-	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup']))
973
-		unset($listOptions['columns']['hostname']);
1002
+	if (!$context['show_duplicates'] || !empty($modSettings['disableHostnameLookup'])) {
1003
+			unset($listOptions['columns']['hostname']);
1004
+	}
974 1005
 
975 1006
 	// Is there any need to show filters?
976 1007
 	if (isset($context['available_filters']) && count($context['available_filters']) > 1)
@@ -978,9 +1009,10 @@  discard block
 block discarded – undo
978 1009
 		$filterOptions = '
979 1010
 			<strong>' . $txt['admin_browse_filter_by'] . ':</strong>
980 1011
 			<select name="filter" onchange="this.form.submit();">';
981
-		foreach ($context['available_filters'] as $filter)
982
-			$filterOptions .= '
1012
+		foreach ($context['available_filters'] as $filter) {
1013
+					$filterOptions .= '
983 1014
 				<option value="' . $filter['type'] . '"' . ($filter['selected'] ? ' selected' : '') . '>' . $filter['desc'] . ' - ' . $filter['amount'] . ' ' . ($filter['amount'] == 1 ? $txt['user'] : $txt['users']) . '</option>';
1015
+		}
984 1016
 		$filterOptions .= '
985 1017
 			</select>
986 1018
 			<noscript><input type="submit" value="' . $txt['go'] . '" name="filter" class="button"></noscript>';
@@ -992,12 +1024,13 @@  discard block
 block discarded – undo
992 1024
 	}
993 1025
 
994 1026
 	// What about if we only have one filter, but it's not the "standard" filter - show them what they are looking at.
995
-	if (!empty($context['show_filter']) && !empty($context['available_filters']))
996
-		$listOptions['additional_rows'][] = array(
1027
+	if (!empty($context['show_filter']) && !empty($context['available_filters'])) {
1028
+			$listOptions['additional_rows'][] = array(
997 1029
 			'position' => 'above_column_headers',
998 1030
 			'value' => '<strong>' . $txt['admin_browse_filter_show'] . ':</strong> ' . $context['available_filters'][0]['desc'],
999 1031
 			'class' => 'smalltext floatright',
1000 1032
 		);
1033
+	}
1001 1034
 
1002 1035
 	// Now that we have all the options, create the list.
1003 1036
 	require_once($sourcedir . '/Subs-List.php');
@@ -1027,12 +1060,14 @@  discard block
 block discarded – undo
1027 1060
 	$current_filter = (int) $_REQUEST['orig_filter'];
1028 1061
 
1029 1062
 	// If we are applying a filter do just that - then redirect.
1030
-	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter'])
1031
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1063
+	if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != $_REQUEST['orig_filter']) {
1064
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $_REQUEST['filter'] . ';start=' . $_REQUEST['start']);
1065
+	}
1032 1066
 
1033 1067
 	// Nothing to do?
1034
-	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed']))
1035
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1068
+	if (!isset($_POST['todoAction']) && !isset($_POST['time_passed'])) {
1069
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1070
+	}
1036 1071
 
1037 1072
 	// Are we dealing with members who have been waiting for > set amount of time?
1038 1073
 	if (isset($_POST['time_passed']))
@@ -1045,8 +1080,9 @@  discard block
 block discarded – undo
1045 1080
 	else
1046 1081
 	{
1047 1082
 		$members = array();
1048
-		foreach ($_POST['todoAction'] as $id)
1049
-			$members[] = (int) $id;
1083
+		foreach ($_POST['todoAction'] as $id) {
1084
+					$members[] = (int) $id;
1085
+		}
1050 1086
 		$condition = '
1051 1087
 			AND id_member IN ({array_int:members})';
1052 1088
 	}
@@ -1067,8 +1103,9 @@  discard block
 block discarded – undo
1067 1103
 	$member_count = $smcFunc['db_num_rows']($request);
1068 1104
 
1069 1105
 	// If no results then just return!
1070
-	if ($member_count == 0)
1071
-		redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1106
+	if ($member_count == 0) {
1107
+			redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1108
+	}
1072 1109
 
1073 1110
 	$member_info = array();
1074 1111
 	$members = array();
@@ -1107,8 +1144,9 @@  discard block
 block discarded – undo
1107 1144
 		// Do we have to let the integration code know about the activations?
1108 1145
 		if (!empty($modSettings['integrate_activate']))
1109 1146
 		{
1110
-			foreach ($member_info as $member)
1111
-				call_integration_hook('integrate_activate', array($member['username']));
1147
+			foreach ($member_info as $member) {
1148
+							call_integration_hook('integrate_activate', array($member['username']));
1149
+			}
1112 1150
 		}
1113 1151
 
1114 1152
 		// Check for email.
@@ -1238,20 +1276,23 @@  discard block
 block discarded – undo
1238 1276
 		$log_action = $_POST['todo'] == 'remind' ? 'remind_member' : 'approve_member';
1239 1277
 
1240 1278
 		require_once($sourcedir . '/Logging.php');
1241
-		foreach ($member_info as $member)
1242
-			logAction($log_action, array('member' => $member['id']), 'admin');
1279
+		foreach ($member_info as $member) {
1280
+					logAction($log_action, array('member' => $member['id']), 'admin');
1281
+		}
1243 1282
 	}
1244 1283
 
1245 1284
 	// Although updateStats *may* catch this, best to do it manually just in case (Doesn't always sort out unapprovedMembers).
1246
-	if (in_array($current_filter, array(3, 4, 5)))
1247
-		updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1285
+	if (in_array($current_filter, array(3, 4, 5))) {
1286
+			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > $member_count ? $modSettings['unapprovedMembers'] - $member_count : 0)));
1287
+	}
1248 1288
 
1249 1289
 	// Update the member's stats. (but, we know the member didn't change their name.)
1250 1290
 	updateStats('member', false);
1251 1291
 
1252 1292
 	// If they haven't been deleted, update the post group statistics on them...
1253
-	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind')))
1254
-		updateStats('postgroups', $members);
1293
+	if (!in_array($_POST['todo'], array('delete', 'deleteemail', 'reject', 'rejectemail', 'remind'))) {
1294
+			updateStats('postgroups', $members);
1295
+	}
1255 1296
 
1256 1297
 	redirectexit('action=admin;area=viewmembers;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';filter=' . $current_filter . ';start=' . $_REQUEST['start']);
1257 1298
 }
@@ -1276,10 +1317,11 @@  discard block
 block discarded – undo
1276 1317
 	$dis = time() - $old;
1277 1318
 
1278 1319
 	// Before midnight?
1279
-	if ($dis < $sinceMidnight)
1280
-		return 0;
1281
-	else
1282
-		$dis -= $sinceMidnight;
1320
+	if ($dis < $sinceMidnight) {
1321
+			return 0;
1322
+	} else {
1323
+			$dis -= $sinceMidnight;
1324
+	}
1283 1325
 
1284 1326
 	// Divide out the seconds in a day to get the number of days.
1285 1327
 	return ceil($dis / (24 * 60 * 60));
Please login to merge, or discard this patch.
other/upgrade.php 1 patch
Braces   +884 added lines, -649 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'];
@@ -197,8 +204,9 @@  discard block
 block discarded – undo
197 204
 			'db_error_skip' => true,
198 205
 		)
199 206
 	);
200
-	while ($row = $smcFunc['db_fetch_assoc']($request))
201
-		$modSettings[$row['variable']] = $row['value'];
207
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
208
+			$modSettings[$row['variable']] = $row['value'];
209
+	}
202 210
 	$smcFunc['db_free_result']($request);
203 211
 }
204 212
 
@@ -208,10 +216,12 @@  discard block
 block discarded – undo
208 216
 	$modSettings['theme_url'] = 'Themes/default';
209 217
 	$modSettings['images_url'] = 'Themes/default/images';
210 218
 }
211
-if (!isset($settings['default_theme_url']))
219
+if (!isset($settings['default_theme_url'])) {
212 220
 	$settings['default_theme_url'] = $modSettings['theme_url'];
213
-if (!isset($settings['default_theme_dir']))
221
+}
222
+if (!isset($settings['default_theme_dir'])) {
214 223
 	$settings['default_theme_dir'] = $modSettings['theme_dir'];
224
+}
215 225
 
216 226
 $upcontext['is_large_forum'] = (empty($modSettings['smfVersion']) || $modSettings['smfVersion'] <= '1.1 RC1') && !empty($modSettings['totalMessages']) && $modSettings['totalMessages'] > 75000;
217 227
 // Default title...
@@ -229,13 +239,15 @@  discard block
 block discarded – undo
229 239
 	$support_js = $upcontext['upgrade_status']['js'];
230 240
 
231 241
 	// Only set this if the upgrader status says so.
232
-	if (empty($is_debug))
233
-		$is_debug = $upcontext['upgrade_status']['debug'];
242
+	if (empty($is_debug)) {
243
+			$is_debug = $upcontext['upgrade_status']['debug'];
244
+	}
234 245
 
235 246
 	// Load the language.
236
-	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
237
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
238
-}
247
+	if (file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
248
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
249
+	}
250
+	}
239 251
 // Set the defaults.
240 252
 else
241 253
 {
@@ -253,15 +265,18 @@  discard block
 block discarded – undo
253 265
 }
254 266
 
255 267
 // If this isn't the first stage see whether they are logging in and resuming.
256
-if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step']))
268
+if ($upcontext['current_step'] != 0 || !empty($upcontext['user']['step'])) {
257 269
 	checkLogin();
270
+}
258 271
 
259
-if ($command_line)
272
+if ($command_line) {
260 273
 	cmdStep0();
274
+}
261 275
 
262 276
 // Don't error if we're using xml.
263
-if (isset($_GET['xml']))
277
+if (isset($_GET['xml'])) {
264 278
 	$upcontext['return_error'] = true;
279
+}
265 280
 
266 281
 // Loop through all the steps doing each one as required.
267 282
 $upcontext['overall_percent'] = 0;
@@ -282,9 +297,9 @@  discard block
 block discarded – undo
282 297
 		}
283 298
 
284 299
 		// Call the step and if it returns false that means pause!
285
-		if (function_exists($step[2]) && $step[2]() === false)
286
-			break;
287
-		elseif (function_exists($step[2])) {
300
+		if (function_exists($step[2]) && $step[2]() === false) {
301
+					break;
302
+		} elseif (function_exists($step[2])) {
288 303
 			//Start each new step with this unset, so the 'normal' template is called first
289 304
 			unset($_GET['xml']);
290 305
 			//Clear out warnings at the start of each step
@@ -330,17 +345,18 @@  discard block
 block discarded – undo
330 345
 		// This should not happen my dear... HELP ME DEVELOPERS!!
331 346
 		if (!empty($command_line))
332 347
 		{
333
-			if (function_exists('debug_print_backtrace'))
334
-				debug_print_backtrace();
348
+			if (function_exists('debug_print_backtrace')) {
349
+							debug_print_backtrace();
350
+			}
335 351
 
336 352
 			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.';
337 353
 			flush();
338 354
 			die();
339 355
 		}
340 356
 
341
-		if (!isset($_GET['xml']))
342
-			template_upgrade_above();
343
-		else
357
+		if (!isset($_GET['xml'])) {
358
+					template_upgrade_above();
359
+		} else
344 360
 		{
345 361
 			header('Content-Type: text/xml; charset=UTF-8');
346 362
 			// Sadly we need to retain the $_GET data thanks to the old upgrade scripts.
@@ -362,25 +378,29 @@  discard block
 block discarded – undo
362 378
 			$upcontext['form_url'] = $upgradeurl . '?step=' . $upcontext['current_step'] . '&amp;substep=' . $_GET['substep'] . '&amp;data=' . base64_encode(json_encode($upcontext['upgrade_status']));
363 379
 
364 380
 			// Custom stuff to pass back?
365
-			if (!empty($upcontext['query_string']))
366
-				$upcontext['form_url'] .= $upcontext['query_string'];
381
+			if (!empty($upcontext['query_string'])) {
382
+							$upcontext['form_url'] .= $upcontext['query_string'];
383
+			}
367 384
 
368 385
 			// Call the appropriate subtemplate
369
-			if (is_callable('template_' . $upcontext['sub_template']))
370
-				call_user_func('template_' . $upcontext['sub_template']);
371
-			else
372
-				die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
386
+			if (is_callable('template_' . $upcontext['sub_template'])) {
387
+							call_user_func('template_' . $upcontext['sub_template']);
388
+			} else {
389
+							die('Upgrade aborted!  Invalid template: template_' . $upcontext['sub_template']);
390
+			}
373 391
 		}
374 392
 
375 393
 		// Was there an error?
376
-		if (!empty($upcontext['forced_error_message']))
377
-			echo $upcontext['forced_error_message'];
394
+		if (!empty($upcontext['forced_error_message'])) {
395
+					echo $upcontext['forced_error_message'];
396
+		}
378 397
 
379 398
 		// Show the footer.
380
-		if (!isset($_GET['xml']))
381
-			template_upgrade_below();
382
-		else
383
-			template_xml_below();
399
+		if (!isset($_GET['xml'])) {
400
+					template_upgrade_below();
401
+		} else {
402
+					template_xml_below();
403
+		}
384 404
 	}
385 405
 
386 406
 
@@ -392,15 +412,19 @@  discard block
 block discarded – undo
392 412
 		$seconds = intval($active % 60);
393 413
 
394 414
 		$totalTime = '';
395
-		if ($hours > 0)
396
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
397
-		if ($minutes > 0)
398
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
399
-		if ($seconds > 0)
400
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
415
+		if ($hours > 0) {
416
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
417
+		}
418
+		if ($minutes > 0) {
419
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
420
+		}
421
+		if ($seconds > 0) {
422
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
423
+		}
401 424
 
402
-		if (!empty($totalTime))
403
-			echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
425
+		if (!empty($totalTime)) {
426
+					echo "\n" . 'Upgrade completed in ' . $totalTime . "\n";
427
+		}
404 428
 	}
405 429
 
406 430
 	// Bang - gone!
@@ -413,8 +437,9 @@  discard block
 block discarded – undo
413 437
 	global $upgradeurl, $upcontext, $command_line;
414 438
 
415 439
 	// Command line users can't be redirected.
416
-	if ($command_line)
417
-		upgradeExit(true);
440
+	if ($command_line) {
441
+			upgradeExit(true);
442
+	}
418 443
 
419 444
 	// Are we providing the core info?
420 445
 	if ($addForm)
@@ -440,12 +465,14 @@  discard block
 block discarded – undo
440 465
 	define('SMF', 1);
441 466
 
442 467
 	// Start the session.
443
-	if (@ini_get('session.save_handler') == 'user')
444
-		@ini_set('session.save_handler', 'files');
468
+	if (@ini_get('session.save_handler') == 'user') {
469
+			@ini_set('session.save_handler', 'files');
470
+	}
445 471
 	@session_start();
446 472
 
447
-	if (empty($smcFunc))
448
-		$smcFunc = array();
473
+	if (empty($smcFunc)) {
474
+			$smcFunc = array();
475
+	}
449 476
 
450 477
 	// We need this for authentication and some upgrade code
451 478
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -472,24 +499,27 @@  discard block
 block discarded – undo
472 499
 		require_once($sourcedir . '/Subs-Db-' . $db_type . '.php');
473 500
 
474 501
 		// Make the connection...
475
-		if (empty($db_connection))
476
-			$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
477
-		else
478
-			// If we've returned here, ping/reconnect to be safe
502
+		if (empty($db_connection)) {
503
+					$db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, array('non_fatal' => true));
504
+		} else {
505
+					// If we've returned here, ping/reconnect to be safe
479 506
 			$smcFunc['db_ping']($db_connection);
507
+		}
480 508
 
481 509
 		// Oh dear god!!
482
-		if ($db_connection === null)
483
-			die('Unable to connect to database - please check username and password are correct in Settings.php');
510
+		if ($db_connection === null) {
511
+					die('Unable to connect to database - please check username and password are correct in Settings.php');
512
+		}
484 513
 
485
-		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1)
486
-			$smcFunc['db_query']('', '
514
+		if ($db_type == 'mysql' && isset($db_character_set) && preg_match('~^\w+$~', $db_character_set) === 1) {
515
+					$smcFunc['db_query']('', '
487 516
 			SET NAMES {string:db_character_set}',
488 517
 			array(
489 518
 				'db_error_skip' => true,
490 519
 				'db_character_set' => $db_character_set,
491 520
 			)
492 521
 		);
522
+		}
493 523
 
494 524
 		// Load the modSettings data...
495 525
 		$request = $smcFunc['db_query']('', '
@@ -500,11 +530,11 @@  discard block
 block discarded – undo
500 530
 			)
501 531
 		);
502 532
 		$modSettings = array();
503
-		while ($row = $smcFunc['db_fetch_assoc']($request))
504
-			$modSettings[$row['variable']] = $row['value'];
533
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
534
+					$modSettings[$row['variable']] = $row['value'];
535
+		}
505 536
 		$smcFunc['db_free_result']($request);
506
-	}
507
-	else
537
+	} else
508 538
 	{
509 539
 		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.');
510 540
 	}
@@ -518,9 +548,10 @@  discard block
 block discarded – undo
518 548
 		cleanRequest();
519 549
 	}
520 550
 
521
-	if (!isset($_GET['substep']))
522
-		$_GET['substep'] = 0;
523
-}
551
+	if (!isset($_GET['substep'])) {
552
+			$_GET['substep'] = 0;
553
+	}
554
+	}
524 555
 
525 556
 function initialize_inputs()
526 557
 {
@@ -550,8 +581,9 @@  discard block
 block discarded – undo
550 581
 		$dh = opendir(dirname(__FILE__));
551 582
 		while ($file = readdir($dh))
552 583
 		{
553
-			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1]))
554
-				@unlink(dirname(__FILE__) . '/' . $file);
584
+			if (preg_match('~upgrade_\d-\d_([A-Za-z])+\.sql~i', $file, $matches) && isset($matches[1])) {
585
+							@unlink(dirname(__FILE__) . '/' . $file);
586
+			}
555 587
 		}
556 588
 		closedir($dh);
557 589
 
@@ -580,8 +612,9 @@  discard block
 block discarded – undo
580 612
 	$temp = 'upgrade_php?step';
581 613
 	while (strlen($temp) > 4)
582 614
 	{
583
-		if (isset($_GET[$temp]))
584
-			unset($_GET[$temp]);
615
+		if (isset($_GET[$temp])) {
616
+					unset($_GET[$temp]);
617
+		}
585 618
 		$temp = substr($temp, 1);
586 619
 	}
587 620
 
@@ -608,32 +641,39 @@  discard block
 block discarded – undo
608 641
 		&& @file_exists(dirname(__FILE__) . '/upgrade_2-1_' . $db_type . '.sql');
609 642
 
610 643
 	// Need legacy scripts?
611
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1)
612
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
613
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0)
614
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
615
-	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1)
616
-		$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
644
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.1) {
645
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_2-0_' . $db_type . '.sql');
646
+	}
647
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 2.0) {
648
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-1.sql');
649
+	}
650
+	if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < 1.1) {
651
+			$check &= @file_exists(dirname(__FILE__) . '/upgrade_1-0.sql');
652
+	}
617 653
 
618 654
 	// We don't need "-utf8" files anymore...
619 655
 	$upcontext['language'] = str_ireplace('-utf8', '', $upcontext['language']);
620 656
 
621 657
 	// This needs to exist!
622
-	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
623
-		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>]');
624
-	else
625
-		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
658
+	if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
659
+			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>]');
660
+	} else {
661
+			require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
662
+	}
626 663
 
627
-	if (!$check)
628
-		// 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.
664
+	if (!$check) {
665
+			// 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.
629 666
 		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.');
667
+	}
630 668
 
631 669
 	// Do they meet the install requirements?
632
-	if (!php_version_check())
633
-		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.');
670
+	if (!php_version_check()) {
671
+			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.');
672
+	}
634 673
 
635
-	if (!db_version_check())
636
-		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.');
674
+	if (!db_version_check()) {
675
+			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.');
676
+	}
637 677
 
638 678
 	// Do some checks to make sure they have proper privileges
639 679
 	db_extend('packages');
@@ -648,14 +688,16 @@  discard block
 block discarded – undo
648 688
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
649 689
 
650 690
 	// Sorry... we need CREATE, ALTER and DROP
651
-	if (!$create || !$alter || !$drop)
652
-		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.');
691
+	if (!$create || !$alter || !$drop) {
692
+			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.');
693
+	}
653 694
 
654 695
 	// Do a quick version spot check.
655 696
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
656 697
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
657
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
658
-		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.');
698
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
699
+			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.');
700
+	}
659 701
 
660 702
 	// What absolutely needs to be writable?
661 703
 	$writable_files = array(
@@ -677,12 +719,13 @@  discard block
 block discarded – undo
677 719
 	quickFileWritable($custom_av_dir);
678 720
 
679 721
 	// Are we good now?
680
-	if (!is_writable($custom_av_dir))
681
-		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));
682
-	elseif ($need_settings_update)
722
+	if (!is_writable($custom_av_dir)) {
723
+			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));
724
+	} elseif ($need_settings_update)
683 725
 	{
684
-		if (!function_exists('cache_put_data'))
685
-			require_once($sourcedir . '/Load.php');
726
+		if (!function_exists('cache_put_data')) {
727
+					require_once($sourcedir . '/Load.php');
728
+		}
686 729
 		updateSettings(array('custom_avatar_dir' => $custom_av_dir));
687 730
 		updateSettings(array('custom_avatar_url' => $custom_av_url));
688 731
 	}
@@ -691,28 +734,33 @@  discard block
 block discarded – undo
691 734
 
692 735
 	// Check the cache directory.
693 736
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
694
-	if (!file_exists($cachedir_temp))
695
-		@mkdir($cachedir_temp);
696
-	if (!file_exists($cachedir_temp))
697
-		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.');
698
-
699
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
700
-		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>.');
701
-	elseif (!isset($_GET['skiplang']))
737
+	if (!file_exists($cachedir_temp)) {
738
+			@mkdir($cachedir_temp);
739
+	}
740
+	if (!file_exists($cachedir_temp)) {
741
+			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.');
742
+	}
743
+
744
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
745
+			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>.');
746
+	} elseif (!isset($_GET['skiplang']))
702 747
 	{
703 748
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
704 749
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
705 750
 
706
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
707
-			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>]');
751
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
752
+					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>]');
753
+		}
708 754
 	}
709 755
 
710
-	if (!makeFilesWritable($writable_files))
711
-		return false;
756
+	if (!makeFilesWritable($writable_files)) {
757
+			return false;
758
+	}
712 759
 
713 760
 	// Check agreement.txt. (it may not exist, in which case $boarddir must be writable.)
714
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
715
-		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.');
761
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
762
+			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.');
763
+	}
716 764
 
717 765
 	// Upgrade the agreement.
718 766
 	elseif (isset($modSettings['agreement']))
@@ -723,8 +771,8 @@  discard block
 block discarded – undo
723 771
 	}
724 772
 
725 773
 	// We're going to check that their board dir setting is right in case they've been moving stuff around.
726
-	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => '')))
727
-		$upcontext['warning'] = '
774
+	if (strtr($boarddir, array('/' => '', '\\' => '')) != strtr(dirname(__FILE__), array('/' => '', '\\' => ''))) {
775
+			$upcontext['warning'] = '
728 776
 			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>
729 777
 			<ul>
730 778
 				<li>Board Directory: ' . $boarddir . '</li>
@@ -732,19 +780,23 @@  discard block
 block discarded – undo
732 780
 				<li>Cache Directory: ' . $cachedir_temp . '</li>
733 781
 			</ul>
734 782
 			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.';
783
+	}
735 784
 
736 785
 	// Confirm mbstring is loaded...
737
-	if (!extension_loaded('mbstring'))
738
-		return throw_error($txt['install_no_mbstring']);
786
+	if (!extension_loaded('mbstring')) {
787
+			return throw_error($txt['install_no_mbstring']);
788
+	}
739 789
 
740 790
 	// Check for https stream support.
741 791
 	$supported_streams = stream_get_wrappers();
742
-	if (!in_array('https', $supported_streams))
743
-		$upcontext['custom_warning'] = $txt['install_no_https'];
792
+	if (!in_array('https', $supported_streams)) {
793
+			$upcontext['custom_warning'] = $txt['install_no_https'];
794
+	}
744 795
 
745 796
 	// Either we're logged in or we're going to present the login.
746
-	if (checkLogin())
747
-		return true;
797
+	if (checkLogin()) {
798
+			return true;
799
+	}
748 800
 
749 801
 	$upcontext += createToken('login');
750 802
 
@@ -758,15 +810,17 @@  discard block
 block discarded – undo
758 810
 	global $smcFunc, $db_type, $support_js;
759 811
 
760 812
 	// Don't bother if the security is disabled.
761
-	if ($disable_security)
762
-		return true;
813
+	if ($disable_security) {
814
+			return true;
815
+	}
763 816
 
764 817
 	// Are we trying to login?
765 818
 	if (isset($_POST['contbutt']) && (!empty($_POST['user'])))
766 819
 	{
767 820
 		// If we've disabled security pick a suitable name!
768
-		if (empty($_POST['user']))
769
-			$_POST['user'] = 'Administrator';
821
+		if (empty($_POST['user'])) {
822
+					$_POST['user'] = 'Administrator';
823
+		}
770 824
 
771 825
 		// Before 2.0 these column names were different!
772 826
 		$oldDB = false;
@@ -781,16 +835,17 @@  discard block
 block discarded – undo
781 835
 					'db_error_skip' => true,
782 836
 				)
783 837
 			);
784
-			if ($smcFunc['db_num_rows']($request) != 0)
785
-				$oldDB = true;
838
+			if ($smcFunc['db_num_rows']($request) != 0) {
839
+							$oldDB = true;
840
+			}
786 841
 			$smcFunc['db_free_result']($request);
787 842
 		}
788 843
 
789 844
 		// Get what we believe to be their details.
790 845
 		if (!$disable_security)
791 846
 		{
792
-			if ($oldDB)
793
-				$request = $smcFunc['db_query']('', '
847
+			if ($oldDB) {
848
+							$request = $smcFunc['db_query']('', '
794 849
 					SELECT id_member, memberName AS member_name, passwd, id_group,
795 850
 					additionalGroups AS additional_groups, lngfile
796 851
 					FROM {db_prefix}members
@@ -800,8 +855,8 @@  discard block
 block discarded – undo
800 855
 						'db_error_skip' => true,
801 856
 					)
802 857
 				);
803
-			else
804
-				$request = $smcFunc['db_query']('', '
858
+			} else {
859
+							$request = $smcFunc['db_query']('', '
805 860
 					SELECT id_member, member_name, passwd, id_group, additional_groups, lngfile
806 861
 					FROM {db_prefix}members
807 862
 					WHERE member_name = {string:member_name}',
@@ -810,6 +865,7 @@  discard block
 block discarded – undo
810 865
 						'db_error_skip' => true,
811 866
 					)
812 867
 				);
868
+			}
813 869
 			if ($smcFunc['db_num_rows']($request) != 0)
814 870
 			{
815 871
 				list ($id_member, $name, $password, $id_group, $addGroups, $user_language) = $smcFunc['db_fetch_row']($request);
@@ -817,16 +873,17 @@  discard block
 block discarded – undo
817 873
 				$groups = explode(',', $addGroups);
818 874
 				$groups[] = $id_group;
819 875
 
820
-				foreach ($groups as $k => $v)
821
-					$groups[$k] = (int) $v;
876
+				foreach ($groups as $k => $v) {
877
+									$groups[$k] = (int) $v;
878
+				}
822 879
 
823 880
 				$sha_passwd = sha1(strtolower($name) . un_htmlspecialchars($_REQUEST['passwrd']));
824 881
 
825 882
 				// We don't use "-utf8" anymore...
826 883
 				$user_language = str_ireplace('-utf8', '', $user_language);
884
+			} else {
885
+							$upcontext['username_incorrect'] = true;
827 886
 			}
828
-			else
829
-				$upcontext['username_incorrect'] = true;
830 887
 			$smcFunc['db_free_result']($request);
831 888
 		}
832 889
 		$upcontext['username'] = $_POST['user'];
@@ -836,13 +893,14 @@  discard block
 block discarded – undo
836 893
 		{
837 894
 			$upcontext['upgrade_status']['js'] = 1;
838 895
 			$support_js = 1;
896
+		} else {
897
+					$support_js = 0;
839 898
 		}
840
-		else
841
-			$support_js = 0;
842 899
 
843 900
 		// Note down the version we are coming from.
844
-		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version']))
845
-			$upcontext['user']['version'] = $modSettings['smfVersion'];
901
+		if (!empty($modSettings['smfVersion']) && empty($upcontext['user']['version'])) {
902
+					$upcontext['user']['version'] = $modSettings['smfVersion'];
903
+		}
846 904
 
847 905
 		// Didn't get anywhere?
848 906
 		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']))
@@ -876,15 +934,15 @@  discard block
 block discarded – undo
876 934
 							'db_error_skip' => true,
877 935
 						)
878 936
 					);
879
-					if ($smcFunc['db_num_rows']($request) == 0)
880
-						return throw_error('You need to be an admin to perform an upgrade!');
937
+					if ($smcFunc['db_num_rows']($request) == 0) {
938
+											return throw_error('You need to be an admin to perform an upgrade!');
939
+					}
881 940
 					$smcFunc['db_free_result']($request);
882 941
 				}
883 942
 
884 943
 				$upcontext['user']['id'] = $id_member;
885 944
 				$upcontext['user']['name'] = $name;
886
-			}
887
-			else
945
+			} else
888 946
 			{
889 947
 				$upcontext['user']['id'] = 1;
890 948
 				$upcontext['user']['name'] = 'Administrator';
@@ -900,11 +958,11 @@  discard block
 block discarded – undo
900 958
 				$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $user_language . '.php')), 0, 4096);
901 959
 				preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
902 960
 
903
-				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
904
-					$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'] . '.';
905
-				elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php'))
906
-					$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'] . '.';
907
-				else
961
+				if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
962
+									$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'] . '.';
963
+				} elseif (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . basename($user_language, '.lng') . '.php')) {
964
+									$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'] . '.';
965
+				} else
908 966
 				{
909 967
 					// Set this as the new language.
910 968
 					$upcontext['language'] = $user_language;
@@ -948,8 +1006,9 @@  discard block
 block discarded – undo
948 1006
 	unset($member_columns);
949 1007
 
950 1008
 	// If we've not submitted then we're done.
951
-	if (empty($_POST['upcont']))
952
-		return false;
1009
+	if (empty($_POST['upcont'])) {
1010
+			return false;
1011
+	}
953 1012
 
954 1013
 	// Firstly, if they're enabling SM stat collection just do it.
955 1014
 	if (!empty($_POST['stats']) && substr($boardurl, 0, 16) != 'http://localhost' && empty($modSettings['allow_sm_stats']) && empty($modSettings['enable_sm_stats']))
@@ -969,16 +1028,17 @@  discard block
 block discarded – undo
969 1028
 				fwrite($fp, $out);
970 1029
 
971 1030
 				$return_data = '';
972
-				while (!feof($fp))
973
-					$return_data .= fgets($fp, 128);
1031
+				while (!feof($fp)) {
1032
+									$return_data .= fgets($fp, 128);
1033
+				}
974 1034
 
975 1035
 				fclose($fp);
976 1036
 
977 1037
 				// Get the unique site ID.
978 1038
 				preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID);
979 1039
 
980
-				if (!empty($ID[1]))
981
-					$smcFunc['db_insert']('replace',
1040
+				if (!empty($ID[1])) {
1041
+									$smcFunc['db_insert']('replace',
982 1042
 						$db_prefix . 'settings',
983 1043
 						array('variable' => 'string', 'value' => 'string'),
984 1044
 						array(
@@ -987,9 +1047,9 @@  discard block
 block discarded – undo
987 1047
 						),
988 1048
 						array('variable')
989 1049
 					);
1050
+				}
990 1051
 			}
991
-		}
992
-		else
1052
+		} else
993 1053
 		{
994 1054
 			$smcFunc['db_insert']('replace',
995 1055
 				$db_prefix . 'settings',
@@ -1000,8 +1060,8 @@  discard block
 block discarded – undo
1000 1060
 		}
1001 1061
 	}
1002 1062
 	// Don't remove stat collection unless we unchecked the box for real, not from the loop.
1003
-	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats']))
1004
-		$smcFunc['db_query']('', '
1063
+	elseif (empty($_POST['stats']) && empty($upcontext['allow_sm_stats'])) {
1064
+			$smcFunc['db_query']('', '
1005 1065
 			DELETE FROM {db_prefix}settings
1006 1066
 			WHERE variable = {string:enable_sm_stats}',
1007 1067
 			array(
@@ -1009,6 +1069,7 @@  discard block
 block discarded – undo
1009 1069
 				'db_error_skip' => true,
1010 1070
 			)
1011 1071
 		);
1072
+	}
1012 1073
 
1013 1074
 	// Deleting old karma stuff?
1014 1075
 	if (!empty($_POST['delete_karma']))
@@ -1023,20 +1084,22 @@  discard block
 block discarded – undo
1023 1084
 		);
1024 1085
 
1025 1086
 		// Cleaning up old karma member settings.
1026
-		if ($upcontext['karma_installed']['good'])
1027
-			$smcFunc['db_query']('', '
1087
+		if ($upcontext['karma_installed']['good']) {
1088
+					$smcFunc['db_query']('', '
1028 1089
 				ALTER TABLE {db_prefix}members
1029 1090
 				DROP karma_good',
1030 1091
 				array()
1031 1092
 			);
1093
+		}
1032 1094
 
1033 1095
 		// Does karma bad was enable?
1034
-		if ($upcontext['karma_installed']['bad'])
1035
-			$smcFunc['db_query']('', '
1096
+		if ($upcontext['karma_installed']['bad']) {
1097
+					$smcFunc['db_query']('', '
1036 1098
 				ALTER TABLE {db_prefix}members
1037 1099
 				DROP karma_bad',
1038 1100
 				array()
1039 1101
 			);
1102
+		}
1040 1103
 
1041 1104
 		// Cleaning up old karma permissions.
1042 1105
 		$smcFunc['db_query']('', '
@@ -1049,32 +1112,37 @@  discard block
 block discarded – undo
1049 1112
 	}
1050 1113
 
1051 1114
 	// Emptying the error log?
1052
-	if (!empty($_POST['empty_error']))
1053
-		$smcFunc['db_query']('truncate_table', '
1115
+	if (!empty($_POST['empty_error'])) {
1116
+			$smcFunc['db_query']('truncate_table', '
1054 1117
 			TRUNCATE {db_prefix}log_errors',
1055 1118
 			array(
1056 1119
 			)
1057 1120
 		);
1121
+	}
1058 1122
 
1059 1123
 	$changes = array();
1060 1124
 
1061 1125
 	// Add proxy settings.
1062
-	if (!isset($GLOBALS['image_proxy_maxsize']))
1063
-		$changes += array(
1126
+	if (!isset($GLOBALS['image_proxy_maxsize'])) {
1127
+			$changes += array(
1064 1128
 			'image_proxy_secret' => '\'' . substr(sha1(mt_rand()), 0, 20) . '\'',
1065 1129
 			'image_proxy_maxsize' => 5190,
1066 1130
 			'image_proxy_enabled' => 0,
1067 1131
 		);
1132
+	}
1068 1133
 
1069 1134
 	// If $boardurl reflects https, set force_ssl
1070
-	if (!function_exists('cache_put_data'))
1071
-		require_once($sourcedir . '/Load.php');
1072
-	if (stripos($boardurl, 'https://') !== false)
1073
-		updateSettings(array('force_ssl' => '2'));
1135
+	if (!function_exists('cache_put_data')) {
1136
+			require_once($sourcedir . '/Load.php');
1137
+	}
1138
+	if (stripos($boardurl, 'https://') !== false) {
1139
+			updateSettings(array('force_ssl' => '2'));
1140
+	}
1074 1141
 
1075 1142
 	// If we're overriding the language follow it through.
1076
-	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php'))
1077
-		$changes['language'] = '\'' . $_GET['lang'] . '\'';
1143
+	if (isset($_GET['lang']) && file_exists($modSettings['theme_dir'] . '/languages/index.' . $_GET['lang'] . '.php')) {
1144
+			$changes['language'] = '\'' . $_GET['lang'] . '\'';
1145
+	}
1078 1146
 
1079 1147
 	if (!empty($_POST['maint']))
1080 1148
 	{
@@ -1086,26 +1154,29 @@  discard block
 block discarded – undo
1086 1154
 		{
1087 1155
 			$changes['mtitle'] = '\'' . addslashes($_POST['maintitle']) . '\'';
1088 1156
 			$changes['mmessage'] = '\'' . addslashes($_POST['mainmessage']) . '\'';
1089
-		}
1090
-		else
1157
+		} else
1091 1158
 		{
1092 1159
 			$changes['mtitle'] = '\'Upgrading the forum...\'';
1093 1160
 			$changes['mmessage'] = '\'Don\\\'t worry, we will be back shortly with an updated forum.  It will only be a minute ;).\'';
1094 1161
 		}
1095 1162
 	}
1096 1163
 
1097
-	if ($command_line)
1098
-		echo ' * Updating Settings.php...';
1164
+	if ($command_line) {
1165
+			echo ' * Updating Settings.php...';
1166
+	}
1099 1167
 
1100 1168
 	// Fix some old paths.
1101
-	if (substr($boarddir, 0, 1) == '.')
1102
-		$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1169
+	if (substr($boarddir, 0, 1) == '.') {
1170
+			$changes['boarddir'] = '\'' . fixRelativePath($boarddir) . '\'';
1171
+	}
1103 1172
 
1104
-	if (substr($sourcedir, 0, 1) == '.')
1105
-		$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1173
+	if (substr($sourcedir, 0, 1) == '.') {
1174
+			$changes['sourcedir'] = '\'' . fixRelativePath($sourcedir) . '\'';
1175
+	}
1106 1176
 
1107
-	if (empty($cachedir) || substr($cachedir, 0, 1) == '.')
1108
-		$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1177
+	if (empty($cachedir) || substr($cachedir, 0, 1) == '.') {
1178
+			$changes['cachedir'] = '\'' . fixRelativePath($boarddir) . '/cache\'';
1179
+	}
1109 1180
 
1110 1181
 	// If they have a "host:port" setup for the host, split that into separate values
1111 1182
 	// You should never have a : in the hostname if you're not on MySQL, but better safe than sorry
@@ -1116,32 +1187,36 @@  discard block
 block discarded – undo
1116 1187
 		$changes['db_server'] = '\'' . $db_server . '\'';
1117 1188
 
1118 1189
 		// Only set this if we're not using the default port
1119
-		if ($db_port != ini_get('mysqli.default_port'))
1120
-			$changes['db_port'] = (int) $db_port;
1121
-	}
1122
-	elseif (!empty($db_port))
1190
+		if ($db_port != ini_get('mysqli.default_port')) {
1191
+					$changes['db_port'] = (int) $db_port;
1192
+		}
1193
+	} elseif (!empty($db_port))
1123 1194
 	{
1124 1195
 		// If db_port is set and is the same as the default, set it to ''
1125 1196
 		if ($db_type == 'mysql')
1126 1197
 		{
1127
-			if ($db_port == ini_get('mysqli.default_port'))
1128
-				$changes['db_port'] = '\'\'';
1129
-			elseif ($db_type == 'postgresql' && $db_port == 5432)
1130
-				$changes['db_port'] = '\'\'';
1198
+			if ($db_port == ini_get('mysqli.default_port')) {
1199
+							$changes['db_port'] = '\'\'';
1200
+			} elseif ($db_type == 'postgresql' && $db_port == 5432) {
1201
+							$changes['db_port'] = '\'\'';
1202
+			}
1131 1203
 		}
1132 1204
 	}
1133 1205
 
1134 1206
 	// Maybe we haven't had this option yet?
1135
-	if (empty($packagesdir))
1136
-		$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1207
+	if (empty($packagesdir)) {
1208
+			$changes['packagesdir'] = '\'' . fixRelativePath($boarddir) . '/Packages\'';
1209
+	}
1137 1210
 
1138 1211
 	// Add support for $tasksdir var.
1139
-	if (empty($tasksdir))
1140
-		$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1212
+	if (empty($tasksdir)) {
1213
+			$changes['tasksdir'] = '\'' . fixRelativePath($sourcedir) . '/tasks\'';
1214
+	}
1141 1215
 
1142 1216
 	// Make sure we fix the language as well.
1143
-	if (stristr($language, '-utf8'))
1144
-		$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1217
+	if (stristr($language, '-utf8')) {
1218
+			$changes['language'] = '\'' . str_ireplace('-utf8', '', $language) . '\'';
1219
+	}
1145 1220
 
1146 1221
 	// @todo Maybe change the cookie name if going to 1.1, too?
1147 1222
 
@@ -1149,8 +1224,9 @@  discard block
 block discarded – undo
1149 1224
 	require_once($sourcedir . '/Subs-Admin.php');
1150 1225
 	updateSettingsFile($changes);
1151 1226
 
1152
-	if ($command_line)
1153
-		echo ' Successful.' . "\n";
1227
+	if ($command_line) {
1228
+			echo ' Successful.' . "\n";
1229
+	}
1154 1230
 
1155 1231
 	// Are we doing debug?
1156 1232
 	if (isset($_POST['debug']))
@@ -1160,8 +1236,9 @@  discard block
 block discarded – undo
1160 1236
 	}
1161 1237
 
1162 1238
 	// If we're not backing up then jump one.
1163
-	if (empty($_POST['backup']))
1164
-		$upcontext['current_step']++;
1239
+	if (empty($_POST['backup'])) {
1240
+			$upcontext['current_step']++;
1241
+	}
1165 1242
 
1166 1243
 	// If we've got here then let's proceed to the next step!
1167 1244
 	return true;
@@ -1176,8 +1253,9 @@  discard block
 block discarded – undo
1176 1253
 	$upcontext['page_title'] = 'Backup Database';
1177 1254
 
1178 1255
 	// Done it already - js wise?
1179
-	if (!empty($_POST['backup_done']))
1180
-		return true;
1256
+	if (!empty($_POST['backup_done'])) {
1257
+			return true;
1258
+	}
1181 1259
 
1182 1260
 	// Some useful stuff here.
1183 1261
 	db_extend();
@@ -1191,9 +1269,10 @@  discard block
 block discarded – undo
1191 1269
 	$tables = $smcFunc['db_list_tables']($db, $filter);
1192 1270
 
1193 1271
 	$table_names = array();
1194
-	foreach ($tables as $table)
1195
-		if (substr($table, 0, 7) !== 'backup_')
1272
+	foreach ($tables as $table) {
1273
+			if (substr($table, 0, 7) !== 'backup_')
1196 1274
 			$table_names[] = $table;
1275
+	}
1197 1276
 
1198 1277
 	$upcontext['table_count'] = count($table_names);
1199 1278
 	$upcontext['cur_table_num'] = $_GET['substep'];
@@ -1203,12 +1282,14 @@  discard block
 block discarded – undo
1203 1282
 	$file_steps = $upcontext['table_count'];
1204 1283
 
1205 1284
 	// What ones have we already done?
1206
-	foreach ($table_names as $id => $table)
1207
-		if ($id < $_GET['substep'])
1285
+	foreach ($table_names as $id => $table) {
1286
+			if ($id < $_GET['substep'])
1208 1287
 			$upcontext['previous_tables'][] = $table;
1288
+	}
1209 1289
 
1210
-	if ($command_line)
1211
-		echo 'Backing Up Tables.';
1290
+	if ($command_line) {
1291
+			echo 'Backing Up Tables.';
1292
+	}
1212 1293
 
1213 1294
 	// If we don't support javascript we backup here.
1214 1295
 	if (!$support_js || isset($_GET['xml']))
@@ -1227,8 +1308,9 @@  discard block
 block discarded – undo
1227 1308
 			backupTable($table_names[$substep]);
1228 1309
 
1229 1310
 			// If this is XML to keep it nice for the user do one table at a time anyway!
1230
-			if (isset($_GET['xml']))
1231
-				return upgradeExit();
1311
+			if (isset($_GET['xml'])) {
1312
+							return upgradeExit();
1313
+			}
1232 1314
 		}
1233 1315
 
1234 1316
 		if ($command_line)
@@ -1261,9 +1343,10 @@  discard block
 block discarded – undo
1261 1343
 
1262 1344
 	$smcFunc['db_backup_table']($table, 'backup_' . $table);
1263 1345
 
1264
-	if ($command_line)
1265
-		echo ' done.';
1266
-}
1346
+	if ($command_line) {
1347
+			echo ' done.';
1348
+	}
1349
+	}
1267 1350
 
1268 1351
 // Step 2: Everything.
1269 1352
 function DatabaseChanges()
@@ -1272,8 +1355,9 @@  discard block
 block discarded – undo
1272 1355
 	global $upcontext, $support_js, $db_type;
1273 1356
 
1274 1357
 	// Have we just completed this?
1275
-	if (!empty($_POST['database_done']))
1276
-		return true;
1358
+	if (!empty($_POST['database_done'])) {
1359
+			return true;
1360
+	}
1277 1361
 
1278 1362
 	$upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
1279 1363
 	$upcontext['page_title'] = 'Database Changes';
@@ -1288,15 +1372,16 @@  discard block
 block discarded – undo
1288 1372
 	);
1289 1373
 
1290 1374
 	// How many files are there in total?
1291
-	if (isset($_GET['filecount']))
1292
-		$upcontext['file_count'] = (int) $_GET['filecount'];
1293
-	else
1375
+	if (isset($_GET['filecount'])) {
1376
+			$upcontext['file_count'] = (int) $_GET['filecount'];
1377
+	} else
1294 1378
 	{
1295 1379
 		$upcontext['file_count'] = 0;
1296 1380
 		foreach ($files as $file)
1297 1381
 		{
1298
-			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1])
1299
-				$upcontext['file_count']++;
1382
+			if (!isset($modSettings['smfVersion']) || $modSettings['smfVersion'] < $file[1]) {
1383
+							$upcontext['file_count']++;
1384
+			}
1300 1385
 		}
1301 1386
 	}
1302 1387
 
@@ -1306,9 +1391,9 @@  discard block
 block discarded – undo
1306 1391
 	$upcontext['cur_file_num'] = 0;
1307 1392
 	foreach ($files as $file)
1308 1393
 	{
1309
-		if ($did_not_do)
1310
-			$did_not_do--;
1311
-		else
1394
+		if ($did_not_do) {
1395
+					$did_not_do--;
1396
+		} else
1312 1397
 		{
1313 1398
 			$upcontext['cur_file_num']++;
1314 1399
 			$upcontext['cur_file_name'] = $file[0];
@@ -1335,12 +1420,13 @@  discard block
 block discarded – undo
1335 1420
 					// Flag to move on to the next.
1336 1421
 					$upcontext['completed_step'] = true;
1337 1422
 					// Did we complete the whole file?
1338
-					if ($nextFile)
1339
-						$upcontext['current_debug_item_num'] = -1;
1423
+					if ($nextFile) {
1424
+											$upcontext['current_debug_item_num'] = -1;
1425
+					}
1340 1426
 					return upgradeExit();
1427
+				} elseif ($support_js) {
1428
+									break;
1341 1429
 				}
1342
-				elseif ($support_js)
1343
-					break;
1344 1430
 			}
1345 1431
 			// Set the progress bar to be right as if we had - even if we hadn't...
1346 1432
 			$upcontext['step_progress'] = ($upcontext['cur_file_num'] / $upcontext['file_count']) * 100;
@@ -1365,8 +1451,9 @@  discard block
 block discarded – undo
1365 1451
 	global $command_line, $language, $upcontext, $sourcedir, $forum_version, $user_info, $maintenance, $smcFunc, $db_type;
1366 1452
 
1367 1453
 	// Now it's nice to have some of the basic SMF source files.
1368
-	if (!isset($_GET['ssi']) && !$command_line)
1369
-		redirectLocation('&ssi=1');
1454
+	if (!isset($_GET['ssi']) && !$command_line) {
1455
+			redirectLocation('&ssi=1');
1456
+	}
1370 1457
 
1371 1458
 	$upcontext['sub_template'] = 'upgrade_complete';
1372 1459
 	$upcontext['page_title'] = 'Upgrade Complete';
@@ -1382,14 +1469,16 @@  discard block
 block discarded – undo
1382 1469
 	// Are we in maintenance mode?
1383 1470
 	if (isset($upcontext['user']['main']))
1384 1471
 	{
1385
-		if ($command_line)
1386
-			echo ' * ';
1472
+		if ($command_line) {
1473
+					echo ' * ';
1474
+		}
1387 1475
 		$upcontext['removed_maintenance'] = true;
1388 1476
 		$changes['maintenance'] = $upcontext['user']['main'];
1389 1477
 	}
1390 1478
 	// Otherwise if somehow we are in 2 let's go to 1.
1391
-	elseif (!empty($maintenance) && $maintenance == 2)
1392
-		$changes['maintenance'] = 1;
1479
+	elseif (!empty($maintenance) && $maintenance == 2) {
1480
+			$changes['maintenance'] = 1;
1481
+	}
1393 1482
 
1394 1483
 	// Wipe this out...
1395 1484
 	$upcontext['user'] = array();
@@ -1404,9 +1493,9 @@  discard block
 block discarded – undo
1404 1493
 	$upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
1405 1494
 
1406 1495
 	// Now is the perfect time to fetch the SM files.
1407
-	if ($command_line)
1408
-		cli_scheduled_fetchSMfiles();
1409
-	else
1496
+	if ($command_line) {
1497
+			cli_scheduled_fetchSMfiles();
1498
+	} else
1410 1499
 	{
1411 1500
 		require_once($sourcedir . '/ScheduledTasks.php');
1412 1501
 		$forum_version = SMF_VERSION; // The variable is usually defined in index.php so lets just use the constant to do it for us.
@@ -1414,8 +1503,9 @@  discard block
 block discarded – undo
1414 1503
 	}
1415 1504
 
1416 1505
 	// Log what we've done.
1417
-	if (empty($user_info['id']))
1418
-		$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1506
+	if (empty($user_info['id'])) {
1507
+			$user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
1508
+	}
1419 1509
 
1420 1510
 	// Log the action manually, so CLI still works.
1421 1511
 	$smcFunc['db_insert']('',
@@ -1434,8 +1524,9 @@  discard block
 block discarded – undo
1434 1524
 
1435 1525
 	// Save the current database version.
1436 1526
 	$server_version = $smcFunc['db_server_info']();
1437
-	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51')))
1438
-		updateSettings(array('db_mysql_group_by_fix' => '1'));
1527
+	if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
1528
+			updateSettings(array('db_mysql_group_by_fix' => '1'));
1529
+	}
1439 1530
 
1440 1531
 	if ($command_line)
1441 1532
 	{
@@ -1447,8 +1538,9 @@  discard block
 block discarded – undo
1447 1538
 
1448 1539
 	// Make sure it says we're done.
1449 1540
 	$upcontext['overall_percent'] = 100;
1450
-	if (isset($upcontext['step_progress']))
1451
-		unset($upcontext['step_progress']);
1541
+	if (isset($upcontext['step_progress'])) {
1542
+			unset($upcontext['step_progress']);
1543
+	}
1452 1544
 
1453 1545
 	$_GET['substep'] = 0;
1454 1546
 	return false;
@@ -1459,8 +1551,9 @@  discard block
 block discarded – undo
1459 1551
 {
1460 1552
 	global $sourcedir, $language, $forum_version, $modSettings, $smcFunc;
1461 1553
 
1462
-	if (empty($modSettings['time_format']))
1463
-		$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1554
+	if (empty($modSettings['time_format'])) {
1555
+			$modSettings['time_format'] = '%B %d, %Y, %I:%M:%S %p';
1556
+	}
1464 1557
 
1465 1558
 	// What files do we want to get
1466 1559
 	$request = $smcFunc['db_query']('', '
@@ -1494,8 +1587,9 @@  discard block
 block discarded – undo
1494 1587
 		$file_data = fetch_web_data($url);
1495 1588
 
1496 1589
 		// If we got an error - give up - the site might be down.
1497
-		if ($file_data === false)
1498
-			return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1590
+		if ($file_data === false) {
1591
+					return throw_error(sprintf('Could not retrieve the file %1$s.', $url));
1592
+		}
1499 1593
 
1500 1594
 		// Save the file to the database.
1501 1595
 		$smcFunc['db_query']('substring', '
@@ -1537,8 +1631,9 @@  discard block
 block discarded – undo
1537 1631
 	$themeData = array();
1538 1632
 	foreach ($values as $variable => $value)
1539 1633
 	{
1540
-		if (!isset($value) || $value === null)
1541
-			$value = 0;
1634
+		if (!isset($value) || $value === null) {
1635
+					$value = 0;
1636
+		}
1542 1637
 
1543 1638
 		$themeData[] = array(0, 1, $variable, $value);
1544 1639
 	}
@@ -1567,8 +1662,9 @@  discard block
 block discarded – undo
1567 1662
 
1568 1663
 	foreach ($values as $variable => $value)
1569 1664
 	{
1570
-		if (empty($modSettings[$value[0]]))
1571
-			continue;
1665
+		if (empty($modSettings[$value[0]])) {
1666
+					continue;
1667
+		}
1572 1668
 
1573 1669
 		$smcFunc['db_query']('', '
1574 1670
 			INSERT IGNORE INTO {db_prefix}themes
@@ -1654,19 +1750,21 @@  discard block
 block discarded – undo
1654 1750
 	set_error_handler(
1655 1751
 		function ($errno, $errstr, $errfile, $errline) use ($support_js)
1656 1752
 		{
1657
-			if ($support_js)
1658
-				return true;
1659
-			else
1660
-				echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1753
+			if ($support_js) {
1754
+							return true;
1755
+			} else {
1756
+							echo 'Error: ' . $errstr . ' File: ' . $errfile . ' Line: ' . $errline;
1757
+			}
1661 1758
 		}
1662 1759
 	);
1663 1760
 
1664 1761
 	// If we're on MySQL, set {db_collation}; this approach is used throughout upgrade_2-0_mysql.php to set new tables to utf8
1665 1762
 	// Note it is expected to be in the format: ENGINE=MyISAM{$db_collation};
1666
-	if ($db_type == 'mysql')
1667
-		$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1668
-	else
1669
-		$db_collation = '';
1763
+	if ($db_type == 'mysql') {
1764
+			$db_collation = ' DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci';
1765
+	} else {
1766
+			$db_collation = '';
1767
+	}
1670 1768
 
1671 1769
 	$endl = $command_line ? "\n" : '<br>' . "\n";
1672 1770
 
@@ -1678,8 +1776,9 @@  discard block
 block discarded – undo
1678 1776
 	$last_step = '';
1679 1777
 
1680 1778
 	// Make sure all newly created tables will have the proper characters set; this approach is used throughout upgrade_2-1_mysql.php
1681
-	if (isset($db_character_set) && $db_character_set === 'utf8')
1682
-		$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1779
+	if (isset($db_character_set) && $db_character_set === 'utf8') {
1780
+			$lines = str_replace(') ENGINE=MyISAM;', ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;', $lines);
1781
+	}
1683 1782
 
1684 1783
 	// Count the total number of steps within this file - for progress.
1685 1784
 	$file_steps = substr_count(implode('', $lines), '---#');
@@ -1699,15 +1798,18 @@  discard block
 block discarded – undo
1699 1798
 		$do_current = $substep >= $_GET['substep'];
1700 1799
 
1701 1800
 		// Get rid of any comments in the beginning of the line...
1702
-		if (substr(trim($line), 0, 2) === '/*')
1703
-			$line = preg_replace('~/\*.+?\*/~', '', $line);
1801
+		if (substr(trim($line), 0, 2) === '/*') {
1802
+					$line = preg_replace('~/\*.+?\*/~', '', $line);
1803
+		}
1704 1804
 
1705 1805
 		// Always flush.  Flush, flush, flush.  Flush, flush, flush, flush!  FLUSH!
1706
-		if ($is_debug && !$support_js && $command_line)
1707
-			flush();
1806
+		if ($is_debug && !$support_js && $command_line) {
1807
+					flush();
1808
+		}
1708 1809
 
1709
-		if (trim($line) === '')
1710
-			continue;
1810
+		if (trim($line) === '') {
1811
+					continue;
1812
+		}
1711 1813
 
1712 1814
 		if (trim(substr($line, 0, 3)) === '---')
1713 1815
 		{
@@ -1717,8 +1819,9 @@  discard block
 block discarded – undo
1717 1819
 			if (trim($current_data) != '' && $type !== '}')
1718 1820
 			{
1719 1821
 				$upcontext['error_message'] = 'Error in upgrade script - line ' . $line_number . '!' . $endl;
1720
-				if ($command_line)
1721
-					echo $upcontext['error_message'];
1822
+				if ($command_line) {
1823
+									echo $upcontext['error_message'];
1824
+				}
1722 1825
 			}
1723 1826
 
1724 1827
 			if ($type == ' ')
@@ -1736,17 +1839,18 @@  discard block
 block discarded – undo
1736 1839
 				if ($do_current)
1737 1840
 				{
1738 1841
 					$upcontext['actioned_items'][] = $last_step;
1739
-					if ($command_line)
1740
-						echo ' * ';
1842
+					if ($command_line) {
1843
+											echo ' * ';
1844
+					}
1741 1845
 				}
1742
-			}
1743
-			elseif ($type == '#')
1846
+			} elseif ($type == '#')
1744 1847
 			{
1745 1848
 				$upcontext['step_progress'] += (100 / $upcontext['file_count']) / $file_steps;
1746 1849
 
1747 1850
 				$upcontext['current_debug_item_num']++;
1748
-				if (trim($line) != '---#')
1749
-					$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1851
+				if (trim($line) != '---#') {
1852
+									$upcontext['current_debug_item_name'] = htmlspecialchars(rtrim(substr($line, 4)));
1853
+				}
1750 1854
 
1751 1855
 				// Have we already done something?
1752 1856
 				if (isset($_GET['xml']) && $done_something)
@@ -1757,34 +1861,36 @@  discard block
 block discarded – undo
1757 1861
 
1758 1862
 				if ($do_current)
1759 1863
 				{
1760
-					if (trim($line) == '---#' && $command_line)
1761
-						echo ' done.', $endl;
1762
-					elseif ($command_line)
1763
-						echo ' +++ ', rtrim(substr($line, 4));
1764
-					elseif (trim($line) != '---#')
1864
+					if (trim($line) == '---#' && $command_line) {
1865
+											echo ' done.', $endl;
1866
+					} elseif ($command_line) {
1867
+											echo ' +++ ', rtrim(substr($line, 4));
1868
+					} elseif (trim($line) != '---#')
1765 1869
 					{
1766
-						if ($is_debug)
1767
-							$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1870
+						if ($is_debug) {
1871
+													$upcontext['actioned_items'][] = htmlspecialchars(rtrim(substr($line, 4)));
1872
+						}
1768 1873
 					}
1769 1874
 				}
1770 1875
 
1771 1876
 				if ($substep < $_GET['substep'] && $substep + 1 >= $_GET['substep'])
1772 1877
 				{
1773
-					if ($command_line)
1774
-						echo ' * ';
1775
-					else
1776
-						$upcontext['actioned_items'][] = $last_step;
1878
+					if ($command_line) {
1879
+											echo ' * ';
1880
+					} else {
1881
+											$upcontext['actioned_items'][] = $last_step;
1882
+					}
1777 1883
 				}
1778 1884
 
1779 1885
 				// Small step - only if we're actually doing stuff.
1780
-				if ($do_current)
1781
-					nextSubstep(++$substep);
1782
-				else
1783
-					$substep++;
1784
-			}
1785
-			elseif ($type == '{')
1786
-				$current_type = 'code';
1787
-			elseif ($type == '}')
1886
+				if ($do_current) {
1887
+									nextSubstep(++$substep);
1888
+				} else {
1889
+									$substep++;
1890
+				}
1891
+			} elseif ($type == '{') {
1892
+							$current_type = 'code';
1893
+			} elseif ($type == '}')
1788 1894
 			{
1789 1895
 				$current_type = 'sql';
1790 1896
 
@@ -1797,8 +1903,9 @@  discard block
 block discarded – undo
1797 1903
 				if (eval('global $db_prefix, $modSettings, $smcFunc; ' . $current_data) === false)
1798 1904
 				{
1799 1905
 					$upcontext['error_message'] = 'Error in upgrade script ' . basename($filename) . ' on line ' . $line_number . '!' . $endl;
1800
-					if ($command_line)
1801
-						echo $upcontext['error_message'];
1906
+					if ($command_line) {
1907
+											echo $upcontext['error_message'];
1908
+					}
1802 1909
 				}
1803 1910
 
1804 1911
 				// Done with code!
@@ -1878,8 +1985,9 @@  discard block
 block discarded – undo
1878 1985
 	$db_unbuffered = false;
1879 1986
 
1880 1987
 	// Failure?!
1881
-	if ($result !== false)
1882
-		return $result;
1988
+	if ($result !== false) {
1989
+			return $result;
1990
+	}
1883 1991
 
1884 1992
 	$db_error_message = $smcFunc['db_error']($db_connection);
1885 1993
 	// If MySQL we do something more clever.
@@ -1907,54 +2015,61 @@  discard block
 block discarded – undo
1907 2015
 			{
1908 2016
 				mysqli_query($db_connection, 'REPAIR TABLE `' . $match[1] . '`');
1909 2017
 				$result = mysqli_query($db_connection, $string);
1910
-				if ($result !== false)
1911
-					return $result;
2018
+				if ($result !== false) {
2019
+									return $result;
2020
+				}
1912 2021
 			}
1913
-		}
1914
-		elseif ($mysqli_errno == 2013)
2022
+		} elseif ($mysqli_errno == 2013)
1915 2023
 		{
1916 2024
 			$db_connection = mysqli_connect($db_server, $db_user, $db_passwd);
1917 2025
 			mysqli_select_db($db_connection, $db_name);
1918 2026
 			if ($db_connection)
1919 2027
 			{
1920 2028
 				$result = mysqli_query($db_connection, $string);
1921
-				if ($result !== false)
1922
-					return $result;
2029
+				if ($result !== false) {
2030
+									return $result;
2031
+				}
1923 2032
 			}
1924 2033
 		}
1925 2034
 		// Duplicate column name... should be okay ;).
1926
-		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091)))
1927
-			return false;
2035
+		elseif (in_array($mysqli_errno, array(1060, 1061, 1068, 1091))) {
2036
+					return false;
2037
+		}
1928 2038
 		// Duplicate insert... make sure it's the proper type of query ;).
1929
-		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query)
1930
-			return false;
2039
+		elseif (in_array($mysqli_errno, array(1054, 1062, 1146)) && $error_query) {
2040
+					return false;
2041
+		}
1931 2042
 		// Creating an index on a non-existent column.
1932
-		elseif ($mysqli_errno == 1072)
1933
-			return false;
1934
-		elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE')
1935
-			return false;
2043
+		elseif ($mysqli_errno == 1072) {
2044
+					return false;
2045
+		} elseif ($mysqli_errno == 1050 && substr(trim($string), 0, 12) == 'RENAME TABLE') {
2046
+					return false;
2047
+		}
1936 2048
 	}
1937 2049
 	// If a table already exists don't go potty.
1938 2050
 	else
1939 2051
 	{
1940 2052
 		if (in_array(substr(trim($string), 0, 8), array('CREATE T', 'CREATE S', 'DROP TABL', 'ALTER TA', 'CREATE I', 'CREATE U')))
1941 2053
 		{
1942
-			if (strpos($db_error_message, 'exist') !== false)
1943
-				return true;
1944
-		}
1945
-		elseif (strpos(trim($string), 'INSERT ') !== false)
2054
+			if (strpos($db_error_message, 'exist') !== false) {
2055
+							return true;
2056
+			}
2057
+		} elseif (strpos(trim($string), 'INSERT ') !== false)
1946 2058
 		{
1947
-			if (strpos($db_error_message, 'duplicate') !== false)
1948
-				return true;
2059
+			if (strpos($db_error_message, 'duplicate') !== false) {
2060
+							return true;
2061
+			}
1949 2062
 		}
1950 2063
 	}
1951 2064
 
1952 2065
 	// Get the query string so we pass everything.
1953 2066
 	$query_string = '';
1954
-	foreach ($_GET as $k => $v)
1955
-		$query_string .= ';' . $k . '=' . $v;
1956
-	if (strlen($query_string) != 0)
1957
-		$query_string = '?' . substr($query_string, 1);
2067
+	foreach ($_GET as $k => $v) {
2068
+			$query_string .= ';' . $k . '=' . $v;
2069
+	}
2070
+	if (strlen($query_string) != 0) {
2071
+			$query_string = '?' . substr($query_string, 1);
2072
+	}
1958 2073
 
1959 2074
 	if ($command_line)
1960 2075
 	{
@@ -2009,16 +2124,18 @@  discard block
 block discarded – undo
2009 2124
 			{
2010 2125
 				$found |= 1;
2011 2126
 				// Do some checks on the data if we have it set.
2012
-				if (isset($change['col_type']))
2013
-					$found &= $change['col_type'] === $column['type'];
2014
-				if (isset($change['null_allowed']))
2015
-					$found &= $column['null'] == $change['null_allowed'];
2016
-				if (isset($change['default']))
2017
-					$found &= $change['default'] === $column['default'];
2127
+				if (isset($change['col_type'])) {
2128
+									$found &= $change['col_type'] === $column['type'];
2129
+				}
2130
+				if (isset($change['null_allowed'])) {
2131
+									$found &= $column['null'] == $change['null_allowed'];
2132
+				}
2133
+				if (isset($change['default'])) {
2134
+									$found &= $change['default'] === $column['default'];
2135
+				}
2018 2136
 			}
2019 2137
 		}
2020
-	}
2021
-	elseif ($change['type'] === 'index')
2138
+	} elseif ($change['type'] === 'index')
2022 2139
 	{
2023 2140
 		$request = upgrade_query('
2024 2141
 			SHOW INDEX
@@ -2027,9 +2144,10 @@  discard block
 block discarded – undo
2027 2144
 		{
2028 2145
 			$cur_index = array();
2029 2146
 
2030
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2031
-				if ($row['Key_name'] === $change['name'])
2147
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2148
+							if ($row['Key_name'] === $change['name'])
2032 2149
 					$cur_index[(int) $row['Seq_in_index']] = $row['Column_name'];
2150
+			}
2033 2151
 
2034 2152
 			ksort($cur_index, SORT_NUMERIC);
2035 2153
 			$found = array_values($cur_index) === $change['target_columns'];
@@ -2039,14 +2157,17 @@  discard block
 block discarded – undo
2039 2157
 	}
2040 2158
 
2041 2159
 	// If we're trying to add and it's added, we're done.
2042
-	if ($found && in_array($change['method'], array('add', 'change')))
2043
-		return true;
2160
+	if ($found && in_array($change['method'], array('add', 'change'))) {
2161
+			return true;
2162
+	}
2044 2163
 	// Otherwise if we're removing and it wasn't found we're also done.
2045
-	elseif (!$found && in_array($change['method'], array('remove', 'change_remove')))
2046
-		return true;
2164
+	elseif (!$found && in_array($change['method'], array('remove', 'change_remove'))) {
2165
+			return true;
2166
+	}
2047 2167
 	// Otherwise is it just a test?
2048
-	elseif ($is_test)
2049
-		return false;
2168
+	elseif ($is_test) {
2169
+			return false;
2170
+	}
2050 2171
 
2051 2172
 	// Not found it yet? Bummer! How about we see if we're currently doing it?
2052 2173
 	$running = false;
@@ -2057,8 +2178,9 @@  discard block
 block discarded – undo
2057 2178
 			SHOW FULL PROCESSLIST');
2058 2179
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2059 2180
 		{
2060
-			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false)
2061
-				$found = true;
2181
+			if (strpos($row['Info'], 'ALTER TABLE ' . $db_prefix . $change['table']) !== false && strpos($row['Info'], $change['text']) !== false) {
2182
+							$found = true;
2183
+			}
2062 2184
 		}
2063 2185
 
2064 2186
 		// Can't find it? Then we need to run it fools!
@@ -2070,8 +2192,9 @@  discard block
 block discarded – undo
2070 2192
 				ALTER TABLE ' . $db_prefix . $change['table'] . '
2071 2193
 				' . $change['text'], true) !== false;
2072 2194
 
2073
-			if (!$success)
2074
-				return false;
2195
+			if (!$success) {
2196
+							return false;
2197
+			}
2075 2198
 
2076 2199
 			// Return
2077 2200
 			$running = true;
@@ -2113,8 +2236,9 @@  discard block
 block discarded – undo
2113 2236
 			'db_error_skip' => true,
2114 2237
 		)
2115 2238
 	);
2116
-	if ($smcFunc['db_num_rows']($request) === 0)
2117
-		die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2239
+	if ($smcFunc['db_num_rows']($request) === 0) {
2240
+			die('Unable to find column ' . $change['column'] . ' inside table ' . $db_prefix . $change['table']);
2241
+	}
2118 2242
 	$table_row = $smcFunc['db_fetch_assoc']($request);
2119 2243
 	$smcFunc['db_free_result']($request);
2120 2244
 
@@ -2136,18 +2260,19 @@  discard block
 block discarded – undo
2136 2260
 			)
2137 2261
 		);
2138 2262
 		// No results? Just forget it all together.
2139
-		if ($smcFunc['db_num_rows']($request) === 0)
2140
-			unset($table_row['Collation']);
2141
-		else
2142
-			$collation_info = $smcFunc['db_fetch_assoc']($request);
2263
+		if ($smcFunc['db_num_rows']($request) === 0) {
2264
+					unset($table_row['Collation']);
2265
+		} else {
2266
+					$collation_info = $smcFunc['db_fetch_assoc']($request);
2267
+		}
2143 2268
 		$smcFunc['db_free_result']($request);
2144 2269
 	}
2145 2270
 
2146 2271
 	if ($column_fix)
2147 2272
 	{
2148 2273
 		// Make sure there are no NULL's left.
2149
-		if ($null_fix)
2150
-			$smcFunc['db_query']('', '
2274
+		if ($null_fix) {
2275
+					$smcFunc['db_query']('', '
2151 2276
 				UPDATE {db_prefix}' . $change['table'] . '
2152 2277
 				SET ' . $change['column'] . ' = {string:default}
2153 2278
 				WHERE ' . $change['column'] . ' IS NULL',
@@ -2156,6 +2281,7 @@  discard block
 block discarded – undo
2156 2281
 					'db_error_skip' => true,
2157 2282
 				)
2158 2283
 			);
2284
+		}
2159 2285
 
2160 2286
 		// Do the actual alteration.
2161 2287
 		$smcFunc['db_query']('', '
@@ -2184,8 +2310,9 @@  discard block
 block discarded – undo
2184 2310
 	}
2185 2311
 
2186 2312
 	// Not a column we need to check on?
2187
-	if (!in_array($change['name'], array('memberGroups', 'passwordSalt')))
2188
-		return;
2313
+	if (!in_array($change['name'], array('memberGroups', 'passwordSalt'))) {
2314
+			return;
2315
+	}
2189 2316
 
2190 2317
 	// Break it up you (six|seven).
2191 2318
 	$temp = explode(' ', str_replace('NOT NULL', 'NOT_NULL', $change['text']));
@@ -2204,13 +2331,13 @@  discard block
 block discarded – undo
2204 2331
 				'new_name' => $temp[2],
2205 2332
 		));
2206 2333
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2207
-		if ($smcFunc['db_num_rows'] != 1)
2208
-			return;
2334
+		if ($smcFunc['db_num_rows'] != 1) {
2335
+					return;
2336
+		}
2209 2337
 
2210 2338
 		list (, $current_type) = $smcFunc['db_fetch_assoc']($request);
2211 2339
 		$smcFunc['db_free_result']($request);
2212
-	}
2213
-	else
2340
+	} else
2214 2341
 	{
2215 2342
 		// Do this the old fashion, sure method way.
2216 2343
 		$request = $smcFunc['db_query']('', '
@@ -2221,21 +2348,24 @@  discard block
 block discarded – undo
2221 2348
 		));
2222 2349
 		// Mayday!
2223 2350
 		// !!! This doesn't technically work because we don't pass request into it, but it hasn't broke anything yet.
2224
-		if ($smcFunc['db_num_rows'] == 0)
2225
-			return;
2351
+		if ($smcFunc['db_num_rows'] == 0) {
2352
+					return;
2353
+		}
2226 2354
 
2227 2355
 		// Oh where, oh where has my little field gone. Oh where can it be...
2228
-		while ($row = $smcFunc['db_query']($request))
2229
-			if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2356
+		while ($row = $smcFunc['db_query']($request)) {
2357
+					if ($row['Field'] == $temp[1] || $row['Field'] == $temp[2])
2230 2358
 			{
2231 2359
 				$current_type = $row['Type'];
2360
+		}
2232 2361
 				break;
2233 2362
 			}
2234 2363
 	}
2235 2364
 
2236 2365
 	// If this doesn't match, the column may of been altered for a reason.
2237
-	if (trim($current_type) != trim($temp[3]))
2238
-		$temp[3] = $current_type;
2366
+	if (trim($current_type) != trim($temp[3])) {
2367
+			$temp[3] = $current_type;
2368
+	}
2239 2369
 
2240 2370
 	// Piece this back together.
2241 2371
 	$change['text'] = str_replace('NOT_NULL', 'NOT NULL', implode(' ', $temp));
@@ -2247,8 +2377,9 @@  discard block
 block discarded – undo
2247 2377
 	global $start_time, $timeLimitThreshold, $command_line, $custom_warning;
2248 2378
 	global $step_progress, $is_debug, $upcontext;
2249 2379
 
2250
-	if ($_GET['substep'] < $substep)
2251
-		$_GET['substep'] = $substep;
2380
+	if ($_GET['substep'] < $substep) {
2381
+			$_GET['substep'] = $substep;
2382
+	}
2252 2383
 
2253 2384
 	if ($command_line)
2254 2385
 	{
@@ -2261,29 +2392,33 @@  discard block
 block discarded – undo
2261 2392
 	}
2262 2393
 
2263 2394
 	@set_time_limit(300);
2264
-	if (function_exists('apache_reset_timeout'))
2265
-		@apache_reset_timeout();
2395
+	if (function_exists('apache_reset_timeout')) {
2396
+			@apache_reset_timeout();
2397
+	}
2266 2398
 
2267
-	if (time() - $start_time <= $timeLimitThreshold)
2268
-		return;
2399
+	if (time() - $start_time <= $timeLimitThreshold) {
2400
+			return;
2401
+	}
2269 2402
 
2270 2403
 	// Do we have some custom step progress stuff?
2271 2404
 	if (!empty($step_progress))
2272 2405
 	{
2273 2406
 		$upcontext['substep_progress'] = 0;
2274 2407
 		$upcontext['substep_progress_name'] = $step_progress['name'];
2275
-		if ($step_progress['current'] > $step_progress['total'])
2276
-			$upcontext['substep_progress'] = 99.9;
2277
-		else
2278
-			$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2408
+		if ($step_progress['current'] > $step_progress['total']) {
2409
+					$upcontext['substep_progress'] = 99.9;
2410
+		} else {
2411
+					$upcontext['substep_progress'] = ($step_progress['current'] / $step_progress['total']) * 100;
2412
+		}
2279 2413
 
2280 2414
 		// Make it nicely rounded.
2281 2415
 		$upcontext['substep_progress'] = round($upcontext['substep_progress'], 1);
2282 2416
 	}
2283 2417
 
2284 2418
 	// If this is XML we just exit right away!
2285
-	if (isset($_GET['xml']))
2286
-		return upgradeExit();
2419
+	if (isset($_GET['xml'])) {
2420
+			return upgradeExit();
2421
+	}
2287 2422
 
2288 2423
 	// We're going to pause after this!
2289 2424
 	$upcontext['pause'] = true;
@@ -2291,13 +2426,15 @@  discard block
 block discarded – undo
2291 2426
 	$upcontext['query_string'] = '';
2292 2427
 	foreach ($_GET as $k => $v)
2293 2428
 	{
2294
-		if ($k != 'data' && $k != 'substep' && $k != 'step')
2295
-			$upcontext['query_string'] .= ';' . $k . '=' . $v;
2429
+		if ($k != 'data' && $k != 'substep' && $k != 'step') {
2430
+					$upcontext['query_string'] .= ';' . $k . '=' . $v;
2431
+		}
2296 2432
 	}
2297 2433
 
2298 2434
 	// Custom warning?
2299
-	if (!empty($custom_warning))
2300
-		$upcontext['custom_warning'] = $custom_warning;
2435
+	if (!empty($custom_warning)) {
2436
+			$upcontext['custom_warning'] = $custom_warning;
2437
+	}
2301 2438
 
2302 2439
 	upgradeExit();
2303 2440
 }
@@ -2312,25 +2449,26 @@  discard block
 block discarded – undo
2312 2449
 	ob_implicit_flush(true);
2313 2450
 	@set_time_limit(600);
2314 2451
 
2315
-	if (!isset($_SERVER['argv']))
2316
-		$_SERVER['argv'] = array();
2452
+	if (!isset($_SERVER['argv'])) {
2453
+			$_SERVER['argv'] = array();
2454
+	}
2317 2455
 	$_GET['maint'] = 1;
2318 2456
 
2319 2457
 	foreach ($_SERVER['argv'] as $i => $arg)
2320 2458
 	{
2321
-		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0)
2322
-			$_GET['lang'] = $match[1];
2323
-		elseif (preg_match('~^--path=(.+)$~', $arg) != 0)
2324
-			continue;
2325
-		elseif ($arg == '--no-maintenance')
2326
-			$_GET['maint'] = 0;
2327
-		elseif ($arg == '--debug')
2328
-			$is_debug = true;
2329
-		elseif ($arg == '--backup')
2330
-			$_POST['backup'] = 1;
2331
-		elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted')))
2332
-			$_GET['conv'] = 1;
2333
-		elseif ($i != 0)
2459
+		if (preg_match('~^--language=(.+)$~', $arg, $match) != 0) {
2460
+					$_GET['lang'] = $match[1];
2461
+		} elseif (preg_match('~^--path=(.+)$~', $arg) != 0) {
2462
+					continue;
2463
+		} elseif ($arg == '--no-maintenance') {
2464
+					$_GET['maint'] = 0;
2465
+		} elseif ($arg == '--debug') {
2466
+					$is_debug = true;
2467
+		} elseif ($arg == '--backup') {
2468
+					$_POST['backup'] = 1;
2469
+		} elseif ($arg == '--template' && (file_exists($boarddir . '/template.php') || file_exists($boarddir . '/template.html') && !file_exists($modSettings['theme_dir'] . '/converted'))) {
2470
+					$_GET['conv'] = 1;
2471
+		} elseif ($i != 0)
2334 2472
 		{
2335 2473
 			echo 'SMF Command-line Upgrader
2336 2474
 Usage: /path/to/php -f ' . basename(__FILE__) . ' -- [OPTION]...
@@ -2344,10 +2482,12 @@  discard block
 block discarded – undo
2344 2482
 		}
2345 2483
 	}
2346 2484
 
2347
-	if (!php_version_check())
2348
-		print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2349
-	if (!db_version_check())
2350
-		print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2485
+	if (!php_version_check()) {
2486
+			print_error('Error: PHP ' . PHP_VERSION . ' does not match version requirements.', true);
2487
+	}
2488
+	if (!db_version_check()) {
2489
+			print_error('Error: ' . $databases[$db_type]['name'] . ' ' . $databases[$db_type]['version'] . ' does not match minimum requirements.', true);
2490
+	}
2351 2491
 
2352 2492
 	// Do some checks to make sure they have proper privileges
2353 2493
 	db_extend('packages');
@@ -2362,39 +2502,45 @@  discard block
 block discarded – undo
2362 2502
 	$drop = $smcFunc['db_drop_table']('{db_prefix}priv_check');
2363 2503
 
2364 2504
 	// Sorry... we need CREATE, ALTER and DROP
2365
-	if (!$create || !$alter || !$drop)
2366
-		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);
2505
+	if (!$create || !$alter || !$drop) {
2506
+			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);
2507
+	}
2367 2508
 
2368 2509
 	$check = @file_exists($modSettings['theme_dir'] . '/index.template.php')
2369 2510
 		&& @file_exists($sourcedir . '/QueryString.php')
2370 2511
 		&& @file_exists($sourcedir . '/ManageBoards.php');
2371
-	if (!$check && !isset($modSettings['smfVersion']))
2372
-		print_error('Error: Some files are missing or out-of-date.', true);
2512
+	if (!$check && !isset($modSettings['smfVersion'])) {
2513
+			print_error('Error: Some files are missing or out-of-date.', true);
2514
+	}
2373 2515
 
2374 2516
 	// Do a quick version spot check.
2375 2517
 	$temp = substr(@implode('', @file($boarddir . '/index.php')), 0, 4096);
2376 2518
 	preg_match('~\*\s@version\s+(.+)[\s]{2}~i', $temp, $match);
2377
-	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION))
2378
-		print_error('Error: Some files have not yet been updated properly.');
2519
+	if (empty($match[1]) || (trim($match[1]) != SMF_VERSION)) {
2520
+			print_error('Error: Some files have not yet been updated properly.');
2521
+	}
2379 2522
 
2380 2523
 	// Make sure Settings.php is writable.
2381 2524
 	quickFileWritable($boarddir . '/Settings.php');
2382
-	if (!is_writable($boarddir . '/Settings.php'))
2383
-		print_error('Error: Unable to obtain write access to "Settings.php".', true);
2525
+	if (!is_writable($boarddir . '/Settings.php')) {
2526
+			print_error('Error: Unable to obtain write access to "Settings.php".', true);
2527
+	}
2384 2528
 
2385 2529
 	// Make sure Settings_bak.php is writable.
2386 2530
 	quickFileWritable($boarddir . '/Settings_bak.php');
2387
-	if (!is_writable($boarddir . '/Settings_bak.php'))
2388
-		print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2531
+	if (!is_writable($boarddir . '/Settings_bak.php')) {
2532
+			print_error('Error: Unable to obtain write access to "Settings_bak.php".');
2533
+	}
2389 2534
 
2390 2535
 	// Make sure db_last_error.php is writable.
2391 2536
 	quickFileWritable($boarddir . '/db_last_error.php');
2392
-	if (!is_writable($boarddir . '/db_last_error.php'))
2393
-		print_error('Error: Unable to obtain write access to "db_last_error.php".');
2537
+	if (!is_writable($boarddir . '/db_last_error.php')) {
2538
+			print_error('Error: Unable to obtain write access to "db_last_error.php".');
2539
+	}
2394 2540
 
2395
-	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt'))
2396
-		print_error('Error: Unable to obtain write access to "agreement.txt".');
2397
-	elseif (isset($modSettings['agreement']))
2541
+	if (isset($modSettings['agreement']) && (!is_writable($boarddir) || file_exists($boarddir . '/agreement.txt')) && !is_writable($boarddir . '/agreement.txt')) {
2542
+			print_error('Error: Unable to obtain write access to "agreement.txt".');
2543
+	} elseif (isset($modSettings['agreement']))
2398 2544
 	{
2399 2545
 		$fp = fopen($boarddir . '/agreement.txt', 'w');
2400 2546
 		fwrite($fp, $modSettings['agreement']);
@@ -2404,31 +2550,36 @@  discard block
 block discarded – undo
2404 2550
 	// Make sure Themes is writable.
2405 2551
 	quickFileWritable($modSettings['theme_dir']);
2406 2552
 
2407
-	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion']))
2408
-		print_error('Error: Unable to obtain write access to "Themes".');
2553
+	if (!is_writable($modSettings['theme_dir']) && !isset($modSettings['smfVersion'])) {
2554
+			print_error('Error: Unable to obtain write access to "Themes".');
2555
+	}
2409 2556
 
2410 2557
 	// Make sure cache directory exists and is writable!
2411 2558
 	$cachedir_temp = empty($cachedir) ? $boarddir . '/cache' : $cachedir;
2412
-	if (!file_exists($cachedir_temp))
2413
-		@mkdir($cachedir_temp);
2559
+	if (!file_exists($cachedir_temp)) {
2560
+			@mkdir($cachedir_temp);
2561
+	}
2414 2562
 
2415 2563
 	// Make sure the cache temp dir is writable.
2416 2564
 	quickFileWritable($cachedir_temp);
2417 2565
 
2418
-	if (!is_writable($cachedir_temp))
2419
-		print_error('Error: Unable to obtain write access to "cache".', true);
2566
+	if (!is_writable($cachedir_temp)) {
2567
+			print_error('Error: Unable to obtain write access to "cache".', true);
2568
+	}
2420 2569
 
2421
-	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang']))
2422
-		print_error('Error: Unable to find language files!', true);
2423
-	else
2570
+	if (!file_exists($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php') && !isset($modSettings['smfVersion']) && !isset($_GET['lang'])) {
2571
+			print_error('Error: Unable to find language files!', true);
2572
+	} else
2424 2573
 	{
2425 2574
 		$temp = substr(@implode('', @file($modSettings['theme_dir'] . '/languages/index.' . $upcontext['language'] . '.php')), 0, 4096);
2426 2575
 		preg_match('~(?://|/\*)\s*Version:\s+(.+?);\s*index(?:[\s]{2}|\*/)~i', $temp, $match);
2427 2576
 
2428
-		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION)
2429
-			print_error('Error: Language files out of date.', true);
2430
-		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php'))
2431
-			print_error('Error: Install language is missing for selected language.', true);
2577
+		if (empty($match[1]) || $match[1] != SMF_LANG_VERSION) {
2578
+					print_error('Error: Language files out of date.', true);
2579
+		}
2580
+		if (!file_exists($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php')) {
2581
+					print_error('Error: Install language is missing for selected language.', true);
2582
+		}
2432 2583
 
2433 2584
 		// Otherwise include it!
2434 2585
 		require_once($modSettings['theme_dir'] . '/languages/Install.' . $upcontext['language'] . '.php');
@@ -2447,8 +2598,9 @@  discard block
 block discarded – undo
2447 2598
 	global $upcontext, $db_character_set, $sourcedir, $smcFunc, $modSettings, $language, $db_prefix, $db_type, $command_line, $support_js;
2448 2599
 
2449 2600
 	// Done it already?
2450
-	if (!empty($_POST['utf8_done']))
2451
-		return true;
2601
+	if (!empty($_POST['utf8_done'])) {
2602
+			return true;
2603
+	}
2452 2604
 
2453 2605
 	// First make sure they aren't already on UTF-8 before we go anywhere...
2454 2606
 	if ($db_type == 'postgresql' || ($db_character_set === 'utf8' && !empty($modSettings['global_character_set']) && $modSettings['global_character_set'] === 'UTF-8'))
@@ -2461,8 +2613,7 @@  discard block
 block discarded – undo
2461 2613
 		);
2462 2614
 
2463 2615
 		return true;
2464
-	}
2465
-	else
2616
+	} else
2466 2617
 	{
2467 2618
 		$upcontext['page_title'] = 'Converting to UTF8';
2468 2619
 		$upcontext['sub_template'] = isset($_GET['xml']) ? 'convert_xml' : 'convert_utf8';
@@ -2506,8 +2657,9 @@  discard block
 block discarded – undo
2506 2657
 			)
2507 2658
 		);
2508 2659
 		$db_charsets = array();
2509
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2510
-			$db_charsets[] = $row['Charset'];
2660
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2661
+					$db_charsets[] = $row['Charset'];
2662
+		}
2511 2663
 
2512 2664
 		$smcFunc['db_free_result']($request);
2513 2665
 
@@ -2543,13 +2695,15 @@  discard block
 block discarded – undo
2543 2695
 		// If there's a fulltext index, we need to drop it first...
2544 2696
 		if ($request !== false || $smcFunc['db_num_rows']($request) != 0)
2545 2697
 		{
2546
-			while ($row = $smcFunc['db_fetch_assoc']($request))
2547
-				if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2698
+			while ($row = $smcFunc['db_fetch_assoc']($request)) {
2699
+							if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT'))
2548 2700
 					$upcontext['fulltext_index'][] = $row['Key_name'];
2701
+			}
2549 2702
 			$smcFunc['db_free_result']($request);
2550 2703
 
2551
-			if (isset($upcontext['fulltext_index']))
2552
-				$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2704
+			if (isset($upcontext['fulltext_index'])) {
2705
+							$upcontext['fulltext_index'] = array_unique($upcontext['fulltext_index']);
2706
+			}
2553 2707
 		}
2554 2708
 
2555 2709
 		// Drop it and make a note...
@@ -2739,8 +2893,9 @@  discard block
 block discarded – undo
2739 2893
 			$replace = '%field%';
2740 2894
 
2741 2895
 			// Build a huge REPLACE statement...
2742
-			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to)
2743
-				$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2896
+			foreach ($translation_tables[$upcontext['charset_detected']] as $from => $to) {
2897
+							$replace = 'REPLACE(' . $replace . ', ' . $from . ', ' . $to . ')';
2898
+			}
2744 2899
 		}
2745 2900
 
2746 2901
 		// Get a list of table names ahead of time... This makes it easier to set our substep and such
@@ -2750,9 +2905,10 @@  discard block
 block discarded – undo
2750 2905
 		$upcontext['table_count'] = count($queryTables);
2751 2906
 
2752 2907
 		// What ones have we already done?
2753
-		foreach ($queryTables as $id => $table)
2754
-			if ($id < $_GET['substep'])
2908
+		foreach ($queryTables as $id => $table) {
2909
+					if ($id < $_GET['substep'])
2755 2910
 				$upcontext['previous_tables'][] = $table;
2911
+		}
2756 2912
 
2757 2913
 		$upcontext['cur_table_num'] = $_GET['substep'];
2758 2914
 		$upcontext['cur_table_name'] = str_replace($db_prefix, '', $queryTables[$_GET['substep']]);
@@ -2789,8 +2945,9 @@  discard block
 block discarded – undo
2789 2945
 			nextSubstep($substep);
2790 2946
 
2791 2947
 			// Just to make sure it doesn't time out.
2792
-			if (function_exists('apache_reset_timeout'))
2793
-				@apache_reset_timeout();
2948
+			if (function_exists('apache_reset_timeout')) {
2949
+							@apache_reset_timeout();
2950
+			}
2794 2951
 
2795 2952
 			$table_charsets = array();
2796 2953
 
@@ -2813,8 +2970,9 @@  discard block
 block discarded – undo
2813 2970
 
2814 2971
 						// Build structure of columns to operate on organized by charset; only operate on columns not yet utf8
2815 2972
 						if ($charset != 'utf8') {
2816
-							if (!isset($table_charsets[$charset]))
2817
-								$table_charsets[$charset] = array();
2973
+							if (!isset($table_charsets[$charset])) {
2974
+															$table_charsets[$charset] = array();
2975
+							}
2818 2976
 
2819 2977
 							$table_charsets[$charset][] = $column_info;
2820 2978
 						}
@@ -2855,10 +3013,11 @@  discard block
 block discarded – undo
2855 3013
 				if (isset($translation_tables[$upcontext['charset_detected']]))
2856 3014
 				{
2857 3015
 					$update = '';
2858
-					foreach ($table_charsets as $charset => $columns)
2859
-						foreach ($columns as $column)
3016
+					foreach ($table_charsets as $charset => $columns) {
3017
+											foreach ($columns as $column)
2860 3018
 							$update .= '
2861 3019
 								' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
3020
+					}
2862 3021
 
2863 3022
 					$smcFunc['db_query']('', '
2864 3023
 						UPDATE {raw:table_name}
@@ -2883,8 +3042,9 @@  discard block
 block discarded – undo
2883 3042
 			// Now do the actual conversion (if still needed).
2884 3043
 			if ($charsets[$upcontext['charset_detected']] !== 'utf8')
2885 3044
 			{
2886
-				if ($command_line)
2887
-					echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3045
+				if ($command_line) {
3046
+									echo 'Converting table ' . $table_info['Name'] . ' to UTF-8...';
3047
+				}
2888 3048
 
2889 3049
 				$smcFunc['db_query']('', '
2890 3050
 					ALTER TABLE {raw:table_name}
@@ -2894,12 +3054,14 @@  discard block
 block discarded – undo
2894 3054
 					)
2895 3055
 				);
2896 3056
 
2897
-				if ($command_line)
2898
-					echo " done.\n";
3057
+				if ($command_line) {
3058
+									echo " done.\n";
3059
+				}
2899 3060
 			}
2900 3061
 			// If this is XML to keep it nice for the user do one table at a time anyway!
2901
-			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count'])
2902
-				return upgradeExit();
3062
+			if (isset($_GET['xml']) && $upcontext['cur_table_num'] < $upcontext['table_count']) {
3063
+							return upgradeExit();
3064
+			}
2903 3065
 		}
2904 3066
 
2905 3067
 		$prev_charset = empty($translation_tables[$upcontext['charset_detected']]) ? $charsets[$upcontext['charset_detected']] : $translation_tables[$upcontext['charset_detected']];
@@ -2928,8 +3090,8 @@  discard block
 block discarded – undo
2928 3090
 		);
2929 3091
 		while ($row = $smcFunc['db_fetch_assoc']($request))
2930 3092
 		{
2931
-			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)
2932
-				$smcFunc['db_query']('', '
3093
+			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) {
3094
+							$smcFunc['db_query']('', '
2933 3095
 					UPDATE {db_prefix}log_actions
2934 3096
 					SET extra = {string:extra}
2935 3097
 					WHERE id_action = {int:current_action}',
@@ -2938,6 +3100,7 @@  discard block
 block discarded – undo
2938 3100
 						'extra' => $matches[1] . strlen($matches[3]) . ':"' . $matches[3] . '"' . $matches[4],
2939 3101
 					)
2940 3102
 				);
3103
+			}
2941 3104
 		}
2942 3105
 		$smcFunc['db_free_result']($request);
2943 3106
 
@@ -2959,15 +3122,17 @@  discard block
 block discarded – undo
2959 3122
 	// First thing's first - did we already do this?
2960 3123
 	if (!empty($modSettings['json_done']))
2961 3124
 	{
2962
-		if ($command_line)
2963
-			return DeleteUpgrade();
2964
-		else
2965
-			return true;
3125
+		if ($command_line) {
3126
+					return DeleteUpgrade();
3127
+		} else {
3128
+					return true;
3129
+		}
2966 3130
 	}
2967 3131
 
2968 3132
 	// Done it already - js wise?
2969
-	if (!empty($_POST['json_done']))
2970
-		return true;
3133
+	if (!empty($_POST['json_done'])) {
3134
+			return true;
3135
+	}
2971 3136
 
2972 3137
 	// List of tables affected by this function
2973 3138
 	// name => array('key', col1[,col2|true[,col3]])
@@ -2999,12 +3164,14 @@  discard block
 block discarded – undo
2999 3164
 	$upcontext['cur_table_name'] = isset($keys[$_GET['substep']]) ? $keys[$_GET['substep']] : $keys[0];
3000 3165
 	$upcontext['step_progress'] = (int) (($upcontext['cur_table_num'] / $upcontext['table_count']) * 100);
3001 3166
 
3002
-	foreach ($keys as $id => $table)
3003
-		if ($id < $_GET['substep'])
3167
+	foreach ($keys as $id => $table) {
3168
+			if ($id < $_GET['substep'])
3004 3169
 			$upcontext['previous_tables'][] = $table;
3170
+	}
3005 3171
 
3006
-	if ($command_line)
3007
-		echo 'Converting data from serialize() to json_encode().';
3172
+	if ($command_line) {
3173
+			echo 'Converting data from serialize() to json_encode().';
3174
+	}
3008 3175
 
3009 3176
 	if (!$support_js || isset($_GET['xml']))
3010 3177
 	{
@@ -3044,8 +3211,9 @@  discard block
 block discarded – undo
3044 3211
 
3045 3212
 				// Loop through and fix these...
3046 3213
 				$new_settings = array();
3047
-				if ($command_line)
3048
-					echo "\n" . 'Fixing some settings...';
3214
+				if ($command_line) {
3215
+									echo "\n" . 'Fixing some settings...';
3216
+				}
3049 3217
 
3050 3218
 				foreach ($serialized_settings as $var)
3051 3219
 				{
@@ -3053,22 +3221,24 @@  discard block
 block discarded – undo
3053 3221
 					{
3054 3222
 						// Attempt to unserialize the setting
3055 3223
 						$temp = @safe_unserialize($modSettings[$var]);
3056
-						if (!$temp && $command_line)
3057
-							echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3058
-						elseif ($temp !== false)
3059
-							$new_settings[$var] = json_encode($temp);
3224
+						if (!$temp && $command_line) {
3225
+													echo "\n - Failed to unserialize the '" . $var . "' setting. Skipping.";
3226
+						} elseif ($temp !== false) {
3227
+													$new_settings[$var] = json_encode($temp);
3228
+						}
3060 3229
 					}
3061 3230
 				}
3062 3231
 
3063 3232
 				// Update everything at once
3064
-				if (!function_exists('cache_put_data'))
3065
-					require_once($sourcedir . '/Load.php');
3233
+				if (!function_exists('cache_put_data')) {
3234
+									require_once($sourcedir . '/Load.php');
3235
+				}
3066 3236
 				updateSettings($new_settings, true);
3067 3237
 
3068
-				if ($command_line)
3069
-					echo ' done.';
3070
-			}
3071
-			elseif ($table == 'themes')
3238
+				if ($command_line) {
3239
+									echo ' done.';
3240
+				}
3241
+			} elseif ($table == 'themes')
3072 3242
 			{
3073 3243
 				// Finally, fix the admin prefs. Unfortunately this is stored per theme, but hopefully they only have one theme installed at this point...
3074 3244
 				$query = $smcFunc['db_query']('', '
@@ -3087,10 +3257,11 @@  discard block
 block discarded – undo
3087 3257
 
3088 3258
 						if ($command_line)
3089 3259
 						{
3090
-							if ($temp === false)
3091
-								echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3092
-							else
3093
-								echo "\n" . 'Fixing admin preferences...';
3260
+							if ($temp === false) {
3261
+															echo "\n" . 'Unserialize of admin_preferences for user ' . $row['id_member'] . ' failed. Skipping.';
3262
+							} else {
3263
+															echo "\n" . 'Fixing admin preferences...';
3264
+							}
3094 3265
 						}
3095 3266
 
3096 3267
 						if ($temp !== false)
@@ -3112,15 +3283,15 @@  discard block
 block discarded – undo
3112 3283
 								)
3113 3284
 							);
3114 3285
 
3115
-							if ($command_line)
3116
-								echo ' done.';
3286
+							if ($command_line) {
3287
+															echo ' done.';
3288
+							}
3117 3289
 						}
3118 3290
 					}
3119 3291
 
3120 3292
 					$smcFunc['db_free_result']($query);
3121 3293
 				}
3122
-			}
3123
-			else
3294
+			} else
3124 3295
 			{
3125 3296
 				// First item is always the key...
3126 3297
 				$key = $info[0];
@@ -3131,8 +3302,7 @@  discard block
 block discarded – undo
3131 3302
 				{
3132 3303
 					$col_select = $info[1];
3133 3304
 					$where = ' WHERE ' . $info[1] . ' != {empty}';
3134
-				}
3135
-				else
3305
+				} else
3136 3306
 				{
3137 3307
 					$col_select = implode(', ', $info);
3138 3308
 				}
@@ -3165,8 +3335,7 @@  discard block
 block discarded – undo
3165 3335
 								if ($temp === false && $command_line)
3166 3336
 								{
3167 3337
 									echo "\nFailed to unserialize " . $row[$col] . "... Skipping\n";
3168
-								}
3169
-								else
3338
+								} else
3170 3339
 								{
3171 3340
 									$row[$col] = json_encode($temp);
3172 3341
 
@@ -3191,16 +3360,18 @@  discard block
 block discarded – undo
3191 3360
 						}
3192 3361
 					}
3193 3362
 
3194
-					if ($command_line)
3195
-						echo ' done.';
3363
+					if ($command_line) {
3364
+											echo ' done.';
3365
+					}
3196 3366
 
3197 3367
 					// Free up some memory...
3198 3368
 					$smcFunc['db_free_result']($query);
3199 3369
 				}
3200 3370
 			}
3201 3371
 			// If this is XML to keep it nice for the user do one table at a time anyway!
3202
-			if (isset($_GET['xml']))
3203
-				return upgradeExit();
3372
+			if (isset($_GET['xml'])) {
3373
+							return upgradeExit();
3374
+			}
3204 3375
 		}
3205 3376
 
3206 3377
 		if ($command_line)
@@ -3215,8 +3386,9 @@  discard block
 block discarded – undo
3215 3386
 
3216 3387
 		$_GET['substep'] = 0;
3217 3388
 		// Make sure we move on!
3218
-		if ($command_line)
3219
-			return DeleteUpgrade();
3389
+		if ($command_line) {
3390
+					return DeleteUpgrade();
3391
+		}
3220 3392
 
3221 3393
 		return true;
3222 3394
 	}
@@ -3236,14 +3408,16 @@  discard block
 block discarded – undo
3236 3408
 	global $upcontext, $txt, $settings;
3237 3409
 
3238 3410
 	// Don't call me twice!
3239
-	if (!empty($upcontext['chmod_called']))
3240
-		return;
3411
+	if (!empty($upcontext['chmod_called'])) {
3412
+			return;
3413
+	}
3241 3414
 
3242 3415
 	$upcontext['chmod_called'] = true;
3243 3416
 
3244 3417
 	// Nothing?
3245
-	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error']))
3246
-		return;
3418
+	if (empty($upcontext['chmod']['files']) && empty($upcontext['chmod']['ftp_error'])) {
3419
+			return;
3420
+	}
3247 3421
 
3248 3422
 	// Was it a problem with Windows?
3249 3423
 	if (!empty($upcontext['chmod']['ftp_error']) && $upcontext['chmod']['ftp_error'] == 'total_mess')
@@ -3275,11 +3449,12 @@  discard block
 block discarded – undo
3275 3449
 					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\');
3276 3450
 					content.write(\'<p>', implode('<br>\n\t\t\t', $upcontext['chmod']['files']), '</p>\n\t\t\t\');';
3277 3451
 
3278
-	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux')
3279
-		echo '
3452
+	if (isset($upcontext['systemos']) && $upcontext['systemos'] == 'linux') {
3453
+			echo '
3280 3454
 					content.write(\'<hr>\n\t\t\t\');
3281 3455
 					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\');
3282 3456
 					content.write(\'<tt># chmod a+w ', implode(' ', $upcontext['chmod']['files']), '</tt>\n\t\t\t\');';
3457
+	}
3283 3458
 
3284 3459
 	echo '
3285 3460
 					content.write(\'<a href="javascript:self.close();">close</a>\n\t\t</div>\n\t</body>\n</html>\');
@@ -3287,17 +3462,19 @@  discard block
 block discarded – undo
3287 3462
 				}
3288 3463
 			</script>';
3289 3464
 
3290
-	if (!empty($upcontext['chmod']['ftp_error']))
3291
-		echo '
3465
+	if (!empty($upcontext['chmod']['ftp_error'])) {
3466
+			echo '
3292 3467
 			<div class="error_message red">
3293 3468
 				The following error was encountered when trying to connect:<br><br>
3294 3469
 				<code>', $upcontext['chmod']['ftp_error'], '</code>
3295 3470
 			</div>
3296 3471
 			<br>';
3472
+	}
3297 3473
 
3298
-	if (empty($upcontext['chmod_in_form']))
3299
-		echo '
3474
+	if (empty($upcontext['chmod_in_form'])) {
3475
+			echo '
3300 3476
 	<form action="', $upcontext['form_url'], '" method="post">';
3477
+	}
3301 3478
 
3302 3479
 	echo '
3303 3480
 		<table width="520" border="0" align="center" style="margin-bottom: 1ex;">
@@ -3332,10 +3509,11 @@  discard block
 block discarded – undo
3332 3509
 		<div class="righttext" style="margin: 1ex;"><input type="submit" value="', $txt['ftp_connect'], '" class="button"></div>
3333 3510
 	</div>';
3334 3511
 
3335
-	if (empty($upcontext['chmod_in_form']))
3336
-		echo '
3512
+	if (empty($upcontext['chmod_in_form'])) {
3513
+			echo '
3337 3514
 	</form>';
3338
-}
3515
+	}
3516
+	}
3339 3517
 
3340 3518
 function template_upgrade_above()
3341 3519
 {
@@ -3395,9 +3573,10 @@  discard block
 block discarded – undo
3395 3573
 				<h2>', $txt['upgrade_progress'], '</h2>
3396 3574
 				<ul>';
3397 3575
 
3398
-	foreach ($upcontext['steps'] as $num => $step)
3399
-		echo '
3576
+	foreach ($upcontext['steps'] as $num => $step) {
3577
+			echo '
3400 3578
 						<li class="', $num < $upcontext['current_step'] ? 'stepdone' : ($num == $upcontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>';
3579
+	}
3401 3580
 
3402 3581
 	echo '
3403 3582
 					</ul>
@@ -3410,8 +3589,8 @@  discard block
 block discarded – undo
3410 3589
 				</div>
3411 3590
 			</div>';
3412 3591
 
3413
-	if (isset($upcontext['step_progress']))
3414
-		echo '
3592
+	if (isset($upcontext['step_progress'])) {
3593
+			echo '
3415 3594
 				<br>
3416 3595
 				<br>
3417 3596
 				<div id="progress_bar_step">
@@ -3420,6 +3599,7 @@  discard block
 block discarded – undo
3420 3599
 						<span>', $txt['upgrade_step_progress'], '</span>
3421 3600
 					</div>
3422 3601
 				</div>';
3602
+	}
3423 3603
 
3424 3604
 	echo '
3425 3605
 				<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>
@@ -3450,32 +3630,36 @@  discard block
 block discarded – undo
3450 3630
 {
3451 3631
 	global $upcontext, $txt;
3452 3632
 
3453
-	if (!empty($upcontext['pause']))
3454
-		echo '
3633
+	if (!empty($upcontext['pause'])) {
3634
+			echo '
3455 3635
 								<em>', $txt['upgrade_incomplete'], '.</em><br>
3456 3636
 
3457 3637
 								<h2 style="margin-top: 2ex;">', $txt['upgrade_not_quite_done'], '</h2>
3458 3638
 								<h3>
3459 3639
 									', $txt['upgrade_paused_overload'], '
3460 3640
 								</h3>';
3641
+	}
3461 3642
 
3462
-	if (!empty($upcontext['custom_warning']))
3463
-		echo '
3643
+	if (!empty($upcontext['custom_warning'])) {
3644
+			echo '
3464 3645
 								<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3465 3646
 									<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3466 3647
 									<strong style="text-decoration: underline;">', $txt['upgrade_note'], '</strong><br>
3467 3648
 									<div style="padding-left: 6ex;">', $upcontext['custom_warning'], '</div>
3468 3649
 								</div>';
3650
+	}
3469 3651
 
3470 3652
 	echo '
3471 3653
 								<div class="righttext" style="margin: 1ex;">';
3472 3654
 
3473
-	if (!empty($upcontext['continue']))
3474
-		echo '
3655
+	if (!empty($upcontext['continue'])) {
3656
+			echo '
3475 3657
 									<input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '"', $upcontext['continue'] == 2 ? ' disabled' : '', ' class="button">';
3476
-	if (!empty($upcontext['skip']))
3477
-		echo '
3658
+	}
3659
+	if (!empty($upcontext['skip'])) {
3660
+			echo '
3478 3661
 									<input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="dontSubmit = true; document.getElementById(\'contbutt\').disabled = \'disabled\'; return true;" class="button">';
3662
+	}
3479 3663
 
3480 3664
 	echo '
3481 3665
 								</div>
@@ -3525,11 +3709,12 @@  discard block
 block discarded – undo
3525 3709
 	echo '<', '?xml version="1.0" encoding="UTF-8"?', '>
3526 3710
 	<smf>';
3527 3711
 
3528
-	if (!empty($upcontext['get_data']))
3529
-		foreach ($upcontext['get_data'] as $k => $v)
3712
+	if (!empty($upcontext['get_data'])) {
3713
+			foreach ($upcontext['get_data'] as $k => $v)
3530 3714
 			echo '
3531 3715
 		<get key="', $k, '">', $v, '</get>';
3532
-}
3716
+	}
3717
+	}
3533 3718
 
3534 3719
 function template_xml_below()
3535 3720
 {
@@ -3570,8 +3755,8 @@  discard block
 block discarded – undo
3570 3755
 	template_chmod();
3571 3756
 
3572 3757
 	// For large, pre 1.1 RC2 forums give them a warning about the possible impact of this upgrade!
3573
-	if ($upcontext['is_large_forum'])
3574
-		echo '
3758
+	if ($upcontext['is_large_forum']) {
3759
+			echo '
3575 3760
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3576 3761
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3577 3762
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3579,10 +3764,11 @@  discard block
 block discarded – undo
3579 3764
 				', $txt['upgrade_warning_lots_data'], '
3580 3765
 			</div>
3581 3766
 		</div>';
3767
+	}
3582 3768
 
3583 3769
 	// A warning message?
3584
-	if (!empty($upcontext['warning']))
3585
-		echo '
3770
+	if (!empty($upcontext['warning'])) {
3771
+			echo '
3586 3772
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
3587 3773
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3588 3774
 			<strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br>
@@ -3590,6 +3776,7 @@  discard block
 block discarded – undo
3590 3776
 				', $upcontext['warning'], '
3591 3777
 			</div>
3592 3778
 		</div>';
3779
+	}
3593 3780
 
3594 3781
 	// Paths are incorrect?
3595 3782
 	echo '
@@ -3605,20 +3792,22 @@  discard block
 block discarded – undo
3605 3792
 	if (!empty($upcontext['user']['id']) && (time() - $upcontext['started'] < 72600 || time() - $upcontext['updated'] < 3600))
3606 3793
 	{
3607 3794
 		$ago = time() - $upcontext['started'];
3608
-		if ($ago < 60)
3609
-			$ago = $ago . ' seconds';
3610
-		elseif ($ago < 3600)
3611
-			$ago = (int) ($ago / 60) . ' minutes';
3612
-		else
3613
-			$ago = (int) ($ago / 3600) . ' hours';
3795
+		if ($ago < 60) {
3796
+					$ago = $ago . ' seconds';
3797
+		} elseif ($ago < 3600) {
3798
+					$ago = (int) ($ago / 60) . ' minutes';
3799
+		} else {
3800
+					$ago = (int) ($ago / 3600) . ' hours';
3801
+		}
3614 3802
 
3615 3803
 		$active = time() - $upcontext['updated'];
3616
-		if ($active < 60)
3617
-			$updated = $active . ' seconds';
3618
-		elseif ($active < 3600)
3619
-			$updated = (int) ($active / 60) . ' minutes';
3620
-		else
3621
-			$updated = (int) ($active / 3600) . ' hours';
3804
+		if ($active < 60) {
3805
+					$updated = $active . ' seconds';
3806
+		} elseif ($active < 3600) {
3807
+					$updated = (int) ($active / 60) . ' minutes';
3808
+		} else {
3809
+					$updated = (int) ($active / 3600) . ' hours';
3810
+		}
3622 3811
 
3623 3812
 		echo '
3624 3813
 		<div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;">
@@ -3627,16 +3816,18 @@  discard block
 block discarded – undo
3627 3816
 			<div style="padding-left: 6ex;">
3628 3817
 				&quot;', $upcontext['user']['name'], '&quot; has been running the upgrade script for the last ', $ago, ' - and was last active ', $updated, ' ago.';
3629 3818
 
3630
-		if ($active < 600)
3631
-			echo '
3819
+		if ($active < 600) {
3820
+					echo '
3632 3821
 				We recommend that you do not run this script unless you are sure that ', $upcontext['user']['name'], ' has completed their upgrade.';
3822
+		}
3633 3823
 
3634
-		if ($active > $upcontext['inactive_timeout'])
3635
-			echo '
3824
+		if ($active > $upcontext['inactive_timeout']) {
3825
+					echo '
3636 3826
 				<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.';
3637
-		else
3638
-			echo '
3827
+		} else {
3828
+					echo '
3639 3829
 				<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!');
3830
+		}
3640 3831
 
3641 3832
 		echo '
3642 3833
 			</div>
@@ -3652,9 +3843,10 @@  discard block
 block discarded – undo
3652 3843
 					<td>
3653 3844
 						<input type="text" name="user" value="', !empty($upcontext['username']) ? $upcontext['username'] : '', '"', $disable_security ? ' disabled' : '', '>';
3654 3845
 
3655
-	if (!empty($upcontext['username_incorrect']))
3656
-		echo '
3846
+	if (!empty($upcontext['username_incorrect'])) {
3847
+			echo '
3657 3848
 						<div class="smalltext" style="color: red;">Username Incorrect</div>';
3849
+	}
3658 3850
 
3659 3851
 	echo '
3660 3852
 					</td>
@@ -3665,9 +3857,10 @@  discard block
 block discarded – undo
3665 3857
 						<input type="password" name="passwrd" value=""', $disable_security ? ' disabled' : '', '>
3666 3858
 						<input type="hidden" name="hash_passwrd" value="">';
3667 3859
 
3668
-	if (!empty($upcontext['password_failed']))
3669
-		echo '
3860
+	if (!empty($upcontext['password_failed'])) {
3861
+			echo '
3670 3862
 						<div class="smalltext" style="color: red;">Password Incorrect</div>';
3863
+	}
3671 3864
 
3672 3865
 	echo '
3673 3866
 					</td>
@@ -3738,8 +3931,8 @@  discard block
 block discarded – undo
3738 3931
 			<form action="', $upcontext['form_url'], '" method="post" name="upform" id="upform">';
3739 3932
 
3740 3933
 	// Warning message?
3741
-	if (!empty($upcontext['upgrade_options_warning']))
3742
-		echo '
3934
+	if (!empty($upcontext['upgrade_options_warning'])) {
3935
+			echo '
3743 3936
 		<div style="margin: 1ex; padding: 1ex; border: 1px dashed #cc3344; color: black; background-color: #ffe4e9;">
3744 3937
 			<div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div>
3745 3938
 			<strong style="text-decoration: underline;">Warning!</strong><br>
@@ -3747,6 +3940,7 @@  discard block
 block discarded – undo
3747 3940
 				', $upcontext['upgrade_options_warning'], '
3748 3941
 			</div>
3749 3942
 		</div>';
3943
+	}
3750 3944
 
3751 3945
 	echo '
3752 3946
 				<table>
@@ -3789,8 +3983,8 @@  discard block
 block discarded – undo
3789 3983
 						</td>
3790 3984
 					</tr>';
3791 3985
 
3792
-	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad']))
3793
-		echo '
3986
+	if (!empty($upcontext['karma_installed']['good']) || !empty($upcontext['karma_installed']['bad'])) {
3987
+			echo '
3794 3988
 					<tr valign="top">
3795 3989
 						<td width="2%">
3796 3990
 							<input type="checkbox" name="delete_karma" id="delete_karma" value="1">
@@ -3799,6 +3993,7 @@  discard block
 block discarded – undo
3799 3993
 							<label for="delete_karma">Delete all karma settings and info from the DB</label>
3800 3994
 						</td>
3801 3995
 					</tr>';
3996
+	}
3802 3997
 
3803 3998
 	echo '
3804 3999
 					<tr valign="top">
@@ -3836,10 +4031,11 @@  discard block
 block discarded – undo
3836 4031
 			</div>';
3837 4032
 
3838 4033
 	// Dont any tables so far?
3839
-	if (!empty($upcontext['previous_tables']))
3840
-		foreach ($upcontext['previous_tables'] as $table)
4034
+	if (!empty($upcontext['previous_tables'])) {
4035
+			foreach ($upcontext['previous_tables'] as $table)
3841 4036
 			echo '
3842 4037
 			<br>Completed Table: &quot;', $table, '&quot;.';
4038
+	}
3843 4039
 
3844 4040
 	echo '
3845 4041
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
@@ -3876,12 +4072,13 @@  discard block
 block discarded – undo
3876 4072
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
3877 4073
 
3878 4074
 		// If debug flood the screen.
3879
-		if ($is_debug)
3880
-			echo '
4075
+		if ($is_debug) {
4076
+					echo '
3881 4077
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
3882 4078
 
3883 4079
 				if (document.getElementById(\'debug_section\').scrollHeight)
3884 4080
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4081
+		}
3885 4082
 
3886 4083
 		echo '
3887 4084
 				// Get the next update...
@@ -3914,8 +4111,9 @@  discard block
 block discarded – undo
3914 4111
 {
3915 4112
 	global $upcontext, $support_js, $is_debug, $timeLimitThreshold;
3916 4113
 
3917
-	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug']))
3918
-		$is_debug = true;
4114
+	if (empty($is_debug) && !empty($upcontext['upgrade_status']['debug'])) {
4115
+			$is_debug = true;
4116
+	}
3919 4117
 
3920 4118
 	echo '
3921 4119
 		<h3>Executing database changes</h3>
@@ -3930,8 +4128,9 @@  discard block
 block discarded – undo
3930 4128
 	{
3931 4129
 		foreach ($upcontext['actioned_items'] as $num => $item)
3932 4130
 		{
3933
-			if ($num != 0)
3934
-				echo ' Successful!';
4131
+			if ($num != 0) {
4132
+							echo ' Successful!';
4133
+			}
3935 4134
 			echo '<br>' . $item;
3936 4135
 		}
3937 4136
 		if (!empty($upcontext['changes_complete']))
@@ -3944,28 +4143,32 @@  discard block
 block discarded – undo
3944 4143
 				$seconds = intval($active % 60);
3945 4144
 
3946 4145
 				$totalTime = '';
3947
-				if ($hours > 0)
3948
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3949
-				if ($minutes > 0)
3950
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3951
-				if ($seconds > 0)
3952
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4146
+				if ($hours > 0) {
4147
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4148
+				}
4149
+				if ($minutes > 0) {
4150
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4151
+				}
4152
+				if ($seconds > 0) {
4153
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4154
+				}
3953 4155
 			}
3954 4156
 
3955
-			if ($is_debug && !empty($totalTime))
3956
-				echo ' Successful! Completed in ', $totalTime, '<br><br>';
3957
-			else
3958
-				echo ' Successful!<br><br>';
4157
+			if ($is_debug && !empty($totalTime)) {
4158
+							echo ' Successful! Completed in ', $totalTime, '<br><br>';
4159
+			} else {
4160
+							echo ' Successful!<br><br>';
4161
+			}
3959 4162
 
3960 4163
 			echo '<span id="commess" style="font-weight: bold;">1 Database Updates Complete! Click Continue to Proceed.</span><br>';
3961 4164
 		}
3962
-	}
3963
-	else
4165
+	} else
3964 4166
 	{
3965 4167
 		// Tell them how many files we have in total.
3966
-		if ($upcontext['file_count'] > 1)
3967
-			echo '
4168
+		if ($upcontext['file_count'] > 1) {
4169
+					echo '
3968 4170
 		<strong id="info1">Executing upgrade script <span id="file_done">', $upcontext['cur_file_num'], '</span> of ', $upcontext['file_count'], '.</strong>';
4171
+		}
3969 4172
 
3970 4173
 		echo '
3971 4174
 		<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>
@@ -3981,19 +4184,23 @@  discard block
 block discarded – undo
3981 4184
 				$seconds = intval($active % 60);
3982 4185
 
3983 4186
 				$totalTime = '';
3984
-				if ($hours > 0)
3985
-					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
3986
-				if ($minutes > 0)
3987
-					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
3988
-				if ($seconds > 0)
3989
-					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4187
+				if ($hours > 0) {
4188
+									$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4189
+				}
4190
+				if ($minutes > 0) {
4191
+									$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4192
+				}
4193
+				if ($seconds > 0) {
4194
+									$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4195
+				}
3990 4196
 			}
3991 4197
 
3992 4198
 			echo '
3993 4199
 			<br><span id="upgradeCompleted">';
3994 4200
 
3995
-			if (!empty($totalTime))
3996
-				echo 'Completed in ', $totalTime, '<br>';
4201
+			if (!empty($totalTime)) {
4202
+							echo 'Completed in ', $totalTime, '<br>';
4203
+			}
3997 4204
 
3998 4205
 			echo '</span>
3999 4206
 			<div id="debug_section" style="height: 59px; overflow: auto;">
@@ -4030,9 +4237,10 @@  discard block
 block discarded – undo
4030 4237
 			var getData = "";
4031 4238
 			var debugItems = ', $upcontext['debug_items'], ';';
4032 4239
 
4033
-		if ($is_debug)
4034
-			echo '
4240
+		if ($is_debug) {
4241
+					echo '
4035 4242
 			var upgradeStartTime = ' . $upcontext['started'] . ';';
4243
+		}
4036 4244
 
4037 4245
 		echo '
4038 4246
 			function getNextItem()
@@ -4072,9 +4280,10 @@  discard block
 block discarded – undo
4072 4280
 						document.getElementById("error_block").style.display = "";
4073 4281
 						setInnerHTML(document.getElementById("error_message"), "Error retrieving information on step: " + (sDebugName == "" ? sLastString : sDebugName));';
4074 4282
 
4075
-	if ($is_debug)
4076
-		echo '
4283
+	if ($is_debug) {
4284
+			echo '
4077 4285
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4286
+	}
4078 4287
 
4079 4288
 	echo '
4080 4289
 					}
@@ -4095,9 +4304,10 @@  discard block
 block discarded – undo
4095 4304
 						document.getElementById("error_block").style.display = "";
4096 4305
 						setInnerHTML(document.getElementById("error_message"), "Upgrade script appears to be going into a loop - step: " + sDebugName);';
4097 4306
 
4098
-	if ($is_debug)
4099
-		echo '
4307
+	if ($is_debug) {
4308
+			echo '
4100 4309
 						setOuterHTML(document.getElementById(\'debuginfo\'), \'<span style="color: red;">failed<\' + \'/span><span id="debuginfo"><\' + \'/span>\');';
4310
+	}
4101 4311
 
4102 4312
 	echo '
4103 4313
 					}
@@ -4156,8 +4366,8 @@  discard block
 block discarded – undo
4156 4366
 				if (bIsComplete && iDebugNum == -1 && curFile >= ', $upcontext['file_count'], ')
4157 4367
 				{';
4158 4368
 
4159
-		if ($is_debug)
4160
-			echo '
4369
+		if ($is_debug) {
4370
+					echo '
4161 4371
 					document.getElementById(\'debug_section\').style.display = "none";
4162 4372
 
4163 4373
 					var upgradeFinishedTime = parseInt(oXMLDoc.getElementsByTagName("curtime")[0].childNodes[0].nodeValue);
@@ -4175,6 +4385,7 @@  discard block
 block discarded – undo
4175 4385
 						totalTime = totalTime + diffSeconds + " second" + (diffSeconds > 1 ? "s" : "");
4176 4386
 
4177 4387
 					setInnerHTML(document.getElementById("upgradeCompleted"), "Completed in " + totalTime);';
4388
+		}
4178 4389
 
4179 4390
 		echo '
4180 4391
 
@@ -4182,9 +4393,10 @@  discard block
 block discarded – undo
4182 4393
 					document.getElementById(\'contbutt\').disabled = 0;
4183 4394
 					document.getElementById(\'database_done\').value = 1;';
4184 4395
 
4185
-		if ($upcontext['file_count'] > 1)
4186
-			echo '
4396
+		if ($upcontext['file_count'] > 1) {
4397
+					echo '
4187 4398
 					document.getElementById(\'info1\').style.display = "none";';
4399
+		}
4188 4400
 
4189 4401
 		echo '
4190 4402
 					document.getElementById(\'info2\').style.display = "none";
@@ -4197,9 +4409,10 @@  discard block
 block discarded – undo
4197 4409
 					lastItem = 0;
4198 4410
 					prevFile = curFile;';
4199 4411
 
4200
-		if ($is_debug)
4201
-			echo '
4412
+		if ($is_debug) {
4413
+					echo '
4202 4414
 					setOuterHTML(document.getElementById(\'debuginfo\'), \'Moving to next script file...done<br><span id="debuginfo"><\' + \'/span>\');';
4415
+		}
4203 4416
 
4204 4417
 		echo '
4205 4418
 					getNextItem();
@@ -4207,8 +4420,8 @@  discard block
 block discarded – undo
4207 4420
 				}';
4208 4421
 
4209 4422
 		// If debug scroll the screen.
4210
-		if ($is_debug)
4211
-			echo '
4423
+		if ($is_debug) {
4424
+					echo '
4212 4425
 				if (iLastSubStepProgress == -1)
4213 4426
 				{
4214 4427
 					// Give it consistent dots.
@@ -4227,6 +4440,7 @@  discard block
 block discarded – undo
4227 4440
 
4228 4441
 				if (document.getElementById(\'debug_section\').scrollHeight)
4229 4442
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4443
+		}
4230 4444
 
4231 4445
 		echo '
4232 4446
 				// Update the page.
@@ -4287,9 +4501,10 @@  discard block
 block discarded – undo
4287 4501
 			}';
4288 4502
 
4289 4503
 		// Start things off assuming we've not errored.
4290
-		if (empty($upcontext['error_message']))
4291
-			echo '
4504
+		if (empty($upcontext['error_message'])) {
4505
+					echo '
4292 4506
 			getNextItem();';
4507
+		}
4293 4508
 
4294 4509
 		echo '
4295 4510
 		//# sourceURL=dynamicScript-dbch.js
@@ -4307,18 +4522,21 @@  discard block
 block discarded – undo
4307 4522
 	<item num="', $upcontext['current_item_num'], '">', $upcontext['current_item_name'], '</item>
4308 4523
 	<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>';
4309 4524
 
4310
-	if (!empty($upcontext['error_message']))
4311
-		echo '
4525
+	if (!empty($upcontext['error_message'])) {
4526
+			echo '
4312 4527
 	<error>', $upcontext['error_message'], '</error>';
4528
+	}
4313 4529
 
4314
-	if (!empty($upcontext['error_string']))
4315
-		echo '
4530
+	if (!empty($upcontext['error_string'])) {
4531
+			echo '
4316 4532
 	<sql>', $upcontext['error_string'], '</sql>';
4533
+	}
4317 4534
 
4318
-	if ($is_debug)
4319
-		echo '
4535
+	if ($is_debug) {
4536
+			echo '
4320 4537
 	<curtime>', time(), '</curtime>';
4321
-}
4538
+	}
4539
+	}
4322 4540
 
4323 4541
 // Template for the UTF-8 conversion step. Basically a copy of the backup stuff with slight modifications....
4324 4542
 function template_convert_utf8()
@@ -4337,18 +4555,20 @@  discard block
 block discarded – undo
4337 4555
 			</div>';
4338 4556
 
4339 4557
 	// Done any tables so far?
4340
-	if (!empty($upcontext['previous_tables']))
4341
-		foreach ($upcontext['previous_tables'] as $table)
4558
+	if (!empty($upcontext['previous_tables'])) {
4559
+			foreach ($upcontext['previous_tables'] as $table)
4342 4560
 			echo '
4343 4561
 			<br>Completed Table: &quot;', $table, '&quot;.';
4562
+	}
4344 4563
 
4345 4564
 	echo '
4346 4565
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>';
4347 4566
 
4348 4567
 	// If we dropped their index, let's let them know
4349
-	if ($upcontext['dropping_index'])
4350
-		echo '
4568
+	if ($upcontext['dropping_index']) {
4569
+			echo '
4351 4570
 				<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>';
4571
+	}
4352 4572
 
4353 4573
 	// Completion notification
4354 4574
 	echo '
@@ -4385,12 +4605,13 @@  discard block
 block discarded – undo
4385 4605
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4386 4606
 
4387 4607
 		// If debug flood the screen.
4388
-		if ($is_debug)
4389
-			echo '
4608
+		if ($is_debug) {
4609
+					echo '
4390 4610
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4391 4611
 
4392 4612
 				if (document.getElementById(\'debug_section\').scrollHeight)
4393 4613
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4614
+		}
4394 4615
 
4395 4616
 		echo '
4396 4617
 				// Get the next update...
@@ -4438,19 +4659,21 @@  discard block
 block discarded – undo
4438 4659
 			</div>';
4439 4660
 
4440 4661
 	// Dont any tables so far?
4441
-	if (!empty($upcontext['previous_tables']))
4442
-		foreach ($upcontext['previous_tables'] as $table)
4662
+	if (!empty($upcontext['previous_tables'])) {
4663
+			foreach ($upcontext['previous_tables'] as $table)
4443 4664
 			echo '
4444 4665
 			<br>Completed Table: &quot;', $table, '&quot;.';
4666
+	}
4445 4667
 
4446 4668
 	echo '
4447 4669
 			<h3 id="current_tab_div">Current Table: &quot;<span id="current_table">', $upcontext['cur_table_name'], '</span>&quot;</h3>
4448 4670
 			<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>';
4449 4671
 
4450 4672
 	// Try to make sure substep was reset.
4451
-	if ($upcontext['cur_table_num'] == $upcontext['table_count'])
4452
-		echo '
4673
+	if ($upcontext['cur_table_num'] == $upcontext['table_count']) {
4674
+			echo '
4453 4675
 			<input type="hidden" name="substep" id="substep" value="0">';
4676
+	}
4454 4677
 
4455 4678
 	// Continue please!
4456 4679
 	$upcontext['continue'] = $support_js ? 2 : 1;
@@ -4483,12 +4706,13 @@  discard block
 block discarded – undo
4483 4706
 				updateStepProgress(iTableNum, ', $upcontext['table_count'], ', ', $upcontext['step_weight'] * ((100 - $upcontext['step_progress']) / 100), ');';
4484 4707
 
4485 4708
 		// If debug flood the screen.
4486
-		if ($is_debug)
4487
-			echo '
4709
+		if ($is_debug) {
4710
+					echo '
4488 4711
 				setOuterHTML(document.getElementById(\'debuginfo\'), \'<br>Completed Table: &quot;\' + sCompletedTableName + \'&quot;.<span id="debuginfo"><\' + \'/span>\');
4489 4712
 
4490 4713
 				if (document.getElementById(\'debug_section\').scrollHeight)
4491 4714
 					document.getElementById(\'debug_section\').scrollTop = document.getElementById(\'debug_section\').scrollHeight';
4715
+		}
4492 4716
 
4493 4717
 		echo '
4494 4718
 				// Get the next update...
@@ -4524,8 +4748,8 @@  discard block
 block discarded – undo
4524 4748
 	<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>
4525 4749
 	<form action="', $boardurl, '/index.php">';
4526 4750
 
4527
-	if (!empty($upcontext['can_delete_script']))
4528
-		echo '
4751
+	if (!empty($upcontext['can_delete_script'])) {
4752
+			echo '
4529 4753
 			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);"> Delete upgrade.php and its data files now</label> <em>(doesn\'t work on all servers).</em>
4530 4754
 			<script>
4531 4755
 				function doTheDelete(theCheck)
@@ -4537,6 +4761,7 @@  discard block
 block discarded – undo
4537 4761
 				}
4538 4762
 			</script>
4539 4763
 			<img src="', $settings['default_theme_url'], '/images/blank.png" alt="" id="delete_upgrader"><br>';
4764
+	}
4540 4765
 
4541 4766
 	$active = time() - $upcontext['started'];
4542 4767
 	$hours = floor($active / 3600);
@@ -4546,16 +4771,20 @@  discard block
 block discarded – undo
4546 4771
 	if ($is_debug)
4547 4772
 	{
4548 4773
 		$totalTime = '';
4549
-		if ($hours > 0)
4550
-			$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4551
-		if ($minutes > 0)
4552
-			$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4553
-		if ($seconds > 0)
4554
-			$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4774
+		if ($hours > 0) {
4775
+					$totalTime .= $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ';
4776
+		}
4777
+		if ($minutes > 0) {
4778
+					$totalTime .= $minutes . ' minute' . ($minutes > 1 ? 's' : '') . ' ';
4779
+		}
4780
+		if ($seconds > 0) {
4781
+					$totalTime .= $seconds . ' second' . ($seconds > 1 ? 's' : '') . ' ';
4782
+		}
4555 4783
 	}
4556 4784
 
4557
-	if ($is_debug && !empty($totalTime))
4558
-		echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4785
+	if ($is_debug && !empty($totalTime)) {
4786
+			echo '<br> Upgrade completed in ', $totalTime, '<br><br>';
4787
+	}
4559 4788
 
4560 4789
 	echo '<br>
4561 4790
 			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>
@@ -4582,8 +4811,9 @@  discard block
 block discarded – undo
4582 4811
 
4583 4812
 	$current_substep = $_GET['substep'];
4584 4813
 
4585
-	if (empty($_GET['a']))
4586
-		$_GET['a'] = 0;
4814
+	if (empty($_GET['a'])) {
4815
+			$_GET['a'] = 0;
4816
+	}
4587 4817
 	$step_progress['name'] = 'Converting ips';
4588 4818
 	$step_progress['current'] = $_GET['a'];
4589 4819
 
@@ -4626,16 +4856,19 @@  discard block
 block discarded – undo
4626 4856
 				'empty' => '',
4627 4857
 				'limit' => $limit,
4628 4858
 		));
4629
-		while ($row = $smcFunc['db_fetch_assoc']($request))
4630
-			$arIp[] = $row[$oldCol];
4859
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
4860
+					$arIp[] = $row[$oldCol];
4861
+		}
4631 4862
 		$smcFunc['db_free_result']($request);
4632 4863
 
4633 4864
 		// Special case, null ip could keep us in a loop.
4634
-		if (is_null($arIp[0]))
4635
-			unset($arIp[0]);
4865
+		if (is_null($arIp[0])) {
4866
+					unset($arIp[0]);
4867
+		}
4636 4868
 
4637
-		if (empty($arIp))
4638
-			$is_done = true;
4869
+		if (empty($arIp)) {
4870
+					$is_done = true;
4871
+		}
4639 4872
 
4640 4873
 		$updates = array();
4641 4874
 		$cases = array();
@@ -4644,16 +4877,18 @@  discard block
 block discarded – undo
4644 4877
 		{
4645 4878
 			$arIp[$i] = trim($arIp[$i]);
4646 4879
 
4647
-			if (empty($arIp[$i]))
4648
-				continue;
4880
+			if (empty($arIp[$i])) {
4881
+							continue;
4882
+			}
4649 4883
 
4650 4884
 			$updates['ip' . $i] = $arIp[$i];
4651 4885
 			$cases[$arIp[$i]] = 'WHEN ' . $oldCol . ' = {string:ip' . $i . '} THEN {inet:ip' . $i . '}';
4652 4886
 
4653 4887
 			if ($setSize > 0 && $i % $setSize === 0)
4654 4888
 			{
4655
-				if (count($updates) == 1)
4656
-					continue;
4889
+				if (count($updates) == 1) {
4890
+									continue;
4891
+				}
4657 4892
 
4658 4893
 				$updates['whereSet'] = array_values($updates);
4659 4894
 				$smcFunc['db_query']('', '
@@ -4687,8 +4922,7 @@  discard block
 block discarded – undo
4687 4922
 							'ip' => $ip
4688 4923
 					));
4689 4924
 				}
4690
-			}
4691
-			else
4925
+			} else
4692 4926
 			{
4693 4927
 				$updates['whereSet'] = array_values($updates);
4694 4928
 				$smcFunc['db_query']('', '
@@ -4702,9 +4936,9 @@  discard block
 block discarded – undo
4702 4936
 					$updates
4703 4937
 				);
4704 4938
 			}
4939
+		} else {
4940
+					$is_done = true;
4705 4941
 		}
4706
-		else
4707
-			$is_done = true;
4708 4942
 
4709 4943
 		$_GET['a'] += $limit;
4710 4944
 		$step_progress['current'] = $_GET['a'];
@@ -4730,10 +4964,11 @@  discard block
 block discarded – undo
4730 4964
 
4731 4965
  	$columns = $smcFunc['db_list_columns']($targetTable, true);
4732 4966
 
4733
-	if (isset($columns[$column]))
4734
-		return $columns[$column];
4735
-	else
4736
-		return null;
4737
-}
4967
+	if (isset($columns[$column])) {
4968
+			return $columns[$column];
4969
+	} else {
4970
+			return null;
4971
+	}
4972
+	}
4738 4973
 
4739 4974
 ?>
4740 4975
\ No newline at end of file
Please login to merge, or discard this patch.
Sources/Subs-Post.php 1 patch
Braces   +531 added lines, -395 removed lines patch added patch discarded remove patch
@@ -15,8 +15,9 @@  discard block
 block discarded – undo
15 15
  * @version 2.1 Beta 4
16 16
  */
17 17
 
18
-if (!defined('SMF'))
18
+if (!defined('SMF')) {
19 19
 	die('No direct access...');
20
+}
20 21
 
21 22
 /**
22 23
  * Takes a message and parses it, returning nothing.
@@ -31,8 +32,9 @@  discard block
 block discarded – undo
31 32
 	global $user_info, $modSettings, $context, $sourcedir;
32 33
 
33 34
 	// This line makes all languages *theoretically* work even with the wrong charset ;).
34
-	if (empty($context['utf8']))
35
-		$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
35
+	if (empty($context['utf8'])) {
36
+			$message = preg_replace('~&amp;#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $message);
37
+	}
36 38
 
37 39
 	// Clean up after nobbc ;).
38 40
 	$message = preg_replace_callback('~\[nobbc\](.+?)\[/nobbc\]~is', function($a)
@@ -47,17 +49,19 @@  discard block
 block discarded – undo
47 49
 	$message = preg_replace('~\.{100,}~', '...', $message);
48 50
 
49 51
 	// Trim off trailing quotes - these often happen by accident.
50
-	while (substr($message, -7) == '[quote]')
51
-		$message = substr($message, 0, -7);
52
-	while (substr($message, 0, 8) == '[/quote]')
53
-		$message = substr($message, 8);
52
+	while (substr($message, -7) == '[quote]') {
53
+			$message = substr($message, 0, -7);
54
+	}
55
+	while (substr($message, 0, 8) == '[/quote]') {
56
+			$message = substr($message, 8);
57
+	}
54 58
 
55 59
 	// Find all code blocks, work out whether we'd be parsing them, then ensure they are all closed.
56 60
 	$in_tag = false;
57 61
 	$had_tag = false;
58 62
 	$codeopen = 0;
59
-	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches))
60
-		foreach ($matches[0] as $index => $dummy)
63
+	if (preg_match_all('~(\[(/)*code(?:=[^\]]+)?\])~is', $message, $matches)) {
64
+			foreach ($matches[0] as $index => $dummy)
61 65
 		{
62 66
 			// Closing?
63 67
 			if (!empty($matches[2][$index]))
@@ -65,6 +69,7 @@  discard block
 block discarded – undo
65 69
 				// If it's closing and we're not in a tag we need to open it...
66 70
 				if (!$in_tag)
67 71
 					$codeopen = true;
72
+	}
68 73
 				// Either way we ain't in one any more.
69 74
 				$in_tag = false;
70 75
 			}
@@ -73,17 +78,20 @@  discard block
 block discarded – undo
73 78
 			{
74 79
 				$had_tag = true;
75 80
 				// If we're in a tag don't do nought!
76
-				if (!$in_tag)
77
-					$in_tag = true;
81
+				if (!$in_tag) {
82
+									$in_tag = true;
83
+				}
78 84
 			}
79 85
 		}
80 86
 
81 87
 	// If we have an open tag, close it.
82
-	if ($in_tag)
83
-		$message .= '[/code]';
88
+	if ($in_tag) {
89
+			$message .= '[/code]';
90
+	}
84 91
 	// Open any ones that need to be open, only if we've never had a tag.
85
-	if ($codeopen && !$had_tag)
86
-		$message = '[code]' . $message;
92
+	if ($codeopen && !$had_tag) {
93
+			$message = '[code]' . $message;
94
+	}
87 95
 
88 96
 	// Now that we've fixed all the code tags, let's fix the img and url tags...
89 97
 	$parts = preg_split('~(\[/code\]|\[code(?:=[^\]]+)?\])~i', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
@@ -109,23 +117,26 @@  discard block
 block discarded – undo
109 117
 	fixTags($message);
110 118
 
111 119
 	// Replace /me.+?\n with [me=name]dsf[/me]\n.
112
-	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false)
113
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
114
-	else
115
-		$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
120
+	if (strpos($user_info['name'], '[') !== false || strpos($user_info['name'], ']') !== false || strpos($user_info['name'], '\'') !== false || strpos($user_info['name'], '"') !== false) {
121
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=&quot;' . $user_info['name'] . '&quot;]$2[/me]', $message);
122
+	} else {
123
+			$message = preg_replace('~(\A|\n)/me(?: |&nbsp;)([^\n]*)(?:\z)?~i', '$1[me=' . $user_info['name'] . ']$2[/me]', $message);
124
+	}
116 125
 
117 126
 	if (!$previewing && strpos($message, '[html]') !== false)
118 127
 	{
119
-		if (allowedTo('admin_forum'))
120
-			$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
128
+		if (allowedTo('admin_forum')) {
129
+					$message = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) {
121 130
 				return '[html]' . strtr(un_htmlspecialchars($m[1]), array("\n" => '&#13;', '  ' => ' &#32;', '[' => '&#91;', ']' => '&#93;')) . '[/html]';
131
+		}
122 132
 			}, $message);
123 133
 
124 134
 		// We should edit them out, or else if an admin edits the message they will get shown...
125 135
 		else
126 136
 		{
127
-			while (strpos($message, '[html]') !== false)
128
-				$message = preg_replace('~\[[/]?html\]~i', '', $message);
137
+			while (strpos($message, '[html]') !== false) {
138
+							$message = preg_replace('~\[[/]?html\]~i', '', $message);
139
+			}
129 140
 		}
130 141
 	}
131 142
 
@@ -147,10 +158,12 @@  discard block
 block discarded – undo
147 158
 
148 159
 	$list_open = substr_count($message, '[list]') + substr_count($message, '[list ');
149 160
 	$list_close = substr_count($message, '[/list]');
150
-	if ($list_close - $list_open > 0)
151
-		$message = str_repeat('[list]', $list_close - $list_open) . $message;
152
-	if ($list_open - $list_close > 0)
153
-		$message = $message . str_repeat('[/list]', $list_open - $list_close);
161
+	if ($list_close - $list_open > 0) {
162
+			$message = str_repeat('[list]', $list_close - $list_open) . $message;
163
+	}
164
+	if ($list_open - $list_close > 0) {
165
+			$message = $message . str_repeat('[/list]', $list_open - $list_close);
166
+	}
154 167
 
155 168
 	$mistake_fixes = array(
156 169
 		// Find [table]s not followed by [tr].
@@ -199,8 +212,9 @@  discard block
 block discarded – undo
199 212
 	);
200 213
 
201 214
 	// Fix up some use of tables without [tr]s, etc. (it has to be done more than once to catch it all.)
202
-	for ($j = 0; $j < 3; $j++)
203
-		$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
215
+	for ($j = 0; $j < 3; $j++) {
216
+			$message = preg_replace(array_keys($mistake_fixes), $mistake_fixes, $message);
217
+	}
204 218
 
205 219
 	// Remove empty bbc from the sections outside the code tags
206 220
 	$allowedEmpty = array(
@@ -210,24 +224,28 @@  discard block
 block discarded – undo
210 224
 
211 225
 	require_once($sourcedir . '/Subs.php');
212 226
 
213
-	foreach (($codes = parse_bbc(false)) as $code)
214
-		if (!in_array($code['tag'], $allowedEmpty))
227
+	foreach (($codes = parse_bbc(false)) as $code) {
228
+			if (!in_array($code['tag'], $allowedEmpty))
215 229
 			$alltags[] = $code['tag'];
230
+	}
216 231
 
217 232
 	$alltags_regex = '\b' . implode("\b|\b", array_unique($alltags)) . '\b';
218 233
 
219
-	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message))
220
-		$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
234
+	while (preg_match('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', $message)) {
235
+			$message = preg_replace('~\[(' . $alltags_regex . ')[^\]]*\]\s*\[/\1\]\s?~i', '', $message);
236
+	}
221 237
 
222 238
 	// Restore code blocks
223
-	if (!empty($code_tags))
224
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
239
+	if (!empty($code_tags)) {
240
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
241
+	}
225 242
 
226 243
 	// Restore white space entities
227
-	if (!$previewing)
228
-		$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
229
-	else
230
-		$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
244
+	if (!$previewing) {
245
+			$message = strtr($message, array('  ' => '&nbsp; ', "\n" => '<br>', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
246
+	} else {
247
+			$message = strtr($message, array('  ' => '&nbsp; ', $context['utf8'] ? "\xC2\xA0" : "\xA0" => '&nbsp;'));
248
+	}
231 249
 
232 250
 	// Now let's quickly clean up things that will slow our parser (which are common in posted code.)
233 251
 	$message = strtr($message, array('[]' => '&#91;]', '[&#039;' => '&#91;&#039;'));
@@ -270,8 +288,9 @@  discard block
 block discarded – undo
270 288
 		return "[time]" . timeformat("$m[1]", false) . "[/time]";
271 289
 	}, $message);
272 290
 
273
-	if (!empty($code_tags))
274
-		$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
291
+	if (!empty($code_tags)) {
292
+			$message = str_replace(array_keys($code_tags), array_values($code_tags), $message);
293
+	}
275 294
 
276 295
 	// Change breaks back to \n's and &nsbp; back to spaces.
277 296
 	return preg_replace('~<br( /)?' . '>~', "\n", str_replace('&nbsp;', ' ', $message));
@@ -352,8 +371,9 @@  discard block
 block discarded – undo
352 371
 	);
353 372
 
354 373
 	// Fix each type of tag.
355
-	foreach ($fixArray as $param)
356
-		fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
374
+	foreach ($fixArray as $param) {
375
+			fixTag($message, $param['tag'], $param['protocols'], $param['embeddedUrl'], $param['hasEqualSign'], !empty($param['hasExtra']));
376
+	}
357 377
 
358 378
 	// Now fix possible security problems with images loading links automatically...
359 379
 	$message = preg_replace_callback('~(\[img.*?\])(.+?)\[/img\]~is', function($m)
@@ -389,16 +409,19 @@  discard block
 block discarded – undo
389 409
 					$desired_height = $height;
390 410
 				}
391 411
 				// Scale it to the width...
392
-				elseif (empty($desired_width) && !empty($height))
393
-					$desired_width = (int) (($desired_height * $width) / $height);
412
+				elseif (empty($desired_width) && !empty($height)) {
413
+									$desired_width = (int) (($desired_height * $width) / $height);
414
+				}
394 415
 				// Scale if to the height.
395
-				elseif (!empty($width))
396
-					$desired_height = (int) (($desired_width * $height) / $width);
416
+				elseif (!empty($width)) {
417
+									$desired_height = (int) (($desired_width * $height) / $width);
418
+				}
397 419
 			}
398 420
 
399 421
 			// If the width and height are fine, just continue along...
400
-			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height'])
401
-				continue;
422
+			if ($desired_width <= $modSettings['max_image_width'] && $desired_height <= $modSettings['max_image_height']) {
423
+							continue;
424
+			}
402 425
 
403 426
 			// Too bad, it's too wide.  Make it as wide as the maximum.
404 427
 			if ($desired_width > $modSettings['max_image_width'] && !empty($modSettings['max_image_width']))
@@ -418,8 +441,9 @@  discard block
 block discarded – undo
418 441
 		}
419 442
 
420 443
 		// If any img tags were actually changed...
421
-		if (!empty($replaces))
422
-			$message = strtr($message, $replaces);
444
+		if (!empty($replaces)) {
445
+					$message = strtr($message, $replaces);
446
+		}
423 447
 	}
424 448
 }
425 449
 
@@ -438,10 +462,11 @@  discard block
 block discarded – undo
438 462
 {
439 463
 	global $boardurl, $scripturl;
440 464
 
441
-	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0)
442
-		$domain_url = $match[1];
443
-	else
444
-		$domain_url = $boardurl . '/';
465
+	if (preg_match('~^([^:]+://[^/]+)~', $boardurl, $match) != 0) {
466
+			$domain_url = $match[1];
467
+	} else {
468
+			$domain_url = $boardurl . '/';
469
+	}
445 470
 
446 471
 	$replaces = array();
447 472
 
@@ -449,11 +474,11 @@  discard block
 block discarded – undo
449 474
 	{
450 475
 		$quoted = preg_match('~\[(' . $myTag . ')=&quot;~', $message);
451 476
 		preg_match_all('~\[(' . $myTag . ')=' . ($quoted ? '&quot;(.*?)&quot;' : '([^\]]*?)') . '\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
477
+	} elseif ($hasEqualSign) {
478
+			preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
479
+	} else {
480
+			preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
452 481
 	}
453
-	elseif ($hasEqualSign)
454
-		preg_match_all('~\[(' . $myTag . ')=([^\]]*?)\](?:(.+?)\[/(' . $myTag . ')\])?~is', $message, $matches);
455
-	else
456
-		preg_match_all('~\[(' . $myTag . ($hasExtra ? '(?:[^\]]*?)' : '') . ')\](.+?)\[/(' . $myTag . ')\]~is', $message, $matches);
457 482
 
458 483
 	foreach ($matches[0] as $k => $dummy)
459 484
 	{
@@ -466,49 +491,53 @@  discard block
 block discarded – undo
466 491
 		foreach ($protocols as $protocol)
467 492
 		{
468 493
 			$found = strncasecmp($replace, $protocol . '://', strlen($protocol) + 3) === 0;
469
-			if ($found)
470
-				break;
494
+			if ($found) {
495
+							break;
496
+			}
471 497
 		}
472 498
 
473 499
 		if (!$found && $protocols[0] == 'http')
474 500
 		{
475
-			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//')
476
-				$replace = $domain_url . $replace;
477
-			elseif (substr($replace, 0, 1) == '?')
478
-				$replace = $scripturl . $replace;
479
-			elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
501
+			if (substr($replace, 0, 1) == '/' && substr($replace, 0, 2) != '//') {
502
+							$replace = $domain_url . $replace;
503
+			} elseif (substr($replace, 0, 1) == '?') {
504
+							$replace = $scripturl . $replace;
505
+			} elseif (substr($replace, 0, 1) == '#' && $embeddedUrl)
480 506
 			{
481 507
 				$replace = '#' . preg_replace('~[^A-Za-z0-9_\-#]~', '', substr($replace, 1));
482 508
 				$this_tag = 'iurl';
483 509
 				$this_close = 'iurl';
510
+			} elseif (substr($replace, 0, 2) != '//') {
511
+							$replace = $protocols[0] . '://' . $replace;
484 512
 			}
485
-			elseif (substr($replace, 0, 2) != '//')
486
-				$replace = $protocols[0] . '://' . $replace;
487
-		}
488
-		elseif (!$found && $protocols[0] == 'ftp')
489
-			$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
490
-		elseif (!$found)
491
-			$replace = $protocols[0] . '://' . $replace;
492
-
493
-		if ($hasEqualSign && $embeddedUrl)
494
-			$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
495
-		elseif ($hasEqualSign)
496
-			$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
497
-		elseif ($embeddedUrl)
498
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
499
-		else
500
-			$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
513
+		} elseif (!$found && $protocols[0] == 'ftp') {
514
+					$replace = $protocols[0] . '://' . preg_replace('~^(?!ftps?)[^:]+://~', '', $replace);
515
+		} elseif (!$found) {
516
+					$replace = $protocols[0] . '://' . $replace;
517
+		}
518
+
519
+		if ($hasEqualSign && $embeddedUrl) {
520
+					$replaces[$matches[0][$k]] = '[' . $this_tag . '=&quot;' . $replace . '&quot;]' . (empty($matches[4][$k]) ? '' : $matches[3][$k] . '[/' . $this_close . ']');
521
+		} elseif ($hasEqualSign) {
522
+					$replaces['[' . $matches[1][$k] . '=' . $matches[2][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']';
523
+		} elseif ($embeddedUrl) {
524
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . '=' . $replace . ']' . $matches[2][$k] . '[/' . $this_close . ']';
525
+		} else {
526
+					$replaces['[' . $matches[1][$k] . ']' . $matches[2][$k] . '[/' . $matches[3][$k] . ']'] = '[' . $this_tag . ']' . $replace . '[/' . $this_close . ']';
527
+		}
501 528
 	}
502 529
 
503 530
 	foreach ($replaces as $k => $v)
504 531
 	{
505
-		if ($k == $v)
506
-			unset($replaces[$k]);
532
+		if ($k == $v) {
533
+					unset($replaces[$k]);
534
+		}
507 535
 	}
508 536
 
509
-	if (!empty($replaces))
510
-		$message = strtr($message, $replaces);
511
-}
537
+	if (!empty($replaces)) {
538
+			$message = strtr($message, $replaces);
539
+	}
540
+	}
512 541
 
513 542
 /**
514 543
  * This function sends an email to the specified recipient(s).
@@ -552,8 +581,9 @@  discard block
 block discarded – undo
552 581
 	}
553 582
 
554 583
 	// Nothing left? Nothing else to do
555
-	if (empty($to_array))
556
-		return true;
584
+	if (empty($to_array)) {
585
+			return true;
586
+	}
557 587
 
558 588
 	// Once upon a time, Hotmail could not interpret non-ASCII mails.
559 589
 	// In honour of those days, it's still called the 'hotmail fix'.
@@ -570,15 +600,17 @@  discard block
 block discarded – undo
570 600
 		}
571 601
 
572 602
 		// Call this function recursively for the hotmail addresses.
573
-		if (!empty($hotmail_to))
574
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
603
+		if (!empty($hotmail_to)) {
604
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_id, $send_html, $priority, true, $is_private);
605
+		}
575 606
 
576 607
 		// The remaining addresses no longer need the fix.
577 608
 		$hotmail_fix = false;
578 609
 
579 610
 		// No other addresses left? Return instantly.
580
-		if (empty($to_array))
581
-			return $mail_result;
611
+		if (empty($to_array)) {
612
+					return $mail_result;
613
+		}
582 614
 	}
583 615
 
584 616
 	// Get rid of entities.
@@ -603,13 +635,15 @@  discard block
 block discarded – undo
603 635
 	$headers .= 'Return-Path: ' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . $line_break;
604 636
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
605 637
 
606
-	if ($message_id !== null && empty($modSettings['mail_no_message_id']))
607
-		$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
638
+	if ($message_id !== null && empty($modSettings['mail_no_message_id'])) {
639
+			$headers .= 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $message_id . strstr(empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from'], '@') . '>' . $line_break;
640
+	}
608 641
 	$headers .= 'X-Mailer: SMF' . $line_break;
609 642
 
610 643
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
611
-	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true))
612
-		return false;
644
+	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers, &$to_array)), true)) {
645
+			return false;
646
+	}
613 647
 
614 648
 	// Save the original message...
615 649
 	$orig_message = $message;
@@ -658,17 +692,19 @@  discard block
 block discarded – undo
658 692
 	}
659 693
 
660 694
 	// Are we using the mail queue, if so this is where we butt in...
661
-	if ($priority != 0)
662
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
695
+	if ($priority != 0) {
696
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private);
697
+	}
663 698
 
664 699
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
665 700
 	elseif (!empty($modSettings['mail_limit']))
666 701
 	{
667 702
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
668
-		if (empty($mails_this_minute) || time() > $last_mail_time + 60)
669
-			$new_queue_stat = time() . '|' . 1;
670
-		else
671
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
703
+		if (empty($mails_this_minute) || time() > $last_mail_time + 60) {
704
+					$new_queue_stat = time() . '|' . 1;
705
+		} else {
706
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
707
+		}
672 708
 
673 709
 		updateSettings(array('mail_recent' => $new_queue_stat));
674 710
 	}
@@ -693,12 +729,13 @@  discard block
 block discarded – undo
693 729
 
694 730
 			// Wait, wait, I'm still sending here!
695 731
 			@set_time_limit(300);
696
-			if (function_exists('apache_reset_timeout'))
697
-				@apache_reset_timeout();
732
+			if (function_exists('apache_reset_timeout')) {
733
+							@apache_reset_timeout();
734
+			}
698 735
 		}
736
+	} else {
737
+			$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
699 738
 	}
700
-	else
701
-		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers);
702 739
 
703 740
 	// Everything go smoothly?
704 741
 	return $mail_result;
@@ -724,8 +761,9 @@  discard block
 block discarded – undo
724 761
 	static $cur_insert = array();
725 762
 	static $cur_insert_len = 0;
726 763
 
727
-	if ($cur_insert_len == 0)
728
-		$cur_insert = array();
764
+	if ($cur_insert_len == 0) {
765
+			$cur_insert = array();
766
+	}
729 767
 
730 768
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
731 769
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -800,8 +838,9 @@  discard block
 block discarded – undo
800 838
 	}
801 839
 
802 840
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
803
-	if (SMF === 'SSI' || SMF === 'BACKGROUND')
804
-		return AddMailQueue(true);
841
+	if (SMF === 'SSI' || SMF === 'BACKGROUND') {
842
+			return AddMailQueue(true);
843
+	}
805 844
 
806 845
 	return true;
807 846
 }
@@ -832,23 +871,26 @@  discard block
 block discarded – undo
832 871
 		'sent' => array()
833 872
 	);
834 873
 
835
-	if ($from === null)
836
-		$from = array(
874
+	if ($from === null) {
875
+			$from = array(
837 876
 			'id' => $user_info['id'],
838 877
 			'name' => $user_info['name'],
839 878
 			'username' => $user_info['username']
840 879
 		);
880
+	}
841 881
 
842 882
 	// This is the one that will go in their inbox.
843 883
 	$htmlmessage = $smcFunc['htmlspecialchars']($message, ENT_QUOTES);
844 884
 	preparsecode($htmlmessage);
845 885
 	$htmlsubject = strtr($smcFunc['htmlspecialchars']($subject), array("\r" => '', "\n" => '', "\t" => ''));
846
-	if ($smcFunc['strlen']($htmlsubject) > 100)
847
-		$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
886
+	if ($smcFunc['strlen']($htmlsubject) > 100) {
887
+			$htmlsubject = $smcFunc['substr']($htmlsubject, 0, 100);
888
+	}
848 889
 
849 890
 	// Make sure is an array
850
-	if (!is_array($recipients))
851
-		$recipients = array($recipients);
891
+	if (!is_array($recipients)) {
892
+			$recipients = array($recipients);
893
+	}
852 894
 
853 895
 	// Integrated PMs
854 896
 	call_integration_hook('integrate_personal_message', array(&$recipients, &$from, &$subject, &$message));
@@ -876,21 +918,23 @@  discard block
 block discarded – undo
876 918
 				'usernames' => array_keys($usernames),
877 919
 			)
878 920
 		);
879
-		while ($row = $smcFunc['db_fetch_assoc']($request))
880
-			if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
921
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
922
+					if (isset($usernames[$smcFunc['strtolower']($row['member_name'])]))
881 923
 				$usernames[$smcFunc['strtolower']($row['member_name'])] = $row['id_member'];
924
+		}
882 925
 		$smcFunc['db_free_result']($request);
883 926
 
884 927
 		// Replace the usernames with IDs. Drop usernames that couldn't be found.
885
-		foreach ($recipients as $rec_type => $rec)
886
-			foreach ($rec as $id => $member)
928
+		foreach ($recipients as $rec_type => $rec) {
929
+					foreach ($rec as $id => $member)
887 930
 			{
888 931
 				if (is_numeric($recipients[$rec_type][$id]))
889 932
 					continue;
933
+		}
890 934
 
891
-				if (!empty($usernames[$member]))
892
-					$recipients[$rec_type][$id] = $usernames[$member];
893
-				else
935
+				if (!empty($usernames[$member])) {
936
+									$recipients[$rec_type][$id] = $usernames[$member];
937
+				} else
894 938
 				{
895 939
 					$log['failed'][$id] = sprintf($txt['pm_error_user_not_found'], $recipients[$rec_type][$id]);
896 940
 					unset($recipients[$rec_type][$id]);
@@ -928,8 +972,9 @@  discard block
 block discarded – undo
928 972
 		$delete = false;
929 973
 		foreach ($criteria as $criterium)
930 974
 		{
931
-			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false))
932
-				$delete = true;
975
+			if (($criterium['t'] == 'mid' && $criterium['v'] == $from['id']) || ($criterium['t'] == 'gid' && in_array($criterium['v'], $user_info['groups'])) || ($criterium['t'] == 'sub' && strpos($subject, $criterium['v']) !== false) || ($criterium['t'] == 'msg' && strpos($message, $criterium['v']) !== false)) {
976
+							$delete = true;
977
+			}
933 978
 			// If we're adding and one criteria don't match then we stop!
934 979
 			elseif (!$row['is_or'])
935 980
 			{
@@ -937,8 +982,9 @@  discard block
 block discarded – undo
937 982
 				break;
938 983
 			}
939 984
 		}
940
-		if ($delete)
941
-			$deletes[$row['id_member']] = 1;
985
+		if ($delete) {
986
+					$deletes[$row['id_member']] = 1;
987
+		}
942 988
 	}
943 989
 	$smcFunc['db_free_result']($request);
944 990
 
@@ -953,8 +999,9 @@  discard block
 block discarded – undo
953 999
 			array(
954 1000
 			)
955 1001
 		);
956
-		while ($row = $smcFunc['db_fetch_assoc']($request))
957
-			$message_limit_cache[$row['id_group']] = $row['max_messages'];
1002
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1003
+					$message_limit_cache[$row['id_group']] = $row['max_messages'];
1004
+		}
958 1005
 		$smcFunc['db_free_result']($request);
959 1006
 	}
960 1007
 
@@ -962,8 +1009,9 @@  discard block
 block discarded – undo
962 1009
 	require_once($sourcedir . '/Subs-Members.php');
963 1010
 	$pmReadGroups = groupsAllowedTo('pm_read');
964 1011
 
965
-	if (empty($modSettings['permission_enable_deny']))
966
-		$pmReadGroups['denied'] = array();
1012
+	if (empty($modSettings['permission_enable_deny'])) {
1013
+			$pmReadGroups['denied'] = array();
1014
+	}
967 1015
 
968 1016
 	// Load their alert preferences
969 1017
 	require_once($sourcedir . '/Subs-Notify.php');
@@ -995,8 +1043,9 @@  discard block
 block discarded – undo
995 1043
 	while ($row = $smcFunc['db_fetch_assoc']($request))
996 1044
 	{
997 1045
 		// Don't do anything for members to be deleted!
998
-		if (isset($deletes[$row['id_member']]))
999
-			continue;
1046
+		if (isset($deletes[$row['id_member']])) {
1047
+					continue;
1048
+		}
1000 1049
 
1001 1050
 		// Load the preferences for this member (if any)
1002 1051
 		$prefs = !empty($notifyPrefs[$row['id_member']]) ? $notifyPrefs[$row['id_member']] : array();
@@ -1017,8 +1066,9 @@  discard block
 block discarded – undo
1017 1066
 		{
1018 1067
 			foreach ($groups as $id)
1019 1068
 			{
1020
-				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id])
1021
-					$message_limit = $message_limit_cache[$id];
1069
+				if (isset($message_limit_cache[$id]) && $message_limit != 0 && $message_limit < $message_limit_cache[$id]) {
1070
+									$message_limit = $message_limit_cache[$id];
1071
+				}
1022 1072
 			}
1023 1073
 
1024 1074
 			if ($message_limit > 0 && $message_limit <= $row['instant_messages'])
@@ -1066,8 +1116,9 @@  discard block
 block discarded – undo
1066 1116
 	$smcFunc['db_free_result']($request);
1067 1117
 
1068 1118
 	// Only 'send' the message if there are any recipients left.
1069
-	if (empty($all_to))
1070
-		return $log;
1119
+	if (empty($all_to)) {
1120
+			return $log;
1121
+	}
1071 1122
 
1072 1123
 	// Insert the message itself and then grab the last insert id.
1073 1124
 	$id_pm = $smcFunc['db_insert']('',
@@ -1088,8 +1139,8 @@  discard block
 block discarded – undo
1088 1139
 	if (!empty($id_pm))
1089 1140
 	{
1090 1141
 		// If this is new we need to set it part of it's own conversation.
1091
-		if (empty($pm_head))
1092
-			$smcFunc['db_query']('', '
1142
+		if (empty($pm_head)) {
1143
+					$smcFunc['db_query']('', '
1093 1144
 				UPDATE {db_prefix}personal_messages
1094 1145
 				SET id_pm_head = {int:id_pm_head}
1095 1146
 				WHERE id_pm = {int:id_pm_head}',
@@ -1097,6 +1148,7 @@  discard block
 block discarded – undo
1097 1148
 					'id_pm_head' => $id_pm,
1098 1149
 				)
1099 1150
 			);
1151
+		}
1100 1152
 
1101 1153
 		// Some people think manually deleting personal_messages is fun... it's not. We protect against it though :)
1102 1154
 		$smcFunc['db_query']('', '
@@ -1112,8 +1164,9 @@  discard block
 block discarded – undo
1112 1164
 		foreach ($all_to as $to)
1113 1165
 		{
1114 1166
 			$insertRows[] = array($id_pm, $to, in_array($to, $recipients['bcc']) ? 1 : 0, isset($deletes[$to]) ? 1 : 0, 1);
1115
-			if (!in_array($to, $recipients['bcc']))
1116
-				$to_list[] = $to;
1167
+			if (!in_array($to, $recipients['bcc'])) {
1168
+							$to_list[] = $to;
1169
+			}
1117 1170
 		}
1118 1171
 
1119 1172
 		$smcFunc['db_insert']('insert',
@@ -1131,9 +1184,9 @@  discard block
 block discarded – undo
1131 1184
 	{
1132 1185
 		censorText($message);
1133 1186
 		$message = trim(un_htmlspecialchars(strip_tags(strtr(parse_bbc($smcFunc['htmlspecialchars']($message), false), array('<br>' => "\n", '</div>' => "\n", '</li>' => "\n", '&#91;' => '[', '&#93;' => ']')))));
1187
+	} else {
1188
+			$message = '';
1134 1189
 	}
1135
-	else
1136
-		$message = '';
1137 1190
 
1138 1191
 	$to_names = array();
1139 1192
 	if (count($to_list) > 1)
@@ -1146,8 +1199,9 @@  discard block
 block discarded – undo
1146 1199
 				'to_members' => $to_list,
1147 1200
 			)
1148 1201
 		);
1149
-		while ($row = $smcFunc['db_fetch_assoc']($request))
1150
-			$to_names[] = un_htmlspecialchars($row['real_name']);
1202
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
1203
+					$to_names[] = un_htmlspecialchars($row['real_name']);
1204
+		}
1151 1205
 		$smcFunc['db_free_result']($request);
1152 1206
 	}
1153 1207
 	$replacements = array(
@@ -1175,11 +1229,13 @@  discard block
 block discarded – undo
1175 1229
 	loadLanguage('index+PersonalMessage');
1176 1230
 
1177 1231
 	// Add one to their unread and read message counts.
1178
-	foreach ($all_to as $k => $id)
1179
-		if (isset($deletes[$id]))
1232
+	foreach ($all_to as $k => $id) {
1233
+			if (isset($deletes[$id]))
1180 1234
 			unset($all_to[$k]);
1181
-	if (!empty($all_to))
1182
-		updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1235
+	}
1236
+	if (!empty($all_to)) {
1237
+			updateMemberData($all_to, array('instant_messages' => '+', 'unread_messages' => '+', 'new_pm' => 1));
1238
+	}
1183 1239
 
1184 1240
 	return $log;
1185 1241
 }
@@ -1209,15 +1265,17 @@  discard block
 block discarded – undo
1209 1265
 		// Let's, for now, assume there are only &#021;'ish characters.
1210 1266
 		$simple = true;
1211 1267
 
1212
-		foreach ($matches[1] as $entity)
1213
-			if ($entity > 128)
1268
+		foreach ($matches[1] as $entity) {
1269
+					if ($entity > 128)
1214 1270
 				$simple = false;
1271
+		}
1215 1272
 		unset($matches);
1216 1273
 
1217
-		if ($simple)
1218
-			$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1274
+		if ($simple) {
1275
+					$string = preg_replace_callback('~&#(\d{3,8});~', function($m)
1219 1276
 			{
1220 1277
 				return chr("$m[1]");
1278
+		}
1221 1279
 			}, $string);
1222 1280
 		else
1223 1281
 		{
@@ -1225,8 +1283,9 @@  discard block
 block discarded – undo
1225 1283
 			if (!$context['utf8'] && function_exists('iconv'))
1226 1284
 			{
1227 1285
 				$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1228
-				if ($newstring)
1229
-					$string = $newstring;
1286
+				if ($newstring) {
1287
+									$string = $newstring;
1288
+				}
1230 1289
 			}
1231 1290
 
1232 1291
 			$string = preg_replace_callback('~&#(\d{3,8});~', 'fixchar__callback', $string);
@@ -1242,23 +1301,25 @@  discard block
 block discarded – undo
1242 1301
 		if (!$context['utf8'] && function_exists('iconv'))
1243 1302
 		{
1244 1303
 			$newstring = @iconv($context['character_set'], 'UTF-8', $string);
1245
-			if ($newstring)
1246
-				$string = $newstring;
1304
+			if ($newstring) {
1305
+							$string = $newstring;
1306
+			}
1247 1307
 		}
1248 1308
 
1249 1309
 		$entityConvert = function($m)
1250 1310
 		{
1251 1311
 			$c = $m[1];
1252
-			if (strlen($c) === 1 && ord($c[0]) <= 0x7F)
1253
-				return $c;
1254
-			elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF)
1255
-				return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1256
-			elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF)
1257
-				return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1258
-			elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7)
1259
-				return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1260
-			else
1261
-				return "";
1312
+			if (strlen($c) === 1 && ord($c[0]) <= 0x7F) {
1313
+							return $c;
1314
+			} elseif (strlen($c) === 2 && ord($c[0]) >= 0xC0 && ord($c[0]) <= 0xDF) {
1315
+							return "&#" . (((ord($c[0]) ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ";";
1316
+			} elseif (strlen($c) === 3 && ord($c[0]) >= 0xE0 && ord($c[0]) <= 0xEF) {
1317
+							return "&#" . (((ord($c[0]) ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ";";
1318
+			} elseif (strlen($c) === 4 && ord($c[0]) >= 0xF0 && ord($c[0]) <= 0xF7) {
1319
+							return "&#" . (((ord($c[0]) ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ";";
1320
+			} else {
1321
+							return "";
1322
+			}
1262 1323
 		};
1263 1324
 
1264 1325
 		// Convert all 'special' characters to HTML entities.
@@ -1272,19 +1333,20 @@  discard block
 block discarded – undo
1272 1333
 		$string = base64_encode($string);
1273 1334
 
1274 1335
 		// Show the characterset and the transfer-encoding for header strings.
1275
-		if ($with_charset)
1276
-			$string = '=?' . $charset . '?B?' . $string . '?=';
1336
+		if ($with_charset) {
1337
+					$string = '=?' . $charset . '?B?' . $string . '?=';
1338
+		}
1277 1339
 
1278 1340
 		// Break it up in lines (mail body).
1279
-		else
1280
-			$string = chunk_split($string, 76, $line_break);
1341
+		else {
1342
+					$string = chunk_split($string, 76, $line_break);
1343
+		}
1281 1344
 
1282 1345
 		return array($charset, $string, 'base64');
1346
+	} else {
1347
+			return array($charset, $string, '7bit');
1348
+	}
1283 1349
 	}
1284
-
1285
-	else
1286
-		return array($charset, $string, '7bit');
1287
-}
1288 1350
 
1289 1351
 /**
1290 1352
  * Sends mail, like mail() but over SMTP.
@@ -1308,8 +1370,9 @@  discard block
 block discarded – undo
1308 1370
 	if ($modSettings['mail_type'] == 3 && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
1309 1371
 	{
1310 1372
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
1311
-		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
1312
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1373
+		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.')) {
1374
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
1375
+		}
1313 1376
 
1314 1377
 		if ($socket)
1315 1378
 		{
@@ -1330,8 +1393,9 @@  discard block
 block discarded – undo
1330 1393
 		// Maybe we can still save this?  The port might be wrong.
1331 1394
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
1332 1395
 		{
1333
-			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
1334
-				log_error($txt['smtp_port_ssl']);
1396
+			if ($socket = fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3)) {
1397
+							log_error($txt['smtp_port_ssl']);
1398
+			}
1335 1399
 		}
1336 1400
 
1337 1401
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -1343,20 +1407,23 @@  discard block
 block discarded – undo
1343 1407
 	}
1344 1408
 
1345 1409
 	// Wait for a response of 220, without "-" continuer.
1346
-	if (!server_parse(null, $socket, '220'))
1347
-		return false;
1410
+	if (!server_parse(null, $socket, '220')) {
1411
+			return false;
1412
+	}
1348 1413
 
1349 1414
 	// Try and determine the servers name, fall back to the mail servers if not found
1350 1415
 	$helo = false;
1351
-	if (function_exists('gethostname') && gethostname() !== false)
1352
-		$helo = gethostname();
1353
-	elseif (function_exists('php_uname'))
1354
-		$helo = php_uname('n');
1355
-	elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME']))
1356
-		$helo = $_SERVER['SERVER_NAME'];
1416
+	if (function_exists('gethostname') && gethostname() !== false) {
1417
+			$helo = gethostname();
1418
+	} elseif (function_exists('php_uname')) {
1419
+			$helo = php_uname('n');
1420
+	} elseif (array_key_exists('SERVER_NAME', $_SERVER) && !empty($_SERVER['SERVER_NAME'])) {
1421
+			$helo = $_SERVER['SERVER_NAME'];
1422
+	}
1357 1423
 
1358
-	if (empty($helo))
1359
-		$helo = $modSettings['smtp_host'];
1424
+	if (empty($helo)) {
1425
+			$helo = $modSettings['smtp_host'];
1426
+	}
1360 1427
 
1361 1428
 	// SMTP = 1, SMTP - STARTTLS = 2
1362 1429
 	if (in_array($modSettings['mail_type'], array(1, 2)) && $modSettings['smtp_username'] != '' && $modSettings['smtp_password'] != '')
@@ -1368,33 +1435,39 @@  discard block
 block discarded – undo
1368 1435
 			if ($modSettings['mail_type'] == 2 && preg_match("~250( |-)STARTTLS~mi", $response))
1369 1436
 			{
1370 1437
 				// Send STARTTLS to enable encryption
1371
-				if (!server_parse('STARTTLS', $socket, '220'))
1372
-					return false;
1438
+				if (!server_parse('STARTTLS', $socket, '220')) {
1439
+									return false;
1440
+				}
1373 1441
 				// Enable the encryption
1374
-				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
1375
-					return false;
1442
+				if (!@stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
1443
+									return false;
1444
+				}
1376 1445
 				// Send the EHLO command again
1377
-				if (!server_parse('EHLO ' . $helo, $socket, null) == '250')
1378
-					return false;
1446
+				if (!server_parse('EHLO ' . $helo, $socket, null) == '250') {
1447
+									return false;
1448
+				}
1379 1449
 			}
1380 1450
 
1381
-			if (!server_parse('AUTH LOGIN', $socket, '334'))
1382
-				return false;
1451
+			if (!server_parse('AUTH LOGIN', $socket, '334')) {
1452
+							return false;
1453
+			}
1383 1454
 			// Send the username and password, encoded.
1384
-			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
1385
-				return false;
1455
+			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334')) {
1456
+							return false;
1457
+			}
1386 1458
 			// The password is already encoded ;)
1387
-			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
1388
-				return false;
1459
+			if (!server_parse($modSettings['smtp_password'], $socket, '235')) {
1460
+							return false;
1461
+			}
1462
+		} elseif (!server_parse('HELO ' . $helo, $socket, '250')) {
1463
+					return false;
1389 1464
 		}
1390
-		elseif (!server_parse('HELO ' . $helo, $socket, '250'))
1391
-			return false;
1392
-	}
1393
-	else
1465
+	} else
1394 1466
 	{
1395 1467
 		// Just say "helo".
1396
-		if (!server_parse('HELO ' . $helo, $socket, '250'))
1397
-			return false;
1468
+		if (!server_parse('HELO ' . $helo, $socket, '250')) {
1469
+					return false;
1470
+		}
1398 1471
 	}
1399 1472
 
1400 1473
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -1407,31 +1480,38 @@  discard block
 block discarded – undo
1407 1480
 		// Reset the connection to send another email.
1408 1481
 		if ($i != 0)
1409 1482
 		{
1410
-			if (!server_parse('RSET', $socket, '250'))
1411
-				return false;
1483
+			if (!server_parse('RSET', $socket, '250')) {
1484
+							return false;
1485
+			}
1412 1486
 		}
1413 1487
 
1414 1488
 		// From, to, and then start the data...
1415
-		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250'))
1416
-			return false;
1417
-		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
1418
-			return false;
1419
-		if (!server_parse('DATA', $socket, '354'))
1420
-			return false;
1489
+		if (!server_parse('MAIL FROM: <' . (empty($modSettings['mail_from']) ? $webmaster_email : $modSettings['mail_from']) . '>', $socket, '250')) {
1490
+					return false;
1491
+		}
1492
+		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250')) {
1493
+					return false;
1494
+		}
1495
+		if (!server_parse('DATA', $socket, '354')) {
1496
+					return false;
1497
+		}
1421 1498
 		fputs($socket, 'Subject: ' . $subject . "\r\n");
1422
-		if (strlen($mail_to) > 0)
1423
-			fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1499
+		if (strlen($mail_to) > 0) {
1500
+					fputs($socket, 'To: <' . $mail_to . '>' . "\r\n");
1501
+		}
1424 1502
 		fputs($socket, $headers . "\r\n\r\n");
1425 1503
 		fputs($socket, $message . "\r\n");
1426 1504
 
1427 1505
 		// Send a ., or in other words "end of data".
1428
-		if (!server_parse('.', $socket, '250'))
1429
-			return false;
1506
+		if (!server_parse('.', $socket, '250')) {
1507
+					return false;
1508
+		}
1430 1509
 
1431 1510
 		// Almost done, almost done... don't stop me just yet!
1432 1511
 		@set_time_limit(300);
1433
-		if (function_exists('apache_reset_timeout'))
1434
-			@apache_reset_timeout();
1512
+		if (function_exists('apache_reset_timeout')) {
1513
+					@apache_reset_timeout();
1514
+		}
1435 1515
 	}
1436 1516
 	fputs($socket, 'QUIT' . "\r\n");
1437 1517
 	fclose($socket);
@@ -1455,8 +1535,9 @@  discard block
 block discarded – undo
1455 1535
 {
1456 1536
 	global $txt;
1457 1537
 
1458
-	if ($message !== null)
1459
-		fputs($socket, $message . "\r\n");
1538
+	if ($message !== null) {
1539
+			fputs($socket, $message . "\r\n");
1540
+	}
1460 1541
 
1461 1542
 	// No response yet.
1462 1543
 	$server_response = '';
@@ -1472,8 +1553,9 @@  discard block
 block discarded – undo
1472 1553
 		$response .= $server_response;
1473 1554
 	}
1474 1555
 
1475
-	if ($code === null)
1476
-		return substr($server_response, 0, 3);
1556
+	if ($code === null) {
1557
+			return substr($server_response, 0, 3);
1558
+	}
1477 1559
 
1478 1560
 	if (substr($server_response, 0, 3) != $code)
1479 1561
 	{
@@ -1503,8 +1585,9 @@  discard block
 block discarded – undo
1503 1585
 	// Create a pspell or enchant dictionary resource
1504 1586
 	$dict = spell_init();
1505 1587
 
1506
-	if (!isset($_POST['spellstring']) || !$dict)
1507
-		die;
1588
+	if (!isset($_POST['spellstring']) || !$dict) {
1589
+			die;
1590
+	}
1508 1591
 
1509 1592
 	// Construct a bit of Javascript code.
1510 1593
 	$context['spell_js'] = '
@@ -1522,8 +1605,9 @@  discard block
 block discarded – undo
1522 1605
 		$check_word = explode('|', $alphas[$i]);
1523 1606
 
1524 1607
 		// If the word is a known word, or spelled right...
1525
-		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2]))
1526
-			continue;
1608
+		if (in_array($smcFunc['strtolower']($check_word[0]), $known_words) || spell_check($dict, $check_word[0]) || !isset($check_word[2])) {
1609
+					continue;
1610
+		}
1527 1611
 
1528 1612
 		// Find the word, and move up the "last occurrence" to here.
1529 1613
 		$found_words = true;
@@ -1537,20 +1621,23 @@  discard block
 block discarded – undo
1537 1621
 		if (!empty($suggestions))
1538 1622
 		{
1539 1623
 			// But first check they aren't going to be censored - no naughty words!
1540
-			foreach ($suggestions as $k => $word)
1541
-				if ($suggestions[$k] != censorText($word))
1624
+			foreach ($suggestions as $k => $word) {
1625
+							if ($suggestions[$k] != censorText($word))
1542 1626
 					unset($suggestions[$k]);
1627
+			}
1543 1628
 
1544
-			if (!empty($suggestions))
1545
-				$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1629
+			if (!empty($suggestions)) {
1630
+							$context['spell_js'] .= '"' . implode('", "', $suggestions) . '"';
1631
+			}
1546 1632
 		}
1547 1633
 
1548 1634
 		$context['spell_js'] .= ']),';
1549 1635
 	}
1550 1636
 
1551 1637
 	// If words were found, take off the last comma.
1552
-	if ($found_words)
1553
-		$context['spell_js'] = substr($context['spell_js'], 0, -1);
1638
+	if ($found_words) {
1639
+			$context['spell_js'] = substr($context['spell_js'], 0, -1);
1640
+	}
1554 1641
 
1555 1642
 	$context['spell_js'] .= '
1556 1643
 		);';
@@ -1585,11 +1672,13 @@  discard block
 block discarded – undo
1585 1672
 	global $user_info, $smcFunc;
1586 1673
 
1587 1674
 	// Can't do it if there's no topics.
1588
-	if (empty($topics))
1589
-		return;
1675
+	if (empty($topics)) {
1676
+			return;
1677
+	}
1590 1678
 	// It must be an array - it must!
1591
-	if (!is_array($topics))
1592
-		$topics = array($topics);
1679
+	if (!is_array($topics)) {
1680
+			$topics = array($topics);
1681
+	}
1593 1682
 
1594 1683
 	// Get the subject and body...
1595 1684
 	$result = $smcFunc['db_query']('', '
@@ -1637,14 +1726,15 @@  discard block
 block discarded – undo
1637 1726
 	}
1638 1727
 	$smcFunc['db_free_result']($result);
1639 1728
 
1640
-	if (!empty($task_rows))
1641
-		$smcFunc['db_insert']('',
1729
+	if (!empty($task_rows)) {
1730
+			$smcFunc['db_insert']('',
1642 1731
 			'{db_prefix}background_tasks',
1643 1732
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1644 1733
 			$task_rows,
1645 1734
 			array('id_task')
1646 1735
 		);
1647
-}
1736
+	}
1737
+	}
1648 1738
 
1649 1739
 /**
1650 1740
  * Create a post, either as new topic (id_topic = 0) or in an existing one.
@@ -1682,9 +1772,9 @@  discard block
 block discarded – undo
1682 1772
 	$msgOptions['send_notifications'] = isset($msgOptions['send_notifications']) ? (bool) $msgOptions['send_notifications'] : true;
1683 1773
 
1684 1774
 	// We need to know if the topic is approved. If we're told that's great - if not find out.
1685
-	if (!$modSettings['postmod_active'])
1686
-		$topicOptions['is_approved'] = true;
1687
-	elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1775
+	if (!$modSettings['postmod_active']) {
1776
+			$topicOptions['is_approved'] = true;
1777
+	} elseif (!empty($topicOptions['id']) && !isset($topicOptions['is_approved']))
1688 1778
 	{
1689 1779
 		$request = $smcFunc['db_query']('', '
1690 1780
 			SELECT approved
@@ -1707,8 +1797,7 @@  discard block
 block discarded – undo
1707 1797
 			$posterOptions['id'] = 0;
1708 1798
 			$posterOptions['name'] = $txt['guest_title'];
1709 1799
 			$posterOptions['email'] = '';
1710
-		}
1711
-		elseif ($posterOptions['id'] != $user_info['id'])
1800
+		} elseif ($posterOptions['id'] != $user_info['id'])
1712 1801
 		{
1713 1802
 			$request = $smcFunc['db_query']('', '
1714 1803
 				SELECT member_name, email_address
@@ -1726,12 +1815,11 @@  discard block
 block discarded – undo
1726 1815
 				$posterOptions['id'] = 0;
1727 1816
 				$posterOptions['name'] = $txt['guest_title'];
1728 1817
 				$posterOptions['email'] = '';
1818
+			} else {
1819
+							list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1729 1820
 			}
1730
-			else
1731
-				list ($posterOptions['name'], $posterOptions['email']) = $smcFunc['db_fetch_row']($request);
1732 1821
 			$smcFunc['db_free_result']($request);
1733
-		}
1734
-		else
1822
+		} else
1735 1823
 		{
1736 1824
 			$posterOptions['name'] = $user_info['name'];
1737 1825
 			$posterOptions['email'] = $user_info['email'];
@@ -1741,8 +1829,9 @@  discard block
 block discarded – undo
1741 1829
 	if (!empty($modSettings['enable_mentions']))
1742 1830
 	{
1743 1831
 		$msgOptions['mentioned_members'] = Mentions::getMentionedMembers($msgOptions['body']);
1744
-		if (!empty($msgOptions['mentioned_members']))
1745
-			$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1832
+		if (!empty($msgOptions['mentioned_members'])) {
1833
+					$msgOptions['body'] = Mentions::getBody($msgOptions['body'], $msgOptions['mentioned_members']);
1834
+		}
1746 1835
 	}
1747 1836
 
1748 1837
 	// It's do or die time: forget any user aborts!
@@ -1775,12 +1864,13 @@  discard block
 block discarded – undo
1775 1864
 	);
1776 1865
 
1777 1866
 	// Something went wrong creating the message...
1778
-	if (empty($msgOptions['id']))
1779
-		return false;
1867
+	if (empty($msgOptions['id'])) {
1868
+			return false;
1869
+	}
1780 1870
 
1781 1871
 	// Fix the attachments.
1782
-	if (!empty($msgOptions['attachments']))
1783
-		$smcFunc['db_query']('', '
1872
+	if (!empty($msgOptions['attachments'])) {
1873
+			$smcFunc['db_query']('', '
1784 1874
 			UPDATE {db_prefix}attachments
1785 1875
 			SET id_msg = {int:id_msg}
1786 1876
 			WHERE id_attach IN ({array_int:attachment_list})',
@@ -1789,6 +1879,7 @@  discard block
 block discarded – undo
1789 1879
 				'id_msg' => $msgOptions['id'],
1790 1880
 			)
1791 1881
 		);
1882
+	}
1792 1883
 
1793 1884
 	// What if we want to export new posts out to a CMS?
1794 1885
 	call_integration_hook('integrate_after_create_post', array($msgOptions, $topicOptions, $posterOptions, $message_columns, $message_parameters));
@@ -1865,20 +1956,23 @@  discard block
 block discarded – undo
1865 1956
 			'id_topic' => $topicOptions['id'],
1866 1957
 			'counter_increment' => 1,
1867 1958
 		);
1868
-		if ($msgOptions['approved'])
1869
-			$topics_columns = array(
1959
+		if ($msgOptions['approved']) {
1960
+					$topics_columns = array(
1870 1961
 				'id_member_updated = {int:poster_id}',
1871 1962
 				'id_last_msg = {int:id_msg}',
1872 1963
 				'num_replies = num_replies + {int:counter_increment}',
1873 1964
 			);
1874
-		else
1875
-			$topics_columns = array(
1965
+		} else {
1966
+					$topics_columns = array(
1876 1967
 				'unapproved_posts = unapproved_posts + {int:counter_increment}',
1877 1968
 			);
1878
-		if ($topicOptions['lock_mode'] !== null)
1879
-			$topics_columns[] = 'locked = {int:locked}';
1880
-		if ($topicOptions['sticky_mode'] !== null)
1881
-			$topics_columns[] = 'is_sticky = {int:is_sticky}';
1969
+		}
1970
+		if ($topicOptions['lock_mode'] !== null) {
1971
+					$topics_columns[] = 'locked = {int:locked}';
1972
+		}
1973
+		if ($topicOptions['sticky_mode'] !== null) {
1974
+					$topics_columns[] = 'is_sticky = {int:is_sticky}';
1975
+		}
1882 1976
 
1883 1977
 		call_integration_hook('integrate_modify_topic', array(&$topics_columns, &$update_parameters, &$msgOptions, &$topicOptions, &$posterOptions));
1884 1978
 
@@ -1907,8 +2001,8 @@  discard block
 block discarded – undo
1907 2001
 	);
1908 2002
 
1909 2003
 	// Increase the number of posts and topics on the board.
1910
-	if ($msgOptions['approved'])
1911
-		$smcFunc['db_query']('', '
2004
+	if ($msgOptions['approved']) {
2005
+			$smcFunc['db_query']('', '
1912 2006
 			UPDATE {db_prefix}boards
1913 2007
 			SET num_posts = num_posts + 1' . ($new_topic ? ', num_topics = num_topics + 1' : '') . '
1914 2008
 			WHERE id_board = {int:id_board}',
@@ -1916,7 +2010,7 @@  discard block
 block discarded – undo
1916 2010
 				'id_board' => $topicOptions['board'],
1917 2011
 			)
1918 2012
 		);
1919
-	else
2013
+	} else
1920 2014
 	{
1921 2015
 		$smcFunc['db_query']('', '
1922 2016
 			UPDATE {db_prefix}boards
@@ -1986,8 +2080,8 @@  discard block
 block discarded – undo
1986 2080
 		}
1987 2081
 	}
1988 2082
 
1989
-	if ($msgOptions['approved'] && empty($topicOptions['is_approved']))
1990
-		$smcFunc['db_insert']('',
2083
+	if ($msgOptions['approved'] && empty($topicOptions['is_approved'])) {
2084
+			$smcFunc['db_insert']('',
1991 2085
 			'{db_prefix}background_tasks',
1992 2086
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
1993 2087
 			array(
@@ -1999,19 +2093,22 @@  discard block
 block discarded – undo
1999 2093
 			),
2000 2094
 			array('id_task')
2001 2095
 		);
2096
+	}
2002 2097
 
2003 2098
 	// If there's a custom search index, it may need updating...
2004 2099
 	require_once($sourcedir . '/Search.php');
2005 2100
 	$searchAPI = findSearchAPI();
2006
-	if (is_callable(array($searchAPI, 'postCreated')))
2007
-		$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2101
+	if (is_callable(array($searchAPI, 'postCreated'))) {
2102
+			$searchAPI->postCreated($msgOptions, $topicOptions, $posterOptions);
2103
+	}
2008 2104
 
2009 2105
 	// Increase the post counter for the user that created the post.
2010 2106
 	if (!empty($posterOptions['update_post_count']) && !empty($posterOptions['id']) && $msgOptions['approved'])
2011 2107
 	{
2012 2108
 		// Are you the one that happened to create this post?
2013
-		if ($user_info['id'] == $posterOptions['id'])
2014
-			$user_info['posts']++;
2109
+		if ($user_info['id'] == $posterOptions['id']) {
2110
+					$user_info['posts']++;
2111
+		}
2015 2112
 		updateMemberData($posterOptions['id'], array('posts' => '+'));
2016 2113
 	}
2017 2114
 
@@ -2019,19 +2116,21 @@  discard block
 block discarded – undo
2019 2116
 	$_SESSION['last_read_topic'] = 0;
2020 2117
 
2021 2118
 	// Better safe than sorry.
2022
-	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']]))
2023
-		$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2119
+	if (isset($_SESSION['topicseen_cache'][$topicOptions['board']])) {
2120
+			$_SESSION['topicseen_cache'][$topicOptions['board']]--;
2121
+	}
2024 2122
 
2025 2123
 	// Update all the stats so everyone knows about this new topic and message.
2026 2124
 	updateStats('message', true, $msgOptions['id']);
2027 2125
 
2028 2126
 	// Update the last message on the board assuming it's approved AND the topic is.
2029
-	if ($msgOptions['approved'])
2030
-		updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2127
+	if ($msgOptions['approved']) {
2128
+			updateLastMessages($topicOptions['board'], $new_topic || !empty($topicOptions['is_approved']) ? $msgOptions['id'] : 0);
2129
+	}
2031 2130
 
2032 2131
 	// Queue createPost background notification
2033
-	if ($msgOptions['send_notifications'] && $msgOptions['approved'])
2034
-		$smcFunc['db_insert']('',
2132
+	if ($msgOptions['send_notifications'] && $msgOptions['approved']) {
2133
+			$smcFunc['db_insert']('',
2035 2134
 			'{db_prefix}background_tasks',
2036 2135
 			array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2037 2136
 			array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
@@ -2042,6 +2141,7 @@  discard block
 block discarded – undo
2042 2141
 			)), 0),
2043 2142
 			array('id_task')
2044 2143
 		);
2144
+	}
2045 2145
 
2046 2146
 	// Alright, done now... we can abort now, I guess... at least this much is done.
2047 2147
 	ignore_user_abort($previous_ignore_user_abort);
@@ -2068,14 +2168,18 @@  discard block
 block discarded – undo
2068 2168
 
2069 2169
 	// This is longer than it has to be, but makes it so we only set/change what we have to.
2070 2170
 	$messages_columns = array();
2071
-	if (isset($posterOptions['name']))
2072
-		$messages_columns['poster_name'] = $posterOptions['name'];
2073
-	if (isset($posterOptions['email']))
2074
-		$messages_columns['poster_email'] = $posterOptions['email'];
2075
-	if (isset($msgOptions['icon']))
2076
-		$messages_columns['icon'] = $msgOptions['icon'];
2077
-	if (isset($msgOptions['subject']))
2078
-		$messages_columns['subject'] = $msgOptions['subject'];
2171
+	if (isset($posterOptions['name'])) {
2172
+			$messages_columns['poster_name'] = $posterOptions['name'];
2173
+	}
2174
+	if (isset($posterOptions['email'])) {
2175
+			$messages_columns['poster_email'] = $posterOptions['email'];
2176
+	}
2177
+	if (isset($msgOptions['icon'])) {
2178
+			$messages_columns['icon'] = $msgOptions['icon'];
2179
+	}
2180
+	if (isset($msgOptions['subject'])) {
2181
+			$messages_columns['subject'] = $msgOptions['subject'];
2182
+	}
2079 2183
 	if (isset($msgOptions['body']))
2080 2184
 	{
2081 2185
 		$messages_columns['body'] = $msgOptions['body'];
@@ -2102,8 +2206,9 @@  discard block
 block discarded – undo
2102 2206
 		$messages_columns['modified_reason'] = $msgOptions['modify_reason'];
2103 2207
 		$messages_columns['id_msg_modified'] = $modSettings['maxMsgID'];
2104 2208
 	}
2105
-	if (isset($msgOptions['smileys_enabled']))
2106
-		$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2209
+	if (isset($msgOptions['smileys_enabled'])) {
2210
+			$messages_columns['smileys_enabled'] = empty($msgOptions['smileys_enabled']) ? 0 : 1;
2211
+	}
2107 2212
 
2108 2213
 	// Which columns need to be ints?
2109 2214
 	$messageInts = array('modified_time', 'id_msg_modified', 'smileys_enabled');
@@ -2121,23 +2226,27 @@  discard block
 block discarded – undo
2121 2226
 		{
2122 2227
 			preg_match_all('/\[member\=([0-9]+)\]([^\[]*)\[\/member\]/U', $msgOptions['old_body'], $match);
2123 2228
 
2124
-			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2]))
2125
-				foreach ($match[1] as $i => $oldID)
2229
+			if (isset($match[1]) && isset($match[2]) && is_array($match[1]) && is_array($match[2])) {
2230
+							foreach ($match[1] as $i => $oldID)
2126 2231
 					$oldmentions[$oldID] = array('id' => $oldID, 'real_name' => $match[2][$i]);
2232
+			}
2127 2233
 
2128
-			if (empty($modSettings['search_custom_index_config']))
2129
-				unset($msgOptions['old_body']);
2234
+			if (empty($modSettings['search_custom_index_config'])) {
2235
+							unset($msgOptions['old_body']);
2236
+			}
2130 2237
 		}
2131 2238
 
2132 2239
 		$mentions = Mentions::getMentionedMembers($msgOptions['body']);
2133 2240
 		$messages_columns['body'] = $msgOptions['body'] = Mentions::getBody($msgOptions['body'], $mentions);
2134 2241
 
2135 2242
 		// Remove the poster.
2136
-		if (isset($mentions[$user_info['id']]))
2137
-			unset($mentions[$user_info['id']]);
2243
+		if (isset($mentions[$user_info['id']])) {
2244
+					unset($mentions[$user_info['id']]);
2245
+		}
2138 2246
 
2139
-		if (isset($oldmentions[$user_info['id']]))
2140
-			unset($oldmentions[$user_info['id']]);
2247
+		if (isset($oldmentions[$user_info['id']])) {
2248
+					unset($oldmentions[$user_info['id']]);
2249
+		}
2141 2250
 
2142 2251
 		if (is_array($mentions) && is_array($oldmentions) && count(array_diff_key($mentions, $oldmentions)) > 0 && count($mentions) > count($oldmentions))
2143 2252
 		{
@@ -2167,8 +2276,9 @@  discard block
 block discarded – undo
2167 2276
 	}
2168 2277
 
2169 2278
 	// Nothing to do?
2170
-	if (empty($messages_columns))
2171
-		return true;
2279
+	if (empty($messages_columns)) {
2280
+			return true;
2281
+	}
2172 2282
 
2173 2283
 	// Change the post.
2174 2284
 	$smcFunc['db_query']('', '
@@ -2229,8 +2339,9 @@  discard block
 block discarded – undo
2229 2339
 	// If there's a custom search index, it needs to be modified...
2230 2340
 	require_once($sourcedir . '/Search.php');
2231 2341
 	$searchAPI = findSearchAPI();
2232
-	if (is_callable(array($searchAPI, 'postModified')))
2233
-		$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2342
+	if (is_callable(array($searchAPI, 'postModified'))) {
2343
+			$searchAPI->postModified($msgOptions, $topicOptions, $posterOptions);
2344
+	}
2234 2345
 
2235 2346
 	if (isset($msgOptions['subject']))
2236 2347
 	{
@@ -2244,14 +2355,16 @@  discard block
 block discarded – undo
2244 2355
 				'id_first_msg' => $msgOptions['id'],
2245 2356
 			)
2246 2357
 		);
2247
-		if ($smcFunc['db_num_rows']($request) == 1)
2248
-			updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2358
+		if ($smcFunc['db_num_rows']($request) == 1) {
2359
+					updateStats('subject', $topicOptions['id'], $msgOptions['subject']);
2360
+		}
2249 2361
 		$smcFunc['db_free_result']($request);
2250 2362
 	}
2251 2363
 
2252 2364
 	// Finally, if we are setting the approved state we need to do much more work :(
2253
-	if ($modSettings['postmod_active'] && isset($msgOptions['approved']))
2254
-		approvePosts($msgOptions['id'], $msgOptions['approved']);
2365
+	if ($modSettings['postmod_active'] && isset($msgOptions['approved'])) {
2366
+			approvePosts($msgOptions['id'], $msgOptions['approved']);
2367
+	}
2255 2368
 
2256 2369
 	return true;
2257 2370
 }
@@ -2268,11 +2381,13 @@  discard block
 block discarded – undo
2268 2381
 {
2269 2382
 	global $smcFunc;
2270 2383
 
2271
-	if (!is_array($msgs))
2272
-		$msgs = array($msgs);
2384
+	if (!is_array($msgs)) {
2385
+			$msgs = array($msgs);
2386
+	}
2273 2387
 
2274
-	if (empty($msgs))
2275
-		return false;
2388
+	if (empty($msgs)) {
2389
+			return false;
2390
+	}
2276 2391
 
2277 2392
 	// May as well start at the beginning, working out *what* we need to change.
2278 2393
 	$request = $smcFunc['db_query']('', '
@@ -2304,20 +2419,22 @@  discard block
 block discarded – undo
2304 2419
 		$topics[] = $row['id_topic'];
2305 2420
 
2306 2421
 		// Ensure our change array exists already.
2307
-		if (!isset($topic_changes[$row['id_topic']]))
2308
-			$topic_changes[$row['id_topic']] = array(
2422
+		if (!isset($topic_changes[$row['id_topic']])) {
2423
+					$topic_changes[$row['id_topic']] = array(
2309 2424
 				'id_last_msg' => $row['id_last_msg'],
2310 2425
 				'approved' => $row['topic_approved'],
2311 2426
 				'replies' => 0,
2312 2427
 				'unapproved_posts' => 0,
2313 2428
 			);
2314
-		if (!isset($board_changes[$row['id_board']]))
2315
-			$board_changes[$row['id_board']] = array(
2429
+		}
2430
+		if (!isset($board_changes[$row['id_board']])) {
2431
+					$board_changes[$row['id_board']] = array(
2316 2432
 				'posts' => 0,
2317 2433
 				'topics' => 0,
2318 2434
 				'unapproved_posts' => 0,
2319 2435
 				'unapproved_topics' => 0,
2320 2436
 			);
2437
+		}
2321 2438
 
2322 2439
 		// If it's the first message then the topic state changes!
2323 2440
 		if ($row['id_msg'] == $row['id_first_msg'])
@@ -2338,14 +2455,13 @@  discard block
 block discarded – undo
2338 2455
 				'poster' => $row['id_member'],
2339 2456
 				'new_topic' => true,
2340 2457
 			);
2341
-		}
2342
-		else
2458
+		} else
2343 2459
 		{
2344 2460
 			$topic_changes[$row['id_topic']]['replies'] += $approve ? 1 : -1;
2345 2461
 
2346 2462
 			// This will be a post... but don't notify unless it's not followed by approved ones.
2347
-			if ($row['id_msg'] > $row['id_last_msg'])
2348
-				$notification_posts[$row['id_topic']] = array(
2463
+			if ($row['id_msg'] > $row['id_last_msg']) {
2464
+							$notification_posts[$row['id_topic']] = array(
2349 2465
 					'id' => $row['id_msg'],
2350 2466
 					'body' => $row['body'],
2351 2467
 					'subject' => $row['subject'],
@@ -2356,28 +2472,33 @@  discard block
 block discarded – undo
2356 2472
 					'new_topic' => false,
2357 2473
 					'msg' => $row['id_msg'],
2358 2474
 				);
2475
+			}
2359 2476
 		}
2360 2477
 
2361 2478
 		// If this is being approved and id_msg is higher than the current id_last_msg then it changes.
2362
-		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg'])
2363
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2479
+		if ($approve && $row['id_msg'] > $topic_changes[$row['id_topic']]['id_last_msg']) {
2480
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_msg'];
2481
+		}
2364 2482
 		// If this is being unapproved, and it's equal to the id_last_msg we need to find a new one!
2365
-		elseif (!$approve)
2366
-			// Default to the first message and then we'll override in a bit ;)
2483
+		elseif (!$approve) {
2484
+					// Default to the first message and then we'll override in a bit ;)
2367 2485
 			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_first_msg'];
2486
+		}
2368 2487
 
2369 2488
 		$topic_changes[$row['id_topic']]['unapproved_posts'] += $approve ? -1 : 1;
2370 2489
 		$board_changes[$row['id_board']]['unapproved_posts'] += $approve ? -1 : 1;
2371 2490
 		$board_changes[$row['id_board']]['posts'] += $approve ? 1 : -1;
2372 2491
 
2373 2492
 		// Post count for the user?
2374
-		if ($row['id_member'] && empty($row['count_posts']))
2375
-			$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2493
+		if ($row['id_member'] && empty($row['count_posts'])) {
2494
+					$member_post_changes[$row['id_member']] = isset($member_post_changes[$row['id_member']]) ? $member_post_changes[$row['id_member']] + 1 : 1;
2495
+		}
2376 2496
 	}
2377 2497
 	$smcFunc['db_free_result']($request);
2378 2498
 
2379
-	if (empty($msgs))
2380
-		return;
2499
+	if (empty($msgs)) {
2500
+			return;
2501
+	}
2381 2502
 
2382 2503
 	// Now we have the differences make the changes, first the easy one.
2383 2504
 	$smcFunc['db_query']('', '
@@ -2404,14 +2525,15 @@  discard block
 block discarded – undo
2404 2525
 				'approved' => 1,
2405 2526
 			)
2406 2527
 		);
2407
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2408
-			$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2528
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2529
+					$topic_changes[$row['id_topic']]['id_last_msg'] = $row['id_last_msg'];
2530
+		}
2409 2531
 		$smcFunc['db_free_result']($request);
2410 2532
 	}
2411 2533
 
2412 2534
 	// ... next the topics...
2413
-	foreach ($topic_changes as $id => $changes)
2414
-		$smcFunc['db_query']('', '
2535
+	foreach ($topic_changes as $id => $changes) {
2536
+			$smcFunc['db_query']('', '
2415 2537
 			UPDATE {db_prefix}topics
2416 2538
 			SET approved = {int:approved}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2417 2539
 				num_replies = num_replies + {int:num_replies}, id_last_msg = {int:id_last_msg}
@@ -2424,10 +2546,11 @@  discard block
 block discarded – undo
2424 2546
 				'id_topic' => $id,
2425 2547
 			)
2426 2548
 		);
2549
+	}
2427 2550
 
2428 2551
 	// ... finally the boards...
2429
-	foreach ($board_changes as $id => $changes)
2430
-		$smcFunc['db_query']('', '
2552
+	foreach ($board_changes as $id => $changes) {
2553
+			$smcFunc['db_query']('', '
2431 2554
 			UPDATE {db_prefix}boards
2432 2555
 			SET num_posts = num_posts + {int:num_posts}, unapproved_posts = unapproved_posts + {int:unapproved_posts},
2433 2556
 				num_topics = num_topics + {int:num_topics}, unapproved_topics = unapproved_topics + {int:unapproved_topics}
@@ -2440,13 +2563,14 @@  discard block
 block discarded – undo
2440 2563
 				'id_board' => $id,
2441 2564
 			)
2442 2565
 		);
2566
+	}
2443 2567
 
2444 2568
 	// Finally, least importantly, notifications!
2445 2569
 	if ($approve)
2446 2570
 	{
2447 2571
 		$task_rows = array();
2448
-		foreach (array_merge($notification_topics, $notification_posts) as $topic)
2449
-			$task_rows[] = array(
2572
+		foreach (array_merge($notification_topics, $notification_posts) as $topic) {
2573
+					$task_rows[] = array(
2450 2574
 				'$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
2451 2575
 					'msgOptions' => array(
2452 2576
 						'id' => $topic['msg'],
@@ -2464,14 +2588,16 @@  discard block
 block discarded – undo
2464 2588
 					'type' => $topic['new_topic'] ? 'topic' : 'reply',
2465 2589
 				)), 0
2466 2590
 			);
2591
+		}
2467 2592
 
2468
-		if ($notify)
2469
-			$smcFunc['db_insert']('',
2593
+		if ($notify) {
2594
+					$smcFunc['db_insert']('',
2470 2595
 				'{db_prefix}background_tasks',
2471 2596
 				array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
2472 2597
 				$task_rows,
2473 2598
 				array('id_task')
2474 2599
 			);
2600
+		}
2475 2601
 
2476 2602
 		$smcFunc['db_query']('', '
2477 2603
 			DELETE FROM {db_prefix}approval_queue
@@ -2487,8 +2613,9 @@  discard block
 block discarded – undo
2487 2613
 	else
2488 2614
 	{
2489 2615
 		$msgInserts = array();
2490
-		foreach ($msgs as $msg)
2491
-			$msgInserts[] = array($msg);
2616
+		foreach ($msgs as $msg) {
2617
+					$msgInserts[] = array($msg);
2618
+		}
2492 2619
 
2493 2620
 		$smcFunc['db_insert']('ignore',
2494 2621
 			'{db_prefix}approval_queue',
@@ -2502,9 +2629,10 @@  discard block
 block discarded – undo
2502 2629
 	updateLastMessages(array_keys($board_changes));
2503 2630
 
2504 2631
 	// Post count for the members?
2505
-	if (!empty($member_post_changes))
2506
-		foreach ($member_post_changes as $id_member => $count_change)
2632
+	if (!empty($member_post_changes)) {
2633
+			foreach ($member_post_changes as $id_member => $count_change)
2507 2634
 			updateMemberData($id_member, array('posts' => 'posts ' . ($approve ? '+' : '-') . ' ' . $count_change));
2635
+	}
2508 2636
 
2509 2637
 	return true;
2510 2638
 }
@@ -2521,11 +2649,13 @@  discard block
 block discarded – undo
2521 2649
 {
2522 2650
 	global $smcFunc;
2523 2651
 
2524
-	if (!is_array($topics))
2525
-		$topics = array($topics);
2652
+	if (!is_array($topics)) {
2653
+			$topics = array($topics);
2654
+	}
2526 2655
 
2527
-	if (empty($topics))
2528
-		return false;
2656
+	if (empty($topics)) {
2657
+			return false;
2658
+	}
2529 2659
 
2530 2660
 	$approve_type = $approve ? 0 : 1;
2531 2661
 
@@ -2541,8 +2671,9 @@  discard block
 block discarded – undo
2541 2671
 		)
2542 2672
 	);
2543 2673
 	$msgs = array();
2544
-	while ($row = $smcFunc['db_fetch_assoc']($request))
2545
-		$msgs[] = $row['id_msg'];
2674
+	while ($row = $smcFunc['db_fetch_assoc']($request)) {
2675
+			$msgs[] = $row['id_msg'];
2676
+	}
2546 2677
 	$smcFunc['db_free_result']($request);
2547 2678
 
2548 2679
 	return approvePosts($msgs, $approve);
@@ -2565,11 +2696,13 @@  discard block
 block discarded – undo
2565 2696
 	global $board_info, $board, $smcFunc;
2566 2697
 
2567 2698
 	// Please - let's be sane.
2568
-	if (empty($setboards))
2569
-		return false;
2699
+	if (empty($setboards)) {
2700
+			return false;
2701
+	}
2570 2702
 
2571
-	if (!is_array($setboards))
2572
-		$setboards = array($setboards);
2703
+	if (!is_array($setboards)) {
2704
+			$setboards = array($setboards);
2705
+	}
2573 2706
 
2574 2707
 	// If we don't know the id_msg we need to find it.
2575 2708
 	if (!$id_msg)
@@ -2587,15 +2720,16 @@  discard block
 block discarded – undo
2587 2720
 			)
2588 2721
 		);
2589 2722
 		$lastMsg = array();
2590
-		while ($row = $smcFunc['db_fetch_assoc']($request))
2591
-			$lastMsg[$row['id_board']] = $row['id_msg'];
2723
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
2724
+					$lastMsg[$row['id_board']] = $row['id_msg'];
2725
+		}
2592 2726
 		$smcFunc['db_free_result']($request);
2593
-	}
2594
-	else
2727
+	} else
2595 2728
 	{
2596 2729
 		// Just to note - there should only be one board passed if we are doing this.
2597
-		foreach ($setboards as $id_board)
2598
-			$lastMsg[$id_board] = $id_msg;
2730
+		foreach ($setboards as $id_board) {
2731
+					$lastMsg[$id_board] = $id_msg;
2732
+		}
2599 2733
 	}
2600 2734
 
2601 2735
 	$parent_boards = array();
@@ -2610,10 +2744,11 @@  discard block
 block discarded – undo
2610 2744
 			$lastModified[$id_board] = 0;
2611 2745
 		}
2612 2746
 
2613
-		if (!empty($board) && $id_board == $board)
2614
-			$parents = $board_info['parent_boards'];
2615
-		else
2616
-			$parents = getBoardParents($id_board);
2747
+		if (!empty($board) && $id_board == $board) {
2748
+					$parents = $board_info['parent_boards'];
2749
+		} else {
2750
+					$parents = getBoardParents($id_board);
2751
+		}
2617 2752
 
2618 2753
 		// Ignore any parents on the top child level.
2619 2754
 		// @todo Why?
@@ -2622,10 +2757,11 @@  discard block
 block discarded – undo
2622 2757
 			if ($parent['level'] != 0)
2623 2758
 			{
2624 2759
 				// If we're already doing this one as a board, is this a higher last modified?
2625
-				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id])
2626
-					$lastModified[$id] = $lastModified[$id_board];
2627
-				elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board]))
2628
-					$parent_boards[$id] = $lastModified[$id_board];
2760
+				if (isset($lastModified[$id]) && $lastModified[$id_board] > $lastModified[$id]) {
2761
+									$lastModified[$id] = $lastModified[$id_board];
2762
+				} elseif (!isset($lastModified[$id]) && (!isset($parent_boards[$id]) || $parent_boards[$id] < $lastModified[$id_board])) {
2763
+									$parent_boards[$id] = $lastModified[$id_board];
2764
+				}
2629 2765
 			}
2630 2766
 		}
2631 2767
 	}
@@ -2638,23 +2774,24 @@  discard block
 block discarded – undo
2638 2774
 	// Finally, to save on queries make the changes...
2639 2775
 	foreach ($parent_boards as $id => $msg)
2640 2776
 	{
2641
-		if (!isset($parent_updates[$msg]))
2642
-			$parent_updates[$msg] = array($id);
2643
-		else
2644
-			$parent_updates[$msg][] = $id;
2777
+		if (!isset($parent_updates[$msg])) {
2778
+					$parent_updates[$msg] = array($id);
2779
+		} else {
2780
+					$parent_updates[$msg][] = $id;
2781
+		}
2645 2782
 	}
2646 2783
 
2647 2784
 	foreach ($lastMsg as $id => $msg)
2648 2785
 	{
2649
-		if (!isset($board_updates[$msg . '-' . $lastModified[$id]]))
2650
-			$board_updates[$msg . '-' . $lastModified[$id]] = array(
2786
+		if (!isset($board_updates[$msg . '-' . $lastModified[$id]])) {
2787
+					$board_updates[$msg . '-' . $lastModified[$id]] = array(
2651 2788
 				'id' => $msg,
2652 2789
 				'updated' => $lastModified[$id],
2653 2790
 				'boards' => array($id)
2654 2791
 			);
2655
-
2656
-		else
2657
-			$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2792
+		} else {
2793
+					$board_updates[$msg . '-' . $lastModified[$id]]['boards'][] = $id;
2794
+		}
2658 2795
 	}
2659 2796
 
2660 2797
 	// Now commit the changes!
@@ -2746,11 +2883,13 @@  discard block
 block discarded – undo
2746 2883
 	global $txt, $mbname, $scripturl, $settings;
2747 2884
 
2748 2885
 	// First things first, load up the email templates language file, if we need to.
2749
-	if ($loadLang)
2750
-		loadLanguage('EmailTemplates', $lang);
2886
+	if ($loadLang) {
2887
+			loadLanguage('EmailTemplates', $lang);
2888
+	}
2751 2889
 
2752
-	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
2753
-		fatal_lang_error('email_no_template', 'template', array($template));
2890
+	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body'])) {
2891
+			fatal_lang_error('email_no_template', 'template', array($template));
2892
+	}
2754 2893
 
2755 2894
 	$ret = array(
2756 2895
 		'subject' => $txt[$template . '_subject'],
@@ -2800,17 +2939,18 @@  discard block
 block discarded – undo
2800 2939
 function user_info_callback($matches)
2801 2940
 {
2802 2941
 	global $user_info;
2803
-	if (empty($matches[1]))
2804
-		return '';
2942
+	if (empty($matches[1])) {
2943
+			return '';
2944
+	}
2805 2945
 
2806 2946
 	$use_ref = true;
2807 2947
 	$ref = &$user_info;
2808 2948
 
2809 2949
 	foreach (explode('.', $matches[1]) as $index)
2810 2950
 	{
2811
-		if ($use_ref && isset($ref[$index]))
2812
-			$ref = &$ref[$index];
2813
-		else
2951
+		if ($use_ref && isset($ref[$index])) {
2952
+					$ref = &$ref[$index];
2953
+		} else
2814 2954
 		{
2815 2955
 			$use_ref = false;
2816 2956
 			break;
@@ -2847,8 +2987,7 @@  discard block
 block discarded – undo
2847 2987
 		if (!empty($lang_locale) && enchant_broker_dict_exists($context['enchant_broker'], $lang_locale))
2848 2988
 		{
2849 2989
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $lang_locale);
2850
-		}
2851
-		elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2990
+		} elseif (enchant_broker_dict_exists($context['enchant_broker'], $txt['lang_dictionary']))
2852 2991
 		{
2853 2992
 			$enchant_link = enchant_broker_request_dict($context['enchant_broker'], $txt['lang_dictionary']);
2854 2993
 		}
@@ -2858,8 +2997,7 @@  discard block
 block discarded – undo
2858 2997
 		{
2859 2998
 			$context['provider'] = 'enchant';
2860 2999
 			return $enchant_link;
2861
-		}
2862
-		else
3000
+		} else
2863 3001
 		{
2864 3002
 			// Free up any resources used...
2865 3003
 			@enchant_broker_free($context['enchant_broker']);
@@ -2880,8 +3018,9 @@  discard block
 block discarded – undo
2880 3018
 		$pspell_link = pspell_new($txt['lang_dictionary'], $txt['lang_spelling'], '', strtr($context['character_set'], array('iso-' => 'iso', 'ISO-' => 'iso')), PSPELL_FAST | PSPELL_RUN_TOGETHER);
2881 3019
 
2882 3020
 		// Most people don't have anything but English installed... So we use English as a last resort.
2883
-		if (!$pspell_link)
2884
-			$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3021
+		if (!$pspell_link) {
3022
+					$pspell_link = pspell_new('en', '', '', '', PSPELL_FAST | PSPELL_RUN_TOGETHER);
3023
+		}
2885 3024
 
2886 3025
 		error_reporting($old);
2887 3026
 		ob_end_clean();
@@ -2921,8 +3060,7 @@  discard block
 block discarded – undo
2921 3060
 			$word = iconv($txt['lang_character_set'], 'UTF-8', $word);
2922 3061
 		}
2923 3062
 		return enchant_dict_check($dict, $word);
2924
-	}
2925
-	elseif ($context['provider'] == 'pspell')
3063
+	} elseif ($context['provider'] == 'pspell')
2926 3064
 	{
2927 3065
 		return pspell_check($dict, $word);
2928 3066
 	}
@@ -2958,13 +3096,11 @@  discard block
 block discarded – undo
2958 3096
 			}
2959 3097
 
2960 3098
 			return $suggestions;
2961
-		}
2962
-		else
3099
+		} else
2963 3100
 		{
2964 3101
 			return enchant_dict_suggest($dict, $word);
2965 3102
 		}
2966
-	}
2967
-	elseif ($context['provider'] == 'pspell')
3103
+	} elseif ($context['provider'] == 'pspell')
2968 3104
 	{
2969 3105
 		return pspell_suggest($dict, $word);
2970 3106
 	}
Please login to merge, or discard this patch.