Completed
Pull Request — release-2.1 (#4490)
by 01
08:01
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) && !httpsOn())
599
-				fatal_lang_error('login_ssl_required');
620
+			if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
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 == 'None')
903
-			continue;
938
+		if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'None') {
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/DbExtra-mysql.php 1 patch
Braces   +66 added lines, -46 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
  * Add the functions implemented in this file to the $smcFunc array.
@@ -23,8 +24,8 @@  discard block
 block discarded – undo
23 24
 {
24 25
 	global $smcFunc;
25 26
 
26
-	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table')
27
-		$smcFunc += array(
27
+	if (!isset($smcFunc['db_backup_table']) || $smcFunc['db_backup_table'] != 'smf_db_backup_table') {
28
+			$smcFunc += array(
28 29
 			'db_backup_table' => 'smf_db_backup_table',
29 30
 			'db_optimize_table' => 'smf_db_optimize_table',
30 31
 			'db_table_sql' => 'smf_db_table_sql',
@@ -32,7 +33,8 @@  discard block
 block discarded – undo
32 33
 			'db_get_version' => 'smf_db_get_version',
33 34
 			'db_get_vendor' => 'smf_db_get_vendor',
34 35
 		);
35
-}
36
+	}
37
+	}
36 38
 
37 39
 /**
38 40
  * Backup $table to $backup_table.
@@ -74,8 +76,9 @@  discard block
 block discarded – undo
74 76
 			));
75 77
 
76 78
 		// Old school or no school?
77
-		if ($request)
78
-			return $request;
79
+		if ($request) {
80
+					return $request;
81
+		}
79 82
 	}
80 83
 
81 84
 	// At this point, the quick method failed.
@@ -99,8 +102,9 @@  discard block
 block discarded – undo
99 102
 	foreach ($create as $k => $l)
100 103
 	{
101 104
 		// Get the name of the auto_increment column.
102
-		if (strpos($l, 'auto_increment'))
103
-			$auto_inc = trim($l);
105
+		if (strpos($l, 'auto_increment')) {
106
+					$auto_inc = trim($l);
107
+		}
104 108
 
105 109
 		// For the engine type, see if we can work out what it is.
106 110
 		if (strpos($l, 'ENGINE') !== false || strpos($l, 'TYPE') !== false)
@@ -108,30 +112,36 @@  discard block
 block discarded – undo
108 112
 			// Extract the engine type.
109 113
 			preg_match('~(ENGINE|TYPE)=(\w+)(\sDEFAULT)?(\sCHARSET=(\w+))?(\sCOLLATE=(\w+))?~', $l, $match);
110 114
 
111
-			if (!empty($match[1]))
112
-				$engine = $match[1];
115
+			if (!empty($match[1])) {
116
+							$engine = $match[1];
117
+			}
113 118
 
114
-			if (!empty($match[2]))
115
-				$engine = $match[2];
119
+			if (!empty($match[2])) {
120
+							$engine = $match[2];
121
+			}
116 122
 
117
-			if (!empty($match[5]))
118
-				$charset = $match[5];
123
+			if (!empty($match[5])) {
124
+							$charset = $match[5];
125
+			}
119 126
 
120
-			if (!empty($match[7]))
121
-				$collate = $match[7];
127
+			if (!empty($match[7])) {
128
+							$collate = $match[7];
129
+			}
122 130
 		}
123 131
 
124 132
 		// Skip everything but keys...
125
-		if (strpos($l, 'KEY') === false)
126
-			unset($create[$k]);
133
+		if (strpos($l, 'KEY') === false) {
134
+					unset($create[$k]);
135
+		}
127 136
 	}
128 137
 
129
-	if (!empty($create))
130
-		$create = '(
138
+	if (!empty($create)) {
139
+			$create = '(
131 140
 			' . implode('
132 141
 			', $create) . ')';
133
-	else
134
-		$create = '';
142
+	} else {
143
+			$create = '';
144
+	}
135 145
 
136 146
 	$request = $smcFunc['db_query']('', '
137 147
 		CREATE TABLE {raw:backup_table} {raw:create}
@@ -150,8 +160,9 @@  discard block
 block discarded – undo
150 160
 
151 161
 	if ($auto_inc != '')
152 162
 	{
153
-		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',')
154
-			$auto_inc = substr($auto_inc, 0, -1);
163
+		if (preg_match('~\`(.+?)\`\s~', $auto_inc, $match) != 0 && substr($auto_inc, -1, 1) == ',') {
164
+					$auto_inc = substr($auto_inc, 0, -1);
165
+		}
155 166
 
156 167
 		$smcFunc['db_query']('', '
157 168
 			ALTER TABLE {raw:backup_table}
@@ -195,8 +206,9 @@  discard block
 block discarded – undo
195 206
 				'table' => $table,
196 207
 			)
197 208
 		);
198
-	if (!$request)
199
-		return -1;
209
+	if (!$request) {
210
+			return -1;
211
+	}
200 212
 
201 213
 	// How much left?
202 214
 	$request = $smcFunc['db_query']('', '
@@ -239,8 +251,9 @@  discard block
 block discarded – undo
239 251
 		)
240 252
 	);
241 253
 	$tables = array();
242
-	while ($row = $smcFunc['db_fetch_row']($request))
243
-		$tables[] = $row[0];
254
+	while ($row = $smcFunc['db_fetch_row']($request)) {
255
+			$tables[] = $row[0];
256
+	}
244 257
 	$smcFunc['db_free_result']($request);
245 258
 
246 259
 	return $tables;
@@ -284,8 +297,9 @@  discard block
 block discarded – undo
284 297
 		if (!empty($row['Default']) || $row['Null'] !== 'YES')
285 298
 		{
286 299
 			// Make a special case of auto-timestamp.
287
-			if ($row['Default'] == 'CURRENT_TIMESTAMP')
288
-				$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
300
+			if ($row['Default'] == 'CURRENT_TIMESTAMP') {
301
+							$schema_create .= ' /*!40102 NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP */';
302
+			}
289 303
 			// Text shouldn't have a default.
290 304
 			elseif ($row['Default'] !== null)
291 305
 			{
@@ -320,14 +334,16 @@  discard block
 block discarded – undo
320 334
 		$row['Key_name'] = $row['Key_name'] == 'PRIMARY' ? 'PRIMARY KEY' : (empty($row['Non_unique']) ? 'UNIQUE ' : ($row['Comment'] == 'FULLTEXT' || (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT') ? 'FULLTEXT ' : 'KEY ')) . '`' . $row['Key_name'] . '`';
321 335
 
322 336
 		// Is this the first column in the index?
323
-		if (empty($indexes[$row['Key_name']]))
324
-			$indexes[$row['Key_name']] = array();
337
+		if (empty($indexes[$row['Key_name']])) {
338
+					$indexes[$row['Key_name']] = array();
339
+		}
325 340
 
326 341
 		// A sub part, like only indexing 15 characters of a varchar.
327
-		if (!empty($row['Sub_part']))
328
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
329
-		else
330
-			$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
342
+		if (!empty($row['Sub_part'])) {
343
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`(' . $row['Sub_part'] . ')';
344
+		} else {
345
+					$indexes[$row['Key_name']][$row['Seq_in_index']] = '`' . $row['Column_name'] . '`';
346
+		}
331 347
 	}
332 348
 	$smcFunc['db_free_result']($result);
333 349
 
@@ -365,8 +381,9 @@  discard block
 block discarded – undo
365 381
 {
366 382
 	static $ver;
367 383
 
368
-	if (!empty($ver))
369
-		return $ver;
384
+	if (!empty($ver)) {
385
+			return $ver;
386
+	}
370 387
 
371 388
 	global $smcFunc;
372 389
 
@@ -391,8 +408,9 @@  discard block
 block discarded – undo
391 408
 	global $smcFunc;
392 409
 	static $db_type;
393 410
 
394
-	if (!empty($db_type))
395
-		return $db_type;
411
+	if (!empty($db_type)) {
412
+			return $db_type;
413
+	}
396 414
 
397 415
 	$request = $smcFunc['db_query']('', 'SELECT @@version_comment');
398 416
 	list ($comment) = $smcFunc['db_fetch_row']($request);
@@ -401,13 +419,15 @@  discard block
 block discarded – undo
401 419
 	// Skip these if we don't have a comment.
402 420
 	if (!empty($comment))
403 421
 	{
404
-		if (stripos($comment, 'percona') !== false)
405
-			return 'Percona';
406
-		if (stripos($comment, 'mariadb') !== false)
407
-			return 'MariaDB';
422
+		if (stripos($comment, 'percona') !== false) {
423
+					return 'Percona';
424
+		}
425
+		if (stripos($comment, 'mariadb') !== false) {
426
+					return 'MariaDB';
427
+		}
428
+	} else {
429
+			return 'fail';
408 430
 	}
409
-	else
410
-		return 'fail';
411 431
 
412 432
 	return 'MySQL';
413 433
 }
Please login to merge, or discard this patch.
other/Settings.php 1 patch
Braces   +13 added lines, -8 removed lines patch added patch discarded remove patch
@@ -186,8 +186,9 @@  discard block
 block discarded – undo
186 186
 
187 187
 ########## Error-Catching ##########
188 188
 # Note: You shouldn't touch these settings.
189
-if (file_exists(dirname(__FILE__) . '/db_last_error.php'))
189
+if (file_exists(dirname(__FILE__) . '/db_last_error.php')) {
190 190
 	include(dirname(__FILE__) . '/db_last_error.php');
191
+}
191 192
 
192 193
 if (!isset($db_last_error))
193 194
 {
@@ -199,20 +200,24 @@  discard block
 block discarded – undo
199 200
 if (file_exists(dirname(__FILE__) . '/install.php'))
200 201
 {
201 202
 	$secure = false;
202
-	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') 
203
-		$secure = true;
204
-	elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') 
205
-		$secure = true;
203
+	if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
204
+			$secure = true;
205
+	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
206
+			$secure = true;
207
+	}
206 208
 
207 209
 	header('Location: http' . ($secure ? 's' : '') . '://' . (empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']) . (strtr(dirname($_SERVER['PHP_SELF']), '\\', '/') == '/' ? '' : strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')) . '/install.php'); exit;
208 210
 }
209 211
 
210 212
 # Make sure the paths are correct... at least try to fix them.
211
-if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt'))
213
+if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) {
212 214
 	$boarddir = dirname(__FILE__);
213
-if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources'))
215
+}
216
+if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) {
214 217
 	$sourcedir = $boarddir . '/Sources';
215
-if (!file_exists($cachedir) && file_exists($boarddir . '/cache'))
218
+}
219
+if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) {
216 220
 	$cachedir = $boarddir . '/cache';
221
+}
217 222
 
218 223
 ?>
219 224
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/default/Memberlist.template.php 1 patch
Braces   +30 added lines, -20 removed lines patch added patch discarded remove patch
@@ -27,9 +27,10 @@  discard block
 block discarded – undo
27 27
 			<h3 class="catbg">
28 28
 				<span class="floatleft">', $txt['members_list'], '</span>';
29 29
 
30
-	if (!isset($context['old_search']))
31
-		echo '
30
+	if (!isset($context['old_search'])) {
31
+			echo '
32 32
 				<span class="floatright">', $context['letter_links'], '</span>';
33
+	}
33 34
 	echo '
34 35
 			</h3>
35 36
 		</div>';
@@ -44,20 +45,23 @@  discard block
 block discarded – undo
44 45
 	foreach ($context['columns'] as $key => $column)
45 46
 	{
46 47
 		// @TODO maybe find something nicer?
47
-		if ($key == 'email_address' && !$context['can_send_email'])
48
-			continue;
48
+		if ($key == 'email_address' && !$context['can_send_email']) {
49
+					continue;
50
+		}
49 51
 
50 52
 		// This is a selected column, so underline it or some such.
51
-		if ($column['selected'])
52
-			echo '
53
+		if ($column['selected']) {
54
+					echo '
53 55
 						<th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', ' selected" style="width: auto;"' . (isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '') . '>
54 56
 							<a href="' . $column['href'] . '" rel="nofollow">' . $column['label'] . '</a><span class="generic_icons sort_' . $context['sort_direction'] . '"></span></th>';
57
+		}
55 58
 
56 59
 		// This is just some column... show the link and be done with it.
57
-		else
58
-			echo '
60
+		else {
61
+					echo '
59 62
 						<th scope="col" class="', $key, isset($column['class']) ? ' ' . $column['class'] : '', '"', isset($column['width']) ? ' style="width: ' . $column['width'] . '"' : '', isset($column['colspan']) ? ' colspan="' . $column['colspan'] . '"' : '', '>
60 63
 						', $column['link'], '</th>';
64
+		}
61 65
 	}
62 66
 
63 67
 	echo '
@@ -77,9 +81,10 @@  discard block
 block discarded – undo
77 81
 						</td>
78 82
 						<td class="lefttext">', $member['link'], '</td>';
79 83
 
80
-			if (!isset($context['disabled_fields']['website']))
81
-				echo '
84
+			if (!isset($context['disabled_fields']['website'])) {
85
+							echo '
82 86
 						<td class="centertext website_url">', $member['website']['url'] != '' ? '<a href="' . $member['website']['url'] . '" target="_blank" rel="noopener"><span class="generic_icons www" title="' . $member['website']['title'] . '"></span></a>' : '', '</td>';
87
+			}
83 88
 
84 89
 			// Group and date.
85 90
 			echo '
@@ -92,32 +97,35 @@  discard block
 block discarded – undo
92 97
 						<td class="centertext" style="white-space: nowrap; width: 15px">', $member['posts'], '</td>
93 98
 						<td class="centertext statsbar" style="width: 120px">';
94 99
 
95
-				if (!empty($member['post_percent']))
96
-					echo '
100
+				if (!empty($member['post_percent'])) {
101
+									echo '
97 102
 							<div class="bar" style="width: ', $member['post_percent'] + 4, 'px;">
98 103
 								<div style="width: ', $member['post_percent'], 'px;"></div>
99 104
 							</div>';
105
+				}
100 106
 
101 107
 				echo '
102 108
 						</td>';
103 109
 			}
104 110
 
105 111
 			// Show custom fields marked to be shown here
106
-			if (!empty($context['custom_profile_fields']['columns']))
107
-				foreach ($context['custom_profile_fields']['columns'] as $key => $column)
112
+			if (!empty($context['custom_profile_fields']['columns'])) {
113
+							foreach ($context['custom_profile_fields']['columns'] as $key => $column)
108 114
 					echo '
109 115
 						<td class="righttext">', $member['options'][$key], '</td>';
116
+			}
110 117
 
111 118
 			echo '
112 119
 					</tr>';
113 120
 		}
114 121
 	}
115 122
 	// No members?
116
-	else
117
-		echo '
123
+	else {
124
+			echo '
118 125
 					<tr>
119 126
 						<td colspan="', $context['colspan'], '" class="windowbg">', $txt['search_no_results'], '</td>
120 127
 					</tr>';
128
+	}
121 129
 
122 130
 	echo '
123 131
 				</tbody>
@@ -130,11 +138,12 @@  discard block
 block discarded – undo
130 138
 			<div class="pagelinks floatleft">', $context['page_index'], '</div>';
131 139
 
132 140
 	// If it is displaying the result of a search show a "search again" link to edit their criteria.
133
-	if (isset($context['old_search']))
134
-		echo '
141
+	if (isset($context['old_search'])) {
142
+			echo '
135 143
 			<div class="buttonlist floatright">
136 144
 				<a class="button" href="', $scripturl, '?action=mlist;sa=search;search=', $context['old_search_value'], '">', $txt['mlist_search_again'], '</a>
137 145
 			</div>';
146
+	}
138 147
 	echo '
139 148
 		</div>
140 149
 	</div><!-- #memberlist -->';
@@ -174,12 +183,13 @@  discard block
 block discarded – undo
174 183
 					<dd>
175 184
 						<ul>';
176 185
 
177
-	foreach ($context['search_fields'] as $id => $title)
178
-		echo '
186
+	foreach ($context['search_fields'] as $id => $title) {
187
+			echo '
179 188
 							<li>
180 189
 								<input type="checkbox" name="fields[]" id="fields-', $id, '" value="', $id, '"', in_array($id, $context['search_defaults']) ? ' checked' : '', '>
181 190
 								<label for="fields-', $id, '">', $title, '</label>
182 191
 							</li>';
192
+	}
183 193
 
184 194
 	echo '
185 195
 						</ul>
Please login to merge, or discard this patch.
Sources/LogInOut.php 1 patch
Braces   +163 added lines, -127 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) && !httpsOn())
87
-		fatal_lang_error('login_ssl_required');
89
+	if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
90
+			fatal_lang_error('login_ssl_required');
91
+	}
88 92
 
89 93
 	// Load cookie authentication stuff.
90 94
 	require_once($sourcedir . '/Subs-Auth.php');
@@ -98,23 +102,26 @@  discard block
 block discarded – undo
98 102
 	if (isset($_GET['sa']) && $_GET['sa'] == 'salt' && !$user_info['is_guest'])
99 103
 	{
100 104
 		// First check for 2.1 json-format cookie in $_COOKIE
101
-		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1)
102
-			list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
105
+		if (isset($_COOKIE[$cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_COOKIE[$cookiename]) === 1) {
106
+					list (,, $timeout) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
107
+		}
103 108
 
104 109
 		// Try checking for 2.1 json-format cookie in $_SESSION
105
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1)
106
-			list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
110
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+~', $_SESSION['login_' . $cookiename]) === 1) {
111
+					list (,, $timeout) = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]);
112
+		}
107 113
 
108 114
 		// Next, try checking for 2.0 serialized string cookie in $_COOKIE
109
-		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1)
110
-			list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
115
+		elseif (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_COOKIE[$cookiename]) === 1) {
116
+					list (,, $timeout) = safe_unserialize($_COOKIE[$cookiename]);
117
+		}
111 118
 
112 119
 		// Last, see if you need to fall back on checking for 2.0 serialized string cookie in $_SESSION
113
-		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1)
114
-			list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
115
-
116
-		else
117
-			trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
120
+		elseif (isset($_SESSION['login_' . $cookiename]) && preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;~', $_SESSION['login_' . $cookiename]) === 1) {
121
+					list (,, $timeout) = safe_unserialize($_SESSION['login_' . $cookiename]);
122
+		} else {
123
+					trigger_error('Login2(): Cannot be logged in without a session or cookie', E_USER_ERROR);
124
+		}
118 125
 
119 126
 		$user_settings['password_salt'] = substr(md5(mt_rand()), 0, 4);
120 127
 		updateMemberData($user_info['id'], array('password_salt' => $user_settings['password_salt']));
@@ -127,10 +134,11 @@  discard block
 block discarded – undo
127 134
 			list ($tfamember, $tfasecret, $exp, $domain, $path, $preserve) = $tfadata;
128 135
 
129 136
 			// If we're preserving the cookie, reset it with updated salt
130
-			if (isset($tfamember, $tfasecret, $exp, $domain, $path, $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, '');
137
+			if (isset($tfamember, $tfasecret, $exp, $domain, $path, $preserve) && $preserve && time() < $exp) {
138
+							setTFACookie(3153600, $user_info['password_salt'], hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']), true);
139
+			} else {
140
+							setTFACookie(-3600, 0, '');
141
+			}
134 142
 		}
135 143
 
136 144
 		setLoginCookie($timeout - time(), $user_info['id'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
@@ -141,20 +149,20 @@  discard block
 block discarded – undo
141 149
 	elseif (isset($_GET['sa']) && $_GET['sa'] == 'check')
142 150
 	{
143 151
 		// Strike!  You're outta there!
144
-		if ($_GET['member'] != $user_info['id'])
145
-			fatal_lang_error('login_cookie_error', false);
152
+		if ($_GET['member'] != $user_info['id']) {
153
+					fatal_lang_error('login_cookie_error', false);
154
+		}
146 155
 
147 156
 		$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 157
 
149 158
 		// 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))
159
+		if (empty($_SESSION['login_url'])) {
160
+					redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
161
+		} elseif (!empty($_SESSION['login_url']) && (strpos($_SESSION['login_url'], 'http://') === false && strpos($_SESSION['login_url'], 'https://') === false))
153 162
 		{
154 163
 			unset ($_SESSION['login_url']);
155 164
 			redirectexit(empty($user_settings['tfa_secret']) ? '' : 'action=logintfa');
156
-		}
157
-		else
165
+		} else
158 166
 		{
159 167
 			// Best not to clutter the session data too much...
160 168
 			$temp = $_SESSION['login_url'];
@@ -165,8 +173,9 @@  discard block
 block discarded – undo
165 173
 	}
166 174
 
167 175
 	// Beyond this point you are assumed to be a guest trying to login.
168
-	if (!$user_info['is_guest'])
169
-		redirectexit();
176
+	if (!$user_info['is_guest']) {
177
+			redirectexit();
178
+	}
170 179
 
171 180
 	// Are you guessing with a script?
172 181
 	checkSession();
@@ -174,18 +183,21 @@  discard block
 block discarded – undo
174 183
 	spamProtection('login');
175 184
 
176 185
 	// 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'];
186
+	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)) {
187
+			$_SESSION['login_url'] = $_SESSION['old_url'];
188
+	}
179 189
 
180 190
 	// 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');
191
+	if (isset($_SESSION['failed_login']) && $_SESSION['failed_login'] >= $modSettings['failed_login_threshold'] * 3) {
192
+			fatal_lang_error('login_threshold_fail', 'login');
193
+	}
183 194
 
184 195
 	// 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'];
196
+	if (isset($_POST['cookieneverexp']) || (!empty($_POST['cookielength']) && $_POST['cookielength'] == -1)) {
197
+			$modSettings['cookieTime'] = 3153600;
198
+	} elseif (!empty($_POST['cookielength']) && ($_POST['cookielength'] >= 1 && $_POST['cookielength'] <= 525600)) {
199
+			$modSettings['cookieTime'] = (int) $_POST['cookielength'];
200
+	}
189 201
 
190 202
 	loadLanguage('Login');
191 203
 	// Load the template stuff.
@@ -305,8 +317,9 @@  discard block
 block discarded – undo
305 317
 			$other_passwords[] = crypt(md5($_POST['passwrd']), md5($_POST['passwrd']));
306 318
 
307 319
 			// 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']));
320
+			if (strlen($user_settings['passwd']) == 64 && function_exists('mhash') && defined('MHASH_SHA256')) {
321
+							$other_passwords[] = bin2hex(mhash(MHASH_SHA256, $_POST['passwrd']));
322
+			}
310 323
 
311 324
 			// phpBB3 users new hashing.  We now support it as well ;).
312 325
 			$other_passwords[] = phpBB3_password_check($_POST['passwrd'], $user_settings['passwd']);
@@ -326,27 +339,29 @@  discard block
 block discarded – undo
326 339
 			// Some common md5 ones.
327 340
 			$other_passwords[] = md5($user_settings['password_salt'] . $_POST['passwrd']);
328 341
 			$other_passwords[] = md5($_POST['passwrd'] . $user_settings['password_salt']);
329
-		}
330
-		elseif (strlen($user_settings['passwd']) == 40)
342
+		} elseif (strlen($user_settings['passwd']) == 40)
331 343
 		{
332 344
 			// Maybe they are using a hash from before the password fix.
333 345
 			// This is also valid for SMF 1.1 to 2.0 style of hashing, changed to bcrypt in SMF 2.1
334 346
 			$other_passwords[] = sha1(strtolower($user_settings['member_name']) . un_htmlspecialchars($_POST['passwrd']));
335 347
 
336 348
 			// 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'])));
349
+			if (!empty($modSettings['enable_password_conversion'])) {
350
+							$other_passwords[] = sha1($user_settings['password_salt'] . sha1($user_settings['password_salt'] . sha1($_POST['passwrd'])));
351
+			}
339 352
 
340 353
 			// Perhaps we converted to UTF-8 and have a valid password being hashed differently.
341 354
 			if ($context['character_set'] == 'UTF-8' && !empty($modSettings['previousCharacterSet']) && $modSettings['previousCharacterSet'] != 'utf8')
342 355
 			{
343 356
 				// 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'])));
357
+				if (function_exists('iconv')) {
358
+									$other_passwords['iconv'] = sha1(strtolower(iconv('UTF-8', $modSettings['previousCharacterSet'], $user_settings['member_name'])) . un_htmlspecialchars(iconv('UTF-8', $modSettings['previousCharacterSet'], $_POST['passwrd'])));
359
+				}
346 360
 
347 361
 				// 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'])));
362
+				if (empty($other_passwords['iconv']) && function_exists('mb_convert_encoding')) {
363
+									$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'])));
364
+				}
350 365
 			}
351 366
 		}
352 367
 
@@ -376,8 +391,9 @@  discard block
 block discarded – undo
376 391
 			$_SESSION['failed_login'] = isset($_SESSION['failed_login']) ? ($_SESSION['failed_login'] + 1) : 1;
377 392
 
378 393
 			// 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');
394
+			if ($_SESSION['failed_login'] >= $modSettings['failed_login_threshold']) {
395
+							redirectexit('action=reminder');
396
+			}
381 397
 			// We'll give you another chance...
382 398
 			else
383 399
 			{
@@ -388,8 +404,7 @@  discard block
 block discarded – undo
388 404
 				return;
389 405
 			}
390 406
 		}
391
-	}
392
-	elseif (!empty($user_settings['passwd_flood']))
407
+	} elseif (!empty($user_settings['passwd_flood']))
393 408
 	{
394 409
 		// Let's be sure they weren't a little hacker.
395 410
 		validatePasswordFlood($user_settings['id_member'], $user_settings['member_name'], $user_settings['passwd_flood'], true);
@@ -406,8 +421,9 @@  discard block
 block discarded – undo
406 421
 	}
407 422
 
408 423
 	// Check their activation status.
409
-	if (!checkActivation())
410
-		return;
424
+	if (!checkActivation()) {
425
+			return;
426
+	}
411 427
 
412 428
 	DoLogin();
413 429
 }
@@ -419,8 +435,9 @@  discard block
 block discarded – undo
419 435
 {
420 436
 	global $sourcedir, $txt, $context, $user_info, $modSettings, $scripturl;
421 437
 
422
-	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode']))
423
-		fatal_lang_error('no_access', false);
438
+	if (!$user_info['is_guest'] || empty($context['tfa_member']) || empty($modSettings['tfa_mode'])) {
439
+			fatal_lang_error('no_access', false);
440
+	}
424 441
 
425 442
 	loadLanguage('Profile');
426 443
 	require_once($sourcedir . '/Class-TOTP.php');
@@ -428,8 +445,9 @@  discard block
 block discarded – undo
428 445
 	$member = $context['tfa_member'];
429 446
 
430 447
 	// 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);
448
+	if (time() - $member['last_login'] < 120) {
449
+			fatal_lang_error('tfa_wait', false);
450
+	}
433 451
 
434 452
 	$totp = new \TOTP\Auth($member['tfa_secret']);
435 453
 	$totp->setRange(1);
@@ -443,8 +461,9 @@  discard block
 block discarded – undo
443 461
 	if (!empty($_POST['tfa_code']) && empty($_POST['tfa_backup']))
444 462
 	{
445 463
 		// Check to ensure we're forcing SSL for authentication
446
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
447
-			fatal_lang_error('login_ssl_required');
464
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
465
+					fatal_lang_error('login_ssl_required');
466
+		}
448 467
 
449 468
 		$code = $_POST['tfa_code'];
450 469
 
@@ -454,20 +473,19 @@  discard block
 block discarded – undo
454 473
 
455 474
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']), !empty($_POST['tfa_preserve']));
456 475
 			redirectexit();
457
-		}
458
-		else
476
+		} else
459 477
 		{
460 478
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
461 479
 
462 480
 			$context['tfa_error'] = true;
463 481
 			$context['tfa_value'] = $_POST['tfa_code'];
464 482
 		}
465
-	}
466
-	elseif (!empty($_POST['tfa_backup']))
483
+	} elseif (!empty($_POST['tfa_backup']))
467 484
 	{
468 485
 		// Check to ensure we're forcing SSL for authentication
469
-		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn())
470
-			fatal_lang_error('login_ssl_required');
486
+		if (!empty($modSettings['force_ssl']) && empty($maintenance) && !httpsOn()) {
487
+					fatal_lang_error('login_ssl_required');
488
+		}
471 489
 
472 490
 		$backup = $_POST['tfa_backup'];
473 491
 
@@ -481,8 +499,7 @@  discard block
 block discarded – undo
481 499
 			));
482 500
 			setTFACookie(3153600, $member['id_member'], hash_salt($member['tfa_backup'], $member['password_salt']));
483 501
 			redirectexit('action=profile;area=tfasetup;backup');
484
-		}
485
-		else
502
+		} else
486 503
 		{
487 504
 			validatePasswordFlood($member['id_member'], $member['member_name'], $member['passwd_flood'], false, true);
488 505
 
@@ -505,8 +522,9 @@  discard block
 block discarded – undo
505 522
 {
506 523
 	global $context, $txt, $scripturl, $user_settings, $modSettings;
507 524
 
508
-	if (!isset($context['login_errors']))
509
-		$context['login_errors'] = array();
525
+	if (!isset($context['login_errors'])) {
526
+			$context['login_errors'] = array();
527
+	}
510 528
 
511 529
 	// What is the true activation status of this account?
512 530
 	$activation_status = $user_settings['is_activated'] > 10 ? $user_settings['is_activated'] - 10 : $user_settings['is_activated'];
@@ -518,8 +536,9 @@  discard block
 block discarded – undo
518 536
 		return false;
519 537
 	}
520 538
 	// Awaiting approval still?
521
-	elseif ($activation_status == 3)
522
-		fatal_lang_error('still_awaiting_approval', 'user');
539
+	elseif ($activation_status == 3) {
540
+			fatal_lang_error('still_awaiting_approval', 'user');
541
+	}
523 542
 	// Awaiting deletion, changed their mind?
524 543
 	elseif ($activation_status == 4)
525 544
 	{
@@ -527,8 +546,7 @@  discard block
 block discarded – undo
527 546
 		{
528 547
 			updateMemberData($user_settings['id_member'], array('is_activated' => 1));
529 548
 			updateSettings(array('unapprovedMembers' => ($modSettings['unapprovedMembers'] > 0 ? $modSettings['unapprovedMembers'] - 1 : 0)));
530
-		}
531
-		else
549
+		} else
532 550
 		{
533 551
 			$context['disable_login_hashing'] = true;
534 552
 			$context['login_errors'][] = $txt['awaiting_delete_account'];
@@ -568,8 +586,9 @@  discard block
 block discarded – undo
568 586
 	setLoginCookie(60 * $modSettings['cookieTime'], $user_settings['id_member'], hash_salt($user_settings['passwd'], $user_settings['password_salt']));
569 587
 
570 588
 	// Reset the login threshold.
571
-	if (isset($_SESSION['failed_login']))
572
-		unset($_SESSION['failed_login']);
589
+	if (isset($_SESSION['failed_login'])) {
590
+			unset($_SESSION['failed_login']);
591
+	}
573 592
 
574 593
 	$user_info['is_guest'] = false;
575 594
 	$user_settings['additional_groups'] = explode(',', $user_settings['additional_groups']);
@@ -591,16 +610,18 @@  discard block
 block discarded – undo
591 610
 			'id_member' => $user_info['id'],
592 611
 		)
593 612
 	);
594
-	if ($smcFunc['db_num_rows']($request) == 1)
595
-		$_SESSION['first_login'] = true;
596
-	else
597
-		unset($_SESSION['first_login']);
613
+	if ($smcFunc['db_num_rows']($request) == 1) {
614
+			$_SESSION['first_login'] = true;
615
+	} else {
616
+			unset($_SESSION['first_login']);
617
+	}
598 618
 	$smcFunc['db_free_result']($request);
599 619
 
600 620
 	// You've logged in, haven't you?
601 621
 	$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();
622
+	if (empty($user_settings['tfa_secret'])) {
623
+			$update['last_login'] = time();
624
+	}
604 625
 	updateMemberData($user_info['id'], $update);
605 626
 
606 627
 	// Get rid of the online entry for that old guest....
@@ -614,8 +635,8 @@  discard block
 block discarded – undo
614 635
 	$_SESSION['log_time'] = 0;
615 636
 
616 637
 	// Log this entry, only if we have it enabled.
617
-	if (!empty($modSettings['loginHistoryDays']))
618
-		$smcFunc['db_insert']('insert',
638
+	if (!empty($modSettings['loginHistoryDays'])) {
639
+			$smcFunc['db_insert']('insert',
619 640
 			'{db_prefix}member_logins',
620 641
 			array(
621 642
 				'id_member' => 'int', 'time' => 'int', 'ip' => 'inet', 'ip2' => 'inet',
@@ -627,13 +648,15 @@  discard block
 block discarded – undo
627 648
 				'id_member', 'time'
628 649
 			)
629 650
 		);
651
+	}
630 652
 
631 653
 	// 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
-}
654
+	if (empty($maintenance) || allowedTo('admin_forum')) {
655
+			redirectexit('action=login2;sa=check;member=' . $user_info['id'], $context['server']['needs_login_fix']);
656
+	} else {
657
+			redirectexit('action=logout;' . $context['session_var'] . '=' . $context['session_id'], $context['server']['needs_login_fix']);
658
+	}
659
+	}
637 660
 
638 661
 /**
639 662
  * Logs the current user out of their account.
@@ -649,13 +672,15 @@  discard block
 block discarded – undo
649 672
 	global $sourcedir, $user_info, $user_settings, $context, $smcFunc, $cookiename, $modSettings;
650 673
 
651 674
 	// Make sure they aren't being auto-logged out.
652
-	if (!$internal)
653
-		checkSession('get');
675
+	if (!$internal) {
676
+			checkSession('get');
677
+	}
654 678
 
655 679
 	require_once($sourcedir . '/Subs-Auth.php');
656 680
 
657
-	if (isset($_SESSION['pack_ftp']))
658
-		$_SESSION['pack_ftp'] = null;
681
+	if (isset($_SESSION['pack_ftp'])) {
682
+			$_SESSION['pack_ftp'] = null;
683
+	}
659 684
 
660 685
 	// It won't be first login anymore.
661 686
 	unset($_SESSION['first_login']);
@@ -683,8 +708,9 @@  discard block
 block discarded – undo
683 708
 
684 709
 	// And some other housekeeping while we're at it.
685 710
 	$salt = substr(md5(mt_rand()), 0, 4);
686
-	if (!empty($user_info['id']))
687
-		updateMemberData($user_info['id'], array('password_salt' => $salt));
711
+	if (!empty($user_info['id'])) {
712
+			updateMemberData($user_info['id'], array('password_salt' => $salt));
713
+	}
688 714
 
689 715
 	if (!empty($modSettings['tfa_mode']) && !empty($user_info['id']) && !empty($_COOKIE[$cookiename . '_tfa']))
690 716
 	{
@@ -693,10 +719,11 @@  discard block
 block discarded – undo
693 719
 		list ($tfamember, $tfasecret, $exp, $domain, $path, $preserve) = $tfadata;
694 720
 
695 721
 		// If we're preserving the cookie, reset it with updated salt
696
-		if (isset($tfamember, $tfasecret, $exp, $domain, $path, $preserve) && $preserve && time() < $exp)
697
-			setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
698
-		else
699
-			setTFACookie(-3600, 0, '');
722
+		if (isset($tfamember, $tfasecret, $exp, $domain, $path, $preserve) && $preserve && time() < $exp) {
723
+					setTFACookie(3153600, $user_info['id'], hash_salt($user_settings['tfa_backup'], $salt), true);
724
+		} else {
725
+					setTFACookie(-3600, 0, '');
726
+		}
700 727
 	}
701 728
 
702 729
 	session_destroy();
@@ -704,14 +731,13 @@  discard block
 block discarded – undo
704 731
 	// Off to the merry board index we go!
705 732
 	if ($redirect)
706 733
 	{
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))
734
+		if (empty($_SESSION['logout_url'])) {
735
+					redirectexit('', $context['server']['needs_login_fix']);
736
+		} elseif (!empty($_SESSION['logout_url']) && (strpos($_SESSION['logout_url'], 'http://') === false && strpos($_SESSION['logout_url'], 'https://') === false))
710 737
 		{
711 738
 			unset ($_SESSION['logout_url']);
712 739
 			redirectexit();
713
-		}
714
-		else
740
+		} else
715 741
 		{
716 742
 			$temp = $_SESSION['logout_url'];
717 743
 			unset($_SESSION['logout_url']);
@@ -744,8 +770,9 @@  discard block
 block discarded – undo
744 770
 function phpBB3_password_check($passwd, $passwd_hash)
745 771
 {
746 772
 	// Too long or too short?
747
-	if (strlen($passwd_hash) != 34)
748
-		return;
773
+	if (strlen($passwd_hash) != 34) {
774
+			return;
775
+	}
749 776
 
750 777
 	// Range of characters allowed.
751 778
 	$range = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@@ -756,8 +783,9 @@  discard block
 block discarded – undo
756 783
 	$salt = substr($passwd_hash, 4, 8);
757 784
 
758 785
 	$hash = md5($salt . $passwd, true);
759
-	for (; $count != 0; --$count)
760
-		$hash = md5($hash . $passwd, true);
786
+	for (; $count != 0; --$count) {
787
+			$hash = md5($hash . $passwd, true);
788
+	}
761 789
 
762 790
 	$output = substr($passwd_hash, 0, 12);
763 791
 	$i = 0;
@@ -766,21 +794,25 @@  discard block
 block discarded – undo
766 794
 		$value = ord($hash[$i++]);
767 795
 		$output .= $range[$value & 0x3f];
768 796
 
769
-		if ($i < 16)
770
-			$value |= ord($hash[$i]) << 8;
797
+		if ($i < 16) {
798
+					$value |= ord($hash[$i]) << 8;
799
+		}
771 800
 
772 801
 		$output .= $range[($value >> 6) & 0x3f];
773 802
 
774
-		if ($i++ >= 16)
775
-			break;
803
+		if ($i++ >= 16) {
804
+					break;
805
+		}
776 806
 
777
-		if ($i < 16)
778
-			$value |= ord($hash[$i]) << 16;
807
+		if ($i < 16) {
808
+					$value |= ord($hash[$i]) << 16;
809
+		}
779 810
 
780 811
 		$output .= $range[($value >> 12) & 0x3f];
781 812
 
782
-		if ($i++ >= 16)
783
-			break;
813
+		if ($i++ >= 16) {
814
+					break;
815
+		}
784 816
 
785 817
 		$output .= $range[($value >> 18) & 0x3f];
786 818
 	}
@@ -812,8 +844,9 @@  discard block
 block discarded – undo
812 844
 		require_once($sourcedir . '/Subs-Auth.php');
813 845
 		setLoginCookie(-3600, 0);
814 846
 
815
-		if (isset($_SESSION['login_' . $cookiename]))
816
-			unset($_SESSION['login_' . $cookiename]);
847
+		if (isset($_SESSION['login_' . $cookiename])) {
848
+					unset($_SESSION['login_' . $cookiename]);
849
+		}
817 850
 	}
818 851
 
819 852
 	// We need a member!
@@ -827,8 +860,9 @@  discard block
 block discarded – undo
827 860
 	}
828 861
 
829 862
 	// Right, have we got a flood value?
830
-	if ($password_flood_value !== false)
831
-		@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
863
+	if ($password_flood_value !== false) {
864
+			@list ($time_stamp, $number_tries) = explode('|', $password_flood_value);
865
+	}
832 866
 
833 867
 	// Timestamp or number of tries invalid?
834 868
 	if (empty($number_tries) || empty($time_stamp))
@@ -844,15 +878,17 @@  discard block
 block discarded – undo
844 878
 		$number_tries = $time_stamp < time() - 20 ? 2 : $number_tries;
845 879
 
846 880
 		// They are trying too fast, make them wait longer
847
-		if ($time_stamp < time() - 10)
848
-			$time_stamp = time();
881
+		if ($time_stamp < time() - 10) {
882
+					$time_stamp = time();
883
+		}
849 884
 	}
850 885
 
851 886
 	$number_tries++;
852 887
 
853 888
 	// Broken the law?
854
-	if ($number_tries > 5)
855
-		fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
889
+	if ($number_tries > 5) {
890
+			fatal_lang_error('login_threshold_brute_fail', 'login', [$member_name]);
891
+	}
856 892
 
857 893
 	// Otherwise set the members data. If they correct on their first attempt then we actually clear it, otherwise we set it!
858 894
 	updateMemberData($id_member, array('passwd_flood' => $was_correct && $number_tries == 1 ? '' : $time_stamp . '|' . $number_tries));
Please login to merge, or discard this patch.
Sources/Subs-Auth.php 1 patch
Braces   +168 added lines, -121 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
  * Sets the SMF-style login cookie and session based on the id_member and password passed.
@@ -45,8 +46,9 @@  discard block
 block discarded – undo
45 46
 	if (isset($_COOKIE[$cookiename]))
46 47
 	{
47 48
 		// First check for 2.1 json-format cookie
48
-		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1)
49
-			list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
49
+		if (preg_match('~^{"0":\d+,"1":"[0-9a-f]*","2":\d+,"3":"[^"]+","4":"[^"]+"~', $_COOKIE[$cookiename]) === 1) {
50
+					list(,,, $old_domain, $old_path) = $smcFunc['json_decode']($_COOKIE[$cookiename], true);
51
+		}
50 52
 
51 53
 		// Legacy format (for recent 2.0 --> 2.1 upgrades)
52 54
 		elseif (preg_match('~^a:[34]:\{i:0;i:\d+;i:1;s:(0|128):"([a-fA-F0-9]{128})?";i:2;[id]:\d+;(i:3;i:\d;)?~', $_COOKIE[$cookiename]) === 1)
@@ -56,15 +58,17 @@  discard block
 block discarded – undo
56 58
 			$cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2);
57 59
 
58 60
 			// Maybe we need to temporarily pretend to be using local cookies
59
-			if ($cookie_state == 0 && $old_state == 1)
60
-				list($old_domain, $old_path) = url_parts(true, false);
61
-			else
62
-				list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
61
+			if ($cookie_state == 0 && $old_state == 1) {
62
+							list($old_domain, $old_path) = url_parts(true, false);
63
+			} else {
64
+							list($old_domain, $old_path) = url_parts($old_state & 1 > 0, $old_state & 2 > 0);
65
+			}
63 66
 		}
64 67
 
65 68
 		// Out with the old, in with the new!
66
-		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1])
67
-			smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
69
+		if (isset($old_domain) && $old_domain != $cookie_url[0] || isset($old_path) && $old_path != $cookie_url[1]) {
70
+					smf_setcookie($cookiename, $smcFunc['json_encode'](array(0, '', 0, $old_domain, $old_path), JSON_FORCE_OBJECT), 1, $old_path, $old_domain);
71
+		}
68 72
 	}
69 73
 
70 74
 	// Get the data and path to set it on.
@@ -80,8 +84,9 @@  discard block
 block discarded – undo
80 84
 	smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], $cookie_url[0]);
81 85
 
82 86
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
83
-	if (empty($id) && !empty($modSettings['globalCookies']))
84
-		smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
87
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
88
+			smf_setcookie($cookiename, $data, $expiry_time, $cookie_url[1], '');
89
+	}
85 90
 
86 91
 	// Any alias URLs?  This is mainly for use with frames, etc.
87 92
 	if (!empty($modSettings['forum_alias_urls']))
@@ -97,8 +102,9 @@  discard block
 block discarded – undo
97 102
 
98 103
 			$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
99 104
 
100
-			if ($cookie_url[0] == '')
101
-				$cookie_url[0] = strtok($alias, '/');
105
+			if ($cookie_url[0] == '') {
106
+							$cookie_url[0] = strtok($alias, '/');
107
+			}
102 108
 
103 109
 			$alias_data = $smcFunc['json_decode']($data);
104 110
 			$alias_data[3] = $cookie_url[0];
@@ -149,8 +155,9 @@  discard block
 block discarded – undo
149 155
 	$identifier = $cookiename . '_tfa';
150 156
 	$cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
151 157
 
152
-	if ($preserve)
153
-		$cookie_length = 81600 * 30;
158
+	if ($preserve) {
159
+			$cookie_length = 81600 * 30;
160
+	}
154 161
 
155 162
 	// Get the data and path to set it on.
156 163
 	$data = $smcFunc['json_encode'](empty($id) ? array(0, '', 0, $cookie_url[0], $cookie_url[1], false) : array($id, $secret, time() + $cookie_length, $cookie_url[0], $cookie_url[1], $preserve), JSON_FORCE_OBJECT);
@@ -159,8 +166,9 @@  discard block
 block discarded – undo
159 166
 	smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]);
160 167
 
161 168
 	// If subdomain-independent cookies are on, unset the subdomain-dependent cookie too.
162
-	if (empty($id) && !empty($modSettings['globalCookies']))
163
-		smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
169
+	if (empty($id) && !empty($modSettings['globalCookies'])) {
170
+			smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], '');
171
+	}
164 172
 
165 173
 	$_COOKIE[$identifier] = $data;
166 174
 }
@@ -182,23 +190,28 @@  discard block
 block discarded – undo
182 190
 	$parsed_url = parse_url($boardurl);
183 191
 
184 192
 	// Is local cookies off?
185
-	if (empty($parsed_url['path']) || !$local)
186
-		$parsed_url['path'] = '';
193
+	if (empty($parsed_url['path']) || !$local) {
194
+			$parsed_url['path'] = '';
195
+	}
187 196
 
188
-	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false)
189
-		$parsed_url['host'] = $modSettings['globalCookiesDomain'];
197
+	if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) {
198
+			$parsed_url['host'] = $modSettings['globalCookiesDomain'];
199
+	}
190 200
 
191 201
 	// Globalize cookies across domains (filter out IP-addresses)?
192
-	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1)
193
-		$parsed_url['host'] = '.' . $parts[1];
202
+	elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) {
203
+			$parsed_url['host'] = '.' . $parts[1];
204
+	}
194 205
 
195 206
 	// We shouldn't use a host at all if both options are off.
196
-	elseif (!$local && !$global)
197
-		$parsed_url['host'] = '';
207
+	elseif (!$local && !$global) {
208
+			$parsed_url['host'] = '';
209
+	}
198 210
 
199 211
 	// The host also shouldn't be set if there aren't any dots in it.
200
-	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false)
201
-		$parsed_url['host'] = '';
212
+	elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) {
213
+			$parsed_url['host'] = '';
214
+	}
202 215
 
203 216
 	return array($parsed_url['host'], $parsed_url['path'] . '/');
204 217
 }
@@ -217,8 +230,9 @@  discard block
 block discarded – undo
217 230
 	createToken('login');
218 231
 
219 232
 	// Never redirect to an attachment
220
-	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false)
221
-		$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
233
+	if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) {
234
+			$_SESSION['login_url'] = $_SERVER['REQUEST_URL'];
235
+	}
222 236
 
223 237
 	$context['sub_template'] = 'kick_guest';
224 238
 	$context['page_title'] = $txt['login'];
@@ -273,10 +287,12 @@  discard block
 block discarded – undo
273 287
 		$txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']);
274 288
 		log_error($txt['security_wrong'], 'critical');
275 289
 
276
-		if (isset($_POST[$type . '_hash_pass']))
277
-			unset($_POST[$type . '_hash_pass']);
278
-		if (isset($_POST[$type . '_pass']))
279
-			unset($_POST[$type . '_pass']);
290
+		if (isset($_POST[$type . '_hash_pass'])) {
291
+					unset($_POST[$type . '_hash_pass']);
292
+		}
293
+		if (isset($_POST[$type . '_pass'])) {
294
+					unset($_POST[$type . '_pass']);
295
+		}
280 296
 
281 297
 		$context['incorrect_password'] = true;
282 298
 	}
@@ -289,15 +305,17 @@  discard block
 block discarded – undo
289 305
 
290 306
 	// Now go through $_POST.  Make sure the session hash is sent.
291 307
 	$_POST[$context['session_var']] = $context['session_id'];
292
-	foreach ($_POST as $k => $v)
293
-		$context['post_data'] .= adminLogin_outputPostVars($k, $v);
308
+	foreach ($_POST as $k => $v) {
309
+			$context['post_data'] .= adminLogin_outputPostVars($k, $v);
310
+	}
294 311
 
295 312
 	// Now we'll use the admin_login sub template of the Login template.
296 313
 	$context['sub_template'] = 'admin_login';
297 314
 
298 315
 	// And title the page something like "Login".
299
-	if (!isset($context['page_title']))
300
-		$context['page_title'] = $txt['login'];
316
+	if (!isset($context['page_title'])) {
317
+			$context['page_title'] = $txt['login'];
318
+	}
301 319
 
302 320
 	// The type of action.
303 321
 	$context['sessionCheckType'] = $type;
@@ -320,14 +338,15 @@  discard block
 block discarded – undo
320 338
 {
321 339
 	global $smcFunc;
322 340
 
323
-	if (!is_array($v))
324
-		return '
341
+	if (!is_array($v)) {
342
+			return '
325 343
 <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '&quot;', '<' => '&lt;', '>' => '&gt;')) . '">';
326
-	else
344
+	} else
327 345
 	{
328 346
 		$ret = '';
329
-		foreach ($v as $k2 => $v2)
330
-			$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
347
+		foreach ($v as $k2 => $v2) {
348
+					$ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2);
349
+		}
331 350
 
332 351
 		return $ret;
333 352
 	}
@@ -354,18 +373,20 @@  discard block
 block discarded – undo
354 373
 		foreach ($get as $k => $v)
355 374
 		{
356 375
 			// Only if it's not already in the $scripturl!
357
-			if (!isset($temp[$k]))
358
-				$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
376
+			if (!isset($temp[$k])) {
377
+							$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
378
+			}
359 379
 			// If it changed, put it out there, but with an ampersand.
360
-			elseif ($temp[$k] != $get[$k])
361
-				$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
380
+			elseif ($temp[$k] != $get[$k]) {
381
+							$query_string .= urlencode($k) . '=' . urlencode($v) . '&amp;';
382
+			}
362 383
 		}
363
-	}
364
-	else
384
+	} else
365 385
 	{
366 386
 		// Add up all the data from $_GET into get_data.
367
-		foreach ($get as $k => $v)
368
-			$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
387
+		foreach ($get as $k => $v) {
388
+					$query_string .= urlencode($k) . '=' . urlencode($v) . ';';
389
+		}
369 390
 	}
370 391
 
371 392
 	$query_string = substr($query_string, 0, -1);
@@ -388,8 +409,9 @@  discard block
 block discarded – undo
388 409
 	global $scripturl, $user_info, $smcFunc;
389 410
 
390 411
 	// If it's not already an array, make it one.
391
-	if (!is_array($names))
392
-		$names = explode(',', $names);
412
+	if (!is_array($names)) {
413
+			$names = explode(',', $names);
414
+	}
393 415
 
394 416
 	$maybe_email = false;
395 417
 	foreach ($names as $i => $name)
@@ -400,10 +422,11 @@  discard block
 block discarded – undo
400 422
 		$maybe_email |= strpos($name, '@') !== false;
401 423
 
402 424
 		// Make it so standard wildcards will work. (* and ?)
403
-		if ($use_wildcards)
404
-			$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
405
-		else
406
-			$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
425
+		if ($use_wildcards) {
426
+					$names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => '&#039;'));
427
+		} else {
428
+					$names[$i] = strtr($names[$i], array('\'' => '&#039;'));
429
+		}
407 430
 	}
408 431
 
409 432
 	// What are we using to compare?
@@ -413,11 +436,12 @@  discard block
 block discarded – undo
413 436
 	$results = array();
414 437
 
415 438
 	// This ensures you can't search someones email address if you can't see it.
416
-	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum'))
417
-		$email_condition = '
439
+	if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) {
440
+			$email_condition = '
418 441
 			OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')';
419
-	else
420
-		$email_condition = '';
442
+	} else {
443
+			$email_condition = '';
444
+	}
421 445
 
422 446
 	// Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise.
423 447
 	$member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name';
@@ -475,10 +499,11 @@  discard block
 block discarded – undo
475 499
 	$context['template_layers'] = array();
476 500
 	$context['sub_template'] = 'find_members';
477 501
 
478
-	if (isset($_REQUEST['search']))
479
-		$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
480
-	else
481
-		$_REQUEST['start'] = 0;
502
+	if (isset($_REQUEST['search'])) {
503
+			$context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES);
504
+	} else {
505
+			$_REQUEST['start'] = 0;
506
+	}
482 507
 
483 508
 	// Allow the user to pass the input to be added to to the box.
484 509
 	$context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to';
@@ -519,10 +544,10 @@  discard block
 block discarded – undo
519 544
 		);
520 545
 
521 546
 		$context['results'] = array_slice($context['results'], $_REQUEST['start'], 7);
547
+	} else {
548
+			$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
549
+	}
522 550
 	}
523
-	else
524
-		$context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']);
525
-}
526 551
 
527 552
 /**
528 553
  * Outputs each member name on its own line.
@@ -538,8 +563,9 @@  discard block
 block discarded – undo
538 563
 	$_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search']));
539 564
 	$_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&#038;' => '&amp;'));
540 565
 
541
-	if (function_exists('iconv'))
542
-		header('Content-Type: text/plain; charset=UTF-8');
566
+	if (function_exists('iconv')) {
567
+			header('Content-Type: text/plain; charset=UTF-8');
568
+	}
543 569
 
544 570
 	$request = $smcFunc['db_query']('', '
545 571
 		SELECT real_name
@@ -559,14 +585,16 @@  discard block
 block discarded – undo
559 585
 		if (function_exists('iconv'))
560 586
 		{
561 587
 			$utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']);
562
-			if ($utf8)
563
-				$row['real_name'] = $utf8;
588
+			if ($utf8) {
589
+							$row['real_name'] = $utf8;
590
+			}
564 591
 		}
565 592
 
566 593
 		$row['real_name'] = strtr($row['real_name'], array('&amp;' => '&#038;', '&lt;' => '&#060;', '&gt;' => '&#062;', '&quot;' => '&#034;'));
567 594
 
568
-		if (preg_match('~&#\d+;~', $row['real_name']) != 0)
569
-			$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
595
+		if (preg_match('~&#\d+;~', $row['real_name']) != 0) {
596
+					$row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']);
597
+		}
570 598
 
571 599
 		echo $row['real_name'], "\n";
572 600
 	}
@@ -623,9 +651,9 @@  discard block
 block discarded – undo
623 651
 
624 652
 		// Update the database...
625 653
 		updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1));
654
+	} else {
655
+			updateMemberData($memID, array('passwd' => $newPassword_sha1));
626 656
 	}
627
-	else
628
-		updateMemberData($memID, array('passwd' => $newPassword_sha1));
629 657
 
630 658
 	call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword));
631 659
 
@@ -656,31 +684,37 @@  discard block
 block discarded – undo
656 684
 	$errors = array();
657 685
 
658 686
 	// Don't use too long a name.
659
-	if ($smcFunc['strlen']($username) > 25)
660
-		$errors[] = array('lang', 'error_long_name');
687
+	if ($smcFunc['strlen']($username) > 25) {
688
+			$errors[] = array('lang', 'error_long_name');
689
+	}
661 690
 
662 691
 	// No name?!  How can you register with no name?
663
-	if ($username == '')
664
-		$errors[] = array('lang', 'need_username');
692
+	if ($username == '') {
693
+			$errors[] = array('lang', 'need_username');
694
+	}
665 695
 
666 696
 	// Only these characters are permitted.
667
-	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false)
668
-		$errors[] = array('lang', 'error_invalid_characters_username');
697
+	if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) {
698
+			$errors[] = array('lang', 'error_invalid_characters_username');
699
+	}
669 700
 
670
-	if (stristr($username, $txt['guest_title']) !== false)
671
-		$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
701
+	if (stristr($username, $txt['guest_title']) !== false) {
702
+			$errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));
703
+	}
672 704
 
673 705
 	if ($check_reserved_name)
674 706
 	{
675 707
 		require_once($sourcedir . '/Subs-Members.php');
676
-		if (isReservedName($username, $memID, false))
677
-			$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
708
+		if (isReservedName($username, $memID, false)) {
709
+					$errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']);
710
+		}
678 711
 	}
679 712
 
680
-	if ($return_error)
681
-		return $errors;
682
-	elseif (empty($errors))
683
-		return null;
713
+	if ($return_error) {
714
+			return $errors;
715
+	} elseif (empty($errors)) {
716
+			return null;
717
+	}
684 718
 
685 719
 	loadLanguage('Errors');
686 720
 	$error = $errors[0];
@@ -706,22 +740,26 @@  discard block
 block discarded – undo
706 740
 	global $modSettings, $smcFunc;
707 741
 
708 742
 	// Perform basic requirements first.
709
-	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8))
710
-		return 'short';
743
+	if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) {
744
+			return 'short';
745
+	}
711 746
 
712 747
 	// Is this enough?
713
-	if (empty($modSettings['password_strength']))
714
-		return null;
748
+	if (empty($modSettings['password_strength'])) {
749
+			return null;
750
+	}
715 751
 
716 752
 	// Otherwise, perform the medium strength test - checking if password appears in the restricted string.
717
-	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0)
718
-		return 'restricted_words';
719
-	elseif ($smcFunc['strpos']($password, $username) !== false)
720
-		return 'restricted_words';
753
+	if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) {
754
+			return 'restricted_words';
755
+	} elseif ($smcFunc['strpos']($password, $username) !== false) {
756
+			return 'restricted_words';
757
+	}
721 758
 
722 759
 	// If just medium, we're done.
723
-	if ($modSettings['password_strength'] == 1)
724
-		return null;
760
+	if ($modSettings['password_strength'] == 1) {
761
+			return null;
762
+	}
725 763
 
726 764
 	// Otherwise, hard test next, check for numbers and letters, uppercase too.
727 765
 	$good = preg_match('~(\D\d|\d\D)~', $password) != 0;
@@ -753,14 +791,16 @@  discard block
 block discarded – undo
753 791
 			)
754 792
 		);
755 793
 		$groups = array();
756
-		while ($row = $smcFunc['db_fetch_assoc']($request))
757
-			$groups[] = $row['id_group'];
794
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
795
+					$groups[] = $row['id_group'];
796
+		}
758 797
 		$smcFunc['db_free_result']($request);
759 798
 
760
-		if (empty($groups))
761
-			$group_query = '0=1';
762
-		else
763
-			$group_query = 'id_group IN (' . implode(',', $groups) . ')';
799
+		if (empty($groups)) {
800
+					$group_query = '0=1';
801
+		} else {
802
+					$group_query = 'id_group IN (' . implode(',', $groups) . ')';
803
+		}
764 804
 	}
765 805
 
766 806
 	// Then, same again, just the boards this time!
@@ -770,10 +810,11 @@  discard block
 block discarded – undo
770 810
 	{
771 811
 		$boards = boardsAllowedTo('moderate_board', true);
772 812
 
773
-		if (empty($boards))
774
-			$board_query = '0=1';
775
-		else
776
-			$board_query = 'id_board IN (' . implode(',', $boards) . ')';
813
+		if (empty($boards)) {
814
+					$board_query = '0=1';
815
+		} else {
816
+					$board_query = 'id_board IN (' . implode(',', $boards) . ')';
817
+		}
777 818
 	}
778 819
 
779 820
 	// What boards are they the moderator of?
@@ -788,8 +829,9 @@  discard block
 block discarded – undo
788 829
 				'current_member' => $user_info['id'],
789 830
 			)
790 831
 		);
791
-		while ($row = $smcFunc['db_fetch_assoc']($request))
792
-			$boards_mod[] = $row['id_board'];
832
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
833
+					$boards_mod[] = $row['id_board'];
834
+		}
793 835
 		$smcFunc['db_free_result']($request);
794 836
 
795 837
 		// Can any of the groups they're in moderate any of the boards?
@@ -801,8 +843,9 @@  discard block
 block discarded – undo
801 843
 				'groups' => $user_info['groups'],
802 844
 			)
803 845
 		);
804
-		while ($row = $smcFunc['db_fetch_assoc']($request))
805
-			$boards_mod[] = $row['id_board'];
846
+		while ($row = $smcFunc['db_fetch_assoc']($request)) {
847
+					$boards_mod[] = $row['id_board'];
848
+		}
806 849
 		$smcFunc['db_free_result']($request);
807 850
 
808 851
 		// Just in case we've got duplicates here...
@@ -847,10 +890,12 @@  discard block
 block discarded – undo
847 890
 	global $modSettings;
848 891
 
849 892
 	// In case a customization wants to override the default settings
850
-	if ($httponly === null)
851
-		$httponly = !empty($modSettings['httponlyCookies']);
852
-	if ($secure === null)
853
-		$secure = !empty($modSettings['secureCookies']);
893
+	if ($httponly === null) {
894
+			$httponly = !empty($modSettings['httponlyCookies']);
895
+	}
896
+	if ($secure === null) {
897
+			$secure = !empty($modSettings['secureCookies']);
898
+	}
854 899
 
855 900
 	// Intercept cookie?
856 901
 	call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly));
@@ -870,8 +915,9 @@  discard block
 block discarded – undo
870 915
 function hash_password($username, $password, $cost = null)
871 916
 {
872 917
 	global $sourcedir, $smcFunc, $modSettings;
873
-	if (!function_exists('password_hash'))
874
-		require_once($sourcedir . '/Subs-Password.php');
918
+	if (!function_exists('password_hash')) {
919
+			require_once($sourcedir . '/Subs-Password.php');
920
+	}
875 921
 
876 922
 	$cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost;
877 923
 
@@ -903,8 +949,9 @@  discard block
 block discarded – undo
903 949
 function hash_verify_password($username, $password, $hash)
904 950
 {
905 951
 	global $sourcedir, $smcFunc;
906
-	if (!function_exists('password_verify'))
907
-		require_once($sourcedir . '/Subs-Password.php');
952
+	if (!function_exists('password_verify')) {
953
+			require_once($sourcedir . '/Subs-Password.php');
954
+	}
908 955
 
909 956
 	return password_verify($smcFunc['strtolower']($username) . $password, $hash);
910 957
 }
Please login to merge, or discard this patch.